Centroid.h
/**********************************************************************
*
* GEOS - Geometry Engine Open Source
* http://geos.osgeo.org
*
* Copyright (C) 2013 Sandro Santilli <strk@kbt.io>
*
* This is free software; you can redistribute and/or modify it under
* the terms of the GNU Lesser General Public Licence as published
* by the Free Software Foundation.
* See the COPYING file for more information.
*
**********************************************************************
*
* Last port: algorithm/Centroid.java r728 (JTS-0.13+)
*
**********************************************************************/
#pragma once
#include <geos/export.h>
#include <geos/geom/Coordinate.h> // for composition
#include <memory> // for std::unique_ptr
// Forward declarations
namespace geos {
namespace geom {
class Geometry;
class Polygon;
class CoordinateSequence;
}
}
namespace geos {
namespace algorithm { // geos::algorithm
class GEOS_DLL Centroid {
public:
static bool getCentroid(const geom::Geometry& geom, geom::CoordinateXY& cent);
Centroid(const geom::Geometry& geom)
:
areasum2(0.0),
totalLength(0.0),
ptCount(0)
{
add(geom);
}
bool getCentroid(geom::CoordinateXY& cent) const;
private:
std::unique_ptr<geom::CoordinateXY> areaBasePt;
geom::CoordinateXY triangleCent3;
geom::CoordinateXY cg3;
geom::CoordinateXY lineCentSum;
geom::CoordinateXY ptCentSum;
double areasum2;
double totalLength;
int ptCount;
void add(const geom::Geometry& geom);
void setAreaBasePoint(const geom::CoordinateXY& basePt);
void add(const geom::Polygon& poly);
void addShell(const geom::CoordinateSequence& pts);
void addHole(const geom::CoordinateSequence& pts);
void addTriangle(const geom::CoordinateXY& p0, const geom::CoordinateXY& p1, const geom::CoordinateXY& p2,
bool isPositiveArea);
static void centroid3(const geom::CoordinateXY& p1, const geom::CoordinateXY& p2, const geom::CoordinateXY& p3,
geom::CoordinateXY& c);
static double area2(const geom::CoordinateXY& p1, const geom::CoordinateXY& p2, const geom::CoordinateXY& p3);
void addLineSegments(const geom::CoordinateSequence& pts);
void addPoint(const geom::CoordinateXY& pt);
};
} // namespace geos::algorithm
} // namespace geos
geos::algorithm::Centroid::Centroid
Centroid(const geom::Geometry &geom)
Creates a new instance for computing the centroid of a geometry.
Definition Centroid.h:78
geos::algorithm::Centroid::getCentroid
static bool getCentroid(const geom::Geometry &geom, geom::CoordinateXY &cent)
Computes the centroid point of a geometry.
geos::algorithm::Centroid::getCentroid
bool getCentroid(geom::CoordinateXY &cent) const
Gets the computed centroid.
geos::geom::CoordinateSequence
The internal representation of a list of coordinates inside a Geometry.
Definition CoordinateSequence.h:56
geos::geom::Geometry
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition Geometry.h:196
geos::geom::Polygon
Represents a linear polygon, which may include holes.
Definition Polygon.h:61
geos::algorithm
Contains classes and interfaces implementing fundamental computational geometry algorithms.
Definition Angle.h:32
geos::geom
Definition Angle.h:26
geos
Basic namespace for all GEOS functionalities.
Definition geos.h:38