You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

112 lines
4.1 KiB

  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. #include <qa_utils/wx_utils/unit_test_utils.h>
  24. #include <pcbnew_utils/board_test_utils.h>
  25. #include <board.h>
  26. #include <board_design_settings.h>
  27. #include <pad.h>
  28. #include <pcb_track.h>
  29. #include <footprint.h>
  30. #include <zone.h>
  31. #include <drc/drc_item.h>
  32. #include <settings/settings_manager.h>
  33. struct TRIANGULATE_TEST_FIXTURE
  34. {
  35. TRIANGULATE_TEST_FIXTURE() :
  36. m_settingsManager( true /* headless */ )
  37. { }
  38. SETTINGS_MANAGER m_settingsManager;
  39. std::unique_ptr<BOARD> m_board;
  40. };
  41. BOOST_FIXTURE_TEST_CASE( RegressionTriangulationTests, TRIANGULATE_TEST_FIXTURE )
  42. {
  43. std::vector<wxString> tests = {
  44. "issue2568",
  45. "issue5313",
  46. "issue5320",
  47. "issue5567",
  48. "issue5830",
  49. "issue6039",
  50. "issue6260",
  51. "issue7086",
  52. "issue14294",
  53. "issue17559",
  54. "bad_triangulation_case"
  55. };
  56. for( const wxString& relPath : tests )
  57. {
  58. KI_TEST::LoadBoard( m_settingsManager, relPath, m_board );
  59. BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
  60. for( ZONE* zone : m_board->Zones() )
  61. {
  62. if( zone->GetIsRuleArea() )
  63. continue;
  64. for( PCB_LAYER_ID layer : zone->GetLayerSet().Seq())
  65. {
  66. auto poly = zone->GetFilledPolysList( layer );
  67. if( poly->OutlineCount() == 0 )
  68. continue;
  69. BOOST_CHECK_MESSAGE(
  70. poly->IsTriangulationUpToDate(),
  71. "Triangulation invalid for " + relPath + " layer " + LayerName( layer )
  72. + " zone " + zone->GetFriendlyName() + " net '" + zone->GetNetname()
  73. + "' with " + std::to_string( poly->OutlineCount() )
  74. + " polygons at position " + std::to_string( poly->BBox().Centre().x )
  75. + ", " + std::to_string( poly->BBox().Centre().y ) );
  76. double area = poly->Area();
  77. double tri_area = 0.0;
  78. for( int ii = 0; ii < poly->TriangulatedPolyCount(); ii++ )
  79. {
  80. const auto tri_poly = poly->TriangulatedPolygon( ii );
  81. for( const auto& tri : tri_poly->Triangles() )
  82. tri_area += tri.Area();
  83. }
  84. double diff = std::abs( area - tri_area );
  85. // The difference should be less than 1e-3 square mm
  86. BOOST_CHECK_MESSAGE( diff < 1e9,
  87. "Triangulation area mismatch in " + relPath + " layer "
  88. + LayerName( layer )
  89. + " difference: " + std::to_string( diff ) );
  90. }
  91. }
  92. }
  93. }