forge
Explore
Log in

Don't you dare go Hollow

edith

Clone
★ 0

0 watching0 forksRust18.3 MiBfbc29d1Tahinli2 months ago972 commits

transform.rs81 lines, 2.8 KiBHistoryRawDownload
1//! Per-clip position/scale/rotate/crop, applied engine-side on the placed
2//! picture so that playback and export land the same pixel from the same
3//! numbers -- [`crate::color::ColorParams`]'s twin in every respect but what
4//! it moves: a grade changes what a sample *is*, this changes where it *goes*.
5//!
6//! Plain data with no invariants of its own: out-of-range or non-finite
7//! values are clamped where the geometry is built ([`crate::scale::crop_rect`],
8//! [`crate::scale::transformed_dst_rect`]), so a deserializer can hand this
9//! over unchecked, exactly as [`ColorParams`](crate::color::ColorParams) can.
10
11/// One clip's placement on the project canvas, on top of whatever
12/// [`crate::scale::FitPolicy`] already does.
13#[derive(Debug, Clone, Copy, PartialEq)]
14pub struct TransformParams {
15 /// Canvas-fraction offset from centred, positive right. `0.0` is
16 /// identity.
17 pub pos_x: f32,
18 /// Canvas-fraction offset from centred, positive down. `0.0` is identity.
19 pub pos_y: f32,
20 /// Multiplier on the fit-policy placement size. `1.0` is identity.
21 pub scale: f32,
22 /// Degrees, clockwise. Rendered at the nearest 90-degree step
23 /// ([`crate::scale::rotate_i420_90s`]); the value itself is kept exactly,
24 /// so a UI that later grows continuous rotation loses nothing already
25 /// saved. `0.0` is identity.
26 pub rotate: f32,
27 /// Fraction of the source cropped off the left, `0.0..0.5`.
28 pub crop_l: f32,
29 /// Fraction of the source cropped off the right, `0.0..0.5`.
30 pub crop_r: f32,
31 /// Fraction of the source cropped off the top, `0.0..0.5`.
32 pub crop_t: f32,
33 /// Fraction of the source cropped off the bottom, `0.0..0.5`.
34 pub crop_b: f32,
35}
36
37impl Default for TransformParams {
38 fn default() -> Self {
39 Self {
40 pos_x: 0.0,
41 pos_y: 0.0,
42 scale: 1.0,
43 rotate: 0.0,
44 crop_l: 0.0,
45 crop_r: 0.0,
46 crop_t: 0.0,
47 crop_b: 0.0,
48 }
49 }
50}
51
52impl TransformParams {
53 /// Whether this is the do-nothing setting. Compared exactly, for
54 /// [`crate::color::ColorParams::is_identity`]'s reason: only a value that
55 /// is precisely identity is allowed to skip the geometry.
56 pub fn is_identity(&self) -> bool {
57 self.pos_x == 0.0
58 && self.pos_y == 0.0
59 && self.scale == 1.0
60 && self.rotate == 0.0
61 && self.crop_l == 0.0
62 && self.crop_r == 0.0
63 && self.crop_t == 0.0
64 && self.crop_b == 0.0
65 }
66}
67
68#[cfg(test)]
69mod tests {
70 use super::*;
71
72 #[test]
73 fn default_is_identity() {
74 assert!(TransformParams::default().is_identity());
75 assert!(!TransformParams {
76 pos_x: 0.001,
77 ..TransformParams::default()
78 }
79 .is_identity());
80 }
81}