Skip to content

Commit efd2ee0

Browse files
tim-blackbirdPietrek14
authored andcommitted
Rename Transform::mul_vec3 to transform_point and improve docs (bevyengine#6132)
The docs ended up quite verbose :v Also added a missing `#[inline]` to `GlobalTransform::mul_transform`. I'd say this resolves bevyengine#5500 # Migration Guide `Transform::mul_vec3` has been renamed to `transform_point`. Co-authored-by: devil-ira <justthecooldude@gmail.com>
1 parent 07c52b9 commit efd2ee0

File tree

4 files changed

+28
-14
lines changed

4 files changed

+28
-14
lines changed

crates/bevy_sprite/src/render/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,9 @@ pub fn queue_sprites(
568568
let positions = QUAD_VERTEX_POSITIONS.map(|quad_pos| {
569569
extracted_sprite
570570
.transform
571-
.mul_vec3(((quad_pos - extracted_sprite.anchor) * quad_size).extend(0.))
571+
.transform_point(
572+
((quad_pos - extracted_sprite.anchor) * quad_size).extend(0.),
573+
)
572574
.into()
573575
});
574576

crates/bevy_transform/src/components/global_transform.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,17 @@ impl GlobalTransform {
142142
(self.0.matrix3 * extents).length()
143143
}
144144

145-
/// Returns a [`Vec3`] of this [`Transform`] applied to `value`.
145+
/// Transforms the given `point`, applying shear, scale, rotation and translation.
146+
///
147+
/// This moves `point` into the local space of this [`GlobalTransform`].
146148
#[inline]
147-
pub fn mul_vec3(&self, v: Vec3) -> Vec3 {
148-
self.0.transform_point3(v)
149+
pub fn transform_point(&self, point: Vec3) -> Vec3 {
150+
self.0.transform_point3(point)
149151
}
150152

151153
/// Multiplies `self` with `transform` component by component, returning the
152154
/// resulting [`GlobalTransform`]
155+
#[inline]
153156
pub fn mul_transform(&self, transform: Transform) -> Self {
154157
Self(self.0 * transform.compute_affine())
155158
}
@@ -202,6 +205,6 @@ impl Mul<Vec3> for GlobalTransform {
202205

203206
#[inline]
204207
fn mul(self, value: Vec3) -> Self::Output {
205-
self.mul_vec3(value)
208+
self.transform_point(value)
206209
}
207210
}

crates/bevy_transform/src/components/transform.rs

+17-8
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ impl Transform {
328328
#[inline]
329329
#[must_use]
330330
pub fn mul_transform(&self, transform: Transform) -> Self {
331-
let translation = self.mul_vec3(transform.translation);
331+
let translation = self.transform_point(transform.translation);
332332
let rotation = self.rotation * transform.rotation;
333333
let scale = self.scale * transform.scale;
334334
Transform {
@@ -338,13 +338,22 @@ impl Transform {
338338
}
339339
}
340340

341-
/// Returns a [`Vec3`] of this [`Transform`] applied to `value`.
341+
/// Transforms the given `point`, applying scale, rotation and translation.
342+
///
343+
/// If this [`Transform`] has a parent, this will transform a `point` that is
344+
/// relative to the parent's [`Transform`] into one relative to this [`Transform`].
345+
///
346+
/// If this [`Transform`] does not have a parent, this will transform a `point`
347+
/// that is in global space into one relative to this [`Transform`].
348+
///
349+
/// If you want to transform a `point` in global space to the local space of this [`Transform`],
350+
/// consider using [`GlobalTransform::transform_point()`] instead.
342351
#[inline]
343-
pub fn mul_vec3(&self, mut value: Vec3) -> Vec3 {
344-
value = self.scale * value;
345-
value = self.rotation * value;
346-
value += self.translation;
347-
value
352+
pub fn transform_point(&self, mut point: Vec3) -> Vec3 {
353+
point = self.scale * point;
354+
point = self.rotation * point;
355+
point += self.translation;
356+
point
348357
}
349358

350359
/// Changes the `scale` of this [`Transform`], multiplying the current `scale` by
@@ -381,6 +390,6 @@ impl Mul<Vec3> for Transform {
381390
type Output = Vec3;
382391

383392
fn mul(self, value: Vec3) -> Self::Output {
384-
self.mul_vec3(value)
393+
self.transform_point(value)
385394
}
386395
}

examples/tools/scene_viewer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ fn setup_scene_after_load(
226226
// correct bounds. However, it could very well be rotated and so we first convert to
227227
// a Sphere, and then back to an Aabb to find the conservative min and max points.
228228
let sphere = Sphere {
229-
center: Vec3A::from(transform.mul_vec3(Vec3::from(aabb.center))),
229+
center: Vec3A::from(transform.transform_point(Vec3::from(aabb.center))),
230230
radius: transform.radius_vec3a(aabb.half_extents),
231231
};
232232
let aabb = Aabb::from(sphere);

0 commit comments

Comments
 (0)