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, see <https://www.gnu.org/licenses/>.
18 */
19
21#include <boost/test/data/test_case.hpp>
22
24#include <board.h>
26#include <pad.h>
27#include <pcb_track.h>
28#include <footprint.h>
29#include <zone.h>
30#include <drc/drc_item.h>
32
33
34namespace {
35
36struct TRIANGULATE_TEST_FIXTURE
37{
38 TRIANGULATE_TEST_FIXTURE()
39 { }
40
41 SETTINGS_MANAGER m_settingsManager;
42 std::unique_ptr<BOARD> m_board;
43};
44
45const std::vector<wxString> RegressionTriangulationTests_tests = {
46 "issue2568",
47 "issue5313",
48 "issue5320",
49 "issue5567",
50 "issue5830",
51 "issue6039",
52 "issue6260",
53 "issue7086",
54 "issue14294",
55 "issue17559",
56 "bad_triangulation_case"
57};
58
59}; // namespace
60
61
62BOOST_DATA_TEST_CASE_F( TRIANGULATE_TEST_FIXTURE, RegressionTriangulationTests,
63 boost::unit_test::data::make( RegressionTriangulationTests_tests ), relPath )
64{
65 KI_TEST::LoadBoard( m_settingsManager, relPath, m_board );
66
67 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
68
69 for( ZONE* zone : m_board->Zones() )
70 {
71 if( zone->GetIsRuleArea() )
72 continue;
73
74 for( PCB_LAYER_ID layer : zone->GetLayerSet().Seq())
75 {
76 auto poly = zone->GetFilledPolysList( layer );
77
78 if( poly->OutlineCount() == 0 )
79 continue;
80
82 poly->IsTriangulationUpToDate(),
83 "Triangulation invalid for " + relPath + " layer " + LayerName( layer )
84 + " zone " + zone->GetFriendlyName() + " net '" + zone->GetNetname()
85 + "' with " + std::to_string( poly->OutlineCount() )
86 + " polygons at position " + std::to_string( poly->BBox().Centre().x )
87 + ", " + std::to_string( poly->BBox().Centre().y ) );
88
89 double area = poly->Area();
90 double tri_area = 0.0;
91
92 for( int ii = 0; ii < poly->TriangulatedPolyCount(); ii++ )
93 {
94 const auto tri_poly = poly->TriangulatedPolygon( ii );
95
96 for( const auto& tri : tri_poly->Triangles() )
97 tri_area += tri.Area();
98 }
99
100 double diff = std::abs( area - tri_area );
101
102 // The difference should be less than 1e-3 square mm
103 BOOST_CHECK_MESSAGE( diff < 1e9,
104 "Triangulation area mismatch in " + relPath + " layer "
105 + LayerName( layer )
106 + " difference: " + std::to_string( diff ) );
107 }
108 }
109}
Container for design settings for a BOARD object.
Handle a list of polygons defining a copper zone.
Definition zone.h:70
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:56
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_CHECK_MESSAGE(totalMismatches==0, std::to_string(totalMismatches)+" board(s) with strategy disagreements")
BOOST_DATA_TEST_CASE_F(TRIANGULATE_TEST_FIXTURE, RegressionTriangulationTests, boost::unit_test::data::make(RegressionTriangulationTests_tests), relPath)