Skip to content

Commit

Permalink
Address review
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn committed Feb 21, 2024
1 parent b1d22b9 commit bc957d6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
13 changes: 6 additions & 7 deletions src/analysis/vector/qgsgeometrysnapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,10 @@ bool QgsSnapIndex::SegmentSnapItem::getProjection( const QgsPoint &p, QgsPoint &
return true;
}

bool QgsSnapIndex::SegmentSnapItem::withinSqrDistance( const QgsPoint &p, const double tolerance )
bool QgsSnapIndex::SegmentSnapItem::withinSquaredDistance( const QgsPoint &p, const double squaredDistance )
{
double minDistX, minDistY;
const double distance = QgsGeometryUtilsBase::sqrDistToLine( p.x(), p.y(), idxFrom->point().x(), idxFrom->point().y(), idxTo->point().x(), idxTo->point().y(), minDistX, minDistY, 4 * std::numeric_limits<double>::epsilon() );
return distance <= tolerance;
return QgsGeometryUtilsBase::sqrDistToLine( p.x(), p.y(), idxFrom->point().x(), idxFrom->point().y(), idxTo->point().x(), idxTo->point().y(), minDistX, minDistY, 4 * std::numeric_limits<double>::epsilon() ) <= squaredDistance;
}

///////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -250,7 +249,7 @@ QgsSnapIndex::SnapItem *QgsSnapIndex::getSnapItem( const QgsPoint &pos, const do
QgsSnapIndex::SegmentSnapItem *snapSegment = nullptr;
QgsSnapIndex::PointSnapItem *snapPoint = nullptr;

const double sqrTolerance = tolerance * tolerance;
const double squaredTolerance = tolerance * tolerance;
const auto constItems = items;
for ( QgsSnapIndex::SnapItem *item : constItems )
{
Expand All @@ -265,7 +264,7 @@ QgsSnapIndex::SnapItem *QgsSnapIndex::getSnapItem( const QgsPoint &pos, const do
}
else if ( item->type == SnapSegment && !endPointOnly )
{
if ( !static_cast<SegmentSnapItem *>( item )->withinSqrDistance( pos, sqrTolerance ) )
if ( !static_cast<SegmentSnapItem *>( item )->withinSquaredDistance( pos, squaredTolerance ) )
continue;

QgsPoint pProj;
Expand All @@ -280,8 +279,8 @@ QgsSnapIndex::SnapItem *QgsSnapIndex::getSnapItem( const QgsPoint &pos, const do
}
}
}
snapPoint = minDistPoint < sqrTolerance ? snapPoint : nullptr;
snapSegment = minDistSegment < sqrTolerance ? snapSegment : nullptr;
snapPoint = minDistPoint < squaredTolerance ? snapPoint : nullptr;
snapSegment = minDistSegment < squaredTolerance ? snapSegment : nullptr;
if ( pSnapPoint ) *pSnapPoint = snapPoint;
if ( pSnapSegment ) *pSnapSegment = snapSegment;
return minDistPoint < minDistSegment ? static_cast<QgsSnapIndex::SnapItem *>( snapPoint ) : static_cast<QgsSnapIndex::SnapItem *>( snapSegment );
Expand Down
2 changes: 1 addition & 1 deletion src/analysis/vector/qgsgeometrysnapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ class QgsSnapIndex
QgsPoint getSnapPoint( const QgsPoint &p ) const override;
bool getIntersection( const QgsPoint &p1, const QgsPoint &p2, QgsPoint &inter ) const;
bool getProjection( const QgsPoint &p, QgsPoint &pProj ) const;
bool withinSqrDistance( const QgsPoint &p, const double distance );
bool withinSquaredDistance( const QgsPoint &p, const double squaredDistance );
const CoordIdx *idxFrom = nullptr;
const CoordIdx *idxTo = nullptr;
};
Expand Down

0 comments on commit bc957d6

Please sign in to comment.