Skip to content

Commit

Permalink
src/pal: delete useless cartesian methods to use QgsGeometryUtilsBase…
Browse files Browse the repository at this point in the history
… one
  • Loading branch information
lbartoletti committed Oct 20, 2023
1 parent 3a3a139 commit f2e03e2
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 26 deletions.
13 changes: 7 additions & 6 deletions src/core/pal/feature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "qgstextlabelfeature.h"
#include "qgsmessagelog.h"
#include "qgsgeometryutils.h"
#include "qgsgeometryutils_base.h"
#include "qgslabeling.h"
#include "qgspolygon.h"
#include "qgstextrendererutils.h"
Expand Down Expand Up @@ -801,7 +802,7 @@ std::size_t FeaturePart::createHorizontalCandidatesAlongLine( std::vector<std::u
else
distanceToSegment[i] = distanceToSegment[i - 1] + segmentLengths[i - 1];

segmentLengths[i] = GeomFunction::dist_euc2d( x[i], y[i], x[i + 1], y[i + 1] );
segmentLengths[i] = QgsGeometryUtilsBase::distance2D( x[i], y[i], x[i + 1], y[i + 1] );
totalLineLength += segmentLengths[i];
}
distanceToSegment[line->nbPoints - 1] = totalLineLength;
Expand Down Expand Up @@ -933,7 +934,7 @@ std::size_t FeaturePart::createCandidatesAlongLineNearStraightSegments( std::vec
else
distanceToSegment[i] = distanceToSegment[i - 1] + segmentLengths[i - 1];

segmentLengths[i] = GeomFunction::dist_euc2d( x[i], y[i], x[i + 1], y[i + 1] );
segmentLengths[i] = QgsGeometryUtilsBase::distance2D( x[i], y[i], x[i + 1], y[i + 1] );
totalLineLength += segmentLengths[i];
if ( extremeAngleNodes.contains( i ) )
{
Expand Down Expand Up @@ -1002,7 +1003,7 @@ std::size_t FeaturePart::createCandidatesAlongLineNearStraightSegments( std::vec
line->getPointByDistance( segmentLengths.data(), distanceToSegment.data(), currentDistanceAlongLine, &candidateStartX, &candidateStartY );
line->getPointByDistance( segmentLengths.data(), distanceToSegment.data(), currentDistanceAlongLine + labelWidth, &candidateEndX, &candidateEndY );

candidateLength = QgsGeometryUtils::distance2D( candidateEndX, candidateEndY, candidateStartX, candidateStartY );
candidateLength = QgsGeometryUtilsBase::distance2D( candidateEndX, candidateEndY, candidateStartX, candidateStartY );


// LOTS OF DIFFERENT COSTS TO BALANCE HERE - feel free to tweak these, but please add a unit test
Expand Down Expand Up @@ -1150,7 +1151,7 @@ std::size_t FeaturePart::createCandidatesAlongLineNearMidpoint( std::vector< std
else
distanceToSegment[i] = distanceToSegment[i - 1] + segmentLengths[i - 1];

segmentLengths[i] = GeomFunction::dist_euc2d( x[i], y[i], x[i + 1], y[i + 1] );
segmentLengths[i] = QgsGeometryUtilsBase::distance2D( x[i], y[i], x[i + 1], y[i + 1] );
totalLineLength += segmentLengths[i];
}
distanceToSegment[line->nbPoints - 1] = totalLineLength;
Expand Down Expand Up @@ -1223,11 +1224,11 @@ std::size_t FeaturePart::createCandidatesAlongLineNearMidpoint( std::vector< std
if ( currentDistanceAlongLine < 0 )
{
// label is bigger than line, use whole available line
candidateLength = QgsGeometryUtils::distance2D( x[nbPoints - 1], y[nbPoints - 1], x[0], y[0] );
candidateLength = QgsGeometryUtilsBase::distance2D( x[nbPoints - 1], y[nbPoints - 1], x[0], y[0] );
}
else
{
candidateLength = QgsGeometryUtils::distance2D( candidateEndX, candidateEndY, candidateStartX, candidateStartY );
candidateLength = QgsGeometryUtilsBase::distance2D( candidateEndX, candidateEndY, candidateStartX, candidateStartY );
}

cost = candidateLength / labelWidth;
Expand Down
5 changes: 3 additions & 2 deletions src/core/pal/geomfunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
*
*/

#include "qgsgeometryutils_base.h"
#include "geomfunction.h"
#include "feature.h"
#include "util.h"
Expand Down Expand Up @@ -225,8 +226,8 @@ std::vector< int > GeomFunction::convexHullId( std::vector< int > &id, const std
// Coolineaire !! garder le plus éloigné
if ( qgsDoubleNear( result, 0.0 ) )
{
if ( dist_euc2d_sq( x[id[stack[second]]], y[id[stack[second]]], x[id[convexHull[i]]], y[id[convexHull[i]]] )
> dist_euc2d_sq( x[id[stack[second]]], y[id[stack[second]]], x[id[stack[top]]], y[id[stack[top]]] ) )
if ( QgsGeometryUtilsBase::sqrDistance2D( x[id[stack[second]]], y[id[stack[second]]], x[id[convexHull[i]]], y[id[convexHull[i]]] )
> QgsGeometryUtilsBase::sqrDistance2D( x[id[stack[second]]], y[id[stack[second]]], x[id[stack[top]]], y[id[stack[top]]] ) )
{
stack[top] = convexHull[i];
}
Expand Down
10 changes: 0 additions & 10 deletions src/core/pal/geomfunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,6 @@ namespace pal
return ( x2 - x1 ) * ( y3 - y1 ) - ( x3 - x1 ) * ( y2 - y1 );
}

static inline double dist_euc2d( double x1, double y1, double x2, double y2 )
{
return std::sqrt( ( x2 - x1 ) * ( x2 - x1 ) + ( y2 - y1 ) * ( y2 - y1 ) );
}

static inline double dist_euc2d_sq( double x1, double y1, double x2, double y2 )
{
return ( x2 - x1 ) * ( x2 - x1 ) + ( y2 - y1 ) * ( y2 - y1 );
}

static void findLineCircleIntersection( double cx, double cy, double radius,
double x1, double y1, double x2, double y2,
double &xRes, double &yRes );
Expand Down
3 changes: 2 additions & 1 deletion src/core/pal/labelposition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "labelposition.h"
#include "geomfunction.h"
#include "qgsgeos.h"
#include "qgsgeometryutils_base.h"
#include "qgsmessagelog.h"
#include <cmath>
#include <cfloat>
Expand Down Expand Up @@ -622,7 +623,7 @@ double LabelPosition::getDistanceToPoint( double xp, double yp, bool useOuterBou
else
{
( void )GEOSCoordSeq_getXY_r( geosctxt, nearestCoord.get(), 0, &nx, &ny );
distance = GeomFunction::dist_euc2d_sq( xp, yp, nx, ny );
distance = QgsGeometryUtilsBase::sqrDistance2D( xp, yp, nx, ny );
}
}
catch ( GEOSException &e )
Expand Down
15 changes: 8 additions & 7 deletions src/core/pal/pointset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "qgsgeos.h"
#include "qgsmessagelog.h"
#include "qgsgeometryutils.h"
#include "qgsgeometryutils_base.h"
#include <qglobal.h>

using namespace pal;
Expand Down Expand Up @@ -357,13 +358,13 @@ QLinkedList<PointSet *> PointSet::splitPolygons( PointSet *inputShape, double la
if ( pt != -1 )
{
// compute the ihs->ihn->pt triangle's area
const double base = GeomFunction::dist_euc2d( x[shape->convexHull[ihs]], y[shape->convexHull[ihs]],
const double base = QgsGeometryUtilsBase::distance2D( x[shape->convexHull[ihs]], y[shape->convexHull[ihs]],
x[shape->convexHull[ihn]], y[shape->convexHull[ihn]] );

b = GeomFunction::dist_euc2d( x[shape->convexHull[ihs]], y[shape->convexHull[ihs]],
x[pt], y[pt] );
b = QgsGeometryUtilsBase::distance2D( x[shape->convexHull[ihs]], y[shape->convexHull[ihs]],
x[pt], y[pt] );

const double c = GeomFunction::dist_euc2d( x[shape->convexHull[ihn]], y[shape->convexHull[ihn]],
const double c = QgsGeometryUtilsBase::distance2D( x[shape->convexHull[ihn]], y[shape->convexHull[ihn]],
x[pt], y[pt] );

const double s = ( base + b + c ) / 2; // s = half perimeter
Expand Down Expand Up @@ -406,7 +407,7 @@ QLinkedList<PointSet *> PointSet::splitPolygons( PointSet *inputShape, double la
// compute distance between retainedPoint and segment
// whether perpendicular distance (if retaindPoint is fronting segment i->j)
// or distance between retainedPt and i or j (choose the nearest)
seg_length = GeomFunction::dist_euc2d( x[i], y[i], x[j], y[j] );
seg_length = QgsGeometryUtilsBase::distance2D( x[i], y[i], x[j], y[j] );
cx = ( x[i] + x[j] ) / 2.0;
cy = ( y[i] + y[j] ) / 2.0;
dx = cy - y[i];
Expand All @@ -419,7 +420,7 @@ QLinkedList<PointSet *> PointSet::splitPolygons( PointSet *inputShape, double la

if ( seg_length < EPSILON || std::fabs( ( b = GeomFunction::cross_product( ex, ey, fx, fy, x[retainedPt], y[retainedPt] ) / ( seg_length ) ) ) > ( seg_length / 2 ) ) // retainedPt is not fronting i->j
{
if ( ( ex = GeomFunction::dist_euc2d_sq( x[i], y[i], x[retainedPt], y[retainedPt] ) ) < ( ey = GeomFunction::dist_euc2d_sq( x[j], y[j], x[retainedPt], y[retainedPt] ) ) )
if ( ( ex = QgsGeometryUtilsBase::sqrDistance2D( x[i], y[i], x[retainedPt], y[retainedPt] ) ) < ( ey = QgsGeometryUtilsBase::sqrDistance2D( x[j], y[j], x[retainedPt], y[retainedPt] ) ) )
{
b = ex;
ps = i;
Expand Down Expand Up @@ -904,7 +905,7 @@ double PointSet::minDistanceToPoint( double px, double py, double *rx, double *r
if ( ry )
*ry = ny;

return GeomFunction::dist_euc2d_sq( px, py, nx, ny );
return QgsGeometryUtilsBase::sqrDistance2D( px, py, nx, ny );
}
catch ( GEOSException &e )
{
Expand Down

0 comments on commit f2e03e2

Please sign in to comment.