GEOS 3.14.0dev
MinimumAreaRectangle.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 *
8 * This is free software; you can redistribute and/or modify it under
9 * the terms of the GNU Lesser General Public Licence as published
10 * by the Free Software Foundation.
11 * See the COPYING file for more information.
12 *
13 **********************************************************************/
14
15#pragma once
16
17#include <geos/export.h>
18
19#include <vector>
20#include <memory>
21
22// Forward declarations
23namespace geos {
24 namespace geom {
25 class CoordinateSequence;
26 class CoordinateXY;
27 class Geometry;
28 class GeometryFactory;
29 class LineSegment;
30 class LineString;
31 class Polygon;
32 }
33}
34
35namespace geos {
36namespace algorithm { // geos::algorithm
37
38
58class GEOS_DLL MinimumAreaRectangle {
60 using CoordinateXY = geos::geom::CoordinateXY;
66
67private:
68
69 // Members
70 const Geometry* m_inputGeom;
71 bool m_isConvex;
72
73 // Methods
74 std::unique_ptr<Geometry> getMinimumRectangle();
75
76 std::unique_ptr<Geometry> computeConvex(const Geometry* convexGeom);
77
86 std::unique_ptr<Polygon> computeConvexRing(const CoordinateSequence* ring);
87
88 std::size_t findFurthestVertex(
89 const CoordinateSequence* pts,
90 const LineSegment& baseSeg,
91 std::size_t startIndex,
92 int orient);
93
94 bool isFurtherOrEqual(double d1, double d2, int orient);
95
96 static double orientedDistance(
97 const LineSegment& seg,
98 const CoordinateXY& p,
99 int orient);
100
101 static std::size_t getNextIndex(
102 const CoordinateSequence* ring,
103 std::size_t index);
104
111 static std::unique_ptr<LineString> computeMaximumLine(
112 const CoordinateSequence* pts,
113 const GeometryFactory* factory);
114
115
116public:
117
124 : m_inputGeom(inputGeom)
125 , m_isConvex(false)
126 {};
127
137 MinimumAreaRectangle(const Geometry* inputGeom, bool isConvex)
138 : m_inputGeom(inputGeom)
139 , m_isConvex(isConvex)
140 {};
141
150 static std::unique_ptr<Geometry> getMinimumRectangle(const Geometry* geom);
151
152};
153
154
155} // namespace geos::algorithm
156} // namespace geos
157
Definition MinimumAreaRectangle.h:58
MinimumAreaRectangle(const Geometry *inputGeom, bool isConvex)
Definition MinimumAreaRectangle.h:137
MinimumAreaRectangle(const Geometry *inputGeom)
Definition MinimumAreaRectangle.h:123
static std::unique_ptr< Geometry > getMinimumRectangle(const Geometry *geom)
The internal representation of a list of coordinates inside a Geometry.
Definition CoordinateSequence.h:56
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
Definition LineSegment.h:61
Definition LineString.h:66
Represents a linear polygon, which may include holes.
Definition Polygon.h:61
Basic namespace for all GEOS functionalities.
Definition geos.h:39