KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_dogbone.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#include <boost/test/unit_test.hpp>
21
23
24#include "geom_test_utils.h"
25
29BOOST_AUTO_TEST_SUITE( Dogbone )
30
32{
37 std::optional<DOGBONE_RESULT> m_expected_result;
38};
39
40static void DoDogboneTestChecks( const DOGBONE_TEST_CASE& aTestCase )
41{
42 // Actally do the chamfer
43 const std::optional<DOGBONE_RESULT> dogbone_result = ComputeDogbone(
44 aTestCase.m_seg_a, aTestCase.m_seg_b, aTestCase.m_radius, aTestCase.m_add_slots );
45
46 BOOST_REQUIRE_EQUAL( dogbone_result.has_value(), aTestCase.m_expected_result.has_value() );
47
48 if( dogbone_result.has_value() )
49 {
50 const DOGBONE_RESULT& expected_result = aTestCase.m_expected_result.value();
51 const DOGBONE_RESULT& actual_result = dogbone_result.value();
52
53 const SEG expected_arc_chord =
54 SEG( expected_result.m_arc.GetP0(), expected_result.m_arc.GetP1() );
55 const SEG actual_arc_chord =
56 SEG( actual_result.m_arc.GetP0(), actual_result.m_arc.GetP1() );
57
59 (actual_arc_chord) ( expected_arc_chord ) );
60 BOOST_CHECK_EQUAL( actual_result.m_arc.GetArcMid(), expected_result.m_arc.GetArcMid() );
61
62 const auto check_updated_seg =
63 [&]( const std::optional<SEG>& updated_seg, const std::optional<SEG>& expected_seg )
64 {
65 BOOST_REQUIRE_EQUAL( updated_seg.has_value(), expected_seg.has_value() );
66
67 if( updated_seg.has_value() )
68 {
70 ( *updated_seg )( *expected_seg ) );
71 }
72 };
73
74 check_updated_seg( actual_result.m_updated_seg_a, expected_result.m_updated_seg_a );
75 check_updated_seg( actual_result.m_updated_seg_b, expected_result.m_updated_seg_b );
76
77 BOOST_CHECK_EQUAL( actual_result.m_small_arc_mouth, expected_result.m_small_arc_mouth );
78 }
79}
80
81BOOST_AUTO_TEST_CASE( SimpleRightAngleAtOrigin )
82{
83 /* /---_
84 * / +----+-------------> 1000
85 * | | \
86 * \| (0,0)
87 * +
88 * |
89 * v
90 */
91
92 const DOGBONE_TEST_CASE testcase{
93 { VECTOR2I( 0, 0 ), VECTOR2I( 100000, 0 ) },
94 { VECTOR2I( 0, 0 ), VECTOR2I( 0, 100000 ) },
95 10000,
96 false,
97 // A right angle is an easy one to see, because the end and center points are
98 // all on 45 degree lines from the center
99 {
100 {
101 SHAPE_ARC{
102 VECTOR2I( 14142, 0 ),
103 VECTOR2I( 0, 0 ),
104 VECTOR2I( 0, 14142 ),
105 0,
106 },
107 SEG( VECTOR2I( 14142, 0 ), VECTOR2I( 100000, 0 ) ),
108 SEG( VECTOR2I( 0, 14142 ), VECTOR2I( 0, 100000 ) ),
109 false,
110 },
111
112 },
113 };
114
115 DoDogboneTestChecks( testcase );
116}
117
Definition seg.h:38
const VECTOR2I & GetArcMid() const
Definition shape_arc.h:116
const VECTOR2I & GetP1() const
Definition shape_arc.h:115
const VECTOR2I & GetP0() const
Definition shape_arc.h:114
std::optional< DOGBONE_RESULT > ComputeDogbone(const SEG &aSegA, const SEG &aSegB, int aDogboneRadius, bool aAddSlots)
Compute the dogbone geometry for a given line pair and dogbone parameters.
bool SegmentsHaveSameEndPoints(const SEG &aSeg1, const SEG &aSeg2)
Check that two SEGs have the same end points, in either order.
std::optional< SEG > m_updated_seg_b
std::optional< SEG > m_updated_seg_a
Declares the DogboneFixture struct as the boost test fixture.
std::optional< DOGBONE_RESULT > m_expected_result
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_CASE(SimpleRightAngleAtOrigin)
static void DoDogboneTestChecks(const DOGBONE_TEST_CASE &aTestCase)
BOOST_AUTO_TEST_SUITE_END()
BOOST_CHECK_PREDICATE(ArePolylineEndPointsNearCircle,(chain)(c.m_geom.m_center_point)(radius)(accuracy+epsilon))
BOOST_CHECK_EQUAL(result, "25.4")
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683