GEOS 3.9.1
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.
12 * See the COPYING file for more information.
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
30namespace geos {
31namespace geom {
32class Geometry;
33class LineString;
34class CoordinateSequence;
35}
36}
37
38
39namespace geos {
40namespace algorithm { // geos::algorithm
41
63class GEOS_DLL MinimumDiameter {
64private:
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
96public:
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
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
Computes the minimum diameter of a geom::Geometry.
Definition: MinimumDiameter.h:63
const geom::Coordinate & getWidthCoordinate()
Gets the geom::Coordinate forming one end of the minimum diameter.
static std::unique_ptr< geom::Geometry > getMinimumRectangle(geom::Geometry *geom)
Gets the minimum rectangle enclosing a geometry.
std::unique_ptr< geom::LineString > getDiameter()
Gets a LineString which is a minimum diameter.
static std::unique_ptr< geom::Geometry > getMinimumDiameter(geom::Geometry *geom)
Gets the length of the minimum diameter enclosing a geometry.
std::unique_ptr< geom::Geometry > getMinimumRectangle()
Gets the minimum rectangular Polygon which encloses the input geometry.
double getLength()
Gets the length of the minimum diameter of the input Geometry.
MinimumDiameter(const geom::Geometry *newInputGeom)
Compute a minimum diameter for a given Geometry.
MinimumDiameter(const geom::Geometry *newInputGeom, const bool newIsConvex)
Compute a minimum diameter for a given Geometry, with a hint if the Geometry is convex (e....
std::unique_ptr< geom::LineString > getSupportingSegment()
Gets the segment forming the base of the minimum diameter.
The internal representation of a list of coordinates inside a Geometry.
Definition: CoordinateSequence.h:58
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
Definition: LineSegment.h:59
Basic namespace for all GEOS functionalities.
Definition: IndexedNestedRingTester.h:26