Fix: bound calculation for negative values #77
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Thank you for maintaining this awesome library.
I recently ran into a problem with the bounds.
Another tool (PotreeConverter) crashed, because it found points outside the bounds.
At first I suspected some floating point issues, so I took a look at the source code where and how the bounds are calculated, just to realize that you already thought about that :-)
but to calculate the bounds both the upper bound (max) and the lower bound (min) are calculated by rounding to the nearest step (inside
Transform.inverse
) but to be correct the upper bound should be rounded up withceil
and the lower bound rounded down withfloor
.I wrote some tests to confirm my suspicion (without touching the rest of the code) and indeed points are outside the bounds after calling the
adapt
method.I implemented a fix in a backwards compatible way (I hope, I kindly ask you to review if I missed anything) but to do so I had to
impl
a newinverse_internal
method on theTransform
struct to allow the caller to determine the rounding mode. The new method and theRoundingMode
enum arepub(crate)
to not increase the public API surface.After fixing the issue the case from above was calculated correctly and the tests I've written all passed.
The external tool that originally crashed because of the bounds no longer complained.
Let me know if you need me to make some changes.
inverse_internal
method intotransform.rs
?FYI I'm out of town for a few days, so it may take a few days (I guess next Monday) for me to respond.