GEOS  3.13.0dev
MinimumDiameter.h
1 /**********************************************************************
2  *
3  * GEOS - Geometry Engine Open Source
4  * http://geos.osgeo.org
5  *
6  * Copyright (C) 2023 Paul Ramsey <pramsey@cleverelephant.ca>
7  * Copyright (C) 2005-2006 Refractions Research Inc.
8  * Copyright (C) 2001-2002 Vivid Solutions Inc.
9  *
10  * This is free software; you can redistribute and/or modify it under
11  * the terms of the GNU Lesser General Public Licence as published
12  * by the Free Software Foundation.
13  * See the COPYING file for more information.
14  *
15  **********************************************************************/
16 
17 #pragma once
18 
19 #include <geos/geom/Coordinate.h>
20 #include <geos/geom/LineSegment.h>
21 
22 #include <memory>
23 #include <geos/export.h>
24 
25 // Forward declarations
26 namespace geos {
27 namespace geom {
28 class GeometryFactory;
29 class Geometry;
30 class LineString;
31 class CoordinateSequence;
32 }
33 }
34 
35 
36 namespace geos {
37 namespace algorithm { // geos::algorithm
38 
64 class GEOS_DLL MinimumDiameter {
65 private:
66  const geom::Geometry* inputGeom;
67  bool isConvex;
68 
69  std::unique_ptr<geom::CoordinateSequence> convexHullPts;
70 
71  geom::LineSegment minBaseSeg;
72  geom::Coordinate minWidthPt;
73  std::size_t minPtIndex;
74  double minWidth;
75  void computeMinimumDiameter();
76  void computeWidthConvex(const geom::Geometry* geom);
77 
85  void computeConvexRingMinDiameter(const geom::CoordinateSequence* pts);
86 
87  unsigned int findMaxPerpDistance(const geom::CoordinateSequence* pts,
88  const geom::LineSegment* seg, unsigned int startIndex);
89 
90  static unsigned int getNextIndex(const geom::CoordinateSequence* pts,
91  unsigned int index);
92 
93  static double computeC(double a, double b, const geom::Coordinate& p);
94 
95  static geom::LineSegment computeSegmentForLine(double a, double b, double c);
96 
97  static std::unique_ptr<geom::Geometry> computeMaximumLine(
98  const geom::CoordinateSequence* pts,
99  const geom::GeometryFactory* factory);
100 
101 public:
102  ~MinimumDiameter() = default;
103 
109  MinimumDiameter(const geom::Geometry* newInputGeom);
110 
120  MinimumDiameter(const geom::Geometry* newInputGeom,
121  const bool newIsConvex);
122 
128  double getLength();
129 
136 
142  std::unique_ptr<geom::LineString> getSupportingSegment();
143 
149  std::unique_ptr<geom::LineString> getDiameter();
150 
164  std::unique_ptr<geom::Geometry> getMinimumRectangle();
165 
173  static std::unique_ptr<geom::Geometry> getMinimumRectangle(geom::Geometry* geom);
174 
180  static std::unique_ptr<geom::Geometry> getMinimumDiameter(geom::Geometry* geom);
181 
182 };
183 
184 } // namespace geos::algorithm
185 } // namespace geos
Computes the minimum diameter of a geom::Geometry.
Definition: MinimumDiameter.h:64
const geom::Coordinate & getWidthCoordinate()
Gets the geom::Coordinate forming one end of the minimum diameter.
std::unique_ptr< geom::LineString > getSupportingSegment()
Gets the segment forming the base of the minimum diameter.
std::unique_ptr< geom::Geometry > getMinimumRectangle()
Gets the rectangular Polygon which encloses the input geometry and is based on the minimum diameter s...
static std::unique_ptr< geom::Geometry > getMinimumRectangle(geom::Geometry *geom)
Gets the minimum rectangle enclosing a geometry.
static std::unique_ptr< geom::Geometry > getMinimumDiameter(geom::Geometry *geom)
Gets the length of the minimum diameter enclosing a 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 > getDiameter()
Gets a LineString which is a minimum diameter.
The internal representation of a list of coordinates inside a Geometry.
Definition: CoordinateSequence.h:56
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:216
Supplies a set of utility methods for building Geometry objects from CoordinateSequence or other Geom...
Definition: GeometryFactory.h:65
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition: Geometry.h:186
Definition: LineSegment.h:61
Basic namespace for all GEOS functionalities.
Definition: Angle.h:25