astrelis-ui 0.2.4

UI Framework designed for Astrelis Game Engine
Documentation
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
//! Animation system for UI widgets.
//!
//! Provides smooth transitions and effects for widget properties like position, size,
//! opacity, color, rotation, and scale.
//!
//! # Example
//!
//! ```ignore
//! use astrelis_ui::*;
//!
//! // Create an animation system
//! let mut anim_system = AnimationSystem::new();
//!
//! // Animate opacity
//! anim_system.animate(
//!     widget_id,
//!     Animation::new(AnimatableProperty::Opacity)
//!         .from(0.0)
//!         .to(1.0)
//!         .duration(0.3)
//!         .easing(EasingFunction::EaseInOut)
//! );
//!
//! // Update animations
//! anim_system.update(delta_time);
//!
//! // Apply animations to widgets
//! anim_system.apply(&mut ui_tree);
//! ```

use crate::widget_id::WidgetId;
use ahash::HashMap;

/// Properties that can be animated.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum AnimatableProperty {
    /// Opacity (0.0 to 1.0)
    Opacity,
    /// X position (alias for TranslateX for backward compatibility)
    PositionX,
    /// Y position (alias for TranslateY for backward compatibility)
    PositionY,
    /// Width
    Width,
    /// Height
    Height,
    /// Rotation in radians
    Rotation,
    /// X scale
    ScaleX,
    /// Y scale
    ScaleY,
    /// Red color channel (0.0 to 1.0)
    ColorR,
    /// Green color channel (0.0 to 1.0)
    ColorG,
    /// Blue color channel (0.0 to 1.0)
    ColorB,
    /// Alpha color channel (0.0 to 1.0)
    ColorA,
    /// Border radius
    BorderRadius,
    /// Padding
    Padding,
    /// Visual-only X translation (does not affect layout)
    TranslateX,
    /// Visual-only Y translation (does not affect layout)
    TranslateY,
}

/// Easing functions for animations.
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum EasingFunction {
    /// Linear interpolation
    Linear,
    /// Ease in (slow start)
    EaseIn,
    /// Ease out (slow end)
    EaseOut,
    /// Ease in and out (slow start and end)
    EaseInOut,
    /// Bounce effect
    Bounce,
    /// Elastic effect
    Elastic,
    /// Quadratic ease in
    QuadIn,
    /// Quadratic ease out
    QuadOut,
    /// Quadratic ease in-out
    QuadInOut,
    /// Cubic ease in
    CubicIn,
    /// Cubic ease out
    CubicOut,
    /// Cubic ease in-out
    CubicInOut,
}

impl EasingFunction {
    /// Apply the easing function to a normalized time value (0.0 to 1.0).
    pub fn apply(&self, t: f32) -> f32 {
        let t = t.clamp(0.0, 1.0);

        match self {
            EasingFunction::Linear => t,
            EasingFunction::EaseIn => t * t,
            EasingFunction::EaseOut => t * (2.0 - t),
            EasingFunction::EaseInOut => {
                if t < 0.5 {
                    2.0 * t * t
                } else {
                    -1.0 + (4.0 - 2.0 * t) * t
                }
            }
            EasingFunction::Bounce => {
                if t < 1.0 / 2.75 {
                    7.5625 * t * t
                } else if t < 2.0 / 2.75 {
                    let t = t - 1.5 / 2.75;
                    7.5625 * t * t + 0.75
                } else if t < 2.5 / 2.75 {
                    let t = t - 2.25 / 2.75;
                    7.5625 * t * t + 0.9375
                } else {
                    let t = t - 2.625 / 2.75;
                    7.5625 * t * t + 0.984375
                }
            }
            EasingFunction::Elastic => {
                if t == 0.0 || t == 1.0 {
                    t
                } else {
                    let p = 0.3;
                    let s = p / 4.0;
                    let t = t - 1.0;
                    -(2.0f32.powf(10.0 * t) * ((t - s) * (2.0 * std::f32::consts::PI) / p).sin())
                }
            }
            EasingFunction::QuadIn => t * t,
            EasingFunction::QuadOut => t * (2.0 - t),
            EasingFunction::QuadInOut => {
                if t < 0.5 {
                    2.0 * t * t
                } else {
                    -1.0 + (4.0 - 2.0 * t) * t
                }
            }
            EasingFunction::CubicIn => t * t * t,
            EasingFunction::CubicOut => {
                let t = t - 1.0;
                t * t * t + 1.0
            }
            EasingFunction::CubicInOut => {
                let t = t * 2.0;
                if t < 1.0 {
                    0.5 * t * t * t
                } else {
                    let t = t - 2.0;
                    0.5 * (t * t * t + 2.0)
                }
            }
        }
    }
}

/// Animation state.
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum AnimationState {
    /// Animation is running
    Running,
    /// Animation is paused
    Paused,
    /// Animation is completed
    Completed,
}

/// An animation for a single property.
#[derive(Debug, Clone)]
pub struct Animation {
    /// The property being animated
    property: AnimatableProperty,
    /// Start value
    from: f32,
    /// End value
    to: f32,
    /// Duration in seconds
    duration: f32,
    /// Elapsed time in seconds
    elapsed: f32,
    /// Easing function
    easing: EasingFunction,
    /// Animation state
    state: AnimationState,
    /// Loop flag
    looping: bool,
    /// Yoyo flag (reverse direction at end)
    yoyo: bool,
    /// Current direction (1.0 = forward, -1.0 = reverse)
    direction: f32,
    /// Delay before starting (seconds)
    delay: f32,
    /// Delay elapsed time
    delay_elapsed: f32,
}

impl Animation {
    /// Create a new animation.
    pub fn new(property: AnimatableProperty) -> Self {
        Self {
            property,
            from: 0.0,
            to: 1.0,
            duration: 1.0,
            elapsed: 0.0,
            easing: EasingFunction::Linear,
            state: AnimationState::Running,
            looping: false,
            yoyo: false,
            direction: 1.0,
            delay: 0.0,
            delay_elapsed: 0.0,
        }
    }

    /// Set the start value.
    pub fn from(mut self, value: f32) -> Self {
        self.from = value;
        self
    }

    /// Set the end value.
    pub fn to(mut self, value: f32) -> Self {
        self.to = value;
        self
    }

    /// Set the duration in seconds.
    pub fn duration(mut self, duration: f32) -> Self {
        self.duration = duration;
        self
    }

    /// Set the easing function.
    pub fn easing(mut self, easing: EasingFunction) -> Self {
        self.easing = easing;
        self
    }

    /// Set looping.
    pub fn looping(mut self, looping: bool) -> Self {
        self.looping = looping;
        self
    }

    /// Set yoyo (reverse at end).
    pub fn yoyo(mut self, yoyo: bool) -> Self {
        self.yoyo = yoyo;
        self
    }

    /// Set delay before starting (seconds).
    pub fn delay(mut self, delay: f32) -> Self {
        self.delay = delay;
        self
    }

    /// Get the property being animated.
    pub fn property(&self) -> AnimatableProperty {
        self.property
    }

    /// Get the current value.
    pub fn value(&self) -> f32 {
        // If we haven't started due to delay, return from value
        if self.delay_elapsed < self.delay {
            return self.from;
        }

        let t = (self.elapsed / self.duration).clamp(0.0, 1.0);
        let eased_t = self.easing.apply(t);

        // For both forward and reverse, interpolate based on elapsed time
        self.from + (self.to - self.from) * eased_t
    }

    /// Get the current state.
    pub fn state(&self) -> AnimationState {
        self.state
    }

    /// Pause the animation.
    pub fn pause(&mut self) {
        self.state = AnimationState::Paused;
    }

    /// Resume the animation.
    pub fn resume(&mut self) {
        if self.state == AnimationState::Paused {
            self.state = AnimationState::Running;
        }
    }

    /// Reset the animation.
    pub fn reset(&mut self) {
        self.elapsed = 0.0;
        self.delay_elapsed = 0.0;
        self.state = AnimationState::Running;
        self.direction = 1.0;
    }

    /// Update the animation by delta time.
    ///
    /// Returns true if the animation is still running.
    pub fn update(&mut self, delta_time: f32) -> bool {
        if self.state != AnimationState::Running {
            return self.state != AnimationState::Completed;
        }

        // Handle delay
        if self.delay_elapsed < self.delay {
            self.delay_elapsed += delta_time;
            if self.delay_elapsed < self.delay {
                return true;
            }
            // Continue with animation after delay
            let _ = delta_time - (self.delay - self.delay_elapsed);
        }

        self.elapsed += delta_time * self.direction;

        if self.direction > 0.0 && self.elapsed >= self.duration {
            if self.yoyo {
                self.direction = -1.0;
                self.elapsed = self.duration;
            } else if self.looping {
                self.elapsed = 0.0;
            } else {
                self.elapsed = self.duration;
                self.state = AnimationState::Completed;
                return false;
            }
        } else if self.direction < 0.0 && self.elapsed <= 0.0 {
            if self.looping {
                self.direction = 1.0;
                self.elapsed = 0.0;
            } else {
                self.elapsed = 0.0;
                self.state = AnimationState::Completed;
                return false;
            }
        }

        true
    }
}

/// A collection of animations for a single widget.
#[derive(Debug, Clone)]
pub struct WidgetAnimations {
    /// Animations for different properties
    animations: HashMap<AnimatableProperty, Animation>,
}

impl WidgetAnimations {
    /// Create a new widget animations collection.
    pub fn new() -> Self {
        Self {
            animations: HashMap::default(),
        }
    }

    /// Add an animation.
    pub fn add(&mut self, animation: Animation) {
        self.animations.insert(animation.property(), animation);
    }

    /// Remove an animation.
    pub fn remove(&mut self, property: AnimatableProperty) {
        self.animations.remove(&property);
    }

    /// Get an animation.
    pub fn get(&self, property: AnimatableProperty) -> Option<&Animation> {
        self.animations.get(&property)
    }

    /// Get a mutable animation.
    pub fn get_mut(&mut self, property: AnimatableProperty) -> Option<&mut Animation> {
        self.animations.get_mut(&property)
    }

    /// Update all animations.
    ///
    /// Returns true if any animations are still running.
    pub fn update(&mut self, delta_time: f32) -> bool {
        let mut any_running = false;

        self.animations.retain(|_, animation| {
            let running = animation.update(delta_time);
            any_running |= running;
            running
        });

        any_running
    }

    /// Get all current animation values.
    pub fn values(&self) -> HashMap<AnimatableProperty, f32> {
        self.animations
            .iter()
            .map(|(prop, anim)| (*prop, anim.value()))
            .collect()
    }

    /// Check if there are any animations.
    pub fn is_empty(&self) -> bool {
        self.animations.is_empty()
    }

    /// Clear all animations.
    pub fn clear(&mut self) {
        self.animations.clear();
    }
}

impl Default for WidgetAnimations {
    fn default() -> Self {
        Self::new()
    }
}

/// Animation system for managing widget animations.
pub struct AnimationSystem {
    /// Animations per widget
    widget_animations: HashMap<WidgetId, WidgetAnimations>,
}

impl AnimationSystem {
    /// Create a new animation system.
    pub fn new() -> Self {
        Self {
            widget_animations: HashMap::default(),
        }
    }

    /// Add an animation for a widget.
    pub fn animate(&mut self, widget_id: WidgetId, animation: Animation) {
        self.widget_animations
            .entry(widget_id)
            .or_default()
            .add(animation);
    }

    /// Remove an animation for a widget.
    pub fn remove_animation(&mut self, widget_id: WidgetId, property: AnimatableProperty) {
        if let Some(animations) = self.widget_animations.get_mut(&widget_id) {
            animations.remove(property);
            if animations.is_empty() {
                self.widget_animations.remove(&widget_id);
            }
        }
    }

    /// Remove all animations for a widget.
    pub fn remove_widget_animations(&mut self, widget_id: WidgetId) {
        self.widget_animations.remove(&widget_id);
    }

    /// Get animations for a widget.
    pub fn get_animations(&self, widget_id: WidgetId) -> Option<&WidgetAnimations> {
        self.widget_animations.get(&widget_id)
    }

    /// Get mutable animations for a widget.
    pub fn get_animations_mut(&mut self, widget_id: WidgetId) -> Option<&mut WidgetAnimations> {
        self.widget_animations.get_mut(&widget_id)
    }

    /// Update all animations by delta time.
    pub fn update(&mut self, delta_time: f32) {
        self.widget_animations.retain(|_, animations| {
            animations.update(delta_time);
            !animations.is_empty()
        });
    }

    /// Get all animated widget values.
    ///
    /// Returns a map of widget IDs to their animated property values.
    pub fn animated_values(&self) -> HashMap<WidgetId, HashMap<AnimatableProperty, f32>> {
        self.widget_animations
            .iter()
            .map(|(id, animations)| (*id, animations.values()))
            .collect()
    }

    /// Clear all animations.
    pub fn clear(&mut self) {
        self.widget_animations.clear();
    }

    /// Get the number of animated widgets.
    pub fn widget_count(&self) -> usize {
        self.widget_animations.len()
    }

    /// Returns true if any animations are currently running.
    pub fn has_active(&self) -> bool {
        !self.widget_animations.is_empty()
    }

    /// Tick all animations by delta time and apply values to the UI.
    ///
    /// This combines `update()` with automatic application of animated values
    /// to the UI system via `update_opacity`, `update_translate_x/y`, `update_scale_x/y`.
    ///
    /// Call once per frame in the update loop:
    /// ```ignore
    /// fn update(&mut self, ctx: &mut AppCtx) {
    ///     let dt = ctx.delta_time();
    ///     self.animations.tick(dt, &mut self.ui);
    /// }
    /// ```
    pub fn tick(&mut self, delta_time: f32, ui: &mut crate::UiCore) {
        self.widget_animations.retain(|&widget_id, animations| {
            animations.update(delta_time);

            // Apply current values to the UI
            for (prop, value) in animations.values() {
                match prop {
                    AnimatableProperty::Opacity => {
                        ui.update_opacity(widget_id, value);
                    }
                    AnimatableProperty::TranslateX | AnimatableProperty::PositionX => {
                        ui.update_translate_x(widget_id, value);
                    }
                    AnimatableProperty::TranslateY | AnimatableProperty::PositionY => {
                        ui.update_translate_y(widget_id, value);
                    }
                    AnimatableProperty::ScaleX => {
                        ui.update_scale_x(widget_id, value);
                    }
                    AnimatableProperty::ScaleY => {
                        ui.update_scale_y(widget_id, value);
                    }
                    // Other properties don't have direct update_ methods yet
                    _ => {}
                }
            }

            !animations.is_empty()
        });
    }

    /// Tick all animations by delta time and apply values to the UI system.
    ///
    /// Convenience method that works with `UiSystem` instead of `UiCore`.
    pub fn tick_system(&mut self, delta_time: f32, ui: &mut crate::UiSystem) {
        self.tick(delta_time, ui.core_mut());
    }
}

impl Default for AnimationSystem {
    fn default() -> Self {
        Self::new()
    }
}

/// Helper function to create a fade-in animation.
pub fn fade_in(duration: f32) -> Animation {
    Animation::new(AnimatableProperty::Opacity)
        .from(0.0)
        .to(1.0)
        .duration(duration)
        .easing(EasingFunction::EaseInOut)
}

/// Helper function to create a fade-out animation.
pub fn fade_out(duration: f32) -> Animation {
    Animation::new(AnimatableProperty::Opacity)
        .from(1.0)
        .to(0.0)
        .duration(duration)
        .easing(EasingFunction::EaseInOut)
}

/// Helper function to create a slide-in animation from the left.
pub fn slide_in_left(from_x: f32, to_x: f32, duration: f32) -> Animation {
    Animation::new(AnimatableProperty::PositionX)
        .from(from_x)
        .to(to_x)
        .duration(duration)
        .easing(EasingFunction::EaseOut)
}

/// Helper function to create a slide-in animation from the top.
pub fn slide_in_top(from_y: f32, to_y: f32, duration: f32) -> Animation {
    Animation::new(AnimatableProperty::PositionY)
        .from(from_y)
        .to(to_y)
        .duration(duration)
        .easing(EasingFunction::EaseOut)
}

/// Helper function to create a scale animation.
pub fn scale(from: f32, to: f32, duration: f32) -> Animation {
    Animation::new(AnimatableProperty::ScaleX)
        .from(from)
        .to(to)
        .duration(duration)
        .easing(EasingFunction::EaseInOut)
}

/// Helper function to create a bounce animation.
pub fn bounce(duration: f32) -> Animation {
    Animation::new(AnimatableProperty::ScaleY)
        .from(1.0)
        .to(1.2)
        .duration(duration)
        .easing(EasingFunction::Bounce)
        .yoyo(true)
        .looping(true)
}

/// Helper function to create a translate-X animation (visual-only slide).
pub fn translate_x(from: f32, to: f32, duration: f32) -> Animation {
    Animation::new(AnimatableProperty::TranslateX)
        .from(from)
        .to(to)
        .duration(duration)
        .easing(EasingFunction::EaseOut)
}

/// Helper function to create a translate-Y animation (visual-only slide).
pub fn translate_y(from: f32, to: f32, duration: f32) -> Animation {
    Animation::new(AnimatableProperty::TranslateY)
        .from(from)
        .to(to)
        .duration(duration)
        .easing(EasingFunction::EaseOut)
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_linear_easing() {
        let easing = EasingFunction::Linear;
        assert_eq!(easing.apply(0.0), 0.0);
        assert_eq!(easing.apply(0.5), 0.5);
        assert_eq!(easing.apply(1.0), 1.0);
    }

    #[test]
    fn test_animation_update() {
        let mut anim = Animation::new(AnimatableProperty::Opacity)
            .from(0.0)
            .to(1.0)
            .duration(1.0);

        // At start
        assert_eq!(anim.value(), 0.0);

        // Halfway
        assert!(anim.update(0.5));
        assert!((anim.value() - 0.5).abs() < 0.01);

        // Complete - should return false when done
        assert!(!anim.update(0.5));
        assert_eq!(anim.value(), 1.0);
        assert_eq!(anim.state(), AnimationState::Completed);
    }

    #[test]
    fn test_animation_system() {
        let mut system = AnimationSystem::new();
        let widget_id = WidgetId::new("test_widget");

        system.animate(widget_id, fade_in(1.0));

        assert_eq!(system.widget_count(), 1);

        system.update(1.0);

        // Animation should be complete and removed
        assert_eq!(system.widget_count(), 0);
    }

    #[test]
    fn test_looping_animation() {
        let mut anim = Animation::new(AnimatableProperty::Opacity)
            .from(0.0)
            .to(1.0)
            .duration(1.0)
            .looping(true);

        // First loop
        anim.update(1.0);
        assert_eq!(anim.state(), AnimationState::Running);
        assert_eq!(anim.value(), 0.0); // Should loop back

        // Second loop
        anim.update(0.5);
        assert!((anim.value() - 0.5).abs() < 0.01);
    }

    #[test]
    fn test_yoyo_animation() {
        let mut anim = Animation::new(AnimatableProperty::Opacity)
            .from(0.0)
            .to(1.0)
            .duration(1.0)
            .yoyo(true);

        // Forward - should still be running after first direction
        assert!(anim.update(1.0));
        assert!((anim.value() - 1.0).abs() < 0.01);
        assert_eq!(anim.state(), AnimationState::Running);

        // Reverse - should complete and return false
        assert!(!anim.update(1.0));
        assert!((anim.value() - 0.0).abs() < 0.01);
        assert_eq!(anim.state(), AnimationState::Completed);
    }

    #[test]
    fn test_translate_animation_helpers() {
        let anim_x = translate_x(-100.0, 0.0, 0.5);
        assert_eq!(anim_x.property(), AnimatableProperty::TranslateX);
        assert_eq!(anim_x.value(), -100.0); // At start

        let anim_y = translate_y(-50.0, 0.0, 0.3);
        assert_eq!(anim_y.property(), AnimatableProperty::TranslateY);
        assert_eq!(anim_y.value(), -50.0); // At start
    }

    #[test]
    fn test_has_active() {
        let mut system = AnimationSystem::new();
        assert!(!system.has_active());

        let widget_id = WidgetId::new("test");
        system.animate(widget_id, fade_in(1.0));
        assert!(system.has_active());

        system.update(2.0); // Complete the animation
        assert!(!system.has_active());
    }

    #[test]
    fn test_easing_boundary_values() {
        // All easing functions should produce 0 at t=0 and 1 at t=1
        let easings = [
            EasingFunction::Linear,
            EasingFunction::EaseIn,
            EasingFunction::EaseOut,
            EasingFunction::EaseInOut,
            EasingFunction::QuadIn,
            EasingFunction::QuadOut,
            EasingFunction::QuadInOut,
            EasingFunction::CubicIn,
            EasingFunction::CubicOut,
            EasingFunction::CubicInOut,
        ];
        for easing in &easings {
            assert!(
                (easing.apply(0.0) - 0.0).abs() < 0.001,
                "{easing:?} failed at t=0"
            );
            assert!(
                (easing.apply(1.0) - 1.0).abs() < 0.001,
                "{easing:?} failed at t=1"
            );
        }
    }
}