svg_path/congruency
Directional semantic congruency checks for path geometry.
Congruency means that a translation, rotation, and uniform scale maps the source geometry to the target geometry within a tolerance. Reflection and shear are not allowed.
These checks compare ordered semantic structure, not rendered shape. Segment constructors must match, subpaths and paths must have matching ordered structure, and closed subpaths are not cycled to search for another starting segment.
Types
A best-fit transform and its root-mean-square point error.
error is measured in the same coordinate units as the input points.
pub type Fit {
Fit(transform: transform.Matrix, error: Float)
}
Constructors
-
Fit(transform: transform.Matrix, error: Float)
The transform family allowed during best-fit congruency.
pub type TransformFamily {
Similar
Affine
}
Constructors
-
SimilarTranslation, rotation, and uniform scale. Reflection and shear are not allowed.
-
AffineA general affine transform, allowing non-uniform scale, shear, and reflection. If the source point cloud is underdetermined for an affine solve, this falls back to
Similar.
Values
pub fn fit_path(
source source: svg_path.Path,
target target: svg_path.Path,
family family: TransformFamily,
) -> Result(Fit, Nil)
Find the best transform mapping one ordered path to another.
Path subpaths must match in order. Each subpath comparison ignores the
subpath closed field. Closed subpaths are not cycled, no alternate
starting segment is attempted, and subpaths are not reordered.
pub fn fit_points(
source source: List(svg_path.Point),
target target: List(svg_path.Point),
family family: TransformFamily,
) -> Result(Fit, Nil)
Find the best transform mapping one ordered point list to another.
Empty lists and lists with different lengths return Error(Nil).
Similar fits translation, rotation, and uniform scale without reflection.
Affine fits a general affine transform; when the source points do not
determine an affine transform stably, it falls back to Similar.
The returned Fit.error is the root-mean-square distance between each
transformed source point and its corresponding target point.
pub fn fit_segment(
source source: svg_path.Segment,
target target: svg_path.Segment,
family family: TransformFamily,
) -> Result(Fit, Nil)
Find the best transform mapping one segment to another segment of the same constructor.
This uses the same semantic point-cloud policy as segment, but returns a
best-fit transform and RMS point error instead of applying a tolerance.
pub fn fit_subpath(
source source: svg_path.Subpath,
target target: svg_path.Subpath,
family family: TransformFamily,
) -> Result(Fit, Nil)
Find the best transform mapping one ordered subpath to another.
The subpath closed field is ignored. Segment constructors must match in
order. Closed subpaths are not cycled, and no alternate starting segment is
attempted.
pub fn path(
source source: svg_path.Path,
target target: svg_path.Path,
tolerance tolerance: Float,
) -> Result(transform.Matrix, Nil)
Find a translation, rotation, and uniform scale mapping one path to another path.
Path subpaths must match in order. Each subpath comparison ignores the
subpath closed field. Closed subpaths are not cycled, no alternate
starting segment is attempted, and subpaths are not reordered.
pub fn points(
source source: List(svg_path.Point),
target target: List(svg_path.Point),
tolerance tolerance: Float,
) -> Result(transform.Matrix, Nil)
Find a translation, rotation, and uniform scale mapping one ordered point list to another.
Empty lists and lists with different lengths return Error(Nil). A
one-point source list uses a translation. For two or more source points, the
candidate transform is built from a triple-sweep source point pair and the
target points at the corresponding positions, then every mapped source point
is checked against the corresponding target point.
pub fn segment(
source source: svg_path.Segment,
target target: svg_path.Segment,
tolerance tolerance: Float,
) -> Result(transform.Matrix, Nil)
Find a translation, rotation, and uniform scale mapping one segment to another segment of the same constructor.
This is a directional, tolerance-based check. Ok(transform) means the
returned transform maps source to target within tolerance under this
module’s semantic segment comparison. Error(Nil) means no such transform
was found.
Segment congruency is intentionally not visual-shape congruency. A segment only matches a target segment built with the same constructor, even if two different constructors would render the same geometry.
pub fn subpath(
source source: svg_path.Subpath,
target target: svg_path.Subpath,
tolerance tolerance: Float,
) -> Result(transform.Matrix, Nil)
Find a translation, rotation, and uniform scale mapping one subpath to another subpath.
The subpath closed field is ignored. Segment constructors must match in
order. Closed subpaths are not cycled, and no alternate starting segment is
attempted.