KiCad PCB EDA Suite
Loading...
Searching...
No Matches
snap_manifold.h
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 3
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
20#ifndef SNAP_MANIFOLD_H
21#define SNAP_MANIFOLD_H
22
24#include <math/vector2d.h>
25
26#include <cmath>
27#include <type_traits>
28#include <variant>
29
36inline double snapManifoldDistance( const INTERSECTABLE_GEOM& aGeometry, const VECTOR2I& aPoint )
37{
38 return std::visit(
39 [&]( const auto& aShape ) -> double
40 {
41 using MANIFOLD_TYPE = std::decay_t<decltype( aShape )>;
42
43 if constexpr( std::is_same_v<MANIFOLD_TYPE, LINE> )
44 return aShape.Distance( aPoint );
45 else if constexpr( std::is_same_v<MANIFOLD_TYPE, HALF_LINE> )
46 return aShape.NearestPoint( aPoint ).Distance( aPoint );
47 else if constexpr( std::is_same_v<MANIFOLD_TYPE, SEG> )
48 return aShape.Distance( aPoint );
49 else if constexpr( std::is_same_v<MANIFOLD_TYPE, CIRCLE> )
50 return std::abs( aShape.Center.Distance( aPoint ) - aShape.Radius );
51 else if constexpr( std::is_same_v<MANIFOLD_TYPE, SHAPE_ARC> )
52 return aShape.NearestPoint( aPoint ).Distance( aPoint );
53 else
54 return aShape.Distance( aPoint );
55 },
56 aGeometry );
57}
58
59#endif
std::variant< LINE, HALF_LINE, SEG, CIRCLE, SHAPE_ARC, BOX2I > INTERSECTABLE_GEOM
A variant type that can hold any of the supported geometry types for intersection calculations.
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition eda_angle.h:400
double snapManifoldDistance(const INTERSECTABLE_GEOM &aGeometry, const VECTOR2I &aPoint)
Distance from a point to the nearest point of a snap manifold shape.
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683