fix float precision bug in text box rendering#1293
fix float precision bug in text box rendering#1293unterkoefler wants to merge 1 commit intoprawnpdf:masterfrom
Conversation
There was a problem hiding this comment.
Could you please add a test that demonstrates validity of this fix?
Also could you please explain the value of that number? Why can't it be smaller/bigger?
There was a problem hiding this comment.
This commit adds a test that fails, but it does so by manually inserting the necessary rounding errors, so I didn't add it to this pr. Because this bug is so rare, I don't know a good way to add a test for it without changing the code.
There was a problem hiding this comment.
I chose the value 0.00001 arbitrarily. Seems like it's big enough fix the bug and small enough to not matter visually. The ruby docs for float link to this page which uses 0.0001 as a delta. Happy to update to that instead if you think that would be better
There was a problem hiding this comment.
FYI In the geom2d gem which heavily uses floating point calculations I have implemented special comparison methods, see https://github.com/gettalong/geom2d/blob/master/lib/geom2d/utils.rb#L24-L34. The precision to use is arbitrarily set.
For Prawn I would probably choose something that reflects the output precision used in https://github.com/prawnpdf/pdf-core/blob/master/lib/pdf/core/pdf_object.rb#L16
There was a problem hiding this comment.
Thanks @gettalong!
@pointlessone I updated to a value based on the precision and also updated one other place doing a similar comparison to use the same value
44b871f to
b319393
Compare
|
I still don't quite understand the root cause of the issue. |
When we render a text box with shrink_to_fit enabled, we call In The bug occurs specifically when the LHS Now, The assumption being violated here is that subsequent calls to Also, regardless, |
fixes #1292