GEOS 3.11.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#pragma once
21
22#include <geos/geom/Coordinate.h>
23#include <geos/geom/LineSegment.h>
24
25#include <memory>
26#include <geos/export.h>
27
28// Forward declarations
29namespace geos {
30namespace geom {
31class GeometryFactory;
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 std::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 static std::unique_ptr<geom::Geometry> computeMaximumLine(
97 const geom::CoordinateSequence* pts,
98 const geom::GeometryFactory* factory);
99
100public:
101 ~MinimumDiameter() = default;
102
108 MinimumDiameter(const geom::Geometry* newInputGeom);
109
119 MinimumDiameter(const geom::Geometry* newInputGeom,
120 const bool newIsConvex);
121
127 double getLength();
128
135
141 std::unique_ptr<geom::LineString> getSupportingSegment();
142
148 std::unique_ptr<geom::LineString> getDiameter();
149
161 std::unique_ptr<geom::Geometry> getMinimumRectangle();
162
169 static std::unique_ptr<geom::Geometry> getMinimumRectangle(geom::Geometry* geom);
170
176 static std::unique_ptr<geom::Geometry> getMinimumDiameter(geom::Geometry* geom);
177
178};
179
180} // namespace geos::algorithm
181} // namespace geos
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:44
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:58
Supplies a set of utility methods for building Geometry objects from CoordinateSequence or other Geom...
Definition: GeometryFactory.h:66
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition: Geometry.h:186
Definition: LineSegment.h:60
Basic namespace for all GEOS functionalities.
Definition: geos.h:39