KiCad PCB EDA Suite
test_shape_poly_set_distance.cpp File Reference

Go to the source code of this file.

Classes

struct  SPS_DISTANCE_TO_SEG_CASE
 Declares the Boost test suite fixture. More...
 

Functions

static constexpr int Millimeter2iu (double mm)
 
static std::vector< SPS_DISTANCE_TO_SEG_CASEGetSPSSegDistCases ()
 
 BOOST_AUTO_TEST_CASE (SegDistance)
 Check segment distances. More...
 

Variables

static constexpr double IU_PER_MM = 1e3
 Mock up a conversion function. More...
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE()

BOOST_AUTO_TEST_CASE ( SegDistance  )

Check segment distances.

Definition at line 144 of file test_shape_poly_set_distance.cpp.

145 {
146  for( const auto& c : GetSPSSegDistCases() )
147  {
148  BOOST_TEST_CONTEXT( c.m_case_name )
149  {
150  SHAPE_POLY_SET polyset = c.m_polyset;
151 
152  int dist = sqrt( polyset.SquaredDistance( c.m_seg ) ) - ( c.m_seg_width / 2 );
153 
154  // right answer?
155  BOOST_CHECK_PREDICATE( KI_TEST::IsWithin<int>, ( dist )( c.m_exp_dist )( 1 ) );
156  }
157  }
158 }
SEG::ecoord SquaredDistance(VECTOR2I aPoint) const
Function SquaredDistance computes the minimum distance squared between aPoint and all the polygons in...
SHAPE_POLY_SET.
#define BOOST_TEST_CONTEXT(A)
static std::vector< SPS_DISTANCE_TO_SEG_CASE > GetSPSSegDistCases()

References BOOST_TEST_CONTEXT, GetSPSSegDistCases(), and SHAPE_POLY_SET::SquaredDistance().

◆ GetSPSSegDistCases()

static std::vector<SPS_DISTANCE_TO_SEG_CASE> GetSPSSegDistCases ( )
static

Definition at line 65 of file test_shape_poly_set_distance.cpp.

66 {
67  namespace KT = KI_TEST;
68  std::vector<SPS_DISTANCE_TO_SEG_CASE> cases;
69 
70  // Single 10mm square at origin
71  const SHAPE_POLY_SET square_10mm_0_0 = KT::BuildPolyset( {
73  } );
74 
75  // Double square: 10mm each, one at (0, 0), one at (10, 0)
76  const SHAPE_POLY_SET squares_10mm_0_0_and_20_0 = KT::BuildPolyset( {
79  { Millimeter2iu( 20 ), Millimeter2iu( 0 ) } ),
80  } );
81 
82  // Hollow square: 10mm hole in 20mm square, at origin
83  const SHAPE_POLY_SET hollow_square_20_10_at_0_0 =
85 
86  cases.push_back( {
87  "Square poly -> 1D segment",
88  square_10mm_0_0,
89  KT::BuildHSeg( { Millimeter2iu( 0 ), Millimeter2iu( 15 ) }, Millimeter2iu( 10 ) ),
90  Millimeter2iu( 0 ), // 1-d segment
91  Millimeter2iu( 10 ),
92  } );
93 
94  cases.push_back( {
95  "Square poly -> 2D (thick) segment",
96  square_10mm_0_0,
97  KT::BuildHSeg( { Millimeter2iu( 0 ), Millimeter2iu( 15 ) }, Millimeter2iu( 10 ) ),
98  Millimeter2iu( 2 ), // thick segment
99  Millimeter2iu( 9 ),
100  } );
101 
102  cases.push_back( {
103  "Two Squares poly -> 2D segment (nearest second square)", squares_10mm_0_0_and_20_0,
104  KT::BuildHSeg( { Millimeter2iu( 15 ), Millimeter2iu( 15 ) }, Millimeter2iu( 10 ) ),
105  Millimeter2iu( 2 ), // thick segment
106  Millimeter2iu( 9 ), // from line to second square
107  } );
108 
109  cases.push_back( {
110  "Square poly -> one intersect", square_10mm_0_0,
111  KT::BuildHSeg( { Millimeter2iu( -5 ), Millimeter2iu( 0 ) }, Millimeter2iu( 10 ) ),
112  Millimeter2iu( 0 ), // 1-d segment
113  Millimeter2iu( 0 ), // intersect
114  } );
115 
116  cases.push_back( {
117  "Square poly -> multiple intersection", square_10mm_0_0,
118  KT::BuildHSeg( { Millimeter2iu( -5 ), Millimeter2iu( 0 ) }, Millimeter2iu( 20 ) ),
119  Millimeter2iu( 0 ), // 1-d segment
120  Millimeter2iu( 0 ), // intersect
121  } );
122 
123  cases.push_back( {
124  "Square poly -> 1D seg touching", square_10mm_0_0,
125  // touch left side at (-5, 0)
126  KT::BuildHSeg( { Millimeter2iu( -10 ), Millimeter2iu( 0 ) }, Millimeter2iu( 5 ) ),
127  Millimeter2iu( 0 ), // 2D segment
128  Millimeter2iu( 0 ), // intersect
129  } );
130 
131  cases.push_back( {
132  "Square poly -> 2D seg (end cap is nearest)", square_10mm_0_0,
133  KT::BuildHSeg( { Millimeter2iu( -20 ), Millimeter2iu( 0 ) }, Millimeter2iu( 10 ) ),
134  Millimeter2iu( 2 ), // 2D segment, 1mm cap radius
135  Millimeter2iu( 4 ), // 4mm short, 5mm to wire end, -1mm radius
136  } );
137 
138  return cases;
139 };
SHAPE_POLY_SET BuildHollowSquare(int aOuterSize, int aInnerSize, const VECTOR2I &aCentre)
Build a SHAPE_POLY_SET in the shape of a square outline, with a square hole, both centred at the give...
SHAPE_POLY_SET.
SHAPE_LINE_CHAIN BuildSquareChain(int aSize, const VECTOR2I &aCentre)
Builds a square SHAPE_LINE_CHAIN of a certain size at a certain centre.
SHAPE_POLY_SET BuildPolyset(const std::vector< SHAPE_LINE_CHAIN > &aOutlines)
Construct a SHAPE_POLY_SET from a list of points for each of outlines (no holes)
SEG BuildHSeg(const VECTOR2I &aStart, int aLength)
Build a horizontal segment from a point with a length.
static constexpr int Millimeter2iu(double mm)

References KI_TEST::BuildHollowSquare(), KI_TEST::BuildHSeg(), KI_TEST::BuildPolyset(), KI_TEST::BuildSquareChain(), and Millimeter2iu().

Referenced by BOOST_AUTO_TEST_CASE().

◆ Millimeter2iu()

static constexpr int Millimeter2iu ( double  mm)
inlinestatic

Definition at line 39 of file test_shape_poly_set_distance.cpp.

40 {
41  return (int) ( mm < 0 ? mm * IU_PER_MM - 0.5 : mm * IU_PER_MM + 0.5 );
42 }
static constexpr double IU_PER_MM
Mock up a conversion function.

References IU_PER_MM.

Referenced by ZONE_FILLER::addHatchFillTypeOnZone(), AddRectCourtyard(), PCAD2KICAD::PCB_PAD::AddToModule(), AR_AUTOPLACER::AR_AUTOPLACER(), AR_AUTOPLACER::AutoplaceModules(), BOARD_DESIGN_SETTINGS::BOARD_DESIGN_SETTINGS(), BOOST_AUTO_TEST_CASE(), BuildBoardPolygonOutlines(), ZONE_FILLER::buildCopperItemClearances(), BOARD_STACKUP::BuildDefaultStackupList(), MODULE::BuildPolyCourtyard(), compute_layer_Zs(), ZONE_FILLER::computeRawFilledArea(), BOARD_ADAPTER::createNewTrack(), PLACEFILE_GERBER_WRITER::CreatePlaceFile(), PL_DRAW_PANEL_GAL::DisplayWorksheet(), KIGFX::SCH_PAINTER::draw(), DRAWSEGMENT::DRAWSEGMENT(), BOARD_NETLIST_UPDATER::estimateComponentInsertionPosition(), ZONE_FILLER::fillSingleZone(), FOOTPRINT_EDITOR_SETTINGS::FOOTPRINT_EDITOR_SETTINGS(), GENDRILL_WRITER_BASE::genDrillMapFile(), C3D_RENDER_OGL_LEGACY::generate_new_3DGrid(), PCB_GROUP::GetBoundingBox(), MODULE::GetBoundingPoly(), BOARD_STACKUP_ITEM::GetCopperDefaultThickness(), FOOTPRINT_EDIT_FRAME::GetDocumentExtents(), BOARD_DESIGN_SETTINGS::GetDRCEpsilon(), MODULE::GetFootprintRect(), BOARD_DESIGN_SETTINGS::GetHolePlatingThickness(), ZONE_CONTAINER::GetInteractingZones(), BOARD_STACKUP_ITEM::GetMaskDefaultThickness(), GetSPSSegDistCases(), GRAPHICS_IMPORTER_PCBNEW::GRAPHICS_IMPORTER_PCBNEW(), GERBER_DRAW_ITEM::HitTest(), ZONE_CONTAINER::HitTest(), BOARD_ADAPTER::InitSettings(), LIB_EDIT_FRAME::LIB_EDIT_FRAME(), LIB_VIEW_FRAME::LIB_VIEW_FRAME(), PCB_EDIT_FRAME::LoadSettings(), MakeInvalidCourtyardTestModule(), DIALOG_EXPORT_STEP::onExportButton(), DIALOG_PAD_PRIMITIVE_POLY_PROPS::onPaintPolyPanel(), EAGLE_PLUGIN::packageWire(), PCB_PARSER::parseDRAWSEGMENT(), PCB_PARSER::parseEDGE_MODULE(), PCB_PLOT_PARAMS::PCB_PLOT_PARAMS(), PCB_TARGET::PCB_TARGET(), PCB_EDITOR_CONTROL::PlaceTarget(), PlotSolderMaskLayer(), PNS_PCBNEW_RULE_RESOLVER::PNS_PCBNEW_RULE_RESOLVER(), DIALOG_PAD_PROPERTIES::prepareCanvas(), LIB_PIN::printPinElectricalTypeName(), PAD_TOOL::recombinePad(), DIALOG_PLOT_SCHEMATIC::SetHPGLPenWidth(), PCBNEW_PRINTOUT::setupPainter(), SpreadFootprints(), PCAD2KICAD::StrToDoublePrecisionUnits(), TEXTE_MODULE::TEXTE_MODULE(), TRACK::TRACK(), DIALOG_NON_COPPER_ZONES_EDITOR::TransferDataToWindow(), DIALOG_COPPER_ZONE::TransferDataToWindow(), EDA_TEXT::TransformBoundingBoxWithClearanceToPolygon(), TRACK::ViewGetLOD(), GERBER_DRAW_ITEM::ViewGetLOD(), VIA::ViewGetLOD(), D_PAD::ViewGetLOD(), and write_layers().

Variable Documentation

◆ IU_PER_MM

constexpr double IU_PER_MM = 1e3
static

Mock up a conversion function.

Definition at line 37 of file test_shape_poly_set_distance.cpp.

Referenced by ZONE_FILLER::buildThermalSpokes(), diameter_in_mm(), PANEL_PREV_3D::doIncrementOffset(), PAD_TOOL::EnumeratePads(), FillNegativeKnockout(), PCB_PLOT_PARAMS::Format(), PCB_IO::format(), FormatInternalUnits(), GENDRILL_WRITER_BASE::genDrillMapFile(), C3D_RENDER_OGL_LEGACY::generate_new_3DGrid(), GERBER_JOBFILE_WRITER::GERBER_JOBFILE_WRITER(), GERBVIEW_DRAW_PANEL_GAL::GERBVIEW_DRAW_PANEL_GAL(), DIALOG_BOARD_STATISTICS::getDataFromPCB(), DIALOG_PLOT_SCHEMATIC::getPlotOptions(), LEGACY_PLUGIN::init(), DIALOG_PLOT::init_Dialog(), DIALOG_PLOT_SCHEMATIC::initDlg(), DSN::IU2um(), GERBVIEW_FRAME::Liste_D_Codes(), LEGACY_PLUGIN::loadGENERAL(), DSN::SPECCTRA_DB::makeVIA(), GBR_TO_PCB_EXPORTER::MapToPcbUnits(), Millimeter2iu(), PANEL_PREV_3D::onMouseWheelOffset(), PCB_PARSER::parseBoardUnits(), PCB_PARSER::parseEDA_TEXT(), SCH_SEXPR_PARSER::parseInternalUnits(), PCB_PARSER::parseZONE_CONTAINER(), PL_DRAW_PANEL_GAL::PL_DRAW_PANEL_GAL(), PLACEFILE_GERBER_WRITER::PLACEFILE_GERBER_WRITER(), PlotSolderMaskLayer(), DIALOG_PAD_PROPERTIES::prepareCanvas(), LP_CACHE::ReadAndVerifyHeader(), MWAVE_POLYGONAL_SHAPE_DLG::ReadDataShapeDescr(), DSN::scale(), scaletoIU(), KIGFX::SCH_RENDER_SETTINGS::SCH_RENDER_SETTINGS(), GERBER_WRITER::SetFormat(), EXCELLON_WRITER::SetFormat(), GERBVIEW_PRINTOUT::setupGal(), C3D_RENDER_RAYTRACING::setupMaterials(), PL_DRAW_PANEL_GAL::SwitchBackend(), GERBVIEW_DRAW_PANEL_GAL::SwitchBackend(), PANEL_SETUP_FEATURE_CONSTRAINTS::TransferDataFromWindow(), GERBVIEW_FRAME::updateDCodeSelectBox(), PANEL_PREV_3D::updateOrientation(), and PCB_EDITOR_CONTROL::ZoneDuplicate().