mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-25 22:39:07 +00:00
Merge pull request #8206 from dotCooCoo/feat/packaging-fold-preview
Packaging Tools: Fold Preview folds the blank in 3D with the printed art on its panels
This commit is contained in:
@@ -821,6 +821,8 @@ pub(crate) fn unique_name_from(base: &str, next: &mut std::collections::HashMap<
|
||||
pub(crate) const MAX_IMPORTED_PRESETS: usize = 1000;
|
||||
|
||||
pub(crate) use addons::{DecodedImages, refresh_color_masks};
|
||||
/// Packaging Tools' blanks and the objects their print leaves out, for the Fold Preview window.
|
||||
pub use addons::{fold_source, print_hidden};
|
||||
/// Document Info's category titles and the Objects category's count labels.
|
||||
pub use docinfo::{CATEGORIES, OBJECT_LABELS};
|
||||
pub use docmenu::guide_indexes;
|
||||
|
||||
@@ -17,6 +17,7 @@ mod typetools;
|
||||
mod units;
|
||||
|
||||
pub(crate) use image::{DecodedImages, refresh_color_masks};
|
||||
pub use packaging::{fold_source, print_hidden};
|
||||
pub(crate) use packaging::{role_swatch_edited, role_swatches_merged};
|
||||
|
||||
use super::CommandSpec;
|
||||
|
||||
@@ -6,8 +6,10 @@
|
||||
//! (Object › Plug-ins › Packaging Tools) and its Fold Lines panel are the UI's.
|
||||
|
||||
mod check;
|
||||
mod fold;
|
||||
mod roles;
|
||||
|
||||
pub use fold::{fold_source, print_hidden};
|
||||
pub(crate) use roles::{role_swatch_edited, role_swatches_merged};
|
||||
|
||||
use super::super::CommandSpec;
|
||||
@@ -15,6 +17,7 @@ use super::super::CommandSpec;
|
||||
pub fn specs() -> Vec<CommandSpec> {
|
||||
let mut v = roles::specs();
|
||||
v.extend(check::specs());
|
||||
v.extend(fold::specs());
|
||||
v
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
use serde_json::{Value, json};
|
||||
use vectorcraft_doc::{Document, Node, NodeId, NodeKind};
|
||||
use vectorcraft_geom::PathData;
|
||||
use vectorcraft_three_d::fold::{FoldLine, IssueCode, LineKind, MAX_SEGMENTS, blanks};
|
||||
use vectorcraft_three_d::fold::{Blank, FoldLine, Issue, IssueCode, LineKind, MAX_SEGMENTS, blanks};
|
||||
|
||||
use super::super::super::pathops::length_given;
|
||||
use super::super::super::{CommandSpec, bad, checked_ids_or_selection, cmd, has_doc, switch_or};
|
||||
@@ -14,7 +14,7 @@ use crate::{Result, Session};
|
||||
const CHECK: &str = "addon.packaging.check";
|
||||
|
||||
/// How far apart the ends of two lines may be and still be joined, in points.
|
||||
const TOLERANCE: (f64, f64, f64) = (0.01, 0.1, 10.0);
|
||||
pub(super) const TOLERANCE: (f64, f64, f64) = (0.01, 0.1, 10.0);
|
||||
|
||||
pub fn specs() -> Vec<CommandSpec> {
|
||||
vec![cmd!(
|
||||
@@ -101,23 +101,44 @@ fn kind(role: Role) -> LineKind {
|
||||
}
|
||||
}
|
||||
|
||||
fn check(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let select = switch_or(p, "select", false, CHECK)?;
|
||||
let tolerance = match length_given(p, "tolerance", CHECK)? {
|
||||
None => TOLERANCE.1,
|
||||
Some(t) if (TOLERANCE.0..=TOLERANCE.2).contains(&t) => t,
|
||||
Some(_) => return Err(bad(CHECK, format!("`tolerance` must be from {} to {} pt", TOLERANCE.0, TOLERANCE.2))),
|
||||
};
|
||||
/// The fold lines a check or a fold reads: where they came from (`ids`, `selection` or
|
||||
/// `document`), the lines, and the ids of those on a non-printing layer.
|
||||
pub(super) struct Lines {
|
||||
pub scope: &'static str,
|
||||
pub lines: Vec<FoldLine>,
|
||||
pub non_printing: Vec<u64>,
|
||||
}
|
||||
|
||||
/// The tolerance `p` gives for `cmd`, or the default.
|
||||
pub(super) fn tolerance(p: &Value, cmd: &str) -> Result<f64> {
|
||||
match length_given(p, "tolerance", cmd)? {
|
||||
None => Ok(TOLERANCE.1),
|
||||
Some(t) if (TOLERANCE.0..=TOLERANCE.2).contains(&t) => Ok(t),
|
||||
Some(_) => Err(bad(cmd, format!("`tolerance` must be from {} to {} pt", TOLERANCE.0, TOLERANCE.2))),
|
||||
}
|
||||
}
|
||||
|
||||
/// The fold lines among the objects `p` names for `cmd` (`ids`, else the selection), or, while
|
||||
/// nothing is selected and `ids` is left out, every shown fold line of the document. Hidden lines
|
||||
/// are left out in every scope, members of a selected group included.
|
||||
pub(super) fn lines(s: &Session, p: &Value, cmd: &str) -> Result<Lines> {
|
||||
let given = p.get("ids").is_some_and(|v| !v.is_null());
|
||||
let roots = checked_ids_or_selection(s, p, CHECK)?;
|
||||
let roots = checked_ids_or_selection(s, p, cmd)?;
|
||||
let d = &s.doc()?.doc;
|
||||
// Hidden lines are left out in every scope, members of a selected group included.
|
||||
let shown = |ids: Vec<NodeId>| ids.into_iter().filter(|id| d.is_visible(*id)).collect::<Vec<_>>();
|
||||
let (scope, targets) = match (given, roots.is_empty()) {
|
||||
(true, _) => ("ids", shown(role_targets(d, &roots, false).0)),
|
||||
(false, false) => ("selection", shown(role_targets(d, &roots, false).0)),
|
||||
(false, true) => ("document", shown_targets(d)),
|
||||
};
|
||||
Ok(match (given, roots.is_empty()) {
|
||||
(true, _) => lines_of(d, "ids", shown(role_targets(d, &roots, false).0)),
|
||||
(false, false) => lines_of(d, "selection", shown(role_targets(d, &roots, false).0)),
|
||||
(false, true) => document_lines(d),
|
||||
})
|
||||
}
|
||||
|
||||
/// Every shown fold line of `d`.
|
||||
pub(super) fn document_lines(d: &Document) -> Lines {
|
||||
lines_of(d, "document", shown_targets(d))
|
||||
}
|
||||
|
||||
fn lines_of(d: &Document, scope: &'static str, targets: Vec<NodeId>) -> Lines {
|
||||
let table = RoleTable::of(d);
|
||||
let mut lines = vec![];
|
||||
let mut non_printing = vec![];
|
||||
@@ -136,12 +157,21 @@ fn check(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
segments = segments.saturating_add(path.subpaths.iter().map(|sp| sp.segment_count()).sum());
|
||||
lines.push(FoldLine { path, kind: kind(role), key: id.0 });
|
||||
}
|
||||
let (found, mut issues) = blanks(&lines, tolerance);
|
||||
if !non_printing.is_empty() {
|
||||
issues.push(vectorcraft_three_d::fold::Issue { code: IssueCode::NonPrinting, keys: non_printing, at: None });
|
||||
Lines { scope, lines, non_printing }
|
||||
}
|
||||
|
||||
/// The blanks `lines` make and their issues, the non-printing one last.
|
||||
pub(super) fn found(lines: &Lines, tolerance: f64) -> (Vec<Blank>, Vec<Issue>) {
|
||||
let (found, mut issues) = blanks(&lines.lines, tolerance);
|
||||
if !lines.non_printing.is_empty() {
|
||||
issues.push(Issue { code: IssueCode::NonPrinting, keys: lines.non_printing.clone(), at: None });
|
||||
}
|
||||
let ok = !issues.iter().any(|i| i.code.is_error());
|
||||
let rows: Vec<Value> = issues
|
||||
(found, issues)
|
||||
}
|
||||
|
||||
/// `issues` as the rows `addon.packaging.check` and `addon.packaging.fold` answer with.
|
||||
pub(super) fn issue_rows(issues: &[Issue], scope: &str) -> Vec<Value> {
|
||||
issues
|
||||
.iter()
|
||||
.map(|i| {
|
||||
let mut row = json!({
|
||||
@@ -155,7 +185,18 @@ fn check(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
}
|
||||
row
|
||||
})
|
||||
.collect();
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn check(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let select = switch_or(p, "select", false, CHECK)?;
|
||||
let tolerance = tolerance(p, CHECK)?;
|
||||
let lines = lines(s, p, CHECK)?;
|
||||
let scope = lines.scope;
|
||||
let (found, issues) = found(&lines, tolerance);
|
||||
let d = &s.doc()?.doc;
|
||||
let ok = !issues.iter().any(|i| i.code.is_error());
|
||||
let rows = issue_rows(&issues, scope);
|
||||
if select {
|
||||
let mut ids: Vec<NodeId> = issues.iter().flat_map(|i| i.keys.iter().map(|k| NodeId(*k))).filter(|id| d.node(*id).is_some()).collect();
|
||||
ids.sort_unstable_by_key(|id| id.0);
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
//! Fold Preview's model (`addon.packaging.fold`): a blank folded into its 3D shape by
|
||||
//! [`vectorcraft_three_d::fold::fold`], and what the Fold Preview window needs to draw it: the
|
||||
//! document's blanks ([`fold_source`]) and the objects its print leaves out ([`print_hidden`]).
|
||||
|
||||
use serde_json::{Value, json};
|
||||
use vectorcraft_doc::{Document, Node, NodeId, NodeKind};
|
||||
use vectorcraft_three_d::fold::{Blank, Issue, fold, pick};
|
||||
|
||||
use super::super::super::{CommandSpec, bad, cmd, finite_numbers, has_doc, number_or};
|
||||
use super::check::{TOLERANCE, document_lines, found, issue_rows, lines, tolerance};
|
||||
use super::roles::{RoleTable, can_carry};
|
||||
use crate::{Result, Session};
|
||||
|
||||
const FOLD: &str = "addon.packaging.fold";
|
||||
|
||||
pub fn specs() -> Vec<CommandSpec> {
|
||||
vec![cmd!(
|
||||
query "addon.packaging.fold",
|
||||
"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: a Crease or a Perforation by 90° away from the printed side, a Partial Cut by 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 within tolerance or 0.5% of the hinge's length. 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
|
||||
)]
|
||||
}
|
||||
|
||||
/// The blanks the shown fold lines of `d` make, and their issues (`addon.packaging.check` on the
|
||||
/// whole document): what the Fold Preview window folds.
|
||||
pub fn fold_source(d: &Document) -> (Vec<Blank>, Vec<Issue>) {
|
||||
found(&document_lines(d), TOLERANCE.1)
|
||||
}
|
||||
|
||||
/// The objects the print on a folded blank leaves out: the layers that do not print and, unless
|
||||
/// `fold_lines`, every object with a line role.
|
||||
pub fn print_hidden(d: &Document, fold_lines: bool) -> Vec<NodeId> {
|
||||
fn walk(n: &Node, table: &RoleTable, fold_lines: bool, out: &mut Vec<NodeId>) {
|
||||
match &n.kind {
|
||||
NodeKind::Layer { printable: false, .. } => out.push(n.id),
|
||||
NodeKind::Layer { children, .. } | NodeKind::Group { children, .. } => children.iter().for_each(|c| walk(c, table, fold_lines, out)),
|
||||
_ if !fold_lines && can_carry(n) && table.role_of(n).is_some() => out.push(n.id),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
let table = RoleTable::of(d);
|
||||
let mut out = vec![];
|
||||
d.layers.iter().for_each(|l| walk(l, &table, fold_lines, &mut out));
|
||||
out
|
||||
}
|
||||
|
||||
fn fold_command(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let tolerance = tolerance(p, FOLD)?;
|
||||
let amount = number_or(p, "amount", 1.0, FOLD)?;
|
||||
if !(0.0..=1.0).contains(&amount) {
|
||||
return Err(bad(FOLD, "`amount` must be from 0 to 1"));
|
||||
}
|
||||
let base = match p.get("base") {
|
||||
None | Some(Value::Null) => None,
|
||||
Some(v) => {
|
||||
let [x, y] = finite_numbers::<2>(v).ok_or_else(|| bad(FOLD, "`base` must be a point: [x, y]"))?;
|
||||
Some(vectorcraft_geom::Point::new(x, y))
|
||||
}
|
||||
};
|
||||
let lines = lines(s, p, FOLD)?;
|
||||
let (blanks, issues) = found(&lines, tolerance);
|
||||
let ok = !issues.iter().any(|i| i.code.is_error());
|
||||
let picked = pick(&blanks, base);
|
||||
if base.is_some() && picked.is_none() {
|
||||
return Err(bad(FOLD, "`base` is in no panel"));
|
||||
}
|
||||
let folded = picked.and_then(|(b, panel)| Some((b, blanks.get(b)?, fold(blanks.get(b)?, Some(panel), amount, tolerance)?)));
|
||||
let Some((index, blank, f)) = folded else {
|
||||
return Ok(json!({
|
||||
"ok": ok, "blank": null, "blanks": blanks.len(), "base": null, "panels": [], "hinges": [], "collisions": [],
|
||||
"issues": issue_rows(&issues, lines.scope),
|
||||
}));
|
||||
};
|
||||
let column = |m: &[[f64; 3]; 3], k: usize| json!([m[0][k], m[1][k], m[2][k]]);
|
||||
let panels: Vec<Value> = blank
|
||||
.panels
|
||||
.iter()
|
||||
.zip(&f.panels)
|
||||
.map(|(panel, placed)| {
|
||||
json!({
|
||||
"outline": panel.outline.to_bezpath().to_svg(),
|
||||
"frame": {"x": column(&placed.pose.m, 0), "y": column(&placed.pose.m, 1), "z": column(&placed.pose.m, 2), "origin": placed.pose.t},
|
||||
"parent": placed.parent,
|
||||
"depth": placed.depth,
|
||||
})
|
||||
})
|
||||
.collect();
|
||||
let hinges: Vec<Value> = f
|
||||
.hinges
|
||||
.iter()
|
||||
.map(|h| json!({"a": h.a, "b": h.b, "angle": h.angle, "kind": if h.tree { "tree" } else { "closing" }, "closes": h.closes, "gap": h.gap}))
|
||||
.collect();
|
||||
Ok(json!({
|
||||
"ok": ok,
|
||||
"blank": index,
|
||||
"blanks": blanks.len(),
|
||||
"base": f.base,
|
||||
"panels": panels,
|
||||
"hinges": hinges,
|
||||
"collisions": f.collisions.iter().map(|(a, b)| [a, b]).collect::<Vec<_>>(),
|
||||
"issues": issue_rows(&issues, lines.scope),
|
||||
}))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
@@ -0,0 +1,157 @@
|
||||
//! Tests for the Fold Preview's model: a blank drawn in a document folded into its 3D shape.
|
||||
|
||||
use serde_json::{Value, json};
|
||||
|
||||
use crate::*;
|
||||
|
||||
fn session() -> Session {
|
||||
let mut s = Session::new();
|
||||
s.execute("file.new", &json!({"width": 600, "height": 600})).unwrap();
|
||||
s
|
||||
}
|
||||
|
||||
fn path(s: &mut Session, d: &str) -> u64 {
|
||||
s.execute("path.create", &json!({ "d": d })).unwrap()["id"].as_u64().unwrap()
|
||||
}
|
||||
|
||||
fn role(s: &mut Session, role: &str, ids: &[u64]) {
|
||||
s.execute("addon.packaging.setRole", &json!({ "role": role, "ids": ids })).unwrap();
|
||||
}
|
||||
|
||||
fn fold(s: &mut Session, p: Value) -> Value {
|
||||
s.execute("addon.packaging.fold", &p).unwrap()
|
||||
}
|
||||
|
||||
/// A tray blank: a 100 pt base (x 140 to 240, y 140 to 240) with a 40 pt wall on each side →
|
||||
/// (outline, creases).
|
||||
fn tray(s: &mut Session) -> (u64, Vec<u64>) {
|
||||
let outline = path(s, "M140 100 L240 100 L240 140 L280 140 L280 240 L240 240 L240 280 L140 280 L140 240 L100 240 L100 140 L140 140 Z");
|
||||
let creases = vec![path(s, "M140 140 L240 140"), path(s, "M240 140 L240 240"), path(s, "M240 240 L140 240"), path(s, "M140 240 L140 140")];
|
||||
role(s, "cut", &[outline]);
|
||||
role(s, "crease", &creases);
|
||||
s.execute("select.none", &json!({})).unwrap();
|
||||
(outline, creases)
|
||||
}
|
||||
|
||||
fn vector(v: &Value) -> [f64; 3] {
|
||||
let a = v.as_array().unwrap();
|
||||
[a[0].as_f64().unwrap(), a[1].as_f64().unwrap(), a[2].as_f64().unwrap()]
|
||||
}
|
||||
|
||||
/// The middle of the bounds of the points of SVG path data `d` (absolute moves and lines only).
|
||||
fn middle(d: &str) -> [f64; 2] {
|
||||
let n: Vec<f64> = d.split(|c: char| !(c.is_ascii_digit() || c == '.' || c == '-')).filter_map(|t| t.parse().ok()).collect();
|
||||
let span = |k: usize| n.iter().skip(k).step_by(2).fold((f64::INFINITY, f64::NEG_INFINITY), |(lo, hi), &t| (lo.min(t), hi.max(t)));
|
||||
let ((x0, x1), (y0, y1)) = (span(0), span(1));
|
||||
[(x0 + x1) / 2.0, (y0 + y1) / 2.0]
|
||||
}
|
||||
|
||||
fn near(a: [f64; 3], b: [f64; 3]) -> bool {
|
||||
a.iter().zip(b).all(|(x, y)| (x - y).abs() < 1e-9)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_tray_folds_its_walls_up_round_the_base() {
|
||||
let mut s = session();
|
||||
tray(&mut s);
|
||||
let steps = s.doc().unwrap().history.undo.len();
|
||||
let r = fold(&mut s, json!({}));
|
||||
assert_eq!((r["ok"].as_bool(), r["blank"].as_u64(), r["blanks"].as_u64()), (Some(true), Some(0), Some(1)), "{r}");
|
||||
let panels = r["panels"].as_array().unwrap();
|
||||
assert_eq!(panels.len(), 5);
|
||||
let base = r["base"].as_u64().unwrap() as usize;
|
||||
let frame = &panels[base]["frame"];
|
||||
assert!(
|
||||
near(vector(&frame["x"]), [1.0, 0.0, 0.0]) && near(vector(&frame["z"]), [0.0, 0.0, 1.0]) && near(vector(&frame["origin"]), [0.0; 3]),
|
||||
"{frame}"
|
||||
);
|
||||
assert!(panels[base]["parent"].is_null());
|
||||
assert!(panels[base]["outline"].as_str().unwrap().starts_with('M'), "SVG path data");
|
||||
for (i, p) in panels.iter().enumerate().filter(|(i, _)| *i != base) {
|
||||
assert_eq!((p["parent"].as_u64(), p["depth"].as_u64()), (Some(base as u64), Some(1)), "{p}");
|
||||
// Each wall stands square to the base, below it (away from the print), its print facing out:
|
||||
// away from the base's middle (190, 190), toward the side the wall lies on.
|
||||
let [cx, cy] = middle(p["outline"].as_str().unwrap());
|
||||
let (x, y, o) = (vector(&p["frame"]["x"]), vector(&p["frame"]["y"]), vector(&p["frame"]["origin"]));
|
||||
let placed: [f64; 3] = std::array::from_fn(|k| o[k] + x[k] * cx - y[k] * cy);
|
||||
let (dx, dy) = (cx - 190.0, 190.0 - cy);
|
||||
let out = if dx.abs() > dy.abs() { [dx.signum(), 0.0, 0.0] } else { [0.0, dy.signum(), 0.0] };
|
||||
assert!(near(vector(&p["frame"]["z"]), out), "wall {i}: {p}");
|
||||
assert!((placed[2] + 20.0).abs() < 1e-9, "wall {i}'s middle is 20 pt below the base: {placed:?}");
|
||||
}
|
||||
let hinges = r["hinges"].as_array().unwrap();
|
||||
assert_eq!(hinges.len(), 4);
|
||||
assert!(hinges.iter().all(|h| h["kind"] == "tree" && h["angle"] == 90.0 && h["closes"] == true), "{r}");
|
||||
assert_eq!(r["collisions"], json!([]));
|
||||
assert_eq!(s.doc().unwrap().history.undo.len(), steps, "a fold records no undo step");
|
||||
|
||||
// Flat, every frame is the flat blank's own.
|
||||
let r = fold(&mut s, json!({ "amount": 0 }));
|
||||
for p in r["panels"].as_array().unwrap() {
|
||||
assert!(near(vector(&p["frame"]["z"]), [0.0, 0.0, 1.0]) && near(vector(&p["frame"]["origin"]), [0.0; 3]), "{p}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_base_is_the_panel_under_a_point() {
|
||||
let mut s = session();
|
||||
tray(&mut s);
|
||||
// The left wall: x 100 to 140, y 140 to 240.
|
||||
let r = fold(&mut s, json!({ "base": [120, 190] }));
|
||||
let base = r["base"].as_u64().unwrap() as usize;
|
||||
let panels = r["panels"].as_array().unwrap();
|
||||
assert!(near(vector(&panels[base]["frame"]["z"]), [0.0, 0.0, 1.0]));
|
||||
// The tray's base is now a child of the wall, and the other walls its children.
|
||||
let depths: Vec<u64> = panels.iter().map(|p| p["depth"].as_u64().unwrap()).collect();
|
||||
let mut sorted = depths.clone();
|
||||
sorted.sort_unstable();
|
||||
assert_eq!(sorted, [0, 1, 2, 2, 2], "{depths:?}");
|
||||
let e = s.execute("addon.packaging.fold", &json!({ "base": [10, 10] })).unwrap_err().to_string();
|
||||
assert!(e.contains("`base` is in no panel"), "{e}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bad_values_are_refused() {
|
||||
let mut s = session();
|
||||
tray(&mut s);
|
||||
for (p, want) in [
|
||||
(json!({ "amount": 1.5 }), "`amount` must be from 0 to 1"),
|
||||
(json!({ "amount": -0.1 }), "`amount` must be from 0 to 1"),
|
||||
(json!({ "amount": "1" }), "`amount` must be a number"),
|
||||
(json!({ "base": [1] }), "`base` must be a point"),
|
||||
(json!({ "base": "middle" }), "`base` must be a point"),
|
||||
(json!({ "tolerance": 50 }), "`tolerance` must be from"),
|
||||
] {
|
||||
let e = s.execute("addon.packaging.fold", &p).unwrap_err().to_string();
|
||||
assert!(e.contains(want), "{p}: {e}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn without_a_blank_nothing_is_folded_and_the_issues_say_why() {
|
||||
let mut s = session();
|
||||
let r = fold(&mut s, json!({}));
|
||||
assert_eq!((r["ok"].as_bool(), r["blank"].is_null(), r["blanks"].as_u64()), (Some(false), true, Some(0)), "{r}");
|
||||
assert_eq!(r["panels"], json!([]));
|
||||
assert_eq!(r["issues"][0]["code"], "noCut");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_print_leaves_out_fold_lines_and_layers_that_do_not_print() {
|
||||
let mut s = session();
|
||||
let (outline, creases) = tray(&mut s);
|
||||
let art = path(&mut s, "M150 150 L200 150 L200 200 Z");
|
||||
let notes = s.execute("layer.new", &json!({})).unwrap()["id"].as_u64().unwrap();
|
||||
s.execute("layer.setProps", &json!({"id": notes, "printable": false})).unwrap();
|
||||
let d = &s.doc().unwrap().doc;
|
||||
let hidden: Vec<u64> = cmd::print_hidden(d, false).into_iter().map(|id| id.0).collect();
|
||||
for id in creases.iter().chain([&outline, ¬es]) {
|
||||
assert!(hidden.contains(id), "{id} in {hidden:?}");
|
||||
}
|
||||
assert!(!hidden.contains(&art));
|
||||
let shown: Vec<u64> = cmd::print_hidden(d, true).into_iter().map(|id| id.0).collect();
|
||||
assert_eq!(shown, vec![notes], "with the fold lines shown, only the layer is left out");
|
||||
let (blanks, issues) = cmd::fold_source(d);
|
||||
assert_eq!((blanks.len(), blanks[0].panels.len()), (1, 5));
|
||||
assert!(issues.is_empty(), "{issues:?}");
|
||||
}
|
||||
@@ -41,6 +41,7 @@ pub(super) const ALLOWED: &[&str] = &[
|
||||
"addon.image.removeBackground",
|
||||
"addon.image.removeColorMask",
|
||||
"addon.packaging.check",
|
||||
"addon.packaging.fold",
|
||||
"addon.packaging.roles",
|
||||
"addon.packaging.setRole",
|
||||
"addon.packaging.setRoleSwatch",
|
||||
|
||||
Reference in New Issue
Block a user