@@ -40,79 +40,93 @@ const AA_WIDTH: f32 = 0.01;
40
40
struct SDFValue ( f32 ) ;
41
41
impl SDFValue {
42
42
/// Creates a new SDFValue.
43
+ #[ must_use]
43
44
pub fn new ( value : f32 ) -> Self {
44
45
SDFValue ( value)
45
46
}
46
47
47
48
/// Returns the raw f32 distance.
49
+ #[ must_use]
48
50
pub fn value ( self ) -> f32 {
49
51
self . 0
50
52
}
51
53
52
54
/// Returns `true` if the SDF value is inside the shape (negative).
55
+ #[ must_use]
53
56
pub fn is_inside ( self ) -> bool {
54
57
self . 0 < 0.0
55
58
}
56
59
57
60
/// Returns `true` if the SDF value is outside the shape (positive).
61
+ #[ must_use]
58
62
pub fn is_outside ( self ) -> bool {
59
63
self . 0 > 0.0
60
64
}
61
65
62
66
/// Converts the SDF value to an alpha value for anti-aliasing.
63
67
/// Alpha is 1.0 deep inside, 0.0 deep outside, and smooth in between.
64
68
/// The transition happens from `AA_WIDTH` (alpha 0) to `-AA_WIDTH` (alpha 1).
69
+ #[ must_use]
65
70
pub fn to_alpha ( self ) -> f32 {
66
71
return smoothstep ( AA_WIDTH , -AA_WIDTH , self . 0 ) ;
67
72
}
68
73
69
74
/// Insets the shape by a given thickness.
70
75
/// This is done by shrinking the shape and then calculating the difference.
76
+ #[ must_use]
71
77
pub fn inset ( self , amount : f32 ) -> Self {
72
78
Self ( self . 0 . max ( -( self . 0 + amount) ) )
73
79
}
74
80
75
81
/// Expands (if amount > 0) or shrinks (if amount < 0) the shape.
76
82
/// This is equivalent to subtracting from the distance value.
83
+ #[ must_use]
77
84
pub fn offset ( & self , amount : f32 ) -> Self {
78
85
Self ( self . 0 - amount)
79
86
}
80
87
81
88
/// Takes the absolute value of the SDF, effectively creating an infinitely thin shell
82
89
/// on the surface of the original shape.
90
+ #[ must_use]
83
91
pub fn shell ( self ) -> Self {
84
92
Self ( self . 0 . abs ( ) )
85
93
}
86
94
87
95
/// Creates an outline (hollow shape) from the SDF.
96
+ #[ must_use]
88
97
pub fn to_outline ( self , thickness : f32 ) -> Self {
89
98
Self ( self . 0 . abs ( ) - thickness)
90
99
}
91
100
92
101
/// Difference operation (self - other). Result is inside if inside self AND outside other.
93
102
/// Equivalent to Intersection(self, Invert(other)).
103
+ #[ must_use]
94
104
pub fn difference ( self , other : Self ) -> Self {
95
105
Self ( self . 0 . max ( -other. 0 ) )
96
106
}
97
107
98
108
/// Union operation (self U other). Result is inside if inside self OR inside other.
109
+ #[ must_use]
99
110
pub fn union ( self , other : Self ) -> Self {
100
111
Self ( self . 0 . min ( other. 0 ) )
101
112
}
102
113
103
114
/// Intersection operation (self ∩ other). Result is inside if inside self AND inside other.
115
+ #[ must_use]
104
116
pub fn intersection ( self , other : Self ) -> Self {
105
117
Self ( self . 0 . max ( other. 0 ) )
106
118
}
107
119
108
120
/// Inverts the SDF (inside becomes outside and vice-versa).
121
+ #[ must_use]
109
122
pub fn invert ( self ) -> Self {
110
123
Self ( -self . 0 )
111
124
}
112
125
}
113
126
114
127
/// Calculates the distance from the origin to the center of the initial main circle so that
115
128
/// at time `0`, only one border circle is visible, with the others just touching the sides/bottom of the viewport.
129
+ #[ must_use]
116
130
fn calculate_initial_distance_for_main_circle_center (
117
131
aspect : Vec2 ,
118
132
border_circle_radius : f32 ,
@@ -213,6 +227,7 @@ fn calculate_initial_distance_for_main_circle_center(
213
227
214
228
/// Given an arc radius and its half-stroke width,
215
229
/// this function computes the angle that the arc extends beyond its endpoints because of the stroke width.
230
+ #[ must_use]
216
231
fn arc_cap_extension_angle ( arc_radius : f32 , half_stroke : f32 ) -> f32 {
217
232
// Avoid division by zero.
218
233
if arc_radius <= 0.0 {
@@ -244,6 +259,7 @@ fn arc_cap_extension_angle(arc_radius: f32, half_stroke: f32) -> f32 {
244
259
/// * `stroke`: Width of the arc body.
245
260
///
246
261
/// Returns the [`SDFValue`] for the arc.
262
+ #[ must_use]
247
263
fn sdf_arc_filled (
248
264
uv : Vec2 ,
249
265
center_shape : Vec2 ,
@@ -328,6 +344,7 @@ fn sdf_arc_filled(
328
344
/// * `fade_intensity`: `0` (fully faded/transparent) to `1` (fully opaque)
329
345
///
330
346
/// Returns `1` in the opaque region, fades to `0` outside it.
347
+ #[ must_use]
331
348
fn arc_fade_out (
332
349
uv : Vec2 ,
333
350
center : Vec2 ,
@@ -421,6 +438,7 @@ fn arc_fade_out(
421
438
///
422
439
/// Returns a `Vec2` with the first component being the [`SDFValue`] for the arc outline,
423
440
/// and the second component being the fade intensity.
441
+ #[ must_use]
424
442
fn sdf_arc_outline (
425
443
uv : Vec2 ,
426
444
center_shape : Vec2 ,
@@ -432,15 +450,17 @@ fn sdf_arc_outline(
432
450
fade_center_angle : f32 ,
433
451
opaque_percentage : f32 ,
434
452
) -> ( SDFValue , f32 ) {
435
- let sdf_outer = sdf_arc_filled (
453
+ let mut sdf_value = sdf_arc_filled (
436
454
uv,
437
455
center_shape,
438
456
start_angle,
439
457
end_angle,
440
458
spine_radius,
441
459
outer_radius * 2.0 ,
442
460
) ;
443
- let sdf_value = sdf_outer. inset ( outer_radius - inner_radius) ;
461
+ if inner_radius > EPSILON {
462
+ sdf_value = sdf_value. inset ( outer_radius - inner_radius) ;
463
+ }
444
464
let fade_intensity = arc_fade_out (
445
465
uv,
446
466
center_shape,
@@ -461,6 +481,7 @@ fn sdf_arc_outline(
461
481
/// * `radius`: The radius of the circle.
462
482
///
463
483
/// Returns the [`SDFValue`] for the circle.
484
+ #[ must_use]
464
485
fn sdf_circle_filled ( uv : Vec2 , center : Vec2 , radius : f32 ) -> SDFValue {
465
486
let p = uv - center;
466
487
let d = p. length ( ) - radius;
@@ -475,6 +496,7 @@ fn sdf_circle_filled(uv: Vec2, center: Vec2, radius: f32) -> SDFValue {
475
496
///
476
497
/// * `t` should be in `0..1`.
477
498
/// * `c` is usually in `-2..2`.
499
+ #[ must_use]
478
500
fn exp_time ( t : f32 , c : f32 ) -> f32 {
479
501
let c = c * 10.0 ;
480
502
@@ -488,6 +510,7 @@ fn exp_time(t: f32, c: f32) -> f32 {
488
510
}
489
511
490
512
/// Returns the derivative of the exponential function.
513
+ #[ must_use]
491
514
fn exp_time_derivative ( t : f32 , c : f32 ) -> f32 {
492
515
let c = c * 10.0 ;
493
516
@@ -500,6 +523,7 @@ fn exp_time_derivative(t: f32, c: f32) -> f32 {
500
523
numerator / denominator
501
524
}
502
525
526
+ #[ must_use]
503
527
fn offset_loop_time ( t : f32 , offset : f32 ) -> f32 {
504
528
// Apply offset
505
529
let offset_t = t + offset;
@@ -512,6 +536,7 @@ struct RotatingCircleResult {
512
536
angle : f32 ,
513
537
}
514
538
539
+ #[ must_use]
515
540
fn rotating_discrete_circle (
516
541
center : Vec2 ,
517
542
radius : f32 ,
@@ -541,6 +566,7 @@ fn rotating_discrete_circle(
541
566
/// * `end_time`: The point in parent_t (`0..1`) where this sub-animation should end.
542
567
///
543
568
/// Returns: `0` before `start_time`, `1` after `end_time`, and a `0..1` ramp between them.
569
+ #[ must_use]
544
570
fn remap_time ( parent_t : f32 , start_time : f32 , end_time : f32 ) -> f32 {
545
571
if start_time >= end_time {
546
572
// If start and end are the same, or invalid order we do an instant step.
@@ -568,6 +594,7 @@ enum Positioning {
568
594
/// * `half_dimensions`: half-width and half-height of the box.
569
595
///
570
596
/// Returns the signed distance from the box.
597
+ #[ must_use]
571
598
fn sdf_box_filled ( uv : Vec2 , center : Vec2 , positioning : Positioning , half_dimensions : Vec2 ) -> f32 {
572
599
let actual_box_center = match positioning {
573
600
Positioning :: Centered => center,
@@ -598,6 +625,7 @@ fn sdf_box_filled(uv: Vec2, center: Vec2, positioning: Positioning, half_dimensi
598
625
/// * `stroke`: This parameter will define the width of the outline.
599
626
///
600
627
/// Returns the signed distance from the rectangle outline.
628
+ #[ must_use]
601
629
fn sdf_box_outline (
602
630
uv : Vec2 ,
603
631
center : Vec2 ,
@@ -624,6 +652,7 @@ fn sdf_box_outline(
624
652
/// `t`: progress of the bar, from 0.0 (empty) to 1.0 (full).
625
653
/// `index`: vertical stacking index of the bar. Index 0 is the top-most bar.
626
654
/// Returns an alpha value (0.0 to 1.0) for the pixel, representing the bar's visibility.
655
+ #[ must_use]
627
656
fn draw_time_bar ( uv : Vec2 , aspect : Vec2 , stroke : f32 , aa_width : f32 , t : f32 , index : u32 ) -> f32 {
628
657
// --- Bar Configuration ---
629
658
// The `stroke` argument is interpreted as the desired height of the bar.
@@ -704,6 +733,7 @@ fn draw_time_bar(uv: Vec2, aspect: Vec2, stroke: f32, aa_width: f32, t: f32, ind
704
733
/// `index`: vertical stacking index of the bar. Index 0 is the top-most bar.
705
734
/// `steps`: the number of discrete steps the bar fills in. If 0, bar is invisible. If 1, bar fades in fully.
706
735
/// Returns an alpha value (0.0 to 1.0) for the pixel, representing the bar's visibility.
736
+ #[ must_use]
707
737
fn draw_time_bar_discrete (
708
738
uv : Vec2 ,
709
739
aspect : Vec2 ,
@@ -1025,7 +1055,7 @@ impl Inputs {
1025
1055
-PI / 4.0 ,
1026
1056
PI / 4.0 ,
1027
1057
1.0 ,
1028
- 0.1 ,
1058
+ 0.0 ,
1029
1059
0.5 ,
1030
1060
-PI / 4.0 ,
1031
1061
1.0 ,
0 commit comments