kishikawakatsumi / IBPCollectionViewCompositionalLayout

Backport of UICollectionViewCompositionalLayout to earlier iOS 12
MIT License
1.55k stars 148 forks source link

Floating Point issues #103

Open notjosh opened 5 years ago

notjosh commented 5 years ago

Whew, this one was a tricky one, and probably a bigger issue to address (there are a lot of float comparisons!), so I'm interested in your thoughts.

The comparison here was causing a layout issue for me, where an orthogonal view wasn't moving down below the header (boundary supplementary) view.

I was getting these values:

(lldb) p itemFrame
(CGRect) $6 = (origin = (x = 0, y = 314.66666666666669), size = (width = 414, height = 58))
(lldb) p frame 
(CGRect) $7 = (origin = (x = 0, y = 314.66666666666663), size = (width = 414, height = 256.66666666666669))

Obviously in UI coordinates, 314.66666666666669 is the same as 314.66666666666663, but the comparison failed.

How do you think we should handle comparisons like this across the lib?

notjosh commented 5 years ago

My quick workaround was this, fyi: https://github.com/notjosh/IBPCollectionViewCompositionalLayout/commit/f8995b313e56f0700521872f993dd3c8bdb049bb

kishikawakatsumi commented 5 years ago

Thank you for reporting the issue. I'll look into it this weekend.

kishikawakatsumi commented 5 years ago

Floating-point values ​​should eventually be rounded to screen scale. It should be delayed as much as possible to minimize the round-ff error.

I'm aware of this issue and it should be fixed, but it's a project-wide issue and I haven't started work.