40 const bool AtoB = aSegA.
Collide( aSegB, aClearance );
41 const bool BtoA = aSegB.
Collide( aSegA, aClearance );
43 const bool ok = ( AtoB == aExp ) && ( BtoA == aExp );
48 ss <<
"Segment collision is not the same in both directions: expected " << aExp <<
", got "
49 << AtoB <<
" & " << BtoA;
50 BOOST_TEST_INFO( ss.str() );
55 ss <<
"Collision incorrect: expected " << aExp <<
", got " << AtoB;
56 BOOST_TEST_INFO( ss.str() );
72 const int AtoB = aSegA.
Distance( aSegB );
73 const int BtoA = aSegB.
Distance( aSegA );
75 bool ok = ( AtoB == aExp ) && ( BtoA == aExp );
80 ss <<
"Segment distance is not the same in both directions: expected " << aExp <<
", got "
81 << AtoB <<
" & " << BtoA;
82 BOOST_TEST_INFO( ss.str() );
87 ss <<
"Distance incorrect: expected " << aExp <<
", got " << AtoB;
88 BOOST_TEST_INFO( ss.str() );
107 BOOST_REQUIRE( squaredDistance >= 0 );
109 const int dist = aSeg.
Distance( aVec );
111 bool ok = ( dist == aExp );
115 std::stringstream ss;
116 ss <<
"Distance incorrect: expected " << aExp <<
", got " << dist;
117 BOOST_TEST_INFO( ss.str() );
132 const bool AtoB = aSegA.
Collinear( aSegB );
133 const bool BtoA = aSegB.
Collinear( aSegA );
135 const bool ok = ( AtoB == aExp ) && ( BtoA == aExp );
139 std::stringstream ss;
140 ss <<
"Segment collinearity is not the same in both directions: expected " << aExp
141 <<
", got " << AtoB <<
" & " << BtoA;
142 BOOST_TEST_INFO( ss.str() );
146 std::stringstream ss;
147 ss <<
"Collinearity incorrect: expected " << aExp <<
", got " << AtoB;
148 BOOST_TEST_INFO( ss.str() );
167 const bool ok = ( AtoB == aExp ) && ( BtoA == aExp );
171 std::stringstream ss;
172 ss <<
"Segment parallelism is not the same in both directions: expected " << aExp
173 <<
", got AtoB: " << AtoB <<
" BtoA:" << BtoA;
174 BOOST_TEST_INFO( ss.str() );
178 std::stringstream ss;
179 ss <<
"Parallelism incorrect: expected " << aExp <<
", got " << AtoB;
180 BOOST_TEST_INFO( ss.str() );
199 const bool ok = ( AtoB == aExp ) && ( BtoA == aExp );
203 std::stringstream ss;
204 ss <<
"Segment perpendicularity is not the same in both directions: expected " << aExp
205 <<
", got AtoB: " << AtoB <<
" BtoA:" << BtoA;
206 BOOST_TEST_INFO( ss.str() );
210 std::stringstream ss;
211 ss <<
"Perpendicularity incorrect: expected " << aExp <<
", got " << AtoB;
212 BOOST_TEST_INFO( ss.str() );
230 SEG segment( pointA, pointB );
232 BOOST_CHECK_EQUAL( pointA,
VECTOR2I( 10, 20 ) );
233 BOOST_CHECK_EQUAL( pointB,
VECTOR2I( 100, 200 ) );
240 BOOST_CHECK_EQUAL( segment.
A,
VECTOR2I( 20, 30 ) );
241 BOOST_CHECK_EQUAL( segment.
B,
VECTOR2I( 200, 300 ) );
256 "Parallel, 10 apart",
257 { { 0, 0 }, { 10, 0 } },
258 { { 0, 10 }, { 10, 10 } },
262 "Non-parallel, 10 apart",
263 { { 0, -5 }, { 10, 0 } },
264 { { 0, 10 }, { 10, 10 } },
269 { { 0, 0 }, { 30, 0 } },
270 { { 10, 0 }, { 20, 0 } },
275 { { 0, -10 }, { 0, 10 } },
276 { { -20, 0 }, { 20, 0 } },
281 { { 0, -10 }, { 0, 10 } },
282 { { -20, 0 }, { 0, 0 } },
286 "T-junction (no touch)",
287 { { 0, -10 }, { 0, 10 } },
288 { { -20, 0 }, { -2, 0 } },
299 BOOST_TEST_CONTEXT( c.m_case_name )
301 BOOST_CHECK_PREDICATE(
SegDistanceCorrect, ( c.m_seg_a )( c.m_seg_b )( c.m_exp_dist ) );
320 { { 0, 0 }, { 10, 0 } },
326 { { 0, 0 }, { 10, 0 } },
332 { { 0, 0 }, { 10, 0 } },
337 "At end (collinear)",
338 { { 0, 0 }, { 10, 0 } },
343 "At end (not collinear)",
344 { { 0, 0 }, { 1000, 0 } },
349 "Issue 18473 (inside hit with rounding error)",
350 { { 187360000, 42510000 }, { 105796472, 42510000 } },
351 { 106645000, 42510000 },
355 "Straight line x distance",
356 { { 187360000, 42510000 }, { 105796472, 42510000 } },
357 { 197360000, 42510000 },
361 "Straight line -x distance",
362 { { 187360000, 42510000 }, { 105796472, 42510000 } },
363 { 104796472, 42510000 },
374 BOOST_TEST_CONTEXT( c.m_case_name )
399 "Parallel, 10 apart, 5 clear",
400 { { 0, 0 }, { 10, 0 } },
401 { { 0, 10 }, { 10, 10 } },
406 "Parallel, 10 apart, 10 clear",
407 { { 0, 0 }, { 10, 0 } },
408 { { 0, 10 }, { 10, 10 } },
413 "Parallel, 10 apart, 11 clear",
414 { { 0, 0 }, { 10, 0 } },
415 { { 0, 10 }, { 10, 10 } },
420 "T-junction, 2 apart, 2 clear",
421 { { 0, -10 }, { 0, 0 } },
422 { { -20, 0 }, { -2, 0 } },
427 "T-junction, 2 apart, 3 clear",
428 { { 0, -10 }, { 0, 0 } },
429 { { -20, 0 }, { -2, 0 } },
441 BOOST_TEST_CONTEXT( c.m_case_name )
444 ( c.m_seg_a )( c.m_seg_b )( c.m_clearance )( c.m_exp_coll ) );
468 { { 0, 0 }, { 10, 0 } },
469 { { 0, 0 }, { 10, 0 } },
474 { { 0, 0 }, { 10, 0 } },
475 { { 10, 0 }, { 20, 0 } },
480 { { 0, 0 }, { 10, 0 } },
481 { { 4, 0 }, { 7, 0 } },
486 { { 0, 0 }, { 10, 0 } },
487 { { 4, 1 }, { 7, 1 } },
492 { { 0, 0 }, { 10, 0 } },
493 { { 5, -5 }, { 5, 5 } },
504 BOOST_TEST_CONTEXT( c.m_case_name )
507 ( c.m_seg_a )( c.m_seg_b )( c.m_exp_result ) );
520 { { 0, 0 }, { 10, 0 } },
521 { { 0, 0 }, { 10, 0 } },
526 { { 0, 0 }, { 10, 0 } },
527 { { 10, 0 }, { 20, 0 } },
532 { { 0, 0 }, { 10, 0 } },
533 { { 4, 0 }, { 7, 0 } },
538 { { 0, 0 }, { 10, 0 } },
539 { { 4, 1 }, { 7, 1 } },
544 { { 0, 0 }, { 10, 0 } },
545 { { 5, -5 }, { 5, 5 } },
556 BOOST_TEST_CONTEXT( c.m_case_name )
559 ( c.m_seg_a )( c.m_seg_b )( c.m_exp_result ) );
572 { { 0, 0 }, { 10, 0 } },
573 { { 0, 0 }, { 10, 0 } },
578 { { 0, 0 }, { 10, 0 } },
579 { { 10, 0 }, { 20, 0 } },
584 { { 0, 0 }, { 10, 0 } },
585 { { 4, 0 }, { 7, 0 } },
590 { { 0, 0 }, { 10, 0 } },
591 { { 4, 1 }, { 7, 1 } },
596 { { 0, 0 }, { 10, 0 } },
597 { { 0, 0 }, { 5, 5 } },
601 "very nearly perpendicular",
602 { { 0, 0 }, { 10, 0 } },
603 { { 0, 0 }, { 1, 10 } },
607 "not really perpendicular",
608 { { 0, 0 }, { 10, 0 } },
609 { { 0, 0 }, { 3, 10 } },
614 { { 0, 0 }, { 10, 0 } },
615 { { 0, 0 }, { 0, 10 } },
619 "perpendicular not intersecting",
620 { { 0, 0 }, { 10, 0 } },
621 { { 15, 5 }, { 15, 10 } },
632 BOOST_TEST_CONTEXT( c.m_case_name )
635 ( c.m_seg_a )( c.m_seg_b )( c.m_exp_result ) );
658 "Horizontal: point on edge of seg",
659 { { 0, 0 }, { 10, 0 } },
663 "Horizontal: point in middle of seg",
664 { { 0, 0 }, { 10, 0 } },
668 "Horizontal: point outside seg",
669 { { 0, 0 }, { 10, 0 } },
673 "Vertical: point on edge of seg",
674 { { 0, 0 }, { 0, 10 } },
678 "Vertical: point in middle of seg",
679 { { 0, 0 }, { 0, 10 } },
683 "Vertical: point outside seg",
684 { { 0, 0 }, { 0, 10 } },
695 BOOST_TEST_CONTEXT( c.m_case_name )
709 BOOST_TEST_CONTEXT( c.m_case_name )
721 SEG seg( { 0, 0 }, { 10, 0 } );
723 BOOST_TEST( seg.LineDistance( { 5, 0 } ) == 0 );
724 BOOST_TEST( seg.LineDistance( { 5, 8 } ) == 8 );
729 SEG seg( { 0, 0 }, { 10, 0 } );
731 BOOST_TEST( seg.LineDistance( { 5, 8 },
true ) == 8 );
732 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.
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_TEST(box.ClosestPointTo(VECTOR2D(0, 0))==VECTOR2D(1, 2))
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
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.
static const std::vector< SEG_SEG_DISTANCE_CASE > seg_seg_dist_cases
bool SegDistanceCorrect(const SEG &aSegA, const SEG &aSegB, int aExp)
Predicate to check expected distance between two segments.
static const std::vector< SEG_VECTOR_DISTANCE_CASE > seg_vec_dist_cases
bool SegParallelCorrect(const SEG &aSegA, const SEG &aSegB, bool aExp)
Predicate to check expected parallelism between two segments.
bool SegCollideCorrect(const SEG &aSegA, const SEG &aSegB, int aClearance, bool aExp)
Predicate to check expected collision between two segments.
static const std::vector< SEG_SEG_COLLIDE_CASE > seg_seg_coll_cases
bool SegVecDistanceCorrect(const SEG &aSeg, const VECTOR2I &aVec, int aExp)
Predicate to check expected distance between a segment and a point.
bool SegPerpendicularCorrect(const SEG &aSegA, const SEG &aSegB, bool aExp)
Predicate to check expected perpendicularity between two segments.
static const std::vector< SEG_SEG_BOOLEAN_CASE > seg_vec_parallel_cases
Test cases for parallelism.
bool SegCollinearCorrect(const SEG &aSegA, const SEG &aSegB, bool aExp)
Predicate to check expected collision between two segments.
VECTOR2< int32_t > VECTOR2I