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, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#include <vector>
25
27
29
32
33BOOST_AUTO_TEST_SUITE( ShapePolySetSplitOutlines )
34
35BOOST_AUTO_TEST_CASE( SplitCoincidentOutlineOppositeDirection )
36{
37 // ASCII art representation of the polygon:
38 // 1-----------------0
39 // | |
40 // | |
41 // | 4------5 |
42 // | | | |
43 // 2/9--3/8 | |
44 // | | | |
45 // 10---7------6----11
46
47 SHAPE_POLY_SET poly;
48 SHAPE_LINE_CHAIN outline1( { 7600000, 9000000, 6600000, 9000000, 6600000, 8750000, 7000000, 8750000, 7000000,
49 9000000, 7250000, 9000000, 7250000, 8500000, 7000000, 8500000, 7000000, 8750000,
50 6600000, 8750000, 6600000, 8000000, 7600000, 8000000 } );
51 outline1.SetClosed( true );
52 poly.AddOutline( outline1 );
53
54 poly.Simplify();
55
57 BOOST_CHECK_EQUAL( poly.Outline( 0 ).PointCount(), 10 ); //Why is this 10? I think it should probably be 8
58 BOOST_CHECK( GEOM_TEST::IsPolySetValid( poly ) );
59}
60
61BOOST_AUTO_TEST_CASE( SplitCoincidentOutlineSameDirection )
62{
63 // ASCII art representation of the polygon (approximate shape):
64 // 8
65 // / /
66 // / /
67 // / 5 /
68 // / /\ /
69 // 7 / 6/ \ /
70 // 1-----------2\ /4
71 // \ \/
72 // \ /3
73 // \ /
74 // \ /
75 // 0
76 // This polygon has a self-intersecting/overlapping path that creates
77 // coincident edges going in the same direction (points 7→2 and 2→7)
78 // Original coordinates (scaled): 0:(99,83) 1:(93,89) 2:(80,86) 3:(94,85)
79 // 4:(96,87) 5:(96,86) 6:(95,85) 7:(94,85) repeated points: 7:(94,85) 2:(80,86)
80
81 SHAPE_POLY_SET poly;
82 SHAPE_LINE_CHAIN outline1( { 9912310, 8325057, 9288816, 8948550, 8000000, 8567586, 9428364,
83 8547698, 9585009, 8652365, 9613140, 8624234, 9471719, 8482813,
84 9428364, 8547698, 8000000, 8567586 } );
85 outline1.SetClosed( true );
86 poly.AddOutline( outline1 );
87
88 poly.Simplify();
89
91 BOOST_CHECK_EQUAL( poly.Outline( 0 ).PointCount(), 7 );
92 BOOST_CHECK( GEOM_TEST::IsPolySetValid( poly ) );
93
94}
95
97
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")