1 // Generated from vec.rs.tera template. Edit the template, not the generated file.
2
3 use crate::{f64::math, BVec3, BVec3A, DQuat, DVec2, DVec4, FloatExt, IVec3, UVec3, Vec3};
4
5 use core::fmt;
6 use core::iter::{Product, Sum};
7 use core::{f32, ops::*};
8
9 /// Creates a 3-dimensional vector.
10 #[inline(always)]
11 #[must_use]
dvec3(x: f64, y: f64, z: f64) -> DVec312 pub const fn dvec3(x: f64, y: f64, z: f64) -> DVec3 {
13 DVec3::new(x, y, z)
14 }
15
16 /// A 3-dimensional vector.
17 #[derive(Clone, Copy, PartialEq)]
18 #[cfg_attr(not(target_arch = "spirv"), repr(C))]
19 #[cfg_attr(target_arch = "spirv", repr(simd))]
20 pub struct DVec3 {
21 pub x: f64,
22 pub y: f64,
23 pub z: f64,
24 }
25
26 impl DVec3 {
27 /// All zeroes.
28 pub const ZERO: Self = Self::splat(0.0);
29
30 /// All ones.
31 pub const ONE: Self = Self::splat(1.0);
32
33 /// All negative ones.
34 pub const NEG_ONE: Self = Self::splat(-1.0);
35
36 /// All `f64::MIN`.
37 pub const MIN: Self = Self::splat(f64::MIN);
38
39 /// All `f64::MAX`.
40 pub const MAX: Self = Self::splat(f64::MAX);
41
42 /// All `f64::NAN`.
43 pub const NAN: Self = Self::splat(f64::NAN);
44
45 /// All `f64::INFINITY`.
46 pub const INFINITY: Self = Self::splat(f64::INFINITY);
47
48 /// All `f64::NEG_INFINITY`.
49 pub const NEG_INFINITY: Self = Self::splat(f64::NEG_INFINITY);
50
51 /// A unit vector pointing along the positive X axis.
52 pub const X: Self = Self::new(1.0, 0.0, 0.0);
53
54 /// A unit vector pointing along the positive Y axis.
55 pub const Y: Self = Self::new(0.0, 1.0, 0.0);
56
57 /// A unit vector pointing along the positive Z axis.
58 pub const Z: Self = Self::new(0.0, 0.0, 1.0);
59
60 /// A unit vector pointing along the negative X axis.
61 pub const NEG_X: Self = Self::new(-1.0, 0.0, 0.0);
62
63 /// A unit vector pointing along the negative Y axis.
64 pub const NEG_Y: Self = Self::new(0.0, -1.0, 0.0);
65
66 /// A unit vector pointing along the negative Z axis.
67 pub const NEG_Z: Self = Self::new(0.0, 0.0, -1.0);
68
69 /// The unit axes.
70 pub const AXES: [Self; 3] = [Self::X, Self::Y, Self::Z];
71
72 /// Creates a new vector.
73 #[inline(always)]
74 #[must_use]
new(x: f64, y: f64, z: f64) -> Self75 pub const fn new(x: f64, y: f64, z: f64) -> Self {
76 Self { x, y, z }
77 }
78
79 /// Creates a vector with all elements set to `v`.
80 #[inline]
81 #[must_use]
splat(v: f64) -> Self82 pub const fn splat(v: f64) -> Self {
83 Self { x: v, y: v, z: v }
84 }
85
86 /// Returns a vector containing each element of `self` modified by a mapping function `f`.
87 #[inline]
88 #[must_use]
map<F>(self, f: F) -> Self where F: Fn(f64) -> f64,89 pub fn map<F>(self, f: F) -> Self
90 where
91 F: Fn(f64) -> f64,
92 {
93 Self::new(f(self.x), f(self.y), f(self.z))
94 }
95
96 /// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use
97 /// for each element of `self`.
98 ///
99 /// A true element in the mask uses the corresponding element from `if_true`, and false
100 /// uses the element from `if_false`.
101 #[inline]
102 #[must_use]
select(mask: BVec3, if_true: Self, if_false: Self) -> Self103 pub fn select(mask: BVec3, if_true: Self, if_false: Self) -> Self {
104 Self {
105 x: if mask.test(0) { if_true.x } else { if_false.x },
106 y: if mask.test(1) { if_true.y } else { if_false.y },
107 z: if mask.test(2) { if_true.z } else { if_false.z },
108 }
109 }
110
111 /// Creates a new vector from an array.
112 #[inline]
113 #[must_use]
from_array(a: [f64; 3]) -> Self114 pub const fn from_array(a: [f64; 3]) -> Self {
115 Self::new(a[0], a[1], a[2])
116 }
117
118 /// `[x, y, z]`
119 #[inline]
120 #[must_use]
to_array(&self) -> [f64; 3]121 pub const fn to_array(&self) -> [f64; 3] {
122 [self.x, self.y, self.z]
123 }
124
125 /// Creates a vector from the first 3 values in `slice`.
126 ///
127 /// # Panics
128 ///
129 /// Panics if `slice` is less than 3 elements long.
130 #[inline]
131 #[must_use]
from_slice(slice: &[f64]) -> Self132 pub const fn from_slice(slice: &[f64]) -> Self {
133 assert!(slice.len() >= 3);
134 Self::new(slice[0], slice[1], slice[2])
135 }
136
137 /// Writes the elements of `self` to the first 3 elements in `slice`.
138 ///
139 /// # Panics
140 ///
141 /// Panics if `slice` is less than 3 elements long.
142 #[inline]
write_to_slice(self, slice: &mut [f64])143 pub fn write_to_slice(self, slice: &mut [f64]) {
144 slice[..3].copy_from_slice(&self.to_array());
145 }
146
147 /// Internal method for creating a 3D vector from a 4D vector, discarding `w`.
148 #[allow(dead_code)]
149 #[inline]
150 #[must_use]
from_vec4(v: DVec4) -> Self151 pub(crate) fn from_vec4(v: DVec4) -> Self {
152 Self {
153 x: v.x,
154 y: v.y,
155 z: v.z,
156 }
157 }
158
159 /// Creates a 4D vector from `self` and the given `w` value.
160 #[inline]
161 #[must_use]
extend(self, w: f64) -> DVec4162 pub fn extend(self, w: f64) -> DVec4 {
163 DVec4::new(self.x, self.y, self.z, w)
164 }
165
166 /// Creates a 2D vector from the `x` and `y` elements of `self`, discarding `z`.
167 ///
168 /// Truncation may also be performed by using [`self.xy()`][crate::swizzles::Vec3Swizzles::xy()].
169 #[inline]
170 #[must_use]
truncate(self) -> DVec2171 pub fn truncate(self) -> DVec2 {
172 use crate::swizzles::Vec3Swizzles;
173 self.xy()
174 }
175
176 /// Creates a 3D vector from `self` with the given value of `x`.
177 #[inline]
178 #[must_use]
with_x(mut self, x: f64) -> Self179 pub fn with_x(mut self, x: f64) -> Self {
180 self.x = x;
181 self
182 }
183
184 /// Creates a 3D vector from `self` with the given value of `y`.
185 #[inline]
186 #[must_use]
with_y(mut self, y: f64) -> Self187 pub fn with_y(mut self, y: f64) -> Self {
188 self.y = y;
189 self
190 }
191
192 /// Creates a 3D vector from `self` with the given value of `z`.
193 #[inline]
194 #[must_use]
with_z(mut self, z: f64) -> Self195 pub fn with_z(mut self, z: f64) -> Self {
196 self.z = z;
197 self
198 }
199
200 /// Computes the dot product of `self` and `rhs`.
201 #[inline]
202 #[must_use]
dot(self, rhs: Self) -> f64203 pub fn dot(self, rhs: Self) -> f64 {
204 (self.x * rhs.x) + (self.y * rhs.y) + (self.z * rhs.z)
205 }
206
207 /// Returns a vector where every component is the dot product of `self` and `rhs`.
208 #[inline]
209 #[must_use]
dot_into_vec(self, rhs: Self) -> Self210 pub fn dot_into_vec(self, rhs: Self) -> Self {
211 Self::splat(self.dot(rhs))
212 }
213
214 /// Computes the cross product of `self` and `rhs`.
215 #[inline]
216 #[must_use]
cross(self, rhs: Self) -> Self217 pub fn cross(self, rhs: Self) -> Self {
218 Self {
219 x: self.y * rhs.z - rhs.y * self.z,
220 y: self.z * rhs.x - rhs.z * self.x,
221 z: self.x * rhs.y - rhs.x * self.y,
222 }
223 }
224
225 /// Returns a vector containing the minimum values for each element of `self` and `rhs`.
226 ///
227 /// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`.
228 #[inline]
229 #[must_use]
min(self, rhs: Self) -> Self230 pub fn min(self, rhs: Self) -> Self {
231 Self {
232 x: self.x.min(rhs.x),
233 y: self.y.min(rhs.y),
234 z: self.z.min(rhs.z),
235 }
236 }
237
238 /// Returns a vector containing the maximum values for each element of `self` and `rhs`.
239 ///
240 /// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`.
241 #[inline]
242 #[must_use]
max(self, rhs: Self) -> Self243 pub fn max(self, rhs: Self) -> Self {
244 Self {
245 x: self.x.max(rhs.x),
246 y: self.y.max(rhs.y),
247 z: self.z.max(rhs.z),
248 }
249 }
250
251 /// Component-wise clamping of values, similar to [`f64::clamp`].
252 ///
253 /// Each element in `min` must be less-or-equal to the corresponding element in `max`.
254 ///
255 /// # Panics
256 ///
257 /// Will panic if `min` is greater than `max` when `glam_assert` is enabled.
258 #[inline]
259 #[must_use]
clamp(self, min: Self, max: Self) -> Self260 pub fn clamp(self, min: Self, max: Self) -> Self {
261 glam_assert!(min.cmple(max).all(), "clamp: expected min <= max");
262 self.max(min).min(max)
263 }
264
265 /// Returns the horizontal minimum of `self`.
266 ///
267 /// In other words this computes `min(x, y, ..)`.
268 #[inline]
269 #[must_use]
min_element(self) -> f64270 pub fn min_element(self) -> f64 {
271 self.x.min(self.y.min(self.z))
272 }
273
274 /// Returns the horizontal maximum of `self`.
275 ///
276 /// In other words this computes `max(x, y, ..)`.
277 #[inline]
278 #[must_use]
max_element(self) -> f64279 pub fn max_element(self) -> f64 {
280 self.x.max(self.y.max(self.z))
281 }
282
283 /// Returns the sum of all elements of `self`.
284 ///
285 /// In other words, this computes `self.x + self.y + ..`.
286 #[inline]
287 #[must_use]
element_sum(self) -> f64288 pub fn element_sum(self) -> f64 {
289 self.x + self.y + self.z
290 }
291
292 /// Returns the product of all elements of `self`.
293 ///
294 /// In other words, this computes `self.x * self.y * ..`.
295 #[inline]
296 #[must_use]
element_product(self) -> f64297 pub fn element_product(self) -> f64 {
298 self.x * self.y * self.z
299 }
300
301 /// Returns a vector mask containing the result of a `==` comparison for each element of
302 /// `self` and `rhs`.
303 ///
304 /// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all
305 /// elements.
306 #[inline]
307 #[must_use]
cmpeq(self, rhs: Self) -> BVec3308 pub fn cmpeq(self, rhs: Self) -> BVec3 {
309 BVec3::new(self.x.eq(&rhs.x), self.y.eq(&rhs.y), self.z.eq(&rhs.z))
310 }
311
312 /// Returns a vector mask containing the result of a `!=` comparison for each element of
313 /// `self` and `rhs`.
314 ///
315 /// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all
316 /// elements.
317 #[inline]
318 #[must_use]
cmpne(self, rhs: Self) -> BVec3319 pub fn cmpne(self, rhs: Self) -> BVec3 {
320 BVec3::new(self.x.ne(&rhs.x), self.y.ne(&rhs.y), self.z.ne(&rhs.z))
321 }
322
323 /// Returns a vector mask containing the result of a `>=` comparison for each element of
324 /// `self` and `rhs`.
325 ///
326 /// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all
327 /// elements.
328 #[inline]
329 #[must_use]
cmpge(self, rhs: Self) -> BVec3330 pub fn cmpge(self, rhs: Self) -> BVec3 {
331 BVec3::new(self.x.ge(&rhs.x), self.y.ge(&rhs.y), self.z.ge(&rhs.z))
332 }
333
334 /// Returns a vector mask containing the result of a `>` comparison for each element of
335 /// `self` and `rhs`.
336 ///
337 /// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all
338 /// elements.
339 #[inline]
340 #[must_use]
cmpgt(self, rhs: Self) -> BVec3341 pub fn cmpgt(self, rhs: Self) -> BVec3 {
342 BVec3::new(self.x.gt(&rhs.x), self.y.gt(&rhs.y), self.z.gt(&rhs.z))
343 }
344
345 /// Returns a vector mask containing the result of a `<=` comparison for each element of
346 /// `self` and `rhs`.
347 ///
348 /// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all
349 /// elements.
350 #[inline]
351 #[must_use]
cmple(self, rhs: Self) -> BVec3352 pub fn cmple(self, rhs: Self) -> BVec3 {
353 BVec3::new(self.x.le(&rhs.x), self.y.le(&rhs.y), self.z.le(&rhs.z))
354 }
355
356 /// Returns a vector mask containing the result of a `<` comparison for each element of
357 /// `self` and `rhs`.
358 ///
359 /// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all
360 /// elements.
361 #[inline]
362 #[must_use]
cmplt(self, rhs: Self) -> BVec3363 pub fn cmplt(self, rhs: Self) -> BVec3 {
364 BVec3::new(self.x.lt(&rhs.x), self.y.lt(&rhs.y), self.z.lt(&rhs.z))
365 }
366
367 /// Returns a vector containing the absolute value of each element of `self`.
368 #[inline]
369 #[must_use]
abs(self) -> Self370 pub fn abs(self) -> Self {
371 Self {
372 x: math::abs(self.x),
373 y: math::abs(self.y),
374 z: math::abs(self.z),
375 }
376 }
377
378 /// Returns a vector with elements representing the sign of `self`.
379 ///
380 /// - `1.0` if the number is positive, `+0.0` or `INFINITY`
381 /// - `-1.0` if the number is negative, `-0.0` or `NEG_INFINITY`
382 /// - `NAN` if the number is `NAN`
383 #[inline]
384 #[must_use]
signum(self) -> Self385 pub fn signum(self) -> Self {
386 Self {
387 x: math::signum(self.x),
388 y: math::signum(self.y),
389 z: math::signum(self.z),
390 }
391 }
392
393 /// Returns a vector with signs of `rhs` and the magnitudes of `self`.
394 #[inline]
395 #[must_use]
copysign(self, rhs: Self) -> Self396 pub fn copysign(self, rhs: Self) -> Self {
397 Self {
398 x: math::copysign(self.x, rhs.x),
399 y: math::copysign(self.y, rhs.y),
400 z: math::copysign(self.z, rhs.z),
401 }
402 }
403
404 /// Returns a bitmask with the lowest 3 bits set to the sign bits from the elements of `self`.
405 ///
406 /// A negative element results in a `1` bit and a positive element in a `0` bit. Element `x` goes
407 /// into the first lowest bit, element `y` into the second, etc.
408 #[inline]
409 #[must_use]
is_negative_bitmask(self) -> u32410 pub fn is_negative_bitmask(self) -> u32 {
411 (self.x.is_sign_negative() as u32)
412 | (self.y.is_sign_negative() as u32) << 1
413 | (self.z.is_sign_negative() as u32) << 2
414 }
415
416 /// Returns `true` if, and only if, all elements are finite. If any element is either
417 /// `NaN`, positive or negative infinity, this will return `false`.
418 #[inline]
419 #[must_use]
is_finite(self) -> bool420 pub fn is_finite(self) -> bool {
421 self.x.is_finite() && self.y.is_finite() && self.z.is_finite()
422 }
423
424 /// Performs `is_finite` on each element of self, returning a vector mask of the results.
425 ///
426 /// In other words, this computes `[x.is_finite(), y.is_finite(), ...]`.
is_finite_mask(self) -> BVec3427 pub fn is_finite_mask(self) -> BVec3 {
428 BVec3::new(self.x.is_finite(), self.y.is_finite(), self.z.is_finite())
429 }
430
431 /// Returns `true` if any elements are `NaN`.
432 #[inline]
433 #[must_use]
is_nan(self) -> bool434 pub fn is_nan(self) -> bool {
435 self.x.is_nan() || self.y.is_nan() || self.z.is_nan()
436 }
437
438 /// Performs `is_nan` on each element of self, returning a vector mask of the results.
439 ///
440 /// In other words, this computes `[x.is_nan(), y.is_nan(), ...]`.
441 #[inline]
442 #[must_use]
is_nan_mask(self) -> BVec3443 pub fn is_nan_mask(self) -> BVec3 {
444 BVec3::new(self.x.is_nan(), self.y.is_nan(), self.z.is_nan())
445 }
446
447 /// Computes the length of `self`.
448 #[doc(alias = "magnitude")]
449 #[inline]
450 #[must_use]
length(self) -> f64451 pub fn length(self) -> f64 {
452 math::sqrt(self.dot(self))
453 }
454
455 /// Computes the squared length of `self`.
456 ///
457 /// This is faster than `length()` as it avoids a square root operation.
458 #[doc(alias = "magnitude2")]
459 #[inline]
460 #[must_use]
length_squared(self) -> f64461 pub fn length_squared(self) -> f64 {
462 self.dot(self)
463 }
464
465 /// Computes `1.0 / length()`.
466 ///
467 /// For valid results, `self` must _not_ be of length zero.
468 #[inline]
469 #[must_use]
length_recip(self) -> f64470 pub fn length_recip(self) -> f64 {
471 self.length().recip()
472 }
473
474 /// Computes the Euclidean distance between two points in space.
475 #[inline]
476 #[must_use]
distance(self, rhs: Self) -> f64477 pub fn distance(self, rhs: Self) -> f64 {
478 (self - rhs).length()
479 }
480
481 /// Compute the squared euclidean distance between two points in space.
482 #[inline]
483 #[must_use]
distance_squared(self, rhs: Self) -> f64484 pub fn distance_squared(self, rhs: Self) -> f64 {
485 (self - rhs).length_squared()
486 }
487
488 /// Returns the element-wise quotient of [Euclidean division] of `self` by `rhs`.
489 #[inline]
490 #[must_use]
div_euclid(self, rhs: Self) -> Self491 pub fn div_euclid(self, rhs: Self) -> Self {
492 Self::new(
493 math::div_euclid(self.x, rhs.x),
494 math::div_euclid(self.y, rhs.y),
495 math::div_euclid(self.z, rhs.z),
496 )
497 }
498
499 /// Returns the element-wise remainder of [Euclidean division] of `self` by `rhs`.
500 ///
501 /// [Euclidean division]: f64::rem_euclid
502 #[inline]
503 #[must_use]
rem_euclid(self, rhs: Self) -> Self504 pub fn rem_euclid(self, rhs: Self) -> Self {
505 Self::new(
506 math::rem_euclid(self.x, rhs.x),
507 math::rem_euclid(self.y, rhs.y),
508 math::rem_euclid(self.z, rhs.z),
509 )
510 }
511
512 /// Returns `self` normalized to length 1.0.
513 ///
514 /// For valid results, `self` must be finite and _not_ of length zero, nor very close to zero.
515 ///
516 /// See also [`Self::try_normalize()`] and [`Self::normalize_or_zero()`].
517 ///
518 /// Panics
519 ///
520 /// Will panic if the resulting normalized vector is not finite when `glam_assert` is enabled.
521 #[inline]
522 #[must_use]
normalize(self) -> Self523 pub fn normalize(self) -> Self {
524 #[allow(clippy::let_and_return)]
525 let normalized = self.mul(self.length_recip());
526 glam_assert!(normalized.is_finite());
527 normalized
528 }
529
530 /// Returns `self` normalized to length 1.0 if possible, else returns `None`.
531 ///
532 /// In particular, if the input is zero (or very close to zero), or non-finite,
533 /// the result of this operation will be `None`.
534 ///
535 /// See also [`Self::normalize_or_zero()`].
536 #[inline]
537 #[must_use]
try_normalize(self) -> Option<Self>538 pub fn try_normalize(self) -> Option<Self> {
539 let rcp = self.length_recip();
540 if rcp.is_finite() && rcp > 0.0 {
541 Some(self * rcp)
542 } else {
543 None
544 }
545 }
546
547 /// Returns `self` normalized to length 1.0 if possible, else returns a
548 /// fallback value.
549 ///
550 /// In particular, if the input is zero (or very close to zero), or non-finite,
551 /// the result of this operation will be the fallback value.
552 ///
553 /// See also [`Self::try_normalize()`].
554 #[inline]
555 #[must_use]
normalize_or(self, fallback: Self) -> Self556 pub fn normalize_or(self, fallback: Self) -> Self {
557 let rcp = self.length_recip();
558 if rcp.is_finite() && rcp > 0.0 {
559 self * rcp
560 } else {
561 fallback
562 }
563 }
564
565 /// Returns `self` normalized to length 1.0 if possible, else returns zero.
566 ///
567 /// In particular, if the input is zero (or very close to zero), or non-finite,
568 /// the result of this operation will be zero.
569 ///
570 /// See also [`Self::try_normalize()`].
571 #[inline]
572 #[must_use]
normalize_or_zero(self) -> Self573 pub fn normalize_or_zero(self) -> Self {
574 self.normalize_or(Self::ZERO)
575 }
576
577 /// Returns whether `self` is length `1.0` or not.
578 ///
579 /// Uses a precision threshold of approximately `1e-4`.
580 #[inline]
581 #[must_use]
is_normalized(self) -> bool582 pub fn is_normalized(self) -> bool {
583 math::abs(self.length_squared() - 1.0) <= 2e-4
584 }
585
586 /// Returns the vector projection of `self` onto `rhs`.
587 ///
588 /// `rhs` must be of non-zero length.
589 ///
590 /// # Panics
591 ///
592 /// Will panic if `rhs` is zero length when `glam_assert` is enabled.
593 #[inline]
594 #[must_use]
project_onto(self, rhs: Self) -> Self595 pub fn project_onto(self, rhs: Self) -> Self {
596 let other_len_sq_rcp = rhs.dot(rhs).recip();
597 glam_assert!(other_len_sq_rcp.is_finite());
598 rhs * self.dot(rhs) * other_len_sq_rcp
599 }
600
601 /// Returns the vector rejection of `self` from `rhs`.
602 ///
603 /// The vector rejection is the vector perpendicular to the projection of `self` onto
604 /// `rhs`, in rhs words the result of `self - self.project_onto(rhs)`.
605 ///
606 /// `rhs` must be of non-zero length.
607 ///
608 /// # Panics
609 ///
610 /// Will panic if `rhs` has a length of zero when `glam_assert` is enabled.
611 #[doc(alias("plane"))]
612 #[inline]
613 #[must_use]
reject_from(self, rhs: Self) -> Self614 pub fn reject_from(self, rhs: Self) -> Self {
615 self - self.project_onto(rhs)
616 }
617
618 /// Returns the vector projection of `self` onto `rhs`.
619 ///
620 /// `rhs` must be normalized.
621 ///
622 /// # Panics
623 ///
624 /// Will panic if `rhs` is not normalized when `glam_assert` is enabled.
625 #[inline]
626 #[must_use]
project_onto_normalized(self, rhs: Self) -> Self627 pub fn project_onto_normalized(self, rhs: Self) -> Self {
628 glam_assert!(rhs.is_normalized());
629 rhs * self.dot(rhs)
630 }
631
632 /// Returns the vector rejection of `self` from `rhs`.
633 ///
634 /// The vector rejection is the vector perpendicular to the projection of `self` onto
635 /// `rhs`, in rhs words the result of `self - self.project_onto(rhs)`.
636 ///
637 /// `rhs` must be normalized.
638 ///
639 /// # Panics
640 ///
641 /// Will panic if `rhs` is not normalized when `glam_assert` is enabled.
642 #[doc(alias("plane"))]
643 #[inline]
644 #[must_use]
reject_from_normalized(self, rhs: Self) -> Self645 pub fn reject_from_normalized(self, rhs: Self) -> Self {
646 self - self.project_onto_normalized(rhs)
647 }
648
649 /// Returns a vector containing the nearest integer to a number for each element of `self`.
650 /// Round half-way cases away from 0.0.
651 #[inline]
652 #[must_use]
round(self) -> Self653 pub fn round(self) -> Self {
654 Self {
655 x: math::round(self.x),
656 y: math::round(self.y),
657 z: math::round(self.z),
658 }
659 }
660
661 /// Returns a vector containing the largest integer less than or equal to a number for each
662 /// element of `self`.
663 #[inline]
664 #[must_use]
floor(self) -> Self665 pub fn floor(self) -> Self {
666 Self {
667 x: math::floor(self.x),
668 y: math::floor(self.y),
669 z: math::floor(self.z),
670 }
671 }
672
673 /// Returns a vector containing the smallest integer greater than or equal to a number for
674 /// each element of `self`.
675 #[inline]
676 #[must_use]
ceil(self) -> Self677 pub fn ceil(self) -> Self {
678 Self {
679 x: math::ceil(self.x),
680 y: math::ceil(self.y),
681 z: math::ceil(self.z),
682 }
683 }
684
685 /// Returns a vector containing the integer part each element of `self`. This means numbers are
686 /// always truncated towards zero.
687 #[inline]
688 #[must_use]
trunc(self) -> Self689 pub fn trunc(self) -> Self {
690 Self {
691 x: math::trunc(self.x),
692 y: math::trunc(self.y),
693 z: math::trunc(self.z),
694 }
695 }
696
697 /// Returns a vector containing the fractional part of the vector as `self - self.trunc()`.
698 ///
699 /// Note that this differs from the GLSL implementation of `fract` which returns
700 /// `self - self.floor()`.
701 ///
702 /// Note that this is fast but not precise for large numbers.
703 #[inline]
704 #[must_use]
fract(self) -> Self705 pub fn fract(self) -> Self {
706 self - self.trunc()
707 }
708
709 /// Returns a vector containing the fractional part of the vector as `self - self.floor()`.
710 ///
711 /// Note that this differs from the Rust implementation of `fract` which returns
712 /// `self - self.trunc()`.
713 ///
714 /// Note that this is fast but not precise for large numbers.
715 #[inline]
716 #[must_use]
fract_gl(self) -> Self717 pub fn fract_gl(self) -> Self {
718 self - self.floor()
719 }
720
721 /// Returns a vector containing `e^self` (the exponential function) for each element of
722 /// `self`.
723 #[inline]
724 #[must_use]
exp(self) -> Self725 pub fn exp(self) -> Self {
726 Self::new(math::exp(self.x), math::exp(self.y), math::exp(self.z))
727 }
728
729 /// Returns a vector containing each element of `self` raised to the power of `n`.
730 #[inline]
731 #[must_use]
powf(self, n: f64) -> Self732 pub fn powf(self, n: f64) -> Self {
733 Self::new(
734 math::powf(self.x, n),
735 math::powf(self.y, n),
736 math::powf(self.z, n),
737 )
738 }
739
740 /// Returns a vector containing the reciprocal `1.0/n` of each element of `self`.
741 #[inline]
742 #[must_use]
recip(self) -> Self743 pub fn recip(self) -> Self {
744 Self {
745 x: 1.0 / self.x,
746 y: 1.0 / self.y,
747 z: 1.0 / self.z,
748 }
749 }
750
751 /// Performs a linear interpolation between `self` and `rhs` based on the value `s`.
752 ///
753 /// When `s` is `0.0`, the result will be equal to `self`. When `s` is `1.0`, the result
754 /// will be equal to `rhs`. When `s` is outside of range `[0, 1]`, the result is linearly
755 /// extrapolated.
756 #[doc(alias = "mix")]
757 #[inline]
758 #[must_use]
lerp(self, rhs: Self, s: f64) -> Self759 pub fn lerp(self, rhs: Self, s: f64) -> Self {
760 self * (1.0 - s) + rhs * s
761 }
762
763 /// Moves towards `rhs` based on the value `d`.
764 ///
765 /// When `d` is `0.0`, the result will be equal to `self`. When `d` is equal to
766 /// `self.distance(rhs)`, the result will be equal to `rhs`. Will not go past `rhs`.
767 #[inline]
768 #[must_use]
move_towards(&self, rhs: Self, d: f64) -> Self769 pub fn move_towards(&self, rhs: Self, d: f64) -> Self {
770 let a = rhs - *self;
771 let len = a.length();
772 if len <= d || len <= 1e-4 {
773 return rhs;
774 }
775 *self + a / len * d
776 }
777
778 /// Calculates the midpoint between `self` and `rhs`.
779 ///
780 /// The midpoint is the average of, or halfway point between, two vectors.
781 /// `a.midpoint(b)` should yield the same result as `a.lerp(b, 0.5)`
782 /// while being slightly cheaper to compute.
783 #[inline]
midpoint(self, rhs: Self) -> Self784 pub fn midpoint(self, rhs: Self) -> Self {
785 (self + rhs) * 0.5
786 }
787
788 /// Returns true if the absolute difference of all elements between `self` and `rhs` is
789 /// less than or equal to `max_abs_diff`.
790 ///
791 /// This can be used to compare if two vectors contain similar elements. It works best when
792 /// comparing with a known value. The `max_abs_diff` that should be used used depends on
793 /// the values being compared against.
794 ///
795 /// For more see
796 /// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/).
797 #[inline]
798 #[must_use]
abs_diff_eq(self, rhs: Self, max_abs_diff: f64) -> bool799 pub fn abs_diff_eq(self, rhs: Self, max_abs_diff: f64) -> bool {
800 self.sub(rhs).abs().cmple(Self::splat(max_abs_diff)).all()
801 }
802
803 /// Returns a vector with a length no less than `min` and no more than `max`.
804 ///
805 /// # Panics
806 ///
807 /// Will panic if `min` is greater than `max`, or if either `min` or `max` is negative, when `glam_assert` is enabled.
808 #[inline]
809 #[must_use]
clamp_length(self, min: f64, max: f64) -> Self810 pub fn clamp_length(self, min: f64, max: f64) -> Self {
811 glam_assert!(0.0 <= min);
812 glam_assert!(min <= max);
813 let length_sq = self.length_squared();
814 if length_sq < min * min {
815 min * (self / math::sqrt(length_sq))
816 } else if length_sq > max * max {
817 max * (self / math::sqrt(length_sq))
818 } else {
819 self
820 }
821 }
822
823 /// Returns a vector with a length no more than `max`.
824 ///
825 /// # Panics
826 ///
827 /// Will panic if `max` is negative when `glam_assert` is enabled.
828 #[inline]
829 #[must_use]
clamp_length_max(self, max: f64) -> Self830 pub fn clamp_length_max(self, max: f64) -> Self {
831 glam_assert!(0.0 <= max);
832 let length_sq = self.length_squared();
833 if length_sq > max * max {
834 max * (self / math::sqrt(length_sq))
835 } else {
836 self
837 }
838 }
839
840 /// Returns a vector with a length no less than `min`.
841 ///
842 /// # Panics
843 ///
844 /// Will panic if `min` is negative when `glam_assert` is enabled.
845 #[inline]
846 #[must_use]
clamp_length_min(self, min: f64) -> Self847 pub fn clamp_length_min(self, min: f64) -> Self {
848 glam_assert!(0.0 <= min);
849 let length_sq = self.length_squared();
850 if length_sq < min * min {
851 min * (self / math::sqrt(length_sq))
852 } else {
853 self
854 }
855 }
856
857 /// Fused multiply-add. Computes `(self * a) + b` element-wise with only one rounding
858 /// error, yielding a more accurate result than an unfused multiply-add.
859 ///
860 /// Using `mul_add` *may* be more performant than an unfused multiply-add if the target
861 /// architecture has a dedicated fma CPU instruction. However, this is not always true,
862 /// and will be heavily dependant on designing algorithms with specific target hardware in
863 /// mind.
864 #[inline]
865 #[must_use]
mul_add(self, a: Self, b: Self) -> Self866 pub fn mul_add(self, a: Self, b: Self) -> Self {
867 Self::new(
868 math::mul_add(self.x, a.x, b.x),
869 math::mul_add(self.y, a.y, b.y),
870 math::mul_add(self.z, a.z, b.z),
871 )
872 }
873
874 /// Returns the reflection vector for a given incident vector `self` and surface normal
875 /// `normal`.
876 ///
877 /// `normal` must be normalized.
878 ///
879 /// # Panics
880 ///
881 /// Will panic if `normal` is not normalized when `glam_assert` is enabled.
882 #[inline]
883 #[must_use]
reflect(self, normal: Self) -> Self884 pub fn reflect(self, normal: Self) -> Self {
885 glam_assert!(normal.is_normalized());
886 self - 2.0 * self.dot(normal) * normal
887 }
888
889 /// Returns the refraction direction for a given incident vector `self`, surface normal
890 /// `normal` and ratio of indices of refraction, `eta`. When total internal reflection occurs,
891 /// a zero vector will be returned.
892 ///
893 /// `self` and `normal` must be normalized.
894 ///
895 /// # Panics
896 ///
897 /// Will panic if `self` or `normal` is not normalized when `glam_assert` is enabled.
898 #[inline]
899 #[must_use]
refract(self, normal: Self, eta: f64) -> Self900 pub fn refract(self, normal: Self, eta: f64) -> Self {
901 glam_assert!(self.is_normalized());
902 glam_assert!(normal.is_normalized());
903 let n_dot_i = normal.dot(self);
904 let k = 1.0 - eta * eta * (1.0 - n_dot_i * n_dot_i);
905 if k >= 0.0 {
906 eta * self - (eta * n_dot_i + math::sqrt(k)) * normal
907 } else {
908 Self::ZERO
909 }
910 }
911
912 /// Returns the angle (in radians) between two vectors in the range `[0, +π]`.
913 ///
914 /// The inputs do not need to be unit vectors however they must be non-zero.
915 #[inline]
916 #[must_use]
angle_between(self, rhs: Self) -> f64917 pub fn angle_between(self, rhs: Self) -> f64 {
918 math::acos_approx(
919 self.dot(rhs)
920 .div(math::sqrt(self.length_squared().mul(rhs.length_squared()))),
921 )
922 }
923
924 /// Returns some vector that is orthogonal to the given one.
925 ///
926 /// The input vector must be finite and non-zero.
927 ///
928 /// The output vector is not necessarily unit length. For that use
929 /// [`Self::any_orthonormal_vector()`] instead.
930 #[inline]
931 #[must_use]
any_orthogonal_vector(&self) -> Self932 pub fn any_orthogonal_vector(&self) -> Self {
933 // This can probably be optimized
934 if math::abs(self.x) > math::abs(self.y) {
935 Self::new(-self.z, 0.0, self.x) // self.cross(Self::Y)
936 } else {
937 Self::new(0.0, self.z, -self.y) // self.cross(Self::X)
938 }
939 }
940
941 /// Returns any unit vector that is orthogonal to the given one.
942 ///
943 /// The input vector must be unit length.
944 ///
945 /// # Panics
946 ///
947 /// Will panic if `self` is not normalized when `glam_assert` is enabled.
948 #[inline]
949 #[must_use]
any_orthonormal_vector(&self) -> Self950 pub fn any_orthonormal_vector(&self) -> Self {
951 glam_assert!(self.is_normalized());
952 // From https://graphics.pixar.com/library/OrthonormalB/paper.pdf
953 let sign = math::signum(self.z);
954 let a = -1.0 / (sign + self.z);
955 let b = self.x * self.y * a;
956 Self::new(b, sign + self.y * self.y * a, -self.y)
957 }
958
959 /// Given a unit vector return two other vectors that together form an orthonormal
960 /// basis. That is, all three vectors are orthogonal to each other and are normalized.
961 ///
962 /// # Panics
963 ///
964 /// Will panic if `self` is not normalized when `glam_assert` is enabled.
965 #[inline]
966 #[must_use]
any_orthonormal_pair(&self) -> (Self, Self)967 pub fn any_orthonormal_pair(&self) -> (Self, Self) {
968 glam_assert!(self.is_normalized());
969 // From https://graphics.pixar.com/library/OrthonormalB/paper.pdf
970 let sign = math::signum(self.z);
971 let a = -1.0 / (sign + self.z);
972 let b = self.x * self.y * a;
973 (
974 Self::new(1.0 + sign * self.x * self.x * a, sign * b, -sign * self.x),
975 Self::new(b, sign + self.y * self.y * a, -self.y),
976 )
977 }
978
979 /// Performs a spherical linear interpolation between `self` and `rhs` based on the value `s`.
980 ///
981 /// When `s` is `0.0`, the result will be equal to `self`. When `s` is `1.0`, the result
982 /// will be equal to `rhs`. When `s` is outside of range `[0, 1]`, the result is linearly
983 /// extrapolated.
984 #[inline]
985 #[must_use]
slerp(self, rhs: Self, s: f64) -> Self986 pub fn slerp(self, rhs: Self, s: f64) -> Self {
987 let self_length = self.length();
988 let rhs_length = rhs.length();
989 // Cosine of the angle between the vectors [-1, 1], or NaN if either vector has a zero length
990 let dot = self.dot(rhs) / (self_length * rhs_length);
991 // If dot is close to 1 or -1, or is NaN the calculations for t1 and t2 break down
992 if math::abs(dot) < 1.0 - 3e-7 {
993 // Angle between the vectors [0, +π]
994 let theta = math::acos_approx(dot);
995 // Sine of the angle between vectors [0, 1]
996 let sin_theta = math::sin(theta);
997 let t1 = math::sin(theta * (1. - s));
998 let t2 = math::sin(theta * s);
999
1000 // Interpolate vector lengths
1001 let result_length = self_length.lerp(rhs_length, s);
1002 // Scale the vectors to the target length and interpolate them
1003 return (self * (result_length / self_length) * t1
1004 + rhs * (result_length / rhs_length) * t2)
1005 * sin_theta.recip();
1006 }
1007 if dot < 0.0 {
1008 // Vectors are almost parallel in opposing directions
1009
1010 // Create a rotation from self to rhs along some axis
1011 let axis = self.any_orthogonal_vector().normalize();
1012 let rotation = DQuat::from_axis_angle(axis, core::f64::consts::PI * s);
1013 // Interpolate vector lengths
1014 let result_length = self_length.lerp(rhs_length, s);
1015 rotation * self * (result_length / self_length)
1016 } else {
1017 // Vectors are almost parallel in the same direction, or dot was NaN
1018 self.lerp(rhs, s)
1019 }
1020 }
1021
1022 /// Casts all elements of `self` to `f32`.
1023 #[inline]
1024 #[must_use]
as_vec3(&self) -> crate::Vec31025 pub fn as_vec3(&self) -> crate::Vec3 {
1026 crate::Vec3::new(self.x as f32, self.y as f32, self.z as f32)
1027 }
1028
1029 /// Casts all elements of `self` to `f32`.
1030 #[inline]
1031 #[must_use]
as_vec3a(&self) -> crate::Vec3A1032 pub fn as_vec3a(&self) -> crate::Vec3A {
1033 crate::Vec3A::new(self.x as f32, self.y as f32, self.z as f32)
1034 }
1035
1036 /// Casts all elements of `self` to `i8`.
1037 #[inline]
1038 #[must_use]
as_i8vec3(&self) -> crate::I8Vec31039 pub fn as_i8vec3(&self) -> crate::I8Vec3 {
1040 crate::I8Vec3::new(self.x as i8, self.y as i8, self.z as i8)
1041 }
1042
1043 /// Casts all elements of `self` to `u8`.
1044 #[inline]
1045 #[must_use]
as_u8vec3(&self) -> crate::U8Vec31046 pub fn as_u8vec3(&self) -> crate::U8Vec3 {
1047 crate::U8Vec3::new(self.x as u8, self.y as u8, self.z as u8)
1048 }
1049
1050 /// Casts all elements of `self` to `i16`.
1051 #[inline]
1052 #[must_use]
as_i16vec3(&self) -> crate::I16Vec31053 pub fn as_i16vec3(&self) -> crate::I16Vec3 {
1054 crate::I16Vec3::new(self.x as i16, self.y as i16, self.z as i16)
1055 }
1056
1057 /// Casts all elements of `self` to `u16`.
1058 #[inline]
1059 #[must_use]
as_u16vec3(&self) -> crate::U16Vec31060 pub fn as_u16vec3(&self) -> crate::U16Vec3 {
1061 crate::U16Vec3::new(self.x as u16, self.y as u16, self.z as u16)
1062 }
1063
1064 /// Casts all elements of `self` to `i32`.
1065 #[inline]
1066 #[must_use]
as_ivec3(&self) -> crate::IVec31067 pub fn as_ivec3(&self) -> crate::IVec3 {
1068 crate::IVec3::new(self.x as i32, self.y as i32, self.z as i32)
1069 }
1070
1071 /// Casts all elements of `self` to `u32`.
1072 #[inline]
1073 #[must_use]
as_uvec3(&self) -> crate::UVec31074 pub fn as_uvec3(&self) -> crate::UVec3 {
1075 crate::UVec3::new(self.x as u32, self.y as u32, self.z as u32)
1076 }
1077
1078 /// Casts all elements of `self` to `i64`.
1079 #[inline]
1080 #[must_use]
as_i64vec3(&self) -> crate::I64Vec31081 pub fn as_i64vec3(&self) -> crate::I64Vec3 {
1082 crate::I64Vec3::new(self.x as i64, self.y as i64, self.z as i64)
1083 }
1084
1085 /// Casts all elements of `self` to `u64`.
1086 #[inline]
1087 #[must_use]
as_u64vec3(&self) -> crate::U64Vec31088 pub fn as_u64vec3(&self) -> crate::U64Vec3 {
1089 crate::U64Vec3::new(self.x as u64, self.y as u64, self.z as u64)
1090 }
1091 }
1092
1093 impl Default for DVec3 {
1094 #[inline(always)]
default() -> Self1095 fn default() -> Self {
1096 Self::ZERO
1097 }
1098 }
1099
1100 impl Div<DVec3> for DVec3 {
1101 type Output = Self;
1102 #[inline]
div(self, rhs: Self) -> Self1103 fn div(self, rhs: Self) -> Self {
1104 Self {
1105 x: self.x.div(rhs.x),
1106 y: self.y.div(rhs.y),
1107 z: self.z.div(rhs.z),
1108 }
1109 }
1110 }
1111
1112 impl Div<&DVec3> for DVec3 {
1113 type Output = DVec3;
1114 #[inline]
div(self, rhs: &DVec3) -> DVec31115 fn div(self, rhs: &DVec3) -> DVec3 {
1116 self.div(*rhs)
1117 }
1118 }
1119
1120 impl Div<&DVec3> for &DVec3 {
1121 type Output = DVec3;
1122 #[inline]
div(self, rhs: &DVec3) -> DVec31123 fn div(self, rhs: &DVec3) -> DVec3 {
1124 (*self).div(*rhs)
1125 }
1126 }
1127
1128 impl Div<DVec3> for &DVec3 {
1129 type Output = DVec3;
1130 #[inline]
div(self, rhs: DVec3) -> DVec31131 fn div(self, rhs: DVec3) -> DVec3 {
1132 (*self).div(rhs)
1133 }
1134 }
1135
1136 impl DivAssign<DVec3> for DVec3 {
1137 #[inline]
div_assign(&mut self, rhs: Self)1138 fn div_assign(&mut self, rhs: Self) {
1139 self.x.div_assign(rhs.x);
1140 self.y.div_assign(rhs.y);
1141 self.z.div_assign(rhs.z);
1142 }
1143 }
1144
1145 impl DivAssign<&DVec3> for DVec3 {
1146 #[inline]
div_assign(&mut self, rhs: &DVec3)1147 fn div_assign(&mut self, rhs: &DVec3) {
1148 self.div_assign(*rhs)
1149 }
1150 }
1151
1152 impl Div<f64> for DVec3 {
1153 type Output = Self;
1154 #[inline]
div(self, rhs: f64) -> Self1155 fn div(self, rhs: f64) -> Self {
1156 Self {
1157 x: self.x.div(rhs),
1158 y: self.y.div(rhs),
1159 z: self.z.div(rhs),
1160 }
1161 }
1162 }
1163
1164 impl Div<&f64> for DVec3 {
1165 type Output = DVec3;
1166 #[inline]
div(self, rhs: &f64) -> DVec31167 fn div(self, rhs: &f64) -> DVec3 {
1168 self.div(*rhs)
1169 }
1170 }
1171
1172 impl Div<&f64> for &DVec3 {
1173 type Output = DVec3;
1174 #[inline]
div(self, rhs: &f64) -> DVec31175 fn div(self, rhs: &f64) -> DVec3 {
1176 (*self).div(*rhs)
1177 }
1178 }
1179
1180 impl Div<f64> for &DVec3 {
1181 type Output = DVec3;
1182 #[inline]
div(self, rhs: f64) -> DVec31183 fn div(self, rhs: f64) -> DVec3 {
1184 (*self).div(rhs)
1185 }
1186 }
1187
1188 impl DivAssign<f64> for DVec3 {
1189 #[inline]
div_assign(&mut self, rhs: f64)1190 fn div_assign(&mut self, rhs: f64) {
1191 self.x.div_assign(rhs);
1192 self.y.div_assign(rhs);
1193 self.z.div_assign(rhs);
1194 }
1195 }
1196
1197 impl DivAssign<&f64> for DVec3 {
1198 #[inline]
div_assign(&mut self, rhs: &f64)1199 fn div_assign(&mut self, rhs: &f64) {
1200 self.div_assign(*rhs)
1201 }
1202 }
1203
1204 impl Div<DVec3> for f64 {
1205 type Output = DVec3;
1206 #[inline]
div(self, rhs: DVec3) -> DVec31207 fn div(self, rhs: DVec3) -> DVec3 {
1208 DVec3 {
1209 x: self.div(rhs.x),
1210 y: self.div(rhs.y),
1211 z: self.div(rhs.z),
1212 }
1213 }
1214 }
1215
1216 impl Div<&DVec3> for f64 {
1217 type Output = DVec3;
1218 #[inline]
div(self, rhs: &DVec3) -> DVec31219 fn div(self, rhs: &DVec3) -> DVec3 {
1220 self.div(*rhs)
1221 }
1222 }
1223
1224 impl Div<&DVec3> for &f64 {
1225 type Output = DVec3;
1226 #[inline]
div(self, rhs: &DVec3) -> DVec31227 fn div(self, rhs: &DVec3) -> DVec3 {
1228 (*self).div(*rhs)
1229 }
1230 }
1231
1232 impl Div<DVec3> for &f64 {
1233 type Output = DVec3;
1234 #[inline]
div(self, rhs: DVec3) -> DVec31235 fn div(self, rhs: DVec3) -> DVec3 {
1236 (*self).div(rhs)
1237 }
1238 }
1239
1240 impl Mul<DVec3> for DVec3 {
1241 type Output = Self;
1242 #[inline]
mul(self, rhs: Self) -> Self1243 fn mul(self, rhs: Self) -> Self {
1244 Self {
1245 x: self.x.mul(rhs.x),
1246 y: self.y.mul(rhs.y),
1247 z: self.z.mul(rhs.z),
1248 }
1249 }
1250 }
1251
1252 impl Mul<&DVec3> for DVec3 {
1253 type Output = DVec3;
1254 #[inline]
mul(self, rhs: &DVec3) -> DVec31255 fn mul(self, rhs: &DVec3) -> DVec3 {
1256 self.mul(*rhs)
1257 }
1258 }
1259
1260 impl Mul<&DVec3> for &DVec3 {
1261 type Output = DVec3;
1262 #[inline]
mul(self, rhs: &DVec3) -> DVec31263 fn mul(self, rhs: &DVec3) -> DVec3 {
1264 (*self).mul(*rhs)
1265 }
1266 }
1267
1268 impl Mul<DVec3> for &DVec3 {
1269 type Output = DVec3;
1270 #[inline]
mul(self, rhs: DVec3) -> DVec31271 fn mul(self, rhs: DVec3) -> DVec3 {
1272 (*self).mul(rhs)
1273 }
1274 }
1275
1276 impl MulAssign<DVec3> for DVec3 {
1277 #[inline]
mul_assign(&mut self, rhs: Self)1278 fn mul_assign(&mut self, rhs: Self) {
1279 self.x.mul_assign(rhs.x);
1280 self.y.mul_assign(rhs.y);
1281 self.z.mul_assign(rhs.z);
1282 }
1283 }
1284
1285 impl MulAssign<&DVec3> for DVec3 {
1286 #[inline]
mul_assign(&mut self, rhs: &DVec3)1287 fn mul_assign(&mut self, rhs: &DVec3) {
1288 self.mul_assign(*rhs)
1289 }
1290 }
1291
1292 impl Mul<f64> for DVec3 {
1293 type Output = Self;
1294 #[inline]
mul(self, rhs: f64) -> Self1295 fn mul(self, rhs: f64) -> Self {
1296 Self {
1297 x: self.x.mul(rhs),
1298 y: self.y.mul(rhs),
1299 z: self.z.mul(rhs),
1300 }
1301 }
1302 }
1303
1304 impl Mul<&f64> for DVec3 {
1305 type Output = DVec3;
1306 #[inline]
mul(self, rhs: &f64) -> DVec31307 fn mul(self, rhs: &f64) -> DVec3 {
1308 self.mul(*rhs)
1309 }
1310 }
1311
1312 impl Mul<&f64> for &DVec3 {
1313 type Output = DVec3;
1314 #[inline]
mul(self, rhs: &f64) -> DVec31315 fn mul(self, rhs: &f64) -> DVec3 {
1316 (*self).mul(*rhs)
1317 }
1318 }
1319
1320 impl Mul<f64> for &DVec3 {
1321 type Output = DVec3;
1322 #[inline]
mul(self, rhs: f64) -> DVec31323 fn mul(self, rhs: f64) -> DVec3 {
1324 (*self).mul(rhs)
1325 }
1326 }
1327
1328 impl MulAssign<f64> for DVec3 {
1329 #[inline]
mul_assign(&mut self, rhs: f64)1330 fn mul_assign(&mut self, rhs: f64) {
1331 self.x.mul_assign(rhs);
1332 self.y.mul_assign(rhs);
1333 self.z.mul_assign(rhs);
1334 }
1335 }
1336
1337 impl MulAssign<&f64> for DVec3 {
1338 #[inline]
mul_assign(&mut self, rhs: &f64)1339 fn mul_assign(&mut self, rhs: &f64) {
1340 self.mul_assign(*rhs)
1341 }
1342 }
1343
1344 impl Mul<DVec3> for f64 {
1345 type Output = DVec3;
1346 #[inline]
mul(self, rhs: DVec3) -> DVec31347 fn mul(self, rhs: DVec3) -> DVec3 {
1348 DVec3 {
1349 x: self.mul(rhs.x),
1350 y: self.mul(rhs.y),
1351 z: self.mul(rhs.z),
1352 }
1353 }
1354 }
1355
1356 impl Mul<&DVec3> for f64 {
1357 type Output = DVec3;
1358 #[inline]
mul(self, rhs: &DVec3) -> DVec31359 fn mul(self, rhs: &DVec3) -> DVec3 {
1360 self.mul(*rhs)
1361 }
1362 }
1363
1364 impl Mul<&DVec3> for &f64 {
1365 type Output = DVec3;
1366 #[inline]
mul(self, rhs: &DVec3) -> DVec31367 fn mul(self, rhs: &DVec3) -> DVec3 {
1368 (*self).mul(*rhs)
1369 }
1370 }
1371
1372 impl Mul<DVec3> for &f64 {
1373 type Output = DVec3;
1374 #[inline]
mul(self, rhs: DVec3) -> DVec31375 fn mul(self, rhs: DVec3) -> DVec3 {
1376 (*self).mul(rhs)
1377 }
1378 }
1379
1380 impl Add<DVec3> for DVec3 {
1381 type Output = Self;
1382 #[inline]
add(self, rhs: Self) -> Self1383 fn add(self, rhs: Self) -> Self {
1384 Self {
1385 x: self.x.add(rhs.x),
1386 y: self.y.add(rhs.y),
1387 z: self.z.add(rhs.z),
1388 }
1389 }
1390 }
1391
1392 impl Add<&DVec3> for DVec3 {
1393 type Output = DVec3;
1394 #[inline]
add(self, rhs: &DVec3) -> DVec31395 fn add(self, rhs: &DVec3) -> DVec3 {
1396 self.add(*rhs)
1397 }
1398 }
1399
1400 impl Add<&DVec3> for &DVec3 {
1401 type Output = DVec3;
1402 #[inline]
add(self, rhs: &DVec3) -> DVec31403 fn add(self, rhs: &DVec3) -> DVec3 {
1404 (*self).add(*rhs)
1405 }
1406 }
1407
1408 impl Add<DVec3> for &DVec3 {
1409 type Output = DVec3;
1410 #[inline]
add(self, rhs: DVec3) -> DVec31411 fn add(self, rhs: DVec3) -> DVec3 {
1412 (*self).add(rhs)
1413 }
1414 }
1415
1416 impl AddAssign<DVec3> for DVec3 {
1417 #[inline]
add_assign(&mut self, rhs: Self)1418 fn add_assign(&mut self, rhs: Self) {
1419 self.x.add_assign(rhs.x);
1420 self.y.add_assign(rhs.y);
1421 self.z.add_assign(rhs.z);
1422 }
1423 }
1424
1425 impl AddAssign<&DVec3> for DVec3 {
1426 #[inline]
add_assign(&mut self, rhs: &DVec3)1427 fn add_assign(&mut self, rhs: &DVec3) {
1428 self.add_assign(*rhs)
1429 }
1430 }
1431
1432 impl Add<f64> for DVec3 {
1433 type Output = Self;
1434 #[inline]
add(self, rhs: f64) -> Self1435 fn add(self, rhs: f64) -> Self {
1436 Self {
1437 x: self.x.add(rhs),
1438 y: self.y.add(rhs),
1439 z: self.z.add(rhs),
1440 }
1441 }
1442 }
1443
1444 impl Add<&f64> for DVec3 {
1445 type Output = DVec3;
1446 #[inline]
add(self, rhs: &f64) -> DVec31447 fn add(self, rhs: &f64) -> DVec3 {
1448 self.add(*rhs)
1449 }
1450 }
1451
1452 impl Add<&f64> for &DVec3 {
1453 type Output = DVec3;
1454 #[inline]
add(self, rhs: &f64) -> DVec31455 fn add(self, rhs: &f64) -> DVec3 {
1456 (*self).add(*rhs)
1457 }
1458 }
1459
1460 impl Add<f64> for &DVec3 {
1461 type Output = DVec3;
1462 #[inline]
add(self, rhs: f64) -> DVec31463 fn add(self, rhs: f64) -> DVec3 {
1464 (*self).add(rhs)
1465 }
1466 }
1467
1468 impl AddAssign<f64> for DVec3 {
1469 #[inline]
add_assign(&mut self, rhs: f64)1470 fn add_assign(&mut self, rhs: f64) {
1471 self.x.add_assign(rhs);
1472 self.y.add_assign(rhs);
1473 self.z.add_assign(rhs);
1474 }
1475 }
1476
1477 impl AddAssign<&f64> for DVec3 {
1478 #[inline]
add_assign(&mut self, rhs: &f64)1479 fn add_assign(&mut self, rhs: &f64) {
1480 self.add_assign(*rhs)
1481 }
1482 }
1483
1484 impl Add<DVec3> for f64 {
1485 type Output = DVec3;
1486 #[inline]
add(self, rhs: DVec3) -> DVec31487 fn add(self, rhs: DVec3) -> DVec3 {
1488 DVec3 {
1489 x: self.add(rhs.x),
1490 y: self.add(rhs.y),
1491 z: self.add(rhs.z),
1492 }
1493 }
1494 }
1495
1496 impl Add<&DVec3> for f64 {
1497 type Output = DVec3;
1498 #[inline]
add(self, rhs: &DVec3) -> DVec31499 fn add(self, rhs: &DVec3) -> DVec3 {
1500 self.add(*rhs)
1501 }
1502 }
1503
1504 impl Add<&DVec3> for &f64 {
1505 type Output = DVec3;
1506 #[inline]
add(self, rhs: &DVec3) -> DVec31507 fn add(self, rhs: &DVec3) -> DVec3 {
1508 (*self).add(*rhs)
1509 }
1510 }
1511
1512 impl Add<DVec3> for &f64 {
1513 type Output = DVec3;
1514 #[inline]
add(self, rhs: DVec3) -> DVec31515 fn add(self, rhs: DVec3) -> DVec3 {
1516 (*self).add(rhs)
1517 }
1518 }
1519
1520 impl Sub<DVec3> for DVec3 {
1521 type Output = Self;
1522 #[inline]
sub(self, rhs: Self) -> Self1523 fn sub(self, rhs: Self) -> Self {
1524 Self {
1525 x: self.x.sub(rhs.x),
1526 y: self.y.sub(rhs.y),
1527 z: self.z.sub(rhs.z),
1528 }
1529 }
1530 }
1531
1532 impl Sub<&DVec3> for DVec3 {
1533 type Output = DVec3;
1534 #[inline]
sub(self, rhs: &DVec3) -> DVec31535 fn sub(self, rhs: &DVec3) -> DVec3 {
1536 self.sub(*rhs)
1537 }
1538 }
1539
1540 impl Sub<&DVec3> for &DVec3 {
1541 type Output = DVec3;
1542 #[inline]
sub(self, rhs: &DVec3) -> DVec31543 fn sub(self, rhs: &DVec3) -> DVec3 {
1544 (*self).sub(*rhs)
1545 }
1546 }
1547
1548 impl Sub<DVec3> for &DVec3 {
1549 type Output = DVec3;
1550 #[inline]
sub(self, rhs: DVec3) -> DVec31551 fn sub(self, rhs: DVec3) -> DVec3 {
1552 (*self).sub(rhs)
1553 }
1554 }
1555
1556 impl SubAssign<DVec3> for DVec3 {
1557 #[inline]
sub_assign(&mut self, rhs: DVec3)1558 fn sub_assign(&mut self, rhs: DVec3) {
1559 self.x.sub_assign(rhs.x);
1560 self.y.sub_assign(rhs.y);
1561 self.z.sub_assign(rhs.z);
1562 }
1563 }
1564
1565 impl SubAssign<&DVec3> for DVec3 {
1566 #[inline]
sub_assign(&mut self, rhs: &DVec3)1567 fn sub_assign(&mut self, rhs: &DVec3) {
1568 self.sub_assign(*rhs)
1569 }
1570 }
1571
1572 impl Sub<f64> for DVec3 {
1573 type Output = Self;
1574 #[inline]
sub(self, rhs: f64) -> Self1575 fn sub(self, rhs: f64) -> Self {
1576 Self {
1577 x: self.x.sub(rhs),
1578 y: self.y.sub(rhs),
1579 z: self.z.sub(rhs),
1580 }
1581 }
1582 }
1583
1584 impl Sub<&f64> for DVec3 {
1585 type Output = DVec3;
1586 #[inline]
sub(self, rhs: &f64) -> DVec31587 fn sub(self, rhs: &f64) -> DVec3 {
1588 self.sub(*rhs)
1589 }
1590 }
1591
1592 impl Sub<&f64> for &DVec3 {
1593 type Output = DVec3;
1594 #[inline]
sub(self, rhs: &f64) -> DVec31595 fn sub(self, rhs: &f64) -> DVec3 {
1596 (*self).sub(*rhs)
1597 }
1598 }
1599
1600 impl Sub<f64> for &DVec3 {
1601 type Output = DVec3;
1602 #[inline]
sub(self, rhs: f64) -> DVec31603 fn sub(self, rhs: f64) -> DVec3 {
1604 (*self).sub(rhs)
1605 }
1606 }
1607
1608 impl SubAssign<f64> for DVec3 {
1609 #[inline]
sub_assign(&mut self, rhs: f64)1610 fn sub_assign(&mut self, rhs: f64) {
1611 self.x.sub_assign(rhs);
1612 self.y.sub_assign(rhs);
1613 self.z.sub_assign(rhs);
1614 }
1615 }
1616
1617 impl SubAssign<&f64> for DVec3 {
1618 #[inline]
sub_assign(&mut self, rhs: &f64)1619 fn sub_assign(&mut self, rhs: &f64) {
1620 self.sub_assign(*rhs)
1621 }
1622 }
1623
1624 impl Sub<DVec3> for f64 {
1625 type Output = DVec3;
1626 #[inline]
sub(self, rhs: DVec3) -> DVec31627 fn sub(self, rhs: DVec3) -> DVec3 {
1628 DVec3 {
1629 x: self.sub(rhs.x),
1630 y: self.sub(rhs.y),
1631 z: self.sub(rhs.z),
1632 }
1633 }
1634 }
1635
1636 impl Sub<&DVec3> for f64 {
1637 type Output = DVec3;
1638 #[inline]
sub(self, rhs: &DVec3) -> DVec31639 fn sub(self, rhs: &DVec3) -> DVec3 {
1640 self.sub(*rhs)
1641 }
1642 }
1643
1644 impl Sub<&DVec3> for &f64 {
1645 type Output = DVec3;
1646 #[inline]
sub(self, rhs: &DVec3) -> DVec31647 fn sub(self, rhs: &DVec3) -> DVec3 {
1648 (*self).sub(*rhs)
1649 }
1650 }
1651
1652 impl Sub<DVec3> for &f64 {
1653 type Output = DVec3;
1654 #[inline]
sub(self, rhs: DVec3) -> DVec31655 fn sub(self, rhs: DVec3) -> DVec3 {
1656 (*self).sub(rhs)
1657 }
1658 }
1659
1660 impl Rem<DVec3> for DVec3 {
1661 type Output = Self;
1662 #[inline]
rem(self, rhs: Self) -> Self1663 fn rem(self, rhs: Self) -> Self {
1664 Self {
1665 x: self.x.rem(rhs.x),
1666 y: self.y.rem(rhs.y),
1667 z: self.z.rem(rhs.z),
1668 }
1669 }
1670 }
1671
1672 impl Rem<&DVec3> for DVec3 {
1673 type Output = DVec3;
1674 #[inline]
rem(self, rhs: &DVec3) -> DVec31675 fn rem(self, rhs: &DVec3) -> DVec3 {
1676 self.rem(*rhs)
1677 }
1678 }
1679
1680 impl Rem<&DVec3> for &DVec3 {
1681 type Output = DVec3;
1682 #[inline]
rem(self, rhs: &DVec3) -> DVec31683 fn rem(self, rhs: &DVec3) -> DVec3 {
1684 (*self).rem(*rhs)
1685 }
1686 }
1687
1688 impl Rem<DVec3> for &DVec3 {
1689 type Output = DVec3;
1690 #[inline]
rem(self, rhs: DVec3) -> DVec31691 fn rem(self, rhs: DVec3) -> DVec3 {
1692 (*self).rem(rhs)
1693 }
1694 }
1695
1696 impl RemAssign<DVec3> for DVec3 {
1697 #[inline]
rem_assign(&mut self, rhs: Self)1698 fn rem_assign(&mut self, rhs: Self) {
1699 self.x.rem_assign(rhs.x);
1700 self.y.rem_assign(rhs.y);
1701 self.z.rem_assign(rhs.z);
1702 }
1703 }
1704
1705 impl RemAssign<&DVec3> for DVec3 {
1706 #[inline]
rem_assign(&mut self, rhs: &DVec3)1707 fn rem_assign(&mut self, rhs: &DVec3) {
1708 self.rem_assign(*rhs)
1709 }
1710 }
1711
1712 impl Rem<f64> for DVec3 {
1713 type Output = Self;
1714 #[inline]
rem(self, rhs: f64) -> Self1715 fn rem(self, rhs: f64) -> Self {
1716 Self {
1717 x: self.x.rem(rhs),
1718 y: self.y.rem(rhs),
1719 z: self.z.rem(rhs),
1720 }
1721 }
1722 }
1723
1724 impl Rem<&f64> for DVec3 {
1725 type Output = DVec3;
1726 #[inline]
rem(self, rhs: &f64) -> DVec31727 fn rem(self, rhs: &f64) -> DVec3 {
1728 self.rem(*rhs)
1729 }
1730 }
1731
1732 impl Rem<&f64> for &DVec3 {
1733 type Output = DVec3;
1734 #[inline]
rem(self, rhs: &f64) -> DVec31735 fn rem(self, rhs: &f64) -> DVec3 {
1736 (*self).rem(*rhs)
1737 }
1738 }
1739
1740 impl Rem<f64> for &DVec3 {
1741 type Output = DVec3;
1742 #[inline]
rem(self, rhs: f64) -> DVec31743 fn rem(self, rhs: f64) -> DVec3 {
1744 (*self).rem(rhs)
1745 }
1746 }
1747
1748 impl RemAssign<f64> for DVec3 {
1749 #[inline]
rem_assign(&mut self, rhs: f64)1750 fn rem_assign(&mut self, rhs: f64) {
1751 self.x.rem_assign(rhs);
1752 self.y.rem_assign(rhs);
1753 self.z.rem_assign(rhs);
1754 }
1755 }
1756
1757 impl RemAssign<&f64> for DVec3 {
1758 #[inline]
rem_assign(&mut self, rhs: &f64)1759 fn rem_assign(&mut self, rhs: &f64) {
1760 self.rem_assign(*rhs)
1761 }
1762 }
1763
1764 impl Rem<DVec3> for f64 {
1765 type Output = DVec3;
1766 #[inline]
rem(self, rhs: DVec3) -> DVec31767 fn rem(self, rhs: DVec3) -> DVec3 {
1768 DVec3 {
1769 x: self.rem(rhs.x),
1770 y: self.rem(rhs.y),
1771 z: self.rem(rhs.z),
1772 }
1773 }
1774 }
1775
1776 impl Rem<&DVec3> for f64 {
1777 type Output = DVec3;
1778 #[inline]
rem(self, rhs: &DVec3) -> DVec31779 fn rem(self, rhs: &DVec3) -> DVec3 {
1780 self.rem(*rhs)
1781 }
1782 }
1783
1784 impl Rem<&DVec3> for &f64 {
1785 type Output = DVec3;
1786 #[inline]
rem(self, rhs: &DVec3) -> DVec31787 fn rem(self, rhs: &DVec3) -> DVec3 {
1788 (*self).rem(*rhs)
1789 }
1790 }
1791
1792 impl Rem<DVec3> for &f64 {
1793 type Output = DVec3;
1794 #[inline]
rem(self, rhs: DVec3) -> DVec31795 fn rem(self, rhs: DVec3) -> DVec3 {
1796 (*self).rem(rhs)
1797 }
1798 }
1799
1800 #[cfg(not(target_arch = "spirv"))]
1801 impl AsRef<[f64; 3]> for DVec3 {
1802 #[inline]
as_ref(&self) -> &[f64; 3]1803 fn as_ref(&self) -> &[f64; 3] {
1804 unsafe { &*(self as *const DVec3 as *const [f64; 3]) }
1805 }
1806 }
1807
1808 #[cfg(not(target_arch = "spirv"))]
1809 impl AsMut<[f64; 3]> for DVec3 {
1810 #[inline]
as_mut(&mut self) -> &mut [f64; 3]1811 fn as_mut(&mut self) -> &mut [f64; 3] {
1812 unsafe { &mut *(self as *mut DVec3 as *mut [f64; 3]) }
1813 }
1814 }
1815
1816 impl Sum for DVec3 {
1817 #[inline]
sum<I>(iter: I) -> Self where I: Iterator<Item = Self>,1818 fn sum<I>(iter: I) -> Self
1819 where
1820 I: Iterator<Item = Self>,
1821 {
1822 iter.fold(Self::ZERO, Self::add)
1823 }
1824 }
1825
1826 impl<'a> Sum<&'a Self> for DVec3 {
1827 #[inline]
sum<I>(iter: I) -> Self where I: Iterator<Item = &'a Self>,1828 fn sum<I>(iter: I) -> Self
1829 where
1830 I: Iterator<Item = &'a Self>,
1831 {
1832 iter.fold(Self::ZERO, |a, &b| Self::add(a, b))
1833 }
1834 }
1835
1836 impl Product for DVec3 {
1837 #[inline]
product<I>(iter: I) -> Self where I: Iterator<Item = Self>,1838 fn product<I>(iter: I) -> Self
1839 where
1840 I: Iterator<Item = Self>,
1841 {
1842 iter.fold(Self::ONE, Self::mul)
1843 }
1844 }
1845
1846 impl<'a> Product<&'a Self> for DVec3 {
1847 #[inline]
product<I>(iter: I) -> Self where I: Iterator<Item = &'a Self>,1848 fn product<I>(iter: I) -> Self
1849 where
1850 I: Iterator<Item = &'a Self>,
1851 {
1852 iter.fold(Self::ONE, |a, &b| Self::mul(a, b))
1853 }
1854 }
1855
1856 impl Neg for DVec3 {
1857 type Output = Self;
1858 #[inline]
neg(self) -> Self1859 fn neg(self) -> Self {
1860 Self {
1861 x: self.x.neg(),
1862 y: self.y.neg(),
1863 z: self.z.neg(),
1864 }
1865 }
1866 }
1867
1868 impl Neg for &DVec3 {
1869 type Output = DVec3;
1870 #[inline]
neg(self) -> DVec31871 fn neg(self) -> DVec3 {
1872 (*self).neg()
1873 }
1874 }
1875
1876 impl Index<usize> for DVec3 {
1877 type Output = f64;
1878 #[inline]
index(&self, index: usize) -> &Self::Output1879 fn index(&self, index: usize) -> &Self::Output {
1880 match index {
1881 0 => &self.x,
1882 1 => &self.y,
1883 2 => &self.z,
1884 _ => panic!("index out of bounds"),
1885 }
1886 }
1887 }
1888
1889 impl IndexMut<usize> for DVec3 {
1890 #[inline]
index_mut(&mut self, index: usize) -> &mut Self::Output1891 fn index_mut(&mut self, index: usize) -> &mut Self::Output {
1892 match index {
1893 0 => &mut self.x,
1894 1 => &mut self.y,
1895 2 => &mut self.z,
1896 _ => panic!("index out of bounds"),
1897 }
1898 }
1899 }
1900
1901 impl fmt::Display for DVec3 {
fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result1902 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1903 if let Some(p) = f.precision() {
1904 write!(f, "[{:.*}, {:.*}, {:.*}]", p, self.x, p, self.y, p, self.z)
1905 } else {
1906 write!(f, "[{}, {}, {}]", self.x, self.y, self.z)
1907 }
1908 }
1909 }
1910
1911 impl fmt::Debug for DVec3 {
fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result1912 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
1913 fmt.debug_tuple(stringify!(DVec3))
1914 .field(&self.x)
1915 .field(&self.y)
1916 .field(&self.z)
1917 .finish()
1918 }
1919 }
1920
1921 impl From<[f64; 3]> for DVec3 {
1922 #[inline]
from(a: [f64; 3]) -> Self1923 fn from(a: [f64; 3]) -> Self {
1924 Self::new(a[0], a[1], a[2])
1925 }
1926 }
1927
1928 impl From<DVec3> for [f64; 3] {
1929 #[inline]
from(v: DVec3) -> Self1930 fn from(v: DVec3) -> Self {
1931 [v.x, v.y, v.z]
1932 }
1933 }
1934
1935 impl From<(f64, f64, f64)> for DVec3 {
1936 #[inline]
from(t: (f64, f64, f64)) -> Self1937 fn from(t: (f64, f64, f64)) -> Self {
1938 Self::new(t.0, t.1, t.2)
1939 }
1940 }
1941
1942 impl From<DVec3> for (f64, f64, f64) {
1943 #[inline]
from(v: DVec3) -> Self1944 fn from(v: DVec3) -> Self {
1945 (v.x, v.y, v.z)
1946 }
1947 }
1948
1949 impl From<(DVec2, f64)> for DVec3 {
1950 #[inline]
from((v, z): (DVec2, f64)) -> Self1951 fn from((v, z): (DVec2, f64)) -> Self {
1952 Self::new(v.x, v.y, z)
1953 }
1954 }
1955
1956 impl From<Vec3> for DVec3 {
1957 #[inline]
from(v: Vec3) -> Self1958 fn from(v: Vec3) -> Self {
1959 Self::new(f64::from(v.x), f64::from(v.y), f64::from(v.z))
1960 }
1961 }
1962
1963 impl From<IVec3> for DVec3 {
1964 #[inline]
from(v: IVec3) -> Self1965 fn from(v: IVec3) -> Self {
1966 Self::new(f64::from(v.x), f64::from(v.y), f64::from(v.z))
1967 }
1968 }
1969
1970 impl From<UVec3> for DVec3 {
1971 #[inline]
from(v: UVec3) -> Self1972 fn from(v: UVec3) -> Self {
1973 Self::new(f64::from(v.x), f64::from(v.y), f64::from(v.z))
1974 }
1975 }
1976
1977 impl From<BVec3> for DVec3 {
1978 #[inline]
from(v: BVec3) -> Self1979 fn from(v: BVec3) -> Self {
1980 Self::new(f64::from(v.x), f64::from(v.y), f64::from(v.z))
1981 }
1982 }
1983
1984 impl From<BVec3A> for DVec3 {
1985 #[inline]
from(v: BVec3A) -> Self1986 fn from(v: BVec3A) -> Self {
1987 let bool_array: [bool; 3] = v.into();
1988 Self::new(
1989 f64::from(bool_array[0]),
1990 f64::from(bool_array[1]),
1991 f64::from(bool_array[2]),
1992 )
1993 }
1994 }
1995