mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-30 18:25:34 +01:00
Merge pull request #9391 from dotCooCoo/fix/packaging-fold-geometry
Fold Preview: preserve panel layer order
This commit is contained in:
6 files changed
+226
-274
No files matched your search
@@ -19,7 +19,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"Fold",
|
||||
[],
|
||||
None,
|
||||
"{ids?: [id…] (default: the selection), base?: [x, y] (the panel under this point; default: the largest panel), amount?: 0..1 (1), tolerance?: pt 0.01..10 (0.1)} fold the blank that the fold lines among the objects make (as addon.packaging.check finds them; while nothing is selected and ids is left out, every fold line of the document) into its 3D shape. The base panel stays in place; every other panel turns about the hinges that join it to the base, each by its angle times amount: the angle of the line with the most length in it, which is the line's own (addon.packaging.setFoldAngle; a positive angle folds away from the printed side) or else its role's, a Crease or a Perforation 90° away from the printed side and a Partial Cut 90° toward it. Hinges that close a loop of panels are not turned about: gap is how far apart their two placements end up when every hinge is folded all the way, whatever amount is, and closes is true when the gap is within the larger of tolerance and 0.5% of the distance between the hinge's two ends. Changes nothing in the document → {ok (no error), blank (the index of the blank folded, or null when none is), blanks, base, panels: [{outline (SVG path data, document coordinates), frame: {x, y, z, origin} (where the flat blank's x and y directions, its printed side and its origin go, in points: x right, y up, z toward the printed side of the flat blank), parent (null for the base and loose panels), depth}], hinges: [{a, b, angle (degrees), kind: tree|closing, closes, gap}], collisions: [[a, b]] (panels that pass through each other; panels stacked in one plane do not), issues (as addon.packaging.check)}. Errors: a base point in no panel",
|
||||
"{ids?: [id…] (default: the selection), base?: [x, y] (the panel under this point; default: the largest panel), amount?: 0..1 (1), tolerance?: pt 0.01..10 (0.1)} fold the blank that the fold lines among the objects make (as addon.packaging.check finds them; while nothing is selected and ids is left out, every fold line of the document) into its 3D shape. The base panel stays in place; every other panel turns about the hinges that join it to the base, each by its angle times amount: the angle of the line with the most length in it, which is the line's own (addon.packaging.setFoldAngle; a positive angle folds away from the printed side) or else its role's, a Crease or a Perforation 90° away from the printed side and a Partial Cut 90° toward it; the lowest id wins a tie. Hinges that close a loop of panels are not turned about: gap is how far apart their two placements end up when every hinge is folded all the way, whatever amount is, and closes is true when the gap is within the larger of tolerance and 0.5% of the distance between the hinge's two ends. Changes nothing in the document → {ok (no error), blank (the index of the blank folded, or null when none is), blanks, base, panels: [{outline (SVG path data, document coordinates), frame: {x, y, z, origin} (where the flat blank's x and y directions, its printed side and its origin go, in points: x right, y up, z toward the printed side of the flat blank), parent (null for the base and loose panels), depth}], hinges: [{a, b, angle (degrees), kind: tree|closing, closes, gap}], collisions: [[a, b]] (panels that pass through each other; panels stacked in one plane do not), issues (as addon.packaging.check)}. Errors: a base point in no panel",
|
||||
has_doc,
|
||||
fold_command
|
||||
)]
|
||||
|
||||
@@ -398,8 +398,8 @@ fn place(placing: &Placing, base: usize, amount: f64) -> Tree {
|
||||
/// next to it: `true` when a point just off the line on the left is inside it and the matching
|
||||
/// point on the right is not, `false` the other way round. `on` (a point of the line where the
|
||||
/// panels meet: [`super::Hinge::on`]) is tried first, then the middle and points a quarter and an
|
||||
/// eighth of the way along, each with the nearest offset first; `None` when no point tells the
|
||||
/// sides apart.
|
||||
/// eighth of the way along. Every position is tried at the nearest offset before larger offsets;
|
||||
/// `None` when no point tells the sides apart.
|
||||
fn side_of(outline: &PathData, from: V3, to: V3, len: f64, on: V3) -> Option<bool> {
|
||||
let bp = outline.to_bezpath();
|
||||
let left = [-(to[1] - from[1]) / len, (to[0] - from[0]) / len, 0.0];
|
||||
@@ -407,8 +407,8 @@ fn side_of(outline: &PathData, from: V3, to: V3, len: f64, on: V3) -> Option<boo
|
||||
let mut offsets = [1e-3, 0.25, len * 0.01];
|
||||
offsets.sort_by(f64::total_cmp);
|
||||
let along = [0.5, 0.25, 0.75, 0.125, 0.375, 0.625, 0.875].map(|t| add(from, scale(sub(to, from), t)));
|
||||
std::iter::once(on).chain(along).find_map(|at| {
|
||||
offsets.into_iter().find_map(|off| {
|
||||
offsets.into_iter().find_map(|off| {
|
||||
std::iter::once(on).chain(along).find_map(|at| {
|
||||
let (l, r) = (bp.winding(doc(add(at, scale(left, off)))) != 0, bp.winding(doc(sub(at, scale(left, off)))) != 0);
|
||||
(l != r).then_some(l)
|
||||
})
|
||||
@@ -518,3 +518,29 @@ fn crossings(rings: &[Vec<V3>], normal: V3, offset: f64, u: V3, tolerance: f64)
|
||||
at.sort_by(f64::total_cmp);
|
||||
at.as_chunks::<2>().0.iter().map(|&[a, b]| (a, b)).collect()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod side_tests {
|
||||
use super::*;
|
||||
use vectorcraft_geom::SubPath;
|
||||
|
||||
#[test]
|
||||
fn a_nearby_probe_at_another_position_precedes_a_remote_probe_at_the_hinge() {
|
||||
let points = [
|
||||
(-2.0, -1.0),
|
||||
(-1.0, -1.0),
|
||||
(-1.0, -0.0005),
|
||||
(1.0, -0.0005),
|
||||
(1.0, -1.0),
|
||||
(101.0, -1.0),
|
||||
(101.0, 0.0),
|
||||
(-1.0, 0.0),
|
||||
(-1.0, 0.2),
|
||||
(1.0, 0.2),
|
||||
(1.0, 0.3),
|
||||
(-2.0, 0.3),
|
||||
];
|
||||
let outline = PathData::single(SubPath::polyline(&points.map(|(x, y)| Point::new(x, y)), true));
|
||||
assert_eq!(side_of(&outline, [0.0; 3], [100.0, 0.0, 0.0], 100.0, [0.0; 3]), Some(true));
|
||||
}
|
||||
}
|
||||
@@ -16,8 +16,6 @@ pub const MAX_SIDE: u32 = 4096;
|
||||
pub const MAX_PIXELS: u32 = 1 << 21;
|
||||
/// The share of the eye's distance a panel is cut at in front of the eye.
|
||||
const NEAREST: f64 = 1e-3;
|
||||
/// How far apart (points of view depth) two panels in one plane may be and still tie.
|
||||
const TIE: f64 = 1e-4;
|
||||
/// How far apart (the sine of the angle) two panels' normals may be for the panels to lie in one
|
||||
/// plane.
|
||||
const PARALLEL: f64 = 1e-9;
|
||||
@@ -269,6 +267,13 @@ struct Mapped {
|
||||
shade: f32,
|
||||
}
|
||||
|
||||
impl Mapped {
|
||||
fn flat_at(&self, x: f64, y: f64) -> Option<(f64, f64)> {
|
||||
let [u, v, w] = mul(&self.inverse, [x, y, 1.0]);
|
||||
(w > 0.0 && w.is_finite()).then(|| (u / w, v / w)).filter(|(u, v)| u.is_finite() && v.is_finite())
|
||||
}
|
||||
}
|
||||
|
||||
fn mul(m: &[[f64; 3]; 3], v: V3) -> V3 {
|
||||
[dot(m[0], v), dot(m[1], v), dot(m[2], v)]
|
||||
}
|
||||
@@ -340,6 +345,8 @@ struct Target {
|
||||
/// [`planes`] gives them), panel number and colors.
|
||||
struct Fill<'a> {
|
||||
mapped: &'a Mapped,
|
||||
/// The group's comparison plane, or this panel when grouping is bypassed.
|
||||
plane: &'a Mapped,
|
||||
rank: u16,
|
||||
planes: &'a [u16],
|
||||
panel: u16,
|
||||
@@ -354,8 +361,7 @@ struct Fill<'a> {
|
||||
impl Fill<'_> {
|
||||
/// The flat point (less [`Fill::origin`]) under pixel center `(x, y)`, or `None` behind the eye.
|
||||
fn flat_at(&self, x: f64, y: f64) -> Option<(f64, f64)> {
|
||||
let [u, v, w] = mul(&self.mapped.inverse, [x, y, 1.0]);
|
||||
(w > 0.0 && w.is_finite()).then(|| (u / w, v / w)).filter(|(u, v)| u.is_finite() && v.is_finite())
|
||||
self.mapped.flat_at(x, y)
|
||||
}
|
||||
|
||||
/// The color of the panel at flat point `(u, v)`, `footprint` points across a pixel.
|
||||
@@ -382,15 +388,15 @@ impl Fill<'_> {
|
||||
for col in first as usize..=last as usize {
|
||||
let x = col as f64 + 0.5;
|
||||
let Some((u, v)) = self.flat_at(x, y) else { continue };
|
||||
let [a, b, c] = self.mapped.depth;
|
||||
let z = u * a + v * b + c;
|
||||
let Some((pu, pv)) = self.plane.flat_at(x, y) else { continue };
|
||||
let [a, b, c] = self.plane.depth;
|
||||
let z = pu * a + pv * b + c;
|
||||
let i = row * target.width + col;
|
||||
let (Some(&zb), Some(&rb), Some(&pb)) = (target.depth.get(i), target.rank.get(i), target.panel.get(i)) else { continue };
|
||||
// Panels in one plane tie within `TIE` and stack by rank; panels in different planes
|
||||
// that pass this close go by depth alone. Panel numbers count from 1.
|
||||
// Members of a plane have the same comparison depth and stack by rank. Distinct
|
||||
// planes compare by depth, then by their number at an exact crossing.
|
||||
let plane = |p: u16| usize::from(p).checked_sub(1).and_then(|p| self.planes.get(p));
|
||||
let one_plane = plane(self.panel).is_some_and(|a| plane(pb) == Some(a));
|
||||
let wins = if one_plane { z > zb + TIE || ((z - zb).abs() <= TIE && self.rank > rb) } else { z > zb };
|
||||
let wins = z.total_cmp(&zb).then_with(|| plane(self.panel).cmp(&plane(pb))).then(self.rank.cmp(&rb)).then(self.panel.cmp(&pb)).is_gt();
|
||||
if !wins {
|
||||
continue;
|
||||
}
|
||||
@@ -639,6 +645,17 @@ pub fn render(scene: &Scene) -> Option<Image> {
|
||||
for (&pi, &rank) in scene.folded.order.iter().zip(&ranks) {
|
||||
let (Some(panel), Some(f)) = (scene.blank.panels.get(pi), scene.folded.panels.get(pi)) else { continue };
|
||||
let Some(mapped) = map_panel(&local, &f.local) else { continue };
|
||||
let plane = if scene.folded.panels.len() <= super::MAX_PANELS {
|
||||
planes.get(pi).and_then(|kind| {
|
||||
planes
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter(|(_, k)| *k == kind)
|
||||
.find_map(|(i, _)| scene.folded.panels.get(i).and_then(|f| map_panel(&local, &f.local)))
|
||||
})
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let Some(rings) = flat_rings(panel, camera.scale) else { continue };
|
||||
let rings: Vec<Vec<[f64; 2]>> = rings.into_iter().map(|r| r.into_iter().map(|[u, v]| [u - o[0], v - o[1]]).collect()).collect();
|
||||
let projected: Vec<Vec<[f64; 2]>> = rings
|
||||
@@ -661,6 +678,7 @@ pub fn render(scene: &Scene) -> Option<Image> {
|
||||
.collect();
|
||||
let fill = Fill {
|
||||
mapped: &mapped,
|
||||
plane: plane.as_ref().unwrap_or(&mapped),
|
||||
rank,
|
||||
planes: &planes,
|
||||
panel: u16::try_from(pi + 1).unwrap_or(u16::MAX),
|
||||
@@ -677,39 +695,51 @@ pub fn render(scene: &Scene) -> Option<Image> {
|
||||
/// The plane each panel of `folded` lies in, as a number shared by the panels in one plane: their
|
||||
/// normals parallel to within [`PARALLEL`] and their planes as far apart as rounding leaves them
|
||||
/// ([`COPLANAR`] at their distance from [`Folded::origin`] for each hinge between them and the
|
||||
/// base), so a parallel panel any measurable way behind another goes by depth. Each panel is
|
||||
/// measured at the middle of its bounds in `blank`, by its pose about [`Folded::origin`]
|
||||
/// ([`super::FoldedPanel::local`]), so where the blank lies in the document does not change the
|
||||
/// planes. Past [`super::MAX_PANELS`] panels, one plane for all.
|
||||
/// base). Each panel's bounds corners are measured by its pose about [`Folded::origin`]
|
||||
/// ([`super::FoldedPanel::local`]). Past [`super::MAX_PANELS`] panels, one plane for all.
|
||||
fn planes(folded: &Folded, blank: &Blank) -> Vec<u16> {
|
||||
let n = folded.panels.len();
|
||||
if n > super::MAX_PANELS {
|
||||
return vec![0; n];
|
||||
}
|
||||
let length = |v: V3| dot(v, v).sqrt();
|
||||
// Each plane's normal, a point of it, the size of the coordinates that point came from and the
|
||||
// hinges that placed it.
|
||||
let mut kinds: Vec<(V3, V3, f64, usize)> = vec![];
|
||||
struct Plane {
|
||||
normal: V3,
|
||||
at: V3,
|
||||
size: f64,
|
||||
depth: usize,
|
||||
corners: [V3; 4],
|
||||
}
|
||||
let separation = |normal: V3, at: V3, points: &[V3; 4]| {
|
||||
points.iter().map(|p| dot(normal, [p[0] - at[0], p[1] - at[1], p[2] - at[2]]).abs()).fold(0.0, f64::max)
|
||||
};
|
||||
let mut kinds: Vec<Vec<Plane>> = vec![];
|
||||
folded
|
||||
.panels
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(i, f)| {
|
||||
let o = folded.origin;
|
||||
let middle = blank.panels.get(i).and_then(|p| p.outline.bounds()).map_or([0.0; 3], |b| [b.center().x - o[0], -b.center().y - o[1], 0.0]);
|
||||
let bounds = blank.panels.get(i).and_then(|p| p.outline.bounds());
|
||||
let middle = bounds.map_or([0.0; 3], |b| [b.center().x - o[0], -b.center().y - o[1], 0.0]);
|
||||
let flat =
|
||||
bounds.map_or([middle; 4], |b| [(b.x0, b.y0), (b.x1, b.y0), (b.x0, b.y1), (b.x1, b.y1)].map(|(x, y)| [x - o[0], -y - o[1], 0.0]));
|
||||
let corners = flat.map(|p| f.local.apply(p));
|
||||
let (normal, at) = (f.local.normal(), f.local.apply(middle));
|
||||
let size = length(at).max(length(middle));
|
||||
let same = |(m, p, s, d): &(V3, V3, f64, usize)| {
|
||||
let size = flat.iter().chain(&corners).map(|&p| length(p)).fold(0.0, f64::max);
|
||||
let same = |p: &Plane| {
|
||||
let m = p.normal;
|
||||
let c = [normal[1] * m[2] - normal[2] * m[1], normal[2] * m[0] - normal[0] * m[2], normal[0] * m[1] - normal[1] * m[0]];
|
||||
let apart = dot(*m, [at[0] - p[0], at[1] - p[1], at[2] - p[2]]).abs();
|
||||
let apart = separation(m, p.at, &corners).max(separation(normal, at, &p.corners));
|
||||
// Saturating: a `Folded` built by a caller may carry any depth.
|
||||
let hinges = f64::from(u32::try_from(f.depth.saturating_add(*d).saturating_add(1)).unwrap_or(u32::MAX));
|
||||
length(c) <= PARALLEL && apart <= COPLANAR * hinges * (1.0 + size.max(*s))
|
||||
let hinges = f64::from(u32::try_from(f.depth.saturating_add(p.depth).saturating_add(1)).unwrap_or(u32::MAX));
|
||||
length(c) <= PARALLEL && apart <= COPLANAR * hinges * (1.0 + size.max(p.size))
|
||||
};
|
||||
let k = kinds.iter().position(same).unwrap_or_else(|| {
|
||||
kinds.push((normal, at, size, f.depth));
|
||||
let k = kinds.iter().position(|group| group.iter().all(&same)).unwrap_or_else(|| {
|
||||
kinds.push(vec![]);
|
||||
kinds.len() - 1
|
||||
});
|
||||
kinds[k].push(Plane { normal, at, size, depth: f.depth, corners });
|
||||
u16::try_from(k).unwrap_or(u16::MAX)
|
||||
})
|
||||
.collect()
|
||||
|
||||
@@ -13,6 +13,18 @@ fn panel(subpaths: Vec<SubPath>) -> Panel {
|
||||
Panel { outline: PathData::new(subpaths), area: 0.0 }
|
||||
}
|
||||
|
||||
fn poly(pts: &[(f64, f64)], closed: bool) -> PathData {
|
||||
PathData::single(SubPath::polyline(&pts.iter().map(|&(x, y)| Point::new(x, y)).collect::<Vec<_>>(), closed))
|
||||
}
|
||||
|
||||
fn fold_line(path: PathData, kind: super::super::LineKind, key: u64, angle: Option<f64>) -> super::super::FoldLine {
|
||||
super::super::FoldLine { path, kind, key, angle }
|
||||
}
|
||||
|
||||
fn line(pts: &[(f64, f64)], closed: bool, kind: super::super::LineKind, key: u64, angle: Option<f64>) -> super::super::FoldLine {
|
||||
fold_line(poly(pts, closed), kind, key, angle)
|
||||
}
|
||||
|
||||
/// A blank of `panels` and a fold that places each at `poses`, in the order given.
|
||||
fn scene_of(panels: Vec<Panel>, poses: Vec<Pose>) -> (Blank, Folded) {
|
||||
let n = panels.len();
|
||||
@@ -37,6 +49,62 @@ fn moved(z: f64) -> Pose {
|
||||
Pose { t: [0.0, 0.0, z], ..Pose::IDENTITY }
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_middle_plane_does_not_join_two_separate_planes_into_one_stack() {
|
||||
let whole = || panel(vec![square(0.0, 0.0, 100.0, 100.0)]);
|
||||
let (b, f) = scene_of(vec![whole(), whole(), whole()], vec![moved(4e-13), moved(8e-13), moved(0.0)]);
|
||||
let image = render(&Scene { blank: &b, folded: &f, print: None, inside: [0; 4], outside: WHITE, camera: front() }).expect("drawn");
|
||||
assert_eq!(image.panel_at(50, 50), Some(1), "the separate farther panel does not cover the near stack");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_caller_supplied_scene_past_the_panel_limit_keeps_actual_depth() {
|
||||
let n = super::super::MAX_PANELS + 1;
|
||||
let panels = (0..n).map(|_| panel(vec![square(0.0, 0.0, 100.0, 100.0)])).collect();
|
||||
let mut poses = vec![Pose::IDENTITY; n];
|
||||
poses[1] = moved(5.0);
|
||||
let (b, f) = scene_of(panels, poses);
|
||||
let image = render(&Scene { blank: &b, folded: &f, print: None, inside: [0; 4], outside: WHITE, camera: front() }).expect("drawn");
|
||||
assert_eq!(image.panel_at(50, 50), Some(1));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn crossing_a_stack_selects_the_same_pixel_in_every_draw_order() {
|
||||
let angle = 1e-4_f64;
|
||||
let (s, c) = angle.sin_cos();
|
||||
let crossing = Pose { m: [[c, 0.0, s], [0.0, 1.0, 0.0], [-s, 0.0, c]], t: [0.0, 0.0, s * 50.5 / c + 2e-13] };
|
||||
let maps = [Pose::IDENTITY, crossing, moved(4e-13)].map(|p| map_panel(&front(), &p).expect("mapped"));
|
||||
let planes = [0, 1, 0];
|
||||
let ranks = [3, 2, 1];
|
||||
let mut winners = vec![];
|
||||
for order in [[0, 1, 2], [2, 1, 0], [0, 2, 1], [1, 0, 2], [1, 2, 0], [2, 0, 1]] {
|
||||
let mut target = Target {
|
||||
width: 100,
|
||||
height: 100,
|
||||
color: vec![0; 40_000],
|
||||
depth: vec![f64::NEG_INFINITY; 10_000],
|
||||
rank: vec![0; 10_000],
|
||||
panel: vec![0; 10_000],
|
||||
};
|
||||
for i in order {
|
||||
Fill {
|
||||
mapped: &maps[i],
|
||||
plane: &maps[usize::from(planes[i])],
|
||||
rank: ranks[i],
|
||||
planes: &planes,
|
||||
panel: (i + 1) as u16,
|
||||
print: None,
|
||||
origin: [0.0; 2],
|
||||
inside: [0.0; 4],
|
||||
outside: [0.0; 4],
|
||||
}
|
||||
.span(&mut target, 50, 50.0, 51.0);
|
||||
}
|
||||
winners.push(target.panel[5050]);
|
||||
}
|
||||
assert!(winners.iter().all(|&winner| winner == winners[0]), "{winners:?}");
|
||||
}
|
||||
|
||||
fn pixel(img: &Image, x: u32, y: u32) -> [u8; 4] {
|
||||
let i = (y * img.width + x) as usize * 4;
|
||||
[img.pixels[i], img.pixels[i + 1], img.pixels[i + 2], img.pixels[i + 3]]
|
||||
@@ -139,9 +207,23 @@ fn the_nearer_of_two_panels_shows_and_a_tie_goes_to_the_later_one() {
|
||||
assert_eq!(img.panel_at(80, 50), Some(1), "and in front on the right");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn nearly_parallel_panels_that_cross_use_depth_on_both_sides() {
|
||||
let angle = 5e-10f64;
|
||||
let (sin, cos) = angle.sin_cos();
|
||||
let tilted = Pose { m: [[cos, 0.0, sin], [0.0, 1.0, 0.0], [-sin, 0.0, cos]], t: [50.0 * (1.0 - cos), 0.0, 50.0 * sin] };
|
||||
let whole = || panel(vec![square(0.0, 0.0, 100.0, 100.0)]);
|
||||
for (poses, left, right) in [(vec![Pose::IDENTITY, tilted], 1, 0), (vec![tilted, Pose::IDENTITY], 0, 1)] {
|
||||
let (b, f) = scene_of(vec![whole(), whole()], poses);
|
||||
let img = render(&Scene { blank: &b, folded: &f, print: None, inside: [0, 0, 0, 255], outside: WHITE, camera: front() }).expect("drawn");
|
||||
assert_eq!(img.panel_at(25, 50), Some(left));
|
||||
assert_eq!(img.panel_at(75, 50), Some(right));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn of_two_parallel_panels_the_nearer_shows_however_close() {
|
||||
// 2 and 2.0001 points deep: a hair more than `TIE` apart once subtracted, though 2 + `TIE`
|
||||
// 2 and 2.0001 points deep: a hair more than 0.0001 apart once subtracted, though 2 + 0.0001
|
||||
// equals 2.0001. The panels lie in different planes, so the nearer shows whichever is drawn
|
||||
// first.
|
||||
let whole = || panel(vec![square(0.0, 0.0, 100.0, 100.0)]);
|
||||
@@ -167,24 +249,11 @@ fn a_scene_whose_panels_claim_any_depth_still_draws() {
|
||||
#[test]
|
||||
fn a_flap_folded_flat_lies_behind_the_print_at_180_and_in_front_at_minus_180() {
|
||||
// A 100 × 60 blank with a crease at x = 60: the flap (x 60 to 100) folds over onto the base.
|
||||
let poly = |pts: &[(f64, f64)], closed: bool| {
|
||||
PathData::single(SubPath::polyline(&pts.iter().map(|&(x, y)| Point::new(x, y)).collect::<Vec<_>>(), closed))
|
||||
};
|
||||
// Folds a hair short of flat lie on the same side, everywhere within a tie of the base.
|
||||
for (angle, flap_in_front) in [(180.0, false), (-180.0, true), (179.9999, false), (-179.9999, true)] {
|
||||
let lines = [
|
||||
super::super::FoldLine {
|
||||
path: poly(&[(0.0, 0.0), (100.0, 0.0), (100.0, 60.0), (0.0, 60.0)], true),
|
||||
kind: super::super::LineKind::Cut,
|
||||
key: 1,
|
||||
angle: None,
|
||||
},
|
||||
super::super::FoldLine {
|
||||
path: poly(&[(60.0, 0.0), (60.0, 60.0)], false),
|
||||
kind: super::super::LineKind::Crease,
|
||||
key: 2,
|
||||
angle: Some(angle),
|
||||
},
|
||||
fold_line(poly(&[(0.0, 0.0), (100.0, 0.0), (100.0, 60.0), (0.0, 60.0)], true), super::super::LineKind::Cut, 1, None),
|
||||
fold_line(poly(&[(60.0, 0.0), (60.0, 60.0)], false), super::super::LineKind::Crease, 2, Some(angle)),
|
||||
];
|
||||
let (blanks, issues) = super::super::blanks(&lines, 0.1);
|
||||
assert!(issues.is_empty(), "{issues:?}");
|
||||
@@ -211,22 +280,9 @@ fn a_flap_folded_flat_lies_behind_the_print_at_180_and_in_front_at_minus_180() {
|
||||
fn a_hinge_left_at_0_degrees_keeps_its_panel_level_with_its_parent() {
|
||||
// A 100 × 60 blank: the base (x 0 to 60), a strip (60 to 65) left flat at 0°, and a flap (65 to
|
||||
// 100) folded back at 180°, which lies behind the base from x 30 to 60.
|
||||
let poly = |pts: &[(f64, f64)], closed: bool| {
|
||||
PathData::single(SubPath::polyline(&pts.iter().map(|&(x, y)| Point::new(x, y)).collect::<Vec<_>>(), closed))
|
||||
};
|
||||
let crease = |x: f64, key: u64, angle: f64| super::super::FoldLine {
|
||||
path: poly(&[(x, 0.0), (x, 60.0)], false),
|
||||
kind: super::super::LineKind::Crease,
|
||||
key,
|
||||
angle: Some(angle),
|
||||
};
|
||||
let crease = |x: f64, key: u64, angle: f64| fold_line(poly(&[(x, 0.0), (x, 60.0)], false), super::super::LineKind::Crease, key, Some(angle));
|
||||
let lines = [
|
||||
super::super::FoldLine {
|
||||
path: poly(&[(0.0, 0.0), (100.0, 0.0), (100.0, 60.0), (0.0, 60.0)], true),
|
||||
kind: super::super::LineKind::Cut,
|
||||
key: 1,
|
||||
angle: None,
|
||||
},
|
||||
fold_line(poly(&[(0.0, 0.0), (100.0, 0.0), (100.0, 60.0), (0.0, 60.0)], true), super::super::LineKind::Cut, 1, None),
|
||||
crease(60.0, 2, 0.0),
|
||||
crease(65.0, 3, 180.0),
|
||||
];
|
||||
@@ -243,22 +299,9 @@ fn a_flap_folded_back_over_a_folded_panel_lies_between_it_and_the_base() {
|
||||
// A 110 × 60 strip: the base (x 0 to 60), a panel (60 to 100) folded back under the base at
|
||||
// 180°, and a flap (100 to 110) folded back at 180° from that panel, between it and the base, at
|
||||
// x 20 to 30.
|
||||
let poly = |pts: &[(f64, f64)], closed: bool| {
|
||||
PathData::single(SubPath::polyline(&pts.iter().map(|&(x, y)| Point::new(x, y)).collect::<Vec<_>>(), closed))
|
||||
};
|
||||
let crease = |x: f64, key: u64| super::super::FoldLine {
|
||||
path: poly(&[(x, 0.0), (x, 60.0)], false),
|
||||
kind: super::super::LineKind::Crease,
|
||||
key,
|
||||
angle: Some(180.0),
|
||||
};
|
||||
let crease = |x: f64, key: u64| fold_line(poly(&[(x, 0.0), (x, 60.0)], false), super::super::LineKind::Crease, key, Some(180.0));
|
||||
let lines = [
|
||||
super::super::FoldLine {
|
||||
path: poly(&[(0.0, 0.0), (110.0, 0.0), (110.0, 60.0), (0.0, 60.0)], true),
|
||||
kind: super::super::LineKind::Cut,
|
||||
key: 1,
|
||||
angle: None,
|
||||
},
|
||||
fold_line(poly(&[(0.0, 0.0), (110.0, 0.0), (110.0, 60.0), (0.0, 60.0)], true), super::super::LineKind::Cut, 1, None),
|
||||
crease(60.0, 2),
|
||||
crease(100.0, 3),
|
||||
];
|
||||
@@ -289,19 +332,9 @@ fn a_strip_far_from_the_origin_stacks_the_same_about_any_base() {
|
||||
let at = |x: f64, y: f64| Point::new(3_000_000.0 + (x - y) * s, 3_000_000.0 + (x + y) * s);
|
||||
let poly =
|
||||
|pts: &[(f64, f64)], closed: bool| PathData::single(SubPath::polyline(&pts.iter().map(|&(x, y)| at(x, y)).collect::<Vec<_>>(), closed));
|
||||
let crease = |x: f64, key: u64| super::super::FoldLine {
|
||||
path: poly(&[(x, 0.0), (x, 60.0)], false),
|
||||
kind: super::super::LineKind::Crease,
|
||||
key,
|
||||
angle: Some(180.0),
|
||||
};
|
||||
let crease = |x: f64, key: u64| fold_line(poly(&[(x, 0.0), (x, 60.0)], false), super::super::LineKind::Crease, key, Some(180.0));
|
||||
let lines = [
|
||||
super::super::FoldLine {
|
||||
path: poly(&[(0.0, 0.0), (110.0, 0.0), (110.0, 60.0), (0.0, 60.0)], true),
|
||||
kind: super::super::LineKind::Cut,
|
||||
key: 1,
|
||||
angle: None,
|
||||
},
|
||||
fold_line(poly(&[(0.0, 0.0), (110.0, 0.0), (110.0, 60.0), (0.0, 60.0)], true), super::super::LineKind::Cut, 1, None),
|
||||
crease(60.0, 2),
|
||||
crease(100.0, 3),
|
||||
];
|
||||
@@ -326,19 +359,9 @@ fn a_flat_stack_far_from_the_origin_stays_in_one_plane() {
|
||||
let poly = |pts: &[(f64, f64)], closed: bool| {
|
||||
PathData::single(SubPath::polyline(&pts.iter().map(|&(x, y)| Point::new(x0 + x, y)).collect::<Vec<_>>(), closed))
|
||||
};
|
||||
let crease = |x: f64, key: u64| super::super::FoldLine {
|
||||
path: poly(&[(x, 0.0), (x, 60.0)], false),
|
||||
kind: super::super::LineKind::Crease,
|
||||
key,
|
||||
angle: Some(180.0),
|
||||
};
|
||||
let crease = |x: f64, key: u64| fold_line(poly(&[(x, 0.0), (x, 60.0)], false), super::super::LineKind::Crease, key, Some(180.0));
|
||||
let lines = [
|
||||
super::super::FoldLine {
|
||||
path: poly(&[(0.0, 0.0), (135.0, 0.0), (135.0, 60.0), (0.0, 60.0)], true),
|
||||
kind: super::super::LineKind::Cut,
|
||||
key: 1,
|
||||
angle: None,
|
||||
},
|
||||
fold_line(poly(&[(0.0, 0.0), (135.0, 0.0), (135.0, 60.0), (0.0, 60.0)], true), super::super::LineKind::Cut, 1, None),
|
||||
crease(60.0, 2),
|
||||
crease(100.0, 3),
|
||||
];
|
||||
@@ -373,19 +396,9 @@ fn parallel_a_hair_behind(dx: f64, back: f64, w: f64) {
|
||||
let poly = |pts: &[(f64, f64)], closed: bool| {
|
||||
PathData::single(SubPath::polyline(&pts.iter().map(|&(x, y)| Point::new(x + dx, y)).collect::<Vec<_>>(), closed))
|
||||
};
|
||||
let crease = |x: f64, key: u64, angle: f64| super::super::FoldLine {
|
||||
path: poly(&[(x, 0.0), (x, 30.0)], false),
|
||||
kind: super::super::LineKind::Crease,
|
||||
key,
|
||||
angle: Some(angle),
|
||||
};
|
||||
let crease = |x: f64, key: u64, angle: f64| fold_line(poly(&[(x, 0.0), (x, 30.0)], false), super::super::LineKind::Crease, key, Some(angle));
|
||||
let lines = [
|
||||
super::super::FoldLine {
|
||||
path: poly(&[(0.0, 0.0), (130.0 + w, 0.0), (130.0 + w, 30.0), (0.0, 30.0)], true),
|
||||
kind: super::super::LineKind::Cut,
|
||||
key: 1,
|
||||
angle: None,
|
||||
},
|
||||
fold_line(poly(&[(0.0, 0.0), (130.0 + w, 0.0), (130.0 + w, 30.0), (0.0, 30.0)], true), super::super::LineKind::Cut, 1, None),
|
||||
crease(100.0, 2, 180.0 - back),
|
||||
crease(100.0 + w, 3, back),
|
||||
];
|
||||
@@ -414,18 +427,8 @@ fn a_small_blank_folded_near_flat_draws_the_same_far_from_the_origin() {
|
||||
PathData::single(SubPath::polyline(&pts.iter().map(|&(x, y)| Point::new(x + at, y + at)).collect::<Vec<_>>(), closed))
|
||||
};
|
||||
let lines = [
|
||||
super::super::FoldLine {
|
||||
path: poly(&[(0.0, 0.0), (4.0, 0.0), (4.0, 1.0), (0.0, 1.0)], true),
|
||||
kind: super::super::LineKind::Cut,
|
||||
key: 1,
|
||||
angle: None,
|
||||
},
|
||||
super::super::FoldLine {
|
||||
path: poly(&[(2.0, 0.0), (2.0, 1.0)], false),
|
||||
kind: super::super::LineKind::Crease,
|
||||
key: 2,
|
||||
angle: Some(179.999999),
|
||||
},
|
||||
fold_line(poly(&[(0.0, 0.0), (4.0, 0.0), (4.0, 1.0), (0.0, 1.0)], true), super::super::LineKind::Cut, 1, None),
|
||||
fold_line(poly(&[(2.0, 0.0), (2.0, 1.0)], false), super::super::LineKind::Crease, 2, Some(179.999999)),
|
||||
];
|
||||
let (blanks, issues) = super::super::blanks(&lines, 0.0001);
|
||||
assert!(issues.is_empty(), "{issues:?}");
|
||||
@@ -448,23 +451,10 @@ fn a_small_blank_folded_near_flat_draws_the_same_far_from_the_origin() {
|
||||
fn a_blank_lying_flat_takes_its_ranks_from_the_order_alone() {
|
||||
// A strip of 64 panels, each crease at 180°, not yet folded: no panel overlaps another, so no
|
||||
// layer is worked out.
|
||||
let poly = |pts: &[(f64, f64)], closed: bool| {
|
||||
PathData::single(SubPath::polyline(&pts.iter().map(|&(x, y)| Point::new(x, y)).collect::<Vec<_>>(), closed))
|
||||
};
|
||||
let mut lines = vec![super::super::FoldLine {
|
||||
path: poly(&[(0.0, 0.0), (640.0, 0.0), (640.0, 10.0), (0.0, 10.0)], true),
|
||||
kind: super::super::LineKind::Cut,
|
||||
key: 1,
|
||||
angle: None,
|
||||
}];
|
||||
let mut lines = vec![fold_line(poly(&[(0.0, 0.0), (640.0, 0.0), (640.0, 10.0), (0.0, 10.0)], true), super::super::LineKind::Cut, 1, None)];
|
||||
for i in 1..64u32 {
|
||||
let x = f64::from(i) * 10.0;
|
||||
lines.push(super::super::FoldLine {
|
||||
path: poly(&[(x, 0.0), (x, 10.0)], false),
|
||||
kind: super::super::LineKind::Crease,
|
||||
key: u64::from(i) + 1,
|
||||
angle: Some(180.0),
|
||||
});
|
||||
lines.push(fold_line(poly(&[(x, 0.0), (x, 10.0)], false), super::super::LineKind::Crease, u64::from(i) + 1, Some(180.0)));
|
||||
}
|
||||
let (blanks, issues) = super::super::blanks(&lines, 0.1);
|
||||
assert!(issues.is_empty(), "{issues:?}");
|
||||
@@ -479,23 +469,12 @@ fn round_a_loop_of_panels_the_stack_follows_the_hinges_that_placed_them() {
|
||||
// point. The crease that closes the loop when folded about the largest panel folds at 180° and
|
||||
// the rest at 0°; folded about a panel on that crease, the crease is in the tree and its flap
|
||||
// lies flat behind the panel.
|
||||
let poly = |pts: &[(f64, f64)], closed: bool| {
|
||||
PathData::single(SubPath::polyline(&pts.iter().map(|&(x, y)| Point::new(x, y)).collect::<Vec<_>>(), closed))
|
||||
};
|
||||
let lines = |flat_key: Option<u64>| {
|
||||
let crease = |from: (f64, f64), to: (f64, f64), key: u64| super::super::FoldLine {
|
||||
path: poly(&[from, to], false),
|
||||
kind: super::super::LineKind::Crease,
|
||||
key,
|
||||
angle: Some(if Some(key) == flat_key { 180.0 } else { 0.0 }),
|
||||
let crease = |from: (f64, f64), to: (f64, f64), key: u64| {
|
||||
fold_line(poly(&[from, to], false), super::super::LineKind::Crease, key, Some(if Some(key) == flat_key { 180.0 } else { 0.0 }))
|
||||
};
|
||||
vec![
|
||||
super::super::FoldLine {
|
||||
path: poly(&[(0.0, 0.0), (100.0, 0.0), (100.0, 100.0), (0.0, 100.0)], true),
|
||||
kind: super::super::LineKind::Cut,
|
||||
key: 1,
|
||||
angle: None,
|
||||
},
|
||||
fold_line(poly(&[(0.0, 0.0), (100.0, 0.0), (100.0, 100.0), (0.0, 100.0)], true), super::super::LineKind::Cut, 1, None),
|
||||
crease((50.0, 0.0), (50.0, 50.0), 2),
|
||||
crease((50.0, 50.0), (50.0, 100.0), 3),
|
||||
crease((0.0, 50.0), (50.0, 50.0), 4),
|
||||
@@ -531,22 +510,16 @@ fn round_a_flat_loop_the_stack_is_the_same_whichever_tree_reaches_the_flaps() {
|
||||
// folded back at 180° off the top right panel: the first (x 100 to 130) under that panel, the
|
||||
// tip (130 to 140) between the two. Folded about the tip, the tree reaches the grid another way,
|
||||
// and the stack stays as it is about the largest panel.
|
||||
let poly = |pts: &[(f64, f64)], closed: bool| {
|
||||
PathData::single(SubPath::polyline(&pts.iter().map(|&(x, y)| Point::new(x, y)).collect::<Vec<_>>(), closed))
|
||||
};
|
||||
let crease = |from: (f64, f64), to: (f64, f64), key: u64, angle: f64| super::super::FoldLine {
|
||||
path: poly(&[from, to], false),
|
||||
kind: super::super::LineKind::Crease,
|
||||
key,
|
||||
angle: Some(angle),
|
||||
let crease = |from: (f64, f64), to: (f64, f64), key: u64, angle: f64| {
|
||||
fold_line(poly(&[from, to], false), super::super::LineKind::Crease, key, Some(angle))
|
||||
};
|
||||
let lines = [
|
||||
super::super::FoldLine {
|
||||
path: poly(&[(0.0, 0.0), (140.0, 0.0), (140.0, 40.0), (100.0, 40.0), (100.0, 100.0), (0.0, 100.0)], true),
|
||||
kind: super::super::LineKind::Cut,
|
||||
key: 1,
|
||||
angle: None,
|
||||
},
|
||||
fold_line(
|
||||
poly(&[(0.0, 0.0), (140.0, 0.0), (140.0, 40.0), (100.0, 40.0), (100.0, 100.0), (0.0, 100.0)], true),
|
||||
super::super::LineKind::Cut,
|
||||
1,
|
||||
None,
|
||||
),
|
||||
crease((60.0, 0.0), (60.0, 40.0), 2, 0.0),
|
||||
crease((60.0, 40.0), (60.0, 100.0), 3, 0.0),
|
||||
crease((0.0, 40.0), (60.0, 40.0), 4, 0.0),
|
||||
@@ -570,10 +543,7 @@ fn round_a_flat_loop_the_stack_is_the_same_whichever_tree_reaches_the_flaps() {
|
||||
fn two_flaps_folded_flat_behind_the_base_show_opposite_ones_from_each_side() {
|
||||
// The base (x 30 to 80) with a window (52 to 58), a flap on each side folded back at 180°: the
|
||||
// left one to x 30 to 60, the right one to 50 to 80, so both lie behind the window.
|
||||
let poly = |pts: &[(f64, f64)], closed: bool| {
|
||||
PathData::single(SubPath::polyline(&pts.iter().map(|&(x, y)| Point::new(x, y)).collect::<Vec<_>>(), closed))
|
||||
};
|
||||
let line = |pts: &[(f64, f64)], closed: bool, kind, key, angle| super::super::FoldLine { path: poly(pts, closed), kind, key, angle };
|
||||
|
||||
use super::super::LineKind::{Crease, Cut};
|
||||
let lines = [
|
||||
line(&[(0.0, 0.0), (110.0, 0.0), (110.0, 60.0), (0.0, 60.0)], true, Cut, 1, None),
|
||||
@@ -598,10 +568,7 @@ fn two_flaps_folded_flat_behind_the_base_show_opposite_ones_from_each_side() {
|
||||
fn a_flap_split_by_a_0_degree_crease_stacks_as_one_against_another_flap() {
|
||||
// The base (x 30 to 90), a right flap (90 to 140) folded back to 40 to 90, and a left flap (0 to
|
||||
// 30) folded back to 30 to 60 in two parts joined at 0° (x 15), both parts over the right flap.
|
||||
let poly = |pts: &[(f64, f64)], closed: bool| {
|
||||
PathData::single(SubPath::polyline(&pts.iter().map(|&(x, y)| Point::new(x, y)).collect::<Vec<_>>(), closed))
|
||||
};
|
||||
let line = |pts: &[(f64, f64)], closed: bool, kind, key, angle| super::super::FoldLine { path: poly(pts, closed), kind, key, angle };
|
||||
|
||||
use super::super::LineKind::{Crease, Cut};
|
||||
let lines = [
|
||||
line(&[(0.0, 0.0), (140.0, 0.0), (140.0, 60.0), (0.0, 60.0)], true, Cut, 1, None),
|
||||
@@ -633,10 +600,7 @@ fn a_tip_folded_on_a_flap_stays_on_that_flap_s_side_of_another_flap() {
|
||||
// Left to right: a tip (x 0 to 20), a left flap (20 to 70), the base (70 to 140) and a right flap
|
||||
// (140 to 205). Both flaps fold back at 180° behind the base (to 70 to 120 and 75 to 140), and
|
||||
// the tip folds at -180° on the left flap (to 100 to 120), so the three overlap from 100 to 120.
|
||||
let poly = |pts: &[(f64, f64)], closed: bool| {
|
||||
PathData::single(SubPath::polyline(&pts.iter().map(|&(x, y)| Point::new(x, y)).collect::<Vec<_>>(), closed))
|
||||
};
|
||||
let line = |pts: &[(f64, f64)], closed: bool, kind, key, angle| super::super::FoldLine { path: poly(pts, closed), kind, key, angle };
|
||||
|
||||
use super::super::LineKind::{Crease, Cut};
|
||||
let lines = [
|
||||
line(&[(0.0, 0.0), (205.0, 0.0), (205.0, 60.0), (0.0, 60.0)], true, Cut, 1, None),
|
||||
@@ -665,10 +629,7 @@ fn a_tip_folded_on_a_flap_stays_on_that_flap_s_side_of_another_flap() {
|
||||
fn a_tip_folded_back_toward_a_folded_panel_s_print_covers_it_from_the_back() {
|
||||
// The base (x 0 to 60), a panel (60 to 100) folded back at 180° to 20 to 60, and a tip (100 to
|
||||
// 110) folded at -180° onto that panel's printed side, to 20 to 30, behind it from the front.
|
||||
let poly = |pts: &[(f64, f64)], closed: bool| {
|
||||
PathData::single(SubPath::polyline(&pts.iter().map(|&(x, y)| Point::new(x, y)).collect::<Vec<_>>(), closed))
|
||||
};
|
||||
let line = |pts: &[(f64, f64)], closed: bool, kind, key, angle| super::super::FoldLine { path: poly(pts, closed), kind, key, angle };
|
||||
|
||||
use super::super::LineKind::{Crease, Cut};
|
||||
// The same with the tip a hair short of flat, and with an 80 pt panel under a 100 pt base.
|
||||
for (middle, tip_angle) in [(40.0, -180.0), (40.0, -179.9999), (40.0, -179.999), (80.0, -179.9999), (1000.0, -179.999)] {
|
||||
@@ -697,10 +658,7 @@ fn overlapping_lid_flaps_keep_their_order_as_the_view_turns_on_one_side_of_the_l
|
||||
// A box strip: a left flap (x 0 to 60), a wall (60 to 100), the base (100 to 200), a wall (200 to
|
||||
// 240) and a right flap (240 to 300). The walls fold 90° down and the flaps 90° in, so the flaps
|
||||
// meet in one plane 40 pt below the base and overlap from x 140 to 160.
|
||||
let poly = |pts: &[(f64, f64)], closed: bool| {
|
||||
PathData::single(SubPath::polyline(&pts.iter().map(|&(x, y)| Point::new(x, y)).collect::<Vec<_>>(), closed))
|
||||
};
|
||||
let line = |pts: &[(f64, f64)], closed: bool, kind, key, angle| super::super::FoldLine { path: poly(pts, closed), kind, key, angle };
|
||||
|
||||
use super::super::LineKind::{Crease, Cut};
|
||||
let crease = |x: f64, key| line(&[(x, 0.0), (x, 60.0)], false, Crease, key, Some(90.0));
|
||||
let lines = [
|
||||
@@ -729,10 +687,7 @@ fn flaps_folded_onto_a_panel_keep_their_order_as_the_panel_tilts_either_way() {
|
||||
// The base (x 0 to 100, y -50 to 110) and a panel (100 to 200, 0 to 60) on a crease at x = 100,
|
||||
// with a flap above (y -40 to 0) and one below (60 to 100), each cut free of the base and folded
|
||||
// at -180° onto the panel's printed side, where they overlap from y 20 to 40.
|
||||
let poly = |pts: &[(f64, f64)], closed: bool| {
|
||||
PathData::single(SubPath::polyline(&pts.iter().map(|&(x, y)| Point::new(x, y)).collect::<Vec<_>>(), closed))
|
||||
};
|
||||
let line = |pts: &[(f64, f64)], closed: bool, kind, key, angle| super::super::FoldLine { path: poly(pts, closed), kind, key, angle };
|
||||
|
||||
use super::super::LineKind::{Crease, Cut};
|
||||
let shown = |tilt: f64| {
|
||||
let outline = [(0.0, -50.0), (100.0, -50.0), (100.0, -40.0), (200.0, -40.0), (200.0, 100.0), (100.0, 100.0), (100.0, 110.0), (0.0, 110.0)];
|
||||
@@ -752,9 +707,11 @@ fn flaps_folded_onto_a_panel_keep_their_order_as_the_panel_tilts_either_way() {
|
||||
let img = render(&Scene { blank: b, folded: &f, print: None, inside: [0, 0, 0, 255], outside: WHITE, camera }).expect("drawn");
|
||||
let flap = |y: f64| b.panels.iter().position(|p| p.outline.bounds().is_some_and(|r| (r.y0 - y).abs() < 1e-6 && r.x0 > 99.0));
|
||||
let shown = img.panel_at(100, 50);
|
||||
if shown == flap(-40.0) {
|
||||
let above = flap(-40.0).expect("the upper flap exists");
|
||||
let below = flap(60.0).expect("the lower flap exists");
|
||||
if shown == Some(above) {
|
||||
"above"
|
||||
} else if shown == flap(60.0) {
|
||||
} else if shown == Some(below) {
|
||||
"below"
|
||||
} else {
|
||||
"neither"
|
||||
@@ -769,10 +726,7 @@ fn flaps_folded_onto_a_panel_keep_their_order_as_the_panel_tilts_either_way() {
|
||||
fn a_flap_folded_onto_a_wall_standing_at_90_degrees_covers_its_print() {
|
||||
// The base (x 0 to 60), a wall (60 to 100) folded 90° and a flap (100 to 130) folded at -180°
|
||||
// onto the wall's printed side, where it covers the wall from 10 to 40 pt out from the base.
|
||||
let poly = |pts: &[(f64, f64)], closed: bool| {
|
||||
PathData::single(SubPath::polyline(&pts.iter().map(|&(x, y)| Point::new(x, y)).collect::<Vec<_>>(), closed))
|
||||
};
|
||||
let line = |pts: &[(f64, f64)], closed: bool, kind, key, angle| super::super::FoldLine { path: poly(pts, closed), kind, key, angle };
|
||||
|
||||
use super::super::LineKind::{Crease, Cut};
|
||||
let lines = [
|
||||
line(&[(0.0, 0.0), (130.0, 0.0), (130.0, 60.0), (0.0, 60.0)], true, Cut, 1, None),
|
||||
@@ -808,10 +762,7 @@ fn end_flaps_seen_straight_through_an_open_carton_show_opposite_ones_from_each_s
|
||||
// The base (x 40 to 140, y 0 to 60) and a side wall on each side (0 to 40 and 140 to 180), each
|
||||
// with an end flap (y 60 to 160) that folds in across the carton's end, so both flaps cover
|
||||
// the same 100 pt. Looking straight through that end, the base and walls are edge on.
|
||||
let poly = |pts: &[(f64, f64)], closed: bool| {
|
||||
PathData::single(SubPath::polyline(&pts.iter().map(|&(x, y)| Point::new(x, y)).collect::<Vec<_>>(), closed))
|
||||
};
|
||||
let line = |pts: &[(f64, f64)], closed: bool, kind, key, angle| super::super::FoldLine { path: poly(pts, closed), kind, key, angle };
|
||||
|
||||
use super::super::LineKind::{Crease, Cut};
|
||||
let outline = [(0.0, 0.0), (180.0, 0.0), (180.0, 160.0), (140.0, 160.0), (140.0, 60.0), (40.0, 60.0), (40.0, 160.0), (0.0, 160.0)];
|
||||
let lines = [
|
||||
@@ -853,10 +804,7 @@ fn end_flaps_seen_straight_through_an_open_carton_show_opposite_ones_from_each_s
|
||||
fn a_flap_looped_round_onto_the_base_shows_from_the_side_it_came_from() {
|
||||
// A strip: the base (x 0 to 100) and panels 40, 60, 40 and 80 pt wide, folded 90°, -90°, -90°
|
||||
// and -90°, so the last one comes round and lies on the base's plane over part of it.
|
||||
let poly = |pts: &[(f64, f64)], closed: bool| {
|
||||
PathData::single(SubPath::polyline(&pts.iter().map(|&(x, y)| Point::new(x, y)).collect::<Vec<_>>(), closed))
|
||||
};
|
||||
let line = |pts: &[(f64, f64)], closed: bool, kind, key, angle| super::super::FoldLine { path: poly(pts, closed), kind, key, angle };
|
||||
|
||||
use super::super::LineKind::{Crease, Cut};
|
||||
let lines = [
|
||||
line(&[(0.0, 0.0), (320.0, 0.0), (320.0, 60.0), (0.0, 60.0)], true, Cut, 1, None),
|
||||
@@ -895,13 +843,9 @@ fn a_strip_wrapped_round_a_wall_lands_its_flap_on_the_print_side_it_came_from()
|
||||
// flap folds from stands on the printed side of the base, and the flap lands on the base at x
|
||||
// 50 to 80. With `tab`, the wall also runs on past the flap's hinge (to x 340, y 30 to 60),
|
||||
// through the base's plane, which moves its middle to the other side of that plane.
|
||||
let poly = |pts: &[(f64, f64)], closed: bool| {
|
||||
PathData::single(SubPath::polyline(&pts.iter().map(|&(x, y)| Point::new(x, y)).collect::<Vec<_>>(), closed))
|
||||
};
|
||||
// With `cutout` of 5, a 10 pt hole on the middle of each crease breaks every hinge in two; with
|
||||
// a larger one, the hole runs to within 2 pt of each end, as wide as `cutout` either side.
|
||||
let shown = |tab: bool, cutout: f64| {
|
||||
let line = |pts: &[(f64, f64)], closed: bool, kind, key, angle| super::super::FoldLine { path: poly(pts, closed), kind, key, angle };
|
||||
use super::super::LineKind::{Crease, Cut};
|
||||
let mut lines = if tab {
|
||||
vec![
|
||||
@@ -963,9 +907,6 @@ fn a_flap_that_comes_down_onto_the_base_at_a_shallow_angle_lands_on_the_side_it_
|
||||
// 20 pt wide back level, one up through the base's plane to `drop` in front of it, a ramp
|
||||
// `ramp` wide that comes back down to the base's plane over its width, and a flap (30 pt) that
|
||||
// lies on the base from where the ramp ends.
|
||||
let poly = |pts: &[(f64, f64)], closed: bool| {
|
||||
PathData::single(SubPath::polyline(&pts.iter().map(|&(x, y)| Point::new(x, y)).collect::<Vec<_>>(), closed))
|
||||
};
|
||||
let shown = |base: f64, ramp: f64, drop: f64| {
|
||||
// To the millionth of a degree a line keeps, and the drop that ramp comes down by.
|
||||
let tilt = super::super::kept_angle((drop / ramp).asin().to_degrees());
|
||||
@@ -973,19 +914,9 @@ fn a_flap_that_comes_down_onto_the_base_at_a_shallow_angle_lands_on_the_side_it_
|
||||
let up = base + 30.0;
|
||||
let creases = [(base, 90.0), (base + 10.0, -90.0), (up, -90.0), (up + 10.0 + drop, -90.0 - tilt), (up + 10.0 + drop + ramp, tilt)];
|
||||
let end = up + 10.0 + drop + ramp + 30.0;
|
||||
let mut lines = vec![super::super::FoldLine {
|
||||
path: poly(&[(0.0, 0.0), (end, 0.0), (end, 30.0), (0.0, 30.0)], true),
|
||||
kind: super::super::LineKind::Cut,
|
||||
key: 1,
|
||||
angle: None,
|
||||
}];
|
||||
let mut lines = vec![fold_line(poly(&[(0.0, 0.0), (end, 0.0), (end, 30.0), (0.0, 30.0)], true), super::super::LineKind::Cut, 1, None)];
|
||||
for (i, (x, a)) in creases.into_iter().enumerate() {
|
||||
lines.push(super::super::FoldLine {
|
||||
path: poly(&[(x, 0.0), (x, 30.0)], false),
|
||||
kind: super::super::LineKind::Crease,
|
||||
key: 2 + i as u64,
|
||||
angle: Some(a),
|
||||
});
|
||||
lines.push(fold_line(poly(&[(x, 0.0), (x, 30.0)], false), super::super::LineKind::Crease, 2 + i as u64, Some(a)));
|
||||
}
|
||||
let (blanks, issues) = super::super::blanks(&lines, 0.0001);
|
||||
assert!(issues.is_empty(), "{issues:?}");
|
||||
@@ -1021,23 +952,10 @@ fn a_flap_brought_back_by_folds_all_near_flat_lands_on_the_side_its_ramp_came_fr
|
||||
}
|
||||
|
||||
fn flap_brought_back_by_folds_all_near_flat(tilt: f64) {
|
||||
let poly = |pts: &[(f64, f64)], closed: bool| {
|
||||
PathData::single(SubPath::polyline(&pts.iter().map(|&(x, y)| Point::new(x, y)).collect::<Vec<_>>(), closed))
|
||||
};
|
||||
let creases = [(1000.0, tilt), (1100.0, 180.0), (1400.0, -2.0 * tilt), (1600.0, tilt)];
|
||||
let mut lines = vec![super::super::FoldLine {
|
||||
path: poly(&[(0.0, 0.0), (1650.0, 0.0), (1650.0, 30.0), (0.0, 30.0)], true),
|
||||
kind: super::super::LineKind::Cut,
|
||||
key: 1,
|
||||
angle: None,
|
||||
}];
|
||||
let mut lines = vec![fold_line(poly(&[(0.0, 0.0), (1650.0, 0.0), (1650.0, 30.0), (0.0, 30.0)], true), super::super::LineKind::Cut, 1, None)];
|
||||
for (i, (x, a)) in creases.into_iter().enumerate() {
|
||||
lines.push(super::super::FoldLine {
|
||||
path: poly(&[(x, 0.0), (x, 30.0)], false),
|
||||
kind: super::super::LineKind::Crease,
|
||||
key: 2 + i as u64,
|
||||
angle: Some(a),
|
||||
});
|
||||
lines.push(fold_line(poly(&[(x, 0.0), (x, 30.0)], false), super::super::LineKind::Crease, 2 + i as u64, Some(a)));
|
||||
}
|
||||
let (blanks, issues) = super::super::blanks(&lines, 0.0001);
|
||||
assert!(issues.is_empty(), "{issues:?}");
|
||||
@@ -1067,10 +985,7 @@ fn flap_brought_back_by_folds_all_near_flat(tilt: f64) {
|
||||
fn a_strip_wrapped_round_onto_a_panel_that_is_not_the_base_lands_on_the_side_it_came_from() {
|
||||
// The strip of the test above, with a larger base (x -150 to 0) on the left that the strip's
|
||||
// first panel (0 to 100) stands up from at -90°. The flap lands on that panel's printed side.
|
||||
let poly = |pts: &[(f64, f64)], closed: bool| {
|
||||
PathData::single(SubPath::polyline(&pts.iter().map(|&(x, y)| Point::new(x, y)).collect::<Vec<_>>(), closed))
|
||||
};
|
||||
let line = |pts: &[(f64, f64)], closed: bool, kind, key, angle| super::super::FoldLine { path: poly(pts, closed), kind, key, angle };
|
||||
|
||||
use super::super::LineKind::{Crease, Cut};
|
||||
let mut lines = vec![line(&[(-150.0, 0.0), (270.0, 0.0), (270.0, 30.0), (240.0, 30.0), (240.0, 60.0), (-150.0, 60.0)], true, Cut, 1, None)];
|
||||
lines.push(line(&[(0.0, 0.0), (0.0, 60.0)], false, Crease, 2, Some(-90.0)));
|
||||
@@ -1103,24 +1018,11 @@ fn a_strip_wrapped_round_onto_a_panel_that_is_not_the_base_lands_on_the_side_it_
|
||||
fn a_strip_rolled_up_45_times_keeps_the_base_in_front() {
|
||||
// A strip: the base (x 0 to 60) and 45 panels 50 pt wide, every crease folded back at 180°, so
|
||||
// each panel rolls under the one before it and all of them lie behind the base.
|
||||
let poly = |pts: &[(f64, f64)], closed: bool| {
|
||||
PathData::single(SubPath::polyline(&pts.iter().map(|&(x, y)| Point::new(x, y)).collect::<Vec<_>>(), closed))
|
||||
};
|
||||
let end = 60.0 + 45.0 * 50.0;
|
||||
let mut lines = vec![super::super::FoldLine {
|
||||
path: poly(&[(0.0, 0.0), (end, 0.0), (end, 60.0), (0.0, 60.0)], true),
|
||||
kind: super::super::LineKind::Cut,
|
||||
key: 1,
|
||||
angle: None,
|
||||
}];
|
||||
let mut lines = vec![fold_line(poly(&[(0.0, 0.0), (end, 0.0), (end, 60.0), (0.0, 60.0)], true), super::super::LineKind::Cut, 1, None)];
|
||||
lines.extend((0u32..45).map(|i| {
|
||||
let x = 60.0 + 50.0 * f64::from(i);
|
||||
super::super::FoldLine {
|
||||
path: poly(&[(x, 0.0), (x, 60.0)], false),
|
||||
kind: super::super::LineKind::Crease,
|
||||
key: 10 + u64::from(i),
|
||||
angle: Some(180.0),
|
||||
}
|
||||
fold_line(poly(&[(x, 0.0), (x, 60.0)], false), super::super::LineKind::Crease, 10 + u64::from(i), Some(180.0))
|
||||
}));
|
||||
let (blanks, issues) = super::super::blanks(&lines, 0.1);
|
||||
assert!(issues.is_empty(), "{issues:?}");
|
||||
@@ -1135,21 +1037,8 @@ fn hinges_left_at_0_degrees_before_two_folds_back_do_not_use_up_layers() {
|
||||
// A 155 × 60 strip: the base (x 0 to 60), 45 strips 1 pt wide left flat at 0°, a panel (105 to
|
||||
// 145) folded back at 180° and a flap (145 to 155) folded back at 180° from it, which lies
|
||||
// behind the flat strips at x 65 to 75.
|
||||
let poly = |pts: &[(f64, f64)], closed: bool| {
|
||||
PathData::single(SubPath::polyline(&pts.iter().map(|&(x, y)| Point::new(x, y)).collect::<Vec<_>>(), closed))
|
||||
};
|
||||
let crease = |x: f64, key: u64, angle: f64| super::super::FoldLine {
|
||||
path: poly(&[(x, 0.0), (x, 60.0)], false),
|
||||
kind: super::super::LineKind::Crease,
|
||||
key,
|
||||
angle: Some(angle),
|
||||
};
|
||||
let mut lines = vec![super::super::FoldLine {
|
||||
path: poly(&[(0.0, 0.0), (155.0, 0.0), (155.0, 60.0), (0.0, 60.0)], true),
|
||||
kind: super::super::LineKind::Cut,
|
||||
key: 1,
|
||||
angle: None,
|
||||
}];
|
||||
let crease = |x: f64, key: u64, angle: f64| fold_line(poly(&[(x, 0.0), (x, 60.0)], false), super::super::LineKind::Crease, key, Some(angle));
|
||||
let mut lines = vec![fold_line(poly(&[(0.0, 0.0), (155.0, 0.0), (155.0, 60.0), (0.0, 60.0)], true), super::super::LineKind::Cut, 1, None)];
|
||||
lines.extend((0u32..45).map(|i| crease(60.0 + f64::from(i), 10 + u64::from(i), 0.0)));
|
||||
lines.push(crease(105.0, 2, 180.0));
|
||||
lines.push(crease(145.0, 3, 180.0));
|
||||
|
||||
@@ -16953,6 +16953,13 @@ turn about and `closing` for the others. `collisions` lists the panels that pass
|
||||
one plane, such as the top flaps of a closed box, are not listed. Without a blank (`ok` false), `blank` and `base` are
|
||||
null and the lists are empty; `issues` are those of `addon.packaging.check`.
|
||||
|
||||
Overlapping panels in one plane stack according to the fold tree from the largest panel. Choosing another base
|
||||
preserves that order when both trees place the panels in the same positions. Every member of a coplanar group must
|
||||
match every other member. The group uses one comparison depth, and its panels stack by rank at that depth. Panels in
|
||||
different planes draw by depth, with the plane number resolving an exact crossing. Nearly parallel panels that cross
|
||||
draw by depth on each side of the intersection. A hinge uses the role of the line
|
||||
with the most total length along it; the lowest line id wins a tie.
|
||||
|
||||
The Fold Preview window (Object › Plug-ins › Packaging Tools › Fold Preview, or the Fold Lines panel's Fold Preview
|
||||
button) shows the blank that the document's shown fold lines make, folded, with the document's printed art on the
|
||||
outside of each panel and the board's inside color on the back. The print leaves out the fold lines, unless Show Fold
|
||||
|
||||
@@ -47,8 +47,8 @@ XMP array insertion with `XMPConst.ARRAY_LAST_ITEM` precedes the last existing i
|
||||
|
||||
XMP parsing rejects invalid qualified names, text other than XML whitespace beside descriptions or properties, and conflicting explicit `rdf:about` values, including empty values. Packet scanning skips other processing instructions inside a packet. Packet padding requires a real wrapper trailer and allows leading XML declarations, comments, and processing instructions. Array appends charge their added bytes without scanning existing items, and indexed property reads copy only the selected value. Pending packets count once toward the heap limit. ES5 and ES2015 library installation checks every published member against that limit. Failed serialization and packet-info scans consume fuel. Sidecar writes allow packets up to VectorCraft's 8 MiB packet limit through the host binding.
|
||||
|
||||
- Fold Preview orders overlapping coplanar panels by their fold tree, draws distinct planes and crossing panels by depth, and calculates poses relative to the blank's center. Each plane uses one comparison depth, and every member of a plane group must match every other member. A hinge uses its longest line across all split pieces. Tests cover flat, near-flat, nested and offset folds in `crates/three-d/src/fold/tests.rs` and `crates/three-d/src/fold/raster/tests.rs`.
|
||||
- `addon.packaging.setFoldAngle` stores or resets individual fold angles for editable Crease, Partial Cut, and Perforation lines. The fold commands read those angles, and role queries report their shared value and stored-angle counts. Engine tests cover validation, locked compound members, one-step undo, native save, and SVG exports.
|
||||
|
||||
`vectorcraft-js` ends a paused or waiting run before `Realm::run` or `Realm::start` compiles new source. Its globals remain available. The earlier run's remaining code and queued jobs do not run. Regressions in `crates/js/src/host_tests.rs` cover paused scripts, Promise reactions, waiting host calls, invalid replacement source, and deferred language settings.
|
||||
|
||||
Scripts: `Promise.prototype[Symbol.toStringTag]` is `"Promise"` when Symbols are available, with a configurable, non-enumerable, non-writable descriptor. Promise instances report `[object Promise]` in engines without Symbols. Test: `promise_prototype_has_a_configurable_string_tag` in `crates/js/src/promise_tests.rs`.
|
||||
|
||||
Reference in new issue
Block a user