diff --git a/core/src/ui/holds.rs b/core/src/ui/holds.rs index 080352c..244aea9 100644 --- a/core/src/ui/holds.rs +++ b/core/src/ui/holds.rs @@ -55,23 +55,26 @@ impl Holds { if rel == 0 { return Self::ANY; } - // In half steps. The box a length was composed down the chain from - // and the box the same length is measured against the window in are - // two routes to one number, each rounding where the other does not, - // and each rounding drops a whole step since `Fixed::mul` truncates: - // two steps either side. The multiply on the way in drops a step of - // its own, and only downward, so it is one more step at the top and - // nothing at the bottom -- and the whole of a box has no multiply in - // it, however many pixels were added to it, since multiplying by one - // is exact and taking the pixels off again is too. Allowing for it - // there anyway compounded, a step a level down a chain of widgets - // each taking the whole of its parent, which is the unsound - // direction: a range wider than what a drawing holds for admits - // reusing it where it does not hold. + // In half steps, and no more than the arithmetic needs: too wide a + // range admits reusing a drawing where it does not hold, and too + // narrow a one leaves out the box a drawing was made in, which the + // `Holds` assertion in `draw_at` catches. `ROUTES` is at that floor + // -- two half steps fires it -- and tightening both ends moved not + // one of the rig's work counters, so the slack is not buying reuse. + // + // `ROUTES` covers a box composed down the chain against the same box + // measured against the window: two routes to one number, each + // rounding where the other does not. `way_in` covers the multiply + // this inverts, which drops a step and only ever downward, so it + // belongs at the top of the range alone -- and the whole of a box has + // no multiply in it, however many pixels were added to it, since + // multiplying by one is exact and taking the pixels off again is too. + // Allowing for it there anyway compounded, a step a level down a + // chain of widgets each taking the whole of its parent. // // Shifted by half of what a `Rel` counts in, to divide by the // fraction: exact until the division takes it back to the grid. - const ROUTES: i64 = 4; + const ROUTES: i64 = 3; let px = len.px.raw() as i64; let half_rel = REL_SHIFT - 1; let way_in = match rel == Rel::ONE.raw() as i64 { @@ -136,19 +139,20 @@ mod tests { /// taken off it, brings no multiply of its own: only the two routes to /// the same length are left to allow for, and not a rounding that did /// not happen. Widening for it as well grew the interval a level at a - /// time down a chain of them. + /// time down a chain of them. Three half steps come back as one whole + /// one, since dividing by a whole box is dividing by one. #[test] fn the_whole_of_a_box_widens_by_the_routes_alone() { let at = Px::from_int(956); - let two_steps = |len: Px| Holds { - lo: len - Px::from_raw(2), - hi: len + Px::from_raw(2), + let one_step = |len: Px| Holds { + lo: len - Px::STEP, + hi: len + Px::STEP, }; - assert_eq!(Holds::at(at).through(Len::FULL), two_steps(at)); + assert_eq!(Holds::at(at).through(Len::FULL), one_step(at)); let less_eight = Len::from_parts(Rel::ONE, Px::from_int(-8)); assert_eq!( Holds::at(at).through(less_eight), - two_steps(at + Px::from_int(8)) + one_step(at + Px::from_int(8)) ); }