GEOS  3.14.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 Coordinate:: 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 #include "geos/util.h"
37 
38 #ifdef _MSC_VER
39 #pragma warning(push)
40 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
41 #endif
42 
43 // Forward declarations
44 namespace geos {
45 namespace geom {
46 class GeometryFactory;
47 }
48 }
49 
50 namespace geos {
51 namespace algorithm { // geos::algorithm
52 
64 class GEOS_DLL ConvexHull {
65 private:
66 
67  static constexpr std::size_t TUNING_REDUCE_SIZE = 50;
68 
69  const geom::Geometry* inputGeom;
70  const geom::GeometryFactory* geomFactory;
72 
77  std::unique_ptr<geom::CoordinateSequence> toCoordinateSequence(geom::Coordinate::ConstVect& cv);
78 
79  void computeInnerOctolateralPts(
80  const geom::Coordinate::ConstVect& src,
82 
83  bool computeInnerOctolateralRing(
84  const geom::Coordinate::ConstVect& src,
86 
111  void reduce(geom::Coordinate::ConstVect& pts);
112 
114  void padArray3(geom::Coordinate::ConstVect& pts);
115 
117  void preSort(geom::Coordinate::ConstVect& pts);
118 
136  int polarCompare(const geom::Coordinate& o,
137  const geom::Coordinate& p,
138  const geom::Coordinate& q);
139 
140  void grahamScan(const geom::Coordinate::ConstVect& c,
142 
152  std::unique_ptr<geom::Geometry> lineOrPolygon(const geom::Coordinate::ConstVect& vertices);
153 
158  void cleanRing(const geom::Coordinate::ConstVect& input,
159  geom::Coordinate::ConstVect& cleaned);
160 
165  bool isBetween(
166  const geom::Coordinate& c1,
167  const geom::Coordinate& c2,
168  const geom::Coordinate& c3);
169 
170  bool extractUnique(geom::Coordinate::ConstVect& pts, std::size_t maxPts);
171  std::unique_ptr<geom::Geometry> createFewPointsResult();
172 
173 
174 
175 public:
176 
180  ConvexHull(const geom::Geometry* newGeometry)
181  : inputGeom(newGeometry)
182  , geomFactory(newGeometry->getFactory())
183  {
184  util::ensureNoCurvedComponents(inputGeom);
185  };
186 
187  ~ConvexHull() {};
188 
201  std::unique_ptr<geom::Geometry> getConvexHull();
202 };
203 
204 } // namespace geos::algorithm
205 } // namespace geos
206 
207 #ifdef _MSC_VER
208 #pragma warning(pop)
209 #endif
210 
211 
Computes the convex hull of a Geometry.
Definition: ConvexHull.h:64
std::unique_ptr< geom::Geometry > getConvexHull()
ConvexHull(const geom::Geometry *newGeometry)
Definition: ConvexHull.h:180
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:217
std::vector< const Coordinate * > ConstVect
A vector of const Coordinate pointers.
Definition: Coordinate.h:229
Supplies a set of utility methods for building Geometry objects from CoordinateSequence or other Geom...
Definition: GeometryFactory.h:70
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition: Geometry.h:197
Basic namespace for all GEOS functionalities.
Definition: Angle.h:25