Fix RTreeError for elements with floating-point precision issues (Issue #140)#143
Fix RTreeError for elements with floating-point precision issues (Issue #140)#143dolfim-ibm wants to merge 1 commit into
Conversation
Signed-off-by: Michele Dolfi <dol@zurich.ibm.com>
|
✅ DCO Check Passed Thanks @dolfim-ibm, all your commits are properly signed off. 🎉 |
Merge ProtectionsYour pull request matches the following merge protections and will not be merged until they are valid. 🔴 Enforce conventional commitWaiting for:
This rule is failing.Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/
🔴 Require two reviewer for test updatesWaiting for:
This rule is failing.When test data is updated, we require two reviewers
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
| # Ensure y_min <= y_max to avoid RTreeError when elements are very close | ||
| # or have floating-point precision issues | ||
| y_min = min(pelem_j.t, pelem_i.b) | ||
| y_max = max(pelem_j.t, pelem_i.b) |
There was a problem hiding this comment.
Even without this change, all tests still pass.
I have also tried the code with the coordinates of pelem_i, pelem_j provided in the issue and again all tests pass (with or without this change).
It would be very helpful if we can get hands on a document that reproduces this issue.
|
@simonschoe would you be able to test this fix with your document? |
|
@nikos-livathinos , @dolfim-ibm Thanks for your work and picking this issue up once more. I must admit that I was not able to reproduce above described issue with the exact same document. It is now being processed correctly even without the fix (as @nikos-livathinos suggested that the fix might not be necessary). I have no idea why to be honest. I used the exact same document and even without your fix @dolfim-ibm it worked as expected. The issue that I described here with the printed values was the cause of the error when I tried it six week ago with that document. Maybe some dependencies changed/updated in the meantime that fixed the issue? I am not quite sure |
Description
This PR fixes an
RTreeErrorthat occurs when querying the spatial index with elements that are very close together vertically. Due to floating-point precision issues, the calculatedy_mincould be greater thany_max, causing the R-tree library to raise an error with the message "Coordinates must not have minimums more than maximums".The fix ensures that
y_minandy_maxare properly ordered by usingmin()andmax()functions when calculating the bounding box for spatial queries, instead of assuming a specific ordering based on element positions.Issue resolved by this Pull Request:
Resolves #140
Changes
reading_order_rb.pyto usemin()andmax()when calculatingy_minandy_maxfor spatial index queriestest_close_elements_with_floating_point_precision(): Tests elements with boundaries that differ by tiny floating-point amountstest_identical_boundaries(): Tests edge case where elements have identical vertical boundariesChecklist: