@@ -411,18 +411,29 @@ static Real CCWDistance(Real from, Real to)
411411// --
412412static bool ccwLeavesAllowedArc (Real from, Real to, Real min, Real max)
413413{
414- if (min > max) { // simplify
415- max += TWO_PI ;
414+ // if (min > max) { // simplify
415+ // max += TWO_PI;
416+ // }
417+ // if (from > to) {
418+ // to += TWO_PI;
419+ // }
420+
421+ Real disallowedCenter;
422+
423+ if (min > max) {
424+ disallowedCenter = normalizeAngle2PI (((max + TWO_PI + min) / 2.0 ) + PI );
416425 }
417- if (from > to) {
418- to += TWO_PI ;
426+ else {
427+ disallowedCenter = normalizeAngle2PI (((max + min) / 2.0 ) + PI ) ;
419428 }
429+ /* DEBUG_LOG((">>> ccw check: from = %f, to = %f, min = %f, max = %f. disCenter = %f",
430+ from * 180 / PI, to * 180 / PI, min * 180 / PI, max * 180 / PI, disallowedCenter * 180 / PI));*/
420431
421- Real disallowedCenter = normalizeAngle2PI (((max + min) / 2.0 ) + PI );
422- // DEBUG_LOG((">>> ccw check: from = %f, to = %f, min = %f, max = %f. disCenter = %f",
423- // from * 180 / PI, to * 180 / PI, min * 180 / PI, max * 180 / PI, disallowedCenter * 180 / PI));
424432
425- return (from < disallowedCenter && to > disallowedCenter);
433+ if (from <= to)
434+ return disallowedCenter >= from && disallowedCenter <= to;
435+ else
436+ return disallowedCenter >= from || disallowedCenter <= to; // wraparound
426437}
427438// -------
428439// return True if CCW, False if CW
@@ -448,8 +459,8 @@ Bool TurretAI::getTurretRotationDir(Real desiredAngle, Real minAngle, Real maxAn
448459 // maxAngle = WWMath::Normalize_Angle(maxAngle);
449460
450461 // Check if preferred direction leaves allowed arc
451- // DEBUG_LOG((">>> curAngle = %f, targetAngle = %f, shortest dir = %d",
452- // origAngle*180/PI, desiredAngle*180/PI, wantCCW));
462+ /* DEBUG_LOG((">>> curAngle = %f, targetAngle = %f, shortest dir = %d",
463+ origAngle*180/PI, desiredAngle*180/PI, wantCCW));*/
453464
454465 if (wantCCW)
455466 {
0 commit comments