Wave 437/509: Curvature comb: every comb shown at one scale, kept by the command (and 3 more)

4 commits, squashed; the originals stay reachable from tag archive/merge-main-develop.

- 0b7468729 jyviko: Curvature comb: every comb shown at one scale, kept by the command
- 6ab96c658 jyviko: View analyses: one toggle group, its state in the session
- 9a45d4248 jyviko: Kernel rig: inspect.analysis is a display analysis switch, exempt like the others
- 8d590c198 jyviko: Kernel tests: the long-setback G2 patch's reach past the box from its exact surface

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DtL5M41G8Nua7HvuFPZkmJ
This commit is contained in:
jyviko
2026-10-30 08:06:05 -04:00
parent faf08ec1bb
commit ff3000e10b
12 changed files with 620 additions and 100 deletions
+124 -33
View File
@@ -6,7 +6,7 @@ use solidcraft_geom::{Aabb3, Seg2, Vec2, Vec3};
use super::CommandSpec;
use crate::params::{bad, bool_, num, string_list, vec3};
use crate::{EngineError, Result, Session};
use crate::{CombPick, CombView, EngineError, Result, Session};
pub static COMMANDS: &[CommandSpec] = &[
CommandSpec::new("inspect.curvature_comb", "Curvature Comb Analysis", curvature_comb)
@@ -19,10 +19,13 @@ pub static COMMANDS: &[CommandSpec] = &[
combs along the face's iso grid); density?: teeth per curve, 2…2000 (default 40; on an edge or an iso curve exactly \
that many, evenly spaced along its parameter); scale?: comb length per unit curvature (default auto: the longest \
tooth a fifth of the combs' size); length?: a multiplier on the automatic scale, 0.01…100 (default 1; ignored with \
`scale`). The curvature is exact: from each sketch curve, edge curve (line, circle, ellipse, B-spline, NURBS, \
`scale`); add?: true keeps the combs shown and adds these, every comb again at one scale (with nothing picked it \
draws those shown again with this call's options, or turns the analysis on with none); clear?: true turns the \
analysis off. Every comb of a call shares one scale, so tooth lengths compare across curves; the viewport draws \
them. The curvature is exact: from each sketch curve, edge curve (line, circle, ellipse, B-spline, NURBS, \
intersection curve) or face surface's own derivatives, never from the display mesh; a face's teeth are the \
surface's normal curvature along each iso curve, along the surface normal. → combs: [{curve, teeth: [[foot, tip]], \
envelope: [tip], max_curvature, min_radius}], scale",
envelope: [tip], max_curvature, min_radius}] (those shown, with `add`), scale",
),
CommandSpec::new("inspect.minimum_radius", "Minimum Radius Analysis", minimum_radius)
.at("SKETCH", "INSPECT")
@@ -100,18 +103,62 @@ fn edge_teeth(st: &solidcraft_doc::ModelState, at: Vec3, density: usize) -> Resu
}
}
/// Most curves Curvature Comb Analysis shows at once.
const MAX_COMB_PICKS: usize = 1000;
/// The combs of one pick, each as (id, teeth (foot, curvature, unit normal)): one for a curve or
/// an edge, one per iso curve for a face.
fn pick_teeth(s: &Session, pick: &CombPick, density: usize) -> Result<Vec<(String, Vec<(Vec3, f64, Vec3)>)>> {
let cmd = "inspect.curvature_comb";
match pick {
CombPick::Curve { sketch, curve } => {
let st = s.model.state();
let ss = st.sketch(*sketch).ok_or_else(|| EngineError::Other("that sketch is not evaluated".into()))?;
let ci = ss.sketch.curve_index(curve).ok_or_else(|| bad(cmd, format!("unknown curve `{curve}`")))?;
let segs = ss.sketch.exact_segs(ci).unwrap_or_else(|| ss.sketch.segs(ci));
let teeth = teeth_2d(&segs, density).into_iter().map(|(q, k, n)| (ss.plane.to_world(q), k, ss.plane.dir_to_world(n))).collect();
Ok(vec![(curve.clone(), teeth)])
}
CombPick::Edge { at } => {
let teeth = edge_teeth(&s.model.state(), *at, density)?.ok_or_else(|| bad(cmd, "no edge there"))?;
Ok(vec![(format!("edge@{},{},{}", at.x, at.y, at.z), teeth)])
}
CombPick::Face { at, count } => {
let world = s.world_state()?;
let (body, face) = iso_face_at(s, &world, *at).ok_or_else(|| bad(cmd, "no face there"))?;
let mut out = Vec::new();
for (k, line) in body.iso_lines(face, *count)?.iter().enumerate() {
out.push((format!("face@{},{},{}#{k}", at.x, at.y, at.z), teeth_exact(&crate::kernel::iso_comb(&body.body, face, line, density)?)));
}
Ok(out)
}
}
}
/// `inspect.curvature_comb`: the combs of the picked curves, edges and faces (with `add`, those
/// already shown too), all at one scale, kept so the viewport draws them. View state only.
fn curvature_comb(s: &mut Session, p: &Value) -> Result<Value> {
let cmd = "inspect.curvature_comb";
if bool_(p, "clear").unwrap_or(false) {
s.comb = None;
s.revision += 1;
return Ok(json!({"analysis": "curvature_comb", "cleared": true}));
}
let add = bool_(p, "add").unwrap_or(false);
let shown = if add { s.comb.clone() } else { None };
let density = num(p, "density")
.filter(|d| d.is_finite())
.map(|d| d.clamp(crate::kernel::MIN_COMB_TEETH as f64, crate::kernel::MAX_COMB_TEETH as f64) as usize)
.unwrap_or(40);
.unwrap_or(shown.as_ref().map_or(40, |v| v.density));
let length = match p.get("length") {
None | Some(Value::Null) => 1.0,
None | Some(Value::Null) => shown.as_ref().map_or(1.0, |v| v.length),
Some(v) => v.as_f64().filter(|x| (0.01..=100.0).contains(x)).ok_or_else(|| bad(cmd, "`length` must be a multiplier 0.01…100"))?,
};
let st = s.model.state();
let mut combs: Vec<(String, Vec<(Vec3, f64, Vec3)>)> = Vec::new();
let fixed_scale = match p.get("scale") {
None | Some(Value::Null) => shown.as_ref().and_then(|v| v.fixed_scale),
Some(_) => num(p, "scale").filter(|x| x.is_finite() && *x > 0.0),
};
let mut picks: Vec<CombPick> = Vec::new();
let curves = string_list(p, "curves");
if !curves.is_empty() {
let id = match p.get("sketch") {
@@ -120,19 +167,11 @@ fn curvature_comb(s: &mut Session, p: &Value) -> Result<Value> {
_ => s.active_sketch,
}
.ok_or_else(|| bad(cmd, "no such sketch (and none is active)"))?;
let ss = st.sketch(id).ok_or_else(|| EngineError::Other("that sketch is not evaluated".into()))?;
for c in curves.iter().take(1000) {
let ci = ss.sketch.curve_index(c).ok_or_else(|| bad(cmd, format!("unknown curve `{c}`")))?;
let segs = ss.sketch.exact_segs(ci).unwrap_or_else(|| ss.sketch.segs(ci));
let teeth = teeth_2d(&segs, density).into_iter().map(|(q, k, n)| (ss.plane.to_world(q), k, ss.plane.dir_to_world(n))).collect();
combs.push((c.clone(), teeth));
}
picks.extend(curves.iter().take(MAX_COMB_PICKS).map(|c| CombPick::Curve { sketch: id, curve: c.clone() }));
}
if let Some(edges) = p.get("edges").and_then(Value::as_array) {
for e in edges.iter().take(1000) {
let at = vec3(e).ok_or_else(|| bad(cmd, "`edges` must be points [x,y,z]"))?;
let teeth = edge_teeth(&st, at, density)?.ok_or_else(|| bad(cmd, "no edge there"))?;
combs.push((format!("edge@{},{},{}", at.x, at.y, at.z), teeth));
for e in edges.iter().take(MAX_COMB_PICKS) {
picks.push(CombPick::Edge { at: vec3(e).ok_or_else(|| bad(cmd, "`edges` must be points [x,y,z]"))? });
}
}
if let Some(faces) = p.get("faces") {
@@ -143,39 +182,57 @@ fn curvature_comb(s: &mut Session, p: &Value) -> Result<Value> {
num(p, "count").filter(|c| c.is_finite()).map(|c| c.clamp(1.0, 50.0) as usize).ok_or_else(|| bad(cmd, "`count` must be a number"))?
}
};
let world = s.world_state()?;
for v in faces.iter().take(100) {
let at = vec3(v).ok_or_else(|| bad(cmd, "`faces` must list points [x,y,z]"))?;
let (body, face) = iso_face_at(s, &world, at).ok_or_else(|| bad(cmd, "no face there"))?;
for (k, line) in body.iso_lines(face, count)?.iter().enumerate() {
let teeth = teeth_exact(&crate::kernel::iso_comb(&body.body, face, line, density)?);
combs.push((format!("face@{},{},{}#{k}", at.x, at.y, at.z), teeth));
}
picks.push(CombPick::Face { at: vec3(v).ok_or_else(|| bad(cmd, "`faces` must list points [x,y,z]"))?, count });
}
}
if combs.is_empty() {
if picks.is_empty() && !add {
return Err(bad(cmd, "give `curves`, `edges` or `faces`"));
}
let shown_picks = shown.map(|v| v.picks).unwrap_or_default();
if shown_picks.len() + picks.len() > MAX_COMB_PICKS {
return Err(bad(cmd, format!("at most {MAX_COMB_PICKS} curves can be combed at once")));
}
// The curves shown are combed again with these options; one gone with a model change since
// (its sketch, edge or face no longer there) is dropped. A new pick must be there.
let mut kept: Vec<CombPick> = Vec::new();
let mut combs: Vec<(String, Vec<(Vec3, f64, Vec3)>)> = Vec::new();
for pick in shown_picks {
if let Ok(teeth) = pick_teeth(s, &pick, density) {
combs.extend(teeth);
kept.push(pick);
}
}
for pick in picks {
combs.extend(pick_teeth(s, &pick, density)?);
kept.push(pick);
}
// One scale for all combs: the longest tooth is a fifth of the largest curve's size.
let kmax = combs.iter().flat_map(|c| c.1.iter().map(|t| t.1.abs())).fold(0.0_f64, f64::max);
let bounds: Aabb3 = combs.iter().flat_map(|c| c.1.iter().map(|t| t.0)).collect();
let diag = bounds.diagonal();
let auto = if kmax > 1e-12 && !bounds.is_empty() && diag.is_finite() { 0.2 * diag / kmax } else { 1.0 };
let scale = num(p, "scale").filter(|x| x.is_finite() && *x > 0.0).unwrap_or(auto * length);
let scale = fixed_scale.unwrap_or(auto * length);
let mut drawn = Vec::with_capacity(combs.len());
let out: Vec<Value> = combs
.iter()
.map(|(id, teeth)| {
let lines: Vec<[[f64; 3]; 2]> = teeth.iter().map(|(q, k, n)| [(*q).into(), (*q - *n * (k * scale)).into()]).collect();
let lines: Vec<[Vec3; 2]> = teeth.iter().map(|(q, k, n)| [*q, *q - *n * (k * scale)]).collect();
let kmax_c = teeth.iter().map(|t| t.1.abs()).fold(0.0_f64, f64::max);
json!({
let reply: Vec<[[f64; 3]; 2]> = lines.iter().map(|[a, b]| [(*a).into(), (*b).into()]).collect();
let value = json!({
"curve": id,
"teeth": lines,
"envelope": lines.iter().map(|l| l[1]).collect::<Vec<_>>(),
"envelope": reply.iter().map(|l| l[1]).collect::<Vec<_>>(),
"teeth": reply,
"max_curvature": kmax_c,
"min_radius": if kmax_c > 1e-12 { Value::from(1.0 / kmax_c) } else { Value::Null },
})
});
drawn.push(lines);
value
})
.collect();
s.analyses_off(Some("inspect.curvature_comb"));
s.comb = Some(CombView { picks: kept, density, length, fixed_scale, scale, teeth: drawn });
Ok(json!({"combs": out, "scale": scale}))
}
@@ -369,7 +426,7 @@ fn isocurves(s: &mut Session, p: &Value) -> Result<Value> {
s.isocurves.clear();
}
s.isocurves.extend(picks.into_iter().map(|(_, k)| k));
s.revision += 1;
s.analyses_off(Some("inspect.isocurve"));
Ok(json!({"curves": curves, "faces": shown}))
}
@@ -475,6 +532,40 @@ mod tests {
assert!(s.execute("inspect.curvature_comb", &json!({"faces": [[58, 0, 5]], "count": "x"})).is_err());
}
/// The combs shown are kept in the session: `add` adds to them and draws them all again at
/// one scale (an R5 circle's teeth twice an R10 circle's), with nothing picked it takes new
/// options, a sketch curve keeps its own sketch, and `clear` turns the analysis off.
#[test]
fn added_combs_share_one_scale_and_clear_turns_them_off() {
use solidcraft_geom::Vec3;
let mut s = Session::default();
s.execute("solid.cylinder", &json!({"radius": 5, "height": 10})).unwrap();
s.execute("solid.cylinder", &json!({"base": [40, 0, 0], "radius": 10, "height": 10})).unwrap();
let one = s.execute("inspect.curvature_comb", &json!({"edges": [[0, 5, 10]], "density": 8})).unwrap();
let both = s.execute("inspect.curvature_comb", &json!({"edges": [[40, 10, 10]], "add": true})).unwrap();
let shown = s.comb.as_ref().unwrap();
assert_eq!((shown.picks.len(), shown.teeth.len(), shown.density), (2, 2, 8), "the first call's density is kept");
assert_eq!(both["combs"].as_array().unwrap().len(), 2);
let tooth = |c: &[[Vec3; 2]]| c[0][0].dist(c[0][1]);
assert!((tooth(&shown.teeth[0]) / tooth(&shown.teeth[1]) - 2.0).abs() < 1e-9);
assert_ne!(one["scale"], both["scale"], "the scale is the pair's, not the first comb's");
let longer = s.execute("inspect.curvature_comb", &json!({"add": true, "length": 2})).unwrap();
assert!((longer["scale"].as_f64().unwrap() - 2.0 * both["scale"].as_f64().unwrap()).abs() < 1e-9);
assert_eq!(s.comb.as_ref().unwrap().picks.len(), 2);
// A sketch curve keeps its sketch after another becomes active.
s.execute("sketch.create", &json!({"plane": "XY"})).unwrap();
let c = s.execute("sketch.circle.center", &json!({"center": [0, 30], "radius": 5})).unwrap()["curves"][0].clone();
s.execute("inspect.curvature_comb", &json!({"curves": [c], "add": true})).unwrap();
s.execute("sketch.finish", &json!({})).unwrap();
s.execute("sketch.create", &json!({"plane": "XZ"})).unwrap();
let r = s.execute("inspect.curvature_comb", &json!({"add": true})).unwrap();
assert_eq!(r["combs"].as_array().unwrap().len(), 3, "{r}");
s.execute("inspect.curvature_comb", &json!({"clear": true})).unwrap();
assert!(s.comb.is_none());
let on = s.execute("inspect.curvature_comb", &json!({"add": true})).unwrap();
assert!(on["combs"].as_array().unwrap().is_empty() && s.comb.as_ref().is_some_and(|v| v.picks.is_empty()));
}
/// Each tooth of a comb reply as (foot, curvature): the tooth's length over the scale.
fn tooth_curvatures(r: &Value, comb: usize) -> Vec<([f64; 3], f64)> {
let scale = r["scale"].as_f64().unwrap();
+83 -1
View File
@@ -1,5 +1,7 @@
//! Surface analyses: zebra stripes, draft angle and curvature map shading of the model's faces.
//! View state only: no geometry changes and no undo step.
//! View state only: no geometry changes and no undo step. The view analyses (these shadings,
//! continuity seams, isocurves and curvature combs) are one group: one at a time is on, and
//! `inspect.analysis` says which or turns it off.
use serde_json::{Value, json};
use solidcraft_geom::Vec3;
@@ -38,6 +40,18 @@ pub static COMMANDS: &[CommandSpec] = &[
.icon("curvature_map")
.noundo()
.params("radius?: mm shown red (default: a tenth of the model's size); clear?: true turns the analysis off"),
CommandSpec::new("inspect.analysis", "View Analysis", crate::checked!("inspect.analysis", analysis))
.icon("zebra")
.noundo()
.doc_only()
.contract(&ANALYSIS_CONTRACT)
.output(crate::schema::output_schema_for::<crate::schema::surface_analysis::AnalysisState>)
.params(
"off?: true turns the view analysis on now off. → active: the command id of the view analysis on (inspect.zebra, \
inspect.draft, inspect.curvature_map, inspect.environment_map, inspect.accessibility, inspect.continuity, \
inspect.isocurve or inspect.curvature_comb), or null. One is on at a time: turning one on turns the one on before \
off. Read-only without `off`",
),
CommandSpec::new("inspect.continuity", "Continuity Analysis", continuity).at("SURFACE", "INSPECT").icon("continuity").noundo().params(
"body?: name (default: the visible bodies); edges?: [x,y,z] points or {\"index\": i} (default: every edge of the body; \
a pick must match one body); samples?: 3…257 stations along each edge, ends included (default 33); \
@@ -52,10 +66,75 @@ pub static COMMANDS: &[CommandSpec] = &[
),
];
const ANALYSIS_CONTRACT: crate::schema::TypedContract<crate::schema::surface_analysis::AnalysisParams> = crate::schema::TypedContract::new();
/// The view analyses, by the command that turns each on: the shadings, the continuity seams, the
/// isocurves and the curvature combs. One at a time is on.
impl Session {
/// The view analysis on now, by its command id, or `None`.
pub fn active_analysis(&self) -> Option<&'static str> {
if let Some(a) = self.analysis {
Some(a.command())
} else if self.comb.is_some() {
Some("inspect.curvature_comb")
} else if !self.isocurves.is_empty() {
Some("inspect.isocurve")
} else if !self.continuity.is_empty() {
Some("inspect.continuity")
} else {
None
}
}
/// Turn every view analysis off but the one command `keep` turns on (`None`: all of them).
pub fn analyses_off(&mut self, keep: Option<&str>) {
if self.analysis.is_some_and(|a| Some(a.command()) != keep) {
self.analysis = None;
}
if keep != Some("inspect.curvature_comb") {
self.comb = None;
}
if keep != Some("inspect.isocurve") {
self.isocurves.clear();
}
if keep != Some("inspect.continuity") {
self.continuity.clear();
}
self.revision += 1;
}
}
impl SurfaceAnalysis {
/// The command that turns this analysis on.
pub fn command(self) -> &'static str {
match self {
SurfaceAnalysis::Zebra { .. } => "inspect.zebra",
SurfaceAnalysis::Draft { .. } => "inspect.draft",
SurfaceAnalysis::Curvature { .. } => "inspect.curvature_map",
SurfaceAnalysis::Environment => "inspect.environment_map",
SurfaceAnalysis::Access { .. } => "inspect.accessibility",
}
}
}
/// `inspect.analysis`: which view analysis is on, and `off` turns it off.
fn analysis(s: &mut Session, p: &Value) -> Result<Value> {
let off = match p.get("off") {
None | Some(Value::Null) => false,
Some(Value::Bool(b)) => *b,
Some(_) => return Err(bad("inspect.analysis", "`off` must be true or false")),
};
if off {
s.analyses_off(None);
}
Ok(json!({"active": s.active_analysis()}))
}
fn set(s: &mut Session, p: &Value, a: SurfaceAnalysis) -> Result<Value> {
if bool_(p, "clear").unwrap_or(false) {
s.analysis = None;
} else {
s.analyses_off(Some(a.command()));
s.analysis = Some(a);
}
s.revision += 1;
@@ -213,6 +292,9 @@ fn continuity(s: &mut Session, p: &Value) -> Result<Value> {
} else {
s.continuity = seams;
}
if !s.continuity.is_empty() {
s.analyses_off(Some("inspect.continuity"));
}
s.revision += 1;
Ok(json!({
"analysis": "continuity",
+34
View File
@@ -439,6 +439,9 @@ pub struct Session {
/// The faces Isocurve Analysis shows the isoparametric curves of, for the viewport to draw
/// ([`Session::isocurve_lines`]). View state: not part of the design and not an undo step.
pub isocurves: Vec<IsoPick>,
/// The curvature combs `inspect.curvature_comb` shows, for the viewport to draw; `None` when
/// the analysis is off. View state: not part of the design and not an undo step.
pub comb: Option<CombView>,
/// What is hidden or shown in the view (`browser.visibility`): saved with the design and an
/// undo step of its own ([`Snapshot::visibility`]). A design brings its saved visibility when
/// it opens (`Session::new`).
@@ -538,6 +541,35 @@ pub struct IsoPick {
pub count: usize,
}
/// What Curvature Comb Analysis shows: the picks, the options every comb is drawn with, and
/// the teeth drawn, all at one scale so their lengths compare. View state only.
#[derive(Clone, Debug, PartialEq, serde::Serialize)]
pub struct CombView {
pub picks: Vec<CombPick>,
/// Teeth per curve.
pub density: usize,
/// The multiplier on the automatic scale.
pub length: f64,
/// A fixed comb length per unit curvature, in place of the automatic one.
pub fixed_scale: Option<f64>,
/// The comb length per unit curvature the teeth are drawn at, shared by every comb.
pub scale: f64,
/// Each comb's teeth as (foot, tip), in world coordinates.
pub teeth: Vec<Vec<[Vec3; 2]>>,
}
/// A curve Curvature Comb Analysis shows, as it was picked (found again whenever it is drawn).
#[derive(Clone, Debug, PartialEq, serde::Serialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum CombPick {
/// A sketch curve.
Curve { sketch: u64, curve: String },
/// The body edge whose exact curve passes nearest `at`.
Edge { at: Vec3 },
/// The face at `at`, combed along `count` iso curves each way.
Face { at: Vec3, count: usize },
}
impl SurfaceAnalysis {
/// How a picture shades the faces for this analysis.
pub fn mode(self) -> render::AnalysisMode {
@@ -633,6 +665,7 @@ impl Session {
analysis: None,
continuity: Vec::new(),
isocurves: Vec::new(),
comb: None,
checkpoints: Vec::new(),
next_checkpoint: 1,
replacements: 0,
@@ -1443,6 +1476,7 @@ impl Session {
analysis: None,
continuity: Vec::new(),
isocurves: Vec::new(),
comb: None,
checkpoints: Vec::new(),
next_checkpoint: 1,
replacements: 0,
+1
View File
@@ -58,6 +58,7 @@ pub mod browser;
pub mod diagnostics;
pub mod features;
pub mod inspect;
pub mod surface_analysis;
pub use check::{Contract, Issue, ParamCheck, TypedContract, input_schema_for, output_schema_for, run_checked, run_checked_as};
pub use types::*;
@@ -0,0 +1,35 @@
//! Contracts and result types for the commands in `cmd/surface_analysis.rs`.
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use serde_json::Value;
/// `true`, `false` or null, with the handler's message for anything else.
fn flag<'de, D: serde::Deserializer<'de>>(d: D) -> Result<Option<bool>, D::Error> {
match Value::deserialize(d)? {
Value::Null => Ok(None),
Value::Bool(b) => Ok(Some(b)),
_ => Err(serde::de::Error::custom("must be true or false")),
}
}
/// Say which view analysis is on (zebra, draft, curvature map, environment map, accessibility,
/// continuity, isocurves or curvature combs: one at a time), or turn it off.
#[derive(Debug, Default, Deserialize, JsonSchema)]
#[schemars(deny_unknown_fields)]
pub struct AnalysisParams {
/// Turn the view analysis on now off.
#[serde(default, deserialize_with = "flag")]
pub off: Option<bool>,
}
/// What `inspect.analysis` returns.
#[derive(Debug, Serialize, JsonSchema)]
pub struct AnalysisState {
/// The command id of the view analysis on (after `off`), or null when none is.
pub active: Option<String>,
}
#[cfg(test)]
#[path = "surface_analysis_tests.rs"]
mod tests;
@@ -0,0 +1,45 @@
use serde_json::json;
use super::AnalysisParams;
use crate::Session;
use crate::schema::input_schema_for;
use crate::schema::tests::{assert_keys, assert_strict_keeps_todays_errors};
#[test]
fn schemas_and_the_key_check_agree() {
assert_keys(input_schema_for::<AnalysisParams>(), &["off"]);
}
#[test]
fn strict_keeps_todays_errors() {
assert_strict_keeps_todays_errors(&[("inspect.analysis", json!({"off": "yes"})), ("inspect.analysis", json!({"off": 1}))]);
}
/// The view analyses are one group: turning one on turns the one on before off, and
/// `inspect.analysis` names the one on and turns it off.
#[test]
fn one_view_analysis_is_on_at_a_time() {
let mut s = Session::default();
s.execute("solid.cylinder", &json!({"radius": 5, "height": 10})).unwrap();
let active = |s: &mut Session| s.execute("inspect.analysis", &json!({})).unwrap()["active"].clone();
assert_eq!(active(&mut s), json!(null));
s.execute("inspect.zebra", &json!({})).unwrap();
assert_eq!(active(&mut s), json!("inspect.zebra"));
s.execute("inspect.curvature_comb", &json!({"edges": [[0, 5, 10]]})).unwrap();
assert_eq!(active(&mut s), json!("inspect.curvature_comb"));
assert!(s.analysis.is_none(), "the zebra stripes went off");
s.execute("inspect.isocurve", &json!({"faces": [[0, 5, 5]]})).unwrap();
assert_eq!(active(&mut s), json!("inspect.isocurve"));
assert!(s.comb.is_none(), "the combs went off");
s.execute("inspect.continuity", &json!({})).unwrap();
assert_eq!(active(&mut s), json!("inspect.continuity"));
assert!(s.isocurves.is_empty(), "the isocurves went off");
s.execute("inspect.draft", &json!({})).unwrap();
assert_eq!(active(&mut s), json!("inspect.draft"));
assert!(s.continuity.is_empty(), "the seams went off");
// Turning on the comb with nothing picked yet.
s.execute("inspect.curvature_comb", &json!({"add": true})).unwrap();
assert_eq!(active(&mut s), json!("inspect.curvature_comb"));
assert_eq!(s.execute("inspect.analysis", &json!({"off": true})).unwrap()["active"], json!(null));
assert!(s.comb.is_none() && s.analysis.is_none());
}