Skip to content

Commit 527e998

Browse files
committed
feat(rendering): add precomputed cursor support to ZoomFocusInterpolator
1 parent 0ac3c47 commit 527e998

1 file changed

Lines changed: 49 additions & 1 deletion

File tree

crates/rendering/src/zoom_focus_interpolation.rs

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ use cap_project::{ClickSpringConfig, CursorEvents, ScreenMovementSpring, XY, Zoo
33
use crate::{
44
Coord, RawDisplayUVSpace,
55
cursor_interpolation::{
6-
InterpolatedCursorPosition, interpolate_cursor, interpolate_cursor_with_click_spring,
6+
InterpolatedCursorPosition, PrecomputedCursorTimeline, interpolate_cursor,
7+
interpolate_cursor_with_click_spring,
78
},
89
spring_mass_damper::{SpringMassDamperSimulation, SpringMassDamperSimulationConfig},
910
};
@@ -130,6 +131,7 @@ pub struct ZoomFocusInterpolator {
130131
events: Option<Vec<SmoothedFocusEvent>>,
131132
precompute_sim: Option<ZoomFocusPrecomputeSim>,
132133
cursor_events: std::sync::Arc<CursorEvents>,
134+
precomputed_cursor: Option<std::sync::Arc<PrecomputedCursorTimeline>>,
133135
cursor_smoothing: Option<SpringMassDamperSimulationConfig>,
134136
click_spring: ClickSpringConfig,
135137
screen_spring: ScreenMovementSpring,
@@ -145,12 +147,33 @@ impl ZoomFocusInterpolator {
145147
screen_spring: ScreenMovementSpring,
146148
duration_secs: f64,
147149
zoom_segments: &[ZoomSegment],
150+
) -> Self {
151+
Self::new_with_precomputed_cursor(
152+
cursor_events,
153+
cursor_smoothing,
154+
click_spring,
155+
screen_spring,
156+
duration_secs,
157+
zoom_segments,
158+
None,
159+
)
160+
}
161+
162+
pub fn new_with_precomputed_cursor(
163+
cursor_events: &CursorEvents,
164+
cursor_smoothing: Option<SpringMassDamperSimulationConfig>,
165+
click_spring: ClickSpringConfig,
166+
screen_spring: ScreenMovementSpring,
167+
duration_secs: f64,
168+
zoom_segments: &[ZoomSegment],
169+
precomputed_cursor: Option<std::sync::Arc<PrecomputedCursorTimeline>>,
148170
) -> Self {
149171
let segment_clusters = Self::build_segment_clusters(cursor_events, zoom_segments);
150172
Self {
151173
events: None,
152174
precompute_sim: None,
153175
cursor_events: std::sync::Arc::new(cursor_events.clone()),
176+
precomputed_cursor,
154177
cursor_smoothing,
155178
click_spring,
156179
screen_spring,
@@ -166,12 +189,33 @@ impl ZoomFocusInterpolator {
166189
screen_spring: ScreenMovementSpring,
167190
duration_secs: f64,
168191
zoom_segments: &[ZoomSegment],
192+
) -> Self {
193+
Self::new_arc_with_precomputed_cursor(
194+
cursor_events,
195+
cursor_smoothing,
196+
click_spring,
197+
screen_spring,
198+
duration_secs,
199+
zoom_segments,
200+
None,
201+
)
202+
}
203+
204+
pub fn new_arc_with_precomputed_cursor(
205+
cursor_events: std::sync::Arc<CursorEvents>,
206+
cursor_smoothing: Option<SpringMassDamperSimulationConfig>,
207+
click_spring: ClickSpringConfig,
208+
screen_spring: ScreenMovementSpring,
209+
duration_secs: f64,
210+
zoom_segments: &[ZoomSegment],
211+
precomputed_cursor: Option<std::sync::Arc<PrecomputedCursorTimeline>>,
169212
) -> Self {
170213
let segment_clusters = Self::build_segment_clusters(cursor_events.as_ref(), zoom_segments);
171214
Self {
172215
events: None,
173216
precompute_sim: None,
174217
cursor_events,
218+
precomputed_cursor,
175219
cursor_smoothing,
176220
click_spring,
177221
screen_spring,
@@ -204,6 +248,10 @@ impl ZoomFocusInterpolator {
204248
}
205249

206250
fn interpolate_cursor_at(&self, time_secs: f32) -> Option<InterpolatedCursorPosition> {
251+
if let Some(precomputed_cursor) = self.precomputed_cursor.as_ref() {
252+
return precomputed_cursor.interpolate(time_secs);
253+
}
254+
207255
match self.cursor_smoothing {
208256
Some(cfg) => interpolate_cursor_with_click_spring(
209257
self.cursor_events.as_ref(),

0 commit comments

Comments
 (0)