diff options
Diffstat (limited to 'crates/typst-library/src/visualize/path.rs')
| -rw-r--r-- | crates/typst-library/src/visualize/path.rs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/crates/typst-library/src/visualize/path.rs b/crates/typst-library/src/visualize/path.rs index 76fd0df0..f592a712 100644 --- a/crates/typst-library/src/visualize/path.rs +++ b/crates/typst-library/src/visualize/path.rs @@ -1,4 +1,5 @@ use kurbo::ParamCurveExtrema; +use typst_utils::Numeric; use self::PathVertex::{AllControlPoints, MirroredControlPoint, Vertex}; use crate::diag::{bail, SourceResult}; @@ -228,6 +229,25 @@ impl Path { self.0.push(PathItem::ClosePath); } + /// Translate all points in this path by the given offset. + pub fn translate(&mut self, offset: Point) { + if offset.is_zero() { + return; + } + for item in self.0.iter_mut() { + match item { + PathItem::MoveTo(p) => *p += offset, + PathItem::LineTo(p) => *p += offset, + PathItem::CubicTo(p1, p2, p3) => { + *p1 += offset; + *p2 += offset; + *p3 += offset; + } + PathItem::ClosePath => (), + } + } + } + /// Computes the size of bounding box of this path. pub fn bbox_size(&self) -> Size { let mut min_x = Abs::inf(); |
