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