mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-18 17:50:02 +00:00
Width Point: the outgoing half adjusts the point after its pair
With Adjust Adjoining on, the outgoing half of a discontinuous point looked for the point after it as the first one farther than 1e-6 from its own place, so a point within 1e-6 of the outgoing half but not of the pair's place was skipped. Both halves now measure from the pair's place.
This commit is contained in:
@@ -265,10 +265,9 @@ fn place(points: &mut Vec<(f64, f64, f64)>, mut pt: (f64, f64, f64), from_below:
|
||||
}
|
||||
|
||||
/// Adjust Adjoining Width Points: point `i` changes from `old` to `new` widths, and the nearest
|
||||
/// points at other positions on the sides `sides` names (before, after) change in proportion (by
|
||||
/// the same amount from zero).
|
||||
fn adjust_adjoining(points: &mut [(f64, f64, f64)], i: usize, old: (f64, f64, f64), new: (f64, f64, f64), sides: [bool; 2]) {
|
||||
let t = points[i].0;
|
||||
/// points farther than [`SAME_T`] from place `t` on the sides `sides` names (before, after)
|
||||
/// change in proportion (by the same amount from zero).
|
||||
fn adjust_adjoining(points: &mut [(f64, f64, f64)], i: usize, t: f64, old: (f64, f64, f64), new: (f64, f64, f64), sides: [bool; 2]) {
|
||||
let scale = |v: f64, o: f64, n: f64| {
|
||||
let width = if o > 1e-9 {
|
||||
let product = v * n;
|
||||
@@ -331,9 +330,11 @@ fn set_pair(
|
||||
Some(false) => ((old_in.0, inc.1, inc.2), (old_in.0, inc.1, inc.2)),
|
||||
Some(true) => ((old_in.0, out.1, out.2), (old_in.0, out.1, out.2)),
|
||||
};
|
||||
// Both halves measure their neighbors from the point's place, so a point within SAME_T of the
|
||||
// outgoing half but not of that place is the point after the pair.
|
||||
if adjust {
|
||||
adjust_adjoining(points, i, old_in, new_in, [true, false]);
|
||||
adjust_adjoining(points, j, old_out, new_out, [false, true]);
|
||||
adjust_adjoining(points, i, at, old_in, new_in, [true, false]);
|
||||
adjust_adjoining(points, j, at, old_out, new_out, [false, true]);
|
||||
}
|
||||
points[i] = new_in;
|
||||
points[j] = new_out;
|
||||
@@ -393,7 +394,7 @@ fn width_point_set(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
(Some(i), None) => {
|
||||
let old = prof.points[i];
|
||||
if adjust {
|
||||
adjust_adjoining(&mut prof.points, i, old, pt, [true, true]);
|
||||
adjust_adjoining(&mut prof.points, i, old.0, old, pt, [true, true]);
|
||||
}
|
||||
if (old.0 - t).abs() <= SAME_T {
|
||||
// Widths only: it keeps its place (and its side of a discontinuous point).
|
||||
@@ -409,7 +410,7 @@ fn width_point_set(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
prof.points.retain(|q| (q.0 - t).abs() > SAME_T);
|
||||
let i = place(&mut prof.points, pt, true);
|
||||
if let Some((left, right)) = old {
|
||||
adjust_adjoining(&mut prof.points, i, (t, left, right), pt, [true, true]);
|
||||
adjust_adjoining(&mut prof.points, i, pt.0, (t, left, right), pt, [true, true]);
|
||||
}
|
||||
i
|
||||
}
|
||||
|
||||
@@ -212,6 +212,18 @@ fn paired_set_adjusts_the_point_before_and_the_point_after_once_each() {
|
||||
assert_eq!(points(&s, id), vec![(0.0, 2.0, 2.0), (0.0, 4.0, 4.0), (1.0, 2.0, 2.0)]);
|
||||
}
|
||||
|
||||
/// Three points each within 1e-6 of the next: the first two are the pair, and the third, though
|
||||
/// within 1e-6 of the outgoing half, is the point after the pair that the outgoing half adjusts.
|
||||
#[test]
|
||||
fn paired_set_adjusts_the_point_after_a_chained_pair() {
|
||||
let (mut s, id) = pair_session(json!([[0, 1, 1], [0.5, 1, 1], [0.50000075, 2, 2], [0.5000015, 1, 1], [1, 1, 1]]));
|
||||
set(
|
||||
&mut s,
|
||||
json!({"id": id.0, "index": 1, "t": 0.5, "left": 5, "right": 5, "outIndex": 2, "outLeft": 5, "outRight": 5, "adjustAdjoining": true}),
|
||||
);
|
||||
assert_eq!(points(&s, id), vec![(0.0, 1.0, 1.0), (0.5, 1.0, 1.0), (0.50000075, 1.0, 1.0), (0.5000015, 0.5, 0.5), (1.0, 1.0, 1.0)]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn single_width_only_leaves_one_continuous_point() {
|
||||
for (single, kept) in [("incoming", (2.0, 1.0)), ("outgoing", (3.0, 4.0))] {
|
||||
|
||||
Reference in New Issue
Block a user