1use crate::{Matrix, Quaternion, Vector2, Vector3, Vector4};
2
3impl Vector2 {
6 pub const ZERO: Self = Self { x: 0.0, y: 0.0 };
8 pub const ONE: Self = Self { x: 1.0, y: 1.0 };
10
11 #[inline]
13 pub fn new(x: f32, y: f32) -> Self {
14 Self { x, y }
15 }
16
17 #[inline]
19 #[must_use]
20 pub fn zero() -> Self {
21 unsafe { crate::Vector2Zero() }
23 }
24
25 #[inline]
27 #[must_use]
28 pub fn one() -> Self {
29 unsafe { crate::Vector2One() }
31 }
32
33 #[inline]
35 #[must_use]
36 pub fn add_value(self, add: f32) -> Self {
37 unsafe { crate::Vector2AddValue(self, add) }
39 }
40
41 #[inline]
43 #[must_use]
44 pub fn sub_value(self, sub: f32) -> Self {
45 unsafe { crate::Vector2SubtractValue(self, sub) }
47 }
48
49 #[inline]
51 #[must_use]
52 pub fn length(self) -> f32 {
53 unsafe { crate::Vector2Length(self) }
55 }
56
57 #[inline]
59 #[must_use]
60 pub fn length_sqr(self) -> f32 {
61 unsafe { crate::Vector2LengthSqr(self) }
63 }
64
65 #[inline]
67 #[must_use]
68 pub fn dot(self, other: Vector2) -> f32 {
69 unsafe { crate::Vector2DotProduct(self, other) }
71 }
72
73 #[inline]
75 #[must_use]
76 pub fn cross(self, other: Vector2) -> f32 {
77 unsafe { crate::Vector2CrossProduct(self, other) }
79 }
80
81 #[inline]
83 #[must_use]
84 pub fn distance(self, other: Vector2) -> f32 {
85 unsafe { crate::Vector2Distance(self, other) }
87 }
88
89 #[inline]
91 #[must_use]
92 pub fn distance_sqr(self, other: Vector2) -> f32 {
93 unsafe { crate::Vector2DistanceSqr(self, other) }
95 }
96
97 #[inline]
99 #[must_use]
100 pub fn angle(self, other: Vector2) -> f32 {
101 unsafe { crate::Vector2Angle(self, other) }
103 }
104
105 #[inline]
107 #[must_use]
108 pub fn line_angle(start: Vector2, end: Vector2) -> f32 {
109 unsafe { crate::Vector2LineAngle(start, end) }
111 }
112
113 #[inline]
115 #[must_use]
116 pub fn scale(self, scale: f32) -> Self {
117 unsafe { crate::Vector2Scale(self, scale) }
119 }
120
121 #[inline]
123 #[must_use]
124 pub fn multiply(self, other: Vector2) -> Self {
125 unsafe { crate::Vector2Multiply(self, other) }
127 }
128
129 #[inline]
131 #[must_use]
132 pub fn negate(self) -> Self {
133 unsafe { crate::Vector2Negate(self) }
135 }
136
137 #[inline]
139 #[must_use]
140 pub fn divide(self, other: Vector2) -> Self {
141 unsafe { crate::Vector2Divide(self, other) }
143 }
144
145 #[inline]
147 #[must_use]
148 pub fn normalize(self) -> Self {
149 unsafe { crate::Vector2Normalize(self) }
151 }
152
153 #[inline]
155 #[must_use]
156 pub fn transform(self, mat: Matrix) -> Self {
157 unsafe { crate::Vector2Transform(self, mat) }
159 }
160
161 #[inline]
163 #[must_use]
164 pub fn lerp(self, other: Vector2, amount: f32) -> Self {
165 unsafe { crate::Vector2Lerp(self, other, amount) }
167 }
168
169 #[inline]
171 #[must_use]
172 pub fn reflect(self, normal: Vector2) -> Self {
173 unsafe { crate::Vector2Reflect(self, normal) }
175 }
176
177 #[inline]
179 #[must_use]
180 pub fn min(self, other: Vector2) -> Self {
181 unsafe { crate::Vector2Min(self, other) }
183 }
184
185 #[inline]
187 #[must_use]
188 pub fn max(self, other: Vector2) -> Self {
189 unsafe { crate::Vector2Max(self, other) }
191 }
192
193 #[inline]
195 #[must_use]
196 pub fn rotate(self, angle: f32) -> Self {
197 unsafe { crate::Vector2Rotate(self, angle) }
199 }
200
201 #[inline]
203 #[must_use]
204 pub fn move_towards(self, target: Vector2, max_distance: f32) -> Self {
205 unsafe { crate::Vector2MoveTowards(self, target, max_distance) }
207 }
208
209 #[inline]
211 #[must_use]
212 pub fn invert(self) -> Self {
213 unsafe { crate::Vector2Invert(self) }
215 }
216
217 #[inline]
219 #[must_use]
220 pub fn clamp(self, min: Vector2, max: Vector2) -> Self {
221 unsafe { crate::Vector2Clamp(self, min, max) }
223 }
224
225 #[inline]
227 #[must_use]
228 pub fn clamp_value(self, min: f32, max: f32) -> Self {
229 unsafe { crate::Vector2ClampValue(self, min, max) }
231 }
232
233 #[inline]
235 #[must_use]
236 pub fn equals(self, other: Vector2) -> bool {
237 unsafe { crate::Vector2Equals(self, other) != 0 }
239 }
240
241 #[inline]
243 #[must_use]
244 pub fn refract(self, n: Vector2, r: f32) -> Self {
245 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 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 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 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 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 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 unsafe { crate::Vector2Negate(self) }
319 }
320}
321
322impl Vector3 {
325 pub const ZERO: Self = Self {
327 x: 0.0,
328 y: 0.0,
329 z: 0.0,
330 };
331 pub const ONE: Self = Self {
333 x: 1.0,
334 y: 1.0,
335 z: 1.0,
336 };
337 pub const X: Self = Self {
339 x: 1.0,
340 y: 0.0,
341 z: 0.0,
342 };
343 pub const Y: Self = Self {
345 x: 0.0,
346 y: 1.0,
347 z: 0.0,
348 };
349 pub const Z: Self = Self {
351 x: 0.0,
352 y: 0.0,
353 z: 1.0,
354 };
355
356 #[inline]
358 pub fn new(x: f32, y: f32, z: f32) -> Self {
359 Self { x, y, z }
360 }
361
362 #[inline]
364 #[must_use]
365 pub fn zero() -> Self {
366 unsafe { crate::Vector3Zero() }
368 }
369
370 #[inline]
372 #[must_use]
373 pub fn one() -> Self {
374 unsafe { crate::Vector3One() }
376 }
377
378 #[inline]
380 #[must_use]
381 pub fn add_value(self, add: f32) -> Self {
382 unsafe { crate::Vector3AddValue(self, add) }
384 }
385
386 #[inline]
388 #[must_use]
389 pub fn sub_value(self, sub: f32) -> Self {
390 unsafe { crate::Vector3SubtractValue(self, sub) }
392 }
393
394 #[inline]
396 #[must_use]
397 pub fn scale(self, scalar: f32) -> Self {
398 unsafe { crate::Vector3Scale(self, scalar) }
400 }
401
402 #[inline]
404 #[must_use]
405 pub fn multiply(self, other: Vector3) -> Self {
406 unsafe { crate::Vector3Multiply(self, other) }
408 }
409
410 #[inline]
412 #[must_use]
413 pub fn cross(self, other: Vector3) -> Self {
414 unsafe { crate::Vector3CrossProduct(self, other) }
416 }
417
418 #[inline]
420 #[must_use]
421 pub fn perpendicular(self) -> Self {
422 unsafe { crate::Vector3Perpendicular(self) }
424 }
425
426 #[inline]
428 #[must_use]
429 pub fn length(self) -> f32 {
430 unsafe { crate::Vector3Length(self) }
432 }
433
434 #[inline]
436 #[must_use]
437 pub fn length_sqr(self) -> f32 {
438 unsafe { crate::Vector3LengthSqr(self) }
440 }
441
442 #[inline]
444 #[must_use]
445 pub fn dot(self, other: Vector3) -> f32 {
446 unsafe { crate::Vector3DotProduct(self, other) }
448 }
449
450 #[inline]
452 #[must_use]
453 pub fn distance(self, other: Vector3) -> f32 {
454 unsafe { crate::Vector3Distance(self, other) }
456 }
457
458 #[inline]
460 #[must_use]
461 pub fn distance_sqr(self, other: Vector3) -> f32 {
462 unsafe { crate::Vector3DistanceSqr(self, other) }
464 }
465
466 #[inline]
468 #[must_use]
469 pub fn angle(self, other: Vector3) -> f32 {
470 unsafe { crate::Vector3Angle(self, other) }
472 }
473
474 #[inline]
476 #[must_use]
477 pub fn negate(self) -> Self {
478 unsafe { crate::Vector3Negate(self) }
480 }
481
482 #[inline]
484 #[must_use]
485 pub fn divide(self, other: Vector3) -> Self {
486 unsafe { crate::Vector3Divide(self, other) }
488 }
489
490 #[inline]
492 #[must_use]
493 pub fn normalize(self) -> Self {
494 unsafe { crate::Vector3Normalize(self) }
496 }
497
498 #[inline]
500 #[must_use]
501 pub fn project(self, other: Vector3) -> Self {
502 unsafe { crate::Vector3Project(self, other) }
504 }
505
506 #[inline]
508 #[must_use]
509 pub fn reject(self, other: Vector3) -> Self {
510 unsafe { crate::Vector3Reject(self, other) }
512 }
513
514 #[inline]
516 #[must_use]
517 pub fn transform(self, mat: Matrix) -> Self {
518 unsafe { crate::Vector3Transform(self, mat) }
520 }
521
522 #[inline]
524 #[must_use]
525 pub fn rotate_by_quaternion(self, q: Quaternion) -> Self {
526 unsafe { crate::Vector3RotateByQuaternion(self, q) }
528 }
529
530 #[inline]
532 #[must_use]
533 pub fn rotate_by_axis_angle(self, axis: Vector3, angle: f32) -> Self {
534 unsafe { crate::Vector3RotateByAxisAngle(self, axis, angle) }
536 }
537
538 #[inline]
540 #[must_use]
541 pub fn move_towards(self, target: Vector3, max_distance: f32) -> Self {
542 unsafe { crate::Vector3MoveTowards(self, target, max_distance) }
544 }
545
546 #[inline]
548 #[must_use]
549 pub fn lerp(self, other: Vector3, amount: f32) -> Self {
550 unsafe { crate::Vector3Lerp(self, other, amount) }
552 }
553
554 #[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 unsafe { crate::Vector3CubicHermite(self, tangent1, v2, tangent2, amount) }
566 }
567
568 #[inline]
570 #[must_use]
571 pub fn reflect(self, normal: Vector3) -> Self {
572 unsafe { crate::Vector3Reflect(self, normal) }
574 }
575
576 #[inline]
578 #[must_use]
579 pub fn min(self, other: Vector3) -> Self {
580 unsafe { crate::Vector3Min(self, other) }
582 }
583
584 #[inline]
586 #[must_use]
587 pub fn max(self, other: Vector3) -> Self {
588 unsafe { crate::Vector3Max(self, other) }
590 }
591
592 #[inline]
594 #[must_use]
595 pub fn barycenter(p: Vector3, a: Vector3, b: Vector3, c: Vector3) -> Self {
596 unsafe { crate::Vector3Barycenter(p, a, b, c) }
598 }
599
600 #[inline]
602 #[must_use]
603 pub fn unproject(self, projection: Matrix, view: Matrix) -> Self {
604 unsafe { crate::Vector3Unproject(self, projection, view) }
606 }
607
608 #[inline]
610 #[must_use]
611 pub fn to_float_array(self) -> crate::float3 {
612 unsafe { crate::Vector3ToFloatV(self) }
614 }
615
616 #[inline]
618 #[must_use]
619 pub fn invert(self) -> Self {
620 unsafe { crate::Vector3Invert(self) }
622 }
623
624 #[inline]
626 #[must_use]
627 pub fn clamp(self, min: Vector3, max: Vector3) -> Self {
628 unsafe { crate::Vector3Clamp(self, min, max) }
630 }
631
632 #[inline]
634 #[must_use]
635 pub fn clamp_value(self, min: f32, max: f32) -> Self {
636 unsafe { crate::Vector3ClampValue(self, min, max) }
638 }
639
640 #[inline]
642 #[must_use]
643 pub fn equals(self, other: Vector3) -> bool {
644 unsafe { crate::Vector3Equals(self, other) != 0 }
646 }
647
648 #[inline]
650 #[must_use]
651 pub fn refract(self, n: Vector3, r: f32) -> Self {
652 unsafe { crate::Vector3Refract(self, n, r) }
654 }
655}
656
657pub fn vector3_ortho_normalize(v1: &mut Vector3, v2: &mut Vector3) {
659 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 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 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 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 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 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 unsafe { crate::Vector3Negate(self) }
734 }
735}
736
737impl Vector4 {
740 #[inline]
742 pub fn new(x: f32, y: f32, z: f32, w: f32) -> Self {
743 Self { x, y, z, w }
744 }
745
746 #[inline]
748 #[must_use]
749 pub fn zero() -> Self {
750 unsafe { crate::Vector4Zero() }
752 }
753
754 #[inline]
756 #[must_use]
757 pub fn one() -> Self {
758 unsafe { crate::Vector4One() }
760 }
761
762 #[inline]
764 #[must_use]
765 pub fn add_value(self, add: f32) -> Self {
766 unsafe { crate::Vector4AddValue(self, add) }
768 }
769
770 #[inline]
772 #[must_use]
773 pub fn sub_value(self, sub: f32) -> Self {
774 unsafe { crate::Vector4SubtractValue(self, sub) }
776 }
777
778 #[inline]
780 #[must_use]
781 pub fn length(self) -> f32 {
782 unsafe { crate::Vector4Length(self) }
784 }
785
786 #[inline]
788 #[must_use]
789 pub fn length_sqr(self) -> f32 {
790 unsafe { crate::Vector4LengthSqr(self) }
792 }
793
794 #[inline]
796 #[must_use]
797 pub fn dot(self, other: Vector4) -> f32 {
798 unsafe { crate::Vector4DotProduct(self, other) }
800 }
801
802 #[inline]
804 #[must_use]
805 pub fn distance(self, other: Vector4) -> f32 {
806 unsafe { crate::Vector4Distance(self, other) }
808 }
809
810 #[inline]
812 #[must_use]
813 pub fn distance_sqr(self, other: Vector4) -> f32 {
814 unsafe { crate::Vector4DistanceSqr(self, other) }
816 }
817
818 #[inline]
820 #[must_use]
821 pub fn scale(self, scale: f32) -> Self {
822 unsafe { crate::Vector4Scale(self, scale) }
824 }
825
826 #[inline]
828 #[must_use]
829 pub fn multiply(self, other: Vector4) -> Self {
830 unsafe { crate::Vector4Multiply(self, other) }
832 }
833
834 #[inline]
836 #[must_use]
837 pub fn negate(self) -> Self {
838 unsafe { crate::Vector4Negate(self) }
840 }
841
842 #[inline]
844 #[must_use]
845 pub fn divide(self, other: Vector4) -> Self {
846 unsafe { crate::Vector4Divide(self, other) }
848 }
849
850 #[inline]
852 #[must_use]
853 pub fn normalize(self) -> Self {
854 unsafe { crate::Vector4Normalize(self) }
856 }
857
858 #[inline]
860 #[must_use]
861 pub fn min(self, other: Vector4) -> Self {
862 unsafe { crate::Vector4Min(self, other) }
864 }
865
866 #[inline]
868 #[must_use]
869 pub fn max(self, other: Vector4) -> Self {
870 unsafe { crate::Vector4Max(self, other) }
872 }
873
874 #[inline]
876 #[must_use]
877 pub fn lerp(self, other: Vector4, amount: f32) -> Self {
878 unsafe { crate::Vector4Lerp(self, other, amount) }
880 }
881
882 #[inline]
884 #[must_use]
885 pub fn move_towards(self, target: Vector4, max_distance: f32) -> Self {
886 unsafe { crate::Vector4MoveTowards(self, target, max_distance) }
888 }
889
890 #[inline]
892 #[must_use]
893 pub fn invert(self) -> Self {
894 unsafe { crate::Vector4Invert(self) }
896 }
897
898 #[inline]
900 #[must_use]
901 pub fn equals(self, other: Vector4) -> bool {
902 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 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 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 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 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 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 unsafe { crate::Vector4Negate(self) }
976 }
977}