GEOS  3.13.0dev
ConvexHull.h
1 /**********************************************************************
2  *
3  * GEOS - Geometry Engine Open Source
4  * http://geos.osgeo.org
5  *
6  * Copyright (C) 2011 Sandro Santilli <strk@kbt.io>
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  * Last port: algorithm/ConvexHull.java r407 (JTS-1.12+)
18  *
19  **********************************************************************/
20 
21 #pragma once
22 
23 #include <geos/export.h>
24 #include <memory>
25 #include <vector>
26 #include <cassert>
27 
28 // FIXME: avoid using Cordinate:: typedefs to avoid full include
29 #include <geos/algorithm/ConvexHull.h>
30 #include <geos/geom/Coordinate.h>
31 #include <geos/geom/CoordinateSequence.h>
32 #include <geos/geom/Geometry.h>
33 #include <geos/util/UniqueCoordinateArrayFilter.h>
34 #include <geos/util/CoordinateArrayFilter.h>
35 
36 #ifdef _MSC_VER
37 #pragma warning(push)
38 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
39 #endif
40 
41 // Forward declarations
42 namespace geos {
43 namespace geom {
44 class GeometryFactory;
45 }
46 }
47 
48 namespace geos {
49 namespace algorithm { // geos::algorithm
50 
62 class GEOS_DLL ConvexHull {
63 private:
64 
65  static constexpr std::size_t TUNING_REDUCE_SIZE = 50;
66 
67  const geom::Geometry* inputGeom;
68  const geom::GeometryFactory* geomFactory;
70 
75  std::unique_ptr<geom::CoordinateSequence> toCoordinateSequence(geom::Coordinate::ConstVect& cv);
76 
77  void computeInnerOctolateralPts(
78  const geom::Coordinate::ConstVect& src,
80 
81  bool computeInnerOctolateralRing(
82  const geom::Coordinate::ConstVect& src,
84 
109  void reduce(geom::Coordinate::ConstVect& pts);
110 
112  void padArray3(geom::Coordinate::ConstVect& pts);
113 
115  void preSort(geom::Coordinate::ConstVect& pts);
116 
134  int polarCompare(const geom::Coordinate& o,
135  const geom::Coordinate& p,
136  const geom::Coordinate& q);
137 
138  void grahamScan(const geom::Coordinate::ConstVect& c,
140 
150  std::unique_ptr<geom::Geometry> lineOrPolygon(const geom::Coordinate::ConstVect& vertices);
151 
156  void cleanRing(const geom::Coordinate::ConstVect& input,
157  geom::Coordinate::ConstVect& cleaned);
158 
163  bool isBetween(
164  const geom::Coordinate& c1,
165  const geom::Coordinate& c2,
166  const geom::Coordinate& c3);
167 
168  bool extractUnique(geom::Coordinate::ConstVect& pts, std::size_t maxPts);
169  std::unique_ptr<geom::Geometry> createFewPointsResult();
170 
171 
172 
173 public:
174 
178  ConvexHull(const geom::Geometry* newGeometry)
179  : inputGeom(newGeometry)
180  , geomFactory(newGeometry->getFactory())
181  {};
182 
183  ~ConvexHull() {};
184 
197  std::unique_ptr<geom::Geometry> getConvexHull();
198 };
199 
200 } // namespace geos::algorithm
201 } // namespace geos
202 
203 #ifdef _MSC_VER
204 #pragma warning(pop)
205 #endif
206 
207 
Computes the convex hull of a Geometry.
Definition: ConvexHull.h:62
std::unique_ptr< geom::Geometry > getConvexHull()
ConvexHull(const geom::Geometry *newGeometry)
Definition: ConvexHull.h:178
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:216
std::vector< const Coordinate * > ConstVect
A vector of const Coordinate pointers.
Definition: Coordinate.h:227
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
Basic namespace for all GEOS functionalities.
Definition: Angle.h:25