Merge pull request #1981 from storytold/fix/sec-arrowhead-weight

fix(pathops): cap an arrowhead's weight like a stroke's width
This commit is contained in:
BFlat authored and GitHub committed 2026-11-07 10:51:51 +08:00
commit 3daa9d3293
1 file changed
+11
+11
View File
@@ -459,6 +459,8 @@ fn path_end(path: &BezPath, at_end: bool) -> Option<(Point, Vec2)> {
/// The filled arrowhead shape for `cap` at one end of an open path.
pub fn arrowhead(path: &BezPath, cap: StrokeCap, weight: f64, at_end: bool) -> Option<BezPath> {
// Capped like a stroke's width: the circle below is flattened at a fixed tolerance.
let weight = weight.min(MAX_STROKE_WIDTH);
let (tip, dir) = path_end(path, at_end)?;
let n = Vec2::new(-dir.y, dir.x);
let s = (weight * 3.0).max(6.0);
@@ -760,6 +762,15 @@ mod tests {
assert!((b.x0 + 5.0).abs() < 0.01);
}
#[test]
fn an_absurd_arrow_weight_is_capped() {
let mut line = BezPath::new();
line.move_to((0.0, 0.0));
line.line_to((100.0, 0.0));
let head = arrowhead(&line, StrokeCap::CircleFilled, 1e300, true).unwrap();
assert!(head.elements().len() < 10_000, "{}", head.elements().len());
}
#[test]
fn arrows_on_open_paths() {
let mut line = BezPath::new();