GEOS 3.6.2
Centroid.h
1/**********************************************************************
2 *
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
5 *
6 * Copyright (C) 2013 Sandro Santilli <strk@keybit.net>
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#ifndef GEOS_ALGORITHM_CENTROID_H
20#define GEOS_ALGORITHM_CENTROID_H
21
22#include <geos/export.h>
23#include <geos/geom/Coordinate.h> // for composition
24#include <memory> // for std::auto_ptr
25
26// Forward declarations
27namespace geos {
28 namespace geom {
29 class Geometry;
30 class Polygon;
32 }
33}
34
35
36namespace geos {
37namespace algorithm { // geos::algorithm
38
61class GEOS_DLL Centroid {
62
63public:
64
74 static bool getCentroid(const geom::Geometry& geom, geom::Coordinate& cent);
75
80 :
81 areasum2(0.0),
82 totalLength(0.0),
83 ptCount(0)
84 {
85 add(geom);
86 }
87
96 bool getCentroid(geom::Coordinate& cent) const;
97
98private:
99
100 std::auto_ptr<geom::Coordinate> areaBasePt;
101 geom::Coordinate triangleCent3;
103 geom::Coordinate lineCentSum;
104 geom::Coordinate ptCentSum;
105 double areasum2;
106 double totalLength;
107 int ptCount;
108
114 void add(const geom::Geometry& geom);
115
116 void setBasePoint(const geom::Coordinate& basePt);
117
118 void add(const geom::Polygon& poly);
119
120 void addShell(const geom::CoordinateSequence& pts);
121
122 void addHole(const geom::CoordinateSequence& pts);
123
124 void addTriangle(const geom::Coordinate& p0, const geom::Coordinate& p1, const geom::Coordinate& p2, bool isPositiveArea);
125
131 static void centroid3(const geom::Coordinate& p1, const geom::Coordinate& p2, const geom::Coordinate& p3, geom::Coordinate& c );
132
137 static double area2(const geom::Coordinate& p1, const geom::Coordinate& p2, const geom::Coordinate& p3 );
138
145 void addLineSegments(const geom::CoordinateSequence& pts);
146
151 void addPoint(const geom::Coordinate& pt);
152};
153
154} // namespace geos::algorithm
155} // namespace geos
156
157#endif // GEOS_ALGORITHM_CENTROID_H
Centroid(const geom::Geometry &geom)
Definition Centroid.h:79
static bool getCentroid(const geom::Geometry &geom, geom::Coordinate &cent)
bool getCentroid(geom::Coordinate &cent) const
The internal representation of a list of coordinates inside a Geometry.
Definition CoordinateSequence.h:59
Coordinate is the lightweight class used to store coordinates.
Definition Coordinate.h:60
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition Geometry.h:167
Represents a linear polygon, which may include holes.
Definition Polygon.h:67
Contains classes and interfaces implementing fundamental computational geometry algorithms.
Definition Angle.h:33
Contains the Geometry interface hierarchy and supporting classes.
Definition IndexedNestedRingTester.h:26
Basic namespace for all GEOS functionalities.
Definition IndexedNestedRingTester.h:25