GEOS  3.9.0dev
MinimumDiameter.h
1 /**********************************************************************
2  *
3  * GEOS - Geometry Engine Open Source
4  * http://geos.osgeo.org
5  *
6  * Copyright (C) 2005-2006 Refractions Research Inc.
7  * Copyright (C) 2001-2002 Vivid Solutions Inc.
8  *
9  * This is free software; you can redistribute and/or modify it under
10  * the terms of the GNU Lesser General Public Licence as published
11  * by the Free Software Foundation.
13  *
14  **********************************************************************
15  *
16  * Last port: algorithm/MinimumDiameter.java r966
17  *
18  **********************************************************************/
19
20 #ifndef GEOS_ALGORITHM_MINIMUMDIAMETER_H
21 #define GEOS_ALGORITHM_MINIMUMDIAMETER_H
22
23 #include <geos/geom/Coordinate.h>
24 #include <geos/geom/LineSegment.h>
25
26 #include <memory>
27 #include <geos/export.h>
28
29 // Forward declarations
30 namespace geos {
31 namespace geom {
32 class Geometry;
33 class LineString;
34 class CoordinateSequence;
35 }
36 }
37
38
39 namespace geos {
40 namespace algorithm { // geos::algorithm
41
63 class GEOS_DLL MinimumDiameter {
64 private:
65  const geom::Geometry* inputGeom;
66  bool isConvex;
67
68  std::unique_ptr<geom::CoordinateSequence> convexHullPts;
69
70  geom::LineSegment minBaseSeg;
71  geom::Coordinate minWidthPt;
72  size_t minPtIndex;
73  double minWidth;
74  void computeMinimumDiameter();
75  void computeWidthConvex(const geom::Geometry* geom);
76
84  void computeConvexRingMinDiameter(const geom::CoordinateSequence* pts);
85
86  unsigned int findMaxPerpDistance(const geom::CoordinateSequence* pts,
87  const geom::LineSegment* seg, unsigned int startIndex);
88
89  static unsigned int getNextIndex(const geom::CoordinateSequence* pts,
90  unsigned int index);
91
92  static double computeC(double a, double b, const geom::Coordinate& p);
93
94  static geom::LineSegment computeSegmentForLine(double a, double b, double c);
95
96 public:
97  ~MinimumDiameter() = default;
98
104  MinimumDiameter(const geom::Geometry* newInputGeom);
105
115  MinimumDiameter(const geom::Geometry* newInputGeom,
116  const bool newIsConvex);
117
123  double getLength();
124
130  const geom::Coordinate& getWidthCoordinate();
131
137  std::unique_ptr<geom::LineString> getSupportingSegment();
138
144  std::unique_ptr<geom::LineString> getDiameter();
145
157  std::unique_ptr<geom::Geometry> getMinimumRectangle();
158
165  static std::unique_ptr<geom::Geometry> getMinimumRectangle(geom::Geometry* geom);
166
172  static std::unique_ptr<geom::Geometry> getMinimumDiameter(geom::Geometry* geom);
173
174 };
175
176 } // namespace geos::algorithm
177 } // namespace geos
178
179 #endif // GEOS_ALGORITHM_MINIMUMDIAMETER_H
180
Definition: LineSegment.h:59
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:60
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition: Geometry.h:188
Basic namespace for all GEOS functionalities.
Definition: IndexedNestedRingTester.h:26
Computes the minimum diameter of a geom::Geometry.
Definition: MinimumDiameter.h:63
The internal representation of a list of coordinates inside a Geometry.
Definition: CoordinateSequence.h:58