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 (C) 2024 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, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#include <boost/test/unit_test.hpp>
25
27
28#include "geom_test_utils.h"
29
33BOOST_AUTO_TEST_SUITE( Dogbone )
34
36{
41 std::optional<DOGBONE_RESULT> m_expected_result;
42};
43
44static void DoDogboneTestChecks( const DOGBONE_TEST_CASE& aTestCase )
45{
46 // Actally do the chamfer
47 const std::optional<DOGBONE_RESULT> dogbone_result = ComputeDogbone(
48 aTestCase.m_seg_a, aTestCase.m_seg_b, aTestCase.m_radius, aTestCase.m_add_slots );
49
50 BOOST_REQUIRE_EQUAL( dogbone_result.has_value(), aTestCase.m_expected_result.has_value() );
51
52 if( dogbone_result.has_value() )
53 {
54 const DOGBONE_RESULT& expected_result = aTestCase.m_expected_result.value();
55 const DOGBONE_RESULT& actual_result = dogbone_result.value();
56
57 const SEG expected_arc_chord =
58 SEG( expected_result.m_arc.GetP0(), expected_result.m_arc.GetP1() );
59 const SEG actual_arc_chord =
60 SEG( actual_result.m_arc.GetP0(), actual_result.m_arc.GetP1() );
61
62 BOOST_CHECK_PREDICATE( GEOM_TEST::SegmentsHaveSameEndPoints,
63 (actual_arc_chord) ( expected_arc_chord ) );
64 BOOST_CHECK_EQUAL( actual_result.m_arc.GetArcMid(), expected_result.m_arc.GetArcMid() );
65
66 const auto check_updated_seg =
67 [&]( const std::optional<SEG>& updated_seg, const std::optional<SEG>& expected_seg )
68 {
69 BOOST_REQUIRE_EQUAL( updated_seg.has_value(), expected_seg.has_value() );
70
71 if( updated_seg.has_value() )
72 {
73 BOOST_CHECK_PREDICATE( GEOM_TEST::SegmentsHaveSameEndPoints,
74 ( *updated_seg )( *expected_seg ) );
75 }
76 };
77
78 check_updated_seg( actual_result.m_updated_seg_a, expected_result.m_updated_seg_a );
79 check_updated_seg( actual_result.m_updated_seg_b, expected_result.m_updated_seg_b );
80
81 BOOST_CHECK_EQUAL( actual_result.m_small_arc_mouth, expected_result.m_small_arc_mouth );
82 }
83}
84
85BOOST_AUTO_TEST_CASE( SimpleRightAngleAtOrigin )
86{
87 /* /---_
88 * / +----+-------------> 1000
89 * | | \
90 * \| (0,0)
91 * +
92 * |
93 * v
94 */
95
96 const DOGBONE_TEST_CASE testcase{
97 { VECTOR2I( 0, 0 ), VECTOR2I( 100000, 0 ) },
98 { VECTOR2I( 0, 0 ), VECTOR2I( 0, 100000 ) },
99 10000,
100 false,
101 // A right angle is an easy one to see, because the end and center points are
102 // all on 45 degree lines from the center
103 {
104 {
105 SHAPE_ARC{
106 VECTOR2I( 14142, 0 ),
107 VECTOR2I( 0, 0 ),
108 VECTOR2I( 0, 14142 ),
109 0,
110 },
111 SEG( VECTOR2I( 14142, 0 ), VECTOR2I( 100000, 0 ) ),
112 SEG( VECTOR2I( 0, 14142 ), VECTOR2I( 0, 100000 ) ),
113 false,
114 },
115
116 },
117 };
118
119 DoDogboneTestChecks( testcase );
120}
121
Definition: seg.h:42
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()
VECTOR2< int32_t > VECTOR2I
Definition: vector2d.h:691