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
33#include <geometry/seg.h>
35
36using namespace KIGFX;
37
38namespace
39{
40
42class COUNTING_GAL : public GAL
43{
44public:
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
58BOOST_AUTO_TEST_SUITE( DashedLine )
59
60
61// A normally sized dashed line still produces a bounded run of dashes.
62BOOST_AUTO_TEST_CASE( NormalLength )
63{
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.
78BOOST_AUTO_TEST_CASE( PathologicallyLongLine )
79{
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.
94BOOST_AUTO_TEST_CASE( ZeroDashSize )
95{
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
Abstract interface for drawing on a 2D-surface.
Definition seg.h:38
Utility functions for drawing compound items (i.e.
The Cairo implementation of the graphics abstraction layer.
Definition eda_group.h:29
void DrawDashedLine(GAL &aGal, const SEG &aSeg, double aDashSize)
Draw a dashed line.
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_CASE(NormalLength)
BOOST_AUTO_TEST_SUITE_END()
BOOST_CHECK_EQUAL(result, "25.4")
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683
VECTOR2< double > VECTOR2D
Definition vector2d.h:682