MinimumDiameter.h
/**********************************************************************
*
* GEOS - Geometry Engine Open Source
* http://geos.osgeo.org
*
* Copyright (C) 2023 Paul Ramsey <pramsey@cleverelephant.ca>
* Copyright (C) 2005-2006 Refractions Research Inc.
* Copyright (C) 2001-2002 Vivid Solutions Inc.
*
* 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.
*
**********************************************************************/
#pragma once
#include <geos/geom/Coordinate.h>
#include <geos/geom/LineSegment.h>
#include <memory>
#include <geos/export.h>
// Forward declarations
namespace geos {
namespace geom {
class GeometryFactory;
class Geometry;
class LineString;
class CoordinateSequence;
}
}
namespace geos {
namespace algorithm { // geos::algorithm
class GEOS_DLL MinimumDiameter {
private:
const geom::Geometry* inputGeom;
bool isConvex;
std::unique_ptr<geom::CoordinateSequence> convexHullPts;
geom::LineSegment minBaseSeg;
geom::Coordinate minWidthPt;
std::size_t minPtIndex;
double minWidth;
void computeMinimumDiameter();
void computeWidthConvex(const geom::Geometry* geom);
void computeConvexRingMinDiameter(const geom::CoordinateSequence* pts);
unsigned int findMaxPerpDistance(const geom::CoordinateSequence* pts,
const geom::LineSegment* seg, unsigned int startIndex);
static unsigned int getNextIndex(const geom::CoordinateSequence* pts,
unsigned int index);
static double computeC(double a, double b, const geom::Coordinate& p);
static geom::LineSegment computeSegmentForLine(double a, double b, double c);
static std::unique_ptr<geom::Geometry> computeMaximumLine(
const geom::CoordinateSequence* pts,
const geom::GeometryFactory* factory);
public:
~MinimumDiameter() = default;
MinimumDiameter(const geom::Geometry* newInputGeom);
MinimumDiameter(const geom::Geometry* newInputGeom,
const bool newIsConvex);
double getLength();
const geom::Coordinate& getWidthCoordinate();
std::unique_ptr<geom::LineString> getSupportingSegment();
std::unique_ptr<geom::LineString> getDiameter();
std::unique_ptr<geom::Geometry> getMinimumRectangle();
static std::unique_ptr<geom::Geometry> getMinimumRectangle(geom::Geometry* geom);
static std::unique_ptr<geom::Geometry> getMinimumDiameter(geom::Geometry* geom);
};
} // namespace geos::algorithm
} // namespace geos
geos::algorithm::MinimumDiameter::getWidthCoordinate
const geom::Coordinate & getWidthCoordinate()
Gets the geom::Coordinate forming one end of the minimum diameter.
geos::algorithm::MinimumDiameter::getMinimumRectangle
static std::unique_ptr< geom::Geometry > getMinimumRectangle(geom::Geometry *geom)
Gets the minimum rectangle enclosing a geometry.
geos::algorithm::MinimumDiameter::getDiameter
std::unique_ptr< geom::LineString > getDiameter()
Gets a LineString which is a minimum diameter.
geos::algorithm::MinimumDiameter::getMinimumDiameter
static std::unique_ptr< geom::Geometry > getMinimumDiameter(geom::Geometry *geom)
Gets the length of the minimum diameter enclosing a geometry.
geos::algorithm::MinimumDiameter::getMinimumRectangle
std::unique_ptr< geom::Geometry > getMinimumRectangle()
Gets the rectangular Polygon which encloses the input geometry and is based on the minimum diameter s...
geos::algorithm::MinimumDiameter::getLength
double getLength()
Gets the length of the minimum diameter of the input Geometry.
geos::algorithm::MinimumDiameter::MinimumDiameter
MinimumDiameter(const geom::Geometry *newInputGeom)
Compute a minimum diameter for a given Geometry.
geos::algorithm::MinimumDiameter::MinimumDiameter
MinimumDiameter(const geom::Geometry *newInputGeom, const bool newIsConvex)
Compute a minimum diameter for a given Geometry, with a hint if the Geometry is convex (e....
geos::algorithm::MinimumDiameter::getSupportingSegment
std::unique_ptr< geom::LineString > getSupportingSegment()
Gets the segment forming the base of the minimum diameter.
geos::geom::CoordinateSequence
The internal representation of a list of coordinates inside a Geometry.
Definition CoordinateSequence.h:56
geos::geom::Coordinate
Coordinate is the lightweight class used to store coordinates.
Definition Coordinate.h:217
geos::geom::GeometryFactory
Supplies a set of utility methods for building Geometry objects from CoordinateSequence or other Geom...
Definition GeometryFactory.h:70
geos::geom::Geometry
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition Geometry.h:196
geos::geom::LineSegment
Definition LineSegment.h:61
geos::geom::LineString
Definition LineString.h:66
geos::algorithm
Contains classes and interfaces implementing fundamental computational geometry algorithms.
Definition Angle.h:32
geos::geom
Definition Angle.h:26
geos::index
Provides classes for various kinds of spatial indexes.
Definition CleanCoverage.h:39
geos
Basic namespace for all GEOS functionalities.
Definition geos.h:38