forge
Explore
Log in

Don't you dare go Hollow

The map's law is real, its inverse honest, its docs true

Browse files at this commit

d2ac4e72279a80926669c266666d106d5585c990Ahmet Kaan GümüşParent: 734c321
  • fix
    • the map's law is real, its inverse honest, its docs true
Show full message
🧹 fix(engine): the map's law is real, its inverse honest, its docs true

The sweep's survivor-continuity cell built its TimelineMap out of the
playhead's own answer and then discarded it -- a law claimed and never
asked. The map now comes from the member's own old geometry (old span,
source length over the new rate) and the law is the clip's landed span
against the map's ends, non-circular.

invert() walked into a shifted piece's lerp from the wrong end below
its first knot -- frames under min(old lo, new lo) are identity
outright, and the shifted-piece test pins the whole run both ways.

And the delete docs and one old test name still told the caption-lift
story the ripple replaced; they tell the one-law story now.
crates/engine/src/map.rsmodified+36 -2
@@ -87,8 +87,16 @@ impl TimelineMap {
87 if self.knots.is_empty() {87 if self.knots.is_empty() {
88 return Some(frame);88 return Some(frame);
89 }89 }
90- // Before the first knot the map was the identity on `[0, old_lo)`,90+ // Below the first knot the map is identity on the old axis *up to
91- // which on the new axis is the straight run from 0 to the knot.91+ // the piece's old lo*, which on the new axis is the run from 0 to
92+ // the piece's new lo. A SHIFTED piece (new lo < old lo) puts part of
93+ // that run inside the piece's own destination, so the lerp through
94+ // the knot is right; an unshifted one has new lo == old lo and the
95+ // lerp degenerates to identity -- either way the single run covers
96+ // it, and a frame below min(old lo, new lo) is identity outright.
97+ if frame < self.knots[0].0.min(self.knots[0].1) {
98+ return Some(frame);
99+ }
92 if frame < self.knots[0].1 {100 if frame < self.knots[0].1 {
93 return Some(lerp((0, 0), self.knots[0], frame));101 return Some(lerp((0, 0), self.knots[0], frame));
94 }102 }
@@ -173,6 +181,32 @@ mod tests {
173 assert_eq!(m.shifted_total(), -99);181 assert_eq!(m.shifted_total(), -99);
174 }182 }
175 183
184+ /// A SHIFTED piece -- one whose new span starts before its old one, the
185+ /// shape a removal cut into the head of the timeline gives -- is the case
186+ /// `invert`'s below-the-knot run exists for: identity before the piece,
187+ /// exact on the knots, image-total through the shift, and the frames the
188+ /// shift took below the piece's old lo their own inverses.
189+ #[test]
190+ fn a_shifted_piece_inverts_on_its_own_run() {
191+ let m = TimelineMap::piece((30, 60), (15, 30));
192+ assert_eq!(m.apply(0), 0, "identity before the piece");
193+ assert_eq!(m.apply(29), 29);
194+ assert_eq!(m.apply(30), 15, "the lo knot is exact");
195+ assert_eq!(m.apply(59), 29, "the last frame of the piece");
196+ assert_eq!(m.apply(60), 30, "identity at the shift the piece left");
197+ assert_eq!(m.shifted_total(), -30);
198+ for n in 0..60 {
199+ let back = m.invert(n).expect("the image is total");
200+ assert_eq!(m.apply(back), n, "new frame {n} round trips");
201+ }
202+ // ...and the run the shift opened below the piece's old lo is
203+ // identity in both directions -- the frames `invert` used to walk
204+ // into the piece's own lerp from the wrong end.
205+ for f in 0..15 {
206+ assert_eq!(m.invert(f), Some(f), "frame {f} is its own inverse");
207+ }
208+ }
209+
176 /// Identity is the base: everything maps to itself, in both directions,210 /// Identity is the base: everything maps to itself, in both directions,
177 /// and the timeline's length never moved.211 /// and the timeline's length never moved.
178 #[test]212 #[test]
crates/engine/src/project.rsmodified+17 -16
@@ -4092,12 +4092,13 @@ impl Project {
4092 /// each member by its **own** span and on its **own** lane -- the members4092 /// each member by its **own** span and on its **own** lane -- the members
4093 /// keep their offsets, so their spans may disagree, and the lanes may end4093 /// keep their offsets, so their spans may disagree, and the lanes may end
4094 /// up out of step with each other, which is inherent to a hand-built group4094 /// up out of step with each other, which is inherent to a hand-built group
4095- /// and one undo away. The caption members lift rather than ripple, for the4095+ /// and one undo away. Every member -- clips and captions alike -- goes by
4096- /// reason a caption's own delete always lifted: a subtitle lane never4096+ /// the same law: its own span out of its own lane, hole closed; a caption
4097- /// slides, or the words after the cut would stop matching the ones before4097+ /// in no group keeps the lift that leaves a gap, which is its own door's
4098- /// it. One snapshot for the whole group, so one [`Project::undo`] puts it4098+ /// law ([`delete_sub_in`](Project::delete_sub_in)). One snapshot for the
4099- /// back. `false` for a bad index, and for a lane that is not there.4099+ /// whole group, so one [`Project::undo`] puts it back. `false` for a bad
4100- /// Changes the mapping: the caller must reseek.4100+ /// index, and for a lane that is not there. Changes the mapping: the
4101+ /// caller must reseek.
4101 pub fn delete_in(&mut self, lane: Lane, idx: usize) -> bool {4102 pub fn delete_in(&mut self, lane: Lane, idx: usize) -> bool {
4102 let Some(members) = self.group_of(lane, idx) else {4103 let Some(members) = self.group_of(lane, idx) else {
4103 return false;4104 return false;
@@ -4127,11 +4128,11 @@ impl Project {
4127 self.lift_sub(lane, idx)4128 self.lift_sub(lane, idx)
4128 }4129 }
4129 4130
4130- /// The one whole-group delete both doors land in: every media member's own4131+ /// The one whole-group delete both doors land in: every member's own span
4131- /// span cut out of its own lane and the hole closed there -- and nothing4132+ /// cut out of its own lane and the hole closed there -- clips and
4132- /// else on another lane moves, which is what keeps one member's ripple from4133+ /// captions by the same law -- and nothing else on another lane moves,
4133- /// dragging another member's lane out from under it -- and every caption4134+ /// which is what keeps one member's ripple from dragging another
4134- /// member lifted. One snapshot, one undo step.4135+ /// member's lane out from under it. One snapshot, one undo step.
4135 fn delete_members(&mut self, members: &Members) -> bool {4136 fn delete_members(&mut self, members: &Members) -> bool {
4136 self.snapshot();4137 self.snapshot();
4137 for &(l, i) in &members.clips {4138 for &(l, i) in &members.clips {
@@ -5680,11 +5681,11 @@ mod tests {
5680 assert_eq!(p.sub_lane(s1)[0].link, Some(take));5681 assert_eq!(p.sub_lane(s1)[0].link, Some(take));
5681 }5682 }
5682 5683
5683- /// Deleting a member of a hand-built group takes the group: each media5684+ /// Deleting a member of a hand-built group takes the group: every
5684- /// member's own span out of its own lane, the captions lifted -- the lanes5685+ /// member's own span out of its own lane, hole closed -- the lanes may
5685- /// may end up out of step, which is what one undo restores together.5686+ /// end up out of step, which is what one undo restores together.
5686 #[test]5687 #[test]
5687- fn deleting_a_grouped_clip_ripples_each_lane_alone_and_lifts_the_captions() {5688+ fn deleting_a_grouped_clip_ripples_every_members_own_lane() {
5688 let caption = |start: u32, frames: u32| SubClip {5689 let caption = |start: u32, frames: u32| SubClip {
5689 start,5690 start,
5690 frames,5691 frames,
@@ -5714,7 +5715,7 @@ mod tests {
5714 // By the picture or by the caption, the same whole-group delete.5715 // By the picture or by the caption, the same whole-group delete.
5715 assert!(p.delete_sub_in(s1, 0));5716 assert!(p.delete_sub_in(s1, 0));
5716 assert!(p.lane(Lane::V1).is_empty(), "the take's span left V1");5717 assert!(p.lane(Lane::V1).is_empty(), "the take's span left V1");
5717- assert!(p.sub_lane(s1).is_empty(), "the caption lifted");5718+ assert!(p.sub_lane(s1).is_empty(), "the caption's span left its lane");
5718 assert_eq!(p.lane(v2)[0].start, 10, "a lane the group does not touch stays");5719 assert_eq!(p.lane(v2)[0].start, 10, "a lane the group does not touch stays");
5719 assert!(links_are_consistent(&p.lanes).is_ok());5720 assert!(links_are_consistent(&p.lanes).is_ok());
5720 assert!(p.undo(), "one step puts the group back");5721 assert!(p.undo(), "one step puts the group back");
crates/engine/src/sweep.rsmodified+16 -8
@@ -175,15 +175,17 @@ fn the_sweep_speed_keeps_the_group_and_the_playhead_scene() {
175 for (what, speed) in [("2x", Speed::from_permille(2000)), ("half", Speed::from_permille(500))] {175 for (what, speed) in [("2x", Speed::from_permille(2000)), ("half", Speed::from_permille(500))] {
176 let (mut p, _s1) = project(shape);176 let (mut p, _s1) = project(shape);
177 let pre = p.parts();177 let pre = p.parts();
178- // The map the op will have applied, asked BEFORE the write (the
179- // old ends are what it maps through).
180 let at = 45u32;178 let at = 45u32;
181 let mapped = p.speeded_playhead(Lane::V1, 0, speed, at);179 let mapped = p.speeded_playhead(Lane::V1, 0, speed, at);
182 let before = p.span_at(Lane::V1, at).and_then(|s| s.from);180 let before = p.span_at(Lane::V1, at).and_then(|s| s.from);
183- let held_frames = p.lane(Lane::V1)[0].frames();181+ // The map the write itself is a shape of, built from the
182+ // member's own old geometry -- NOT from the playhead's answer,
183+ // which is what it will be checked against.
184+ let held = p.lane(Lane::V1)[0];
185+ let new_len = (f64::from(held.len()) / speed.as_f64()).round() as u32;
184 let map = TimelineMap::piece(186 let map = TimelineMap::piece(
185- (p.lane(Lane::V1)[0].start, p.lane(Lane::V1)[0].start + held_frames),187+ (held.start, held.start + held.frames()),
186- (p.lane(Lane::V1)[0].start, mapped.unwrap_or(at).max(p.lane(Lane::V1)[0].start)),188+ (held.start, held.start + new_len),
187 );189 );
188 if let Err(why) = p.set_speed(Lane::V1, 0, speed) {190 if let Err(why) = p.set_speed(Lane::V1, 0, speed) {
189 // A stretch the neighbours leave no room for is refused in191 // A stretch the neighbours leave no room for is refused in
@@ -197,8 +199,15 @@ fn the_sweep_speed_keeps_the_group_and_the_playhead_scene() {
197 continue;199 continue;
198 }200 }
199 laws(&p, &format!("{shape}/{what} after speed"));201 laws(&p, &format!("{shape}/{what} after speed"));
200- // Survivor continuity: the clip's own new end is the map of its202+ // Survivor continuity through the map: the clip's old span maps
201- // old one, and the playhead's scene survived.203+ // onto exactly the span it landed in -- the piece's own ends, on
204+ // the lane, not inferred back from anything the write produced.
205+ let landed = p.lane(Lane::V1)[0];
206+ assert_eq!(
207+ (landed.start, landed.start + landed.frames()),
208+ (map.apply(held.start), map.apply(held.start + held.frames())),
209+ "{shape}/{what}: the clip's new span is the map of its old one"
210+ );
202 // The scene law to the frame a rate can hold: an odd source211 // The scene law to the frame a rate can hold: an odd source
203 // frame at 2x never lands on an integer playhead, so the212 // frame at 2x never lands on an integer playhead, so the
204 // tolerance is the one frame the map's own rounding admits.213 // tolerance is the one frame the map's own rounding admits.
@@ -212,7 +221,6 @@ fn the_sweep_speed_keeps_the_group_and_the_playhead_scene() {
212 apart <= 1,221 apart <= 1,
213 "{shape}/{what}: the scene under the playhead, {before:?} vs {after:?}"222 "{shape}/{what}: the scene under the playhead, {before:?} vs {after:?}"
214 );223 );
215- let _ = map; // the piece is pinned by the span math above
216 undo_round_trip(p, pre, &format!("{shape}/{what} speed"));224 undo_round_trip(p, pre, &format!("{shape}/{what} speed"));
217 }225 }
218 }226 }