Skip to content

Commit

Permalink
CircularArcIntersector: Add tests with nearly-degenerate arcs
Browse files Browse the repository at this point in the history
  • Loading branch information
dbaston committed Oct 3, 2024
1 parent 828fc46 commit 9910456
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion include/geos/geom/CircularArc.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class GEOS_DLL CircularArc {

/// Returns whether this arc forms a straight line (p0, p1, and p2 are collinear)
bool isLinear() const {
return std::isnan(getRadius());
return !std::isfinite(getRadius());
}

/// Return the inner angle of the sector associated with this arc
Expand Down
39 changes: 39 additions & 0 deletions tests/unit/algorithm/CircularArcIntersectorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -464,4 +464,43 @@ void object::test<35>()
{0, 0});
}

template<>
template<>
void object::test<36>()
{
set_test_name("intersection between a segment and a degenerate arc (radius = Infinity)");

checkIntersection({-5, -5}, {0, 0}, {5, 5 + 1e-14},
{-5, 5}, {5, -5},
CircularArcIntersector::ONE_POINT_INTERSECTION,
CoordinateXY{0, 0});
}

template<>
template<>
void object::test<37>()
{
set_test_name("intersection between a segment and a nearly-degenerate arc (radius ~= 1e5)");

checkIntersection({-5, -5}, {0, 0}, {5, 5 + 1e-4},
{-5, 5}, {5, -5},
CircularArcIntersector::ONE_POINT_INTERSECTION,
CoordinateXY{0, 0});
}

#if 0
// failed assertion: Values are not equal: expected `POINT (0 0)` actual `POINT (-5.4568517953157425e-06 5.4568517953157425e-06)`
template<>
template<>
void object::test<38>()
{
set_test_name("intersection between a segment and a nearly-degenerate arc (radius ~= 2e6)");

checkIntersection({-5, -5}, {0, 0}, {5, 5 + 1e-9},
{-5, 5}, {5, -5},
CircularArcIntersector::ONE_POINT_INTERSECTION,
CoordinateXY{0, 0});
}
#endif

}

0 comments on commit 9910456

Please sign in to comment.