mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2024-11-28 00:31:20 +00:00
b2be0d39bd
This is a pretty major rework of the snapping system. The GRID_HELPERs now have a separate CONSTRUCTION_MANAGER which handles some of the state involving "construction geometry". This is fed with 'extended' geometry (e.g. "infinite" lines from segments) for use in generating things like intersection points. It also handles adding this geoemtry to a GAL view item (CONSTRUCTION_GEOM) for display to the user. The process is: * A TOOL creates a GRID_HELPER * Optionally, it pre-loads a "persistent" batch of construction geometry (e.g. for an item's original position) * The grid helper finds useful snap 'anchors' as before, including those involving the construction items. * Other items on the board can be 'activated' by snapping to one of their main points. Then, if it has construction geometry, it will be added to the display. At most 2 items of this kind of geometry are shown, plus the original item, to reduce avoid too much clutter. The dashed snap lines state machine is also handled in the CONSTRUCTION_MANAGER and displayed in the CONSTRUCTION_GEOM item.
135 lines
4.7 KiB
C++
135 lines
4.7 KiB
C++
/*
|
|
* 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;
|
|
|
|
/**
|
|
* Represent basic circle geometry with utility geometry functions.
|
|
*/
|
|
class CIRCLE
|
|
{
|
|
public:
|
|
CIRCLE();
|
|
|
|
CIRCLE( const VECTOR2I& aCenter, int aRadius );
|
|
|
|
CIRCLE( const CIRCLE& aOther );
|
|
|
|
bool operator==( const CIRCLE& aOther ) const = default;
|
|
|
|
/**
|
|
* Construct this circle such that it is tangent to the given segments and passes through the
|
|
* given point, generating the solution which can be used to fillet both segments.
|
|
*
|
|
* The caller is responsible for ensuring it is providing a solvable problem. This function will
|
|
* assert if this is not the case.
|
|
*
|
|
* @param aLineA is the first tangent line. Treated as an infinite line except for the purpose
|
|
* of selecting the solution to return.
|
|
* @param aLineB is the second tangent line. Treated as an infinite line except for the purpose
|
|
* of selecting the solution to return.
|
|
* @param aP is the point to pass through.
|
|
* @return this circle.
|
|
*/
|
|
CIRCLE& ConstructFromTanTanPt( const SEG& aLineA, const SEG& aLineB, const VECTOR2I& aP );
|
|
|
|
/**
|
|
* 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;
|
|
|
|
/**
|
|
* Compute the point 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.
|
|
*/
|
|
VECTOR2I NearestPoint( const VECTOR2I& aP ) const;
|
|
|
|
/**
|
|
* 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;
|
|
|
|
/**
|
|
* Compute the intersection points between this circle and \a aCircle.
|
|
*
|
|
* @param aCircle The other circle to intersect with this.
|
|
* @return std::vector containing:
|
|
* - 0 elements if the circles do not intersect.
|
|
* - 1 element if the circles are tangent.
|
|
* - 2 elements if the circles intersect.
|
|
*/
|
|
std::vector<VECTOR2I> Intersect( const CIRCLE& aCircle ) const;
|
|
|
|
/**
|
|
* Compute the intersection points between this circle and \a aSeg.
|
|
*
|
|
* @param aSeg The segment to intersect with this circle (end points ignored).
|
|
* @return std::vector containing up to two intersection points.
|
|
*/
|
|
std::vector<VECTOR2I> Intersect( const SEG& aSeg ) const;
|
|
|
|
/**
|
|
* Compute the intersection points between this circle and aLine.
|
|
*
|
|
* @param aLine The line to intersect with this circle (end points ignored).
|
|
* @return std::vector containing:
|
|
* - 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.
|
|
*/
|
|
std::vector<VECTOR2I> IntersectLine( const SEG& aLine ) const;
|
|
|
|
/**
|
|
* Check whether point aP is inside this circle.
|
|
*
|
|
* @param aP The point to check.
|
|
* @return true if the point is inside, false otherwise.
|
|
*/
|
|
bool Contains( const VECTOR2I& aP );
|
|
|
|
int Radius; ///< Public to make access simpler
|
|
VECTOR2I Center; ///< Public to make access simpler
|
|
};
|
|
|
|
#endif // __CIRCLE_H
|
|
|