You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: splashsurf_lib/src/traits.rs
+49-4Lines changed: 49 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -62,35 +62,42 @@ pub trait Index:
62
62
+ ThreadSafe
63
63
+ 'static
64
64
{
65
+
#[inline]
65
66
fnrange(start:Self,end:Self) -> IndexRange<Self>{
66
67
IndexRange::new(start, end)
67
68
}
68
69
70
+
#[inline(always)]
69
71
fntwo() -> Self{
70
72
Self::one() + Self::one()
71
73
}
72
74
73
75
/// Converts this value to the specified [`Real`] type `T` by converting first to `f64` followed by `T::from_f64`. If the value cannot be represented by the target type, `None` is returned.
76
+
#[inline]
74
77
fnto_real<R:Real>(self) -> Option<R>{
75
78
R::from_f64(self.to_f64()?)
76
79
}
77
80
78
81
/// Converts this value to the specified [`Real`] type, panics if the value cannot be represented by the target type.
82
+
#[inline]
79
83
fnto_real_unchecked<R:Real>(self) -> R{
80
84
R::from_f64(self.to_f64().unwrap()).unwrap()
81
85
}
82
86
83
87
/// Multiplies this value by the specified `i32` coefficient. Panics if the coefficient cannot be converted into the target type.
88
+
#[inline]
84
89
fntimes(self,n:i32) -> Self{
85
90
self.mul(Self::from_i32(n).unwrap())
86
91
}
87
92
88
93
/// Returns the squared value of this value.
94
+
#[inline]
89
95
fnsquared(self) -> Self{
90
96
self*self
91
97
}
92
98
93
99
/// Returns the cubed value of this value.
100
+
#[inline]
94
101
fncubed(self) -> Self{
95
102
self*self*self
96
103
}
@@ -117,19 +124,21 @@ pub trait Real:
117
124
+ ThreadSafe
118
125
{
119
126
/// Converts the given float value to this Real type
120
-
#[inline]
127
+
#[inline(always)]
121
128
fnfrom_float<T>(value:T) -> Self
122
-
whereSelf:SupersetOf<T>
129
+
whereSelf:SupersetOf<T>
123
130
{
124
131
Self::from_subset(&value)
125
132
}
126
-
133
+
127
134
/// Converts this value to the specified [`Index`] type. If the value cannot be represented by the target type, `None` is returned.
135
+
#[inline]
128
136
fnto_index<I:Index>(self) -> Option<I>{
129
137
I::from_f64(self.to_f64()?)
130
138
}
131
139
132
140
/// Converts this value to the specified [`Index`] type, panics if the value cannot be represented by the target type.
141
+
#[inline]
133
142
fnto_index_unchecked<I:Index>(self) -> I{
134
143
I::from_f64(self.to_f64().unwrap()).unwrap()
135
144
}
@@ -206,6 +215,42 @@ impl<From: Real> RealConvert for &From {
206
215
}
207
216
}
208
217
218
+
implRealConvertforf32{
219
+
typeOut<To>
220
+
= To
221
+
where
222
+
To:Real;
223
+
224
+
/// Converts this `f32` value to the target `Real` type. Never returns `None`.
225
+
#[inline(always)]
226
+
fntry_convert<To:Real>(self) -> Option<To>{
227
+
Some(To::from_float(self))
228
+
}
229
+
/// Converts this `f32` value to the target `Real` type. Never panics.
230
+
#[inline(always)]
231
+
fnconvert<To:Real>(self) -> To{
232
+
To::from_float(self)
233
+
}
234
+
}
235
+
236
+
implRealConvertforf64{
237
+
typeOut<To>
238
+
= To
239
+
where
240
+
To:Real;
241
+
242
+
/// Converts this `f64` value to the target `Real` type. Never returns `None`.
243
+
#[inline(always)]
244
+
fntry_convert<To:Real>(self) -> Option<To>{
245
+
Some(To::from_float(self))
246
+
}
247
+
/// Converts this `f64` value to the target `Real` type. Never panics.
0 commit comments