mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-26 22:27:08 +00:00
Quick Pen: a length drag measures the curve against the canvas, not its handles
A cubic earlier in the path whose handle lies past the canvas while the curve stays on it no longer blocks every length drag at the end of the path.
This commit is contained in:
@@ -25,7 +25,7 @@ use std::sync::Arc;
|
||||
|
||||
use serde_json::{Value, json};
|
||||
use vectorcraft_doc::{Document, MAX_COORD, Node, NodeId, NodeKind};
|
||||
use vectorcraft_geom::{Anchor, AnchorKind, BezPath, Point, SubPath, Vec2};
|
||||
use vectorcraft_geom::{Anchor, AnchorKind, BezPath, PathData, Point, SubPath, Vec2};
|
||||
|
||||
use crate::draw2::FEEDBACK;
|
||||
use crate::guides::{DrawSnap, Leave};
|
||||
@@ -363,9 +363,12 @@ fn selected_alone(cx: &ToolContext, id: NodeId) -> bool {
|
||||
sel == [id] || cx.doc.parent_of(id).is_some_and(|p| sel == [p] && cx.doc.node(p).is_some_and(|n| matches!(n.kind, NodeKind::Compound { .. })))
|
||||
}
|
||||
|
||||
/// Whether every point and handle of `sp` lies on the canvas.
|
||||
/// Whether `sp` lies on the canvas: every point and handle does, or else the curve itself (its
|
||||
/// extrema, not its handles) does.
|
||||
fn on_canvas(sp: &SubPath) -> bool {
|
||||
sp.anchors.iter().all(|a| [a.p, a.h_in, a.h_out].iter().all(|q| q.x.abs() <= MAX_COORD && q.y.abs() <= MAX_COORD))
|
||||
let within = |v: f64| v.abs() <= MAX_COORD;
|
||||
sp.anchors.iter().all(|a| [a.p, a.h_in, a.h_out].iter().all(|q| within(q.x) && within(q.y)))
|
||||
|| PathData::new(vec![sp.clone()]).bounds().is_some_and(|b| [b.x0, b.y0, b.x1, b.y1].into_iter().all(within))
|
||||
}
|
||||
|
||||
fn point_tol(cx: &ToolContext) -> f64 {
|
||||
|
||||
@@ -317,3 +317,23 @@ fn other_ends_have_no_piece() {
|
||||
closed.closed = true;
|
||||
assert_eq!(length::end_piece(&closed, false), None);
|
||||
}
|
||||
|
||||
/// A control point may lie past the canvas while the curve stays on it; a curve that reaches past
|
||||
/// the canvas is refused.
|
||||
#[test]
|
||||
fn the_canvas_check_measures_the_curve_not_its_control_points() {
|
||||
let m = MAX_COORD;
|
||||
let cubic = |out_x: f64| {
|
||||
let mut a = Anchor::corner(pt(m - 100.0, 0.0));
|
||||
a.h_out = pt(out_x, 0.0);
|
||||
let mut b = Anchor::corner(pt(m - 100.0, 100.0));
|
||||
b.h_in = b.p;
|
||||
SubPath::new(vec![a, b], false)
|
||||
};
|
||||
assert!(on_canvas(&cubic(m - 100.0)));
|
||||
assert!(on_canvas(&cubic(m + 100.0)));
|
||||
assert!(!on_canvas(&cubic(m + 1000.0)));
|
||||
let mut far = start(pt(m + 1.0, 0.0));
|
||||
far.anchors.push(Anchor::corner(pt(0.0, 0.0)));
|
||||
assert!(!on_canvas(&far));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user