28#include <boost/test/unit_test.hpp>
46 for(
int ii = 0; ii < aVertices; ++ii )
48 double angle = 2.0 *
M_PI * ii / aVertices;
49 chain.Append( aCentre.
x +
KiROUND( aRadius * cos( angle ) ), aCentre.
y +
KiROUND( aRadius * sin( angle ) ) );
52 chain.SetClosed(
true );
79 bool operator==(
const PROBE_RESULT& aOther )
const
81 return collides == aOther.collides && actual == aOther.actual;
86std::ostream&
operator<<( std::ostream& aStream,
const PROBE_RESULT& aResult )
88 return aStream <<
"{ collides=" << aResult.collides <<
" actual=" << aResult.actual <<
" }";
96 r.collides = aPoly.
Collide( &aShape, aClearance, &r.actual,
nullptr );
105PROBE_RESULT ReferenceScan(
const SHAPE_POLY_SET& aPoly,
const SHAPE& aShape,
int aClearance )
111 int best = std::numeric_limits<int>::max();
121 if( aShape.
Collide( &tri, aClearance, &triActual,
nullptr ) )
122 best = std::min( best, triActual );
126 if( best < std::numeric_limits<int>::max() )
129 r.actual = std::max( 0, best );
144 return aPoly.
Collide( &aShape, aClearance );
157 if( aShape.
Collide( &tri, aClearance ) )
184const std::vector<VECTOR2I> g_probes = {
228 WarmAndRequireIndexed( poly );
230 std::vector<const SHAPE*> before;
234 std::vector<VECTOR2I> firstVertexBefore;
236 for(
const SHAPE* s : before )
242 std::vector<const SHAPE*> after;
245 BOOST_REQUIRE_EQUAL( before.size(), after.size() );
247 for(
size_t ii = 0; ii < before.size(); ++ii )
268 const int gap = 20000;
269 const VECTOR2I a( 1000000 + gap, -100000 );
270 const VECTOR2I b( 1000000 + gap, 100000 );
277 BOOST_CHECK_EQUAL( Probe( poly, compound, gap / 2 ), ReferenceScan( poly, compound, gap / 2 ) );
281 BOOST_CHECK_EQUAL( Probe( poly, compound, gap * 4 ), ReferenceScan( poly, compound, gap * 4 ) );
283 BOOST_CHECK( Probe( poly, compound, gap * 4 ).collides );
297 const std::vector<std::pair<VECTOR2I, int>> cases = {
306 for(
const auto& [pt,
clearance] : cases )
325 size_t triangles = 0;
341 BOOST_CHECK_EQUAL( ProbeBool( poly, probe, 0 ), ReferenceScanBool( poly, probe, 0 ) );
361 WarmAndRequireIndexed( poly );
367 for(
const VECTOR2I& pt : g_probes )
370 BOOST_CHECK_EQUAL( Probe( poly, shifted, 0 ), ReferenceScan( poly, shifted, 0 ) );
371 BOOST_CHECK_EQUAL( ProbeBool( poly, shifted, 0 ), ReferenceScanBool( poly, shifted, 0 ) );
380 WarmAndRequireIndexed( poly );
386 WarmAndRequireIndexed( poly );
391 for(
const VECTOR2I& pt : g_probes )
395 BOOST_CHECK_EQUAL( ProbeBool( poly, probe, 0 ), ReferenceScanBool( poly, probe, 0 ) );
400 BOOST_CHECK_EQUAL( Probe( poly, inNewHole, 0 ), ReferenceScan( poly, inNewHole, 0 ) );
404 WarmAndRequireIndexed( target );
415 const std::vector<VECTOR2I> probes = {
425 BOOST_CHECK_EQUAL( Probe( target, probe, 0 ), ReferenceScan( target, probe, 0 ) );
426 BOOST_CHECK_EQUAL( ProbeBool( target, probe, 0 ), ReferenceScanBool( target, probe, 0 ) );
bool operator==(const wxAuiPaneInfo &aLhs, const wxAuiPaneInfo &aRhs)
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
void AddShape(SHAPE *aShape)
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
size_t GetTriangleCount() const
const std::deque< TRI > & Triangles() const
Represent a set of closed polygons.
void RemoveAllContours()
Remove all outlines & holes (clears) the polygon set.
virtual void GetIndexableSubshapes(std::vector< const SHAPE * > &aSubshapes) const override
const TRIANGULATION_INDEX * TriangulationIndex() const
The spatial index over the cached triangulation, or nullptr when none was built.
int AddOutline(const SHAPE_LINE_CHAIN &aOutline)
Adds a new outline to the set and returns its index.
virtual void CacheTriangulation(bool aSimplify=false, const TASK_SUBMITTER &aSubmitter={}, bool aBuildIndexes=false)
Build a polygon triangulation, needed to draw a polygon on OpenGL and in some other calculations.
bool Collide(const SHAPE *aShape, int aClearance=0, int *aActual=nullptr, VECTOR2I *aLocation=nullptr) const override
Check if the boundary of shape (this) lies closer to the shape aShape than aClearance,...
int AddHole(const SHAPE_LINE_CHAIN &aHole, int aOutline=-1)
Adds a new hole to the given outline (default: last) and returns its index.
const TRIANGULATED_POLYGON * TriangulatedPolygon(int aIndex) const
unsigned int TriangulatedPolyCount() const
Return the number of triangulated polygons.
void Move(const VECTOR2I &aVector) override
An abstract shape on 2D plane.
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,...
std::ostream & operator<<(std::ostream &aStream, const EDA_TEXT &aText)
FILE_INFO Probe(const wxString &aPath)
Identify a file; projects are parsed fully, while designs and libraries are only inspected....
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
const SHAPE_LINE_CHAIN chain
BOOST_AUTO_TEST_CASE(FirstColdCollideBuildsTheIndex)
A cold Collide() must come back indexed.
BOOST_CHECK_EQUAL(result, "25.4")
VECTOR2< int32_t > VECTOR2I