KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_planegcs_smoke.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 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/*
21 * Build-integration smoke test for the vendored planegcs solver (issue #2329).
22 * Proves planegcs links into the pcbnew QA target and solves a small 2D system.
23 * The geometry mirrors thirdparty/planegcs/kicad/smoke_solve.cpp.
24 */
25
26#include <cmath>
27
29
30#include <GCS.h>
31
32
33BOOST_AUTO_TEST_SUITE( PlanegcsSmokeSolve )
34
35
36BOOST_AUTO_TEST_CASE( ParallelDistancePinnedSegment )
37{
38 GCS::System sys;
39
40 // Fixed horizontal reference segment A (endpoints not declared as unknowns).
41 double ax0 = 0.0, ay0 = 0.0, ax1 = 10.0, ay1 = 0.0;
42 GCS::Point a0{ &ax0, &ay0 };
43 GCS::Point a1{ &ax1, &ay1 };
44 GCS::Line lineA;
45 lineA.p1 = a0;
46 lineA.p2 = a1;
47
48 // Segment B: the unknowns, deliberately initialized off every constraint.
49 double bx0 = 1.0, by0 = 5.0, bx1 = 9.0, by1 = 7.0;
50 GCS::Point b0{ &bx0, &by0 };
51 GCS::Point b1{ &bx1, &by1 };
52 GCS::Line lineB;
53 lineB.p1 = b0;
54 lineB.p2 = b1;
55
56 // Driving parameter values (constants, not unknowns).
57 double length = 8.0;
58 double pinX = 2.0;
59 double pinY = 5.0;
60
61 int tag = 1;
62 sys.addConstraintParallel( lineB, lineA, tag++ );
63 sys.addConstraintP2PDistance( b0, b1, &length, tag++ );
64 sys.addConstraintCoordinateX( b0, &pinX, tag++ );
65 sys.addConstraintCoordinateY( b0, &pinY, tag++ );
66
67 GCS::VEC_pD unknowns{ &bx0, &by0, &bx1, &by1 };
68 sys.declareUnknowns( unknowns );
69 sys.initSolution();
70
71 int ret = sys.solve();
72 sys.applySolution();
73
74 BOOST_TEST_INFO( "solve() returned " << ret << " dof=" << sys.dofsNumber() );
75 BOOST_CHECK_EQUAL( ret, GCS::Success );
76
77 // Parallel to a horizontal reference means B is horizontal.
78 BOOST_CHECK_SMALL( by1 - by0, 1e-6 );
79
80 // Distance constraint satisfied.
81 double dx = bx1 - bx0, dy = by1 - by0;
82 BOOST_CHECK_SMALL( std::sqrt( dx * dx + dy * dy ) - length, 1e-6 );
83
84 // Coordinate pins satisfied.
85 BOOST_CHECK_SMALL( bx0 - pinX, 1e-6 );
86 BOOST_CHECK_SMALL( by0 - pinY, 1e-6 );
87
88 // Fully determined, so no remaining degrees of freedom.
89 BOOST_CHECK_EQUAL( sys.dofsNumber(), 0 );
90}
91
92
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_SUITE_END()
BOOST_TEST_INFO("Two-port Series .op current = "<< iDevice)
BOOST_CHECK_EQUAL(result, "25.4")