115 int64_t dX_a, dY_a, dX_b, dY_b, dX_ab, dY_ab;
116 int64_t num_a, num_b, den;
124 dX_a = int64_t{ a_p2_l1.
x } - a_p1_l1.
x;
125 dY_a = int64_t{ a_p2_l1.
y } - a_p1_l1.
y;
126 dX_b = int64_t{ a_p2_l2.
x } - a_p1_l2.
x;
127 dY_b = int64_t{ a_p2_l2.
y } - a_p1_l2.
y;
128 dX_ab = int64_t{ a_p1_l2.
x } - a_p1_l1.
x;
129 dY_ab = int64_t{ a_p1_l2.
y } - a_p1_l1.
y;
131 den = dY_a * dX_b - dY_b * dX_a ;
137 num_a = dY_ab * dX_b - dY_b * dX_ab;
138 num_b = dY_ab * dX_a - dY_a * dX_ab;
141 if( aIntersectionPoint )
143 *aIntersectionPoint = a_p1_l1;
144 aIntersectionPoint->
x +=
KiROUND( dX_a * (
double )num_a / (
double )den );
145 aIntersectionPoint->
y +=
KiROUND( dY_a * (
double )num_b / (
double )den );
373 double yDelta_21 = aMid.
y - aStart.
y;
374 double xDelta_21 = aMid.
x - aStart.
x;
375 double yDelta_32 = aEnd.
y - aMid.
y;
376 double xDelta_32 = aEnd.
x - aMid.
x;
381 if( ( ( xDelta_21 == 0.0 ) && ( yDelta_32 == 0.0 ) ) ||
382 ( ( yDelta_21 == 0.0 ) && ( xDelta_32 == 0.0 ) ) )
384 center.x = ( aStart.
x + aEnd.
x ) / 2.0;
385 center.y = ( aStart.
y + aEnd.
y ) / 2.0 ;
390 if( xDelta_21 == 0.0 )
391 xDelta_21 = std::numeric_limits<double>::epsilon();
393 if( xDelta_32 == 0.0 )
394 xDelta_32 = -std::numeric_limits<double>::epsilon();
396 double aSlope = yDelta_21 / xDelta_21;
397 double bSlope = yDelta_32 / xDelta_32;
402 if( aSlope == bSlope )
408 center.x = ( aStart.
x + aMid.
x ) / 2.0;
409 center.y = ( aStart.
y + aMid.
y ) / 2.0 ;
417 aSlope += std::numeric_limits<double>::epsilon();
418 bSlope -= std::numeric_limits<double>::epsilon();
421#ifdef USE_ALTERNATE_CENTER_ALGO
444 double abSlopeStartEndY = aSlope * bSlope * ( aStart.
y - aEnd.
y );
445 double dabSlopeStartEndY = abSlopeStartEndY *
446 std::sqrt( ( daSlope / aSlope * daSlope / aSlope )
447 + ( dbSlope / bSlope * dbSlope / bSlope )
448 + ( M_SQRT1_2 / ( aStart.
y - aEnd.
y )
449 * M_SQRT1_2 / ( aStart.
y - aEnd.
y ) ) );
451 double bSlopeStartMidX = bSlope * ( aStart.
x + aMid.
x );
452 double dbSlopeStartMidX = bSlopeStartMidX * std::sqrt( ( dbSlope / bSlope * dbSlope / bSlope )
453 + ( M_SQRT1_2 / ( aStart.
x + aMid.
x )
454 * M_SQRT1_2 / ( aStart.
x + aMid.
x ) ) );
456 double aSlopeMidEndX = aSlope * ( aMid.
x + aEnd.
x );
457 double daSlopeMidEndX = aSlopeMidEndX * std::sqrt( ( daSlope / aSlope * daSlope / aSlope )
458 + ( M_SQRT1_2 / ( aMid.
x + aEnd.
x )
459 * M_SQRT1_2 / ( aMid.
x + aEnd.
x ) ) );
461 double twiceBASlopeDiff = 2 * ( bSlope - aSlope );
462 double dtwiceBASlopeDiff = 2 * std::sqrt( dbSlope * dbSlope + daSlope * daSlope );
464 double centerNumeratorX = abSlopeStartEndY + bSlopeStartMidX - aSlopeMidEndX;
465 double dCenterNumeratorX = std::sqrt( dabSlopeStartEndY * dabSlopeStartEndY
466 + dbSlopeStartMidX * dbSlopeStartMidX
467 + daSlopeMidEndX * daSlopeMidEndX );
469 double centerX = ( abSlopeStartEndY + bSlopeStartMidX - aSlopeMidEndX ) / twiceBASlopeDiff;
470 double dCenterX = centerX * std::sqrt( ( dCenterNumeratorX / centerNumeratorX *
471 dCenterNumeratorX / centerNumeratorX )
472 + ( dtwiceBASlopeDiff / twiceBASlopeDiff *
473 dtwiceBASlopeDiff / twiceBASlopeDiff ) );
476 double centerNumeratorY = ( ( aStart.
x + aMid.
x ) / 2.0 - centerX );
477 double dCenterNumeratorY = std::sqrt( 1.0 / 8.0 + dCenterX * dCenterX );
479 double centerFirstTerm = centerNumeratorY / aSlope;
480 double dcenterFirstTermY = centerFirstTerm * std::sqrt(
481 ( dCenterNumeratorY/ centerNumeratorY *
482 dCenterNumeratorY / centerNumeratorY )
483 + ( daSlope / aSlope * daSlope / aSlope ) );
485 double centerY = centerFirstTerm + ( aStart.
y + aMid.
y ) / 2.0;
486 double dCenterY = std::sqrt( dcenterFirstTermY * dcenterFirstTermY + 1.0 / 8.0 );
488 double rounded100CenterX = std::floor( ( centerX + 50.0 ) / 100.0 ) * 100.0;
489 double rounded100CenterY = std::floor( ( centerY + 50.0 ) / 100.0 ) * 100.0;
490 double rounded10CenterX = std::floor( ( centerX + 5.0 ) / 10.0 ) * 10.0;
491 double rounded10CenterY = std::floor( ( centerY + 5.0 ) / 10.0 ) * 10.0;
498 if(
std::abs( rounded100CenterX - centerX ) < dCenterX &&
499 std::abs( rounded100CenterY - centerY ) < dCenterY )
501 center.x = rounded100CenterX;
502 center.y = rounded100CenterY;
504 else if(
std::abs( rounded10CenterX - centerX ) < dCenterX &&
505 std::abs( rounded10CenterY - centerY ) < dCenterY )
507 center.x = rounded10CenterX;
508 center.y = rounded10CenterY;
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.
void RotatePoint(int *pX, int *pY, const EDA_ANGLE &aAngle)
Calculate the new point of coord coord pX, pY, for a rotation center 0, 0.
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.