GEOS 3.6.2
CentroidArea.h
1/**********************************************************************
2 *
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
5 *
6 * Copyright (C) 2005-2006 Refractions Research Inc.
7 * Copyright (C) 2001-2002 Vivid Solutions Inc.
8 *
9 * This is free software; you can redistribute and/or modify it under
10 * the terms of the GNU Lesser General Public Licence as published
11 * by the Free Software Foundation.
12 * See the COPYING file for more information.
13 *
14 **********************************************************************
15 *
16 * Last port: algorithm/CentroidArea.java r612
17 *
18 **********************************************************************/
19
20#ifndef GEOS_ALGORITHM_CENTROIDAREA_H
21#define GEOS_ALGORITHM_CENTROIDAREA_H
22
23
24#include <geos/export.h>
25#include <geos/geom/Coordinate.h>
26
27// Forward declarations
28namespace geos {
29 namespace geom {
31 class Geometry;
32 class Polygon;
33 }
34}
35
36namespace geos {
37namespace algorithm { // geos::algorithm
38
60class GEOS_DLL CentroidArea {
61
62public:
63
64 CentroidArea()
65 :
66 basePt(0.0, 0.0),
67 areasum2(0.0),
68 totalLength(0.0)
69 {}
70
71 ~CentroidArea() {}
72
79 void add(const geom::Geometry *geom);
80
87 void add(const geom::CoordinateSequence *ring);
88
89 // TODO: deprecate
90 geom::Coordinate* getCentroid() const;
91
93 bool getCentroid(geom::Coordinate& ret) const;
94
95private:
96
98 geom::Coordinate basePt;
99
100 // temporary variable to hold centroid of triangle
101 geom::Coordinate triangleCent3;
102
104 double areasum2;
105
108
109 // data for linear centroid computation, if needed
110 geom::Coordinate centSum;
111 double totalLength;
112
113 void setBasePoint(const geom::Coordinate &newbasePt);
114
115 void add(const geom::Polygon *poly);
116
117 void addShell(const geom::CoordinateSequence *pts);
118
119 void addHole(const geom::CoordinateSequence *pts);
120
121 void addTriangle(const geom::Coordinate &p0, const geom::Coordinate &p1,
122 const geom::Coordinate &p2,bool isPositiveArea);
123
124 static void centroid3(const geom::Coordinate &p1, const geom::Coordinate &p2,
125 const geom::Coordinate &p3, geom::Coordinate &c);
126
127 static double area2(const geom::Coordinate &p1, const geom::Coordinate &p2,
128 const geom::Coordinate &p3);
129
139 void addLinearSegments(const geom::CoordinateSequence& pts);
140
141};
142
143} // namespace geos::algorithm
144} // namespace geos
145
146
147#endif // GEOS_ALGORITHM_CENTROIDAREA_H
void add(const geom::Geometry *geom)
void add(const geom::CoordinateSequence *ring)
bool getCentroid(geom::Coordinate &ret) const
Return false if a centroid couldn't be computed ( empty polygon ).
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