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 { }
44
45 SETTINGS_MANAGER m_settingsManager;
46 std::unique_ptr<BOARD> m_board;
47};
48
49const std::vector<wxString> RegressionTriangulationTests_tests = {
50 "issue2568",
51 "issue5313",
52 "issue5320",
53 "issue5567",
54 "issue5830",
55 "issue6039",
56 "issue6260",
57 "issue7086",
58 "issue14294",
59 "issue17559",
60 "bad_triangulation_case"
61};
62
63}; // namespace
64
65
66BOOST_DATA_TEST_CASE_F( TRIANGULATE_TEST_FIXTURE, RegressionTriangulationTests,
67 boost::unit_test::data::make( RegressionTriangulationTests_tests ), relPath )
68{
69 KI_TEST::LoadBoard( m_settingsManager, relPath, m_board );
70
71 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
72
73 for( ZONE* zone : m_board->Zones() )
74 {
75 if( zone->GetIsRuleArea() )
76 continue;
77
78 for( PCB_LAYER_ID layer : zone->GetLayerSet().Seq())
79 {
80 auto poly = zone->GetFilledPolysList( layer );
81
82 if( poly->OutlineCount() == 0 )
83 continue;
84
85 BOOST_CHECK_MESSAGE(
86 poly->IsTriangulationUpToDate(),
87 "Triangulation invalid for " + relPath + " layer " + LayerName( layer )
88 + " zone " + zone->GetFriendlyName() + " net '" + zone->GetNetname()
89 + "' with " + std::to_string( poly->OutlineCount() )
90 + " polygons at position " + std::to_string( poly->BBox().Centre().x )
91 + ", " + std::to_string( poly->BBox().Centre().y ) );
92
93 double area = poly->Area();
94 double tri_area = 0.0;
95
96 for( int ii = 0; ii < poly->TriangulatedPolyCount(); ii++ )
97 {
98 const auto tri_poly = poly->TriangulatedPolygon( ii );
99
100 for( const auto& tri : tri_poly->Triangles() )
101 tri_area += tri.Area();
102 }
103
104 double diff = std::abs( area - tri_area );
105
106 // The difference should be less than 1e-3 square mm
107 BOOST_CHECK_MESSAGE( diff < 1e9,
108 "Triangulation area mismatch in " + relPath + " layer "
109 + LayerName( layer )
110 + " difference: " + std::to_string( diff ) );
111 }
112 }
113}
Container for design settings for a BOARD object.
Handle a list of polygons defining a copper zone.
Definition zone.h:74
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:400
BOOST_DATA_TEST_CASE_F(TRIANGULATE_TEST_FIXTURE, RegressionTriangulationTests, boost::unit_test::data::make(RegressionTriangulationTests_tests), relPath)