2021-01-03 01:21:20 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2021 Roberto Fernandez Bautista <roberto.fer.bau@gmail.com>
|
|
|
|
* Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation, either version 3 of the License, or (at your
|
|
|
|
* option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __CIRCLE_H
|
|
|
|
#define __CIRCLE_H
|
|
|
|
|
|
|
|
#include <math/vector2d.h> // for VECTOR2I
|
|
|
|
#include <vector> // for std::vector
|
|
|
|
|
|
|
|
class SEG;
|
|
|
|
|
|
|
|
/**
|
2021-07-01 17:46:17 +00:00
|
|
|
* Represent basic circle geometry with utility geometry functions.
|
2021-01-03 01:21:20 +00:00
|
|
|
*/
|
|
|
|
class CIRCLE
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CIRCLE();
|
|
|
|
|
|
|
|
CIRCLE( const VECTOR2I& aCenter, int aRadius );
|
|
|
|
|
|
|
|
CIRCLE( const CIRCLE& aOther );
|
|
|
|
|
|
|
|
/**
|
2021-07-01 17:46:17 +00:00
|
|
|
* Construct this circle such that it is tangent to the given segments and passes through the
|
2021-01-11 21:06:00 +00:00
|
|
|
* given point, generating the solution which can be used to fillet both segments.
|
2021-01-10 13:04:21 +00:00
|
|
|
*
|
2021-01-11 21:06:00 +00:00
|
|
|
* The caller is responsible for ensuring it is providing a solvable problem. This function will
|
|
|
|
* assert if this is not the case.
|
2021-01-03 01:21:20 +00:00
|
|
|
*
|
|
|
|
* @param aLineA is the first tangent line. Treated as an infinite line except for the purpose
|
2021-07-01 17:46:17 +00:00
|
|
|
* of selecting the solution to return.
|
2021-01-03 01:21:20 +00:00
|
|
|
* @param aLineB is the second tangent line. Treated as an infinite line except for the purpose
|
2021-07-01 17:46:17 +00:00
|
|
|
* of selecting the solution to return.
|
|
|
|
* @param aP is the point to pass through.
|
|
|
|
* @return this circle.
|
2021-01-03 01:21:20 +00:00
|
|
|
*/
|
2021-01-11 21:06:00 +00:00
|
|
|
CIRCLE& ConstructFromTanTanPt( const SEG& aLineA, const SEG& aLineB, const VECTOR2I& aP );
|
2021-01-03 01:21:20 +00:00
|
|
|
|
2021-03-01 20:38:55 +00:00
|
|
|
/**
|
|
|
|
* Return true if aP is on the circumference of this circle. Note that there is an accepted
|
|
|
|
* margin of error of SHAPE::MIN_PRECISION_IU to account for integer rounding errors.
|
|
|
|
*
|
|
|
|
* @param aP A point to test
|
|
|
|
* @return true if aP is on the circumference.
|
|
|
|
*/
|
|
|
|
bool Contains( const VECTOR2I& aP ) const;
|
|
|
|
|
2021-01-03 01:21:20 +00:00
|
|
|
/**
|
2021-07-01 17:46:17 +00:00
|
|
|
* Compute the point on the circumference of the circle that is the closest to aP.
|
2021-01-03 01:21:20 +00:00
|
|
|
*
|
|
|
|
* In other words: finds the intersection point of this circle and a line that passes through
|
|
|
|
* both this circle's center and aP.
|
2021-01-10 13:04:21 +00:00
|
|
|
*
|
2021-07-01 17:46:17 +00:00
|
|
|
* @param aP.
|
|
|
|
* @return nearest point to aP.
|
2021-01-03 01:21:20 +00:00
|
|
|
*/
|
|
|
|
VECTOR2I NearestPoint( const VECTOR2I& aP ) const;
|
|
|
|
|
2024-06-03 23:28:44 +00:00
|
|
|
/**
|
|
|
|
* Compute the point (floating point version) on the circumference of the circle that
|
|
|
|
* is the closest to aP.
|
|
|
|
*
|
|
|
|
* In other words: finds the intersection point of this circle and a line that passes through
|
|
|
|
* both this circle's center and aP.
|
|
|
|
*
|
|
|
|
* @param aP.
|
|
|
|
* @return nearest point to aP.
|
|
|
|
*/
|
|
|
|
VECTOR2D NearestPoint( const VECTOR2D& aP ) const;
|
|
|
|
|
2021-01-03 01:21:20 +00:00
|
|
|
/**
|
2021-07-01 17:46:17 +00:00
|
|
|
* Compute the intersection points between this circle and \a aCircle.
|
2021-01-10 13:04:21 +00:00
|
|
|
*
|
2021-07-01 17:46:17 +00:00
|
|
|
* @param aCircle The other circle to intersect with this.
|
2021-01-03 01:21:20 +00:00
|
|
|
* @return std::vector containing:
|
2021-07-01 17:46:17 +00:00
|
|
|
* - 0 elements if the circles do not intersect.
|
|
|
|
* - 1 element if the circles are tangent.
|
|
|
|
* - 2 elements if the circles intersect.
|
2021-01-03 01:21:20 +00:00
|
|
|
*/
|
|
|
|
std::vector<VECTOR2I> Intersect( const CIRCLE& aCircle ) const;
|
|
|
|
|
|
|
|
/**
|
2021-07-01 17:46:17 +00:00
|
|
|
* Compute the intersection points between this circle and \a aSeg.
|
2021-03-05 23:10:18 +00:00
|
|
|
*
|
2021-07-01 17:46:17 +00:00
|
|
|
* @param aSeg The segment to intersect with this circle (end points ignored).
|
|
|
|
* @return std::vector containing up to two intersection points.
|
2021-03-05 23:10:18 +00:00
|
|
|
*/
|
|
|
|
std::vector<VECTOR2I> Intersect( const SEG& aSeg ) const;
|
|
|
|
|
|
|
|
/**
|
2021-07-01 17:46:17 +00:00
|
|
|
* Compute the intersection points between this circle and aLine.
|
2021-03-05 23:10:18 +00:00
|
|
|
*
|
2021-07-01 17:46:17 +00:00
|
|
|
* @param aLine The line to intersect with this circle (end points ignored).
|
2021-01-03 01:21:20 +00:00
|
|
|
* @return std::vector containing:
|
2021-07-01 17:46:17 +00:00
|
|
|
* - 0 elements if there is no intersection.
|
|
|
|
* - 1 element if the line is tangent to the circle.
|
|
|
|
* - 2 elements if the line intersects the circle.
|
2021-01-03 01:21:20 +00:00
|
|
|
*/
|
2021-03-05 23:10:18 +00:00
|
|
|
std::vector<VECTOR2I> IntersectLine( const SEG& aLine ) const;
|
|
|
|
|
|
|
|
/**
|
2021-07-01 17:46:17 +00:00
|
|
|
* Check whether point aP is inside this circle.
|
2021-03-05 23:10:18 +00:00
|
|
|
*
|
2021-07-01 17:46:17 +00:00
|
|
|
* @param aP The point to check.
|
|
|
|
* @return true if the point is inside, false otherwise.
|
2021-03-05 23:10:18 +00:00
|
|
|
*/
|
|
|
|
bool Contains( const VECTOR2I& aP );
|
2021-07-01 17:46:17 +00:00
|
|
|
|
|
|
|
int Radius; ///< Public to make access simpler
|
|
|
|
VECTOR2I Center; ///< Public to make access simpler
|
2021-01-03 01:21:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // __CIRCLE_H
|
|
|
|
|