Skip to content

[api] Add qgsDoubleLessThanOrNear, qgsDoubleGreaterThanOrNear, and optimize qgsDoubleNear#66419

Merged
nyalldawson merged 6 commits into
qgis:masterfrom
nyalldawson:api_near
Jun 11, 2026
Merged

[api] Add qgsDoubleLessThanOrNear, qgsDoubleGreaterThanOrNear, and optimize qgsDoubleNear#66419
nyalldawson merged 6 commits into
qgis:masterfrom
nyalldawson:api_near

Conversation

@nyalldawson

Copy link
Copy Markdown
Collaborator

Description

For #66404 I had a need for a "is less than or roughly equal to" method. I've split those out to a separate PR for review.

While doing this, I've also added some optimisations for qgsDoubleNear (and a fix for infinite value handling which was identified in new tests written by Gemini). qgsDoubleNear frequently shows up in QGIS profiling due to how frequently it's called, and the costly isnan checks involved there. By rearranging this function a bit we can unlock some early-exit paths for the more common non-nan value checks.

AI tool usage

  • AI tool(s) Gemini wrote the tests

Allows testing for >= or <=, with a fuzzy tolerance for the equality check
This would cause undefined behavior, and shouldn't be used anyway
Move the expensive nan comparisons to last

These methods are called a LOT, and the nan check is costly and unlikely
@nyalldawson nyalldawson added API API improvement only, no visible user interface changes Optimization I feel the need... the need for speed! labels Jun 10, 2026
@github-actions github-actions Bot added this to the 4.2.0 milestone Jun 10, 2026

@troopa81 troopa81 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM👍

If the extent was a null extent and we tried to do operations like
retrieve its width and scale it, then the extent becomes infinite.

Now that we correctly handle inf values in qgsDoubleNear, this means
that comparing a infinite QgsRectangle to an infinite QgsRectangle
now (correctly) returns true, bypassing fallback logic that
unintentionally undid the extent corruption.

Just handle this correctly now by NOT trying to scale or move
a null extent, which is a meaningless operation anyway.
@qgis qgis deleted a comment from github-actions Bot Jun 10, 2026
@github-actions github-actions Bot added the Print Layouts Related to QGIS Print Layouts, Atlas or Reporting frameworks label Jun 10, 2026
@qgis qgis deleted a comment from github-actions Bot Jun 10, 2026
@nyalldawson nyalldawson merged commit 3e489bc into qgis:master Jun 11, 2026
37 of 40 checks passed
@nyalldawson nyalldawson deleted the api_near branch June 11, 2026 20:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

API API improvement only, no visible user interface changes Optimization I feel the need... the need for speed! Print Layouts Related to QGIS Print Layouts, Atlas or Reporting frameworks

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants