fix: allow more palm movement while progress fills
This commit is contained in:
43
src/palm.rs
43
src/palm.rs
@@ -166,9 +166,21 @@ impl Tracker {
|
||||
}
|
||||
return;
|
||||
};
|
||||
// Only relax movement after accepted samples established the initial
|
||||
// steady period. Keep the original anchor so slow drift is still bounded.
|
||||
let filling = self
|
||||
.steady_since
|
||||
.zip(self.last_seen)
|
||||
.is_some_and(|(since, seen)| seen.duration_since(since) >= STEADY_WAIT);
|
||||
let (position_tolerance, minimum_pixels, size_tolerance) = if filling {
|
||||
(0.50, 16.0, 0.40)
|
||||
} else {
|
||||
(0.25, 8.0, 0.25)
|
||||
};
|
||||
let steady = self.anchor.is_some_and(|anchor| {
|
||||
(palm.x - anchor.x).hypot(palm.y - anchor.y) <= (anchor.radius * 0.25).max(8.0)
|
||||
&& (palm.radius - anchor.radius).abs() <= anchor.radius * 0.25
|
||||
(palm.x - anchor.x).hypot(palm.y - anchor.y)
|
||||
<= (anchor.radius * position_tolerance).max(minimum_pixels)
|
||||
&& (palm.radius - anchor.radius).abs() <= anchor.radius * size_tolerance
|
||||
}) && self
|
||||
.last_seen
|
||||
.is_some_and(|seen| now.duration_since(seen) < STALE_AFTER);
|
||||
@@ -295,13 +307,38 @@ mod tests {
|
||||
);
|
||||
}
|
||||
let now = start + Duration::from_millis(2250);
|
||||
tracker.update(palm(120.0), now);
|
||||
tracker.update(palm(132.0), now);
|
||||
assert_eq!(tracker.visible(now).unwrap().1, 0.0);
|
||||
tracker.update(None, now);
|
||||
assert_eq!(tracker.visible(now).unwrap().1, 0.0);
|
||||
assert!(tracker.visible(now + STALE_AFTER).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn filling_allows_more_movement_but_still_limits_drift() {
|
||||
let start = Instant::now();
|
||||
let mut tracker = Tracker::default();
|
||||
for ms in [0, 250, 500] {
|
||||
tracker.update(palm(100.0), start + Duration::from_millis(ms));
|
||||
}
|
||||
let now = start + Duration::from_millis(750);
|
||||
tracker.update(
|
||||
Some(Palm {
|
||||
x: 118.0,
|
||||
y: 100.0,
|
||||
radius: 52.0,
|
||||
}),
|
||||
now,
|
||||
);
|
||||
assert_eq!(tracker.visible(now).unwrap().1, 0.25);
|
||||
tracker.update(palm(120.0), start + Duration::from_secs(1));
|
||||
assert_eq!(tracker.steady_since, Some(start));
|
||||
let now = start + Duration::from_millis(1250);
|
||||
tracker.update(palm(122.0), now);
|
||||
assert_eq!(tracker.visible(now).unwrap().1, 0.0);
|
||||
assert_eq!(tracker.steady_since, Some(now));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn drift_and_stale_results_reset() {
|
||||
let start = Instant::now();
|
||||
|
||||
Reference in New Issue
Block a user