Skip to content

Commit 22b65b7

Browse files
authored
Add Isometry2d::from_xy and Isometry3d::from_xyz (#14312)
# Objective Creating isometry types with just a translation is a bit more verbose than it needs to be for cases where you don't have an existing vector to pass in. ```rust let iso = Isometry3d::from_translation(Vec3::new(2.0, 1.0, -1.0)); ``` This could be made more ergonomic with a method similar to `Dir2::from_xy`, `Dir3::from_xyz`, and `Transform::from_xyz`: ```rust let iso = Isometry3d::from_xyz(2.0, 1.0, -1.0); ``` ## Solution Add `Isometry2d::from_xy` and `Isometry3d::from_xyz`.
1 parent 3b23aa0 commit 22b65b7

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

crates/bevy_math/src/isometry.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,15 @@ impl Isometry2d {
7171
}
7272
}
7373

74+
/// Create a two-dimensional isometry from a translation with the given `x` and `y` components.
75+
#[inline]
76+
pub fn from_xy(x: f32, y: f32) -> Self {
77+
Isometry2d {
78+
rotation: Rot2::IDENTITY,
79+
translation: Vec2::new(x, y),
80+
}
81+
}
82+
7483
/// The inverse isometry that undoes this one.
7584
#[inline]
7685
pub fn inverse(&self) -> Self {
@@ -229,6 +238,15 @@ impl Isometry3d {
229238
}
230239
}
231240

241+
/// Create a three-dimensional isometry from a translation with the given `x`, `y`, and `z` components.
242+
#[inline]
243+
pub fn from_xyz(x: f32, y: f32, z: f32) -> Self {
244+
Isometry3d {
245+
rotation: Quat::IDENTITY,
246+
translation: Vec3A::new(x, y, z),
247+
}
248+
}
249+
232250
/// The inverse isometry that undoes this one.
233251
#[inline]
234252
pub fn inverse(&self) -> Self {

0 commit comments

Comments
 (0)