KiCad PCB EDA Suite
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 <alejandro.garciamontoro@gmail.com>
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 
31 namespace KI_TEST
32 {
33 
43 {
44  // Polygon sets common for all the tests
49 
50  // Vectors containing the information with which the polygons are populated.
51  std::vector<VECTOR2I> uniquePoints;
52  std::vector<VECTOR2I> holeyPoints;
53  std::vector<SEG> holeySegments;
54 
59  {
60  // UniqueVertexPolySet shall have a unique vertex
61  uniquePoints.emplace_back( 100, 50 );
62 
63  // Populate the holey polygon set points with 12 points
64 
65  // Square
66  holeyPoints.emplace_back( 100, 100 );
67  holeyPoints.emplace_back( 0, 100 );
68  holeyPoints.emplace_back( 0, 0 );
69  holeyPoints.emplace_back( 100, 0 );
70 
71  // Pentagon
72  holeyPoints.emplace_back( 10, 10 );
73  holeyPoints.emplace_back( 10, 20 );
74  holeyPoints.emplace_back( 15, 15 );
75  holeyPoints.emplace_back( 20, 20 );
76  holeyPoints.emplace_back( 20, 10 );
77 
78  // Triangle
79  holeyPoints.emplace_back( 40, 10 );
80  holeyPoints.emplace_back( 40, 20 );
81  holeyPoints.emplace_back( 60, 10 );
82 
83  // Save the segments of the holeyPolySet.
84  holeySegments.emplace_back( holeyPoints[0], holeyPoints[1] );
85  holeySegments.emplace_back( holeyPoints[1], holeyPoints[2] );
86  holeySegments.emplace_back( holeyPoints[2], holeyPoints[3] );
87  holeySegments.emplace_back( holeyPoints[3], holeyPoints[0] );
88 
89  // Pentagon segments
90  holeySegments.emplace_back( holeyPoints[4], holeyPoints[5] );
91  holeySegments.emplace_back( holeyPoints[5], holeyPoints[6] );
92  holeySegments.emplace_back( holeyPoints[6], holeyPoints[7] );
93  holeySegments.emplace_back( holeyPoints[7], holeyPoints[8] );
94  holeySegments.emplace_back( holeyPoints[8], holeyPoints[4] );
95 
96  // Triangle segments
97  holeySegments.emplace_back( holeyPoints[9], holeyPoints[10] );
98  holeySegments.emplace_back( holeyPoints[10], holeyPoints[11] );
99  holeySegments.emplace_back( holeyPoints[11], holeyPoints[9] );
100 
101  // Auxiliary variables to store the contours that will be added to the polygons
102  SHAPE_LINE_CHAIN polyLine, hole;
103 
104  // Create a polygon set with a unique vertex
105  polyLine.Append( uniquePoints[0] );
106  polyLine.SetClosed( true );
107  uniqueVertexPolySet.AddOutline( polyLine );
108 
109  // Create a polygon set without holes
113 
114  // Create a polygon set with holes
115 
116  // Adds a new squared outline
117  polyLine.Clear();
118 
119  for( int i = 0; i < 4; i++ )
120  polyLine.Append( holeyPoints[i] );
121 
122  polyLine.SetClosed( true );
123 
124  holeyPolySet.AddOutline( polyLine );
125 
126  // Adds a new hole (a pentagon)
127  for( int i = 4; i < 9; i++ )
128  hole.Append( holeyPoints[i] );
129 
130  hole.SetClosed( true );
131  holeyPolySet.AddHole( hole );
132 
133 
134  // Adds a new hole (a triangle)
135  hole.Clear();
136  for( int i = 9; i < 12; i++ )
137  hole.Append( holeyPoints[i] );
138 
139  hole.SetClosed( true );
140  holeyPolySet.AddHole( hole );
141  }
142 
144  {
145  }
146 };
147 
148 } // namespace KI_TEST
149 
150 #endif // QA_COMMON_GEOMETRY_FIXTURES_GEOEMETRY__H
Common data for some of the SHAPE_POLY_SET tests:
void Append(int aX, int aY, bool aAllowDuplication=false)
Function Append()
void SetClosed(bool aClosed)
Function SetClosed()
std::vector< VECTOR2I > uniquePoints
std::vector< VECTOR2I > holeyPoints
SHAPE_POLY_SET.
int NewOutline()
Creates a new empty polygon in 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
SHAPE_POLY_SET uniqueVertexPolySet
int AddOutline(const SHAPE_LINE_CHAIN &aOutline)
Adds a new outline to the set and returns its index
std::vector< SEG > holeySegments
SHAPE_LINE_CHAIN.
void Clear()
Function Clear() Removes all points from the line chain.