GEOS 3.4.2

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List

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
27 namespace geos {
28 namespace geom {
29 class Geometry;
30 class Polygon;
31 class CoordinateSequence;
32 }
33 }
34
35
36 namespace geos {
37 namespace algorithm { // geos::algorithm
38
61 class GEOS_DLL Centroid {
62
63 public:
64
74 static bool getCentroid(const geom::Geometry& geom, geom::Coordinate& cent);
75
79 Centroid(const geom::Geometry& geom)
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
98 private:
99
100 std::auto_ptr<geom::Coordinate> areaBasePt;
101 geom::Coordinate triangleCent3;
102 geom::Coordinate cg3;
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