GEOS  3.3.8
CentroidArea.h
1 /**********************************************************************
2  * $Id: CentroidArea.h 3681 2012-06-22 15:46:04Z strk $
3  *
4  * GEOS - Geometry Engine Open Source
5  * http://geos.refractions.net
6  *
7  * Copyright (C) 2005-2006 Refractions Research Inc.
8  * Copyright (C) 2001-2002 Vivid Solutions Inc.
9  *
10  * This is free software; you can redistribute and/or modify it under
11  * the terms of the GNU Lesser General Public Licence as published
12  * by the Free Software Foundation.
13  * See the COPYING file for more information.
14  *
15  **********************************************************************
16  *
17  * Last port: algorithm/CentroidArea.java r612
18  *
19  **********************************************************************/
20 
21 #ifndef GEOS_ALGORITHM_CENTROIDAREA_H
22 #define GEOS_ALGORITHM_CENTROIDAREA_H
23 
24 
25 #include <geos/export.h>
26 #include <geos/geom/Coordinate.h>
27 
28 // Forward declarations
29 namespace geos {
30  namespace geom {
31  class CoordinateSequence;
32  class Geometry;
33  class Polygon;
34  }
35 }
36 
37 namespace geos {
38 namespace algorithm { // geos::algorithm
39 
58 class GEOS_DLL CentroidArea {
59 
60 public:
61 
62  CentroidArea()
63  :
64  basePt(0.0, 0.0),
65  areasum2(0.0),
66  totalLength(0.0)
67  {}
68 
69  ~CentroidArea() {}
70 
77  void add(const geom::Geometry *geom);
78 
85  void add(const geom::CoordinateSequence *ring);
86 
87  // TODO: deprecate
88  geom::Coordinate* getCentroid() const;
89 
91  bool getCentroid(geom::Coordinate& ret) const;
92 
93 private:
94 
96  geom::Coordinate basePt;
97 
98  // temporary variable to hold centroid of triangle
99  geom::Coordinate triangleCent3;
100 
102  double areasum2;
103 
105  geom::Coordinate cg3;
106 
107  // data for linear centroid computation, if needed
108  geom::Coordinate centSum;
109  double totalLength;
110 
111  void setBasePoint(const geom::Coordinate &newbasePt);
112 
113  void add(const geom::Polygon *poly);
114 
115  void addShell(const geom::CoordinateSequence *pts);
116 
117  void addHole(const geom::CoordinateSequence *pts);
118 
119  void addTriangle(const geom::Coordinate &p0, const geom::Coordinate &p1,
120  const geom::Coordinate &p2,bool isPositiveArea);
121 
122  static void centroid3(const geom::Coordinate &p1, const geom::Coordinate &p2,
123  const geom::Coordinate &p3, geom::Coordinate &c);
124 
125  static double area2(const geom::Coordinate &p1, const geom::Coordinate &p2,
126  const geom::Coordinate &p3);
127 
137  void addLinearSegments(const geom::CoordinateSequence& pts);
138 
139 };
140 
141 } // namespace geos::algorithm
142 } // namespace geos
143 
144 
145 #endif // GEOS_ALGORITHM_CENTROIDAREA_H