Skip to main content

raylib_sys/
vector_math.rs

1use crate::{Matrix, Quaternion, Vector2, Vector3, Vector4};
2
3// ─── Vector2 ─────────────────────────────────────────────────────────────────
4
5impl Vector2 {
6    /// The zero vector `(0, 0)`.
7    pub const ZERO: Self = Self { x: 0.0, y: 0.0 };
8    /// The vector `(1, 1)`.
9    pub const ONE: Self = Self { x: 1.0, y: 1.0 };
10
11    /// Construct a new Vector2.
12    #[inline]
13    pub fn new(x: f32, y: f32) -> Self {
14        Self { x, y }
15    }
16
17    /// Zero vector. (raymath `Vector2Zero`)
18    #[inline]
19    #[must_use]
20    pub fn zero() -> Self {
21        // SAFETY: Vector2Zero is a pure value-out raymath fn; no preconditions.
22        unsafe { crate::Vector2Zero() }
23    }
24
25    /// Vector with both components set to 1. (raymath `Vector2One`)
26    #[inline]
27    #[must_use]
28    pub fn one() -> Self {
29        // SAFETY: Vector2One is a pure value-out raymath fn; no preconditions.
30        unsafe { crate::Vector2One() }
31    }
32
33    /// Add scalar to both components. (raymath `Vector2AddValue`)
34    #[inline]
35    #[must_use]
36    pub fn add_value(self, add: f32) -> Self {
37        // SAFETY: pure value-in/out, no preconditions.
38        unsafe { crate::Vector2AddValue(self, add) }
39    }
40
41    /// Subtract scalar from both components. (raymath `Vector2SubtractValue`)
42    #[inline]
43    #[must_use]
44    pub fn sub_value(self, sub: f32) -> Self {
45        // SAFETY: pure value-in/out, no preconditions.
46        unsafe { crate::Vector2SubtractValue(self, sub) }
47    }
48
49    /// Vector length. (raymath `Vector2Length`)
50    #[inline]
51    #[must_use]
52    pub fn length(self) -> f32 {
53        // SAFETY: pure value-in/out, no preconditions.
54        unsafe { crate::Vector2Length(self) }
55    }
56
57    /// Squared vector length. (raymath `Vector2LengthSqr`)
58    #[inline]
59    #[must_use]
60    pub fn length_sqr(self) -> f32 {
61        // SAFETY: pure value-in/out, no preconditions.
62        unsafe { crate::Vector2LengthSqr(self) }
63    }
64
65    /// Dot product. (raymath `Vector2DotProduct`)
66    #[inline]
67    #[must_use]
68    pub fn dot(self, other: Vector2) -> f32 {
69        // SAFETY: pure value-in/out, no preconditions.
70        unsafe { crate::Vector2DotProduct(self, other) }
71    }
72
73    /// Cross product (scalar). (raymath `Vector2CrossProduct`)
74    #[inline]
75    #[must_use]
76    pub fn cross(self, other: Vector2) -> f32 {
77        // SAFETY: pure value-in/out, no preconditions.
78        unsafe { crate::Vector2CrossProduct(self, other) }
79    }
80
81    /// Distance between two vectors. (raymath `Vector2Distance`)
82    #[inline]
83    #[must_use]
84    pub fn distance(self, other: Vector2) -> f32 {
85        // SAFETY: pure value-in/out, no preconditions.
86        unsafe { crate::Vector2Distance(self, other) }
87    }
88
89    /// Squared distance between two vectors. (raymath `Vector2DistanceSqr`)
90    #[inline]
91    #[must_use]
92    pub fn distance_sqr(self, other: Vector2) -> f32 {
93        // SAFETY: pure value-in/out, no preconditions.
94        unsafe { crate::Vector2DistanceSqr(self, other) }
95    }
96
97    /// Angle between two vectors (radians). (raymath `Vector2Angle`)
98    #[inline]
99    #[must_use]
100    pub fn angle(self, other: Vector2) -> f32 {
101        // SAFETY: pure value-in/out, no preconditions.
102        unsafe { crate::Vector2Angle(self, other) }
103    }
104
105    /// Angle of line defined by two points. (raymath `Vector2LineAngle`)
106    #[inline]
107    #[must_use]
108    pub fn line_angle(start: Vector2, end: Vector2) -> f32 {
109        // SAFETY: pure value-in/out, no preconditions.
110        unsafe { crate::Vector2LineAngle(start, end) }
111    }
112
113    /// Scale vector by scalar. (raymath `Vector2Scale`)
114    #[inline]
115    #[must_use]
116    pub fn scale(self, scale: f32) -> Self {
117        // SAFETY: pure value-in/out, no preconditions.
118        unsafe { crate::Vector2Scale(self, scale) }
119    }
120
121    /// Component-wise multiply. (raymath `Vector2Multiply`)
122    #[inline]
123    #[must_use]
124    pub fn multiply(self, other: Vector2) -> Self {
125        // SAFETY: pure value-in/out, no preconditions.
126        unsafe { crate::Vector2Multiply(self, other) }
127    }
128
129    /// Negate vector. (raymath `Vector2Negate`)
130    #[inline]
131    #[must_use]
132    pub fn negate(self) -> Self {
133        // SAFETY: pure value-in/out, no preconditions.
134        unsafe { crate::Vector2Negate(self) }
135    }
136
137    /// Component-wise divide. (raymath `Vector2Divide`)
138    #[inline]
139    #[must_use]
140    pub fn divide(self, other: Vector2) -> Self {
141        // SAFETY: pure value-in/out, no preconditions.
142        unsafe { crate::Vector2Divide(self, other) }
143    }
144
145    /// Normalize vector. (raymath `Vector2Normalize`)
146    #[inline]
147    #[must_use]
148    pub fn normalize(self) -> Self {
149        // SAFETY: pure value-in/out, no preconditions.
150        unsafe { crate::Vector2Normalize(self) }
151    }
152
153    /// Transform by matrix. (raymath `Vector2Transform`)
154    #[inline]
155    #[must_use]
156    pub fn transform(self, mat: Matrix) -> Self {
157        // SAFETY: pure value-in/out, no preconditions.
158        unsafe { crate::Vector2Transform(self, mat) }
159    }
160
161    /// Linear interpolation. (raymath `Vector2Lerp`)
162    #[inline]
163    #[must_use]
164    pub fn lerp(self, other: Vector2, amount: f32) -> Self {
165        // SAFETY: pure value-in/out, no preconditions.
166        unsafe { crate::Vector2Lerp(self, other, amount) }
167    }
168
169    /// Reflect vector about normal. (raymath `Vector2Reflect`)
170    #[inline]
171    #[must_use]
172    pub fn reflect(self, normal: Vector2) -> Self {
173        // SAFETY: pure value-in/out, no preconditions.
174        unsafe { crate::Vector2Reflect(self, normal) }
175    }
176
177    /// Component-wise minimum. (raymath `Vector2Min`)
178    #[inline]
179    #[must_use]
180    pub fn min(self, other: Vector2) -> Self {
181        // SAFETY: pure value-in/out, no preconditions.
182        unsafe { crate::Vector2Min(self, other) }
183    }
184
185    /// Component-wise maximum. (raymath `Vector2Max`)
186    #[inline]
187    #[must_use]
188    pub fn max(self, other: Vector2) -> Self {
189        // SAFETY: pure value-in/out, no preconditions.
190        unsafe { crate::Vector2Max(self, other) }
191    }
192
193    /// Rotate by angle (radians). (raymath `Vector2Rotate`)
194    #[inline]
195    #[must_use]
196    pub fn rotate(self, angle: f32) -> Self {
197        // SAFETY: pure value-in/out, no preconditions.
198        unsafe { crate::Vector2Rotate(self, angle) }
199    }
200
201    /// Move towards target by at most maxDistance. (raymath `Vector2MoveTowards`)
202    #[inline]
203    #[must_use]
204    pub fn move_towards(self, target: Vector2, max_distance: f32) -> Self {
205        // SAFETY: pure value-in/out, no preconditions.
206        unsafe { crate::Vector2MoveTowards(self, target, max_distance) }
207    }
208
209    /// Invert components (1/x, 1/y). (raymath `Vector2Invert`)
210    #[inline]
211    #[must_use]
212    pub fn invert(self) -> Self {
213        // SAFETY: pure value-in/out, no preconditions.
214        unsafe { crate::Vector2Invert(self) }
215    }
216
217    /// Clamp components between min and max vectors. (raymath `Vector2Clamp`)
218    #[inline]
219    #[must_use]
220    pub fn clamp(self, min: Vector2, max: Vector2) -> Self {
221        // SAFETY: pure value-in/out, no preconditions.
222        unsafe { crate::Vector2Clamp(self, min, max) }
223    }
224
225    /// Clamp length between min and max scalars. (raymath `Vector2ClampValue`)
226    #[inline]
227    #[must_use]
228    pub fn clamp_value(self, min: f32, max: f32) -> Self {
229        // SAFETY: pure value-in/out, no preconditions.
230        unsafe { crate::Vector2ClampValue(self, min, max) }
231    }
232
233    /// Approximate equality (uses raymath epsilon). (raymath `Vector2Equals`)
234    #[inline]
235    #[must_use]
236    pub fn equals(self, other: Vector2) -> bool {
237        // SAFETY: pure value-in/out, no preconditions.
238        unsafe { crate::Vector2Equals(self, other) != 0 }
239    }
240
241    /// Refract through surface with index ratio r. (raymath `Vector2Refract`)
242    #[inline]
243    #[must_use]
244    pub fn refract(self, n: Vector2, r: f32) -> Self {
245        // SAFETY: pure value-in/out, no preconditions.
246        unsafe { crate::Vector2Refract(self, n, r) }
247    }
248}
249
250impl std::ops::Add for Vector2 {
251    type Output = Vector2;
252    #[inline]
253    fn add(self, rhs: Vector2) -> Vector2 {
254        // SAFETY: Vector2Add is a pure value-in/out raymath fn; no preconditions.
255        unsafe { crate::Vector2Add(self, rhs) }
256    }
257}
258impl std::ops::AddAssign for Vector2 {
259    #[inline]
260    fn add_assign(&mut self, rhs: Vector2) {
261        *self = *self + rhs;
262    }
263}
264
265impl std::ops::Sub for Vector2 {
266    type Output = Vector2;
267    #[inline]
268    fn sub(self, rhs: Vector2) -> Vector2 {
269        // SAFETY: Vector2Subtract is a pure value-in/out raymath fn; no preconditions.
270        unsafe { crate::Vector2Subtract(self, rhs) }
271    }
272}
273impl std::ops::SubAssign for Vector2 {
274    #[inline]
275    fn sub_assign(&mut self, rhs: Vector2) {
276        *self = *self - rhs;
277    }
278}
279
280impl std::ops::Mul<f32> for Vector2 {
281    type Output = Vector2;
282    #[inline]
283    fn mul(self, rhs: f32) -> Vector2 {
284        // SAFETY: Vector2Scale is a pure value-in/out raymath fn; no preconditions.
285        unsafe { crate::Vector2Scale(self, rhs) }
286    }
287}
288impl std::ops::MulAssign<f32> for Vector2 {
289    #[inline]
290    fn mul_assign(&mut self, rhs: f32) {
291        *self = *self * rhs;
292    }
293}
294
295impl std::ops::Mul<Vector2> for Vector2 {
296    type Output = Vector2;
297    #[inline]
298    fn mul(self, rhs: Vector2) -> Vector2 {
299        // SAFETY: Vector2Multiply is a pure value-in/out raymath fn (component-wise); no preconditions.
300        unsafe { crate::Vector2Multiply(self, rhs) }
301    }
302}
303
304impl std::ops::Div<Vector2> for Vector2 {
305    type Output = Vector2;
306    #[inline]
307    fn div(self, rhs: Vector2) -> Vector2 {
308        // SAFETY: Vector2Divide is a pure value-in/out raymath fn (component-wise); no preconditions.
309        unsafe { crate::Vector2Divide(self, rhs) }
310    }
311}
312
313impl std::ops::Neg for Vector2 {
314    type Output = Vector2;
315    #[inline]
316    fn neg(self) -> Vector2 {
317        // SAFETY: Vector2Negate is a pure value-in/out raymath fn; no preconditions.
318        unsafe { crate::Vector2Negate(self) }
319    }
320}
321
322// ─── Vector3 ─────────────────────────────────────────────────────────────────
323
324impl Vector3 {
325    /// The zero vector `(0, 0, 0)`.
326    pub const ZERO: Self = Self {
327        x: 0.0,
328        y: 0.0,
329        z: 0.0,
330    };
331    /// The vector `(1, 1, 1)`.
332    pub const ONE: Self = Self {
333        x: 1.0,
334        y: 1.0,
335        z: 1.0,
336    };
337    /// The unit vector along +X `(1, 0, 0)`.
338    pub const X: Self = Self {
339        x: 1.0,
340        y: 0.0,
341        z: 0.0,
342    };
343    /// The unit vector along +Y `(0, 1, 0)`.
344    pub const Y: Self = Self {
345        x: 0.0,
346        y: 1.0,
347        z: 0.0,
348    };
349    /// The unit vector along +Z `(0, 0, 1)`.
350    pub const Z: Self = Self {
351        x: 0.0,
352        y: 0.0,
353        z: 1.0,
354    };
355
356    /// Construct a new Vector3.
357    #[inline]
358    pub fn new(x: f32, y: f32, z: f32) -> Self {
359        Self { x, y, z }
360    }
361
362    /// Zero vector. (raymath `Vector3Zero`)
363    #[inline]
364    #[must_use]
365    pub fn zero() -> Self {
366        // SAFETY: Vector3Zero is a pure value-out raymath fn; no preconditions.
367        unsafe { crate::Vector3Zero() }
368    }
369
370    /// Vector with all components set to 1. (raymath `Vector3One`)
371    #[inline]
372    #[must_use]
373    pub fn one() -> Self {
374        // SAFETY: Vector3One is a pure value-out raymath fn; no preconditions.
375        unsafe { crate::Vector3One() }
376    }
377
378    /// Add scalar to all components. (raymath `Vector3AddValue`)
379    #[inline]
380    #[must_use]
381    pub fn add_value(self, add: f32) -> Self {
382        // SAFETY: pure value-in/out, no preconditions.
383        unsafe { crate::Vector3AddValue(self, add) }
384    }
385
386    /// Subtract scalar from all components. (raymath `Vector3SubtractValue`)
387    #[inline]
388    #[must_use]
389    pub fn sub_value(self, sub: f32) -> Self {
390        // SAFETY: pure value-in/out, no preconditions.
391        unsafe { crate::Vector3SubtractValue(self, sub) }
392    }
393
394    /// Scale vector by scalar. (raymath `Vector3Scale`)
395    #[inline]
396    #[must_use]
397    pub fn scale(self, scalar: f32) -> Self {
398        // SAFETY: pure value-in/out, no preconditions.
399        unsafe { crate::Vector3Scale(self, scalar) }
400    }
401
402    /// Component-wise multiply. (raymath `Vector3Multiply`)
403    #[inline]
404    #[must_use]
405    pub fn multiply(self, other: Vector3) -> Self {
406        // SAFETY: pure value-in/out, no preconditions.
407        unsafe { crate::Vector3Multiply(self, other) }
408    }
409
410    /// Cross product. (raymath `Vector3CrossProduct`)
411    #[inline]
412    #[must_use]
413    pub fn cross(self, other: Vector3) -> Self {
414        // SAFETY: pure value-in/out, no preconditions.
415        unsafe { crate::Vector3CrossProduct(self, other) }
416    }
417
418    /// Perpendicular vector. (raymath `Vector3Perpendicular`)
419    #[inline]
420    #[must_use]
421    pub fn perpendicular(self) -> Self {
422        // SAFETY: pure value-in/out, no preconditions.
423        unsafe { crate::Vector3Perpendicular(self) }
424    }
425
426    /// Vector length. (raymath `Vector3Length`)
427    #[inline]
428    #[must_use]
429    pub fn length(self) -> f32 {
430        // SAFETY: pure value-in/out, no preconditions.
431        unsafe { crate::Vector3Length(self) }
432    }
433
434    /// Squared vector length. (raymath `Vector3LengthSqr`)
435    #[inline]
436    #[must_use]
437    pub fn length_sqr(self) -> f32 {
438        // SAFETY: pure value-in/out, no preconditions.
439        unsafe { crate::Vector3LengthSqr(self) }
440    }
441
442    /// Dot product. (raymath `Vector3DotProduct`)
443    #[inline]
444    #[must_use]
445    pub fn dot(self, other: Vector3) -> f32 {
446        // SAFETY: pure value-in/out, no preconditions.
447        unsafe { crate::Vector3DotProduct(self, other) }
448    }
449
450    /// Distance between two vectors. (raymath `Vector3Distance`)
451    #[inline]
452    #[must_use]
453    pub fn distance(self, other: Vector3) -> f32 {
454        // SAFETY: pure value-in/out, no preconditions.
455        unsafe { crate::Vector3Distance(self, other) }
456    }
457
458    /// Squared distance between two vectors. (raymath `Vector3DistanceSqr`)
459    #[inline]
460    #[must_use]
461    pub fn distance_sqr(self, other: Vector3) -> f32 {
462        // SAFETY: pure value-in/out, no preconditions.
463        unsafe { crate::Vector3DistanceSqr(self, other) }
464    }
465
466    /// Angle between two vectors (radians). (raymath `Vector3Angle`)
467    #[inline]
468    #[must_use]
469    pub fn angle(self, other: Vector3) -> f32 {
470        // SAFETY: pure value-in/out, no preconditions.
471        unsafe { crate::Vector3Angle(self, other) }
472    }
473
474    /// Negate vector. (raymath `Vector3Negate`)
475    #[inline]
476    #[must_use]
477    pub fn negate(self) -> Self {
478        // SAFETY: pure value-in/out, no preconditions.
479        unsafe { crate::Vector3Negate(self) }
480    }
481
482    /// Component-wise divide. (raymath `Vector3Divide`)
483    #[inline]
484    #[must_use]
485    pub fn divide(self, other: Vector3) -> Self {
486        // SAFETY: pure value-in/out, no preconditions.
487        unsafe { crate::Vector3Divide(self, other) }
488    }
489
490    /// Normalize vector. (raymath `Vector3Normalize`)
491    #[inline]
492    #[must_use]
493    pub fn normalize(self) -> Self {
494        // SAFETY: pure value-in/out, no preconditions.
495        unsafe { crate::Vector3Normalize(self) }
496    }
497
498    /// Project `self` onto `other`. (raymath `Vector3Project`)
499    #[inline]
500    #[must_use]
501    pub fn project(self, other: Vector3) -> Self {
502        // SAFETY: pure value-in/out, no preconditions.
503        unsafe { crate::Vector3Project(self, other) }
504    }
505
506    /// Reject `self` from `other` (component perpendicular to `other`). (raymath `Vector3Reject`)
507    #[inline]
508    #[must_use]
509    pub fn reject(self, other: Vector3) -> Self {
510        // SAFETY: pure value-in/out, no preconditions.
511        unsafe { crate::Vector3Reject(self, other) }
512    }
513
514    /// Transform by matrix. (raymath `Vector3Transform`)
515    #[inline]
516    #[must_use]
517    pub fn transform(self, mat: Matrix) -> Self {
518        // SAFETY: pure value-in/out, no preconditions.
519        unsafe { crate::Vector3Transform(self, mat) }
520    }
521
522    /// Rotate by quaternion. (raymath `Vector3RotateByQuaternion`)
523    #[inline]
524    #[must_use]
525    pub fn rotate_by_quaternion(self, q: Quaternion) -> Self {
526        // SAFETY: pure value-in/out; Quaternion is #[repr(C)] matching the FFI type.
527        unsafe { crate::Vector3RotateByQuaternion(self, q) }
528    }
529
530    /// Rotate by axis and angle (radians). (raymath `Vector3RotateByAxisAngle`)
531    #[inline]
532    #[must_use]
533    pub fn rotate_by_axis_angle(self, axis: Vector3, angle: f32) -> Self {
534        // SAFETY: pure value-in/out, no preconditions.
535        unsafe { crate::Vector3RotateByAxisAngle(self, axis, angle) }
536    }
537
538    /// Move towards target by at most maxDistance. (raymath `Vector3MoveTowards`)
539    #[inline]
540    #[must_use]
541    pub fn move_towards(self, target: Vector3, max_distance: f32) -> Self {
542        // SAFETY: pure value-in/out, no preconditions.
543        unsafe { crate::Vector3MoveTowards(self, target, max_distance) }
544    }
545
546    /// Linear interpolation. (raymath `Vector3Lerp`)
547    #[inline]
548    #[must_use]
549    pub fn lerp(self, other: Vector3, amount: f32) -> Self {
550        // SAFETY: pure value-in/out, no preconditions.
551        unsafe { crate::Vector3Lerp(self, other, amount) }
552    }
553
554    /// Cubic Hermite interpolation. (raymath `Vector3CubicHermite`)
555    #[inline]
556    #[must_use]
557    pub fn cubic_hermite(
558        self,
559        tangent1: Vector3,
560        v2: Vector3,
561        tangent2: Vector3,
562        amount: f32,
563    ) -> Self {
564        // SAFETY: pure value-in/out, no preconditions.
565        unsafe { crate::Vector3CubicHermite(self, tangent1, v2, tangent2, amount) }
566    }
567
568    /// Reflect vector about normal. (raymath `Vector3Reflect`)
569    #[inline]
570    #[must_use]
571    pub fn reflect(self, normal: Vector3) -> Self {
572        // SAFETY: pure value-in/out, no preconditions.
573        unsafe { crate::Vector3Reflect(self, normal) }
574    }
575
576    /// Component-wise minimum. (raymath `Vector3Min`)
577    #[inline]
578    #[must_use]
579    pub fn min(self, other: Vector3) -> Self {
580        // SAFETY: pure value-in/out, no preconditions.
581        unsafe { crate::Vector3Min(self, other) }
582    }
583
584    /// Component-wise maximum. (raymath `Vector3Max`)
585    #[inline]
586    #[must_use]
587    pub fn max(self, other: Vector3) -> Self {
588        // SAFETY: pure value-in/out, no preconditions.
589        unsafe { crate::Vector3Max(self, other) }
590    }
591
592    /// Barycentric coordinates of point p in triangle (a, b, c). (raymath `Vector3Barycenter`)
593    #[inline]
594    #[must_use]
595    pub fn barycenter(p: Vector3, a: Vector3, b: Vector3, c: Vector3) -> Self {
596        // SAFETY: pure value-in/out, no preconditions.
597        unsafe { crate::Vector3Barycenter(p, a, b, c) }
598    }
599
600    /// Unproject vector from screen space using projection and view matrices. (raymath `Vector3Unproject`)
601    #[inline]
602    #[must_use]
603    pub fn unproject(self, projection: Matrix, view: Matrix) -> Self {
604        // SAFETY: pure value-in/out, no preconditions.
605        unsafe { crate::Vector3Unproject(self, projection, view) }
606    }
607
608    /// Convert to array of floats. (raymath `Vector3ToFloatV`)
609    #[inline]
610    #[must_use]
611    pub fn to_float_array(self) -> crate::float3 {
612        // SAFETY: pure value-in/out, no preconditions.
613        unsafe { crate::Vector3ToFloatV(self) }
614    }
615
616    /// Invert components (1/x, 1/y, 1/z). (raymath `Vector3Invert`)
617    #[inline]
618    #[must_use]
619    pub fn invert(self) -> Self {
620        // SAFETY: pure value-in/out, no preconditions.
621        unsafe { crate::Vector3Invert(self) }
622    }
623
624    /// Clamp components between min and max vectors. (raymath `Vector3Clamp`)
625    #[inline]
626    #[must_use]
627    pub fn clamp(self, min: Vector3, max: Vector3) -> Self {
628        // SAFETY: pure value-in/out, no preconditions.
629        unsafe { crate::Vector3Clamp(self, min, max) }
630    }
631
632    /// Clamp length between min and max scalars. (raymath `Vector3ClampValue`)
633    #[inline]
634    #[must_use]
635    pub fn clamp_value(self, min: f32, max: f32) -> Self {
636        // SAFETY: pure value-in/out, no preconditions.
637        unsafe { crate::Vector3ClampValue(self, min, max) }
638    }
639
640    /// Approximate equality (uses raymath epsilon). (raymath `Vector3Equals`)
641    #[inline]
642    #[must_use]
643    pub fn equals(self, other: Vector3) -> bool {
644        // SAFETY: pure value-in/out, no preconditions.
645        unsafe { crate::Vector3Equals(self, other) != 0 }
646    }
647
648    /// Refract through surface with index ratio r. (raymath `Vector3Refract`)
649    #[inline]
650    #[must_use]
651    pub fn refract(self, n: Vector3, r: f32) -> Self {
652        // SAFETY: pure value-in/out, no preconditions.
653        unsafe { crate::Vector3Refract(self, n, r) }
654    }
655}
656
657/// Orthonormalize two vectors in-place. (raymath `Vector3OrthoNormalize`)
658pub fn vector3_ortho_normalize(v1: &mut Vector3, v2: &mut Vector3) {
659    // SAFETY: Vector3OrthoNormalize writes through the given pointers, which are valid,
660    // non-null, properly aligned &mut references. v1 and v2 are distinct borrows so
661    // there is no aliasing.
662    unsafe { crate::Vector3OrthoNormalize(v1 as *mut _, v2 as *mut _) }
663}
664
665impl std::ops::Add for Vector3 {
666    type Output = Vector3;
667    #[inline]
668    fn add(self, rhs: Vector3) -> Vector3 {
669        // SAFETY: Vector3Add is a pure value-in/out raymath fn; no preconditions.
670        unsafe { crate::Vector3Add(self, rhs) }
671    }
672}
673impl std::ops::AddAssign for Vector3 {
674    #[inline]
675    fn add_assign(&mut self, rhs: Vector3) {
676        *self = *self + rhs;
677    }
678}
679
680impl std::ops::Sub for Vector3 {
681    type Output = Vector3;
682    #[inline]
683    fn sub(self, rhs: Vector3) -> Vector3 {
684        // SAFETY: Vector3Subtract is a pure value-in/out raymath fn; no preconditions.
685        unsafe { crate::Vector3Subtract(self, rhs) }
686    }
687}
688impl std::ops::SubAssign for Vector3 {
689    #[inline]
690    fn sub_assign(&mut self, rhs: Vector3) {
691        *self = *self - rhs;
692    }
693}
694
695impl std::ops::Mul<f32> for Vector3 {
696    type Output = Vector3;
697    #[inline]
698    fn mul(self, rhs: f32) -> Vector3 {
699        // SAFETY: Vector3Scale is a pure value-in/out raymath fn; no preconditions.
700        unsafe { crate::Vector3Scale(self, rhs) }
701    }
702}
703impl std::ops::MulAssign<f32> for Vector3 {
704    #[inline]
705    fn mul_assign(&mut self, rhs: f32) {
706        *self = *self * rhs;
707    }
708}
709
710impl std::ops::Mul<Vector3> for Vector3 {
711    type Output = Vector3;
712    #[inline]
713    fn mul(self, rhs: Vector3) -> Vector3 {
714        // SAFETY: Vector3Multiply is a pure value-in/out raymath fn (component-wise); no preconditions.
715        unsafe { crate::Vector3Multiply(self, rhs) }
716    }
717}
718
719impl std::ops::Div<Vector3> for Vector3 {
720    type Output = Vector3;
721    #[inline]
722    fn div(self, rhs: Vector3) -> Vector3 {
723        // SAFETY: Vector3Divide is a pure value-in/out raymath fn (component-wise); no preconditions.
724        unsafe { crate::Vector3Divide(self, rhs) }
725    }
726}
727
728impl std::ops::Neg for Vector3 {
729    type Output = Vector3;
730    #[inline]
731    fn neg(self) -> Vector3 {
732        // SAFETY: Vector3Negate is a pure value-in/out raymath fn; no preconditions.
733        unsafe { crate::Vector3Negate(self) }
734    }
735}
736
737// ─── Vector4 ─────────────────────────────────────────────────────────────────
738
739impl Vector4 {
740    /// Construct a new Vector4.
741    #[inline]
742    pub fn new(x: f32, y: f32, z: f32, w: f32) -> Self {
743        Self { x, y, z, w }
744    }
745
746    /// Zero vector. (raymath `Vector4Zero`)
747    #[inline]
748    #[must_use]
749    pub fn zero() -> Self {
750        // SAFETY: Vector4Zero is a pure value-out raymath fn; no preconditions.
751        unsafe { crate::Vector4Zero() }
752    }
753
754    /// Vector with all components set to 1. (raymath `Vector4One`)
755    #[inline]
756    #[must_use]
757    pub fn one() -> Self {
758        // SAFETY: Vector4One is a pure value-out raymath fn; no preconditions.
759        unsafe { crate::Vector4One() }
760    }
761
762    /// Add scalar to all components. (raymath `Vector4AddValue`)
763    #[inline]
764    #[must_use]
765    pub fn add_value(self, add: f32) -> Self {
766        // SAFETY: pure value-in/out, no preconditions.
767        unsafe { crate::Vector4AddValue(self, add) }
768    }
769
770    /// Subtract scalar from all components. (raymath `Vector4SubtractValue`)
771    #[inline]
772    #[must_use]
773    pub fn sub_value(self, sub: f32) -> Self {
774        // SAFETY: pure value-in/out, no preconditions.
775        unsafe { crate::Vector4SubtractValue(self, sub) }
776    }
777
778    /// Vector length. (raymath `Vector4Length`)
779    #[inline]
780    #[must_use]
781    pub fn length(self) -> f32 {
782        // SAFETY: pure value-in/out, no preconditions.
783        unsafe { crate::Vector4Length(self) }
784    }
785
786    /// Squared vector length. (raymath `Vector4LengthSqr`)
787    #[inline]
788    #[must_use]
789    pub fn length_sqr(self) -> f32 {
790        // SAFETY: pure value-in/out, no preconditions.
791        unsafe { crate::Vector4LengthSqr(self) }
792    }
793
794    /// Dot product. (raymath `Vector4DotProduct`)
795    #[inline]
796    #[must_use]
797    pub fn dot(self, other: Vector4) -> f32 {
798        // SAFETY: pure value-in/out, no preconditions.
799        unsafe { crate::Vector4DotProduct(self, other) }
800    }
801
802    /// Distance between two vectors. (raymath `Vector4Distance`)
803    #[inline]
804    #[must_use]
805    pub fn distance(self, other: Vector4) -> f32 {
806        // SAFETY: pure value-in/out, no preconditions.
807        unsafe { crate::Vector4Distance(self, other) }
808    }
809
810    /// Squared distance between two vectors. (raymath `Vector4DistanceSqr`)
811    #[inline]
812    #[must_use]
813    pub fn distance_sqr(self, other: Vector4) -> f32 {
814        // SAFETY: pure value-in/out, no preconditions.
815        unsafe { crate::Vector4DistanceSqr(self, other) }
816    }
817
818    /// Scale vector by scalar. (raymath `Vector4Scale`)
819    #[inline]
820    #[must_use]
821    pub fn scale(self, scale: f32) -> Self {
822        // SAFETY: pure value-in/out, no preconditions.
823        unsafe { crate::Vector4Scale(self, scale) }
824    }
825
826    /// Component-wise multiply. (raymath `Vector4Multiply`)
827    #[inline]
828    #[must_use]
829    pub fn multiply(self, other: Vector4) -> Self {
830        // SAFETY: pure value-in/out, no preconditions.
831        unsafe { crate::Vector4Multiply(self, other) }
832    }
833
834    /// Negate vector. (raymath `Vector4Negate`)
835    #[inline]
836    #[must_use]
837    pub fn negate(self) -> Self {
838        // SAFETY: pure value-in/out, no preconditions.
839        unsafe { crate::Vector4Negate(self) }
840    }
841
842    /// Component-wise divide. (raymath `Vector4Divide`)
843    #[inline]
844    #[must_use]
845    pub fn divide(self, other: Vector4) -> Self {
846        // SAFETY: pure value-in/out, no preconditions.
847        unsafe { crate::Vector4Divide(self, other) }
848    }
849
850    /// Normalize vector. (raymath `Vector4Normalize`)
851    #[inline]
852    #[must_use]
853    pub fn normalize(self) -> Self {
854        // SAFETY: pure value-in/out, no preconditions.
855        unsafe { crate::Vector4Normalize(self) }
856    }
857
858    /// Component-wise minimum. (raymath `Vector4Min`)
859    #[inline]
860    #[must_use]
861    pub fn min(self, other: Vector4) -> Self {
862        // SAFETY: pure value-in/out, no preconditions.
863        unsafe { crate::Vector4Min(self, other) }
864    }
865
866    /// Component-wise maximum. (raymath `Vector4Max`)
867    #[inline]
868    #[must_use]
869    pub fn max(self, other: Vector4) -> Self {
870        // SAFETY: pure value-in/out, no preconditions.
871        unsafe { crate::Vector4Max(self, other) }
872    }
873
874    /// Linear interpolation. (raymath `Vector4Lerp`)
875    #[inline]
876    #[must_use]
877    pub fn lerp(self, other: Vector4, amount: f32) -> Self {
878        // SAFETY: pure value-in/out, no preconditions.
879        unsafe { crate::Vector4Lerp(self, other, amount) }
880    }
881
882    /// Move towards target by at most maxDistance. (raymath `Vector4MoveTowards`)
883    #[inline]
884    #[must_use]
885    pub fn move_towards(self, target: Vector4, max_distance: f32) -> Self {
886        // SAFETY: pure value-in/out, no preconditions.
887        unsafe { crate::Vector4MoveTowards(self, target, max_distance) }
888    }
889
890    /// Invert components (1/x, 1/y, 1/z, 1/w). (raymath `Vector4Invert`)
891    #[inline]
892    #[must_use]
893    pub fn invert(self) -> Self {
894        // SAFETY: pure value-in/out, no preconditions.
895        unsafe { crate::Vector4Invert(self) }
896    }
897
898    /// Approximate equality (uses raymath epsilon). (raymath `Vector4Equals`)
899    #[inline]
900    #[must_use]
901    pub fn equals(self, other: Vector4) -> bool {
902        // SAFETY: pure value-in/out, no preconditions.
903        unsafe { crate::Vector4Equals(self, other) != 0 }
904    }
905}
906
907impl std::ops::Add for Vector4 {
908    type Output = Vector4;
909    #[inline]
910    fn add(self, rhs: Vector4) -> Vector4 {
911        // SAFETY: Vector4Add is a pure value-in/out raymath fn; no preconditions.
912        unsafe { crate::Vector4Add(self, rhs) }
913    }
914}
915impl std::ops::AddAssign for Vector4 {
916    #[inline]
917    fn add_assign(&mut self, rhs: Vector4) {
918        *self = *self + rhs;
919    }
920}
921
922impl std::ops::Sub for Vector4 {
923    type Output = Vector4;
924    #[inline]
925    fn sub(self, rhs: Vector4) -> Vector4 {
926        // SAFETY: Vector4Subtract is a pure value-in/out raymath fn; no preconditions.
927        unsafe { crate::Vector4Subtract(self, rhs) }
928    }
929}
930impl std::ops::SubAssign for Vector4 {
931    #[inline]
932    fn sub_assign(&mut self, rhs: Vector4) {
933        *self = *self - rhs;
934    }
935}
936
937impl std::ops::Mul<f32> for Vector4 {
938    type Output = Vector4;
939    #[inline]
940    fn mul(self, rhs: f32) -> Vector4 {
941        // SAFETY: Vector4Scale is a pure value-in/out raymath fn; no preconditions.
942        unsafe { crate::Vector4Scale(self, rhs) }
943    }
944}
945impl std::ops::MulAssign<f32> for Vector4 {
946    #[inline]
947    fn mul_assign(&mut self, rhs: f32) {
948        *self = *self * rhs;
949    }
950}
951
952impl std::ops::Mul<Vector4> for Vector4 {
953    type Output = Vector4;
954    #[inline]
955    fn mul(self, rhs: Vector4) -> Vector4 {
956        // SAFETY: Vector4Multiply is a pure value-in/out raymath fn (component-wise); no preconditions.
957        unsafe { crate::Vector4Multiply(self, rhs) }
958    }
959}
960
961impl std::ops::Div<Vector4> for Vector4 {
962    type Output = Vector4;
963    #[inline]
964    fn div(self, rhs: Vector4) -> Vector4 {
965        // SAFETY: Vector4Divide is a pure value-in/out raymath fn (component-wise); no preconditions.
966        unsafe { crate::Vector4Divide(self, rhs) }
967    }
968}
969
970impl std::ops::Neg for Vector4 {
971    type Output = Vector4;
972    #[inline]
973    fn neg(self) -> Vector4 {
974        // SAFETY: Vector4Negate is a pure value-in/out raymath fn; no preconditions.
975        unsafe { crate::Vector4Negate(self) }
976    }
977}