/src/geos/include/geos/algorithm/MinimumBoundingCircle.h
Line | Count | Source |
1 | | /********************************************************************** |
2 | | * |
3 | | * GEOS - Geometry Engine Open Source |
4 | | * http://geos.osgeo.org |
5 | | * |
6 | | * Copyright (C) 2019 Paul Ramsey <pramsey@cleverelephant.ca> |
7 | | * |
8 | | * This is free software; you can redistribute and/or modify it under |
9 | | * the terms of the GNU Lesser General Public Licence as published |
10 | | * by the Free Software Foundation. |
11 | | * See the COPYING file for more information. |
12 | | * |
13 | | ********************************************************************** |
14 | | * |
15 | | * Last port: algorithm/MinimumBoundingCircle.java 2019-01-23 |
16 | | * |
17 | | **********************************************************************/ |
18 | | |
19 | | #pragma once |
20 | | |
21 | | #include <geos/export.h> |
22 | | #include <geos/geom/Coordinate.h> |
23 | | #include <geos/geom/CoordinateSequence.h> |
24 | | #include <geos/geom/Geometry.h> |
25 | | #include <geos/geom/Point.h> |
26 | | #include <geos/geom/Triangle.h> |
27 | | |
28 | | #include <vector> |
29 | | |
30 | | // Forward declarations |
31 | | // namespace geos { |
32 | | // namespace geom { |
33 | | // class GeometryCollection; |
34 | | // } |
35 | | // } |
36 | | |
37 | | |
38 | | namespace geos { |
39 | | namespace algorithm { // geos::algorithm |
40 | | |
41 | | class GEOS_DLL MinimumBoundingCircle { |
42 | | |
43 | | private: |
44 | | |
45 | | // member variables |
46 | | const geom::Geometry* input; |
47 | | std::vector<geom::CoordinateXY> extremalPts; |
48 | | geom::CoordinateXY centre; |
49 | | double radius; |
50 | | |
51 | | void computeCentre(); |
52 | | void compute(); |
53 | | void computeCirclePoints(); |
54 | | geom::CoordinateXY lowestPoint(std::vector<geom::CoordinateXY>& pts); |
55 | | geom::CoordinateXY pointWitMinAngleWithX(std::vector<geom::CoordinateXY>& pts, geom::CoordinateXY& P); |
56 | | geom::CoordinateXY pointWithMinAngleWithSegment(std::vector<geom::CoordinateXY>& pts, |
57 | | geom::CoordinateXY& P, geom::CoordinateXY& Q); |
58 | | std::vector<geom::CoordinateXY> farthestPoints(std::vector<geom::CoordinateXY>& pts); |
59 | | |
60 | | |
61 | | public: |
62 | | |
63 | | MinimumBoundingCircle(const geom::Geometry* geom): |
64 | 0 | input(nullptr), |
65 | 0 | radius(0.0) |
66 | 0 | { |
67 | 0 | input = geom; |
68 | 0 | centre.setNull(); |
69 | 0 | } |
70 | | |
71 | 0 | ~MinimumBoundingCircle() {}; |
72 | | |
73 | | /** |
74 | | * Gets a geometry which represents the Minimum Bounding Circle. |
75 | | * If the input is degenerate (empty or a single unique point), |
76 | | * this method will return an empty geometry or a single Point geometry. |
77 | | * Otherwise, a Polygon will be returned which approximates the |
78 | | * Minimum Bounding Circle. |
79 | | * (Note that because the computed polygon is only an approximation, |
80 | | * it may not precisely contain all the input points.) |
81 | | * |
82 | | * @return a Geometry representing the Minimum Bounding Circle. |
83 | | */ |
84 | | std::unique_ptr<geom::Geometry> getCircle(); |
85 | | |
86 | | /** |
87 | | * Gets a geometry representing a line between the two farthest points |
88 | | * in the input. |
89 | | * These points will be two of the extremal points of the Minimum Bounding Circle. |
90 | | * They also lie on the convex hull of the input. |
91 | | * |
92 | | * @return a LineString between the two farthest points of the input |
93 | | * @return a empty LineString if the input is empty |
94 | | * @return a Point if the input is a point |
95 | | */ |
96 | | std::unique_ptr<geom::Geometry> getMaximumDiameter(); |
97 | | |
98 | | /** |
99 | | * Gets a geometry representing the diameter of the computed Minimum Bounding |
100 | | * Circle. |
101 | | * |
102 | | * @return the diameter LineString of the Minimum Bounding Circle |
103 | | * @return a empty LineString if the input is empty |
104 | | * @return a Point if the input is a point |
105 | | */ |
106 | | std::unique_ptr<geom::Geometry> getDiameter(); |
107 | | |
108 | | /** |
109 | | * Gets the extremal points which define the computed Minimum Bounding Circle. |
110 | | * There may be zero, one, two or three of these points, |
111 | | * depending on the number of points in the input |
112 | | * and the geometry of those points. |
113 | | * |
114 | | * @return the points defining the Minimum Bounding Circle |
115 | | */ |
116 | | std::vector<geom::CoordinateXY> getExtremalPoints(); |
117 | | |
118 | | /** |
119 | | * Gets the centre point of the computed Minimum Bounding Circle. |
120 | | * |
121 | | * @return the centre point of the Minimum Bounding Circle |
122 | | * @return null if the input is empty |
123 | | */ |
124 | | geom::CoordinateXY getCentre(); |
125 | | |
126 | | /** |
127 | | * Gets the radius of the computed Minimum Bounding Circle. |
128 | | * |
129 | | * @return the radius of the Minimum Bounding Circle |
130 | | */ |
131 | | double getRadius(); |
132 | | |
133 | | }; |
134 | | |
135 | | } // namespace geos::algorithm |
136 | | } // namespace geos |
137 | | |