KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_dashed_line.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, 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
28
29
#include <boost/test/unit_test.hpp>
30
31
#include <
gal/graphics_abstraction_layer.h
>
32
#include <
gal/gal_display_options.h
>
33
#include <
geometry/seg.h
>
34
#include <
preview_items/item_drawing_utils.h
>
35
36
using namespace
KIGFX
;
37
38
namespace
39
{
40
42
class
COUNTING_GAL :
public
GAL
43
{
44
public
:
45
COUNTING_GAL( GAL_DISPLAY_OPTIONS& aOptions ) : GAL( aOptions ) {}
46
47
void
DrawLine(
const
VECTOR2D
& aStartPoint,
const
VECTOR2D
& aEndPoint )
override
48
{
49
m_lineCount++;
50
}
51
52
unsigned
m_lineCount = 0;
53
};
54
55
}
// namespace
56
57
58
BOOST_AUTO_TEST_SUITE
( DashedLine )
59
60
61
// A normally sized dashed line still produces a bounded run of dashes.
62
BOOST_AUTO_TEST_CASE
( NormalLength )
63
{
64
GAL_DISPLAY_OPTIONS
opts;
65
COUNTING_GAL gal( opts );
66
67
const
SEG
seg(
VECTOR2I
( 0, 0 ),
VECTOR2I
( 0, 100000000 ) );
68
const
double
dashSize = 1000000;
69
70
DrawDashedLine
( gal, seg, dashSize );
71
72
BOOST_CHECK_GT( gal.m_lineCount, 1u );
73
BOOST_CHECK_LT( gal.m_lineCount, 200u );
74
}
75
76
77
// The #23824 regression. The old code looped length/dashCycle (~1.4e9) times here and hung.
78
BOOST_AUTO_TEST_CASE
( PathologicallyLongLine )
79
{
80
GAL_DISPLAY_OPTIONS
opts;
81
COUNTING_GAL gal( opts );
82
83
// ~2147 mm at 1 nm resolution, near the int32 coordinate limit.
84
const
SEG
seg(
VECTOR2I
( 0, 0 ),
VECTOR2I
( 0, 2100000000 ) );
85
const
double
dashSize = 1;
86
87
DrawDashedLine
( gal, seg, dashSize );
88
89
BOOST_CHECK_LE( gal.m_lineCount, 2u );
90
}
91
92
93
// A zero dash size must not divide by zero or loop forever.
94
BOOST_AUTO_TEST_CASE
( ZeroDashSize )
95
{
96
GAL_DISPLAY_OPTIONS
opts;
97
COUNTING_GAL gal( opts );
98
99
const
SEG
seg(
VECTOR2I
( 0, 0 ),
VECTOR2I
( 0, 1000000 ) );
100
101
DrawDashedLine
( gal, seg, 0.0 );
102
103
BOOST_CHECK_EQUAL
( gal.m_lineCount, 1u );
104
}
105
106
107
BOOST_AUTO_TEST_SUITE_END
()
KIGFX::GAL_DISPLAY_OPTIONS
Definition
gal_display_options.h:83
KIGFX::GAL
Abstract interface for drawing on a 2D-surface.
Definition
graphics_abstraction_layer.h:59
SEG
Definition
seg.h:38
gal_display_options.h
graphics_abstraction_layer.h
item_drawing_utils.h
Utility functions for drawing compound items (i.e.
KIGFX
The Cairo implementation of the graphics abstraction layer.
Definition
eda_group.h:29
KIGFX::DrawDashedLine
void DrawDashedLine(GAL &aGal, const SEG &aSeg, double aDashSize)
Draw a dashed line.
Definition
item_drawing_utils.cpp:37
seg.h
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
Definition
test_api_enums.cpp:71
BOOST_AUTO_TEST_SUITE
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(NormalLength)
Definition
test_dashed_line.cpp:62
BOOST_AUTO_TEST_SUITE_END
BOOST_AUTO_TEST_SUITE_END()
BOOST_CHECK_EQUAL
BOOST_CHECK_EQUAL(result, "25.4")
VECTOR2I
VECTOR2< int32_t > VECTOR2I
Definition
vector2d.h:683
VECTOR2D
VECTOR2< double > VECTOR2D
Definition
vector2d.h:682
src
qa
tests
common
test_dashed_line.cpp
Generated on Fri Jun 26 2026 00:05:43 for KiCad PCB EDA Suite by
1.13.2