Skip to content

Commit 55a01dc

Browse files
strkm-kuhn
authored andcommittedAug 28, 2017
Simplify linearizeArc code dropping useless conditionals
1 parent 1438847 commit 55a01dc

File tree

1 file changed

+16
-45
lines changed

1 file changed

+16
-45
lines changed
 

‎src/core/geometry/qgsgeometryutils.cpp

Lines changed: 16 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -633,23 +633,17 @@ double QgsGeometryUtils::circleTangentDirection( const QgsPoint &tangentPoint, c
633633
void QgsGeometryUtils::segmentizeArc( const QgsPoint &p1, const QgsPoint &p2, const QgsPoint &p3, QgsPointSequence &points, double tolerance, QgsAbstractGeometry::SegmentationToleranceType toleranceType, bool hasZ, bool hasM )
634634
{
635635
bool reversed = false;
636-
bool clockwise = false;
637636
int segSide = segmentSide( p1, p3, p2 );
638-
if ( segSide == -1 )
639-
{
640-
clockwise = true;
641-
}
642637

643638
QgsPoint circlePoint1;
644639
const QgsPoint circlePoint2 = p2;
645640
QgsPoint circlePoint3;
646641

647-
if ( clockwise )
642+
if ( segSide == -1 )
648643
{
649644
// Reverse !
650645
circlePoint1 = p3;
651646
circlePoint3 = p1;
652-
clockwise = false;
653647
reversed = true;
654648
}
655649
else
@@ -664,8 +658,8 @@ void QgsGeometryUtils::segmentizeArc( const QgsPoint &p1, const QgsPoint &p2, co
664658
double centerY = 0;
665659
circleCenterRadius( circlePoint1, circlePoint2, circlePoint3, radius, centerX, centerY );
666660

667-
QgsDebugMsg( QString( "Center: POINT(%1 %2) - Radius: %3 - Clockwise: %4" )
668-
.arg( centerX ) .arg( centerY ) .arg( radius ) .arg( clockwise ) );
661+
QgsDebugMsg( QString( "Center: POINT(%1 %2) - Radius: %3 - Reversed: %4" )
662+
.arg( centerX ) .arg( centerY ) .arg( radius ) .arg( reversed ) );
669663

670664
if ( circlePoint1 != circlePoint3 && ( radius < 0 || qgsDoubleNear( segSide, 0.0 ) ) ) //points are colinear
671665
{
@@ -698,7 +692,7 @@ void QgsGeometryUtils::segmentizeArc( const QgsPoint &p1, const QgsPoint &p2, co
698692
const bool symmetric = true;
699693
if ( symmetric )
700694
{
701-
double angle = clockwise ? a1 - a3 : a3 - a1;
695+
double angle = a3 - a1;
702696
if ( angle < 0 ) angle += M_PI * 2;
703697
QgsDebugMsg( QString( "total angle: %1 (%2)" )
704698
.arg( angle ) .arg( angle * 180 / M_PI )
@@ -712,23 +706,11 @@ void QgsGeometryUtils::segmentizeArc( const QgsPoint &p1, const QgsPoint &p2, co
712706
QgsDebugMsg( QString( "symmetric adjusted increment:%1" ) .arg( increment ) );
713707
}
714708

715-
if ( clockwise )
716-
{
717-
increment *= -1;
718-
/* Adjust a3 down so we can increment from a1 to a3 cleanly */
719-
if ( a3 > a1 )
720-
a3 -= 2.0 * M_PI;
721-
if ( a2 > a1 )
722-
a2 -= 2.0 * M_PI;
723-
}
724-
else
725-
{
726-
/* Adjust a3 up so we can increment from a1 to a3 cleanly */
727-
if ( a3 < a1 )
728-
a3 += 2.0 * M_PI;
729-
if ( a2 < a1 )
730-
a2 += 2.0 * M_PI;
731-
}
709+
/* Adjust a3 up so we can increment from a1 to a3 cleanly */
710+
if ( a3 < a1 )
711+
a3 += 2.0 * M_PI;
712+
if ( a2 < a1 )
713+
a2 += 2.0 * M_PI;
732714

733715
QgsDebugMsg( QString( "ADJUSTED - a1:%1 (%4) a2:%2 (%5) a3:%3 (%6)" )
734716
.arg( a1 ).arg( a2 ).arg( a3 )
@@ -749,10 +731,10 @@ void QgsGeometryUtils::segmentizeArc( const QgsPoint &p1, const QgsPoint &p2, co
749731
if ( hasM )
750732
pointWkbType = QgsWkbTypes::addM( pointWkbType );
751733

752-
QgsDebugMsg( QString( "a1:%1 (%2), a3:%3 (%4), inc:%5, shi:?, cw:%6" )
734+
QgsDebugMsg( QString( "a1:%1 (%2), a3:%3 (%4), inc:%5" )
753735
. arg( a1 ). arg( a1 * 180 / M_PI )
754736
. arg( a3 ). arg( a3 * 180 / M_PI )
755-
. arg( increment ). arg( clockwise )
737+
. arg( increment )
756738
);
757739

758740
//make sure the curve point p2 is part of the segmentized vertices. But only if p1 != p3
@@ -771,27 +753,16 @@ void QgsGeometryUtils::segmentizeArc( const QgsPoint &p1, const QgsPoint &p2, co
771753
// are more distant than requested. This is at most 1% off
772754
// from requested MaxAngle and less for MaxError.
773755
double tolError = increment / 100;
774-
double stopAngle = clockwise ? a3 - tolError : a3 - tolError;
756+
double stopAngle = a3 - tolError;
775757
QgsDebugMsg( QString( "stopAngle: %1 (%2)" ) . arg( stopAngle ) .arg( stopAngle * 180 / M_PI ) );
776-
for ( double angle = a1 + increment; clockwise ? angle > stopAngle : angle < stopAngle; angle += increment )
758+
for ( double angle = a1 + increment; angle < stopAngle; angle += increment )
777759
{
778760
if ( addP2 && angle > a2 )
779761
{
780-
if ( clockwise )
781-
{
782-
if ( stringPoints.empty() || stringPoints.front() != circlePoint2 )
783-
{
784-
QgsDebugMsg( QString( "Adding control point, with angle %1 (%2)" ) . arg( a2 ) .arg( a2 * 180 / M_PI ) );
785-
stringPoints.insert( 0, circlePoint2 );
786-
}
787-
}
788-
else
762+
if ( stringPoints.empty() || stringPoints.back() != circlePoint2 )
789763
{
790-
if ( stringPoints.empty() || stringPoints.back() != circlePoint2 )
791-
{
792-
QgsDebugMsg( QString( "Adding control point, with angle %1 (%2)" ) . arg( a2 ) .arg( a2 * 180 / M_PI ) );
793-
stringPoints.insert( stringPoints.size(), circlePoint2 );
794-
}
764+
QgsDebugMsg( QString( "Adding control point, with angle %1 (%2)" ) . arg( a2 ) .arg( a2 * 180 / M_PI ) );
765+
stringPoints.insert( stringPoints.size(), circlePoint2 );
795766
}
796767
addP2 = false;
797768
}

0 commit comments

Comments
 (0)
Please sign in to comment.