KiCad PCB EDA Suite
Loading...
Searching...
No Matches
nearest.h File Reference
#include <variant>
#include <vector>
#include <math/vector2d.h>
#include <math/box2.h>
#include <geometry/circle.h>
#include <geometry/half_line.h>
#include <geometry/line.h>
#include <geometry/seg.h>
#include <geometry/shape_arc.h>

Go to the source code of this file.

Typedefs

using NEARABLE_GEOM = std::variant< LINE, HALF_LINE, SEG, CIRCLE, SHAPE_ARC, BOX2I, VECTOR2I >
 A variant type that can hold any of the supported geometry types for nearest point calculations.
 

Functions

VECTOR2I GetNearestPoint (const NEARABLE_GEOM &aGeom, const VECTOR2I &aPt)
 Get the nearest point on a geometry to a given point.
 
OPT_VECTOR2I GetNearestPoint (const std::vector< NEARABLE_GEOM > &aGeoms, const VECTOR2I &aPt)
 Get the nearest point on any of a list of geometries to a given point.
 

Typedef Documentation

◆ NEARABLE_GEOM

A variant type that can hold any of the supported geometry types for nearest point calculations.

Definition at line 43 of file nearest.h.

Function Documentation

◆ GetNearestPoint() [1/2]

VECTOR2I GetNearestPoint ( const NEARABLE_GEOM aGeom,
const VECTOR2I aPt 
)

Get the nearest point on a geometry to a given point.

Definition at line 58 of file nearest.cpp.

Referenced by PCB_GRID_HELPER::BestSnapAnchor(), and GetNearestPoint().

◆ GetNearestPoint() [2/2]

OPT_VECTOR2I GetNearestPoint ( const std::vector< NEARABLE_GEOM > &  aGeoms,
const VECTOR2I aPt 
)

Get the nearest point on any of a list of geometries to a given point.

Parameters
aGeomsThe geometries to check.
aPtThe point to find the nearest point to.
Returns
The nearest point on any of the geometries to the given point (or std::nullopt if no geometries were provided).

Definition at line 96 of file nearest.cpp.

References VECTOR2< T >::Distance(), and GetNearestPoint().