# CentroidArea.h

    00001 /**********************************************************************
    00002  * $Id: CentroidArea.h 1820 2006-09-06 16:54:23Z mloskot $
    00003  *
    00004  * GEOS - Geometry Engine Open Source
    00005  * http://geos.refractions.net
    00006  *
    00007  * Copyright (C) 2005-2006 Refractions Research Inc.
    00008  * Copyright (C) 2001-2002 Vivid Solutions Inc.
    00009  *
    00010  * This is free software; you can redistribute and/or modify it under
    00011  * the terms of the GNU Lesser General Public Licence as published
    00012  * by the Free Software Foundation.
    00013  * See the COPYING file for more information.
    00014  *
    00015  **********************************************************************/
    00016
    00017 #ifndef GEOS_ALGORITHM_CENTROIDAREA_H
    00018 #define GEOS_ALGORITHM_CENTROIDAREA_H
    00019
    00020
    00021 #include <geos/geom/Coordinate.h>
    00022
    00023 // Forward declarations
    00024 namespace geos {
    00025         namespace geom {
    00026                 class CoordinateSequence;
    00027                 class Geometry;
    00028                 class Polygon;
    00029         }
    00030 }
    00031
    00032 namespace geos {
    00033 namespace algorithm { // geos::algorithm
    00034
    00049 class CentroidArea {
    00050
    00051 public:
    00052
    00053         CentroidArea()
    00054                 :
    00055                 basePt(0.0, 0.0),
    00056                 areasum2(0)
    00057         {}
    00058
    00059         ~CentroidArea() {}
    00060
    00067         void add(const geom::Geometry *geom);
    00068
    00075         void add(const geom::CoordinateSequence *ring);
    00076
    00077         geom::Coordinate* getCentroid() const;
    00078
    00080         bool getCentroid(geom::Coordinate& ret) const;
    00081
    00082 private:
    00083
    00085         geom::Coordinate basePt;
    00086
    00087         // temporary variable to hold centroid of triangle
    00088         geom::Coordinate triangleCent3;
    00089
    00091         double areasum2;
    00092
    00094         geom::Coordinate cg3;
    00095
    00096         void setBasePoint(const geom::Coordinate &newbasePt);
    00097
    00098         void add(const geom::Polygon *poly);
    00099
    00100         void addShell(const geom::CoordinateSequence *pts);
    00101
    00102         void addHole(const geom::CoordinateSequence *pts);
    00103
    00104         void addTriangle(const geom::Coordinate &p0, const geom::Coordinate &p1,
    00105                         const geom::Coordinate &p2,bool isPositiveArea);
    00106
    00107         static void centroid3(const geom::Coordinate &p1, const geom::Coordinate &p2,
    00108                         const geom::Coordinate &p3, geom::Coordinate &c);
    00109
    00110         static double area2(const geom::Coordinate &p1, const geom::Coordinate &p2,
    00111                         const geom::Coordinate &p3);
    00112
    00113 };
    00114
    00115 } // namespace geos::algorithm
    00116 } // namespace geos
    00117
    00118
    00119 #endif // GEOS_ALGORITHM_CENTROIDAREA_H
    00120
    00121 /**********************************************************************
    00122  * $Log$
    00123  * Revision 1.1  2006/03/09 16:46:48  strk
    00124  * geos::geom namespace definition, first pass at headers split
    00125  *
    00126  **********************************************************************/
    00127