Skip to content

Commit

Permalink
Remove vector to_2d() + to_3d() methods
Browse files Browse the repository at this point in the history
Semantics aren't obvious -- while Z component is the mathematically natural extension,
in Godot Y would be more typical (being the up/down axis in 3D). There's also the topic
of +/- signs... Maybe it can be re-added once there are clearer use cases.

Alternatively, a more flexible swizzle! macro supporting 0 when extending is possible.
  • Loading branch information
Bromeon committed Nov 5, 2024
1 parent 4c283d4 commit 3aefb03
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 22 deletions.
4 changes: 2 additions & 2 deletions godot-core/src/builtin/vectors/vector2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use sys::{ffi_methods, GodotFfi};

use crate::builtin::math::{FloatExt, GlamConv, GlamType};
use crate::builtin::vectors::Vector2Axis;
use crate::builtin::{inner, real, RAffine2, RVec2, Vector2i, Vector3};
use crate::builtin::{inner, real, RAffine2, RVec2, Vector2i};

use std::fmt;

Expand Down Expand Up @@ -44,7 +44,7 @@ use std::fmt;
/// | 3D | [`Vector3`][crate::builtin::Vector3] | [`Vector3i`][crate::builtin::Vector3i] |
/// | 4D | [`Vector4`][crate::builtin::Vector4] | [`Vector4i`][crate::builtin::Vector4i] |
///
/// <br>You can convert to 3D vectors using [`to_3d(z)`][Self::to_3d], and to `Vector2i` using [`cast_int()`][Self::cast_int].
/// <br>You can convert to `Vector2i` using [`cast_int()`][Self::cast_int].
///
/// # Godot docs
///
Expand Down
4 changes: 2 additions & 2 deletions godot-core/src/builtin/vectors/vector2i.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::cmp::Ordering;
use sys::{ffi_methods, GodotFfi};

use crate::builtin::math::{GlamConv, GlamType};
use crate::builtin::{inner, real, RVec2, Vector2, Vector2Axis, Vector3i};
use crate::builtin::{inner, real, RVec2, Vector2, Vector2Axis};

use std::fmt;

Expand Down Expand Up @@ -42,7 +42,7 @@ use std::fmt;
/// | 3D | [`Vector3`][crate::builtin::Vector3] | [`Vector3i`][crate::builtin::Vector3i] |
/// | 4D | [`Vector4`][crate::builtin::Vector4] | [`Vector4i`][crate::builtin::Vector4i] |
///
/// <br>You can convert to 3D vectors using [`to_3d(z)`][Self::to_3d], and to `Vector2` using [`cast_float()`][Self::cast_float].
/// <br>You can convert to `Vector2` using [`cast_float()`][Self::cast_float].
///
/// # Godot docs
///
Expand Down
2 changes: 1 addition & 1 deletion godot-core/src/builtin/vectors/vector3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ use std::fmt;
/// | 3D | **`Vector3`** | [`Vector3i`][crate::builtin::Vector3i] |
/// | 4D | [`Vector4`][crate::builtin::Vector4] | [`Vector4i`][crate::builtin::Vector4i] |
///
/// <br>You can convert to 2D vectors using [`to_2d()`][Self::to_2d], and to `Vector3i` using [`cast_int()`][Self::cast_int].
/// <br>You can convert to `Vector3i` using [`cast_int()`][Self::cast_int].
///
/// # Godot docs
///
Expand Down
4 changes: 2 additions & 2 deletions godot-core/src/builtin/vectors/vector3i.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use godot_ffi as sys;
use sys::{ffi_methods, GodotFfi};

use crate::builtin::math::{GlamConv, GlamType};
use crate::builtin::{inner, real, RVec3, Vector2i, Vector3, Vector3Axis};
use crate::builtin::{inner, real, RVec3, Vector3, Vector3Axis};

/// Vector used for 3D math using integer coordinates.
///
Expand Down Expand Up @@ -42,7 +42,7 @@ use crate::builtin::{inner, real, RVec3, Vector2i, Vector3, Vector3Axis};
/// | 3D | [`Vector3`][crate::builtin::Vector3] | **`Vector3i`** |
/// | 4D | [`Vector4`][crate::builtin::Vector4] | [`Vector4i`][crate::builtin::Vector4i] |
///
/// <br>You can convert to 2D vectors using [`to_2d()`][Self::to_2d], and to `Vector3` using [`cast_float()`][Self::cast_float].
/// <br>You can convert to `Vector3` using [`cast_float()`][Self::cast_float].
///
/// # Godot docs
///
Expand Down
15 changes: 0 additions & 15 deletions godot-core/src/builtin/vectors/vector_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -791,12 +791,6 @@ macro_rules! impl_vector2x_fns {
/// # 2D functions
/// The following methods are only available on 2D vectors (for both float and int).
impl $Vector {
/// Increases dimension to 3D, accepting a new value for the Z component.
#[inline]
pub fn to_3d(self, z: $Scalar) -> $Vector3D {
<$Vector3D>::new(self.x, self.y, z)
}

/// Returns the aspect ratio of this vector, the ratio of [`Self::x`] to [`Self::y`].
#[inline]
pub fn aspect(self) -> real {
Expand Down Expand Up @@ -853,15 +847,6 @@ macro_rules! impl_vector3x_fns {
/// # 3D functions
/// The following methods are only available on 3D vectors (for both float and int).
impl $Vector {
/// Reduces dimension to 2D, discarding the Z component.
///
/// See also [`swizzle!`][crate::builtin::swizzle] for a more general way to extract components.
/// `self.to_2d()` is equivalent to `swizzle!(self => x, y)`.
#[inline]
pub fn to_2d(self) -> $Vector2D {
<$Vector2D>::new(self.x, self.y)
}

/// Returns the axis of the vector's highest value. See [`Vector3Axis`] enum. If all components are equal, this method returns [`None`].
///
/// To mimic Godot's behavior, unwrap this function's result with `unwrap_or(Vector3Axis::X)`.
Expand Down

0 comments on commit 3aefb03

Please sign in to comment.