Skip to content

Use point/size in ClipBox instead of rect.#1776

Merged
jneem merged 1 commit intolinebender:masterfrom
jneem:clipbox-size
May 19, 2021
Merged

Use point/size in ClipBox instead of rect.#1776
jneem merged 1 commit intolinebender:masterfrom
jneem:clipbox-size

Conversation

@jneem
Copy link
Member

@jneem jneem commented May 12, 2021

This fixes a layout bug I was having, but I think it's also an
indication of a bigger issue.

The issue is that in various parts of the layout code, we expand
dimensions to the nearest display point. Besides the fact that we should
be using pixels intead of display points (IMO), this is numerically
unstable: if because of some numerical stuff you have a dimension that's
a rounding error larger than an integer number of pixels, the layout
"jumps".

What does this have to do with ClipBox? Well, ClipBox was storing its
layout rect as a Rect, which is stored as the coordinates of opposite
corners. When scrolling the ClipBox, the size should stay fixed but the
origin should move. But moving the origin can change the size very
slightly because of numerical errors converting to/from the Rect
representation. These slight errors got magnified by the pixel expansion
in other parts of the layout code.

This PR fixes the numerical imprecision in the ClipBox code, but I
suspect that the real fix is to eliminate the numerical instability.

This fixes a layout bug I was having, but I think it's also an
indication of a bigger issue.

The issue is that in various parts of the layout code, we expand
dimensions to the nearest display point. Besides the fact that we should
be using pixels intead of display points (IMO), this is numerically
unstable: if because of some numerical stuff you have a dimension that's
a rounding error larger than an integer number of pixels, the layout
"jumps".

What does this have to do with ClipBox? Well, ClipBox was storing its
layout rect as a `Rect`, which is stored as the coordinates of opposite
corners. When scrolling the ClipBox, the size should stay fixed but the
origin should move. But moving the origin can *change the size* very
slightly because of numerical errors converting to/from the Rect
representation. These slight errors got magnified by the pixel expansion
in other parts of the layout code.

This PR fixes the numerical imprecision in the ClipBox code, but I
suspect that the real fix is to eliminate the numerical instability.
@josh-audio josh-audio added the S-needs-review waits for review label May 12, 2021
Copy link
Collaborator

@maan2003 maan2003 left a comment

Choose a reason for hiding this comment

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

Looks good! The .expand() is tricky to manage ☹️

@maan2003 maan2003 added S-ready PR is ready to merge and removed S-needs-review waits for review labels May 18, 2021
@jneem jneem merged commit e946f3d into linebender:master May 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-ready PR is ready to merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants