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 (C) 2021 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
26#include <board.h>
28#include <pad.h>
29#include <pcb_track.h>
30#include <footprint.h>
31#include <zone.h>
32#include <drc/drc_item.h>
34
35
37{
39 m_settingsManager( true /* headless */ )
40 { }
41
43 std::unique_ptr<BOARD> m_board;
44};
45
46
47BOOST_FIXTURE_TEST_CASE( RegressionTriangulationTests, TRIANGULATE_TEST_FIXTURE )
48{
49 std::vector<wxString> 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
64 for( const wxString& relPath : tests )
65 {
66 KI_TEST::LoadBoard( m_settingsManager, relPath, m_board );
67
68 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
69
70 for( ZONE* zone : m_board->Zones() )
71 {
72 if( zone->GetIsRuleArea() )
73 continue;
74
75 for( PCB_LAYER_ID layer : zone->GetLayerSet().Seq())
76 {
77 auto poly = zone->GetFilledPolysList( layer );
78
79 if( poly->OutlineCount() == 0 )
80 continue;
81
82 BOOST_CHECK_MESSAGE(
83 poly->IsTriangulationUpToDate(),
84 "Triangulation invalid for " + relPath + " layer " + LayerName( layer )
85 + " zone " + zone->GetFriendlyName() + " net '" + zone->GetNetname()
86 + "' with " + std::to_string( poly->OutlineCount() )
87 + " polygons at position " + std::to_string( poly->BBox().Centre().x )
88 + ", " + std::to_string( poly->BBox().Centre().y ) );
89
90 double area = poly->Area();
91 double tri_area = 0.0;
92
93 for( int ii = 0; ii < poly->TriangulatedPolyCount(); ii++ )
94 {
95 const auto tri_poly = poly->TriangulatedPolygon( ii );
96
97 for( const auto& tri : tri_poly->Triangles() )
98 tri_area += tri.Area();
99 }
100
101 double diff = std::abs( area - tri_area );
102
103 // The difference should be less than 1e-3 square mm
104 BOOST_CHECK_MESSAGE( diff < 1e9,
105 "Triangulation area mismatch in " + relPath + " layer "
106 + LayerName( layer )
107 + " difference: " + std::to_string( diff ) );
108 }
109 }
110 }
111}
112
Container for design settings for a BOARD object.
Handle a list of polygons defining a copper zone.
Definition: zone.h:72
wxString LayerName(int aLayer)
Returns the default display name for a given layer.
Definition: layer_id.cpp:30
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
SETTINGS_MANAGER m_settingsManager
std::unique_ptr< BOARD > m_board
BOOST_FIXTURE_TEST_CASE(RegressionTriangulationTests, TRIANGULATE_TEST_FIXTURE)