Skip to main content

Module xpath

Module xpath 

Source
Expand description

Flattened, matrix-transformed path edge table.

XPath is the Rust equivalent of SplashXPath from splash/SplashXPath.h/.cc. It converts a Path (in user space) into a sorted sequence of line segments in device space, ready for scan conversion by crate::XPathScanner.

§Typical usage pipeline

XPath::new(path, matrix, flatness, close_subpaths)   ← construction
    │  internally calls add_segment for every flattened edge
    ▼
XPath                                                 ← device-space edge table
    │  optionally:
    ▼
xpath.aa_scale()                                      ← scale coords × AA_SIZE
    │  must be called AT MOST ONCE, before handing to XPathScanner
    ▼
XPathScanner                                          ← scan conversion

§Key invariants (established by XPath::add_segment — internal)

  • For every non-horizontal segment, y0 ≤ y1 after construction (swapped if necessary; XPathFlags::FLIPPED is set when a swap occurred).
  • XPathFlags::HORIZ is set when y0 == y1 (despite the misleading “vertical” comment in the original C++ header — trust the code).
  • XPathFlags::VERT is set when x0 == x1.
  • dxdy = (x1-x0)/(y1-y0) for sloped segments; 0.0 for horizontal/vertical. Division is safe because the HORIZ early-return guarantees y0 ≠ y1 for any segment that reaches the slope computation.

§Affine transform convention

x_out = x_in * m[0] + y_in * m[2] + m[4]
y_out = x_in * m[1] + y_in * m[3] + m[5]

(column-vector convention matching SplashXPath::transform.)

Structs§

XPath
Matrix-transformed, flattened edge table derived from a Path.
XPathFlags
Per-segment flags for XPathSeg.
XPathSeg
A single line segment in the edge table, in device space.

Functions§

transform
Apply a 2-D affine matrix to point (xi, yi), returning the transformed PathPoint in device space.