1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
//! Coordinate space conversions for compositing.
//!
//! ## Coordinate Spaces (simplified)
//!
//! - **Image space**: origin top-left, +Y down (pixels).
//! Standard image/texture coordinates for sampling.
//!
//! - **Frame space**: origin CENTER, +Y up (pixels).
//! Used for layer transforms and viewport/gizmo.
//! `position = (0,0,0)` = layer centered in comp.
//! Same as viewport space - no conversion needed for gizmo!
//!
//! - **Object space**: origin at layer center, +Y up (pixels).
//! Local space for rotation/scale around pivot.
//!
//! ## Transform Pipeline
//!
//! ```text
//! Screen pixel (image space)
//! | image_to_frame()
//! v
//! Frame space (centered, Y-up)
//! | inverse model transform
//! v
//! Object space (layer center)
//! | object_to_src()
//! v
//! Source pixel (for texture sampling)
//! ```
use Vec2;
// =============================================================================
// Frame Space (centered, Y-up) - PRIMARY coordinate system for transforms
// =============================================================================
/// Image space -> Frame space (centered, Y-up).
///
/// Converts screen/image pixel coords to centered frame coords.
/// - Image (0, 0) = top-left -> Frame (-w/2, h/2)
/// - Image (w/2, h/2) = center -> Frame (0, 0)
/// - Image (w, h) = bottom-right -> Frame (w/2, -h/2)
/// Frame space -> Image space.
///
/// Inverse of image_to_frame.
// =============================================================================
// Object Space (layer center origin)
// =============================================================================
// =============================================================================
// Rotation Convention Helpers
// =============================================================================
// User convention: clockwise-positive (CW+) — matches After Effects, common UI expectation.
// Math convention: counter-clockwise-positive (CCW+) — glam, OpenGL, standard math.
/// Convert user rotation (CW+, degrees) to math rotation (CCW+, radians).
/// Convert math rotation (CCW+, radians) to user rotation (CW+, degrees).