pub struct Path { /* private fields */ }Expand description
One subpath: an ordered run of Commands with a cached current point.
Every *_to constructor is absolute; every *_by constructor is relative
to the current point and resolves to the identical absolute command, so
a path built either way compares equal.
Implementations§
Source§impl Path
impl Path
Sourcepub fn starting_at(x: f32, y: f32) -> Self
pub fn starting_at(x: f32, y: f32) -> Self
A path holding a single MoveTo — the usual first call.
Sourcepub const fn current_point(&self) -> (f32, f32)
pub const fn current_point(&self) -> (f32, f32)
The current point: the end of the last on-curve command, the subpath
start after a Close, or (0, 0) for an empty path.
Sourcepub const fn start_point(&self) -> (f32, f32)
pub const fn start_point(&self) -> (f32, f32)
The start of the current subpath.
Sourcepub fn move_to(&mut self, x: f32, y: f32) -> &mut Self
pub fn move_to(&mut self, x: f32, y: f32) -> &mut Self
Absolute MoveTo, starting a new subpath.
Sourcepub fn quad_by(&mut self, dcx: f32, dcy: f32, dx: f32, dy: f32) -> &mut Self
pub fn quad_by(&mut self, dcx: f32, dcy: f32, dx: f32, dy: f32) -> &mut Self
Relative QuadTo: control point and endpoint both relative to the
current point.
Sourcepub fn cubic_to(
&mut self,
c1x: f32,
c1y: f32,
c2x: f32,
c2y: f32,
x: f32,
y: f32,
) -> &mut Self
pub fn cubic_to( &mut self, c1x: f32, c1y: f32, c2x: f32, c2y: f32, x: f32, y: f32, ) -> &mut Self
Absolute CubicTo.
Sourcepub fn cubic_by(
&mut self,
dc1x: f32,
dc1y: f32,
dc2x: f32,
dc2y: f32,
dx: f32,
dy: f32,
) -> &mut Self
pub fn cubic_by( &mut self, dc1x: f32, dc1y: f32, dc2x: f32, dc2y: f32, dx: f32, dy: f32, ) -> &mut Self
Relative CubicTo: both control points and the endpoint relative to
the current point.
Sourcepub fn close(&mut self) -> &mut Self
pub fn close(&mut self) -> &mut Self
Close: append the explicit Close command and reset the current
point to the subpath start.
Sourcepub fn open(&mut self) -> Option<Command>
pub fn open(&mut self) -> Option<Command>
Drop the trailing Close, leaving the subpath open. None when the
path was not closed.
Sourcepub fn truncate(&mut self, len: usize) -> Option<()>
pub fn truncate(&mut self, len: usize) -> Option<()>
Truncate to len commands. None when len exceeds the length.
The cached current point and subpath start are recomputed, so the path stays internally consistent.
Sourcepub fn push(&mut self, cmd: Command) -> &mut Self
pub fn push(&mut self, cmd: Command) -> &mut Self
Append a raw command, keeping the cached current point in step.
Sourcepub fn ensure_closed(&mut self) -> &mut Self
pub fn ensure_closed(&mut self) -> &mut Self
Close the path unless it is empty or already closed. Idempotent.
Sourcepub fn bbox(&self) -> Option<Bbox>
pub fn bbox(&self) -> Option<Bbox>
Exact bounding box: line endpoints plus the true interior extrema of
every quadratic and cubic. None for a path with no points.
use font_model::Path;
// A cubic from (0,0) through controls (3,0) (3,3) to (0,3): the exact
// box reaches well inside the control hull's x = 3.
let mut p = Path::starting_at(0.0, 0.0);
p.cubic_to(3.0, 0.0, 3.0, 3.0, 0.0, 3.0);
p.close();
let b = p.bbox().expect("non-empty");
assert!(b.max_x() < 3.0);
// The known extreme of this cubic: x peaks at 2.25.
assert!((b.max_x() - 2.25).abs() < 1e-5, "max_x {}", b.max_x());Sourcepub fn signed_area(&self) -> f32
pub fn signed_area(&self) -> f32
Signed area of the path in square font units, treating every subpath as closed. Curves contribute their exact analytic integral, so this is not a flattened approximation.