1#[repr(C)]
3#[derive(Default, Debug, Clone, Copy, PartialEq, PartialOrd)]
4#[cfg_attr(feature = "bevy", derive(bevy_ecs::prelude::Component))]
5#[cfg_attr(feature = "bevy_reflect", derive(bevy_reflect::Reflect))]
6pub struct Vec2 {
7 pub x: f32,
8 pub y: f32,
9}
10
11impl Vec2 {
12 pub const ZERO: Self = Self::new(0.0, 0.0);
13
14 pub const fn new(x: f32, y: f32) -> Self {
15 Self { x, y }
16 }
17}
18
19#[repr(C)]
21#[derive(Default, Debug, Clone, Copy, PartialEq, PartialOrd)]
22#[cfg_attr(feature = "bevy", derive(bevy_ecs::prelude::Component))]
23#[cfg_attr(feature = "bevy_reflect", derive(bevy_reflect::Reflect))]
24pub struct Vec3 {
25 pub x: f32,
26 pub y: f32,
27 pub z: f32,
28}
29
30impl Vec3 {
31 pub const ZERO: Self = Self::new(0.0, 0.0, 0.0);
32
33 pub const fn new(x: f32, y: f32, z: f32) -> Self {
34 Self { x, y, z }
35 }
36}
37
38impl From<[f32; 2]> for Vec2 {
39 fn from(value: [f32; 2]) -> Self {
40 Self::new(value[0], value[1])
41 }
42}
43
44impl From<[f32; 3]> for Vec3 {
45 fn from(value: [f32; 3]) -> Self {
46 Self::new(value[0], value[1], value[2])
47 }
48}
49
50impl From<(f32, f32)> for Vec2 {
51 fn from(value: (f32, f32)) -> Self {
52 Self::new(value.0, value.1)
53 }
54}
55
56impl From<(f32, f32, f32)> for Vec3 {
57 fn from(value: (f32, f32, f32)) -> Self {
58 Self::new(value.0, value.1, value.2)
59 }
60}
61
62impl From<Vec2> for [f32; 2] {
63 fn from(value: Vec2) -> Self {
64 [value.x, value.y]
65 }
66}
67
68impl From<Vec3> for [f32; 3] {
69 fn from(value: Vec3) -> Self {
70 [value.x, value.y, value.z]
71 }
72}
73
74impl From<Vec2> for (f32, f32) {
75 fn from(value: Vec2) -> Self {
76 (value.x, value.y)
77 }
78}
79
80impl From<Vec3> for (f32, f32, f32) {
81 fn from(value: Vec3) -> Self {
82 (value.x, value.y, value.z)
83 }
84}
85
86#[cfg(feature = "glam-29")]
87impl From<glam::Vec2> for Vec2 {
88 fn from(value: glam::Vec2) -> Self {
89 Self::new(value.x, value.y)
90 }
91}
92
93#[cfg(feature = "glam-29")]
94impl From<glam::Vec3> for Vec3 {
95 fn from(value: glam::Vec3) -> Self {
96 Self::new(value.x, value.y, value.z)
97 }
98}
99
100#[cfg(feature = "glam-29")]
101impl From<Vec2> for glam::Vec2 {
102 fn from(value: Vec2) -> Self {
103 Self::new(value.x, value.y)
104 }
105}
106
107#[cfg(feature = "glam-29")]
108impl From<Vec3> for glam::Vec3 {
109 fn from(value: Vec3) -> Self {
110 Self::new(value.x, value.y, value.z)
111 }
112}