Skip to main content

Matrix

Struct Matrix 

Source
pub struct Matrix(/* private fields */);
Expand description

Full 4×4 column-major transform (glam-backed — the byte layout Flutter and Impeller use).

Canvas semantics throughout valo: the current transform maps LOCAL (drawn) coordinates to the list’s ROOT space, and then(local) appends a transform that applies to subsequently drawn geometry FIRST — i.e. current ∘ local, matrix product current × local. Same convention as Skia/Impeller’s transform stack.

2D content maps as (x, y, 0, 1): the w row does perspective (the hardware divide, with perspective-correct interpolation); the z output is IGNORED for painting — valo writes its own per-draw depth (2.5D, Flutter’s model).

Implementations§

Source§

impl Matrix

Source

pub const IDENTITY: Matrix

Source

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

Source

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

Source

pub fn rotation(radians: f32) -> Self

Source

pub fn from_affine(a: f32, b: f32, c: f32, d: f32, tx: f32, ty: f32) -> Self

The classic 2×3 affine (column vectors (a,b), (c,d), translation).

Source

pub fn from_flutter_array(values: &[f32; 16]) -> Self

The 16 column-major floats Flutter-architecture hosts hand a canvas.

Source

pub fn to_flutter_array(&self) -> [f32; 16]

Source

pub fn to_mat4(self) -> Mat4

The backing matrix, for MVP assembly.

Source

pub fn then(&self, other: &Matrix) -> Matrix

self ∘ other: apply other first, then self (product self × other).

Source

pub fn is_affine(&self) -> bool

True when the w row is inert for 2D content ((0, 0, ·, 1) — the z column never matters because inputs have z = 0).

Source

pub fn kind(&self) -> MatrixKind

Source

pub fn map_point(&self, p: Point) -> Point

Source

pub fn map_rect(&self, r: &Rect) -> Rect

Axis-aligned bounds of the mapped rect: exact for rectilinear transforms, conservative under rotation, and Rect::EVERYTHING when any corner reaches the eye plane (w ≤ ε) — culling must never reject such content, and layers clamp to their clip instead.

Source

pub fn max_scale(&self) -> f32

Maximum length the XY basis vectors scale a unit vector to — the device-scale factor text pickers and blur sigmas care about (Impeller’s maxBasisLengthXY; ignores perspective, so approximate under it).

Source

pub fn to_affine(&self) -> [f32; 6]

The 2D affine block [a, b, c, d, tx, ty] (column vectors (a,b), (c,d), translation) — ignores any perspective row; pair with Self::is_affine where exactness matters (gradient locals and embed quads are affine by construction).

Source

pub fn determinant(&self) -> f32

The 2D block’s determinant (orientation / area factor of the xy plane — what stroking and winding care about).

Source

pub fn invert(&self) -> Option<Matrix>

Trait Implementations§

Source§

impl Clone for Matrix

Source§

fn clone(&self) -> Matrix

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for Matrix

Source§

impl Debug for Matrix

Source§

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

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

impl Default for Matrix

Source§

fn default() -> Self

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

impl PartialEq for Matrix

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Matrix

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.