Decide layout on the grid end to end, and delete the tolerance

`Px` and `PxVec2` reach the last places a pixel was a float: the window, the
box a widget reads, the box it is compared against, and `PixelRegion`. A
pointer, a wheel notch and a shaped glyph advance still arrive as floats,
and each is put on the grid where it arrives.

`Holds` is an interval of `Px`. `HOLDS_EPSILON_PX` is gone with the
`exact`/tolerant split it existed for: `at` is the length a widget read, an
open end is the next step along, and `same_px` is equality. `Span`'s margin
from `5ed9e87` goes too -- the box a parent hands back and the sum of what
its children asked for are counts of the same step, so the boundary decides
the same way from either side.

Three things had to be true for that, and were not:

`Holds::through` inverts `px + rel * box`, which rounds -- so a part of a
given length came from a range of boxes, and inverting the length alone gave
a point that need not contain the box the part was drawn in. It now maps the
half step either side, and one more for a length composed down the chain
against the same length measured against the window.

`RegionRemap` translates when a box only moved, rather than dividing to find
each part's fraction and multiplying to place it again. Two roundings landed
a step from where growing the tree that way does; a move is exact on a grid,
which is the whole reason `tests/drift.rs` was written.

A pixel is `1/1024` rather than `1/64`. At `1/64` the residue of a length
reached two ways was one step, and one step was 0.016 px -- enough to move
a box. `PX_SHIFT` and `REL_SHIFT` are the only statement of the grid now,
and the shader's copy is prepended from them rather than written twice.

Checked: fmt, clippy, 102 tests, 100 generated seeds in 75 s, all five
shrinker cases at 300 seeds, and `tabs`, `view`, `minimal`, `text` and
`random` byte-identical at 1920x1200.

What the fuzzers ask for is now a step, not a twentieth of a pixel: the
shrinker's five cases agree within one (`resize` exactly), and the oracle's
two-operation cases within two. The residue is a single rounding either way
-- it scales with the grid rather than accumulating, which is why it is a
thousandth of a pixel now. Closing it means one way of asking how long a box
is, rather than a chain composed down and a length measured against the
window; that is a bigger change than this one.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
iris-aiandClaude Opus 5 committed 2026-09-16 02:56:48 -04:00
1 parent bd6de71a55
commit 39e4ca20e6
24 files changed
+420 -194

No files matched your search

+24
View File
@@ -1,4 +1,5 @@
use super::*;
use crate::{Fixed, FixedVec2};
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum Axis {
@@ -40,6 +41,29 @@ pub enum Sign {
Pos,
}
impl<const SHIFT: u32> FixedVec2<SHIFT> {
pub const fn axis(&self, axis: Axis) -> Fixed<SHIFT> {
match axis {
Axis::X => self.x,
Axis::Y => self.y,
}
}
pub const fn axis_mut(&mut self, axis: Axis) -> &mut Fixed<SHIFT> {
match axis {
Axis::X => &mut self.x,
Axis::Y => &mut self.y,
}
}
pub const fn from_axis(axis: Axis, aligned: Fixed<SHIFT>, ortho: Fixed<SHIFT>) -> Self {
match axis {
Axis::X => Self::new(aligned, ortho),
Axis::Y => Self::new(ortho, aligned),
}
}
}
impl Vec2 {
pub fn axis(&self, axis: Axis) -> f32 {
match axis {
+15 -3
View File
@@ -1,5 +1,5 @@
use super::*;
use crate::{Px, Rel, UiNum, Weight, util::impl_op};
use crate::{Px, PxVec2, Rel, UiNum, Weight, util::impl_op};
#[derive(Debug, Default, Clone, Copy, PartialEq)]
pub struct Size {
@@ -49,10 +49,22 @@ impl Size {
y: Len::LEFTOVER,
};
/// From something measured outside layout -- a texture, a shaped line --
/// which is where a size in floats comes from.
pub fn px(v: Vec2) -> Self {
Self::from_px(PxVec2::from_f32(v))
}
pub const fn from_px(v: PxVec2) -> Self {
Self {
x: Len::px(v.x),
y: Len::px(v.y),
x: Len {
px: v.x,
..Len::ZERO
},
y: Len {
px: v.y,
..Len::ZERO
},
}
}
+13 -16
View File
@@ -1,7 +1,7 @@
use std::{fmt::Display, marker::Destruct};
use super::*;
use crate::{Px, Rel, UiNum, util::impl_op};
use crate::{Px, PxVec2, Rel, UiNum, util::impl_op};
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, bytemuck::Pod, bytemuck::Zeroable, Default)]
@@ -67,13 +67,10 @@ impl UiVec2 {
}
}
/// Resolved against a box of `size`, in whole `f32` pixels for a caller
/// outside layout -- a pointer position, or something being drawn.
pub fn to_px(&self, size: Vec2) -> Vec2 {
Vec2 {
x: self.x.to_px(Px::from_f32(size.x)).to_f32(),
y: self.y.to_px(Px::from_f32(size.y)).to_f32(),
}
/// Resolved against a box of `size`, which is where a fraction stops
/// being one and becomes a place.
pub fn to_px(&self, size: PxVec2) -> PxVec2 {
PxVec2::new(self.x.to_px(size.x), self.y.to_px(size.y))
}
pub const FULL_SIZE: Self = Self::rel(Vec2::ONE);
@@ -344,10 +341,10 @@ impl UiRegion {
self
}
pub fn to_px(&self, size: Vec2) -> PixelRegion {
pub fn to_px(&self, size: PxVec2) -> PixelRegion {
PixelRegion {
top_left: self.top_left().get_rel() * size + self.top_left().get_px(),
bot_right: self.bot_right().get_rel() * size + self.bot_right().get_px(),
top_left: self.top_left().to_px(size),
bot_right: self.bot_right().to_px(size),
}
}
@@ -402,21 +399,21 @@ impl Display for UiRegion {
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct PixelRegion {
pub top_left: Vec2,
pub bot_right: Vec2,
pub top_left: PxVec2,
pub bot_right: PxVec2,
}
impl PixelRegion {
pub fn contains(&self, pos: Vec2) -> bool {
pub fn contains(&self, pos: PxVec2) -> bool {
pos.x >= self.top_left.x
&& pos.x <= self.bot_right.x
&& pos.y >= self.top_left.y
&& pos.y <= self.bot_right.y
}
pub fn size(&self) -> Vec2 {
pub fn size(&self) -> PxVec2 {
self.bot_right - self.top_left
}
}