111 int64_t dX_a, dY_a, dX_b, dY_b, dX_ab, dY_ab;
112 int64_t num_a, num_b, den;
120 dX_a = int64_t{ a_p2_l1.
x } - a_p1_l1.
x;
121 dY_a = int64_t{ a_p2_l1.
y } - a_p1_l1.
y;
122 dX_b = int64_t{ a_p2_l2.
x } - a_p1_l2.
x;
123 dY_b = int64_t{ a_p2_l2.
y } - a_p1_l2.
y;
124 dX_ab = int64_t{ a_p1_l2.
x } - a_p1_l1.
x;
125 dY_ab = int64_t{ a_p1_l2.
y } - a_p1_l1.
y;
127 den = dY_a * dX_b - dY_b * dX_a ;
133 num_a = dY_ab * dX_b - dY_b * dX_ab;
134 num_b = dY_ab * dX_a - dY_a * dX_ab;
137 if( aIntersectionPoint )
139 *aIntersectionPoint = a_p1_l1;
140 aIntersectionPoint->
x +=
KiROUND( dX_a * (
double )num_a / (
double )den );
141 aIntersectionPoint->
y +=
KiROUND( dY_a * (
double )num_b / (
double )den );
369 constexpr double kCoincidentRadius = 5.0;
371 auto [minX, maxX] = std::minmax( { aStart.
x, aMid.
x, aEnd.
x } );
372 auto [minY, maxY] = std::minmax( { aStart.
y, aMid.
y, aEnd.
y } );
374 if( maxX - minX < kCoincidentRadius && maxY - minY < kCoincidentRadius )
376 return VECTOR2D( ( aStart.
x + aMid.
x + aEnd.
x ) / 3.0,
377 ( aStart.
y + aMid.
y + aEnd.
y ) / 3.0 );
382 double yDelta_21 = aMid.
y - aStart.
y;
383 double xDelta_21 = aMid.
x - aStart.
x;
384 double yDelta_32 = aEnd.
y - aMid.
y;
385 double xDelta_32 = aEnd.
x - aMid.
x;
390 if( ( ( xDelta_21 == 0.0 ) && ( yDelta_32 == 0.0 ) ) ||
391 ( ( yDelta_21 == 0.0 ) && ( xDelta_32 == 0.0 ) ) )
393 center.x = ( aStart.
x + aEnd.
x ) / 2.0;
394 center.y = ( aStart.
y + aEnd.
y ) / 2.0 ;
399 if( xDelta_21 == 0.0 )
400 xDelta_21 = std::numeric_limits<double>::epsilon();
402 if( xDelta_32 == 0.0 )
403 xDelta_32 = -std::numeric_limits<double>::epsilon();
405 double aSlope = yDelta_21 / xDelta_21;
406 double bSlope = yDelta_32 / xDelta_32;
411 if( aSlope == bSlope )
417 center.x = ( aStart.
x + aMid.
x ) / 2.0;
418 center.y = ( aStart.
y + aMid.
y ) / 2.0 ;
426 aSlope += std::numeric_limits<double>::epsilon();
427 bSlope -= std::numeric_limits<double>::epsilon();
430#ifdef USE_ALTERNATE_CENTER_ALGO
453 double abSlopeStartEndY = aSlope * bSlope * ( aStart.
y - aEnd.
y );
454 double dabSlopeStartEndY = abSlopeStartEndY *
455 std::sqrt( ( daSlope / aSlope * daSlope / aSlope )
456 + ( dbSlope / bSlope * dbSlope / bSlope )
457 + ( M_SQRT1_2 / ( aStart.
y - aEnd.
y )
458 * M_SQRT1_2 / ( aStart.
y - aEnd.
y ) ) );
460 double bSlopeStartMidX = bSlope * ( aStart.
x + aMid.
x );
461 double dbSlopeStartMidX = bSlopeStartMidX * std::sqrt( ( dbSlope / bSlope * dbSlope / bSlope )
462 + ( M_SQRT1_2 / ( aStart.
x + aMid.
x )
463 * M_SQRT1_2 / ( aStart.
x + aMid.
x ) ) );
465 double aSlopeMidEndX = aSlope * ( aMid.
x + aEnd.
x );
466 double daSlopeMidEndX = aSlopeMidEndX * std::sqrt( ( daSlope / aSlope * daSlope / aSlope )
467 + ( M_SQRT1_2 / ( aMid.
x + aEnd.
x )
468 * M_SQRT1_2 / ( aMid.
x + aEnd.
x ) ) );
470 double twiceBASlopeDiff = 2 * ( bSlope - aSlope );
471 double dtwiceBASlopeDiff = 2 * std::sqrt( dbSlope * dbSlope + daSlope * daSlope );
473 double centerNumeratorX = abSlopeStartEndY + bSlopeStartMidX - aSlopeMidEndX;
474 double dCenterNumeratorX = std::sqrt( dabSlopeStartEndY * dabSlopeStartEndY
475 + dbSlopeStartMidX * dbSlopeStartMidX
476 + daSlopeMidEndX * daSlopeMidEndX );
478 double centerX = ( abSlopeStartEndY + bSlopeStartMidX - aSlopeMidEndX ) / twiceBASlopeDiff;
479 double dCenterX = centerX * std::sqrt( ( dCenterNumeratorX / centerNumeratorX *
480 dCenterNumeratorX / centerNumeratorX )
481 + ( dtwiceBASlopeDiff / twiceBASlopeDiff *
482 dtwiceBASlopeDiff / twiceBASlopeDiff ) );
485 double centerNumeratorY = ( ( aStart.
x + aMid.
x ) / 2.0 - centerX );
486 double dCenterNumeratorY = std::sqrt( 1.0 / 8.0 + dCenterX * dCenterX );
488 double centerFirstTerm = centerNumeratorY / aSlope;
489 double dcenterFirstTermY = centerFirstTerm * std::sqrt(
490 ( dCenterNumeratorY/ centerNumeratorY *
491 dCenterNumeratorY / centerNumeratorY )
492 + ( daSlope / aSlope * daSlope / aSlope ) );
494 double centerY = centerFirstTerm + ( aStart.
y + aMid.
y ) / 2.0;
495 double dCenterY = std::sqrt( dcenterFirstTermY * dcenterFirstTermY + 1.0 / 8.0 );
497 double rounded100CenterX = std::floor( ( centerX + 50.0 ) / 100.0 ) * 100.0;
498 double rounded100CenterY = std::floor( ( centerY + 50.0 ) / 100.0 ) * 100.0;
499 double rounded10CenterX = std::floor( ( centerX + 5.0 ) / 10.0 ) * 10.0;
500 double rounded10CenterY = std::floor( ( centerY + 5.0 ) / 10.0 ) * 10.0;
507 if(
std::abs( rounded100CenterX - centerX ) < dCenterX &&
508 std::abs( rounded100CenterY - centerY ) < dCenterY )
510 center.x = rounded100CenterX;
511 center.y = rounded100CenterY;
513 else if(
std::abs( rounded10CenterX - centerX ) < dCenterX &&
514 std::abs( rounded10CenterY - centerY ) < dCenterY )
516 center.x = rounded10CenterX;
517 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.