2018-02-04 12:09:30 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2018-02-18 20:00:28 +00:00
|
|
|
* Copyright (C) 2018 CERN
|
2022-01-14 15:34:41 +00:00
|
|
|
* Copyright (C) 2019-2022 KiCad Developers, see AUTHORS.txt for contributors.
|
2018-02-04 12:09:30 +00:00
|
|
|
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
|
|
|
|
*
|
|
|
|
* 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 2
|
|
|
|
* 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, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __SHAPE_ARC_H
|
|
|
|
#define __SHAPE_ARC_H
|
|
|
|
|
2020-01-07 17:12:59 +00:00
|
|
|
#include <geometry/shape.h>
|
2022-09-17 01:07:36 +00:00
|
|
|
#include <base_units.h>
|
2020-01-07 17:12:59 +00:00
|
|
|
#include <math/vector2d.h> // for VECTOR2I
|
2022-01-15 01:12:24 +00:00
|
|
|
#include <geometry/eda_angle.h>
|
2018-02-04 12:09:30 +00:00
|
|
|
|
|
|
|
class SHAPE_LINE_CHAIN;
|
|
|
|
|
|
|
|
class SHAPE_ARC : public SHAPE
|
|
|
|
{
|
|
|
|
public:
|
2020-10-20 21:23:05 +00:00
|
|
|
|
2018-02-04 12:09:30 +00:00
|
|
|
SHAPE_ARC() :
|
2020-12-12 03:43:16 +00:00
|
|
|
SHAPE( SH_ARC ),
|
|
|
|
m_width( 0 )
|
|
|
|
{};
|
2018-02-04 12:09:30 +00:00
|
|
|
|
2020-01-03 13:27:00 +00:00
|
|
|
/**
|
2021-07-01 17:46:17 +00:00
|
|
|
* Construct and arc using center, start, angle.
|
|
|
|
*
|
|
|
|
* Center and angle are used to calculate the mid and end points of the arc, and are not
|
|
|
|
* stored.
|
|
|
|
*
|
|
|
|
* @param aArcCenter is the arc center.
|
|
|
|
* @param aArcStartPoint is the arc start point.
|
2022-01-14 15:34:41 +00:00
|
|
|
* @param aCenterAngle is the arc angle.
|
2021-07-01 17:46:17 +00:00
|
|
|
* @param aWidth is the arc line thickness.
|
2020-01-03 13:27:00 +00:00
|
|
|
*/
|
2022-01-14 15:34:41 +00:00
|
|
|
SHAPE_ARC( const VECTOR2I& aArcCenter, const VECTOR2I& aArcStartPoint,
|
|
|
|
const EDA_ANGLE& aCenterAngle, int aWidth = 0 );
|
2018-02-04 12:09:30 +00:00
|
|
|
|
2020-06-12 21:58:24 +00:00
|
|
|
/**
|
2021-07-01 17:46:17 +00:00
|
|
|
* @param aArcStart is the arc start point.
|
|
|
|
* @param aArcEnd is the arc end point.
|
|
|
|
* @param aArcMid is the arc mid point.
|
|
|
|
* @param aWidth is the arc line thickness.
|
2020-06-12 21:58:24 +00:00
|
|
|
*/
|
2020-12-12 03:43:16 +00:00
|
|
|
SHAPE_ARC( const VECTOR2I& aArcStart, const VECTOR2I& aArcMid, const VECTOR2I& aArcEnd,
|
|
|
|
int aWidth );
|
2021-06-26 11:18:46 +00:00
|
|
|
|
2020-10-20 21:23:05 +00:00
|
|
|
/**
|
2021-07-01 17:46:17 +00:00
|
|
|
* Build a SHAPE_ARC which is tangent to two segments and a given radius.
|
|
|
|
*
|
2020-10-20 21:23:05 +00:00
|
|
|
* @param aSegmentA is the first segment
|
|
|
|
* @param aSegmentB is the second segment
|
|
|
|
* @param aRadius is the arc radius
|
|
|
|
* @param aWidth is the arc line thickness
|
|
|
|
*/
|
|
|
|
SHAPE_ARC( const SEG& aSegmentA, const SEG& aSegmentB, int aRadius, int aWidth = 0 );
|
2020-06-12 21:58:24 +00:00
|
|
|
|
|
|
|
SHAPE_ARC( const SHAPE_ARC& aOther );
|
2018-02-04 12:09:30 +00:00
|
|
|
|
2020-06-11 18:26:03 +00:00
|
|
|
virtual ~SHAPE_ARC() {}
|
2018-02-04 12:09:30 +00:00
|
|
|
|
|
|
|
SHAPE* Clone() const override
|
|
|
|
{
|
|
|
|
return new SHAPE_ARC( *this );
|
|
|
|
}
|
|
|
|
|
2020-12-31 16:56:49 +00:00
|
|
|
/**
|
2021-07-01 17:46:17 +00:00
|
|
|
* Construct this arc from the given start, end and angle.
|
|
|
|
*
|
2020-12-31 16:56:49 +00:00
|
|
|
* @param aStart is the arc starting point
|
|
|
|
* @param aEnd is the arc endpoint
|
|
|
|
* @param aAngle is the arc included angle
|
|
|
|
* @param aWidth is the arc line thickness
|
2021-07-01 17:46:17 +00:00
|
|
|
* @return this arc.
|
2020-12-31 16:56:49 +00:00
|
|
|
*/
|
|
|
|
SHAPE_ARC& ConstructFromStartEndAngle( const VECTOR2I& aStart, const VECTOR2I& aEnd,
|
2022-01-16 21:15:20 +00:00
|
|
|
const EDA_ANGLE& aAngle, double aWidth = 0 );
|
2020-12-31 16:56:49 +00:00
|
|
|
|
2021-05-09 22:27:02 +00:00
|
|
|
/**
|
|
|
|
* Constructs this arc from the given start, end and center.
|
|
|
|
* @param aStart is the arc starting point
|
|
|
|
* @param aEnd is the arc endpoint
|
|
|
|
* @param aCenter is the arc center
|
|
|
|
* @param aClockwise determines which of the two solutions to construct
|
|
|
|
* @param aWidth is the arc line thickness
|
|
|
|
* @return *this
|
|
|
|
*/
|
|
|
|
SHAPE_ARC& ConstructFromStartEndCenter( const VECTOR2I& aStart, const VECTOR2I& aEnd,
|
|
|
|
const VECTOR2I& aCenter, bool aClockwise = false,
|
|
|
|
double aWidth = 0 );
|
|
|
|
|
2020-06-12 21:58:24 +00:00
|
|
|
const VECTOR2I& GetP0() const { return m_start; }
|
|
|
|
const VECTOR2I& GetP1() const { return m_end; }
|
|
|
|
const VECTOR2I& GetArcMid() const { return m_mid; }
|
|
|
|
VECTOR2I GetCenter() const;
|
2018-02-04 12:09:30 +00:00
|
|
|
|
2018-04-19 20:20:25 +00:00
|
|
|
const BOX2I BBox( int aClearance = 0 ) const override;
|
2018-02-04 12:09:30 +00:00
|
|
|
|
2024-01-31 20:38:05 +00:00
|
|
|
VECTOR2I NearestPoint( const VECTOR2I& aP ) const;
|
|
|
|
|
2020-09-28 22:27:33 +00:00
|
|
|
bool Collide( const SEG& aSeg, int aClearance = 0, int* aActual = nullptr,
|
|
|
|
VECTOR2I* aLocation = nullptr ) const override;
|
|
|
|
bool Collide( const VECTOR2I& aP, int aClearance = 0, int* aActual = nullptr,
|
|
|
|
VECTOR2I* aLocation = nullptr ) const override;
|
2018-02-04 12:09:30 +00:00
|
|
|
|
2021-07-13 19:01:53 +00:00
|
|
|
|
|
|
|
bool Collide( const SHAPE* aShape, int aClearance = 0, int* aActual = nullptr,
|
|
|
|
VECTOR2I* aLocation = nullptr ) const override
|
|
|
|
{
|
|
|
|
return SHAPE::Collide( aShape, aClearance, aActual, aLocation );
|
|
|
|
}
|
|
|
|
|
2021-07-25 19:46:00 +00:00
|
|
|
/**
|
|
|
|
* Find intersection points between this arc and aSeg, treating aSeg as an infinite line.
|
|
|
|
* Ignores arc width.
|
|
|
|
*
|
|
|
|
* @param aSeg Line to intersect against (treated as an infinite line)
|
|
|
|
* @param aIpsBuffer Buffer to store the resulting intersection points (if any)
|
|
|
|
* @return Number of intersection points found
|
|
|
|
*/
|
|
|
|
int IntersectLine( const SEG& aSeg, std::vector<VECTOR2I>* aIpsBuffer ) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Find intersection points between this arc and aArc. Ignores arc width.
|
|
|
|
*
|
|
|
|
* @param aSeg
|
|
|
|
* @param aIpsBuffer Buffer to store the resulting intersection points (if any)
|
|
|
|
* @return Number of intersection points found
|
|
|
|
*/
|
|
|
|
int Intersect( const SHAPE_ARC& aArc, std::vector<VECTOR2I>* aIpsBuffer ) const;
|
|
|
|
|
2021-05-09 22:27:02 +00:00
|
|
|
bool IsClockwise() const;
|
|
|
|
|
2018-02-04 12:09:30 +00:00
|
|
|
void SetWidth( int aWidth )
|
|
|
|
{
|
|
|
|
m_width = aWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
int GetWidth() const
|
|
|
|
{
|
|
|
|
return m_width;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsSolid() const override
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-06-12 21:58:24 +00:00
|
|
|
void Move( const VECTOR2I& aVector ) override;
|
2018-02-04 12:09:30 +00:00
|
|
|
|
2019-03-26 02:55:59 +00:00
|
|
|
/**
|
2021-07-01 17:46:17 +00:00
|
|
|
* Rotate the arc by a given angle about a point.
|
|
|
|
*
|
|
|
|
* @param aCenter is the rotation center.
|
2022-01-20 20:54:22 +00:00
|
|
|
* @param aAngle rotation angle.
|
2019-03-26 02:55:59 +00:00
|
|
|
*/
|
2022-01-20 20:54:22 +00:00
|
|
|
void Rotate( const EDA_ANGLE& aAngle, const VECTOR2I& aCenter ) override;
|
2019-03-26 02:55:59 +00:00
|
|
|
|
2020-06-12 21:58:24 +00:00
|
|
|
void Mirror( bool aX = true, bool aY = false, const VECTOR2I& aVector = { 0, 0 } );
|
2019-03-26 02:55:59 +00:00
|
|
|
|
2021-04-11 12:28:32 +00:00
|
|
|
void Mirror( const SEG& axis );
|
|
|
|
|
2021-01-04 13:54:29 +00:00
|
|
|
void Reverse();
|
|
|
|
|
|
|
|
SHAPE_ARC Reversed() const;
|
|
|
|
|
2020-06-13 18:21:14 +00:00
|
|
|
double GetRadius() const;
|
2018-02-04 12:09:30 +00:00
|
|
|
|
|
|
|
SEG GetChord() const
|
|
|
|
{
|
2020-06-12 21:58:24 +00:00
|
|
|
return SEG( m_start, m_end );
|
2018-02-04 12:09:30 +00:00
|
|
|
}
|
|
|
|
|
2021-06-26 11:18:46 +00:00
|
|
|
/**
|
2022-01-15 12:52:20 +00:00
|
|
|
* @return the central angle of the arc shape, normalized between 0..360 deg.
|
2021-06-26 11:18:46 +00:00
|
|
|
*/
|
2022-01-15 12:52:20 +00:00
|
|
|
EDA_ANGLE GetCentralAngle() const;
|
2021-06-26 11:18:46 +00:00
|
|
|
|
|
|
|
/**
|
2022-01-15 12:52:20 +00:00
|
|
|
* @return the start angle of the arc shape, normalized between 0..360 deg.
|
2021-06-26 11:18:46 +00:00
|
|
|
*/
|
2022-01-15 12:52:20 +00:00
|
|
|
EDA_ANGLE GetStartAngle() const;
|
2021-06-26 11:18:46 +00:00
|
|
|
|
|
|
|
/**
|
2022-01-15 12:52:20 +00:00
|
|
|
* @return the end angle of the arc shape, normalized between 0..360 deg.
|
2021-06-26 11:18:46 +00:00
|
|
|
*/
|
2022-01-15 12:52:20 +00:00
|
|
|
EDA_ANGLE GetEndAngle() const;
|
2018-02-04 12:09:30 +00:00
|
|
|
|
2021-05-11 01:22:51 +00:00
|
|
|
/**
|
2021-07-01 17:46:17 +00:00
|
|
|
* @return the length of the arc shape.
|
2021-05-11 01:22:51 +00:00
|
|
|
*/
|
|
|
|
double GetLength() const;
|
|
|
|
|
2021-06-30 11:33:49 +00:00
|
|
|
/**
|
2021-07-01 17:46:17 +00:00
|
|
|
* @note The default is #ARC_HIGH_DEF in Pcbnew units. This is to allow common geometry
|
|
|
|
* collision functions. Other programs should call this using explicit accuracy
|
|
|
|
* values.
|
|
|
|
*
|
|
|
|
* @todo Unify KiCad internal units.
|
|
|
|
*
|
|
|
|
* @return a default accuracy value for ConvertToPolyline() to build the polyline.
|
2021-06-30 11:33:49 +00:00
|
|
|
*/
|
|
|
|
static double DefaultAccuracyForPCB(){ return 0.005 * PCB_IU_PER_MM; }
|
|
|
|
|
2018-05-16 20:06:44 +00:00
|
|
|
/**
|
2021-07-01 17:46:17 +00:00
|
|
|
* Construct a SHAPE_LINE_CHAIN of segments from a given arc.
|
|
|
|
*
|
|
|
|
* @note The default is #ARC_HIGH_DEF in Pcbnew units. This is to allow common geometry
|
|
|
|
* collision functions. Other programs should call this using explicit accuracy
|
|
|
|
* values.
|
|
|
|
*
|
|
|
|
* @todo Unify KiCad internal units.
|
|
|
|
*
|
|
|
|
* @param aAccuracy maximum divergence from true arc given in internal units.
|
|
|
|
* @param aEffectiveAccuracy is the actual divergence from true arc given.
|
2021-06-30 11:33:49 +00:00
|
|
|
* the approximation error is between -aEffectiveAccuracy/2 and +aEffectiveAccuracy/2
|
|
|
|
* in internal units
|
2021-07-01 17:46:17 +00:00
|
|
|
* @return a #SHAPE_LINE_CHAIN.
|
2018-05-16 20:06:44 +00:00
|
|
|
*/
|
2021-06-30 11:33:49 +00:00
|
|
|
const SHAPE_LINE_CHAIN ConvertToPolyline( double aAccuracy = DefaultAccuracyForPCB(),
|
|
|
|
double* aEffectiveAccuracy = nullptr ) const;
|
2018-02-04 12:09:30 +00:00
|
|
|
|
2021-03-14 20:28:49 +00:00
|
|
|
bool operator==( SHAPE_ARC const& aArc ) const
|
|
|
|
{
|
|
|
|
return ( aArc.m_start == m_start ) && ( aArc.m_end == m_end ) && ( aArc.m_mid == m_mid )
|
|
|
|
&& ( aArc.m_width == m_width );
|
|
|
|
}
|
|
|
|
|
2023-08-16 03:49:22 +00:00
|
|
|
void TransformToPolygon( SHAPE_POLY_SET& aBuffer, int aError,
|
|
|
|
ERROR_LOC aErrorLoc ) const override;
|
|
|
|
|
2018-02-04 12:09:30 +00:00
|
|
|
private:
|
|
|
|
bool ccw( const VECTOR2I& aA, const VECTOR2I& aB, const VECTOR2I& aC ) const
|
|
|
|
{
|
2020-10-05 10:41:14 +00:00
|
|
|
return ( ecoord{ aC.y } - aA.y ) * ( ecoord{ aB.x } - aA.x ) >
|
|
|
|
( ecoord{ aB.y } - aA.y ) * ( ecoord{ aC.x } - aA.x );
|
2018-02-04 12:09:30 +00:00
|
|
|
}
|
|
|
|
|
2019-05-17 00:13:21 +00:00
|
|
|
void update_bbox();
|
|
|
|
|
2021-07-25 19:46:00 +00:00
|
|
|
bool sliceContainsPoint( const VECTOR2I& p ) const;
|
|
|
|
|
2020-12-12 03:43:16 +00:00
|
|
|
private:
|
2020-06-12 21:58:24 +00:00
|
|
|
VECTOR2I m_start;
|
|
|
|
VECTOR2I m_mid;
|
|
|
|
VECTOR2I m_end;
|
2018-02-16 16:34:57 +00:00
|
|
|
|
2020-12-12 03:43:16 +00:00
|
|
|
int m_width;
|
|
|
|
BOX2I m_bbox;
|
2018-02-04 12:09:30 +00:00
|
|
|
};
|
|
|
|
|
2021-03-14 20:28:49 +00:00
|
|
|
// Required for Boost Test BOOST_CHECK_EQUAL:
|
|
|
|
std::ostream& operator<<( std::ostream& aStream, const SHAPE_ARC& aArc );
|
|
|
|
|
2018-02-04 12:09:30 +00:00
|
|
|
#endif
|