@@ -2453,7 +2453,7 @@ double QgsGeometry::closestSegmentWithContext(
2453
2453
2454
2454
if ( index > 0 )
2455
2455
{
2456
- if (( testdist = distanceSquaredPointToSegment ( point, prevx, prevy, thisx, thisy, distPoint ) ) < sqrDist )
2456
+ if (( testdist = point. sqrDistToSegment ( * prevx, * prevy, * thisx, * thisy, distPoint ) ) < sqrDist )
2457
2457
{
2458
2458
closestSegmentIndex = index ;
2459
2459
sqrDist = testdist;
@@ -2497,7 +2497,7 @@ double QgsGeometry::closestSegmentWithContext(
2497
2497
}
2498
2498
if ( prevx && prevy )
2499
2499
{
2500
- if (( testdist = distanceSquaredPointToSegment ( point, prevx, prevy, thisx, thisy, distPoint ) ) < sqrDist )
2500
+ if (( testdist = point. sqrDistToSegment ( * prevx, * prevy, * thisx, * thisy, distPoint ) ) < sqrDist )
2501
2501
{
2502
2502
closestSegmentIndex = pointindex;
2503
2503
sqrDist = testdist;
@@ -2539,7 +2539,7 @@ double QgsGeometry::closestSegmentWithContext(
2539
2539
}
2540
2540
if ( prevx && prevy )
2541
2541
{
2542
- if (( testdist = distanceSquaredPointToSegment ( point, prevx, prevy, thisx, thisy, distPoint ) ) < sqrDist )
2542
+ if (( testdist = point. sqrDistToSegment ( * prevx, * prevy, * thisx, * thisy, distPoint ) ) < sqrDist )
2543
2543
{
2544
2544
closestSegmentIndex = index ;
2545
2545
sqrDist = testdist;
@@ -2587,7 +2587,7 @@ double QgsGeometry::closestSegmentWithContext(
2587
2587
}
2588
2588
if ( prevx && prevy )
2589
2589
{
2590
- if (( testdist = distanceSquaredPointToSegment ( point, prevx, prevy, thisx, thisy, distPoint ) ) < sqrDist )
2590
+ if (( testdist = point. sqrDistToSegment ( * prevx, * prevy, * thisx, * thisy, distPoint ) ) < sqrDist )
2591
2591
{
2592
2592
closestSegmentIndex = pointindex;
2593
2593
sqrDist = testdist;
@@ -4679,102 +4679,6 @@ bool QgsGeometry::exportGeosToWkb()
4679
4679
return FALSE ;
4680
4680
}
4681
4681
4682
-
4683
-
4684
-
4685
- double QgsGeometry::distanceSquaredPointToSegment (
4686
- const QgsPoint& point,
4687
- double *x1, double *y1,
4688
- double *x2, double *y2,
4689
- QgsPoint& minDistPoint )
4690
- {
4691
-
4692
- double nx, ny; // normal vector
4693
-
4694
- nx = *y2 - *y1 ;
4695
- ny = -( *x2 - *x1 );
4696
-
4697
- double t;
4698
- t = ( point.x () * ny - point.y () * nx - *x1 * ny + *y1 * nx ) / (( *x2 - *x1 ) * ny - ( *y2 - *y1 ) * nx );
4699
-
4700
- if ( t < 0.0 )
4701
- {
4702
- minDistPoint.setX ( *x1 );
4703
- minDistPoint.setY ( *y1 );
4704
- }
4705
- else if ( t > 1.0 )
4706
- {
4707
- minDistPoint.setX ( *x2 );
4708
- minDistPoint.setY ( *y2 );
4709
- }
4710
- else
4711
- {
4712
- minDistPoint.setX ( *x1 + t *( *x2 - *x1 ) );
4713
- minDistPoint.setY ( *y1 + t *( *y2 - *y1 ) );
4714
- }
4715
-
4716
- return ( minDistPoint.sqrDist ( point ) );
4717
- #if 0
4718
- double d;
4719
-
4720
- // Proportion along segment (0 to 1) the perpendicular of the point falls upon
4721
- double t;
4722
-
4723
-
4724
- // Projection of point on the segment
4725
- double xn;
4726
- double yn;
4727
-
4728
- double segmentsqrdist = ( *x2 - *x1 ) * ( *x2 - *x1 ) +
4729
- ( *y2 - *y1 ) * ( *y2 - *y1 );
4730
-
4731
- // QgsDebugMsg(QString("Entered with (%1, %2) (%3, %4) %5.").arg(*x1).arg(*y1).arg(*x2).arg(*y2).arg(segmentsqrdist));
4732
-
4733
-
4734
- if ( segmentsqrdist == 0.0 )
4735
- {
4736
- // segment is a point
4737
- xn = *x1;
4738
- yn = *y1;
4739
- }
4740
- else
4741
- {
4742
-
4743
- d =
4744
- ( point.x() - *x1 ) * ( *x2 - *x1 )
4745
- + ( point.y() - *y1 ) * ( *y2 - *y1 );
4746
-
4747
- t = d / segmentsqrdist;
4748
-
4749
- // Do not go beyond end of line
4750
- // (otherwise this would be a comparison to an infinite line)
4751
- if ( t < 0.0 )
4752
- {
4753
- xn = *x1;
4754
- yn = *y1;
4755
- }
4756
- else if ( t > 1.0 )
4757
- {
4758
- xn = *x2;
4759
- yn = *y2;
4760
- }
4761
- else
4762
- {
4763
- xn = *x1 + t * ( *x2 - *x1 );
4764
- yn = *y1 + t * ( *y2 - *y1 );
4765
- }
4766
-
4767
- }
4768
-
4769
- minDistPoint.set( xn, yn );
4770
-
4771
- return (
4772
- ( xn - point.x() ) *( xn - point.x() ) +
4773
- ( yn - point.y() ) *( yn - point.y() )
4774
- );
4775
- #endif // 0
4776
- }
4777
-
4778
4682
bool QgsGeometry::convertToMultiType ()
4779
4683
{
4780
4684
if ( !mGeometry )
0 commit comments