Debian Codegraph @

src/atlas/util/PolygonXY.h

raw
1 /*
2 * (C) Copyright 2013 ECMWF.
3 *
4 * This software is licensed under the terms of the Apache Licence Version 2.0
5 * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6 * In applying this licence, ECMWF does not waive the privileges and immunities
7 * granted to it by virtue of its status as an intergovernmental organisation
8 * nor does it submit to any jurisdiction.
9 */
10
11 #pragma once
12
13 #include <type_traits>
14
15 #include "atlas/util/Polygon.h"
16
17 namespace atlas {
18 namespace util {
19
20 class PartitionPolygon;
21 class PolygonXY;
22 class ListPolygonXY;
23
24 //------------------------------------------------------------------------------------------------------
25
26 /// @brief Implement PolygonCoordinates::contains for a polygon defined in XY space.
27 class PolygonXY : public PolygonCoordinates {
28 public:
29 using Vector = ListPolygonXY;
30
31 PolygonXY(const PartitionPolygon&);
32
33 /// @brief Point-in-polygon test based on winding number
34 /// @note reference <a href="http://geomalgorithms.com/a03-_inclusion.html">Inclusion of a Point in a Polygon</a>
35 /// @param[in] P given point
36 /// @return if point (x,y) is in polygon
37 bool contains(const Point2& Pxy) const override;
38
39 private:
40 Point2 centroid_;
41 double inner_radius_squared_{0};
42 Point2 inner_coordinatesMin_;
43 Point2 inner_coordinatesMax_;
44 };
45
46
47 //------------------------------------------------------------------------------------------------------
48
49 /// @brief Vector of all polygons with functionality to find partition using a KDTree
50 class ListPolygonXY : public PolygonCoordinates::Vector {
51 public:
52 ListPolygonXY(const PartitionPolygons& partition_polygons) {
53 reserve(partition_polygons.size());
54 for (auto& partition_polygon : partition_polygons) {
55 emplace_back(new PolygonXY(partition_polygon));
56 }
57 }
58 };
59
60 //------------------------------------------------------------------------------------------------------
61
62 } // namespace util
63 } // namespace atlas