GEOS 3.14.0dev
Centroid.h
1/**********************************************************************
2 *
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
5 *
6 * Copyright (C) 2013 Sandro Santilli <strk@kbt.io>
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 * Last port: algorithm/Centroid.java r728 (JTS-0.13+)
16 *
17 **********************************************************************/
18
19#pragma once
20
21#include <geos/export.h>
22#include <geos/geom/Coordinate.h> // for composition
23#include <memory> // for std::unique_ptr
24
25// Forward declarations
26namespace geos {
27namespace geom {
28class Geometry;
29class Polygon;
30class CoordinateSequence;
31}
32}
33
34
35namespace geos {
36namespace algorithm { // geos::algorithm
37
60class GEOS_DLL Centroid {
61
62public:
63
73 static bool getCentroid(const geom::Geometry& geom, geom::CoordinateXY& cent);
74
79 :
80 areasum2(0.0),
81 totalLength(0.0),
82 ptCount(0)
83 {
84 add(geom);
85 }
86
95 bool getCentroid(geom::CoordinateXY& cent) const;
96
97private:
98
99 std::unique_ptr<geom::CoordinateXY> areaBasePt;
100 geom::CoordinateXY triangleCent3;
101 geom::CoordinateXY cg3;
102 geom::CoordinateXY lineCentSum;
103 geom::CoordinateXY ptCentSum;
104 double areasum2;
105 double totalLength;
106 int ptCount;
107
113 void add(const geom::Geometry& geom);
114
115 void setAreaBasePoint(const geom::CoordinateXY& basePt);
116
117 void add(const geom::Polygon& poly);
118
119 void addShell(const geom::CoordinateSequence& pts);
120
121 void addHole(const geom::CoordinateSequence& pts);
122
123 void addTriangle(const geom::CoordinateXY& p0, const geom::CoordinateXY& p1, const geom::CoordinateXY& p2,
124 bool isPositiveArea);
125
131 static void centroid3(const geom::CoordinateXY& p1, const geom::CoordinateXY& p2, const geom::CoordinateXY& p3,
132 geom::CoordinateXY& c);
133
138 static double area2(const geom::CoordinateXY& p1, const geom::CoordinateXY& p2, const geom::CoordinateXY& p3);
139
146 void addLineSegments(const geom::CoordinateSequence& pts);
147
152 void addPoint(const geom::CoordinateXY& pt);
153};
154
155} // namespace geos::algorithm
156} // namespace geos
157
Computes the centroid of a Geometry of any dimension.
Definition Centroid.h:60
Centroid(const geom::Geometry &geom)
Creates a new instance for computing the centroid of a geometry.
Definition Centroid.h:78
static bool getCentroid(const geom::Geometry &geom, geom::CoordinateXY &cent)
Computes the centroid point of a geometry.
bool getCentroid(geom::CoordinateXY &cent) const
Gets the computed centroid.
The internal representation of a list of coordinates inside a Geometry.
Definition CoordinateSequence.h:56
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition Geometry.h:197
Represents a linear polygon, which may include holes.
Definition Polygon.h:61
Basic namespace for all GEOS functionalities.
Definition geos.h:39