Skip to content

Commit e7fa8a8

Browse files
committed
Apply rustfmt and minor review feedback
1 parent 66a487a commit e7fa8a8

File tree

7 files changed

+153
-138
lines changed

7 files changed

+153
-138
lines changed

godot-core/src/builtin/vector2.rs

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use crate::builtin::Vector2i;
1919
/// It uses floating-point coordinates of 32-bit precision, unlike the engine's `float` type which
2020
/// is always 64-bit. The engine can be compiled with the option `precision=double` to use 64-bit
2121
/// vectors, but this is not yet supported in the `gdextension` crate.
22-
///
22+
///
2323
/// See [`Vector2i`] for its integer counterpart.
2424
#[derive(Debug, Default, Clone, Copy, PartialEq)]
2525
#[repr(C)]
@@ -30,48 +30,46 @@ pub struct Vector2 {
3030
pub y: f32,
3131
}
3232

33-
impl_vector_operators!(Vector2, f32, (x, y));
34-
impl_vector_index!(Vector2, f32, (x, y), Vector2Axis, (X, Y));
35-
impl_common_vector_fns!(Vector2, f32);
36-
impl_float_vector_fns!(Vector2, f32);
37-
3833
impl Vector2 {
39-
/// Constructs a new `Vector2` from the given `x` and `y`.
40-
pub const fn new(x: f32, y: f32) -> Self {
41-
Self { x, y }
42-
}
43-
44-
/// Constructs a new `Vector2` with all components set to `v`.
45-
pub const fn splat(v: f32) -> Self {
46-
Self { x: v, y: v }
47-
}
48-
49-
/// Constructs a new `Vector2` from a [`Vector2i`].
50-
pub const fn from_vector2i(v: Vector2i) -> Self {
51-
Self { x: v.x as f32, y: v.y as f32 }
52-
}
53-
54-
/// Zero vector, a vector with all components set to `0.0`.
34+
/// Vector with all components set to `0.0`.
5535
pub const ZERO: Self = Self::splat(0.0);
5636

57-
/// One vector, a vector with all components set to `1.0`.
37+
/// Vector with all components set to `1.0`.
5838
pub const ONE: Self = Self::splat(1.0);
5939

60-
/// Infinity vector, a vector with all components set to `INFIINTY`.
40+
/// Vector with all components set to `f32::INFINITY`.
6141
pub const INF: Self = Self::splat(f32::INFINITY);
6242

63-
/// Left unit vector. Represents the direction of left.
43+
/// Unit vector in -X direction (right in 2D coordinate system).
6444
pub const LEFT: Self = Self::new(-1.0, 0.0);
6545

66-
/// Right unit vector. Represents the direction of right.
46+
/// Unit vector in +X direction (right in 2D coordinate system).
6747
pub const RIGHT: Self = Self::new(1.0, 0.0);
6848

69-
/// Up unit vector. Y is down in 2D, so this vector points -Y.
49+
/// Unit vector in -Y direction (up in 2D coordinate system).
7050
pub const UP: Self = Self::new(0.0, -1.0);
7151

72-
/// Down unit vector. Y is down in 2D, so this vector points +Y.
52+
/// Unit vector in +Y direction (down in 2D coordinate system).
7353
pub const DOWN: Self = Self::new(0.0, 1.0);
7454

55+
/// Constructs a new `Vector2` from the given `x` and `y`.
56+
pub const fn new(x: f32, y: f32) -> Self {
57+
Self { x, y }
58+
}
59+
60+
/// Constructs a new `Vector2` with both components set to `v`.
61+
pub const fn splat(v: f32) -> Self {
62+
Self::new(v, v)
63+
}
64+
65+
/// Constructs a new `Vector2` from a [`Vector2i`].
66+
pub const fn from_vector2i(v: Vector2i) -> Self {
67+
Self {
68+
x: v.x as f32,
69+
y: v.y as f32,
70+
}
71+
}
72+
7573
/// Returns the result of rotating this vector by `angle` (in radians).
7674
pub fn rotated(self, angle: f32) -> Self {
7775
Self::from_glam(glam::Affine2::from_angle(angle).transform_vector2(self.to_glam()))
@@ -88,13 +86,18 @@ impl Vector2 {
8886
}
8987
}
9088

91-
/// Formats this vector in the same way the Godot engine would.
89+
/// Formats the vector like Godot: `(x, y)`.
9290
impl fmt::Display for Vector2 {
9391
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9492
write!(f, "({}, {})", self.x, self.y)
9593
}
9694
}
9795

96+
impl_common_vector_fns!(Vector2, f32);
97+
impl_float_vector_fns!(Vector2, f32);
98+
impl_vector_operators!(Vector2, f32, (x, y));
99+
impl_vector_index!(Vector2, f32, (x, y), Vector2Axis, (X, Y));
100+
98101
impl GodotFfi for Vector2 {
99102
ffi_methods! { type sys::GDExtensionTypePtr = *mut Self; .. }
100103
}

godot-core/src/builtin/vector2i.rs

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::builtin::Vector2;
1515
///
1616
/// 2-element structure that can be used to represent positions in 2D space or any other pair of
1717
/// numeric values.
18-
///
18+
///
1919
/// It uses integer coordinates and is therefore preferable to [`Vector2`] when exact precision is
2020
/// required. Note that the values are limited to 32 bits, and unlike [`Vector2`] this cannot be
2121
/// configured with an engine build option. Use `i64` or [`PackedInt64Array`] if 64-bit values are
@@ -29,45 +29,43 @@ pub struct Vector2i {
2929
pub y: i32,
3030
}
3131

32-
impl_vector_operators!(Vector2i, i32, (x, y));
33-
impl_vector_index!(Vector2i, i32, (x, y), Vector2iAxis, (X, Y));
34-
impl_common_vector_fns!(Vector2i, i32);
35-
3632
impl Vector2i {
37-
/// Constructs a new `Vector2i` from the given `x` and `y`.
38-
pub const fn new(x: i32, y: i32) -> Self {
39-
Self { x, y }
40-
}
41-
42-
/// Constructs a new `Vector2i` with all components set to `v`.
43-
pub const fn splat(v: i32) -> Self {
44-
Self { x: v, y: v }
45-
}
46-
47-
/// Constructs a new `Vector2i` from a [`Vector2`]. The floating point coordinates will be
48-
/// truncated.
49-
pub const fn from_vector2(v: Vector2) -> Self {
50-
Self { x: v.x as i32, y: v.y as i32 }
51-
}
52-
53-
/// Zero vector, a vector with all components set to `0`.
33+
/// Vector with all components set to `0`.
5434
pub const ZERO: Self = Self::splat(0);
5535

56-
/// One vector, a vector with all components set to `1`.
36+
/// Vector with all components set to `1`.
5737
pub const ONE: Self = Self::splat(1);
5838

59-
/// Left unit vector. Represents the direction of left.
39+
/// Unit vector in -X direction (right in 2D coordinate system).
6040
pub const LEFT: Self = Self::new(-1, 0);
6141

62-
/// Right unit vector. Represents the direction of right.
42+
/// Unit vector in +X direction (right in 2D coordinate system).
6343
pub const RIGHT: Self = Self::new(1, 0);
6444

65-
/// Up unit vector. Y is down in 2D, so this vector points -Y.
45+
/// Unit vector in -Y direction (up in 2D coordinate system).
6646
pub const UP: Self = Self::new(0, -1);
6747

68-
/// Down unit vector. Y is down in 2D, so this vector points +Y.
48+
/// Unit vector in +Y direction (down in 2D coordinate system).
6949
pub const DOWN: Self = Self::new(0, 1);
7050

51+
/// Constructs a new `Vector2i` from the given `x` and `y`.
52+
pub const fn new(x: i32, y: i32) -> Self {
53+
Self { x, y }
54+
}
55+
56+
/// Constructs a new `Vector2i` with both components set to `v`.
57+
pub const fn splat(v: i32) -> Self {
58+
Self::new(v, v)
59+
}
60+
61+
/// Constructs a new `Vector2i` from a [`Vector2`]. The floating point coordinates will be truncated.
62+
pub const fn from_vector2(v: Vector2) -> Self {
63+
Self {
64+
x: v.x as i32,
65+
y: v.y as i32,
66+
}
67+
}
68+
7169
/// Converts the corresponding `glam` type to `Self`.
7270
fn from_glam(v: glam::IVec2) -> Self {
7371
Self::new(v.x, v.y)
@@ -79,13 +77,17 @@ impl Vector2i {
7977
}
8078
}
8179

82-
/// Formats this vector in the same way the Godot engine would.
80+
/// Formats the vector like Godot: `(x, y)`.
8381
impl fmt::Display for Vector2i {
8482
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
8583
write!(f, "({}, {})", self.x, self.y)
8684
}
8785
}
8886

87+
impl_common_vector_fns!(Vector2i, i32);
88+
impl_vector_operators!(Vector2i, i32, (x, y));
89+
impl_vector_index!(Vector2i, i32, (x, y), Vector2iAxis, (X, Y));
90+
8991
impl GodotFfi for Vector2i {
9092
ffi_methods! { type sys::GDExtensionTypePtr = *mut Self; .. }
9193
}

godot-core/src/builtin/vector3.rs

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ use crate::builtin::Vector3i;
1313

1414
/// Vector used for 3D math using floating point coordinates.
1515
///
16-
/// 2-element structure that can be used to represent positions in 2D space or any other pair of
16+
/// 3-element structure that can be used to represent positions in 2D space or any other triple of
1717
/// numeric values.
1818
///
1919
/// It uses floating-point coordinates of 32-bit precision, unlike the engine's `float` type which
2020
/// is always 64-bit. The engine can be compiled with the option `precision=double` to use 64-bit
2121
/// vectors, but this is not yet supported in the `gdextension` crate.
22-
///
22+
///
2323
/// See [`Vector3i`] for its integer counterpart.
2424
#[derive(Debug, Default, Clone, Copy, PartialEq)]
2525
#[repr(C)]
@@ -32,54 +32,50 @@ pub struct Vector3 {
3232
pub z: f32,
3333
}
3434

35-
impl_vector_operators!(Vector3, f32, (x, y, z));
36-
impl_vector_index!(Vector3, f32, (x, y, z), Vector3Axis, (X, Y, Z));
37-
impl_common_vector_fns!(Vector3, f32);
38-
impl_float_vector_fns!(Vector3, f32);
39-
4035
impl Vector3 {
41-
/// Returns a `Vector3` with the given components.
42-
pub const fn new(x: f32, y: f32, z: f32) -> Self {
43-
Self { x, y, z }
44-
}
45-
46-
/// Returns a new `Vector3` with all components set to `v`.
47-
pub const fn splat(v: f32) -> Self {
48-
Self { x: v, y: v, z: v }
49-
}
50-
51-
/// Constructs a new `Vector3` from a [`Vector3i`].
52-
pub const fn from_vector3i(v: Vector3i) -> Self {
53-
Self { x: v.x as f32, y: v.y as f32, z: v.z as f32 }
54-
}
55-
56-
/// Zero vector, a vector with all components set to `0.0`.
36+
/// Vector with all components set to `0.0`.
5737
pub const ZERO: Self = Self::splat(0.0);
5838

59-
/// One vector, a vector with all components set to `1.0`.
39+
/// Vector with all components set to `1.0`.
6040
pub const ONE: Self = Self::splat(1.0);
6141

62-
/// Infinity vector, a vector with all components set to `INFIINTY`.
63-
pub const INF: Self = Self::splat(f32::INFINITY);
64-
65-
/// Left unit vector. Represents the local direction of left, and the global direction of west.
42+
/// Unit vector in -X direction. Can be interpreted as left in an untransformed 3D world.
6643
pub const LEFT: Self = Self::new(-1.0, 0.0, 0.0);
6744

68-
/// Right unit vector. Represents the local direction of right, and the global direction of east.
45+
/// Unit vector in +X direction. Can be interpreted as right in an untransformed 3D world.
6946
pub const RIGHT: Self = Self::new(1.0, 0.0, 0.0);
7047

71-
/// Up unit vector.
48+
/// Unit vector in -Y direction. Typically interpreted as down in a 3D world.
7249
pub const UP: Self = Self::new(0.0, -1.0, 0.0);
7350

74-
/// Down unit vector.
51+
/// Unit vector in +Y direction. Typically interpreted as up in a 3D world.
7552
pub const DOWN: Self = Self::new(0.0, 1.0, 0.0);
7653

77-
/// Forward unit vector. Represents the local direction of forward, and the global direction of north.
54+
/// Unit vector in -Z direction. Can be interpreted as "into the screen" in an untransformed 3D world.
7855
pub const FORWARD: Self = Self::new(0.0, 0.0, -1.0);
7956

80-
/// Back unit vector. Represents the local direction of back, and the global direction of south.
57+
/// Unit vector in +Z direction. Can be interpreted as "out of the screen" in an untransformed 3D world.
8158
pub const BACK: Self = Self::new(0.0, 0.0, 1.0);
8259

60+
/// Returns a `Vector3` with the given components.
61+
pub const fn new(x: f32, y: f32, z: f32) -> Self {
62+
Self { x, y, z }
63+
}
64+
65+
/// Returns a new `Vector3` with all components set to `v`.
66+
pub const fn splat(v: f32) -> Self {
67+
Self::new(v, v, v)
68+
}
69+
70+
/// Constructs a new `Vector3` from a [`Vector3i`].
71+
pub const fn from_vector3i(v: Vector3i) -> Self {
72+
Self {
73+
x: v.x as f32,
74+
y: v.y as f32,
75+
z: v.z as f32,
76+
}
77+
}
78+
8379
/// Converts the corresponding `glam` type to `Self`.
8480
fn from_glam(v: glam::Vec3) -> Self {
8581
Self::new(v.x, v.y, v.z)
@@ -91,13 +87,18 @@ impl Vector3 {
9187
}
9288
}
9389

94-
/// Formats this vector in the same way the Godot engine would.
90+
/// Formats the vector like Godot: `(x, y, z)`.
9591
impl fmt::Display for Vector3 {
9692
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9793
write!(f, "({}, {}, {})", self.x, self.y, self.z)
9894
}
9995
}
10096

97+
impl_common_vector_fns!(Vector3, f32);
98+
impl_float_vector_fns!(Vector3, f32);
99+
impl_vector_operators!(Vector3, f32, (x, y, z));
100+
impl_vector_index!(Vector3, f32, (x, y, z), Vector3Axis, (X, Y, Z));
101+
101102
impl GodotFfi for Vector3 {
102103
ffi_methods! { type sys::GDExtensionTypePtr = *mut Self; .. }
103104
}

0 commit comments

Comments
 (0)