mirror of
https://github.com/qgis/QGIS.git
synced 2025-12-30 00:29:39 -05:00
Merge pull request #60114 from lbartoletti/spatialindex_rm_duplicate_code
chore(spatial index): Remove duplicate rectangleToRegion code
This commit is contained in:
commit
f999386492
@ -15,6 +15,7 @@
|
||||
|
||||
#include "qgsmeshspatialindex.h"
|
||||
#include "qgsrectangle.h"
|
||||
#include "qgsspatialindexutils.h"
|
||||
#include "qgslogger.h"
|
||||
#include "qgsfeedback.h"
|
||||
|
||||
@ -74,13 +75,6 @@ static Region edgeToRegion( const QgsMesh &mesh, int id, bool &ok )
|
||||
return SpatialIndex::Region( pt1, pt2, 2 );
|
||||
}
|
||||
|
||||
static Region rectToRegion( const QgsRectangle &rect )
|
||||
{
|
||||
double pt1[2] = { rect.xMinimum(), rect.yMinimum() };
|
||||
double pt2[2] = { rect.xMaximum(), rect.yMaximum() };
|
||||
return SpatialIndex::Region( pt1, pt2, 2 );
|
||||
}
|
||||
|
||||
/**
|
||||
* \ingroup core
|
||||
* \class QgisMeshVisitor
|
||||
@ -376,7 +370,7 @@ QList<int> QgsMeshSpatialIndex::intersects( const QgsRectangle &rect ) const
|
||||
QList<int> list;
|
||||
QgisMeshVisitor visitor( list );
|
||||
|
||||
const SpatialIndex::Region r = rectToRegion( rect );
|
||||
const SpatialIndex::Region r = QgsSpatialIndexUtils::rectangleToRegion( rect );
|
||||
|
||||
const QMutexLocker locker( &d->mMutex );
|
||||
d->mRTree->intersectsWithQuery( r, visitor );
|
||||
|
||||
@ -30,6 +30,7 @@
|
||||
#include "qgscurvepolygon.h"
|
||||
#include "qgsrendercontext.h"
|
||||
#include "qgspointlocatorinittask.h"
|
||||
#include "qgsspatialindexutils.h"
|
||||
#include <spatialindex/SpatialIndex.h>
|
||||
|
||||
#include <QLinkedListIterator>
|
||||
@ -46,14 +47,6 @@ static SpatialIndex::Point point2point( const QgsPointXY &point )
|
||||
}
|
||||
|
||||
|
||||
static SpatialIndex::Region rect2region( const QgsRectangle &rect )
|
||||
{
|
||||
double pLow[2] = { rect.xMinimum(), rect.yMinimum() };
|
||||
double pHigh[2] = { rect.xMaximum(), rect.yMaximum() };
|
||||
return SpatialIndex::Region( pLow, pHigh, 2 );
|
||||
}
|
||||
|
||||
|
||||
// Ahh.... another magic number. Taken from QgsVectorLayer::snapToGeometry() call to closestSegmentWithContext().
|
||||
// The default epsilon used for sqrDistToSegment (1e-8) is too high when working with lat/lon coordinates
|
||||
// I still do not fully understand why the sqrDistToSegment() code uses epsilon and if the square distance
|
||||
@ -1128,7 +1121,7 @@ bool QgsPointLocator::rebuildIndex( int maxFeaturesToIndex )
|
||||
const QgsRectangle bbox = f.geometry().boundingBox();
|
||||
if ( bbox.isFinite() )
|
||||
{
|
||||
SpatialIndex::Region r( rect2region( bbox ) );
|
||||
SpatialIndex::Region r( QgsSpatialIndexUtils::rectangleToRegion( bbox ) );
|
||||
dataList << new RTree::Data( 0, nullptr, r, f.id() );
|
||||
|
||||
auto it = mGeoms.find( f.id() );
|
||||
@ -1262,7 +1255,7 @@ void QgsPointLocator::onFeatureAdded( QgsFeatureId fid )
|
||||
const QgsRectangle bbox = f.geometry().boundingBox();
|
||||
if ( bbox.isFinite() )
|
||||
{
|
||||
const SpatialIndex::Region r( rect2region( bbox ) );
|
||||
const SpatialIndex::Region r( QgsSpatialIndexUtils::rectangleToRegion( bbox ) );
|
||||
mRTree->insertData( 0, nullptr, r, f.id() );
|
||||
|
||||
auto it = mGeoms.find( f.id() );
|
||||
@ -1301,7 +1294,7 @@ void QgsPointLocator::onFeatureDeleted( QgsFeatureId fid )
|
||||
auto it = mGeoms.find( fid );
|
||||
if ( it != mGeoms.end() )
|
||||
{
|
||||
mRTree->deleteData( rect2region( ( *it )->boundingBox() ), fid );
|
||||
mRTree->deleteData( QgsSpatialIndexUtils::rectangleToRegion( ( *it )->boundingBox() ), fid );
|
||||
delete *it;
|
||||
mGeoms.erase( it );
|
||||
}
|
||||
@ -1335,7 +1328,7 @@ QgsPointLocator::Match QgsPointLocator::nearestVertex( const QgsPointXY &point,
|
||||
Match m;
|
||||
QgsPointLocator_VisitorNearestVertex visitor( this, m, point, filter );
|
||||
const QgsRectangle rect( point.x() - tolerance, point.y() - tolerance, point.x() + tolerance, point.y() + tolerance );
|
||||
mRTree->intersectsWithQuery( rect2region( rect ), visitor );
|
||||
mRTree->intersectsWithQuery( QgsSpatialIndexUtils::rectangleToRegion( rect ), visitor );
|
||||
if ( m.isValid() && m.distance() > tolerance )
|
||||
return Match(); // make sure that only match strictly within the tolerance is returned
|
||||
return m;
|
||||
@ -1350,7 +1343,7 @@ QgsPointLocator::Match QgsPointLocator::nearestCentroid( const QgsPointXY &point
|
||||
QgsPointLocator_VisitorNearestCentroid visitor( this, m, point, filter );
|
||||
|
||||
const QgsRectangle rect( point.x() - tolerance, point.y() - tolerance, point.x() + tolerance, point.y() + tolerance );
|
||||
mRTree->intersectsWithQuery( rect2region( rect ), visitor );
|
||||
mRTree->intersectsWithQuery( QgsSpatialIndexUtils::rectangleToRegion( rect ), visitor );
|
||||
if ( m.isValid() && m.distance() > tolerance )
|
||||
return Match(); // make sure that only match strictly within the tolerance is returned
|
||||
return m;
|
||||
@ -1365,7 +1358,7 @@ QgsPointLocator::Match QgsPointLocator::nearestMiddleOfSegment( const QgsPointXY
|
||||
QgsPointLocator_VisitorNearestMiddleOfSegment visitor( this, m, point, filter );
|
||||
|
||||
const QgsRectangle rect( point.x() - tolerance, point.y() - tolerance, point.x() + tolerance, point.y() + tolerance );
|
||||
mRTree->intersectsWithQuery( rect2region( rect ), visitor );
|
||||
mRTree->intersectsWithQuery( QgsSpatialIndexUtils::rectangleToRegion( rect ), visitor );
|
||||
if ( m.isValid() && m.distance() > tolerance )
|
||||
return Match(); // make sure that only match strictly within the tolerance is returned
|
||||
return m;
|
||||
@ -1380,7 +1373,7 @@ QgsPointLocator::Match QgsPointLocator::nearestLineEndpoints( const QgsPointXY &
|
||||
QgsPointLocator_VisitorNearestLineEndpoint visitor( this, m, point, filter );
|
||||
|
||||
const QgsRectangle rect( point.x() - tolerance, point.y() - tolerance, point.x() + tolerance, point.y() + tolerance );
|
||||
mRTree->intersectsWithQuery( rect2region( rect ), visitor );
|
||||
mRTree->intersectsWithQuery( QgsSpatialIndexUtils::rectangleToRegion( rect ), visitor );
|
||||
if ( m.isValid() && m.distance() > tolerance )
|
||||
return Match(); // make sure that only match strictly within the tolerance is returned
|
||||
return m;
|
||||
@ -1398,7 +1391,7 @@ QgsPointLocator::Match QgsPointLocator::nearestEdge( const QgsPointXY &point, do
|
||||
Match m;
|
||||
QgsPointLocator_VisitorNearestEdge visitor( this, m, point, filter );
|
||||
const QgsRectangle rect( point.x() - tolerance, point.y() - tolerance, point.x() + tolerance, point.y() + tolerance );
|
||||
mRTree->intersectsWithQuery( rect2region( rect ), visitor );
|
||||
mRTree->intersectsWithQuery( QgsSpatialIndexUtils::rectangleToRegion( rect ), visitor );
|
||||
if ( m.isValid() && m.distance() > tolerance )
|
||||
return Match(); // make sure that only match strictly within the tolerance is returned
|
||||
return m;
|
||||
@ -1445,7 +1438,7 @@ QgsPointLocator::MatchList QgsPointLocator::edgesInRect( const QgsRectangle &rec
|
||||
|
||||
MatchList lst;
|
||||
QgsPointLocator_VisitorEdgesInRect visitor( this, lst, rect, filter );
|
||||
mRTree->intersectsWithQuery( rect2region( rect ), visitor );
|
||||
mRTree->intersectsWithQuery( QgsSpatialIndexUtils::rectangleToRegion( rect ), visitor );
|
||||
|
||||
return lst;
|
||||
}
|
||||
@ -1463,7 +1456,7 @@ QgsPointLocator::MatchList QgsPointLocator::verticesInRect( const QgsRectangle &
|
||||
|
||||
MatchList lst;
|
||||
QgsPointLocator_VisitorVerticesInRect visitor( this, lst, rect, filter );
|
||||
mRTree->intersectsWithQuery( rect2region( rect ), visitor );
|
||||
mRTree->intersectsWithQuery( QgsSpatialIndexUtils::rectangleToRegion( rect ), visitor );
|
||||
|
||||
return lst;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user