GEOS 3.11.1
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
35#ifdef _MSC_VER
36#pragma warning(push)
37#pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
38#endif
39
40// Forward declarations
41namespace geos {
42namespace geom {
43class GeometryFactory;
44}
45}
46
47namespace geos {
48namespace algorithm { // geos::algorithm
49
61class GEOS_DLL ConvexHull {
62private:
63 const geom::GeometryFactory* geomFactory;
65
66 void
67 extractCoordinates(const geom::Geometry* geom)
68 {
69 util::UniqueCoordinateArrayFilter filter(inputPts);
70 geom->apply_ro(&filter);
71 }
72
77 std::unique_ptr<geom::CoordinateSequence> toCoordinateSequence(geom::Coordinate::ConstVect& cv);
78
79 void computeOctPts(const geom::Coordinate::ConstVect& src,
81
82 bool computeOctRing(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, const geom::Coordinate& q);
136
137 void grahamScan(const geom::Coordinate::ConstVect& c,
139
149 std::unique_ptr<geom::Geometry> lineOrPolygon(const geom::Coordinate::ConstVect& vertices);
150
155 void cleanRing(const geom::Coordinate::ConstVect& input,
157
162 bool isBetween(const geom::Coordinate& c1, const geom::Coordinate& c2, const geom::Coordinate& c3);
163
164public:
165
169 ConvexHull(const geom::Geometry* newGeometry)
170 : geomFactory(newGeometry->getFactory())
171 {
172 extractCoordinates(newGeometry);
173 };
174
175 ~ConvexHull() {};
176
189 std::unique_ptr<geom::Geometry> getConvexHull();
190};
191
192} // namespace geos::algorithm
193} // namespace geos
194
195#ifdef _MSC_VER
196#pragma warning(pop)
197#endif
198
199
Computes the convex hull of a Geometry.
Definition: ConvexHull.h:61
std::unique_ptr< geom::Geometry > getConvexHull()
ConvexHull(const geom::Geometry *newGeometry)
Definition: ConvexHull.h:169
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:58
std::vector< const Coordinate * > ConstVect
A vector of const Coordinate pointers.
Definition: Coordinate.h:69
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
Basic namespace for all GEOS functionalities.
Definition: geos.h:39