mirror of
https://github.com/storytold/cadcraft.git
synced 2026-10-25 19:36:49 -06:00
* Build: line tables only in dev, no debug info for dependencies * Tests: one integration-test binary per crate Each crate's tests/*.rs becomes a module of tests/it/main.rs. Files that install process-wide state (the file io hooks, user aliases, SAVETIME and SAVEFILEPATH, user linetype and pattern files, registered fonts) stay their own test binaries. * xtask ci: nextest, tests without examples, one wasm check call
34 lines
1.5 KiB
Rust
34 lines
1.5 KiB
Rust
//! OFFSET keeps a closed (periodic) spline closed (issue #303): the offset copy was built with
|
|
//! the open-spline interpolation, so it came out open with a seam where the curve started.
|
|
|
|
use cadcraft_engine::Session;
|
|
use cadcraft_engine::doc::EntityKind;
|
|
use cadcraft_engine::geom::Spline;
|
|
use serde_json::json;
|
|
|
|
fn last_spline(s: &Session) -> (String, Spline) {
|
|
let d = s.doc().unwrap();
|
|
let Some(e) = d.model.iter().last() else { panic!("empty drawing") };
|
|
let EntityKind::Spline(sp) = &e.kind else { panic!("not a spline: {:?}", e.kind) };
|
|
(e.handle.hex(), sp.clone())
|
|
}
|
|
|
|
#[test]
|
|
fn offset_of_closed_spline_is_closed() {
|
|
let mut s = Session::new();
|
|
s.cmdline("spline 0,0 10,0 10,10 0,10 c").unwrap();
|
|
let (h, src) = last_spline(&s);
|
|
assert!(src.closed && src.is_periodic());
|
|
for (side, outward) in [([5.0, 5.0], false), ([30.0, 5.0], true)] {
|
|
s.execute("offset", &json!({ "handle": h, "distance": 1, "side": side })).unwrap();
|
|
let (_, off) = last_spline(&s);
|
|
assert!(off.closed && off.is_periodic(), "offset copy is open: {off:?}");
|
|
let (lo, hi) = off.domain();
|
|
assert!(off.eval(lo).near(off.eval(hi), 1e-9), "offset copy has a gap at the seam");
|
|
// The copy lies 1 unit inside / outside the original everywhere.
|
|
let (sb, ob) = (src.bounds(), off.bounds());
|
|
let grow = ob.max.x - sb.max.x;
|
|
assert!((grow - if outward { 1.0 } else { -1.0 }).abs() < 0.1, "{grow}");
|
|
}
|
|
}
|