KiCad PCB EDA Suite
Loading...
Searching...
No Matches
fixtures_geometry.h
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, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25#ifndef QA_COMMON_GEOMETRY_FIXTURES_GEOEMETRY__H
26#define QA_COMMON_GEOMETRY_FIXTURES_GEOEMETRY__H
27
30
31namespace KI_TEST
32{
33
43{
44 // Polygon sets common for all the tests
58
59 // Vectors containing the information with which the polygons are populated.
60 std::vector<VECTOR2I> uniquePoints;
61 std::vector<VECTOR2I> holeyPoints;
62 std::vector<SEG> holeySegments;
63
68 {
69 // UniqueVertexPolySet shall have a unique vertex
70 uniquePoints.emplace_back( 100, 50 );
71
72 // Populate the holey polygon set points with 12 points
73
74 // Square
75 holeyPoints.emplace_back( 100, 100 );
76 holeyPoints.emplace_back( 0, 100 );
77 holeyPoints.emplace_back( 0, 0 );
78 holeyPoints.emplace_back( 100, 0 );
79
80 // Pentagon
81 holeyPoints.emplace_back( 10, 10 );
82 holeyPoints.emplace_back( 10, 20 );
83 holeyPoints.emplace_back( 15, 15 );
84 holeyPoints.emplace_back( 20, 20 );
85 holeyPoints.emplace_back( 20, 10 );
86
87 // Triangle
88 holeyPoints.emplace_back( 40, 10 );
89 holeyPoints.emplace_back( 40, 20 );
90 holeyPoints.emplace_back( 60, 10 );
91
92 // Save the segments of the holeyPolySet.
93 holeySegments.emplace_back( holeyPoints[0], holeyPoints[1] );
94 holeySegments.emplace_back( holeyPoints[1], holeyPoints[2] );
95 holeySegments.emplace_back( holeyPoints[2], holeyPoints[3] );
96 holeySegments.emplace_back( holeyPoints[3], holeyPoints[0] );
97
98 // Pentagon segments
99 holeySegments.emplace_back( holeyPoints[4], holeyPoints[5] );
100 holeySegments.emplace_back( holeyPoints[5], holeyPoints[6] );
101 holeySegments.emplace_back( holeyPoints[6], holeyPoints[7] );
102 holeySegments.emplace_back( holeyPoints[7], holeyPoints[8] );
103 holeySegments.emplace_back( holeyPoints[8], holeyPoints[4] );
104
105 // Triangle segments
106 holeySegments.emplace_back( holeyPoints[9], holeyPoints[10] );
107 holeySegments.emplace_back( holeyPoints[10], holeyPoints[11] );
108 holeySegments.emplace_back( holeyPoints[11], holeyPoints[9] );
109
110 // Auxiliary variables to store the contours that will be added to the polygons
111 SHAPE_LINE_CHAIN polyLine, hole;
112
113 // Create a polygon set with a unique vertex
114 polyLine.Append( uniquePoints[0] );
115 polyLine.SetClosed( true );
117
118 // Create a polygon set without holes
122
123 // Create a polygon set with holes
124
125 // Adds a new squared outline
126 polyLine.Clear();
127
128 for( int i = 0; i < 4; i++ )
129 polyLine.Append( holeyPoints[i] );
130
131 polyLine.SetClosed( true );
132
133 holeyPolySet.AddOutline( polyLine );
134
135 // Adds a new hole (a pentagon)
136 for( int i = 4; i < 9; i++ )
137 hole.Append( holeyPoints[i] );
138
139 hole.SetClosed( true );
140 holeyPolySet.AddHole( hole );
141
142
143 // Adds a new hole (a triangle)
144 hole.Clear();
145 for( int i = 9; i < 12; i++ )
146 hole.Append( holeyPoints[i] );
147
148 hole.SetClosed( true );
149 holeyPolySet.AddHole( hole );
150
151 //GENERATE CURVED POLYGON THAT CAUSES WRAPAROUND
152 SHAPE_LINE_CHAIN wrapLine;
153 wrapLine.Append( SHAPE_ARC( { -4300000, -6950000 }, { 2000000, 0 }, { -4300000, 6950000 }, 0 ) );
154 wrapLine.Append( SHAPE_ARC( { -4300000, 2200000 }, { -2700000, 0 }, { -4300000, -2200000 }, 0 ) );
155 wrapLine.SetClosed( true );
157
158 // GENERATE CURVED POLYGON WITH HOLES
159 // For visualisation, launch test_pns with the arguments "viewcurvedpoly -[single|multi]"
160
161 // First shape:
162 SHAPE_LINE_CHAIN oline0;
163 oline0.Append( { 244000, 180000 } );
164 oline0.Append( SHAPE_ARC( { 582000, 232000 }, { 614000, 354000 }, { 450000, 436000 }, 0 ) );
165 oline0.Append( SHAPE_ARC( { 450000, 436000 }, { 310000, 480000 }, { 502000, 614000 }, 0 ) );
166 oline0.Append( { 872000, 202000 } );
167 oline0.SetClosed( true );
169
170 SHAPE_LINE_CHAIN o0h1;
171 o0h1.Append( { 370000, 482000 } );
172 o0h1.Append( SHAPE_ARC( { 342000, 576000 }, { 436000, 552000 }, { 474000, 622000 }, 0 ) );
173 o0h1.Append( SHAPE_ARC( { 474000, 622000 }, { 534000, 520000 }, { 518000, 470000 }, 0 ) );
174 o0h1.SetClosed( true );
176
177 SHAPE_LINE_CHAIN o0h2;
178 o0h2.Append( SHAPE_ARC( { 680000, 286000 }, { 728000, 306000 }, { 760000, 258000 }, 0 ) );
179 o0h2.Append( SHAPE_ARC( { 760000, 258000 }, { 746000, 222000 }, { 686000, 260000 }, 0 ) );
180 o0h2.SetClosed( true );
182
184
185 // Second shape:
186 SHAPE_LINE_CHAIN oline1;
187 oline1.Append( { 640000, 840000 } );
188 oline1.Append( SHAPE_ARC( { 829000, 959000 }, { 990000, 736000 }, { 951000, 461000 }, 0 ) );
189 oline1.Append( SHAPE_ARC( { 951000, 461000 }, { 600000, 572000 }, { 620000, 726000 }, 0 ) );
190 oline1.SetClosed( true );
192
193 SHAPE_LINE_CHAIN o1h1;
194 o1h1.Append( { 670000, 482000 } );
195 o1h1.Append( SHAPE_ARC( { 642000, 576000 }, { 736000, 652000 }, { 774000, 622000 }, 0 ) );
196 o1h1.Append( SHAPE_ARC( { 774000, 622000 }, { 834000, 520000 }, { 818000, 470000 }, 0 ) );
197 o1h1.SetClosed( true );
199
200 SHAPE_LINE_CHAIN o1h2;
201 o1h2.Append( SHAPE_ARC( { 680000, 286000 }, { 728000, 306000 }, { 760000, 258000 }, 0 ) );
202 o1h2.Append( SHAPE_ARC( { 760000, 258000 }, { 746000, 222000 }, { 686000, 260000 }, 0 ) );
203 o1h2.SetClosed( true );
205
206 // Intersecting shape:
207 SHAPE_LINE_CHAIN oline2;
208 oline2.Append( { 340000, 540000 } );
209 oline2.Append( SHAPE_ARC( { 629000, 659000 }, { 790000, 436000 }, { 751000, 161000 }, 0 ) );
210 oline2.Append( SHAPE_ARC( { 651000, 161000 }, { 300000, 272000 }, { 320000, 426000 }, 0 ) );
211 oline2.SetClosed( true );
213
214 SHAPE_LINE_CHAIN o2h2;
215 o2h2.Append( SHAPE_ARC( { 680000, 486000 }, { 728000, 506000 }, { 760000, 458000 }, 0 ) );
216 o2h2.Append( SHAPE_ARC( { 760000, 458000 }, { 746000, 422000 }, { 686000, 460000 }, 0 ) );
217 o2h2.SetClosed( true );
219 }
220
222 {
223 }
224};
225
226} // namespace KI_TEST
227
228#endif // QA_COMMON_GEOMETRY_FIXTURES_GEOEMETRY__H
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.
void Clear()
Remove all points from the line chain.
void Append(int aX, int aY, bool aAllowDuplication=false)
Append a new point at the end of the 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.
int AddHole(const SHAPE_LINE_CHAIN &aHole, int aOutline=-1)
Adds a new hole to the given outline (default: last) and returns its index.
int NewOutline()
Creates a new empty polygon in the set and returns its index.
Common data for some of the SHAPE_POLY_SET tests:
SHAPE_POLY_SET uniqueVertexPolySet
SHAPE_POLY_SET holeyCurvedPolySingle
Polygon with a single outline + multiple holes.
std::vector< SEG > holeySegments
std::vector< VECTOR2I > holeyPoints
SHAPE_POLY_SET holeyCurvedPolyInter
Polygon with a single outlines + multiple holes.
SHAPE_POLY_SET curvedPolyWrapRound
Causes arc wraparound when reloading from Clipper see https://gitlab.com/kicad/code/kicad/-/issues/96...
std::vector< VECTOR2I > uniquePoints
SHAPE_POLY_SET holeyCurvedPolyMulti
Polygon with a multiple outlines + multiple holes.