GEOS  3.12.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.
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
29 namespace geos {
30 namespace geom {
31 class GeometryFactory;
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  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 
100 public:
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 
134  const geom::Coordinate& getWidthCoordinate();
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
geos
Basic namespace for all GEOS functionalities.
Definition: Angle.h:25
geos::geom::Coordinate
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:82
geos::geom::Geometry
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition: Geometry.h:186
geos::geom::CoordinateSequence
The internal representation of a list of coordinates inside a Geometry.
Definition: CoordinateSequence.h:44
geos::geom::LineSegment
Definition: LineSegment.h:60
geos::geom::GeometryFactory
Supplies a set of utility methods for building Geometry objects from CoordinateSequence or other Geom...
Definition: GeometryFactory.h:66
geos::algorithm::MinimumDiameter
Computes the minimum diameter of a geom::Geometry.
Definition: MinimumDiameter.h:63