KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_shape_line_chain_collision.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2017 CERN
5 * @author Alejandro GarcĂ­a Montoro <[email protected]>
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
22
23#include <geometry/shape.h>
24#include <geometry/shape_arc.h>
26
27#include "fixtures_geometry.h"
28
29
30BOOST_AUTO_TEST_SUITE( SHAPE_LINE_CHAIN_COLLIDE_TEST )
31
32BOOST_AUTO_TEST_CASE( Collide_LineToLine )
33{
34 SHAPE_LINE_CHAIN lineA;
35 lineA.Append( VECTOR2I( 0, 0 ) );
36 lineA.Append( VECTOR2I( 10, 0 ) );
37
38 SHAPE_LINE_CHAIN lineB;
39 lineB.Append( VECTOR2I( 5, 5 ) );
40 lineB.Append( VECTOR2I( 5, -5 ) );
41
43 int actual = 0;
44 bool collided = static_cast<SHAPE*>( &lineA )->Collide( &lineB, 0, &actual, &location );
45
46 BOOST_CHECK( collided );
47 BOOST_TEST( actual == 0 );
48 BOOST_CHECK_MESSAGE( location == VECTOR2I( 5, 0 ), "Expected: " << VECTOR2I( 5, 0 ) << " Actual: " << location );
49}
50
51BOOST_AUTO_TEST_CASE( Collide_LineToArc )
52{
53 SHAPE_LINE_CHAIN lineA;
54 lineA.Append( VECTOR2I( 0, 0 ) );
55 lineA.Append( VECTOR2I( 10, 0 ) );
56
58 arcB.Append( SHAPE_ARC( VECTOR2I( 5, 5 ), VECTOR2I( 6, 4 ), VECTOR2I( 7, 0 ), 0 ) );
59
61 int actual = 0;
62 bool collided = static_cast<SHAPE*>( &lineA )->Collide( &arcB, 0, &actual, &location );
63
64 BOOST_CHECK( collided );
65 BOOST_TEST( actual == 0 );
66 BOOST_CHECK_MESSAGE( location == VECTOR2I( 7, 0 ), "Expected: " << VECTOR2I( 7, 0 ) << " Actual: " << location );
67}
68
69BOOST_AUTO_TEST_CASE( Collide_ArcToArc )
70{
72 arcA.Append( SHAPE_ARC( VECTOR2I( 0, 0 ), VECTOR2I( 10, 0 ), VECTOR2I( 5, 5 ), 0 ) );
73
75 arcB.Append( SHAPE_ARC( VECTOR2I( 5, 5 ), VECTOR2I( 5, -5 ), VECTOR2I( 10, 0 ), 0 ) );
76
78 int actual = 0;
79 bool collided = static_cast<SHAPE*>( &arcA )->Collide( &arcB, 0, &actual, &location );
80
81 BOOST_CHECK( collided );
82 BOOST_TEST( actual == 0 );
83 BOOST_CHECK_MESSAGE( location == VECTOR2I( 5, 5 ), "Expected: " << VECTOR2I( 5, 5 ) << " Actual: " << location );
84}
85
86BOOST_AUTO_TEST_CASE( Collide_WithClearance )
87{
88 SHAPE_LINE_CHAIN lineA;
89 lineA.Append( VECTOR2I( 0, 0 ) );
90 lineA.Append( VECTOR2I( 10, 0 ) );
91
92 SHAPE_LINE_CHAIN lineB;
93 lineB.Append( VECTOR2I( 5, 6 ) );
94 lineB.Append( VECTOR2I( -5, 6 ) );
95
97 int actual = 0;
98 bool collided = static_cast<SHAPE*>( &lineA )->Collide( &lineB, 7, &actual, &location );
99
100 BOOST_CHECK( collided );
101 BOOST_CHECK_MESSAGE( actual == 6, "Expected: " << 6 << " Actual: " << actual );
102 BOOST_CHECK_MESSAGE( location == VECTOR2I( 0, 0 ), "Expected: " << VECTOR2I( 0, 0 ) << " Actual: " << location );
103}
104
105BOOST_AUTO_TEST_CASE( Collide_NoClearance )
106{
107 SHAPE_LINE_CHAIN lineA;
108 lineA.Append( VECTOR2I( 0, 0 ) );
109 lineA.Append( VECTOR2I( 10, 0 ) );
110
111 SHAPE_LINE_CHAIN lineB;
112 lineB.Append( VECTOR2I( 5, 6 ) );
113 lineB.Append( VECTOR2I( -5, 6 ) );
114
116 int actual = 0;
117 bool collided = static_cast<SHAPE*>( &lineA )->Collide( &lineB, 0, &actual, &location );
118
119 BOOST_CHECK( !collided );
120 BOOST_CHECK_MESSAGE( actual == 0, "Expected: " << 0 << " Actual: " << actual );
121}
122
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
void Append(int aX, int aY, bool aAllowDuplication=false)
Append a new point at the end of the line chain.
An abstract shape on 2D plane.
Definition shape.h:124
virtual bool Collide(const VECTOR2I &aP, int aClearance=0, int *aActual=nullptr, VECTOR2I *aLocation=nullptr) const
Check if the boundary of shape (this) lies closer to the point aP than aClearance,...
Definition shape.h:179
static bool Collide(const SHAPE_CIRCLE &aA, const SHAPE_CIRCLE &aB, int aClearance, int *aActual, VECTOR2I *aLocation, VECTOR2I *aMTV)
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_SUITE_END()
BOOST_TEST(netlist.find("R_G1 ARM_OUT1 DIE_B R='0.001 / ((SW_STATE)") !=std::string::npos)
BOOST_CHECK_MESSAGE(totalMismatches==0, std::to_string(totalMismatches)+" board(s) with strategy disagreements")
VECTOR2I location
int actual
BOOST_AUTO_TEST_CASE(Collide_LineToLine)
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683