File Coverage

/usr/local/lib/perl5/site_perl/5.26.1/x86_64-linux/CPP/geos.x/i/geos/algorithm/CentroidArea.h
Criterion Covered Total %
statement 4 4 100.0
branch n/a
condition n/a
subroutine n/a
pod n/a
total 4 4 100.0


line stmt bran cond sub pod time code
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
25             #include
26              
27             // Forward declarations
28             namespace geos {
29             namespace geom {
30             class CoordinateSequence;
31             class Geometry;
32             class Polygon;
33             }
34             }
35              
36             namespace geos {
37             namespace algorithm { // geos::algorithm
38              
39             /**
40             * \class CentroidArea geosAlgorithm.h geos/geosAlgorithm.h
41             *
42             * \brief Computes the centroid of an area geometry.
43             *
44             * Algorithm:
45             *
46             * Based on the usual algorithm for calculating
47             * the centroid as a weighted sum of the centroids
48             * of a decomposition of the area into (possibly overlapping) triangles.
49             * The algorithm has been extended to handle holes and multi-polygons.
50             * See http://www.faqs.org/faqs/graphics/algorithms-faq/
51             * for further details of the basic approach.
52             *
53             * The code has also be extended to handle degenerate (zero-area) polygons.
54             * In this case, the centroid of the line segments in the polygon
55             * will be returned.
56             *
57             * @deprecated use Centroid instead
58             *
59             */
60             class GEOS_DLL CentroidArea {
61              
62             public:
63              
64 3           CentroidArea()
65             :
66             basePt(0.0, 0.0),
67             areasum2(0.0),
68 3           totalLength(0.0)
69 3           {}
70              
71 3           ~CentroidArea() {}
72              
73             /**
74             * Adds the area defined by a Geometry to the centroid total.
75             * If the geometry has no area it does not contribute to the centroid.
76             *
77             * @param geom the geometry to add
78             */
79             void add(const geom::Geometry *geom);
80              
81             /**
82             * Adds the area defined by an array of
83             * coordinates. The array must be a ring;
84             * i.e. end with the same coordinate as it starts with.
85             * @param ring an array of {@link Coordinate}s
86             */
87             void add(const geom::CoordinateSequence *ring);
88              
89             // TODO: deprecate
90             geom::Coordinate* getCentroid() const;
91              
92             /// Return false if a centroid couldn't be computed ( empty polygon )
93             bool getCentroid(geom::Coordinate& ret) const;
94              
95             private:
96              
97             /// the point all triangles are based at
98             geom::Coordinate basePt;
99              
100             // temporary variable to hold centroid of triangle
101             geom::Coordinate triangleCent3;
102              
103             /// Partial area sum
104             double areasum2;
105              
106             /// partial centroid sum
107             geom::Coordinate cg3;
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              
130             /**
131             * Adds the linear segments defined by an array of coordinates
132             * to the linear centroid accumulators.
133             *
134             * This is done in case the polygon(s) have zero-area,
135             * in which case the linear centroid is computed instead.
136             *
137             * @param pts an array of {@link Coordinate}s
138             */
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