KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_dcode.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
23
24#include <cstdlib>
25
26#include <boost/test/unit_test.hpp>
27
28#include <dcode.h>
29#include <gerber_draw_item.h>
30#include <gerber_file_image.h>
31#include <base_units.h>
33
34
35namespace
36{
37
38SHAPE_POLY_SET convertOvalAperture( double aWidthMm, double aHeightMm )
39{
41 GERBER_DRAW_ITEM item( &image );
42 D_CODE dcode( 10 );
43
44 dcode.m_ApertType = APT_OVAL;
45 dcode.m_Size = VECTOR2I( gerbIUScale.mmToIU( aWidthMm ), gerbIUScale.mmToIU( aHeightMm ) );
46 dcode.m_DrillShape = APT_DEF_NO_HOLE;
47 dcode.ConvertShapeToPolygon( &item );
48
49 return dcode.m_Polygon;
50}
51
52} // namespace
53
54
55BOOST_AUTO_TEST_SUITE( GerbviewDcode )
56
57
58// Guards against regressing to a segment count independent of the aperture size.
59BOOST_AUTO_TEST_CASE( OvalTessellationScalesWithSize )
60{
61 int smallCount = convertOvalAperture( 2.0, 1.0 ).VertexCount();
62 int largeCount = convertOvalAperture( 40.0, 20.0 ).VertexCount();
63
64 BOOST_CHECK_GT( largeCount, smallCount );
65}
66
67
68// Exercises the true oval path (unequal axes) in both orientations.
69BOOST_AUTO_TEST_CASE( OvalTessellationKeepsRequestedSize )
70{
71 const int tolerance = 2 * gerbIUScale.mmToIU( 0.005 );
72
73 BOX2I horizontal = convertOvalAperture( 2.0, 1.0 ).BBox();
74
75 BOOST_CHECK_LE( std::abs( horizontal.GetWidth() - gerbIUScale.mmToIU( 2.0 ) ), tolerance );
76 BOOST_CHECK_LE( std::abs( horizontal.GetHeight() - gerbIUScale.mmToIU( 1.0 ) ), tolerance );
77
78 BOX2I vertical = convertOvalAperture( 1.0, 2.0 ).BBox();
79
80 BOOST_CHECK_LE( std::abs( vertical.GetWidth() - gerbIUScale.mmToIU( 1.0 ) ), tolerance );
81 BOOST_CHECK_LE( std::abs( vertical.GetHeight() - gerbIUScale.mmToIU( 2.0 ) ), tolerance );
82}
83
84
constexpr EDA_IU_SCALE gerbIUScale
Definition base_units.h:120
BOX2< VECTOR2I > BOX2I
Definition box2.h:918
constexpr size_type GetWidth() const
Definition box2.h:210
constexpr size_type GetHeight() const
Definition box2.h:211
A gerber DCODE (also called Aperture) definition.
Definition dcode.h:76
Hold the image data and parameters for one gerber file and layer parameters.
Represent a set of closed polygons.
@ APT_DEF_NO_HOLE
Definition dcode.h:57
@ APT_OVAL
Definition dcode.h:47
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition eda_angle.h:400
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_CASE(OvalTessellationScalesWithSize)
BOOST_AUTO_TEST_SUITE_END()
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683