Skip to content

Commit

Permalink
Add tests for curved geometry types
Browse files Browse the repository at this point in the history
  • Loading branch information
dbaston committed Mar 25, 2024
1 parent ccedb1d commit 4fc18f5
Show file tree
Hide file tree
Showing 36 changed files with 1,294 additions and 154 deletions.
6 changes: 5 additions & 1 deletion include/geos/algorithm/ConvexHull.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#include <geos/util/UniqueCoordinateArrayFilter.h>
#include <geos/util/CoordinateArrayFilter.h>

#include "geos/util.h"

#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
Expand Down Expand Up @@ -178,7 +180,9 @@ class GEOS_DLL ConvexHull {
ConvexHull(const geom::Geometry* newGeometry)
: inputGeom(newGeometry)
, geomFactory(newGeometry->getFactory())
{};
{
util::ensureNotCurvedType(inputGeom);
};

~ConvexHull() {};

Expand Down
5 changes: 5 additions & 0 deletions include/geos/geom/CircularString.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#pragma once

#include <geos/geom/SimpleCurve.h>
#include <geos/util/UnsupportedOperationException.h>

namespace geos {
namespace geom {
Expand Down Expand Up @@ -47,6 +48,10 @@ class GEOS_DLL CircularString : public SimpleCurve {
return SORTINDEX_LINESTRING;
};

double getLength() const override {
throw util::UnsupportedOperationException("Cannot calculate length of CircularString");
}

};


Expand Down
20 changes: 7 additions & 13 deletions include/geos/geom/CompoundCurve.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#pragma once

#include <geos/geom/SimpleCurve.h>
#include <geos/util.h>
#include <vector>

namespace geos {
Expand Down Expand Up @@ -48,10 +49,6 @@ class GEOS_DLL CompoundCurve : public Curve {

const SimpleCurve* getCurveN(std::size_t) const;

std::size_t getNumGeometries() const override;

const Geometry* getGeometryN(std::size_t) const override;

std::size_t getNumPoints() const override;

std::unique_ptr<Geometry> getBoundary() const override;
Expand All @@ -78,17 +75,14 @@ class GEOS_DLL CompoundCurve : public Curve {

CompoundCurve* reverseImpl() const override;

void apply_rw(const CoordinateFilter* filter) override;

void apply_ro(CoordinateFilter* filter) const override;

void apply_rw(GeometryFilter* filter) override;
double getLength() const override;

void apply_ro(GeometryFilter* filter) const override;
using Curve::apply_ro;
using Curve::apply_rw;

void apply_rw(GeometryComponentFilter* filter) override;
void apply_rw(const CoordinateFilter* filter) override;

void apply_ro(GeometryComponentFilter* filter) const override;
void apply_ro(CoordinateFilter* filter) const override;

void apply_rw(CoordinateSequenceFilter& filter) override;

Expand All @@ -113,7 +107,7 @@ class GEOS_DLL CompoundCurve : public Curve {
envelope = computeEnvelopeInternal();
}

Envelope computeEnvelopeInternal();
Envelope computeEnvelopeInternal() const;

private:
std::vector<std::unique_ptr<SimpleCurve>> curves;
Expand Down
11 changes: 11 additions & 0 deletions include/geos/geom/Curve.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ class GEOS_DLL Curve : public Geometry {

virtual bool isClosed() const = 0;

using Geometry::apply_ro;
using Geometry::apply_rw;

void apply_rw(GeometryFilter* filter) override;

void apply_ro(GeometryFilter* filter) const override;

void apply_rw(GeometryComponentFilter* filter) override;

void apply_ro(GeometryComponentFilter* filter) const override;

protected:

Curve(const GeometryFactory& factory) : Geometry(&factory) {}
Expand Down
2 changes: 2 additions & 0 deletions include/geos/geom/CurvePolygon.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ class GEOS_DLL CurvePolygon : public SurfaceImpl<Curve> {

void normalize() override;

double getArea() const override;

protected:
using SurfaceImpl::SurfaceImpl;

Expand Down
5 changes: 5 additions & 0 deletions include/geos/geom/Geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,11 @@ class GEOS_DLL Geometry {
/// Return a string representation of this Geometry type
virtual std::string getGeometryType() const = 0; //Abstract

/// Returns whether the Geometry type _may_ contain curved elements
virtual bool isCurvedType() const;

static bool isCurvedType(GeometryTypeId);

/// Return an integer representation of this Geometry type
virtual GeometryTypeId getGeometryTypeId() const = 0; //Abstract

Expand Down
3 changes: 0 additions & 3 deletions include/geos/geom/Polygon.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,6 @@ class GEOS_DLL Polygon: public SurfaceImpl<LinearRing> {

double getArea() const override;

/// Returns the perimeter of this <code>Polygon</code>
double getLength() const override;

bool isRectangle() const override;

/**
Expand Down
13 changes: 4 additions & 9 deletions include/geos/geom/SimpleCurve.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class GEOS_DLL SimpleCurve : public Curve {

bool isRing() const;

virtual bool isCoordinate(Coordinate& pt) const;
virtual bool isCoordinate(CoordinateXY& pt) const;

bool equalsExact(const Geometry* other, double tolerance = 0)
const override;
Expand All @@ -99,18 +99,13 @@ class GEOS_DLL SimpleCurve : public Curve {
return &envelope;
}

using Curve::apply_ro;
using Curve::apply_rw;

void apply_rw(const CoordinateFilter* filter) override;

void apply_ro(CoordinateFilter* filter) const override;

void apply_rw(GeometryFilter* filter) override;

void apply_ro(GeometryFilter* filter) const override;

void apply_rw(GeometryComponentFilter* filter) override;

void apply_ro(GeometryComponentFilter* filter) const override;

void apply_rw(CoordinateSequenceFilter& filter) override;

void apply_ro(CoordinateSequenceFilter& filter) const override;
Expand Down
5 changes: 4 additions & 1 deletion include/geos/geom/Surface.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class GEOS_DLL Surface : public Geometry {


bool
equalsExact(const Geometry* other, double tolerance) const override;
equalsExact(const Geometry* other, double tolerance = 0.0) const override;

bool
equalsIdentical(const Geometry* other) const override;
Expand Down Expand Up @@ -75,6 +75,9 @@ class GEOS_DLL Surface : public Geometry {

bool isEmpty() const override;

/// Returns the perimeter of this Surface
double getLength() const override;

void
apply_ro(CoordinateFilter* filter) const override;

Expand Down
11 changes: 5 additions & 6 deletions include/geos/geom/SurfaceImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ class SurfaceImpl : public Surface {

/**
* \brief
* Take ownership of this Polygon's exterior ring.
* After releasing the exterior ring, the Polygon should be
* Take ownership of this Surface's exterior ring.
* After releasing the exterior ring, the Surface should be
* considered in a moved-from state and should not be accessed,
* except to release the interior rings (if desired.)
* @return exterior ring
Expand Down Expand Up @@ -139,14 +139,13 @@ class SurfaceImpl : public Surface {

/**
* \brief
* Take ownership of this Polygon's interior rings.
* After releasing the rings, the Polygon should be
* Take ownership of this Surfaces's interior rings.
* After releasing the rings, the Surface should be
* considered in a moved-from state and should not be accessed,
* except to release the exterior ring (if desired.)
* @return vector of rings (may be empty)
*/
std::vector<std::unique_ptr<RingType>>
releaseInteriorRings()
std::vector<std::unique_ptr<RingType>> releaseInteriorRings()
{
return std::move(holes);
}
Expand Down
4 changes: 4 additions & 0 deletions include/geos/operation/union/UnaryUnionOp.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#include <geos/geom/util/GeometryExtracter.h>
#include <geos/operation/union/CascadedPolygonUnion.h>

#include <geos/util.h>

#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
Expand Down Expand Up @@ -169,6 +171,8 @@ class GEOS_DLL UnaryUnionOp {
void
extract(const geom::Geometry& geom)
{
util::ensureNotCurvedType(geom);

using namespace geom::util;

if(! geomFact) {
Expand Down
23 changes: 23 additions & 0 deletions include/geos/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <cassert>
#include <memory>
#include <type_traits>
#include <geos/util/UnsupportedOperationException.h>

//
// Private macros definition
Expand Down Expand Up @@ -59,6 +60,28 @@ template<typename To, typename From> inline To down_cast(From* f)
}

} // namespace detail

namespace util {

template<typename T>
void ensureNotCurvedType(const T* geom)
{
if (geom->isCurvedType()) {
throw UnsupportedOperationException("Curved geometry types are not supported.");
}
}

template<typename T>
void ensureNotCurvedType(const T& geom)
{
if (geom.isCurvedType()) {
throw UnsupportedOperationException("Curved geometry types are not supported.");
}
}

}


} // namespace geos

#endif // GEOS_UTIL_H
4 changes: 4 additions & 0 deletions src/algorithm/Centroid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

#include <cmath> // for std::abs

#include "geos/util.h"

using namespace geos::geom;

namespace geos {
Expand Down Expand Up @@ -68,6 +70,8 @@ Centroid::getCentroid(CoordinateXY& cent) const
void
Centroid::add(const Geometry& geom)
{
util::ensureNotCurvedType(geom);

if(geom.isEmpty()) {
return;
}
Expand Down
1 change: 1 addition & 0 deletions src/geom/CircularString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <geos/geom/CircularString.h>
#include <geos/geom/CoordinateSequence.h>
#include <geos/geom/GeometryFactory.h>
#include <geos/util/UnsupportedOperationException.h>

namespace geos {
namespace geom {
Expand Down
Loading

0 comments on commit 4fc18f5

Please sign in to comment.