45 VECTOR2I vectSeg = aSegEnd - aSegStart;
46 VECTOR2I vectPoint = aTestPoint - aSegStart;
49 if( (
long long) vectSeg.
x * vectPoint.
y - (
long long) vectSeg.
y * vectPoint.
x )
52 if( ( (
long long) vectSeg.
x * vectPoint.
x + (
long long) vectSeg.
y * vectPoint.
y ) <
53 ( (
long long) vectPoint.
x * vectPoint.
x + (
long long) vectPoint.
y * vectPoint.
y ) )
69 int64_t dX_a, dY_a, dX_b, dY_b, dX_ab, dY_ab;
70 int64_t num_a, num_b, den;
78 dX_a = int64_t{ a_p2_l1.
x } - a_p1_l1.
x;
79 dY_a = int64_t{ a_p2_l1.
y } - a_p1_l1.
y;
80 dX_b = int64_t{ a_p2_l2.
x } - a_p1_l2.
x;
81 dY_b = int64_t{ a_p2_l2.
y } - a_p1_l2.
y;
82 dX_ab = int64_t{ a_p1_l2.
x } - a_p1_l1.
x;
83 dY_ab = int64_t{ a_p1_l2.
y } - a_p1_l1.
y;
85 den = dY_a * dX_b - dY_b * dX_a ;
91 num_a = dY_ab * dX_b - dY_b * dX_ab;
92 num_b = dY_ab * dX_a - dY_a * dX_ab;
95 if( aIntersectionPoint )
97 *aIntersectionPoint = a_p1_l1;
98 aIntersectionPoint->
x +=
KiROUND( dX_a * (
double )num_a / (
double )den );
99 aIntersectionPoint->
y +=
KiROUND( dY_a * (
double )num_b / (
double )den );
139 std::swap( xmax, xmin );
142 std::swap( ymax, ymin );
145 if( ( ymin - aRefPoint.
y > aDist ) || ( aRefPoint.
y - ymax > aDist ) )
148 if( ( xmin - aRefPoint.
x > aDist ) || ( aRefPoint.
x - xmax > aDist ) )
152 if( aStart.
x == aEnd.
x && aRefPoint.
y > ymin && aRefPoint.
y < ymax )
155 if( aStart.
y == aEnd.
y && aRefPoint.
x > xmin && aRefPoint.
x < xmax )
158 SEG segment( aStart, aEnd );
166 VECTOR2I startVector = aStart - aCenter;
167 VECTOR2I endVector = aEnd - aCenter;
171 EDA_ANGLE midPointRotAngle = ( startAngle - endAngle ).Normalize180() / 2;
209 double sinus = angle.
Sin();
210 double cosinus = angle.
Cos();
212 pt.
x =
KiROUND( ( *pY * sinus ) + ( *pX * cosinus ) );
213 pt.
y =
KiROUND( ( *pY * cosinus ) - ( *pX * sinus ) );
275 double sinus = angle.
Sin();
276 double cosinus = angle.
Cos();
278 pt.
x = ( *pY * sinus ) + ( *pX * cosinus );
279 pt.
y = ( *pY * cosinus ) - ( *pX * sinus );
296 std::swap( start, end );
302 std::swap( start, end );
307 double r = ( chord / 2.0 ) / ( angle / 2.0 ).Sin();
308 double d_squared = r * r - chord* chord / 4.0;
311 if( d_squared > 0.0 )
312 d = sqrt( d_squared );
319 return VECTOR2D( start + vc + vec2 );
326 double yDelta_21 = aMid.
y - aStart.
y;
327 double xDelta_21 = aMid.
x - aStart.
x;
328 double yDelta_32 = aEnd.
y - aMid.
y;
329 double xDelta_32 = aEnd.
x - aMid.
x;
334 if( ( ( xDelta_21 == 0.0 ) && ( yDelta_32 == 0.0 ) ) ||
335 ( ( yDelta_21 == 0.0 ) && ( xDelta_32 == 0.0 ) ) )
337 center.
x = ( aStart.
x + aEnd.
x ) / 2.0;
338 center.
y = ( aStart.
y + aEnd.
y ) / 2.0 ;
343 if( xDelta_21 == 0.0 )
344 xDelta_21 = std::numeric_limits<double>::epsilon();
346 if( xDelta_32 == 0.0 )
347 xDelta_32 = -std::numeric_limits<double>::epsilon();
349 double aSlope = yDelta_21 / xDelta_21;
350 double bSlope = yDelta_32 / xDelta_32;
355 if( aSlope == bSlope )
361 center.
x = ( aStart.
x + aMid.
x ) / 2.0;
362 center.
y = ( aStart.
y + aMid.
y ) / 2.0 ;
370 aSlope += std::numeric_limits<double>::epsilon();
371 bSlope -= std::numeric_limits<double>::epsilon();
377 aSlope = std::numeric_limits<double>::epsilon();
387 double abSlopeStartEndY = aSlope * bSlope * ( aStart.
y - aEnd.
y );
388 double dabSlopeStartEndY = abSlopeStartEndY * std::sqrt( ( daSlope / aSlope * daSlope / aSlope )
389 + ( dbSlope / bSlope * dbSlope / bSlope )
390 + ( M_SQRT1_2 / ( aStart.
y - aEnd.
y )
391 * M_SQRT1_2 / ( aStart.
y - aEnd.
y ) ) );
393 double bSlopeStartMidX = bSlope * ( aStart.
x + aMid.
x );
394 double dbSlopeStartMidX = bSlopeStartMidX * std::sqrt( ( dbSlope / bSlope * dbSlope / bSlope )
395 + ( M_SQRT1_2 / ( aStart.
x + aMid.
x )
396 * M_SQRT1_2 / ( aStart.
x + aMid.
x ) ) );
398 double aSlopeMidEndX = aSlope * ( aMid.
x + aEnd.
x );
399 double daSlopeMidEndX = aSlopeMidEndX * std::sqrt( ( daSlope / aSlope * daSlope / aSlope )
400 + ( M_SQRT1_2 / ( aMid.
x + aEnd.
x )
401 * M_SQRT1_2 / ( aMid.
x + aEnd.
x ) ) );
403 double twiceBASlopeDiff = 2 * ( bSlope - aSlope );
404 double dtwiceBASlopeDiff = 2 * std::sqrt( dbSlope * dbSlope + daSlope * daSlope );
406 double centerNumeratorX = abSlopeStartEndY + bSlopeStartMidX - aSlopeMidEndX;
407 double dCenterNumeratorX = std::sqrt( dabSlopeStartEndY * dabSlopeStartEndY
408 + dbSlopeStartMidX * dbSlopeStartMidX
409 + daSlopeMidEndX * daSlopeMidEndX );
411 double centerX = ( abSlopeStartEndY + bSlopeStartMidX - aSlopeMidEndX ) / twiceBASlopeDiff;
413 double dCenterX = centerX * std::sqrt( ( dCenterNumeratorX / centerNumeratorX * dCenterNumeratorX / centerNumeratorX )
414 + ( dtwiceBASlopeDiff / twiceBASlopeDiff * dtwiceBASlopeDiff / twiceBASlopeDiff ) );
417 double centerNumeratorY = ( ( aStart.
x + aMid.
x ) / 2.0 - centerX );
418 double dCenterNumeratorY = std::sqrt( 1.0 / 8.0 + dCenterX * dCenterX );
420 double centerFirstTerm = centerNumeratorY / aSlope;
421 double dcenterFirstTermY = centerFirstTerm * std::sqrt(
422 ( dCenterNumeratorY/ centerNumeratorY * dCenterNumeratorY / centerNumeratorY )
423 + ( daSlope / aSlope * daSlope / aSlope ) );
425 double centerY = centerFirstTerm + ( aStart.
y + aMid.
y ) / 2.0;
426 double dCenterY = std::sqrt( dcenterFirstTermY * dcenterFirstTermY + 1.0 / 8.0 );
428 double rounded100CenterX = std::floor( ( centerX + 50.0 ) / 100.0 ) * 100.0;
429 double rounded100CenterY = std::floor( ( centerY + 50.0 ) / 100.0 ) * 100.0;
430 double rounded10CenterX = std::floor( ( centerX + 5.0 ) / 10.0 ) * 10.0;
431 double rounded10CenterY = std::floor( ( centerY + 5.0 ) / 10.0 ) * 10.0;
437 if(
std::abs( rounded100CenterX - centerX ) < dCenterX &&
std::abs( rounded100CenterY - centerY ) < dCenterY )
439 center.
x = rounded100CenterX;
440 center.
y = rounded100CenterY;
442 else if(
std::abs( rounded10CenterX - centerX ) < dCenterX &&
std::abs( rounded10CenterY - centerY ) < dCenterY )
444 center.
x = rounded10CenterX;
445 center.
y = rounded10CenterY;
460 VECTOR2D dStart(
static_cast<double>( aStart.
x ),
static_cast<double>( aStart.
y ) );
461 VECTOR2D dMid(
static_cast<double>( aMid.
x ),
static_cast<double>( aMid.
y ) );
462 VECTOR2D dEnd(
static_cast<double>( aEnd.
x ),
static_cast<double>( aEnd.
y ) );
467 iCenter.
x =
KiROUND( Clamp<double>(
double( std::numeric_limits<int>::min() / 2.0 ),
469 double( std::numeric_limits<int>::max() / 2.0 ) ) );
471 iCenter.
y =
KiROUND( Clamp<double>(
double( std::numeric_limits<int>::min() / 2.0 ),
473 double( std::numeric_limits<int>::max() / 2.0 ) ) );
ecoord SquaredDistance(const SEG &aSeg) const
static SEG::ecoord Square(int a)
T EuclideanNorm() const
Compute the Euclidean norm of the vector, which is defined as sqrt(x ** 2 + y ** 2).
VECTOR2< T > Resize(T aNewLength) const
Return a vector of the same direction, but length specified in aNewLength.
static constexpr EDA_ANGLE & ANGLE_180
static constexpr EDA_ANGLE & ANGLE_360
static constexpr EDA_ANGLE & ANGLE_90
static constexpr EDA_ANGLE & ANGLE_0
static constexpr EDA_ANGLE & ANGLE_270
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
const VECTOR2I CalcArcMid(const VECTOR2I &aStart, const VECTOR2I &aEnd, const VECTOR2I &aCenter, bool aMinArcAngle)
Return the middle point of an arc, half-way between aStart and aEnd.
bool TestSegmentHit(const VECTOR2I &aRefPoint, const VECTOR2I &aStart, const VECTOR2I &aEnd, int aDist)
Test if aRefPoint is with aDistance on the line defined by aStart and aEnd.
void RotatePoint(int *pX, int *pY, const EDA_ANGLE &aAngle)
bool SegmentIntersectsSegment(const VECTOR2I &a_p1_l1, const VECTOR2I &a_p2_l1, const VECTOR2I &a_p1_l2, const VECTOR2I &a_p2_l2, VECTOR2I *aIntersectionPoint)
Test if two lines intersect.
bool IsPointOnSegment(const VECTOR2I &aSegStart, const VECTOR2I &aSegEnd, const VECTOR2I &aTestPoint)
Test if aTestPoint is on line defined by aSegStart and aSegEnd.
const VECTOR2D CalcArcCenter(const VECTOR2D &aStart, const VECTOR2D &aEnd, const EDA_ANGLE &aAngle)
double EuclideanNorm(const VECTOR2I &vector)
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
VECTOR2< double > VECTOR2D