Skip to content

Commit

Permalink
Unit test and fix for dateline clipping case reported by @roualt
Browse files Browse the repository at this point in the history
  • Loading branch information
pramsey committed Sep 17, 2020
1 parent 1bb0721 commit 49ac5aa
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 2 deletions.
8 changes: 8 additions & 0 deletions include/geos/geom/Geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,14 @@ class GEOS_DLL Geometry {
return isDimensionStrict(Dimension::A);
}

bool isCollection() const {
int t = getGeometryTypeId();
return t == GEOS_GEOMETRYCOLLECTION ||
t == GEOS_MULTIPOINT ||
t == GEOS_MULTILINESTRING ||
t == GEOS_MULTIPOLYGON;
}

/// Returns the coordinate dimension of this Geometry (2=XY, 3=XYZ, 4=XYZM in future).
virtual int getCoordinateDimension() const = 0; //Abstract

Expand Down
4 changes: 3 additions & 1 deletion src/operation/overlayng/OverlayNG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,12 @@ OverlayNG::computeEdgeOverlay()
* Edge* list allocated in the EdgeNodingBuilder survives
* long enough to be copied into the OverlayGraph
*/
// XXX sort the edges first
// Sort the edges first, for comparison with JTS results
// std::sort(edges.begin(), edges.end(), EdgeComparator);
OverlayGraph graph;
for (Edge* e : edges) {
// Write out edge graph as hex for examination
// std::cout << *e << std::endl;
graph.addEdge(e);
}

Expand Down
2 changes: 1 addition & 1 deletion src/operation/overlayng/RobustClipEnvelopeComputer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ RobustClipEnvelopeComputer::add(const Geometry* g)

if (g->getGeometryTypeId() == GEOS_POLYGON)
addPolygon(static_cast<const Polygon*>(g));
else if (g->getGeometryTypeId() == GEOS_GEOMETRYCOLLECTION)
else if (g->isCollection())
addCollection(static_cast<const GeometryCollection*>(g));
}

Expand Down
1 change: 1 addition & 0 deletions tests/unit/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ geos_unit_SOURCES = \
operation/overlayng/OverlayNGFloatingNoderTest.cpp \
operation/overlayng/OverlayNGPointsTest.cpp \
operation/overlayng/OverlayNGMixedPointsTest.cpp \
operation/overlayng/OverlayNGRobustTest.cpp \
operation/overlayng/OverlayNGSnappingNoderTest.cpp \
operation/overlayng/OverlayNGSnappingOneTest.cpp \
operation/overlayng/OverlayNGTest.cpp \
Expand Down
65 changes: 65 additions & 0 deletions tests/unit/operation/overlayng/OverlayNGRobustTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
//
// Test Suite for geos::operation::overlayng::OverlayNG class.

#include <tut/tut.hpp>
#include <utility.h>

// geos
#include <geos/operation/overlayng/OverlayNGRobust.h>

// std
#include <memory>

using namespace geos::geom;
using namespace geos::operation::overlayng;
using geos::io::WKTReader;
using geos::io::WKTWriter;

namespace tut {
//
// Test Group
//

// Common data used by all tests
struct test_overlayngrobust_data {

WKTReader r;
WKTWriter w;

void
testOverlay(const std::string& a, const std::string& b, const std::string& expected, int opCode)
{
std::unique_ptr<Geometry> geom_a = r.read(a);
std::unique_ptr<Geometry> geom_b = r.read(b);
std::unique_ptr<Geometry> geom_expected = r.read(expected);
std::unique_ptr<Geometry> geom_result = OverlayNGRobust::Overlay(geom_a.get(), geom_b.get(), opCode);
// std::string wkt_result = w.write(geom_result.get());
// std::cout << std::endl << wkt_result << std::endl;
ensure_equals_geometry(geom_expected.get(), geom_result.get());
}

};

typedef test_group<test_overlayngrobust_data> group;
typedef group::object object;

group test_overlayngrobust_data("geos::operation::overlayng::OverlayNGRobust");

//
// Test Cases
//

// Square overlapping square
template<>
template<>
void object::test<1> ()
{
std::string a = "LINESTRING(832864.275023695 0,835092.849076364 0)";
std::string b = "MULTIPOLYGON (((832864.275023695 0.0,833978.556808034 -0.000110682755987,833978.556808034 0.0,833978.556808034 0.000110682755987,832864.275023695 0.0,832864.275023695 0.0)),((835092.849076364 0.0,833978.557030887 -0.000110682755987,833978.557030887 0.0,833978.557030887 0.000110682755987,835092.849076364 0.0,835092.849076364 0.0)))";
std::string exp = "MULTILINESTRING ((832864.275023695 0.0,833978.556808034 0.0),(833978.557030887 0.0,835092.849076364 0.0))";
testOverlay(a, b, exp, OverlayNG::INTERSECTION);
}



} // namespace tut

0 comments on commit 49ac5aa

Please sign in to comment.