Debian Codegraph @

3rd_party/router/kimath/include/geometry/circle.h

raw
1 /*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2021 Roberto Fernandez Bautista <[email protected]>
5 * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #ifndef __CIRCLE_H
22 #define __CIRCLE_H
23
24 #include <math/vector2d.h> // for VECTOR2I
25 #include <vector> // for std::vector
26
27 class SEG;
28
29 /**
30 * Represent basic circle geometry with utility geometry functions.
31 */
32 class CIRCLE
33 {
34 public:
35 CIRCLE();
36
37 CIRCLE( const VECTOR2I& aCenter, int aRadius );
38
39 CIRCLE( const CIRCLE& aOther );
40
41 /**
42 * Construct this circle such that it is tangent to the given segments and passes through the
43 * given point, generating the solution which can be used to fillet both segments.
44 *
45 * The caller is responsible for ensuring it is providing a solvable problem. This function will
46 * assert if this is not the case.
47 *
48 * @param aLineA is the first tangent line. Treated as an infinite line except for the purpose
49 * of selecting the solution to return.
50 * @param aLineB is the second tangent line. Treated as an infinite line except for the purpose
51 * of selecting the solution to return.
52 * @param aP is the point to pass through.
53 * @return this circle.
54 */
55 CIRCLE& ConstructFromTanTanPt( const SEG& aLineA, const SEG& aLineB, const VECTOR2I& aP );
56
57 /**
58 * Return true if aP is on the circumference of this circle. Note that there is an accepted
59 * margin of error of SHAPE::MIN_PRECISION_IU to account for integer rounding errors.
60 *
61 * @param aP A point to test
62 * @return true if aP is on the circumference.
63 */
64 bool Contains( const VECTOR2I& aP ) const;
65
66 /**
67 * Compute the point on the circumference of the circle that is the closest to aP.
68 *
69 * In other words: finds the intersection point of this circle and a line that passes through
70 * both this circle's center and aP.
71 *
72 * @param aP.
73 * @return nearest point to aP.
74 */
75 VECTOR2I NearestPoint( const VECTOR2I& aP ) const;
76
77 /**
78 * Compute the intersection points between this circle and \a aCircle.
79 *
80 * @param aCircle The other circle to intersect with this.
81 * @return std::vector containing:
82 * - 0 elements if the circles do not intersect.
83 * - 1 element if the circles are tangent.
84 * - 2 elements if the circles intersect.
85 */
86 std::vector<VECTOR2I> Intersect( const CIRCLE& aCircle ) const;
87
88 /**
89 * Compute the intersection points between this circle and \a aSeg.
90 *
91 * @param aSeg The segment to intersect with this circle (end points ignored).
92 * @return std::vector containing up to two intersection points.
93 */
94 std::vector<VECTOR2I> Intersect( const SEG& aSeg ) const;
95
96 /**
97 * Compute the intersection points between this circle and aLine.
98 *
99 * @param aLine The line to intersect with this circle (end points ignored).
100 * @return std::vector containing:
101 * - 0 elements if there is no intersection.
102 * - 1 element if the line is tangent to the circle.
103 * - 2 elements if the line intersects the circle.
104 */
105 std::vector<VECTOR2I> IntersectLine( const SEG& aLine ) const;
106
107 /**
108 * Check whether point aP is inside this circle.
109 *
110 * @param aP The point to check.
111 * @return true if the point is inside, false otherwise.
112 */
113 bool Contains( const VECTOR2I& aP );
114
115 int Radius; ///< Public to make access simpler
116 VECTOR2I Center; ///< Public to make access simpler
117 };
118
119 #endif // __CIRCLE_H
120