Address review

This commit is contained in:
Matt Fellenz 2025-03-11 11:55:34 +01:00
parent 5865f0e9e9
commit 61f9f7389f
No known key found for this signature in database
GPG Key ID: DCBCE4091A4F9434
2 changed files with 18 additions and 6 deletions

View File

@ -59,7 +59,13 @@ pub fn jump_from_click(
continue;
}
}
let pos = pos.transform_inf(group.transform.invert().unwrap());
// Realistic transforms should always be invertible.
// An example of one that isn't is a scale of 0, which would
// not be clickable anyway.
let Some(inv_transform) = group.transform.invert() else {
continue;
};
let pos = pos.transform_inf(inv_transform);
if let Some(span) = jump_from_click(world, document, &group.frame, pos) {
return Some(span);
}
@ -292,7 +298,8 @@ mod tests {
cursor(45),
);
test_click(
"#box(width: 10pt, height: 10pt, clip: true, scale(x: 300%, y: 300%, origin: top + left, rect(width: 10pt, height: 10pt)))",
"#box(width: 10pt, height: 10pt, clip: true, scale(x: 300%, y: 300%, \
origin: top + left, rect(width: 10pt, height: 10pt)))",
point(20.0, 20.0) + margin,
None,
);
@ -306,6 +313,11 @@ mod tests {
point(20.0, 20.0) + margin,
None,
);
test_click(
"#rotate(90deg, origin: bottom + left)[hello world]",
point(5.0, 15.0) + margin,
cursor(40),
);
}
#[test]

View File

@ -531,10 +531,6 @@ impl Curve {
}
}
fn point_to_kurbo(point: Point) -> kurbo::Point {
kurbo::Point::new(point.x.to_raw(), point.y.to_raw())
}
impl Curve {
fn to_kurbo(&self) -> kurbo::BezPath {
use kurbo::{BezPath, PathEl};
@ -557,3 +553,7 @@ impl Curve {
kurbo::Shape::contains(&self.to_kurbo(), point_to_kurbo(needle))
}
}
fn point_to_kurbo(point: Point) -> kurbo::Point {
kurbo::Point::new(point.x.to_raw(), point.y.to_raw())
}