token_value_map/shutter.rs
1use crate::*;
2use std::ops::Range;
3
4/// Shutter timing for motion blur sampling.
5///
6/// A [`Shutter`] `struct` defines a time range and opening pattern for
7/// generating motion blur samples. The opening function determines the weight
8/// of samples at different times within the shutter interval.
9#[derive(Clone, Debug, PartialEq, Hash, Default)]
10pub struct Shutter {
11 /// The overall time range for sampling.
12 pub range: Range<Time>,
13 /// The time range during which the shutter is opening.
14 pub opening: Range<Time>,
15}
16
17impl Shutter {
18 /// Evaluate the shutter at `time`.
19 ///
20 /// Returns a value between 0.0 and 1.0 that represents the shutter's
21 /// opening at `time`.
22 #[inline]
23 pub fn opening(&self, pos: Time) -> f32 {
24 if pos < self.opening.start {
25 f32::from(pos) / f32::from(self.opening.start)
26 } else {
27 1.0f32 - f32::from(pos - self.opening.end) / f32::from(self.opening.end)
28 }
29 }
30
31 #[inline]
32 pub fn evaluate(&self, pos: f32) -> Time {
33 self.range.start.lerp(self.range.end, pos as _)
34 }
35
36 /// Returns the center of the shutter.
37 #[inline]
38 pub fn center(&self) -> Time {
39 (self.range.start + self.range.end) * 0.5
40 }
41}
42
43// Manual Eq implementation for Shutter
44// This is safe because we handle floating point comparison deterministically
45impl Eq for Shutter {}