solid.cylinder, box, sphere, torus and coil place by expressions: base, corner and center take numbers or length expressions per coordinate ("basin_width/2", "10 mm") and follow parameter changes, renames and component frames; before, a point that was not three plain numbers (or an unreadable axis) was silently replaced by the origin (or Z). The features now store the point as expressions (plain numbers still saved as numbers, so existing designs read and write the same) and evaluate it on every recompute; an unreadable or out-of-range point or axis is refused with an error. Tests: primitive points take expressions, follow parameters, renames and a moved component, and bad points are refused
This commit is contained in:
1 parent
31dadcee63
commit
c61b77613a
13 files changed
+412
-65
No files matched your search
@@ -10,7 +10,7 @@
|
||||
//! without moved components).
|
||||
|
||||
use serde_json::{Map, Value};
|
||||
use solvecraft_doc::{Mat, apply_point, apply_vector, is_identity, mat_inverse};
|
||||
use solvecraft_doc::{Mat, apply_point, apply_vector, is_identity, map_point_expr, mat_inverse};
|
||||
use solvecraft_geom::Vec3;
|
||||
|
||||
use crate::Session;
|
||||
@@ -203,11 +203,29 @@ impl Mapper<'_> {
|
||||
}
|
||||
|
||||
fn make(&mut self, v: &Value) -> Option<Value> {
|
||||
let p = vec3(v)?;
|
||||
let m = self.f.active;
|
||||
let Some(p) = vec3(v) else { return self.make_expr(&m, v) };
|
||||
self.local_point(&m, p)
|
||||
}
|
||||
|
||||
/// A point with expression coordinates (`["w / 2", 0, 0]`): mapped as expressions.
|
||||
fn make_expr(&mut self, m: &Mat, v: &Value) -> Option<Value> {
|
||||
let a = v.as_array().filter(|a| a.len() == 3)?;
|
||||
let c = |i: usize| match a.get(i)? {
|
||||
Value::Number(n) => n.as_f64().filter(|x| x.is_finite()).map(|x| format!("{x}")),
|
||||
Value::String(e) => Some(e.clone()),
|
||||
_ => None,
|
||||
};
|
||||
let mut p = [c(0)?, c(1)?, c(2)?];
|
||||
if is_identity(m) {
|
||||
return None;
|
||||
}
|
||||
let inv = mat_inverse(m)?;
|
||||
map_point_expr(&inv, &mut p);
|
||||
self.changed = true;
|
||||
Some(serde_json::json!(p))
|
||||
}
|
||||
|
||||
fn dir(&mut self, v: &Value) -> Option<Value> {
|
||||
let d = vec3(v)?;
|
||||
let m = self.first.unwrap_or(self.f.active);
|
||||
|
||||
Reference in new issue
Block a user