105 if( !only45 && absVec.x > ext_type( absVec.y ) * 2 )
110 else if( !only45 && absVec.y > ext_type( absVec.x ) * 2 )
115 else if( absVec.x > absVec.y )
118 newVec.y = std::copysign( aVec.
x, aVec.
y );
123 newVec.x = std::copysign( aVec.
y, aVec.
x );
142template <
typename in_type,
typename ret_type = in_type,
typename pad_type =
unsigned int,
143 typename =
typename std::enable_if<std::is_unsigned<pad_type>::value>::type>
146 typedef std::numeric_limits<int32_t> coord_limits;
148 in_type x = aCoords.
x;
149 in_type y = aCoords.
y;
151 if constexpr( !std::is_floating_point_v<in_type> )
153 int64_t max =
static_cast<int64_t
>( coord_limits::max() ) - aPadding;
155 x = std::clamp<int64_t>(
static_cast<int64_t
>( x ), min, max );
156 y = std::clamp<int64_t>(
static_cast<int64_t
>( y ), min, max );
160 double max =
static_cast<double>( coord_limits::max() ) - aPadding;
162 x = std::clamp<double>(
static_cast<double>( x ), min, max );
163 y = std::clamp<double>(
static_cast<double>( y ), min, max );
166 if constexpr( !std::is_integral_v<in_type> && std::is_integral_v<ret_type> )
169 KiROUND<in_type, ret_type>( y,
true ) );
182 constexpr T min = std::numeric_limits<int>::min();
183 constexpr T max = std::numeric_limits<int>::max();
185 return aVec.
x > min && aVec.
x < max && aVec.
y > min && aVec.
y < max;
202bool ClipLine(
const BOX2I *aClipBox,
int &x1,
int &y1,
int &x2,
int &y2 );
226bool BoxHitTest(
const BOX2I& aHitter,
const BOX2I& aHittee,
bool aHitteeContained,
int aAccuracy );
When creating polygons to create a clearance polygonal area, the polygon must be same or bigger than ...
~DISABLE_ARC_RADIUS_CORRECTION()
DISABLE_ARC_RADIUS_CORRECTION()
Define a general 2D-vector/point.
VECTOR2_TRAITS< T >::extended_type extended_type
int GetCircleToPolyCorrection(int aMaxError)
int CircleToEndSegmentDeltaRadius(int aInnerCircleRadius, int aSegCount)
VECTOR2< T > GetVectorSnapped45(const VECTOR2< T > &aVec, bool only45=false)
Snap a vector onto the nearest 0, 45 or 90 degree line.
bool IsVec2SafeXY(const VECTOR2< T > &aVec)
Check if both coordinates of a vector are within the limits of the integer type.
bool ClipLine(const BOX2I *aClipBox, int &x1, int &y1, int &x2, int &y2)
Test if any part of a line falls within the bounds of a rectangle.
int GetArcToSegmentCount(int aRadius, int aErrorMax, const EDA_ANGLE &aArcAngle)
VECTOR2< ret_type > GetClampedCoords(const VECTOR2< in_type > &aCoords, pad_type aPadding=1u)
Clamps a vector to values that can be negated, respecting numeric limits of coordinates data type wit...
bool BoxHitTest(const VECTOR2I &aHitPoint, const BOX2I &aHittee, int aAccuracy)
Perform a point-to-box hit test.
EDA_ANGLE abs(const EDA_ANGLE &aAngle)