KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_triangulation.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
25#include <boost/test/data/test_case.hpp>
26
28#include <board.h>
30#include <pad.h>
31#include <pcb_track.h>
32#include <footprint.h>
33#include <zone.h>
34#include <drc/drc_item.h>
36
37
38namespace {
39
40struct TRIANGULATE_TEST_FIXTURE
41{
42 TRIANGULATE_TEST_FIXTURE() :
43 m_settingsManager( true /* headless */ )
44 { }
45
46 SETTINGS_MANAGER m_settingsManager;
47 std::unique_ptr<BOARD> m_board;
48};
49
50const std::vector<wxString> RegressionTriangulationTests_tests = {
51 "issue2568",
52 "issue5313",
53 "issue5320",
54 "issue5567",
55 "issue5830",
56 "issue6039",
57 "issue6260",
58 "issue7086",
59 "issue14294",
60 "issue17559",
61 "bad_triangulation_case"
62};
63
64}; // namespace
65
66
67BOOST_DATA_TEST_CASE_F( TRIANGULATE_TEST_FIXTURE, RegressionTriangulationTests,
68 boost::unit_test::data::make( RegressionTriangulationTests_tests ), relPath )
69{
70 KI_TEST::LoadBoard( m_settingsManager, relPath, m_board );
71
72 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
73
74 for( ZONE* zone : m_board->Zones() )
75 {
76 if( zone->GetIsRuleArea() )
77 continue;
78
79 for( PCB_LAYER_ID layer : zone->GetLayerSet().Seq())
80 {
81 auto poly = zone->GetFilledPolysList( layer );
82
83 if( poly->OutlineCount() == 0 )
84 continue;
85
86 BOOST_CHECK_MESSAGE(
87 poly->IsTriangulationUpToDate(),
88 "Triangulation invalid for " + relPath + " layer " + LayerName( layer )
89 + " zone " + zone->GetFriendlyName() + " net '" + zone->GetNetname()
90 + "' with " + std::to_string( poly->OutlineCount() )
91 + " polygons at position " + std::to_string( poly->BBox().Centre().x )
92 + ", " + std::to_string( poly->BBox().Centre().y ) );
93
94 double area = poly->Area();
95 double tri_area = 0.0;
96
97 for( int ii = 0; ii < poly->TriangulatedPolyCount(); ii++ )
98 {
99 const auto tri_poly = poly->TriangulatedPolygon( ii );
100
101 for( const auto& tri : tri_poly->Triangles() )
102 tri_area += tri.Area();
103 }
104
105 double diff = std::abs( area - tri_area );
106
107 // The difference should be less than 1e-3 square mm
108 BOOST_CHECK_MESSAGE( diff < 1e9,
109 "Triangulation area mismatch in " + relPath + " layer "
110 + LayerName( layer )
111 + " difference: " + std::to_string( diff ) );
112 }
113 }
114}
Container for design settings for a BOARD object.
Handle a list of polygons defining a copper zone.
Definition: zone.h:73
wxString LayerName(int aLayer)
Returns the default display name for a given layer.
Definition: layer_id.cpp:31
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
void LoadBoard(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< BOARD > &aBoard)
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition: eda_angle.h:390
BOOST_DATA_TEST_CASE_F(TRIANGULATE_TEST_FIXTURE, RegressionTriangulationTests, boost::unit_test::data::make(RegressionTriangulationTests_tests), relPath)