Skip to content
Permalink
Browse files
Make segmentLength argument optional with default as 0 instead of the…
… nullptr option
  • Loading branch information
tschmetzer authored and nyalldawson committed Jan 6, 2022
1 parent 7640026 commit f0c77274678df6e001210ace02a2954c5924d34b
@@ -649,7 +649,7 @@ Create a perpendicular line segment from p to segment [s1, s2]
double segmentPoint2x, double segmentPoint2y,
double &perpendicularSegmentPoint1x /Out/, double &perpendicularSegmentPoint1y /Out/,
double &perpendicularSegmentPoint2x /Out/, double &perpendicularSegmentPoint2y /Out/,
double *segmentLength = 0
double segmentLength = 0
) /HoldGIL/;
%Docstring
Create a perpendicular line segment to a given segment [``segmentPoint1``,``segmentPoint2``] with its center at ``centerPoint``.
@@ -1605,19 +1605,15 @@ QgsLineString QgsGeometryUtils::perpendicularSegment( const QgsPoint &p, const Q
return line;
}

void QgsGeometryUtils::perpendicularCenterSegment( double pointx, double pointy, double segmentPoint1x, double segmentPoint1y, double segmentPoint2x, double segmentPoint2y, double &perpendicularSegmentPoint1x, double &perpendicularSegmentPoint1y, double &perpendicularSegmentPoint2x, double &perpendicularSegmentPoint2y, double *desiredSegmentLength )
void QgsGeometryUtils::perpendicularCenterSegment( double pointx, double pointy, double segmentPoint1x, double segmentPoint1y, double segmentPoint2x, double segmentPoint2y, double &perpendicularSegmentPoint1x, double &perpendicularSegmentPoint1y, double &perpendicularSegmentPoint2x, double &perpendicularSegmentPoint2y, double desiredSegmentLength )
{
QgsVector segmentVector = QgsVector( segmentPoint2x - segmentPoint1x, segmentPoint2y - segmentPoint1y );
QgsVector perpendicularVector = segmentVector.perpVector();
if ( desiredSegmentLength )
{
if ( *desiredSegmentLength == 0 )
if ( desiredSegmentLength != 0 )
{
perpendicularVector = perpendicularVector * 1;
}
else
{
perpendicularVector = perpendicularVector.normalized() * ( *desiredSegmentLength ) / 2;
perpendicularVector = perpendicularVector.normalized() * ( desiredSegmentLength ) / 2;
}
}
perpendicularSegmentPoint1x = pointx - perpendicularVector.x();
@@ -703,7 +703,7 @@ class CORE_EXPORT QgsGeometryUtils
double segmentPoint2x, double segmentPoint2y,
double &perpendicularSegmentPoint1x SIP_OUT, double &perpendicularSegmentPoint1y SIP_OUT,
double &perpendicularSegmentPoint2x SIP_OUT, double &perpendicularSegmentPoint2y SIP_OUT,
double *segmentLength = nullptr
double segmentLength = 0
) SIP_HOLDGIL;

/**
@@ -750,7 +750,7 @@ void TestQgsGeometryUtils::testPerpendicularCenterSegment()
// case 1 with segmentLength
segmentLength = 3;
QgsGeometryUtils::perpendicularCenterSegment( centerPoint.x(), centerPoint.y(), segmentPoint1.x(), segmentPoint1.y(), segmentPoint2.x(), segmentPoint2.y(),
perpendicularSegmentPoint1x, perpendicularSegmentPoint1y, perpendicularSegmentPoint2x, perpendicularSegmentPoint2y, &segmentLength );
perpendicularSegmentPoint1x, perpendicularSegmentPoint1y, perpendicularSegmentPoint2x, perpendicularSegmentPoint2y, segmentLength );
QCOMPARE( perpendicularSegmentPoint1x, ( 3.5 ) );
QCOMPARE( perpendicularSegmentPoint1y, ( 1.5 ) );
QCOMPARE( perpendicularSegmentPoint2x, ( 0.5 ) );
@@ -759,7 +759,7 @@ void TestQgsGeometryUtils::testPerpendicularCenterSegment()
// default case 1 with default segmentLength=0 (meaning no effect)
segmentLength = 0;
QgsGeometryUtils::perpendicularCenterSegment( centerPoint.x(), centerPoint.y(), segmentPoint1.x(), segmentPoint1.y(), segmentPoint2.x(), segmentPoint2.y(),
perpendicularSegmentPoint1x, perpendicularSegmentPoint1y, perpendicularSegmentPoint2x, perpendicularSegmentPoint2y, &segmentLength );
perpendicularSegmentPoint1x, perpendicularSegmentPoint1y, perpendicularSegmentPoint2x, perpendicularSegmentPoint2y, segmentLength );
QCOMPARE( perpendicularSegmentPoint1x, 3.0 );
QCOMPARE( perpendicularSegmentPoint1y, ( 1.5 ) );
QCOMPARE( perpendicularSegmentPoint2x, ( 1.0 ) );
@@ -784,7 +784,7 @@ void TestQgsGeometryUtils::testPerpendicularCenterSegment()

segmentLength = 5;
QgsGeometryUtils::perpendicularCenterSegment( centerPoint.x(), centerPoint.y(), segmentPoint1.x(), segmentPoint1.y(), segmentPoint2.x(), segmentPoint2.y(),
perpendicularSegmentPoint1x, perpendicularSegmentPoint1y, perpendicularSegmentPoint2x, perpendicularSegmentPoint2y, &segmentLength );
perpendicularSegmentPoint1x, perpendicularSegmentPoint1y, perpendicularSegmentPoint2x, perpendicularSegmentPoint2y, segmentLength );

QCOMPARE( perpendicularSegmentPoint1x, ( -1.0 ) );
QCOMPARE( perpendicularSegmentPoint1y, ( 4.5 ) );
@@ -816,7 +816,7 @@ void TestQgsGeometryUtils::testPerpendicularCenterSegment()
// vertical with normalization of segmentLength
segmentLength = 1;
QgsGeometryUtils::perpendicularCenterSegment( centerPoint.x(), centerPoint.y(), segmentPoint1.x(), segmentPoint1.y(), segmentPoint2.x(), segmentPoint2.y(),
perpendicularSegmentPoint1x, perpendicularSegmentPoint1y, perpendicularSegmentPoint2x, perpendicularSegmentPoint2y, &segmentLength );
perpendicularSegmentPoint1x, perpendicularSegmentPoint1y, perpendicularSegmentPoint2x, perpendicularSegmentPoint2y, segmentLength );
QCOMPARE( perpendicularSegmentPoint1x, ( -7.5 ) );
QCOMPARE( perpendicularSegmentPoint1y, ( 8.0 ) );
QCOMPARE( perpendicularSegmentPoint2x, ( -6.5 ) );

0 comments on commit f0c7727

Please sign in to comment.