Skip to main content

TransPerspective

Struct TransPerspective 

Source
pub struct TransPerspective {
    pub sx: f64,
    pub shy: f64,
    pub w0: f64,
    pub shx: f64,
    pub sy: f64,
    pub w1: f64,
    pub tx: f64,
    pub ty: f64,
    pub w2: f64,
}
Expand description

Perspective 2D transformation (3×3 projective matrix).

| sx  shy  w0 |
| shx  sy  w1 |
| tx   ty  w2 |

Transform: m = 1/(x*w0 + y*w1 + w2), then x' = m*(x*sx + y*shx + tx), y' = m*(x*shy + y*sy + ty).

Port of C++ trans_perspective.

Fields§

§sx: f64§shy: f64§w0: f64§shx: f64§sy: f64§w1: f64§tx: f64§ty: f64§w2: f64

Implementations§

Source§

impl TransPerspective

Source

pub fn new() -> Self

Identity matrix.

Source

pub fn new_from_values( v0: f64, v1: f64, v2: f64, v3: f64, v4: f64, v5: f64, v6: f64, v7: f64, v8: f64, ) -> Self

Custom matrix from 9 values.

Source

pub fn new_from_array(m: &[f64; 9]) -> Self

Custom matrix from array of 9 doubles.

Source

pub fn new_from_affine(a: &TransAffine) -> Self

From an affine transformation (w0=0, w1=0, w2=1).

Source

pub fn square_to_quad(&mut self, q: &[f64; 8]) -> bool

Map unit square (0,0,1,1) to the quadrilateral.

Source

pub fn quad_to_square(&mut self, q: &[f64; 8]) -> bool

Map the quadrilateral to unit square (inverse of square_to_quad).

Source

pub fn quad_to_quad(&mut self, qs: &[f64; 8], qd: &[f64; 8]) -> bool

Map quadrilateral src to quadrilateral dst.

Source

pub fn rect_to_quad( &mut self, x1: f64, y1: f64, x2: f64, y2: f64, q: &[f64; 8], ) -> bool

Rectangle → quadrilateral.

Source

pub fn quad_to_rect( &mut self, q: &[f64; 8], x1: f64, y1: f64, x2: f64, y2: f64, ) -> bool

Quadrilateral → rectangle.

Source

pub fn reset(&mut self)

Reset to identity matrix.

Source

pub fn invert(&mut self) -> bool

Invert the matrix. Returns false if degenerate.

Source

pub fn translate(&mut self, x: f64, y: f64)

Translate the matrix.

Source

pub fn rotate(&mut self, a: f64)

Rotate the matrix.

Source

pub fn scale_uniform(&mut self, s: f64)

Scale uniformly.

Source

pub fn scale_xy(&mut self, x: f64, y: f64)

Scale non-uniformly.

Source

pub fn multiply(&mut self, a: &TransPerspective)

Multiply by another perspective matrix: self = a * self.

Source

pub fn premultiply(&mut self, b: &TransPerspective)

Premultiply: self = self * b.

Source

pub fn multiply_affine(&mut self, a: &TransAffine)

Multiply by an affine matrix: self = a * self.

Source

pub fn premultiply_affine(&mut self, b: &TransAffine)

Premultiply by an affine matrix: self = self * b.

Source

pub fn multiply_inv(&mut self, m: &TransPerspective)

Multiply by inverse of another perspective matrix.

Source

pub fn premultiply_inv(&mut self, m: &TransPerspective)

Premultiply by inverse of another perspective matrix.

Source

pub fn multiply_inv_affine(&mut self, m: &TransAffine)

Multiply by inverse of an affine matrix.

Source

pub fn premultiply_inv_affine(&mut self, m: &TransAffine)

Premultiply by inverse of an affine matrix.

Source

pub fn transform(&self, x: &mut f64, y: &mut f64)

Direct transformation of x and y with perspective divide.

Source

pub fn transform_affine(&self, x: &mut f64, y: &mut f64)

Direct transformation, affine part only (no perspective divide).

Source

pub fn transform_2x2(&self, x: &mut f64, y: &mut f64)

Direct transformation, 2×2 matrix only (no translation).

Source

pub fn inverse_transform(&self, x: &mut f64, y: &mut f64)

Inverse transformation (slow — inverts on every call).

Source

pub fn store_to(&self, m: &mut [f64; 9])

Store matrix to array of 9 doubles.

Source

pub fn load_from(&mut self, m: &[f64; 9])

Load matrix from array of 9 doubles.

Source

pub fn from_affine(&mut self, a: &TransAffine)

Load from an affine transformation.

Source

pub fn determinant(&self) -> f64

Determinant of the 3×3 matrix.

Source

pub fn determinant_reciprocal(&self) -> f64

Reciprocal of determinant.

Source

pub fn is_valid(&self) -> bool

Check if matrix is valid (non-degenerate).

Source

pub fn is_valid_eps(&self, epsilon: f64) -> bool

Check if matrix is valid with custom epsilon.

Source

pub fn is_identity(&self) -> bool

Check if matrix is identity.

Source

pub fn is_identity_eps(&self, epsilon: f64) -> bool

Check if matrix is identity with custom epsilon.

Source

pub fn is_equal(&self, m: &TransPerspective) -> bool

Check equality with another matrix.

Source

pub fn is_equal_eps(&self, m: &TransPerspective, epsilon: f64) -> bool

Check equality with custom epsilon.

Source

pub fn scale(&self) -> f64

Determine overall scale factor.

Source

pub fn rotation(&self) -> f64

Determine rotation angle.

Source

pub fn translation(&self) -> (f64, f64)

Get translation components.

Source

pub fn scaling(&self) -> (f64, f64)

Determine scaling components.

Source

pub fn scaling_abs(&self) -> (f64, f64)

Absolute scaling components.

Source

pub fn begin(&self, x: f64, y: f64, step: f64) -> PerspectiveIteratorX

Create an incremental scanline iterator.

Trait Implementations§

Source§

impl Clone for TransPerspective

Source§

fn clone(&self) -> TransPerspective

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 Default for TransPerspective

Source§

fn default() -> Self

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

impl Transformer for TransPerspective

Source§

fn transform(&self, x: &mut f64, y: &mut f64)

Source§

impl Copy for TransPerspective

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.