@@ -17,7 +17,7 @@ use std::f32::consts::PI;
1717// ============================================================================
1818
1919/// Animation easing functions for smooth transitions
20- #[ derive( Debug , Clone , Copy , PartialEq ) ]
20+ #[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
2121pub enum Easing {
2222 Linear ,
2323 EaseInOut ,
@@ -36,7 +36,7 @@ impl Easing {
3636 if t < 0.5 {
3737 2.0 * t * t
3838 } else {
39- 1.0 - ( -2.0 * t + 2.0 ) . powi ( 2 ) / 2.0
39+ 1.0 - ( -2.0f32 ) . mul_add ( t , 2.0 ) . powi ( 2 ) / 2.0
4040 }
4141 }
4242 Self :: EaseOutBounce => {
@@ -46,21 +46,21 @@ impl Easing {
4646 N1 * t * t
4747 } else if t < 2.0 / D1 {
4848 let t = t - 1.5 / D1 ;
49- N1 * t * t + 0.75
49+ ( N1 * t) . mul_add ( t , 0.75 )
5050 } else if t < 2.5 / D1 {
5151 let t = t - 2.25 / D1 ;
52- N1 * t * t + 0.9375
52+ ( N1 * t) . mul_add ( t , 0.9375 )
5353 } else {
5454 let t = t - 2.625 / D1 ;
55- N1 * t * t + 0.984375
55+ ( N1 * t) . mul_add ( t , 0.984_375 )
5656 }
5757 }
5858 Self :: EaseOutElastic => {
5959 if t == 0.0 || t == 1.0 {
6060 t
6161 } else {
6262 let c4 = ( 2.0 * PI ) / 3.0 ;
63- 2.0_f32 . powf ( -10.0 * t) * ( ( t * 10.0 - 0.75 ) * c4) . sin ( ) + 1.0
63+ ( -10.0 * t) . exp2 ( ) . mul_add ( ( ( t * 10.0 - 0.75 ) * c4) . sin ( ) , 1.0 )
6464 }
6565 }
6666 }
@@ -81,7 +81,7 @@ pub struct AnimatedValue {
8181impl AnimatedValue {
8282 /// Create new animated value
8383 #[ must_use]
84- pub fn new ( value : f32 ) -> Self {
84+ pub const fn new ( value : f32 ) -> Self {
8585 Self {
8686 start : value,
8787 end : value,
@@ -106,13 +106,13 @@ impl AnimatedValue {
106106 if self . progress < 1.0 {
107107 self . progress = ( self . progress + dt_ms / self . duration_ms ) . min ( 1.0 ) ;
108108 let t = self . easing . apply ( self . progress ) ;
109- self . current = self . start + ( self . end - self . start ) * t ;
109+ self . current = ( self . end - self . start ) . mul_add ( t , self . start ) ;
110110 }
111111 }
112112
113113 /// Get current value
114114 #[ must_use]
115- pub fn value ( & self ) -> f32 {
115+ pub const fn value ( & self ) -> f32 {
116116 self . current
117117 }
118118
@@ -167,15 +167,15 @@ impl AnimColor {
167167 #[ must_use]
168168 pub fn lerp ( self , other : Self , t : f32 ) -> Self {
169169 Self {
170- r : self . r + ( other. r - self . r ) * t ,
171- g : self . g + ( other. g - self . g ) * t ,
172- b : self . b + ( other. b - self . b ) * t ,
173- a : self . a + ( other. a - self . a ) * t ,
170+ r : ( other. r - self . r ) . mul_add ( t , self . r ) ,
171+ g : ( other. g - self . g ) . mul_add ( t , self . g ) ,
172+ b : ( other. b - self . b ) . mul_add ( t , self . b ) ,
173+ a : ( other. a - self . a ) . mul_add ( t , self . a ) ,
174174 }
175175 }
176176
177177 #[ must_use]
178- pub fn to_array ( self ) -> [ f32 ; 4 ] {
178+ pub const fn to_array ( self ) -> [ f32 ; 4 ] {
179179 [ self . r , self . g , self . b , self . a ]
180180 }
181181}
@@ -230,7 +230,7 @@ impl FrameTiming {
230230
231231 /// Get frame count
232232 #[ must_use]
233- pub fn frame_count ( & self ) -> u64 {
233+ pub const fn frame_count ( & self ) -> u64 {
234234 self . frame_count
235235 }
236236
@@ -380,7 +380,7 @@ impl BarChart {
380380
381381 /// Get corner radius for rounded bars
382382 #[ must_use]
383- pub fn corner_radius ( & self ) -> f32 {
383+ pub const fn corner_radius ( & self ) -> f32 {
384384 self . corner_radius
385385 }
386386
@@ -412,7 +412,7 @@ pub struct Particle {
412412impl Particle {
413413 /// Create new particle at position
414414 #[ must_use]
415- pub fn new ( x : f32 , y : f32 , color : AnimColor ) -> Self {
415+ pub const fn new ( x : f32 , y : f32 , color : AnimColor ) -> Self {
416416 Self {
417417 x,
418418 y,
@@ -485,7 +485,7 @@ impl ParticleSystem {
485485
486486 /// Maximum particles
487487 #[ must_use]
488- pub fn max_particles ( & self ) -> usize {
488+ pub const fn max_particles ( & self ) -> usize {
489489 self . max_particles
490490 }
491491
@@ -507,7 +507,7 @@ impl ParticleSystem {
507507
508508 let mut p = Particle :: new ( x, y, color) ;
509509 p. vx = angle. cos ( ) * speed;
510- p. vy = angle. sin ( ) * speed - 80.0 ; // Upward bias
510+ p. vy = angle. sin ( ) . mul_add ( speed, - 80.0 ) ; // Upward bias
511511 p. size = 4.0 + ( i as f32 % 8.0 ) ;
512512 p. lifetime = 800.0 + ( i as f32 * 50.0 ) % 400.0 ;
513513 p. max_lifetime = p. lifetime ;
@@ -558,14 +558,12 @@ impl DonutChart {
558558 /// Create donut chart with n segments
559559 #[ must_use]
560560 pub fn new ( segments : usize ) -> Self {
561- let colors = vec ! [
562- AnimColor :: INDIGO ,
561+ let colors = [ AnimColor :: INDIGO ,
563562 AnimColor :: EMERALD ,
564563 AnimColor :: AMBER ,
565564 AnimColor :: ROSE ,
566565 AnimColor :: SKY ,
567- AnimColor :: from_hex( 0x8B5CF6 ) ,
568- ] ;
566+ AnimColor :: from_hex ( 0x008B_5CF6 ) ] ;
569567
570568 Self {
571569 values : ( 0 ..segments) . map ( |_| AnimatedValue :: new ( 1.0 ) ) . collect ( ) ,
@@ -608,7 +606,7 @@ impl DonutChart {
608606
609607 /// Current rotation angle
610608 #[ must_use]
611- pub fn rotation ( & self ) -> f32 {
609+ pub const fn rotation ( & self ) -> f32 {
612610 self . rotation
613611 }
614612
@@ -636,7 +634,7 @@ impl DonutChart {
636634
637635 /// Inner/outer radius ratio
638636 #[ must_use]
639- pub fn radii ( & self ) -> ( f32 , f32 ) {
637+ pub const fn radii ( & self ) -> ( f32 , f32 ) {
640638 ( self . inner_radius , self . outer_radius )
641639 }
642640}
@@ -680,13 +678,13 @@ impl FpsCounter {
680678
681679 /// Get current FPS
682680 #[ must_use]
683- pub fn current_fps ( & self ) -> u32 {
681+ pub const fn current_fps ( & self ) -> u32 {
684682 self . current_fps
685683 }
686684
687685 /// Get performance grade
688686 #[ must_use]
689- pub fn grade ( & self ) -> & ' static str {
687+ pub const fn grade ( & self ) -> & ' static str {
690688 match self . current_fps {
691689 fps if fps >= 58 => "A+" ,
692690 fps if fps >= 50 => "A" ,
@@ -699,7 +697,7 @@ impl FpsCounter {
699697
700698 /// Get color based on FPS
701699 #[ must_use]
702- pub fn color ( & self ) -> AnimColor {
700+ pub const fn color ( & self ) -> AnimColor {
703701 match self . current_fps {
704702 fps if fps >= 55 => AnimColor :: EMERALD ,
705703 fps if fps >= 40 => AnimColor :: AMBER ,
@@ -728,7 +726,7 @@ pub enum Theme {
728726impl Theme {
729727 /// Background color
730728 #[ must_use]
731- pub fn background ( self ) -> AnimColor {
729+ pub const fn background ( self ) -> AnimColor {
732730 match self {
733731 Self :: Light => AnimColor :: new ( 0.98 , 0.98 , 0.98 , 1.0 ) ,
734732 Self :: Dark => AnimColor :: new ( 0.08 , 0.09 , 0.11 , 1.0 ) ,
@@ -737,7 +735,7 @@ impl Theme {
737735
738736 /// Text color
739737 #[ must_use]
740- pub fn text ( self ) -> AnimColor {
738+ pub const fn text ( self ) -> AnimColor {
741739 match self {
742740 Self :: Light => AnimColor :: new ( 0.07 , 0.09 , 0.11 , 1.0 ) ,
743741 Self :: Dark => AnimColor :: new ( 0.95 , 0.95 , 0.97 , 1.0 ) ,
@@ -746,7 +744,7 @@ impl Theme {
746744
747745 /// Card background
748746 #[ must_use]
749- pub fn card ( self ) -> AnimColor {
747+ pub const fn card ( self ) -> AnimColor {
750748 match self {
751749 Self :: Light => AnimColor :: WHITE ,
752750 Self :: Dark => AnimColor :: new ( 0.12 , 0.13 , 0.15 , 1.0 ) ,
@@ -755,7 +753,7 @@ impl Theme {
755753
756754 /// Toggle theme
757755 #[ must_use]
758- pub fn toggle ( self ) -> Self {
756+ pub const fn toggle ( self ) -> Self {
759757 match self {
760758 Self :: Light => Self :: Dark ,
761759 Self :: Dark => Self :: Light ,
@@ -802,19 +800,19 @@ impl ShowcaseDemo {
802800
803801 /// Width
804802 #[ must_use]
805- pub fn width ( & self ) -> f32 {
803+ pub const fn width ( & self ) -> f32 {
806804 self . width
807805 }
808806
809807 /// Height
810808 #[ must_use]
811- pub fn height ( & self ) -> f32 {
809+ pub const fn height ( & self ) -> f32 {
812810 self . height
813811 }
814812
815813 /// Current theme
816814 #[ must_use]
817- pub fn theme ( & self ) -> Theme {
815+ pub const fn theme ( & self ) -> Theme {
818816 self . theme
819817 }
820818
@@ -825,7 +823,7 @@ impl ShowcaseDemo {
825823
826824 /// Frame count
827825 #[ must_use]
828- pub fn frame_count ( & self ) -> u64 {
826+ pub const fn frame_count ( & self ) -> u64 {
829827 self . frame_timing . frame_count ( )
830828 }
831829
@@ -846,22 +844,22 @@ impl ShowcaseDemo {
846844
847845 /// Trigger data update with animation
848846 pub fn trigger_data_update ( & mut self ) {
849- self . data_seed = self . data_seed . wrapping_mul ( 1103515245 ) . wrapping_add ( 12345 ) ;
847+ self . data_seed = self . data_seed . wrapping_mul ( 1_103_515_245 ) . wrapping_add ( 12345 ) ;
850848 let seed = self . data_seed ;
851849
852850 // Pseudo-random values
853851 let values: Vec < f32 > = ( 0 ..6 )
854852 . map ( |i| {
855853 let v = ( ( seed >> ( i * 4 ) ) & 0xFF ) as f32 ;
856- 20.0 + ( v / 255.0 ) * 80.0
854+ ( v / 255.0 ) . mul_add ( 80.0 , 20.0 )
857855 } )
858856 . collect ( ) ;
859857 self . bar_chart . set_values ( & values) ;
860858
861859 let donut_values: Vec < f32 > = ( 0 ..5 )
862860 . map ( |i| {
863861 let v = ( ( seed >> ( i * 5 + 2 ) ) & 0x7F ) as f32 ;
864- 5.0 + ( v / 127.0 ) * 40.0
862+ ( v / 127.0 ) . mul_add ( 40.0 , 5.0 )
865863 } )
866864 . collect ( ) ;
867865 self . donut_chart . set_values ( & donut_values) ;
@@ -874,31 +872,31 @@ impl ShowcaseDemo {
874872
875873 /// Get FPS
876874 #[ must_use]
877- pub fn fps ( & self ) -> u32 {
875+ pub const fn fps ( & self ) -> u32 {
878876 self . fps_counter . current_fps ( )
879877 }
880878
881879 /// Get FPS grade
882880 #[ must_use]
883- pub fn fps_grade ( & self ) -> & ' static str {
881+ pub const fn fps_grade ( & self ) -> & ' static str {
884882 self . fps_counter . grade ( )
885883 }
886884
887885 /// Get bar chart ref
888886 #[ must_use]
889- pub fn bar_chart ( & self ) -> & BarChart {
887+ pub const fn bar_chart ( & self ) -> & BarChart {
890888 & self . bar_chart
891889 }
892890
893891 /// Get donut chart ref
894892 #[ must_use]
895- pub fn donut_chart ( & self ) -> & DonutChart {
893+ pub const fn donut_chart ( & self ) -> & DonutChart {
896894 & self . donut_chart
897895 }
898896
899897 /// Get particles ref
900898 #[ must_use]
901- pub fn particles ( & self ) -> & ParticleSystem {
899+ pub const fn particles ( & self ) -> & ParticleSystem {
902900 & self . particles
903901 }
904902}
0 commit comments