From c5c07332c8262e81e44993b03fae49c6cf83115c Mon Sep 17 00:00:00 2001 From: Martin Davis Date: Tue, 12 Sep 2023 11:39:14 -0700 Subject: [PATCH] Add SnapToGrid test case --- src/geom/PrecisionModel.cpp | 4 ++++ src/operation/overlayng/OverlayLabeller.cpp | 2 ++ tests/unit/capi/GEOSGeom_setPrecisionTest.cpp | 12 +++++++++++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/geom/PrecisionModel.cpp b/src/geom/PrecisionModel.cpp index 71af03a2e0..23bf41ad4b 100644 --- a/src/geom/PrecisionModel.cpp +++ b/src/geom/PrecisionModel.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #ifndef GEOS_DEBUG #define GEOS_DEBUG 0 @@ -50,6 +51,7 @@ PrecisionModel::makePrecise(double val) const std::cerr << "PrecisionModel[" << this << "]::makePrecise called" << std::endl; #endif +//std::cout << std::setprecision(17) << val << " ==> "; if(modelType == FLOATING_SINGLE) { float floatSingleVal = static_cast(val); return static_cast(floatSingleVal); @@ -59,6 +61,8 @@ PrecisionModel::makePrecise(double val) const return util::round(val / gridSize) * gridSize; } else { +// double v2 = util::round(val * scale) / scale; +//std::cout << std::setprecision(17) << v2 << std::endl; return util::round(val * scale) / scale; } } diff --git a/src/operation/overlayng/OverlayLabeller.cpp b/src/operation/overlayng/OverlayLabeller.cpp index 478f26e7ed..f9c708d8d9 100644 --- a/src/operation/overlayng/OverlayLabeller.cpp +++ b/src/operation/overlayng/OverlayLabeller.cpp @@ -23,6 +23,7 @@ #include #include +#include namespace geos { // geos @@ -331,6 +332,7 @@ OverlayLabeller::markResultAreaEdges(int overlayOpCode) void OverlayLabeller::markInResultArea(OverlayEdge* e, int overlayOpCode) { +std::cout << std::setprecision(16) << *e << std::endl; const OverlayLabel* label = e->getLabel(); if (label->isBoundaryEither() && OverlayNG::isResultOfOp(overlayOpCode, label->getLocationBoundaryOrLine(0, Position::RIGHT, e->isForward()), diff --git a/tests/unit/capi/GEOSGeom_setPrecisionTest.cpp b/tests/unit/capi/GEOSGeom_setPrecisionTest.cpp index efa4b06c50..8588642dc8 100644 --- a/tests/unit/capi/GEOSGeom_setPrecisionTest.cpp +++ b/tests/unit/capi/GEOSGeom_setPrecisionTest.cpp @@ -238,7 +238,17 @@ void object::test<15>() "LINESTRING (674169.89 198051.38, 674197.7 198065.55, 674200.36 198052.38)"); } - +// see https://trac.osgeo.org/postgis/ticket/3929 +template<> +template<> +void object::test<16>() +{ + geom1_ = fromWKT("POINT(311.4 0)"); + geom2_ = GEOSGeom_setPrecision(geom1_, .1, 0); +//std::cout << toWKT(geom2_) << std::endl; + ensure_geometry_equals(geom2_, + "POINT(311.4 0)"); +} } // namespace tut