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: f64Implementations§
Source§impl TransPerspective
impl TransPerspective
Sourcepub fn new_from_values(
v0: f64,
v1: f64,
v2: f64,
v3: f64,
v4: f64,
v5: f64,
v6: f64,
v7: f64,
v8: f64,
) -> Self
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.
Sourcepub fn new_from_array(m: &[f64; 9]) -> Self
pub fn new_from_array(m: &[f64; 9]) -> Self
Custom matrix from array of 9 doubles.
Sourcepub fn new_from_affine(a: &TransAffine) -> Self
pub fn new_from_affine(a: &TransAffine) -> Self
From an affine transformation (w0=0, w1=0, w2=1).
Sourcepub fn square_to_quad(&mut self, q: &[f64; 8]) -> bool
pub fn square_to_quad(&mut self, q: &[f64; 8]) -> bool
Map unit square (0,0,1,1) to the quadrilateral.
Sourcepub fn quad_to_square(&mut self, q: &[f64; 8]) -> bool
pub fn quad_to_square(&mut self, q: &[f64; 8]) -> bool
Map the quadrilateral to unit square (inverse of square_to_quad).
Sourcepub fn quad_to_quad(&mut self, qs: &[f64; 8], qd: &[f64; 8]) -> bool
pub fn quad_to_quad(&mut self, qs: &[f64; 8], qd: &[f64; 8]) -> bool
Map quadrilateral src to quadrilateral dst.
Sourcepub fn rect_to_quad(
&mut self,
x1: f64,
y1: f64,
x2: f64,
y2: f64,
q: &[f64; 8],
) -> bool
pub fn rect_to_quad( &mut self, x1: f64, y1: f64, x2: f64, y2: f64, q: &[f64; 8], ) -> bool
Rectangle → quadrilateral.
Sourcepub fn quad_to_rect(
&mut self,
q: &[f64; 8],
x1: f64,
y1: f64,
x2: f64,
y2: f64,
) -> bool
pub fn quad_to_rect( &mut self, q: &[f64; 8], x1: f64, y1: f64, x2: f64, y2: f64, ) -> bool
Quadrilateral → rectangle.
Sourcepub fn scale_uniform(&mut self, s: f64)
pub fn scale_uniform(&mut self, s: f64)
Scale uniformly.
Sourcepub fn multiply(&mut self, a: &TransPerspective)
pub fn multiply(&mut self, a: &TransPerspective)
Multiply by another perspective matrix: self = a * self.
Sourcepub fn premultiply(&mut self, b: &TransPerspective)
pub fn premultiply(&mut self, b: &TransPerspective)
Premultiply: self = self * b.
Sourcepub fn multiply_affine(&mut self, a: &TransAffine)
pub fn multiply_affine(&mut self, a: &TransAffine)
Multiply by an affine matrix: self = a * self.
Sourcepub fn premultiply_affine(&mut self, b: &TransAffine)
pub fn premultiply_affine(&mut self, b: &TransAffine)
Premultiply by an affine matrix: self = self * b.
Sourcepub fn multiply_inv(&mut self, m: &TransPerspective)
pub fn multiply_inv(&mut self, m: &TransPerspective)
Multiply by inverse of another perspective matrix.
Sourcepub fn premultiply_inv(&mut self, m: &TransPerspective)
pub fn premultiply_inv(&mut self, m: &TransPerspective)
Premultiply by inverse of another perspective matrix.
Sourcepub fn multiply_inv_affine(&mut self, m: &TransAffine)
pub fn multiply_inv_affine(&mut self, m: &TransAffine)
Multiply by inverse of an affine matrix.
Sourcepub fn premultiply_inv_affine(&mut self, m: &TransAffine)
pub fn premultiply_inv_affine(&mut self, m: &TransAffine)
Premultiply by inverse of an affine matrix.
Sourcepub fn transform(&self, x: &mut f64, y: &mut f64)
pub fn transform(&self, x: &mut f64, y: &mut f64)
Direct transformation of x and y with perspective divide.
Sourcepub fn transform_affine(&self, x: &mut f64, y: &mut f64)
pub fn transform_affine(&self, x: &mut f64, y: &mut f64)
Direct transformation, affine part only (no perspective divide).
Sourcepub fn transform_2x2(&self, x: &mut f64, y: &mut f64)
pub fn transform_2x2(&self, x: &mut f64, y: &mut f64)
Direct transformation, 2×2 matrix only (no translation).
Sourcepub fn inverse_transform(&self, x: &mut f64, y: &mut f64)
pub fn inverse_transform(&self, x: &mut f64, y: &mut f64)
Inverse transformation (slow — inverts on every call).
Sourcepub fn from_affine(&mut self, a: &TransAffine)
pub fn from_affine(&mut self, a: &TransAffine)
Load from an affine transformation.
Sourcepub fn determinant(&self) -> f64
pub fn determinant(&self) -> f64
Determinant of the 3×3 matrix.
Sourcepub fn determinant_reciprocal(&self) -> f64
pub fn determinant_reciprocal(&self) -> f64
Reciprocal of determinant.
Sourcepub fn is_valid_eps(&self, epsilon: f64) -> bool
pub fn is_valid_eps(&self, epsilon: f64) -> bool
Check if matrix is valid with custom epsilon.
Sourcepub fn is_identity(&self) -> bool
pub fn is_identity(&self) -> bool
Check if matrix is identity.
Sourcepub fn is_identity_eps(&self, epsilon: f64) -> bool
pub fn is_identity_eps(&self, epsilon: f64) -> bool
Check if matrix is identity with custom epsilon.
Sourcepub fn is_equal(&self, m: &TransPerspective) -> bool
pub fn is_equal(&self, m: &TransPerspective) -> bool
Check equality with another matrix.
Sourcepub fn is_equal_eps(&self, m: &TransPerspective, epsilon: f64) -> bool
pub fn is_equal_eps(&self, m: &TransPerspective, epsilon: f64) -> bool
Check equality with custom epsilon.
Sourcepub fn translation(&self) -> (f64, f64)
pub fn translation(&self) -> (f64, f64)
Get translation components.
Sourcepub fn scaling_abs(&self) -> (f64, f64)
pub fn scaling_abs(&self) -> (f64, f64)
Absolute scaling components.
Trait Implementations§
Source§impl Clone for TransPerspective
impl Clone for TransPerspective
Source§fn clone(&self) -> TransPerspective
fn clone(&self) -> TransPerspective
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more