27#include <boost/test/data/test_case.hpp>
42bool SegCollideCorrect(
const SEG& aSegA,
const SEG& aSegB,
int aClearance,
bool aExp )
44 const bool AtoB = aSegA.
Collide( aSegB, aClearance );
45 const bool BtoA = aSegB.
Collide( aSegA, aClearance );
47 const bool ok = ( AtoB == aExp ) && ( BtoA == aExp );
52 ss <<
"Segment collision is not the same in both directions: expected " << aExp <<
", got "
53 << AtoB <<
" & " << BtoA;
54 BOOST_TEST_INFO( ss.str() );
59 ss <<
"Collision incorrect: expected " << aExp <<
", got " << AtoB;
60 BOOST_TEST_INFO( ss.str() );
74bool SegDistanceCorrect(
const SEG& aSegA,
const SEG& aSegB,
int aExp )
76 const int AtoB = aSegA.
Distance( aSegB );
77 const int BtoA = aSegB.
Distance( aSegA );
79 bool ok = ( AtoB == aExp ) && ( BtoA == aExp );
84 ss <<
"Segment distance is not the same in both directions: expected " << aExp <<
", got "
85 << AtoB <<
" & " << BtoA;
86 BOOST_TEST_INFO( ss.str() );
91 ss <<
"Distance incorrect: expected " << aExp <<
", got " << AtoB;
92 BOOST_TEST_INFO( ss.str() );
96 ok = ok && SegCollideCorrect( aSegA, aSegB, 0, aExp == 0 );
108bool SegVecDistanceCorrect(
const SEG& aSeg,
const VECTOR2I& aVec,
int aExp )
113 const int dist = aSeg.
Distance( aVec );
115 bool ok = ( dist == aExp );
119 std::stringstream ss;
120 ss <<
"Distance incorrect: expected " << aExp <<
", got " << dist;
121 BOOST_TEST_INFO( ss.str() );
134bool SegCollinearCorrect(
const SEG& aSegA,
const SEG& aSegB,
bool aExp )
136 const bool AtoB = aSegA.
Collinear( aSegB );
137 const bool BtoA = aSegB.
Collinear( aSegA );
139 const bool ok = ( AtoB == aExp ) && ( BtoA == aExp );
143 std::stringstream ss;
144 ss <<
"Segment collinearity is not the same in both directions: expected " << aExp
145 <<
", got " << AtoB <<
" & " << BtoA;
146 BOOST_TEST_INFO( ss.str() );
150 std::stringstream ss;
151 ss <<
"Collinearity incorrect: expected " << aExp <<
", got " << AtoB;
152 BOOST_TEST_INFO( ss.str() );
166bool SegParallelCorrect(
const SEG& aSegA,
const SEG& aSegB,
bool aExp )
171 const bool ok = ( AtoB == aExp ) && ( BtoA == aExp );
175 std::stringstream ss;
176 ss <<
"Segment parallelism is not the same in both directions: expected " << aExp
177 <<
", got AtoB: " << AtoB <<
" BtoA:" << BtoA;
178 BOOST_TEST_INFO( ss.str() );
182 std::stringstream ss;
183 ss <<
"Parallelism incorrect: expected " << aExp <<
", got " << AtoB;
184 BOOST_TEST_INFO( ss.str() );
198bool SegPerpendicularCorrect(
const SEG& aSegA,
const SEG& aSegB,
bool aExp )
203 const bool ok = ( AtoB == aExp ) && ( BtoA == aExp );
207 std::stringstream ss;
208 ss <<
"Segment perpendicularity is not the same in both directions: expected " << aExp
209 <<
", got AtoB: " << AtoB <<
" BtoA:" << BtoA;
210 BOOST_TEST_INFO( ss.str() );
214 std::stringstream ss;
215 ss <<
"Perpendicularity incorrect: expected " << aExp <<
", got " << AtoB;
216 BOOST_TEST_INFO( ss.str() );
236 SEG segment( pointA, pointB );
261 "Parallel, 10 apart",
262 { { 0, 0 }, { 10, 0 } },
263 { { 0, 10 }, { 10, 10 } },
267 "Non-parallel, 10 apart",
268 { { 0, -5 }, { 10, 0 } },
269 { { 0, 10 }, { 10, 10 } },
274 { { 0, 0 }, { 30, 0 } },
275 { { 10, 0 }, { 20, 0 } },
280 { { 0, -10 }, { 0, 10 } },
281 { { -20, 0 }, { 20, 0 } },
286 { { 0, -10 }, { 0, 10 } },
287 { { -20, 0 }, { 0, 0 } },
291 "T-junction (no touch)",
292 { { 0, -10 }, { 0, 10 } },
293 { { -20, 0 }, { -2, 0 } },
318 { { 0, 0 }, { 10, 0 } },
324 { { 0, 0 }, { 10, 0 } },
330 { { 0, 0 }, { 10, 0 } },
335 "At end (collinear)",
336 { { 0, 0 }, { 10, 0 } },
341 "At end (not collinear)",
342 { { 0, 0 }, { 1000, 0 } },
347 "Issue 18473 (inside hit with rounding error)",
348 { { 187360000, 42510000 }, { 105796472, 42510000 } },
349 { 106645000, 42510000 },
353 "Straight line x distance",
354 { { 187360000, 42510000 }, { 105796472, 42510000 } },
355 { 197360000, 42510000 },
359 "Straight line -x distance",
360 { { 187360000, 42510000 }, { 105796472, 42510000 } },
361 { 104796472, 42510000 },
390 "Parallel, 10 apart, 5 clear",
391 { { 0, 0 }, { 10, 0 } },
392 { { 0, 10 }, { 10, 10 } },
397 "Parallel, 10 apart, 10 clear",
398 { { 0, 0 }, { 10, 0 } },
399 { { 0, 10 }, { 10, 10 } },
404 "Parallel, 10 apart, 11 clear",
405 { { 0, 0 }, { 10, 0 } },
406 { { 0, 10 }, { 10, 10 } },
411 "T-junction, 2 apart, 2 clear",
412 { { 0, -10 }, { 0, 0 } },
413 { { -20, 0 }, { -2, 0 } },
418 "T-junction, 2 apart, 3 clear",
419 { { 0, -10 }, { 0, 0 } },
420 { { -20, 0 }, { -2, 0 } },
431 ( c.m_seg_a )( c.m_seg_b )( c.m_clearance )( c.m_exp_coll ) );
452 { { 0, 0 }, { 10, 0 } },
453 { { 0, 0 }, { 10, 0 } },
458 { { 0, 0 }, { 10, 0 } },
459 { { 10, 0 }, { 20, 0 } },
464 { { 0, 0 }, { 10, 0 } },
465 { { 4, 0 }, { 7, 0 } },
470 { { 0, 0 }, { 10, 0 } },
471 { { 4, 1 }, { 7, 1 } },
476 { { 0, 0 }, { 10, 0 } },
477 { { 5, -5 }, { 5, 5 } },
497 { { 0, 0 }, { 10, 0 } },
498 { { 0, 0 }, { 10, 0 } },
503 { { 0, 0 }, { 10, 0 } },
504 { { 10, 0 }, { 20, 0 } },
509 { { 0, 0 }, { 10, 0 } },
510 { { 4, 0 }, { 7, 0 } },
515 { { 0, 0 }, { 10, 0 } },
516 { { 4, 1 }, { 7, 1 } },
521 { { 0, 0 }, { 10, 0 } },
522 { { 5, -5 }, { 5, 5 } },
542 { { 0, 0 }, { 10, 0 } },
543 { { 0, 0 }, { 10, 0 } },
548 { { 0, 0 }, { 10, 0 } },
549 { { 10, 0 }, { 20, 0 } },
554 { { 0, 0 }, { 10, 0 } },
555 { { 4, 0 }, { 7, 0 } },
560 { { 0, 0 }, { 10, 0 } },
561 { { 4, 1 }, { 7, 1 } },
566 { { 0, 0 }, { 10, 0 } },
567 { { 0, 0 }, { 5, 5 } },
571 "very nearly perpendicular",
572 { { 0, 0 }, { 10, 0 } },
573 { { 0, 0 }, { 1, 10 } },
577 "not really perpendicular",
578 { { 0, 0 }, { 10, 0 } },
579 { { 0, 0 }, { 3, 10 } },
584 { { 0, 0 }, { 10, 0 } },
585 { { 0, 0 }, { 0, 10 } },
589 "perpendicular not intersecting",
590 { { 0, 0 }, { 10, 0 } },
591 { { 15, 5 }, { 15, 10 } },
621 "Horizontal: point on edge of seg",
622 { { 0, 0 }, { 10, 0 } },
626 "Horizontal: point in middle of seg",
627 { { 0, 0 }, { 10, 0 } },
631 "Horizontal: point outside seg",
632 { { 0, 0 }, { 10, 0 } },
636 "Vertical: point on edge of seg",
637 { { 0, 0 }, { 0, 10 } },
641 "Vertical: point in middle of seg",
642 { { 0, 0 }, { 0, 10 } },
646 "Vertical: point outside seg",
647 { { 0, 0 }, { 0, 10 } },
674 SEG seg( { 0, 0 }, { 10, 0 } );
676 BOOST_TEST( seg.LineDistance( { 5, 0 } ) == 0 );
677 BOOST_TEST( seg.LineDistance( { 5, 8 } ) == 8 );
682 SEG seg( { 0, 0 }, { 10, 0 } );
684 BOOST_TEST( seg.LineDistance( { 5, 8 },
true ) == 8 );
685 BOOST_TEST( seg.LineDistance( { 5, -8 },
true ) == -8 );
ecoord SquaredDistance(const SEG &aSeg) const
VECTOR2I::extended_type ecoord
bool Collide(const SEG &aSeg, int aClearance, int *aActual=nullptr) const
bool ApproxParallel(const SEG &aSeg, int aDistanceThreshold=1) const
bool Collinear(const SEG &aSeg) const
Check if segment aSeg lies on the same line as (this).
SEG ParallelSeg(const VECTOR2I &aP) const
Compute a segment parallel to this one, passing through point aP.
bool ApproxPerpendicular(const SEG &aSeg) const
int Distance(const SEG &aSeg) const
Compute minimum Euclidean distance to segment aSeg.
SEG PerpendicularSeg(const VECTOR2I &aP) const
Compute a segment perpendicular to this one, passing through point aP.
A named data-driven test case.
Struct to hold general cases for collinearity, parallelism and perpendicularity.
Test cases for collisions (with clearance, for no clearance, it's just a SEG_SEG_DISTANCE_CASE of 0)
Struct to hold cases for operations with a SEG, and a VECTOR2I.
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_CHECK_EQUAL(ret, c.m_exp_result)
BOOST_TEST(contains==c.ExpectedContains)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
static const std::vector< SEG_SEG_BOOLEAN_CASE > seg_vec_perpendicular_cases
Test cases for perpendicularity.
BOOST_AUTO_TEST_CASE(EndpointCtorMod)
Checks whether the construction of a segment referencing external points works and that the endpoints...
static const std::vector< SEG_SEG_BOOLEAN_CASE > seg_vec_collinear_cases
Test cases for collinearity.
static const std::vector< SEG_VEC_CASE > segment_and_point_cases
Test cases to create segments passing through a point.
BOOST_DATA_TEST_CASE(SegSegPerpendicular, boost::unit_test::data::make(seg_vec_perpendicular_cases), c)
static const std::vector< SEG_SEG_DISTANCE_CASE > seg_seg_dist_cases
static const std::vector< SEG_VECTOR_DISTANCE_CASE > seg_vec_dist_cases
static const std::vector< SEG_SEG_COLLIDE_CASE > seg_seg_coll_cases
static const std::vector< SEG_SEG_BOOLEAN_CASE > seg_vec_parallel_cases
Test cases for parallelism.
BOOST_CHECK_PREDICATE(ArePolylineEndPointsNearCircle,(chain)(c.m_geom.m_center_point)(radius)(accuracy+epsilon))
VECTOR2< int32_t > VECTOR2I