Skip to content

Commit

Permalink
Add SnapToGrid test case
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-jts committed Sep 12, 2023
1 parent 73be95d commit c5c0733
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/geom/PrecisionModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <string>
#include <cmath>
#include <iostream>
#include <iomanip>

#ifndef GEOS_DEBUG
#define GEOS_DEBUG 0
Expand All @@ -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<float>(val);
return static_cast<double>(floatSingleVal);
Expand All @@ -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;
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/operation/overlayng/OverlayLabeller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <geos/util/TopologyException.h>

#include <sstream>
#include <iomanip>


namespace geos { // geos
Expand Down Expand Up @@ -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()),
Expand Down
12 changes: 11 additions & 1 deletion tests/unit/capi/GEOSGeom_setPrecisionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit c5c0733

Please sign in to comment.