Transform

Struct Transform 

Source
pub struct Transform {
    pub local_transform: Transform3D<f32, UnknownUnit, UnknownUnit>,
    pub world_transform: Transform3D<f32, UnknownUnit, UnknownUnit>,
    pub origin: (f32, f32),
    pub position_relative_to_parent: (f32, f32),
    pub parent_container_camera_perspective: Option<Transform3D<f32, UnknownUnit, UnknownUnit>>,
}

Fields§

§local_transform: Transform3D<f32, UnknownUnit, UnknownUnit>

Local transform relative to parent

§world_transform: Transform3D<f32, UnknownUnit, UnknownUnit>

Fully composed world transform including all parent transforms (may include perspective)

§origin: (f32, f32)

Origin relative to the shape (pivot)

§position_relative_to_parent: (f32, f32)

Layout position relative to the parent

§parent_container_camera_perspective: Option<Transform3D<f32, UnknownUnit, UnknownUnit>>

Optional perspective matrix of the current element’s parent

Implementations§

Source§

impl Transform

Source

pub fn new() -> Self

Source

pub fn compose(&mut self, parent: &Transform)

Composes local transform with parent’s world transform, and stores the result as this transform’s world transform. Prent should be composed before calling this method. You can set up an empty transform for the root element.

Source

pub fn compose_2(self, parent: &Transform) -> Self

Source

pub fn set_origin(&mut self, ox: f32, oy: f32)

Source

pub fn with_origin(self, ox: f32, oy: f32) -> Self

Source

pub fn set_position_relative_to_parent(&mut self, x: f32, y: f32)

Source

pub fn with_position_relative_to_parent(self, x: f32, y: f32) -> Self

Source

pub fn set_parent_container_perspective( &mut self, distance: f32, origin_x: f32, origin_y: f32, )

Sets the parent’s perspective parameters. In CSS this would be done on the parent element, but here we set it on the child for convenience.

Source

pub fn with_parent_container_perspective( self, distance: f32, origin_x: f32, origin_y: f32, ) -> Self

Sets the parent’s perspective parameters. In CSS this would be done on the parent element, but here we set it on the child for convenience.

Source

pub fn translate(&mut self, tx: f32, ty: f32)

Source

pub fn then_translate(self, tx: f32, ty: f32) -> Self

Source

pub fn translate_3d(&mut self, tx: f32, ty: f32, tz: f32)

Source

pub fn then_translate_3d(self, tx: f32, ty: f32, tz: f32) -> Self

Source

pub fn translate_x(&mut self, tx: f32)

Source

pub fn then_translate_x(self, tx: f32) -> Self

Source

pub fn translate_y(&mut self, ty: f32)

Source

pub fn then_translate_y(self, ty: f32) -> Self

Source

pub fn translate_z(&mut self, tz: f32)

Source

pub fn then_translate_z(self, tz: f32) -> Self

Source

pub fn translate_2d(&mut self, tx: f32, ty: f32)

Source

pub fn then_translate_2d(self, tx: f32, ty: f32) -> Self

Source

pub fn rotate_x_deg(degrees: f32) -> Self

Source

pub fn rotate_x_rad(radians: f32) -> Self

Source

pub fn then_rotate_x_deg(self, degrees: f32) -> Self

Source

pub fn then_rotate_x_rad(self, radians: f32) -> Self

Source

pub fn rotate_y_deg(degrees: f32) -> Self

Source

pub fn rotate_y_rad(radians: f32) -> Self

Source

pub fn then_rotate_y_deg(self, degrees: f32) -> Self

Source

pub fn then_rotate_y_rad(self, radians: f32) -> Self

Source

pub fn rotate_z_deg(degrees: f32) -> Self

Source

pub fn rotate_z_rad(radians: f32) -> Self

Source

pub fn then_rotate_z_deg(self, degrees: f32) -> Self

Source

pub fn then_rotate_z_rad(self, radians: f32) -> Self

Source

pub fn rotate(axis_x: f32, axis_y: f32, axis_z: f32, angle: Angle<f32>) -> Self

Source

pub fn then_rotate( self, axis_x: f32, axis_y: f32, axis_z: f32, angle: Angle<f32>, ) -> Self

Source

pub fn scale(sx: f32, sy: f32) -> Self

Source

pub fn then_scale(self, sx: f32, sy: f32) -> Self

Source

pub fn scale_3d(sx: f32, sy: f32, sz: f32) -> Self

Source

pub fn then_scale_3d(self, sx: f32, sy: f32, sz: f32) -> Self

Source

pub fn transform_local_point2d_to_world(&self, x: f32, y: f32) -> (f32, f32)

Transforms a local 2D point (x, y) to world coordinates using the composed world transform. Properly handles perspective transforms with homogeneous coordinates.

Source

pub fn transform_world_point_to_local( &self, x: f32, y: f32, z: f32, ) -> Option<(f32, f32)>

Transform a point from world space to local space (inverse transform). Returns None if the transform is not invertible. Useful for hit testing - convert mouse position to shape-local coordinates. Properly handles perspective transforms with homogeneous coordinates.

For perspective transforms, you need to provide the Z coordinate in world space. For hit testing 2D shapes at z=0 in local space, first transform local (0,0,0) to world to get the Z, then use that Z when inverse transforming mouse coordinates.

Source

pub fn project_screen_point_to_local_2d( &self, screen_pos: (f32, f32), ) -> Option<(f32, f32)>

Convert world coordinates to local coordinates for hit testing arbitrary shapes.

This uses ray-casting similar to browsers: it casts a ray from the screen point perpendicular to the screen (parallel to the Z-axis) and finds where it intersects the transformed plane at z=0 in local space.

§Arguments
  • screen_pos - Screen/world coordinates (e.g., mouse position)
§Returns

Local coordinates (x, y) if the ray intersects the plane, None otherwise.

§Example
// For hit testing a path
if let Some((lx, ly)) = transform.project_screen_point_to_local_2d((mouse_x, mouse_y)) {
    hit_test_path(&Point::new(lx, ly), path, FillRule::EvenOdd, 0.1)
} else {
    false
}
Source

pub fn rows_local(&self) -> [[f32; 4]; 4]

Source

pub fn rows_world(&self) -> [[f32; 4]; 4]

Trait Implementations§

Source§

impl Clone for Transform

Source§

fn clone(&self) -> Transform

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Transform

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Transform

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl PartialEq for Transform

Source§

fn eq(&self, other: &Transform) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Transform

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.