KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_shape_poly_set_split_outlines.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) 2025 The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#include <vector>
21
23
25
28
29BOOST_AUTO_TEST_SUITE( ShapePolySetSplitOutlines )
30
31BOOST_AUTO_TEST_CASE( SplitCoincidentOutlineOppositeDirection )
32{
33 // ASCII art representation of the polygon:
34 // 1-----------------0
35 // | |
36 // | |
37 // | 4------5 |
38 // | | | |
39 // 2/9--3/8 | |
40 // | | | |
41 // 10---7------6----11
42
43 SHAPE_POLY_SET poly;
44 SHAPE_LINE_CHAIN outline1( { 7600000, 9000000, 6600000, 9000000, 6600000, 8750000, 7000000, 8750000, 7000000,
45 9000000, 7250000, 9000000, 7250000, 8500000, 7000000, 8500000, 7000000, 8750000,
46 6600000, 8750000, 6600000, 8000000, 7600000, 8000000 } );
47 outline1.SetClosed( true );
48 poly.AddOutline( outline1 );
49
50 poly.Simplify();
51
53 BOOST_CHECK_EQUAL( poly.Outline( 0 ).PointCount(), 10 ); //Why is this 10? I think it should probably be 8
54 BOOST_CHECK( GEOM_TEST::IsPolySetValid( poly ) );
55}
56
57BOOST_AUTO_TEST_CASE( SplitCoincidentOutlineSameDirection )
58{
59 // ASCII art representation of the polygon (approximate shape):
60 // 8
61 // / /
62 // / /
63 // / 5 /
64 // / /\ /
65 // 7 / 6/ \ /
66 // 1-----------2\ /4
67 // \ \/
68 // \ /3
69 // \ /
70 // \ /
71 // 0
72 // This polygon has a self-intersecting/overlapping path that creates
73 // coincident edges going in the same direction (points 7→2 and 2→7)
74 // Original coordinates (scaled): 0:(99,83) 1:(93,89) 2:(80,86) 3:(94,85)
75 // 4:(96,87) 5:(96,86) 6:(95,85) 7:(94,85) repeated points: 7:(94,85) 2:(80,86)
76
77 SHAPE_POLY_SET poly;
78 SHAPE_LINE_CHAIN outline1( { 9912310, 8325057, 9288816, 8948550, 8000000, 8567586, 9428364,
79 8547698, 9585009, 8652365, 9613140, 8624234, 9471719, 8482813,
80 9428364, 8547698, 8000000, 8567586 } );
81 outline1.SetClosed( true );
82 poly.AddOutline( outline1 );
83
84 poly.Simplify();
85
87 BOOST_CHECK_EQUAL( poly.Outline( 0 ).PointCount(), 7 );
88 BOOST_CHECK( GEOM_TEST::IsPolySetValid( poly ) );
89
90}
91
93
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
void SetClosed(bool aClosed)
Mark the line chain as closed (i.e.
int PointCount() const
Return the number of points (vertices) in this line chain.
Represent a set of closed polygons.
int AddOutline(const SHAPE_LINE_CHAIN &aOutline)
Adds a new outline to the set and returns its index.
void Simplify()
Simplify the polyset (merges overlapping polys, eliminates degeneracy/self-intersections)
SHAPE_LINE_CHAIN & Outline(int aIndex)
Return the reference to aIndex-th outline in the set.
int OutlineCount() const
Return the number of outlines in the set.
bool IsPolySetValid(const SHAPE_POLY_SET &aSet)
Verify that a SHAPE_POLY_SET has been assembled correctly by verifying each of the outlines and holes...
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(SplitCoincidentOutlineOppositeDirection)
BOOST_CHECK_EQUAL(result, "25.4")