KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_pads_arc_structures.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 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 <boost/test/unit_test.hpp>
21#include <sstream>
23
24using namespace PADS_IO;
25
26
27BOOST_AUTO_TEST_SUITE( PadsArcStructures )
28
29
30BOOST_AUTO_TEST_CASE( ArcPoint_DefaultConstruction )
31{
32 ARC_POINT pt;
33 BOOST_CHECK_EQUAL( pt.x, 0.0 );
34 BOOST_CHECK_EQUAL( pt.y, 0.0 );
35 BOOST_CHECK_EQUAL( pt.is_arc, false );
36 BOOST_CHECK_EQUAL( pt.arc.cx, 0.0 );
37 BOOST_CHECK_EQUAL( pt.arc.cy, 0.0 );
38}
39
40
41BOOST_AUTO_TEST_CASE( ArcPoint_LineConstruction )
42{
43 ARC_POINT pt( 100.0, 200.0 );
44 BOOST_CHECK_EQUAL( pt.x, 100.0 );
45 BOOST_CHECK_EQUAL( pt.y, 200.0 );
46 BOOST_CHECK_EQUAL( pt.is_arc, false );
47}
48
49
50BOOST_AUTO_TEST_CASE( ArcPoint_ArcConstruction )
51{
52 ARC arc{ 50.0, 50.0, 25.0, 0.0, 180.0 };
53 ARC_POINT pt( 75.0, 50.0, arc );
54
55 BOOST_CHECK_EQUAL( pt.x, 75.0 );
56 BOOST_CHECK_EQUAL( pt.y, 50.0 );
57 BOOST_CHECK_EQUAL( pt.is_arc, true );
58 BOOST_CHECK_EQUAL( pt.arc.cx, 50.0 );
59 BOOST_CHECK_EQUAL( pt.arc.cy, 50.0 );
60 BOOST_CHECK_EQUAL( pt.arc.radius, 25.0 );
63}
64
65
66BOOST_AUTO_TEST_CASE( ArcPoint_EmplaceBack_Line )
67{
68 std::vector<ARC_POINT> points;
69 points.emplace_back( 10.0, 20.0 );
70 points.emplace_back( 30.0, 40.0 );
71
72 BOOST_REQUIRE_EQUAL( points.size(), 2 );
73 BOOST_CHECK_EQUAL( points[0].x, 10.0 );
74 BOOST_CHECK_EQUAL( points[0].y, 20.0 );
75 BOOST_CHECK_EQUAL( points[0].is_arc, false );
76 BOOST_CHECK_EQUAL( points[1].x, 30.0 );
77 BOOST_CHECK_EQUAL( points[1].y, 40.0 );
78 BOOST_CHECK_EQUAL( points[1].is_arc, false );
79}
80
81
82BOOST_AUTO_TEST_CASE( ArcPoint_EmplaceBack_Arc )
83{
84 std::vector<ARC_POINT> points;
85 points.emplace_back( 0.0, 0.0 );
86 points.emplace_back( 100.0, 0.0, ARC{ 50.0, 0.0, 50.0, 180.0, -180.0 } );
87
88 BOOST_REQUIRE_EQUAL( points.size(), 2 );
89 BOOST_CHECK_EQUAL( points[1].is_arc, true );
90 BOOST_CHECK_EQUAL( points[1].arc.cx, 50.0 );
91 BOOST_CHECK_EQUAL( points[1].arc.delta_angle, -180.0 );
92}
93
94
95BOOST_AUTO_TEST_CASE( Arc_FromBoundingBox )
96{
97 // PADS arc format: XLOC YLOC ISA IDA CX-R CY-R CX+R CY+R
98 // Example: 0 0 900 -900 -50 -50 50 50
99 // This represents arc from (0,0), center at (0,0), radius 50, 90deg start, -90deg delta
100 double bboxMinX = -50.0, bboxMinY = -50.0;
101 double bboxMaxX = 50.0, bboxMaxY = 50.0;
102 int startAngleTenths = 900; // 90.0 degrees
103 int deltaAngleTenths = -900; // -90.0 degrees (clockwise)
104
105 double cx = ( bboxMinX + bboxMaxX ) / 2.0;
106 double cy = ( bboxMinY + bboxMaxY ) / 2.0;
107 double radius = ( bboxMaxX - bboxMinX ) / 2.0;
108 double startAngle = startAngleTenths / 10.0;
109 double deltaAngle = deltaAngleTenths / 10.0;
110
111 BOOST_CHECK_CLOSE( cx, 0.0, 0.001 );
112 BOOST_CHECK_CLOSE( cy, 0.0, 0.001 );
113 BOOST_CHECK_CLOSE( radius, 50.0, 0.001 );
114 BOOST_CHECK_CLOSE( startAngle, 90.0, 0.001 );
115 BOOST_CHECK_CLOSE( deltaAngle, -90.0, 0.001 );
116}
117
118
119BOOST_AUTO_TEST_CASE( Arc_FromBoundingBox_OffCenter )
120{
121 // Arc with center at (100, 200), radius 25
122 // Bounding box: (75, 175) to (125, 225)
123 double bboxMinX = 75.0, bboxMinY = 175.0;
124 double bboxMaxX = 125.0, bboxMaxY = 225.0;
125
126 double cx = ( bboxMinX + bboxMaxX ) / 2.0;
127 double cy = ( bboxMinY + bboxMaxY ) / 2.0;
128 double radius = ( bboxMaxX - bboxMinX ) / 2.0;
129
130 BOOST_CHECK_CLOSE( cx, 100.0, 0.001 );
131 BOOST_CHECK_CLOSE( cy, 200.0, 0.001 );
132 BOOST_CHECK_CLOSE( radius, 25.0, 0.001 );
133}
134
135
136BOOST_AUTO_TEST_CASE( ArcPoint_ParseFromStream )
137{
138 // Simulate parsing a PADS arc line: "0 0 900 -900 -50 -50 50 50"
139 std::string line = "0 0 900 -900 -50 -50 50 50";
140 std::istringstream iss( line );
141
142 double dx, dy;
143 int startAngleTenths, deltaAngleTenths;
144 double bboxMinX, bboxMinY, bboxMaxX, bboxMaxY;
145
146 iss >> dx >> dy;
147 bool hasArc = static_cast<bool>( iss >> startAngleTenths >> deltaAngleTenths
148 >> bboxMinX >> bboxMinY >> bboxMaxX >> bboxMaxY );
149
150 BOOST_CHECK( hasArc );
151 BOOST_CHECK_EQUAL( startAngleTenths, 900 );
152 BOOST_CHECK_EQUAL( deltaAngleTenths, -900 );
153}
154
155
156BOOST_AUTO_TEST_CASE( ArcPoint_ParseFromStream_NoArc )
157{
158 // Simulate parsing a simple PADS line point: "100 200"
159 std::string line = "100 200";
160 std::istringstream iss( line );
161
162 double dx, dy;
163 int startAngleTenths, deltaAngleTenths;
164 double bboxMinX, bboxMinY, bboxMaxX, bboxMaxY;
165
166 iss >> dx >> dy;
167 bool hasArc = static_cast<bool>( iss >> startAngleTenths >> deltaAngleTenths
168 >> bboxMinX >> bboxMinY >> bboxMaxX >> bboxMaxY );
169
170 BOOST_CHECK( !hasArc );
171 BOOST_CHECK_CLOSE( dx, 100.0, 0.001 );
172 BOOST_CHECK_CLOSE( dy, 200.0, 0.001 );
173}
174
175
A point that may be either a line endpoint or an arc segment.
Definition pads_parser.h:68
ARC arc
Arc parameters (only valid when is_arc is true)
Definition pads_parser.h:72
bool is_arc
True if this segment is an arc, false for line.
Definition pads_parser.h:71
double y
Endpoint Y coordinate.
Definition pads_parser.h:70
double x
Endpoint X coordinate.
Definition pads_parser.h:69
Arc definition using center point, radius, and angles.
Definition pads_parser.h:53
double radius
Arc radius.
Definition pads_parser.h:56
double cx
Center X coordinate.
Definition pads_parser.h:54
double delta_angle
Arc sweep angle in degrees (positive = CCW)
Definition pads_parser.h:58
double start_angle
Start angle in degrees (0 = +X, CCW positive)
Definition pads_parser.h:57
double cy
Center Y coordinate.
Definition pads_parser.h:55
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(ArcPoint_DefaultConstruction)
int radius
BOOST_CHECK_EQUAL(result, "25.4")