Rename Transform::mul_vec3 to transform_point and improve docs (#6132)

The docs ended up quite verbose :v

Also added a missing `#[inline]` to `GlobalTransform::mul_transform`.

I'd say this resolves #5500

# Migration Guide
`Transform::mul_vec3` has been renamed to `transform_point`.

Co-authored-by: devil-ira <justthecooldude@gmail.com>
This commit is contained in:
ira 2022-10-10 16:50:17 +00:00
parent 2cde4c73ed
commit 9423cb6a8d
4 changed files with 28 additions and 14 deletions

View File

@ -568,7 +568,9 @@ pub fn queue_sprites(
let positions = QUAD_VERTEX_POSITIONS.map(|quad_pos| { let positions = QUAD_VERTEX_POSITIONS.map(|quad_pos| {
extracted_sprite extracted_sprite
.transform .transform
.mul_vec3(((quad_pos - extracted_sprite.anchor) * quad_size).extend(0.)) .transform_point(
((quad_pos - extracted_sprite.anchor) * quad_size).extend(0.),
)
.into() .into()
}); });

View File

@ -142,14 +142,17 @@ impl GlobalTransform {
(self.0.matrix3 * extents).length() (self.0.matrix3 * extents).length()
} }
/// Returns a [`Vec3`] of this [`Transform`] applied to `value`. /// Transforms the given `point`, applying shear, scale, rotation and translation.
///
/// This moves `point` into the local space of this [`GlobalTransform`].
#[inline] #[inline]
pub fn mul_vec3(&self, v: Vec3) -> Vec3 { pub fn transform_point(&self, point: Vec3) -> Vec3 {
self.0.transform_point3(v) self.0.transform_point3(point)
} }
/// Multiplies `self` with `transform` component by component, returning the /// Multiplies `self` with `transform` component by component, returning the
/// resulting [`GlobalTransform`] /// resulting [`GlobalTransform`]
#[inline]
pub fn mul_transform(&self, transform: Transform) -> Self { pub fn mul_transform(&self, transform: Transform) -> Self {
Self(self.0 * transform.compute_affine()) Self(self.0 * transform.compute_affine())
} }
@ -202,6 +205,6 @@ impl Mul<Vec3> for GlobalTransform {
#[inline] #[inline]
fn mul(self, value: Vec3) -> Self::Output { fn mul(self, value: Vec3) -> Self::Output {
self.mul_vec3(value) self.transform_point(value)
} }
} }

View File

@ -328,7 +328,7 @@ impl Transform {
#[inline] #[inline]
#[must_use] #[must_use]
pub fn mul_transform(&self, transform: Transform) -> Self { pub fn mul_transform(&self, transform: Transform) -> Self {
let translation = self.mul_vec3(transform.translation); let translation = self.transform_point(transform.translation);
let rotation = self.rotation * transform.rotation; let rotation = self.rotation * transform.rotation;
let scale = self.scale * transform.scale; let scale = self.scale * transform.scale;
Transform { Transform {
@ -338,13 +338,22 @@ impl Transform {
} }
} }
/// Returns a [`Vec3`] of this [`Transform`] applied to `value`. /// Transforms the given `point`, applying scale, rotation and translation.
///
/// If this [`Transform`] has a parent, this will transform a `point` that is
/// relative to the parent's [`Transform`] into one relative to this [`Transform`].
///
/// If this [`Transform`] does not have a parent, this will transform a `point`
/// that is in global space into one relative to this [`Transform`].
///
/// If you want to transform a `point` in global space to the local space of this [`Transform`],
/// consider using [`GlobalTransform::transform_point()`] instead.
#[inline] #[inline]
pub fn mul_vec3(&self, mut value: Vec3) -> Vec3 { pub fn transform_point(&self, mut point: Vec3) -> Vec3 {
value = self.scale * value; point = self.scale * point;
value = self.rotation * value; point = self.rotation * point;
value += self.translation; point += self.translation;
value point
} }
/// Changes the `scale` of this [`Transform`], multiplying the current `scale` by /// Changes the `scale` of this [`Transform`], multiplying the current `scale` by
@ -381,6 +390,6 @@ impl Mul<Vec3> for Transform {
type Output = Vec3; type Output = Vec3;
fn mul(self, value: Vec3) -> Self::Output { fn mul(self, value: Vec3) -> Self::Output {
self.mul_vec3(value) self.transform_point(value)
} }
} }

View File

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