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 3, 2024
1 parent 9ae407d commit f0d53cc
Show file tree
Hide file tree
Showing 28 changed files with 772 additions and 115 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
12 changes: 12 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,17 @@ class GEOS_DLL CircularString : public SimpleCurve {
return SORTINDEX_LINESTRING;
};

const Envelope* getEnvelopeInternal() const override {
throw util::UnsupportedOperationException();
}

double getLength() const override {
throw util::UnsupportedOperationException();
}

protected:
Envelope computeEnvelopeInternal() const override;

};


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 @@ -67,7 +64,7 @@ class GEOS_DLL CompoundCurve : public Curve {

const Envelope* getEnvelopeInternal() const override
{
return &envelope;
throw util::UnsupportedOperationException();
}

std::unique_ptr<CompoundCurve> clone() const;
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 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
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
2 changes: 2 additions & 0 deletions include/geos/geom/LineString.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ class GEOS_DLL LineString: public SimpleCurve {

LineString* reverseImpl() const override;

Envelope computeEnvelopeInternal() const override;

int
getSortIndex() const override
{
Expand Down
15 changes: 5 additions & 10 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 All @@ -135,7 +130,7 @@ class GEOS_DLL SimpleCurve : public Curve {
SimpleCurve(std::unique_ptr<CoordinateSequence>&& newCoords,
const GeometryFactory& factory);

Envelope computeEnvelopeInternal() const;
virtual Envelope computeEnvelopeInternal() const = 0;

void geometryChangedAction() override
{
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
12 changes: 12 additions & 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 Expand Up @@ -53,5 +54,16 @@ CircularString::reverseImpl() const
return getFactory()->createCircularString(std::move(seq)).release();
}

Envelope
CircularString::computeEnvelopeInternal() const
{
if(isEmpty()) {
return Envelope();
}

throw util::UnsupportedOperationException();
}


}
}
Loading

0 comments on commit f0d53cc

Please sign in to comment.