KiCad PCB EDA Suite
test_shape_poly_set_collision.cpp File Reference

Go to the source code of this file.

Classes

struct  CollisionFixture
 Fixture for the Collision test suite. More...
 

Functions

 BOOST_AUTO_TEST_CASE (HasHoles)
 Declares the CollisionFixture as the boost test suite fixture. More...
 
 BOOST_AUTO_TEST_CASE (PointOnEdge)
 This test checks basic behaviour of PointOnEdge, testing if points on corners, outline edges and hole edges are detected as colliding. More...
 
 BOOST_AUTO_TEST_CASE (pointInPolygonSet)
 This test checks that the function Contains, whose behaviour has been updated to also manage holey polygons, does the right work. More...
 
 BOOST_AUTO_TEST_CASE (Collide)
 This test checks the behaviour of the Collide (with a point) method. More...
 
 BOOST_AUTO_TEST_CASE (CollideVertex)
 This test checks the behaviour of the CollideVertex method, testing whether the collision with vertices is well detected. More...
 
 BOOST_AUTO_TEST_CASE (CollideVertexWithClearance)
 This test checks the behaviour of the CollideVertex method, testing whether the collision with vertices is well detected. More...
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/6]

BOOST_AUTO_TEST_CASE ( HasHoles  )

Declares the CollisionFixture as the boost test suite fixture.

Simple dummy test to check that HasHoles() definition is right

Definition at line 85 of file test_shape_poly_set_collision.cpp.

86 {
87  BOOST_CHECK( !common.solidPolySet.HasHoles() );
88  BOOST_CHECK( common.holeyPolySet.HasHoles() );
89 }

◆ BOOST_AUTO_TEST_CASE() [2/6]

BOOST_AUTO_TEST_CASE ( PointOnEdge  )

This test checks basic behaviour of PointOnEdge, testing if points on corners, outline edges and hole edges are detected as colliding.

Definition at line 95 of file test_shape_poly_set_collision.cpp.

96 {
97  // Check points on corners
98  BOOST_CHECK( common.holeyPolySet.PointOnEdge( VECTOR2I( 0, 50 ) ) );
99 
100  // Check points on outline edges
101  BOOST_CHECK( common.holeyPolySet.PointOnEdge( VECTOR2I( 0, 10 ) ) );
102 
103  // Check points on hole edges
104  BOOST_CHECK( common.holeyPolySet.PointOnEdge( VECTOR2I( 10, 11 ) ) );
105 
106  // Check points inside a hole -> not in edge
107  BOOST_CHECK( !common.holeyPolySet.PointOnEdge( VECTOR2I( 12, 12 ) ) );
108 
109  // Check points inside the polygon and outside any hole -> not on edge
110  BOOST_CHECK( !common.holeyPolySet.PointOnEdge( VECTOR2I( 90, 90 ) ) );
111 
112  // Check points outside the polygon -> not on edge
113  BOOST_CHECK( !common.holeyPolySet.PointOnEdge( VECTOR2I( 200, 200 ) ) );
114 }
VECTOR2 defines a general 2D-vector/point.
Definition: vector2d.h:61

◆ BOOST_AUTO_TEST_CASE() [3/6]

BOOST_AUTO_TEST_CASE ( pointInPolygonSet  )

This test checks that the function Contains, whose behaviour has been updated to also manage holey polygons, does the right work.

Definition at line 120 of file test_shape_poly_set_collision.cpp.

121 {
122  // Check that the set contains the points that collide with it
123  for( const VECTOR2I& point : collidingPoints )
124  {
125  std::stringstream ss;
126  ss << "Point {" << point.x << ", " << point.y << " }";
127  BOOST_TEST_INFO( ss.str() );
128 
129  BOOST_CHECK( common.holeyPolySet.Contains( point ) );
130  }
131 
132  // Check that the set does not contain any point outside of it
133  for( const VECTOR2I& point : nonCollidingPoints )
134  {
135  std::stringstream ss;
136  ss << "Point {" << point.x << ", " << point.y << " }";
137  BOOST_TEST_INFO( ss.str() );
138 
139  BOOST_CHECK( !common.holeyPolySet.Contains( point ) );
140  }
141 }
VECTOR2 defines a general 2D-vector/point.
Definition: vector2d.h:61
#define BOOST_TEST_INFO(A)
If HAVE_EXPECTED_FAILURES is defined, this means that boost::unit_test::expected_failures is availabl...

References BOOST_TEST_INFO.

◆ BOOST_AUTO_TEST_CASE() [4/6]

BOOST_AUTO_TEST_CASE ( Collide  )

This test checks the behaviour of the Collide (with a point) method.

Definition at line 146 of file test_shape_poly_set_collision.cpp.

147 {
148  // When clearance = 0, the behaviour should be the same as with Contains
149 
150  // Check that the set collides with the colliding points
151  for( const VECTOR2I& point : collidingPoints )
152  {
153  std::stringstream ss;
154  ss << "Point {" << point.x << ", " << point.y << " }";
155  BOOST_TEST_INFO( ss.str() );
156 
157  BOOST_CHECK( common.holeyPolySet.Collide( point, 0 ) );
158  }
159 
160  // Check that the set does not collide with the non colliding points
161  for( const VECTOR2I& point : nonCollidingPoints )
162  {
163  std::stringstream ss;
164  ss << "Point {" << point.x << ", " << point.y << " }";
165  BOOST_TEST_INFO( ss.str() );
166 
167  BOOST_CHECK( !common.holeyPolySet.Collide( point, 0 ) );
168  }
169 
170  // Checks with clearance > 0
171 
172  // Point at the offset zone outside of the outline => collision!
173  BOOST_CHECK( common.holeyPolySet.Collide( VECTOR2I( -1, 10 ), 5 ) );
174 
175  // Point at the offset zone outside of a hole => collision!
176  BOOST_CHECK( common.holeyPolySet.Collide( VECTOR2I( 11, 11 ), 5 ) );
177 }
VECTOR2 defines a general 2D-vector/point.
Definition: vector2d.h:61
#define BOOST_TEST_INFO(A)
If HAVE_EXPECTED_FAILURES is defined, this means that boost::unit_test::expected_failures is availabl...

References BOOST_TEST_INFO.

◆ BOOST_AUTO_TEST_CASE() [5/6]

BOOST_AUTO_TEST_CASE ( CollideVertex  )

This test checks the behaviour of the CollideVertex method, testing whether the collision with vertices is well detected.

Definition at line 183 of file test_shape_poly_set_collision.cpp.

184 {
185  // Variable to store the index of the corner hit
187 
188  // Check that the set collides with the colliding points
189  for( const VECTOR2I& point : common.holeyPoints )
190  {
191  BOOST_CHECK_MESSAGE( common.holeyPolySet.CollideVertex( point, cornerHit, 0 ), " Point "
192  << point.x << ", " << point.y << " does not collide with holeyPolySet polygon" );
193  }
194 }
VECTOR2 defines a general 2D-vector/point.
Definition: vector2d.h:61
Struct VERTEX_INDEX.

References VECTOR2< T >::x, and VECTOR2< T >::y.

◆ BOOST_AUTO_TEST_CASE() [6/6]

BOOST_AUTO_TEST_CASE ( CollideVertexWithClearance  )

This test checks the behaviour of the CollideVertex method, testing whether the collision with vertices is well detected.

Definition at line 200 of file test_shape_poly_set_collision.cpp.

201 {
202  // Variable to store the index of the corner hit
204 
205  // Check that the set collides with the colliding points
206  for( const VECTOR2I& point : common.holeyPoints )
207  {
208  BOOST_CHECK( common.holeyPolySet.CollideVertex( point + VECTOR2I( 1, 1 ), cornerHit, 2 ) );
209  }
210 }
VECTOR2 defines a general 2D-vector/point.
Definition: vector2d.h:61
Struct VERTEX_INDEX.