pub struct Vector4<T> {
pub x: T,
pub y: T,
pub z: T,
pub w: T,
}Fields§
§x: T§y: T§z: T§w: TImplementations§
Source§impl<T> Vector4<T>
impl<T> Vector4<T>
pub fn new(x: T, y: T, z: T, w: T) -> Self
Sourcepub fn length(&self) -> f64
pub fn length(&self) -> f64
Examples found in repository?
examples/vector_operations.rs (line 59)
3fn main() {
4 // Example usage
5 let v2_a = Vector2 { x: 1.0, y: 2.0 };
6 let v2_b = Vector2 { x: 3.0, y: 4.0 };
7 let v3_a = Vector3 {
8 x: 1.0,
9 y: 2.0,
10 z: 3.0,
11 };
12 let v3_b = Vector3 {
13 x: 4.0,
14 y: 5.0,
15 z: 6.0,
16 };
17 let v4_a = Vector4 {
18 x: 1.0,
19 y: 2.0,
20 z: 3.0,
21 w: 4.0,
22 };
23 let v4_b = Vector4 {
24 x: 5.0,
25 y: 6.0,
26 z: 7.0,
27 w: 8.0,
28 };
29
30 println!("========================================");
31
32 println!("v2_a + v2_b = {:?}", v2_a + v2_b);
33 println!("v3_a + v3_b = {:?}", v3_a + v3_b);
34 println!("v4_a + v4_b = {:?}", v4_a + v4_b);
35
36 println!("========================================");
37
38 println!("v2_a - v2_b = {:?}", v2_a - v2_b);
39 println!("v3_a - v3_b = {:?}", v3_a - v3_b);
40 println!("v4_a - v4_b = {:?}", v4_a - v4_b);
41
42 println!("========================================");
43
44 println!("v2_a * v2_b = {:?}", v2_a - v2_b);
45 println!("v3_a * v3_b = {:?}", v3_a - v3_b);
46 println!("v4_a * v4_b = {:?}", v4_a - v4_b);
47
48 println!("========================================");
49
50 println!("v2_a / v2_b = {:?}", v2_a / v2_b);
51 println!("v3_a / v3_b = {:?}", v3_a / v3_b);
52 println!("v4_a / v4_b = {:?}", v4_a / v4_b);
53
54 println!("========================================");
55
56 // Example of length calculation
57 println!("Length of Vector2: {}", v2_a.length());
58 println!("Length of Vector3: {}", v3_a.length());
59 println!("Length of Vector4: {}", v4_a.length());
60
61 println!("========================================");
62
63 // Example of dot product calculation
64 println!("Dot Product of Vector2: {}", v2_a.dot(&v2_b));
65 println!("Dot Product of Vector3: {}", v3_a.dot(&v3_b));
66 println!("Dot Product of Vector4: {}", v4_a.dot(&v4_b));
67
68 println!("========================================");
69
70 // Example of cross product calculation
71 println!("Cross Product of Vector2: {:?}", v2_a.cross(&v2_a));
72 println!("Cross Product of Vector3: {:?}", v3_a.cross(&v3_b));
73 println!("Cross Product of Vector4: {:?}", v4_a.cross(&v4_b));
74
75 println!("========================================");
76
77 // Example of projection
78 println!("Projection onto of Vector2: {:?}", v2_a.project_onto(&v2_b));
79 println!("Projection onto of Vector3: {:?}", v3_a.project_onto(&v3_b));
80 println!("Projection onto of Vector4: {:?}", v4_a.project_onto(&v4_b));
81
82 println!("========================================");
83
84 // Example of Linear Interpolation
85 println!("Lerp for Vector2 (t = 0.5): {:?}", v2_a.lerp(&v2_b, 0.5));
86 println!("Lerp for Vector3 (t = 0.5): {:?}", v3_a.lerp(&v3_b, 0.5));
87 println!("Lerp for Vector4 (t = 0.5): {:?}", v4_a.lerp(&v4_b, 0.5));
88
89 println!("Lerp for Vector2 (t = 0.0): {:?}", v2_a.lerp(&v2_b, 0.0)); // Should return v2_a
90 println!("Lerp for Vector3 (t = 1.0): {:?}", v3_a.lerp(&v3_b, 1.0)); // Should return v3_b
91
92 println!("========================================");
93
94 // Example of Swizzling
95 println!("Swizzled Vector2 (yx): {:?}", v2_a.swizzle(1, 0)); // Swap x and y
96 println!("Swizzled Vector3 (yxz): {:?}", v3_a.swizzle(1, 0, 2)); // Swap x and y
97 println!("Swizzled Vector4 (wzyx): {:?}", v4_a.swizzle(3, 2, 1, 0)); // Reverse order
98
99 println!("========================================");
100
101 // Example of Angle Between Vectors
102 println!(
103 "Angle between Vector2 (radians): {}",
104 v2_a.angle_between(&v2_b)
105 );
106 println!(
107 "Angle between Vector3 (radians): {}",
108 v3_a.angle_between(&v3_b)
109 );
110 println!(
111 "Angle between Vector4 (radians): {}",
112 v4_a.angle_between(&v4_b)
113 );
114
115 println!("========================================");
116}Sourcepub fn dot(&self, other: &Self) -> f64
pub fn dot(&self, other: &Self) -> f64
Examples found in repository?
examples/vector_operations.rs (line 66)
3fn main() {
4 // Example usage
5 let v2_a = Vector2 { x: 1.0, y: 2.0 };
6 let v2_b = Vector2 { x: 3.0, y: 4.0 };
7 let v3_a = Vector3 {
8 x: 1.0,
9 y: 2.0,
10 z: 3.0,
11 };
12 let v3_b = Vector3 {
13 x: 4.0,
14 y: 5.0,
15 z: 6.0,
16 };
17 let v4_a = Vector4 {
18 x: 1.0,
19 y: 2.0,
20 z: 3.0,
21 w: 4.0,
22 };
23 let v4_b = Vector4 {
24 x: 5.0,
25 y: 6.0,
26 z: 7.0,
27 w: 8.0,
28 };
29
30 println!("========================================");
31
32 println!("v2_a + v2_b = {:?}", v2_a + v2_b);
33 println!("v3_a + v3_b = {:?}", v3_a + v3_b);
34 println!("v4_a + v4_b = {:?}", v4_a + v4_b);
35
36 println!("========================================");
37
38 println!("v2_a - v2_b = {:?}", v2_a - v2_b);
39 println!("v3_a - v3_b = {:?}", v3_a - v3_b);
40 println!("v4_a - v4_b = {:?}", v4_a - v4_b);
41
42 println!("========================================");
43
44 println!("v2_a * v2_b = {:?}", v2_a - v2_b);
45 println!("v3_a * v3_b = {:?}", v3_a - v3_b);
46 println!("v4_a * v4_b = {:?}", v4_a - v4_b);
47
48 println!("========================================");
49
50 println!("v2_a / v2_b = {:?}", v2_a / v2_b);
51 println!("v3_a / v3_b = {:?}", v3_a / v3_b);
52 println!("v4_a / v4_b = {:?}", v4_a / v4_b);
53
54 println!("========================================");
55
56 // Example of length calculation
57 println!("Length of Vector2: {}", v2_a.length());
58 println!("Length of Vector3: {}", v3_a.length());
59 println!("Length of Vector4: {}", v4_a.length());
60
61 println!("========================================");
62
63 // Example of dot product calculation
64 println!("Dot Product of Vector2: {}", v2_a.dot(&v2_b));
65 println!("Dot Product of Vector3: {}", v3_a.dot(&v3_b));
66 println!("Dot Product of Vector4: {}", v4_a.dot(&v4_b));
67
68 println!("========================================");
69
70 // Example of cross product calculation
71 println!("Cross Product of Vector2: {:?}", v2_a.cross(&v2_a));
72 println!("Cross Product of Vector3: {:?}", v3_a.cross(&v3_b));
73 println!("Cross Product of Vector4: {:?}", v4_a.cross(&v4_b));
74
75 println!("========================================");
76
77 // Example of projection
78 println!("Projection onto of Vector2: {:?}", v2_a.project_onto(&v2_b));
79 println!("Projection onto of Vector3: {:?}", v3_a.project_onto(&v3_b));
80 println!("Projection onto of Vector4: {:?}", v4_a.project_onto(&v4_b));
81
82 println!("========================================");
83
84 // Example of Linear Interpolation
85 println!("Lerp for Vector2 (t = 0.5): {:?}", v2_a.lerp(&v2_b, 0.5));
86 println!("Lerp for Vector3 (t = 0.5): {:?}", v3_a.lerp(&v3_b, 0.5));
87 println!("Lerp for Vector4 (t = 0.5): {:?}", v4_a.lerp(&v4_b, 0.5));
88
89 println!("Lerp for Vector2 (t = 0.0): {:?}", v2_a.lerp(&v2_b, 0.0)); // Should return v2_a
90 println!("Lerp for Vector3 (t = 1.0): {:?}", v3_a.lerp(&v3_b, 1.0)); // Should return v3_b
91
92 println!("========================================");
93
94 // Example of Swizzling
95 println!("Swizzled Vector2 (yx): {:?}", v2_a.swizzle(1, 0)); // Swap x and y
96 println!("Swizzled Vector3 (yxz): {:?}", v3_a.swizzle(1, 0, 2)); // Swap x and y
97 println!("Swizzled Vector4 (wzyx): {:?}", v4_a.swizzle(3, 2, 1, 0)); // Reverse order
98
99 println!("========================================");
100
101 // Example of Angle Between Vectors
102 println!(
103 "Angle between Vector2 (radians): {}",
104 v2_a.angle_between(&v2_b)
105 );
106 println!(
107 "Angle between Vector3 (radians): {}",
108 v3_a.angle_between(&v3_b)
109 );
110 println!(
111 "Angle between Vector4 (radians): {}",
112 v4_a.angle_between(&v4_b)
113 );
114
115 println!("========================================");
116}Sourcepub fn cross(&self, other: &Self) -> Vector4<f64>
pub fn cross(&self, other: &Self) -> Vector4<f64>
Examples found in repository?
examples/vector_operations.rs (line 73)
3fn main() {
4 // Example usage
5 let v2_a = Vector2 { x: 1.0, y: 2.0 };
6 let v2_b = Vector2 { x: 3.0, y: 4.0 };
7 let v3_a = Vector3 {
8 x: 1.0,
9 y: 2.0,
10 z: 3.0,
11 };
12 let v3_b = Vector3 {
13 x: 4.0,
14 y: 5.0,
15 z: 6.0,
16 };
17 let v4_a = Vector4 {
18 x: 1.0,
19 y: 2.0,
20 z: 3.0,
21 w: 4.0,
22 };
23 let v4_b = Vector4 {
24 x: 5.0,
25 y: 6.0,
26 z: 7.0,
27 w: 8.0,
28 };
29
30 println!("========================================");
31
32 println!("v2_a + v2_b = {:?}", v2_a + v2_b);
33 println!("v3_a + v3_b = {:?}", v3_a + v3_b);
34 println!("v4_a + v4_b = {:?}", v4_a + v4_b);
35
36 println!("========================================");
37
38 println!("v2_a - v2_b = {:?}", v2_a - v2_b);
39 println!("v3_a - v3_b = {:?}", v3_a - v3_b);
40 println!("v4_a - v4_b = {:?}", v4_a - v4_b);
41
42 println!("========================================");
43
44 println!("v2_a * v2_b = {:?}", v2_a - v2_b);
45 println!("v3_a * v3_b = {:?}", v3_a - v3_b);
46 println!("v4_a * v4_b = {:?}", v4_a - v4_b);
47
48 println!("========================================");
49
50 println!("v2_a / v2_b = {:?}", v2_a / v2_b);
51 println!("v3_a / v3_b = {:?}", v3_a / v3_b);
52 println!("v4_a / v4_b = {:?}", v4_a / v4_b);
53
54 println!("========================================");
55
56 // Example of length calculation
57 println!("Length of Vector2: {}", v2_a.length());
58 println!("Length of Vector3: {}", v3_a.length());
59 println!("Length of Vector4: {}", v4_a.length());
60
61 println!("========================================");
62
63 // Example of dot product calculation
64 println!("Dot Product of Vector2: {}", v2_a.dot(&v2_b));
65 println!("Dot Product of Vector3: {}", v3_a.dot(&v3_b));
66 println!("Dot Product of Vector4: {}", v4_a.dot(&v4_b));
67
68 println!("========================================");
69
70 // Example of cross product calculation
71 println!("Cross Product of Vector2: {:?}", v2_a.cross(&v2_a));
72 println!("Cross Product of Vector3: {:?}", v3_a.cross(&v3_b));
73 println!("Cross Product of Vector4: {:?}", v4_a.cross(&v4_b));
74
75 println!("========================================");
76
77 // Example of projection
78 println!("Projection onto of Vector2: {:?}", v2_a.project_onto(&v2_b));
79 println!("Projection onto of Vector3: {:?}", v3_a.project_onto(&v3_b));
80 println!("Projection onto of Vector4: {:?}", v4_a.project_onto(&v4_b));
81
82 println!("========================================");
83
84 // Example of Linear Interpolation
85 println!("Lerp for Vector2 (t = 0.5): {:?}", v2_a.lerp(&v2_b, 0.5));
86 println!("Lerp for Vector3 (t = 0.5): {:?}", v3_a.lerp(&v3_b, 0.5));
87 println!("Lerp for Vector4 (t = 0.5): {:?}", v4_a.lerp(&v4_b, 0.5));
88
89 println!("Lerp for Vector2 (t = 0.0): {:?}", v2_a.lerp(&v2_b, 0.0)); // Should return v2_a
90 println!("Lerp for Vector3 (t = 1.0): {:?}", v3_a.lerp(&v3_b, 1.0)); // Should return v3_b
91
92 println!("========================================");
93
94 // Example of Swizzling
95 println!("Swizzled Vector2 (yx): {:?}", v2_a.swizzle(1, 0)); // Swap x and y
96 println!("Swizzled Vector3 (yxz): {:?}", v3_a.swizzle(1, 0, 2)); // Swap x and y
97 println!("Swizzled Vector4 (wzyx): {:?}", v4_a.swizzle(3, 2, 1, 0)); // Reverse order
98
99 println!("========================================");
100
101 // Example of Angle Between Vectors
102 println!(
103 "Angle between Vector2 (radians): {}",
104 v2_a.angle_between(&v2_b)
105 );
106 println!(
107 "Angle between Vector3 (radians): {}",
108 v3_a.angle_between(&v3_b)
109 );
110 println!(
111 "Angle between Vector4 (radians): {}",
112 v4_a.angle_between(&v4_b)
113 );
114
115 println!("========================================");
116}pub fn normalize(&self) -> Self
Sourcepub fn project_onto(&self, other: &Self) -> Self
pub fn project_onto(&self, other: &Self) -> Self
Examples found in repository?
examples/vector_operations.rs (line 80)
3fn main() {
4 // Example usage
5 let v2_a = Vector2 { x: 1.0, y: 2.0 };
6 let v2_b = Vector2 { x: 3.0, y: 4.0 };
7 let v3_a = Vector3 {
8 x: 1.0,
9 y: 2.0,
10 z: 3.0,
11 };
12 let v3_b = Vector3 {
13 x: 4.0,
14 y: 5.0,
15 z: 6.0,
16 };
17 let v4_a = Vector4 {
18 x: 1.0,
19 y: 2.0,
20 z: 3.0,
21 w: 4.0,
22 };
23 let v4_b = Vector4 {
24 x: 5.0,
25 y: 6.0,
26 z: 7.0,
27 w: 8.0,
28 };
29
30 println!("========================================");
31
32 println!("v2_a + v2_b = {:?}", v2_a + v2_b);
33 println!("v3_a + v3_b = {:?}", v3_a + v3_b);
34 println!("v4_a + v4_b = {:?}", v4_a + v4_b);
35
36 println!("========================================");
37
38 println!("v2_a - v2_b = {:?}", v2_a - v2_b);
39 println!("v3_a - v3_b = {:?}", v3_a - v3_b);
40 println!("v4_a - v4_b = {:?}", v4_a - v4_b);
41
42 println!("========================================");
43
44 println!("v2_a * v2_b = {:?}", v2_a - v2_b);
45 println!("v3_a * v3_b = {:?}", v3_a - v3_b);
46 println!("v4_a * v4_b = {:?}", v4_a - v4_b);
47
48 println!("========================================");
49
50 println!("v2_a / v2_b = {:?}", v2_a / v2_b);
51 println!("v3_a / v3_b = {:?}", v3_a / v3_b);
52 println!("v4_a / v4_b = {:?}", v4_a / v4_b);
53
54 println!("========================================");
55
56 // Example of length calculation
57 println!("Length of Vector2: {}", v2_a.length());
58 println!("Length of Vector3: {}", v3_a.length());
59 println!("Length of Vector4: {}", v4_a.length());
60
61 println!("========================================");
62
63 // Example of dot product calculation
64 println!("Dot Product of Vector2: {}", v2_a.dot(&v2_b));
65 println!("Dot Product of Vector3: {}", v3_a.dot(&v3_b));
66 println!("Dot Product of Vector4: {}", v4_a.dot(&v4_b));
67
68 println!("========================================");
69
70 // Example of cross product calculation
71 println!("Cross Product of Vector2: {:?}", v2_a.cross(&v2_a));
72 println!("Cross Product of Vector3: {:?}", v3_a.cross(&v3_b));
73 println!("Cross Product of Vector4: {:?}", v4_a.cross(&v4_b));
74
75 println!("========================================");
76
77 // Example of projection
78 println!("Projection onto of Vector2: {:?}", v2_a.project_onto(&v2_b));
79 println!("Projection onto of Vector3: {:?}", v3_a.project_onto(&v3_b));
80 println!("Projection onto of Vector4: {:?}", v4_a.project_onto(&v4_b));
81
82 println!("========================================");
83
84 // Example of Linear Interpolation
85 println!("Lerp for Vector2 (t = 0.5): {:?}", v2_a.lerp(&v2_b, 0.5));
86 println!("Lerp for Vector3 (t = 0.5): {:?}", v3_a.lerp(&v3_b, 0.5));
87 println!("Lerp for Vector4 (t = 0.5): {:?}", v4_a.lerp(&v4_b, 0.5));
88
89 println!("Lerp for Vector2 (t = 0.0): {:?}", v2_a.lerp(&v2_b, 0.0)); // Should return v2_a
90 println!("Lerp for Vector3 (t = 1.0): {:?}", v3_a.lerp(&v3_b, 1.0)); // Should return v3_b
91
92 println!("========================================");
93
94 // Example of Swizzling
95 println!("Swizzled Vector2 (yx): {:?}", v2_a.swizzle(1, 0)); // Swap x and y
96 println!("Swizzled Vector3 (yxz): {:?}", v3_a.swizzle(1, 0, 2)); // Swap x and y
97 println!("Swizzled Vector4 (wzyx): {:?}", v4_a.swizzle(3, 2, 1, 0)); // Reverse order
98
99 println!("========================================");
100
101 // Example of Angle Between Vectors
102 println!(
103 "Angle between Vector2 (radians): {}",
104 v2_a.angle_between(&v2_b)
105 );
106 println!(
107 "Angle between Vector3 (radians): {}",
108 v3_a.angle_between(&v3_b)
109 );
110 println!(
111 "Angle between Vector4 (radians): {}",
112 v4_a.angle_between(&v4_b)
113 );
114
115 println!("========================================");
116}pub fn reject_from(&self, other: &Self) -> Self
Sourcepub fn lerp(&self, other: &Self, t: f64) -> Self
pub fn lerp(&self, other: &Self, t: f64) -> Self
Examples found in repository?
examples/vector_operations.rs (line 87)
3fn main() {
4 // Example usage
5 let v2_a = Vector2 { x: 1.0, y: 2.0 };
6 let v2_b = Vector2 { x: 3.0, y: 4.0 };
7 let v3_a = Vector3 {
8 x: 1.0,
9 y: 2.0,
10 z: 3.0,
11 };
12 let v3_b = Vector3 {
13 x: 4.0,
14 y: 5.0,
15 z: 6.0,
16 };
17 let v4_a = Vector4 {
18 x: 1.0,
19 y: 2.0,
20 z: 3.0,
21 w: 4.0,
22 };
23 let v4_b = Vector4 {
24 x: 5.0,
25 y: 6.0,
26 z: 7.0,
27 w: 8.0,
28 };
29
30 println!("========================================");
31
32 println!("v2_a + v2_b = {:?}", v2_a + v2_b);
33 println!("v3_a + v3_b = {:?}", v3_a + v3_b);
34 println!("v4_a + v4_b = {:?}", v4_a + v4_b);
35
36 println!("========================================");
37
38 println!("v2_a - v2_b = {:?}", v2_a - v2_b);
39 println!("v3_a - v3_b = {:?}", v3_a - v3_b);
40 println!("v4_a - v4_b = {:?}", v4_a - v4_b);
41
42 println!("========================================");
43
44 println!("v2_a * v2_b = {:?}", v2_a - v2_b);
45 println!("v3_a * v3_b = {:?}", v3_a - v3_b);
46 println!("v4_a * v4_b = {:?}", v4_a - v4_b);
47
48 println!("========================================");
49
50 println!("v2_a / v2_b = {:?}", v2_a / v2_b);
51 println!("v3_a / v3_b = {:?}", v3_a / v3_b);
52 println!("v4_a / v4_b = {:?}", v4_a / v4_b);
53
54 println!("========================================");
55
56 // Example of length calculation
57 println!("Length of Vector2: {}", v2_a.length());
58 println!("Length of Vector3: {}", v3_a.length());
59 println!("Length of Vector4: {}", v4_a.length());
60
61 println!("========================================");
62
63 // Example of dot product calculation
64 println!("Dot Product of Vector2: {}", v2_a.dot(&v2_b));
65 println!("Dot Product of Vector3: {}", v3_a.dot(&v3_b));
66 println!("Dot Product of Vector4: {}", v4_a.dot(&v4_b));
67
68 println!("========================================");
69
70 // Example of cross product calculation
71 println!("Cross Product of Vector2: {:?}", v2_a.cross(&v2_a));
72 println!("Cross Product of Vector3: {:?}", v3_a.cross(&v3_b));
73 println!("Cross Product of Vector4: {:?}", v4_a.cross(&v4_b));
74
75 println!("========================================");
76
77 // Example of projection
78 println!("Projection onto of Vector2: {:?}", v2_a.project_onto(&v2_b));
79 println!("Projection onto of Vector3: {:?}", v3_a.project_onto(&v3_b));
80 println!("Projection onto of Vector4: {:?}", v4_a.project_onto(&v4_b));
81
82 println!("========================================");
83
84 // Example of Linear Interpolation
85 println!("Lerp for Vector2 (t = 0.5): {:?}", v2_a.lerp(&v2_b, 0.5));
86 println!("Lerp for Vector3 (t = 0.5): {:?}", v3_a.lerp(&v3_b, 0.5));
87 println!("Lerp for Vector4 (t = 0.5): {:?}", v4_a.lerp(&v4_b, 0.5));
88
89 println!("Lerp for Vector2 (t = 0.0): {:?}", v2_a.lerp(&v2_b, 0.0)); // Should return v2_a
90 println!("Lerp for Vector3 (t = 1.0): {:?}", v3_a.lerp(&v3_b, 1.0)); // Should return v3_b
91
92 println!("========================================");
93
94 // Example of Swizzling
95 println!("Swizzled Vector2 (yx): {:?}", v2_a.swizzle(1, 0)); // Swap x and y
96 println!("Swizzled Vector3 (yxz): {:?}", v3_a.swizzle(1, 0, 2)); // Swap x and y
97 println!("Swizzled Vector4 (wzyx): {:?}", v4_a.swizzle(3, 2, 1, 0)); // Reverse order
98
99 println!("========================================");
100
101 // Example of Angle Between Vectors
102 println!(
103 "Angle between Vector2 (radians): {}",
104 v2_a.angle_between(&v2_b)
105 );
106 println!(
107 "Angle between Vector3 (radians): {}",
108 v3_a.angle_between(&v3_b)
109 );
110 println!(
111 "Angle between Vector4 (radians): {}",
112 v4_a.angle_between(&v4_b)
113 );
114
115 println!("========================================");
116}Sourcepub fn angle_between(&self, other: &Self) -> f64
pub fn angle_between(&self, other: &Self) -> f64
Examples found in repository?
examples/vector_operations.rs (line 112)
3fn main() {
4 // Example usage
5 let v2_a = Vector2 { x: 1.0, y: 2.0 };
6 let v2_b = Vector2 { x: 3.0, y: 4.0 };
7 let v3_a = Vector3 {
8 x: 1.0,
9 y: 2.0,
10 z: 3.0,
11 };
12 let v3_b = Vector3 {
13 x: 4.0,
14 y: 5.0,
15 z: 6.0,
16 };
17 let v4_a = Vector4 {
18 x: 1.0,
19 y: 2.0,
20 z: 3.0,
21 w: 4.0,
22 };
23 let v4_b = Vector4 {
24 x: 5.0,
25 y: 6.0,
26 z: 7.0,
27 w: 8.0,
28 };
29
30 println!("========================================");
31
32 println!("v2_a + v2_b = {:?}", v2_a + v2_b);
33 println!("v3_a + v3_b = {:?}", v3_a + v3_b);
34 println!("v4_a + v4_b = {:?}", v4_a + v4_b);
35
36 println!("========================================");
37
38 println!("v2_a - v2_b = {:?}", v2_a - v2_b);
39 println!("v3_a - v3_b = {:?}", v3_a - v3_b);
40 println!("v4_a - v4_b = {:?}", v4_a - v4_b);
41
42 println!("========================================");
43
44 println!("v2_a * v2_b = {:?}", v2_a - v2_b);
45 println!("v3_a * v3_b = {:?}", v3_a - v3_b);
46 println!("v4_a * v4_b = {:?}", v4_a - v4_b);
47
48 println!("========================================");
49
50 println!("v2_a / v2_b = {:?}", v2_a / v2_b);
51 println!("v3_a / v3_b = {:?}", v3_a / v3_b);
52 println!("v4_a / v4_b = {:?}", v4_a / v4_b);
53
54 println!("========================================");
55
56 // Example of length calculation
57 println!("Length of Vector2: {}", v2_a.length());
58 println!("Length of Vector3: {}", v3_a.length());
59 println!("Length of Vector4: {}", v4_a.length());
60
61 println!("========================================");
62
63 // Example of dot product calculation
64 println!("Dot Product of Vector2: {}", v2_a.dot(&v2_b));
65 println!("Dot Product of Vector3: {}", v3_a.dot(&v3_b));
66 println!("Dot Product of Vector4: {}", v4_a.dot(&v4_b));
67
68 println!("========================================");
69
70 // Example of cross product calculation
71 println!("Cross Product of Vector2: {:?}", v2_a.cross(&v2_a));
72 println!("Cross Product of Vector3: {:?}", v3_a.cross(&v3_b));
73 println!("Cross Product of Vector4: {:?}", v4_a.cross(&v4_b));
74
75 println!("========================================");
76
77 // Example of projection
78 println!("Projection onto of Vector2: {:?}", v2_a.project_onto(&v2_b));
79 println!("Projection onto of Vector3: {:?}", v3_a.project_onto(&v3_b));
80 println!("Projection onto of Vector4: {:?}", v4_a.project_onto(&v4_b));
81
82 println!("========================================");
83
84 // Example of Linear Interpolation
85 println!("Lerp for Vector2 (t = 0.5): {:?}", v2_a.lerp(&v2_b, 0.5));
86 println!("Lerp for Vector3 (t = 0.5): {:?}", v3_a.lerp(&v3_b, 0.5));
87 println!("Lerp for Vector4 (t = 0.5): {:?}", v4_a.lerp(&v4_b, 0.5));
88
89 println!("Lerp for Vector2 (t = 0.0): {:?}", v2_a.lerp(&v2_b, 0.0)); // Should return v2_a
90 println!("Lerp for Vector3 (t = 1.0): {:?}", v3_a.lerp(&v3_b, 1.0)); // Should return v3_b
91
92 println!("========================================");
93
94 // Example of Swizzling
95 println!("Swizzled Vector2 (yx): {:?}", v2_a.swizzle(1, 0)); // Swap x and y
96 println!("Swizzled Vector3 (yxz): {:?}", v3_a.swizzle(1, 0, 2)); // Swap x and y
97 println!("Swizzled Vector4 (wzyx): {:?}", v4_a.swizzle(3, 2, 1, 0)); // Reverse order
98
99 println!("========================================");
100
101 // Example of Angle Between Vectors
102 println!(
103 "Angle between Vector2 (radians): {}",
104 v2_a.angle_between(&v2_b)
105 );
106 println!(
107 "Angle between Vector3 (radians): {}",
108 v3_a.angle_between(&v3_b)
109 );
110 println!(
111 "Angle between Vector4 (radians): {}",
112 v4_a.angle_between(&v4_b)
113 );
114
115 println!("========================================");
116}Sourcepub fn swizzle(&self, x: usize, y: usize, z: usize, w: usize) -> Selfwhere
T: Copy,
pub fn swizzle(&self, x: usize, y: usize, z: usize, w: usize) -> Selfwhere
T: Copy,
Examples found in repository?
examples/vector_operations.rs (line 97)
3fn main() {
4 // Example usage
5 let v2_a = Vector2 { x: 1.0, y: 2.0 };
6 let v2_b = Vector2 { x: 3.0, y: 4.0 };
7 let v3_a = Vector3 {
8 x: 1.0,
9 y: 2.0,
10 z: 3.0,
11 };
12 let v3_b = Vector3 {
13 x: 4.0,
14 y: 5.0,
15 z: 6.0,
16 };
17 let v4_a = Vector4 {
18 x: 1.0,
19 y: 2.0,
20 z: 3.0,
21 w: 4.0,
22 };
23 let v4_b = Vector4 {
24 x: 5.0,
25 y: 6.0,
26 z: 7.0,
27 w: 8.0,
28 };
29
30 println!("========================================");
31
32 println!("v2_a + v2_b = {:?}", v2_a + v2_b);
33 println!("v3_a + v3_b = {:?}", v3_a + v3_b);
34 println!("v4_a + v4_b = {:?}", v4_a + v4_b);
35
36 println!("========================================");
37
38 println!("v2_a - v2_b = {:?}", v2_a - v2_b);
39 println!("v3_a - v3_b = {:?}", v3_a - v3_b);
40 println!("v4_a - v4_b = {:?}", v4_a - v4_b);
41
42 println!("========================================");
43
44 println!("v2_a * v2_b = {:?}", v2_a - v2_b);
45 println!("v3_a * v3_b = {:?}", v3_a - v3_b);
46 println!("v4_a * v4_b = {:?}", v4_a - v4_b);
47
48 println!("========================================");
49
50 println!("v2_a / v2_b = {:?}", v2_a / v2_b);
51 println!("v3_a / v3_b = {:?}", v3_a / v3_b);
52 println!("v4_a / v4_b = {:?}", v4_a / v4_b);
53
54 println!("========================================");
55
56 // Example of length calculation
57 println!("Length of Vector2: {}", v2_a.length());
58 println!("Length of Vector3: {}", v3_a.length());
59 println!("Length of Vector4: {}", v4_a.length());
60
61 println!("========================================");
62
63 // Example of dot product calculation
64 println!("Dot Product of Vector2: {}", v2_a.dot(&v2_b));
65 println!("Dot Product of Vector3: {}", v3_a.dot(&v3_b));
66 println!("Dot Product of Vector4: {}", v4_a.dot(&v4_b));
67
68 println!("========================================");
69
70 // Example of cross product calculation
71 println!("Cross Product of Vector2: {:?}", v2_a.cross(&v2_a));
72 println!("Cross Product of Vector3: {:?}", v3_a.cross(&v3_b));
73 println!("Cross Product of Vector4: {:?}", v4_a.cross(&v4_b));
74
75 println!("========================================");
76
77 // Example of projection
78 println!("Projection onto of Vector2: {:?}", v2_a.project_onto(&v2_b));
79 println!("Projection onto of Vector3: {:?}", v3_a.project_onto(&v3_b));
80 println!("Projection onto of Vector4: {:?}", v4_a.project_onto(&v4_b));
81
82 println!("========================================");
83
84 // Example of Linear Interpolation
85 println!("Lerp for Vector2 (t = 0.5): {:?}", v2_a.lerp(&v2_b, 0.5));
86 println!("Lerp for Vector3 (t = 0.5): {:?}", v3_a.lerp(&v3_b, 0.5));
87 println!("Lerp for Vector4 (t = 0.5): {:?}", v4_a.lerp(&v4_b, 0.5));
88
89 println!("Lerp for Vector2 (t = 0.0): {:?}", v2_a.lerp(&v2_b, 0.0)); // Should return v2_a
90 println!("Lerp for Vector3 (t = 1.0): {:?}", v3_a.lerp(&v3_b, 1.0)); // Should return v3_b
91
92 println!("========================================");
93
94 // Example of Swizzling
95 println!("Swizzled Vector2 (yx): {:?}", v2_a.swizzle(1, 0)); // Swap x and y
96 println!("Swizzled Vector3 (yxz): {:?}", v3_a.swizzle(1, 0, 2)); // Swap x and y
97 println!("Swizzled Vector4 (wzyx): {:?}", v4_a.swizzle(3, 2, 1, 0)); // Reverse order
98
99 println!("========================================");
100
101 // Example of Angle Between Vectors
102 println!(
103 "Angle between Vector2 (radians): {}",
104 v2_a.angle_between(&v2_b)
105 );
106 println!(
107 "Angle between Vector3 (radians): {}",
108 v3_a.angle_between(&v3_b)
109 );
110 println!(
111 "Angle between Vector4 (radians): {}",
112 v4_a.angle_between(&v4_b)
113 );
114
115 println!("========================================");
116}Trait Implementations§
impl<T: Copy> Copy for Vector4<T>
impl<T> StructuralPartialEq for Vector4<T>
Auto Trait Implementations§
impl<T> Freeze for Vector4<T>where
T: Freeze,
impl<T> RefUnwindSafe for Vector4<T>where
T: RefUnwindSafe,
impl<T> Send for Vector4<T>where
T: Send,
impl<T> Sync for Vector4<T>where
T: Sync,
impl<T> Unpin for Vector4<T>where
T: Unpin,
impl<T> UnsafeUnpin for Vector4<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for Vector4<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more