Fix large arrow proportions
This commit is contained in:
parent
3df1300b07
commit
39db39a8b2
|
|
@ -2245,7 +2245,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "pdf-presenter"
|
||||
version = "0.1.67"
|
||||
version = "0.1.68"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"chrono",
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ default-members = ["crates/pdf-presenter"]
|
|||
resolver = "3"
|
||||
|
||||
[workspace.package]
|
||||
version = "0.1.67"
|
||||
version = "0.1.68"
|
||||
edition = "2024"
|
||||
license = "MIT"
|
||||
repository = "https://proxy.dandaedre.com/gitea/idle-org/pdf-presenter"
|
||||
|
|
|
|||
|
|
@ -201,23 +201,18 @@ pub fn paint(painter: &egui::Painter, target: Rect, uv: Rect, overlay: &Overlay)
|
|||
Color32::from_rgba_unmultiplied(mark.color[0], mark.color[1], mark.color[2], 105)
|
||||
}
|
||||
};
|
||||
let width = mark.width * painter.ctx().pixels_per_point().sqrt().clamp(1., 2.);
|
||||
painter.line_segment([from, to], Stroke::new(width, color));
|
||||
if mark.kind == MarkKind::Arrow {
|
||||
let direction = to - from;
|
||||
if direction.length_sq() > 4. {
|
||||
let direction = direction.normalized();
|
||||
let normal = Vec2::new(-direction.y, direction.x);
|
||||
let length = (width * 2.8).clamp(12., 42.);
|
||||
painter.line_segment(
|
||||
[to, to - direction * length + normal * length * 0.45],
|
||||
Stroke::new(width, color),
|
||||
);
|
||||
painter.line_segment(
|
||||
[to, to - direction * length - normal * length * 0.45],
|
||||
Stroke::new(width, color),
|
||||
);
|
||||
}
|
||||
let width = mark.width;
|
||||
if mark.kind == MarkKind::Arrow
|
||||
&& let Some((shaft_end, head)) = arrow_geometry(from, to, width)
|
||||
{
|
||||
painter.line_segment([from, shaft_end], Stroke::new(width, color));
|
||||
painter.add(egui::Shape::convex_polygon(
|
||||
head.to_vec(),
|
||||
color,
|
||||
Stroke::NONE,
|
||||
));
|
||||
} else {
|
||||
painter.line_segment([from, to], Stroke::new(width, color));
|
||||
}
|
||||
}
|
||||
if let Some(point) = overlay
|
||||
|
|
@ -237,3 +232,45 @@ pub fn paint(painter: &egui::Painter, target: Rect, uv: Rect, overlay: &Overlay)
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// A filled head avoids the three overlapping thick strokes that deform large arrows.
|
||||
fn arrow_geometry(from: Pos2, to: Pos2, width: f32) -> Option<(Pos2, [Pos2; 3])> {
|
||||
let vector = to - from;
|
||||
let distance = vector.length();
|
||||
if distance <= 2. {
|
||||
return None;
|
||||
}
|
||||
let direction = vector / distance;
|
||||
let normal = Vec2::new(-direction.y, direction.x);
|
||||
let head_length = (width * 1.8).clamp(10., 56.).min(distance * 0.45);
|
||||
let head_half_width = (width * 0.9).clamp(6., 30.).min(head_length * 0.75);
|
||||
let base = to - direction * head_length;
|
||||
let shaft_end = base + direction * (width * 0.12).min(head_length * 0.12);
|
||||
Some((
|
||||
shaft_end,
|
||||
[
|
||||
to,
|
||||
base + normal * head_half_width,
|
||||
base - normal * head_half_width,
|
||||
],
|
||||
))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn large_arrow_has_a_bounded_filled_head_and_shortened_shaft() {
|
||||
let from = Pos2::new(0., 0.);
|
||||
let to = Pos2::new(0., 200.);
|
||||
let (shaft_end, head) = arrow_geometry(from, to, 48.).unwrap();
|
||||
assert!(shaft_end.y < to.y);
|
||||
assert_eq!(head[0], to);
|
||||
assert!(head[1].distance(head[2]) <= 60.);
|
||||
assert!(to.distance(head[1]) < 70.);
|
||||
|
||||
let (_, short_head) = arrow_geometry(from, Pos2::new(20., 0.), 48.).unwrap();
|
||||
assert!(short_head[0].distance(short_head[1]) < 15.);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,14 @@
|
|||
|
||||
## Unreleased
|
||||
|
||||
### 0.1.68
|
||||
|
||||
- Keep large arrows clean and proportional: shorten the shaft beneath a filled,
|
||||
length-bounded triangular head instead of overlapping three thick strokes. Use
|
||||
logical tool sizes directly so display DPI does not inflate arrows or highlights.
|
||||
Linux checks pass with 84.42% whole-application coverage; the release binary is
|
||||
rebuilt.
|
||||
|
||||
### 0.1.67
|
||||
|
||||
- Add a presenter toolbox with a low-latency pointer, straight arrows and
|
||||
|
|
|
|||
Loading…
Reference in New Issue