svg_path/affine
Low-level two-dimensional affine matrix helpers.
Matrices use SVG’s six-value affine form matrix(a b c d e f) and are
applied to column vectors: x' = a*x + c*y + e,
y' = b*x + d*y + f.
Types
A two-dimensional affine transform in SVG’s six-value matrix form.
pub type Affine {
Affine(
a: Float,
b: Float,
c: Float,
d: Float,
e: Float,
f: Float,
)
}
Constructors
-
Affine( a: Float, b: Float, c: Float, d: Float, e: Float, f: Float, )
Failures while constructing a transform from point correspondences.
pub type Error {
DegenerateSourcePair
DegenerateSourceTriple
NonFiniteTransform
}
Constructors
-
DegenerateSourcePairThe source pair has zero separation in the scaled calculation.
-
DegenerateSourceTripleThe source triple has zero determinant in the calculation, for example when its points are collinear or repeated.
-
NonFiniteTransformConstruction produced a non-finite denominator or matrix coefficient.
Values
pub fn about_point(
transform transform: Affine,
x x: Float,
y y: Float,
) -> Affine
Create a matrix that applies a transform about a point.
pub fn chain(first first: Affine, then second: Affine) -> Affine
Chain two transforms in application order.
chain(first: a, then: b) creates a matrix that applies a first and b
second. In algebraic matrix order, this is b * a.
pub fn determinant(transform: Affine) -> Float
Return the determinant of the linear part.
pub fn from_tuple(
values: #(Float, Float, Float, Float, Float, Float),
) -> Affine
Create an affine matrix from SVG’s six matrix values as a tuple.
pub fn is_finite(transform: Affine) -> Bool
Return true when all six matrix entries are finite.
pub fn linear_point(
transform: Affine,
x x: Float,
y y: Float,
) -> #(Float, Float)
Apply only the linear part of the matrix to raw coordinates.
pub fn matrix(
a a: Float,
b b: Float,
c c: Float,
d d: Float,
e e: Float,
f f: Float,
) -> Affine
Create an affine matrix from SVG’s six matrix values.
pub fn multiply(left left: Affine, right right: Affine) -> Affine
Multiply two matrices in algebraic order.
multiply(left: a, right: b) returns a * b.
pub fn point(
transform: Affine,
x x: Float,
y y: Float,
) -> #(Float, Float)
Apply the full affine matrix to raw coordinates.
pub fn point_pair_similarity(
source_start source_start: #(Float, Float),
source_end source_end: #(Float, Float),
target_start target_start: #(Float, Float),
target_end target_end: #(Float, Float),
) -> Result(Affine, Error)
Find a translation, rotation, and uniform scale mapping one point pair to another.
Points are represented as raw coordinate tuples.
Returns DegenerateSourcePair for zero computed source separation, or
NonFiniteTransform when construction produces non-finite values.
pub fn point_triple_map(
source_a source_a: #(Float, Float),
source_b source_b: #(Float, Float),
source_c source_c: #(Float, Float),
target_a target_a: #(Float, Float),
target_b target_b: #(Float, Float),
target_c target_c: #(Float, Float),
) -> Result(Affine, Error)
Find an affine transform mapping one point triple to another.
Points are represented as raw coordinate tuples.
Returns DegenerateSourceTriple for a zero computed source determinant,
or NonFiniteTransform when construction produces non-finite values.
pub fn rotate(degrees degrees: Float) -> Affine
Create a rotation matrix from an angle in degrees. Positive angles rotate visually clockwise in SVG coordinates (y down).
pub fn skew_x(degrees degrees: Float) -> Affine
Create an x-axis skew matrix from an angle in degrees.
pub fn skew_y(degrees degrees: Float) -> Affine
Create a y-axis skew matrix from an angle in degrees.
pub fn to_tuple(
transform: Affine,
) -> #(Float, Float, Float, Float, Float, Float)
Return SVG’s six matrix values as #(a, b, c, d, e, f).