Construct: plane through an axis and a point (#10178) (#10472)

* claim: #10178

* feat: add plane through axis and point (#10178)
This commit is contained in:
PapaEcho
2026-11-01 09:15:25 +00:00
committed by GitHub
parent f25a8e6abc
commit ce72abacf9
24 changed files with 361 additions and 16 deletions
+22 -2
View File
@@ -16,8 +16,8 @@ use super::features::{add_feature, check_expr, plane_param, sketch_id};
use crate::params::{bad, req_expr, str_, vec3};
use crate::schema::construct::{
AxisEdgeParams, AxisNormalToFaceParams, AxisThroughCylinderParams, AxisTwoPlanesParams, AxisTwoPointsParams, MidplaneParams,
PlaneAlongPathParams, PlanePerpendicularParams, PlaneTangentParams, PlaneThreePointsParams, PlaneTwoEdgesParams, PointAlongPathParams,
PointCenterParams, PointEdgePlaneParams, PointThreePlanesParams, PointTwoEdgesParams, PointVertexParams,
PlaneAlongPathParams, PlaneAxisPointParams, PlanePerpendicularParams, PlaneTangentParams, PlaneThreePointsParams, PlaneTwoEdgesParams,
PointAlongPathParams, PointCenterParams, PointEdgePlaneParams, PointThreePlanesParams, PointTwoEdgesParams, PointVertexParams,
};
use crate::schema::features::FeatureResult;
use crate::schema::{TypedContract, output_schema_for};
@@ -39,6 +39,7 @@ const POINT_EDGE_PLANE_CONTRACT: TypedContract<PointEdgePlaneParams> = TypedCont
const POINT_ALONG_PATH_CONTRACT: TypedContract<PointAlongPathParams> = TypedContract::new();
const PLANE_MIDPLANE_CONTRACT: TypedContract<MidplaneParams> = TypedContract::new();
const PLANE_TWO_EDGES_CONTRACT: TypedContract<PlaneTwoEdgesParams> = TypedContract::new();
const PLANE_AXIS_POINT_CONTRACT: TypedContract<PlaneAxisPointParams> = TypedContract::new();
const PLANE_THREE_POINTS_CONTRACT: TypedContract<PlaneThreePointsParams> = TypedContract::new();
const PLANE_TANGENT_CONTRACT: TypedContract<PlaneTangentParams> = TypedContract::new();
const PLANE_ALONG_PATH_CONTRACT: TypedContract<PlaneAlongPathParams> = TypedContract::new();
@@ -123,6 +124,12 @@ pub static COMMANDS: &[CommandSpec] = &[
.contract(&PLANE_TWO_EDGES_CONTRACT)
.output(output_schema_for::<FeatureResult>)
.params("a, b: straight edge or line refs in one plane; name?"),
CommandSpec::new("construct.plane.axis_point", "Plane Through Axis And Point", crate::checked!("construct.plane.axis_point", plane_axis_point))
.at("SOLID", "CONSTRUCT")
.icon("plane_axis_point")
.contract(&PLANE_AXIS_POINT_CONTRACT)
.output(output_schema_for::<FeatureResult>)
.params("axis: origin axis, construction axis, straight edge or sketch line ref; point: off-axis point ref; name?"),
CommandSpec::new("construct.plane.three_points", "Plane Through Three Points", crate::checked!("construct.plane.three_points", plane_points))
.at("SOLID", "CONSTRUCT")
.icon("plane_three_points")
@@ -374,6 +381,19 @@ fn plane_edges(s: &mut Session, p: &Value) -> Result<Value> {
plane(s, p, PlaneRef::TwoEdges { a: Box::new(a), b: Box::new(b) })
}
fn plane_axis_point(s: &mut Session, p: &Value) -> Result<Value> {
let kind = plane_axis_point_kind(s, p)?;
add_feature(s, p, kind)
}
/// Shared parser for the constructor and its world-to-authoring-frame boundary.
pub(crate) fn plane_axis_point_kind(s: &Session, p: &Value) -> Result<FeatureKind> {
let cmd = "construct.plane.axis_point";
let axis = geo(s, p.get("axis"), cmd, "axis")?;
let point = geo(s, p.get("point"), cmd, "point")?;
Ok(FeatureKind::ConstructionPlane { plane: PlaneRef::AxisPoint { axis: Box::new(axis), point: Box::new(point) } })
}
fn plane_points(s: &mut Session, p: &Value) -> Result<Value> {
let cmd = "construct.plane.three_points";
let (a, b, c) = (geo(s, p.get("a"), cmd, "a")?, geo(s, p.get("b"), cmd, "b")?, geo(s, p.get("c"), cmd, "c")?);
+1 -1
View File
@@ -37,7 +37,7 @@ mod face;
mod features;
mod features_more;
mod join_pieces;
pub(crate) use construct::{GeoForm, GeoFormError, REF as GEO_REF_FORMS, SKETCH_PART, geo_form, is_model_axis};
pub(crate) use construct::{GeoForm, GeoFormError, REF as GEO_REF_FORMS, SKETCH_PART, geo_form, is_model_axis, plane_axis_point_kind};
pub(crate) use face::{FaceRefForm, face_ref_form};
pub(crate) use features::profiles as feature_profiles;
pub(crate) use features::{EdgeRefForm, PLANE_FORMS, axis_dir_form, axis_line_object, edge_ref_form, explicit_plane, plane_name_problem, sketch_key};
+82
View File
@@ -108,6 +108,88 @@ fn on_plane(pl: &Plane, p: Vec3) -> bool {
(p - pl.origin).dot(pl.normal()).abs() < 1e-3
}
#[test]
fn plane_through_axis_and_point_contains_both_and_rejects_an_on_axis_point() {
let mut s = Session::default();
run(&mut s, "construct.plane.axis_point", json!({"axis": {"axis": "Z"}, "point": {"point": [10, 20, 30]}, "name": "Fence"}));
let pl = plane(&s, "Fence");
for p in [Vec3::ZERO, Vec3::Z * 100.0, Vec3::new(10.0, 20.0, 30.0)] {
assert!(on_plane(&pl, p), "{p:?} is on {pl:?}");
}
assert!(parallel(pl.normal(), Vec3::new(-20.0, 10.0, 0.0)));
let before = s.doc.to_json();
let error = s.execute("construct.plane.axis_point", &json!({"axis": {"axis": "Z"}, "point": {"point": [0, 0, 50]}})).unwrap_err();
assert!(error.to_string().contains("point is on the axis"), "{error}");
assert_eq!(s.doc.to_json(), before, "a degenerate plane leaves the design unchanged");
}
#[test]
fn plane_through_axis_and_point_follows_renamed_sources_edits_undo_and_reopen() {
let mut s = Session::default();
run(&mut s, "construct.axis.two_points", json!({"a":{"point":[5,6,7]},"b":{"point":[5,6,17]},"name":"Spine"}));
run(&mut s, "construct.point.vertex", json!({"point":{"point":[15,6,7]},"name":"Pin"}));
run(&mut s, "construct.plane.axis_point", json!({"axis":{"axis":"Spine"},"point":{"construct_point":"Pin"},"name":"Fence"}));
assert!(parallel(plane(&s, "Fence").normal(), Vec3::Y));
run(&mut s, "timeline.rename", json!({"feature":"Spine","name":"Mast"}));
run(&mut s, "timeline.rename", json!({"feature":"Pin","name":"Peg"}));
let definition = run(&mut s, "timeline.inspect", json!({"feature":"Fence"}));
assert_eq!(definition["definition"]["plane"]["axis"]["name"], "Mast");
assert_eq!(definition["definition"]["plane"]["point"]["name"], "Peg");
run(&mut s, "timeline.edit", json!({"feature":"Peg","set":{"def.point":{"type":"point","p":[5,16,7]}}}));
assert!(parallel(plane(&s, "Fence").normal(), Vec3::X), "point edit rotates the dependent plane");
run(&mut s, "edit.undo", json!({}));
assert!(parallel(plane(&s, "Fence").normal(), Vec3::Y));
run(&mut s, "edit.redo", json!({}));
let reopened = solidcraft_doc::format::read(&s.doc.to_json()).unwrap();
let mut cold = Session::new(reopened);
cold.refresh();
assert!(cold.model.results.iter().all(|r| r.error.is_none()), "{:?}", cold.model.results);
let pl = plane(&cold, "Fence");
assert!(parallel(pl.normal(), Vec3::X));
assert!(on_plane(&pl, Vec3::new(5.0, 16.0, 7.0)));
run(&mut cold, "sketch.create", json!({"plane":"Fence"}));
}
#[test]
fn plane_through_axis_and_point_accepts_straight_model_and_sketch_lines() {
let mut s = part();
run(&mut s, "construct.plane.axis_point", json!({"axis":{"edge":[20,0,0]},"point":{"vertex":[40,30,0]},"name":"Base"}));
assert!(parallel(plane(&s, "Base").normal(), Vec3::Z));
let sk = run(&mut s, "sketch.create", json!({"plane":"XY"}))["sketch"].as_u64().unwrap();
let line = run(&mut s, "sketch.line", json!({"points":[[0,0],[10,0]]}));
let curve = line["curves"][0].as_str().unwrap();
run(&mut s, "sketch.finish", json!({}));
run(&mut s, "construct.plane.axis_point", json!({"axis":{"sketch":sk,"curve":curve},"point":{"point":[0,0,10]},"name":"Side"}));
assert!(parallel(plane(&s, "Side").normal(), Vec3::Y));
}
#[test]
fn plane_through_axis_and_point_in_a_moved_component_keeps_its_world_picks() {
let mut s = Session::default();
run(&mut s, "component.create", json!({"name":"Part","grounded":false}));
run(&mut s, "occurrence.move", json!({"occurrence":"Part:1","translate":[50,0,0]}));
run(&mut s, "construct.axis.two_points", json!({"a":{"point":[50,0,0]},"b":{"point":[50,0,10]},"name":"Mast"}));
run(&mut s, "construct.plane.axis_point", json!({"axis":{"axis":"Mast"},"point":{"point":[60,0,0]},"name":"Fence"}));
run(&mut s, "occurrence.move", json!({"occurrence":"Part:1","translate":[0,20,0]}));
let pl = plane(&s, "Fence");
assert!(parallel(pl.normal(), Vec3::Y));
for p in [Vec3::new(50.0, 20.0, 0.0), Vec3::new(50.0, 20.0, 10.0), Vec3::new(60.0, 20.0, 0.0)] {
assert!(on_plane(&pl, p), "{p:?} on {pl:?}");
}
run(&mut s, "component.activate", json!({"component":0}));
run(
&mut s,
"timeline.redefine",
json!({"feature":"Fence","command":"construct.plane.axis_point","params":{"axis":{"axis":"Mast"},"point":{"point":[70,20,0]}}}),
);
let definition = run(&mut s, "timeline.inspect", json!({"feature":"Fence"}));
assert_eq!(
definition["definition"]["plane"]["point"],
json!({"type":"point","p":[20.,0.,0.]}),
"redefine uses the feature's authoring frame, not the active root"
);
}
#[test]
fn axis_through_cylinder_cone_or_torus() {
let mut s = part();
+15 -1
View File
@@ -404,7 +404,7 @@ impl Nested {
});
if outer {
let inner = if id == "timeline.redefine" { None } else { Some(id) };
MAPPED.with(|m| m.set(inner.is_none_or(|i| !table(i).is_empty())));
MAPPED.with(|m| m.set(inner.is_none_or(|i| !table(i).is_empty() || i == "construct.plane.axis_point")));
}
(Nested, outer)
}
@@ -487,6 +487,20 @@ pub fn to_local(s: &Session, id: &str, params: &Value) -> Option<Value> {
{
return None;
}
if id == "construct.plane.axis_point" && placed(s) {
// Construction references include tagged saved forms as well as pick wrappers.
// Map the parsed definition once at the boundary, including a nested Edit Feature.
// The constructor can then name local model picks and retain their exact references.
let mut kind = crate::cmd::plane_axis_point_kind(s, params).ok()?;
kind.transform_geometry(&mat_inverse(&s.active_component_frame())?);
let solidcraft_doc::FeatureKind::ConstructionPlane { plane: solidcraft_doc::PlaneRef::AxisPoint { axis, point } } = kind else {
return None;
};
let mut out = params.clone();
out["axis"] = serde_json::to_value(axis).ok()?;
out["point"] = serde_json::to_value(point).ok()?;
return Some(out);
}
let keys = table(id);
if keys.is_empty() || !placed(s) {
return None;
+12
View File
@@ -175,6 +175,18 @@ pub struct PlaneTwoEdgesParams {
pub common: PlaneCommon,
}
/// Add a construction plane containing an axis and a point off that axis.
#[derive(Debug, Deserialize, JsonSchema)]
#[schemars(deny_unknown_fields)]
pub struct PlaneAxisPointParams {
/// An origin axis, construction axis, straight edge or sketch line reference.
pub axis: GeoRefParam,
/// A vertex, sketch point, construction point or fixed point, not on the axis.
pub point: GeoRefParam,
#[serde(flatten, deserialize_with = "feature_common")]
pub common: PlaneCommon,
}
/// Add a construction plane through three points.
#[derive(Debug, Deserialize, JsonSchema)]
#[schemars(deny_unknown_fields)]
+4 -2
View File
@@ -2,8 +2,8 @@ use serde_json::{Value, json};
use super::{
AxisEdgeParams, AxisNormalToFaceParams, AxisThroughCylinderParams, AxisTwoPlanesParams, AxisTwoPointsParams, MidplaneParams,
PlaneAlongPathParams, PlanePerpendicularParams, PlaneTangentParams, PlaneThreePointsParams, PlaneTwoEdgesParams, PointAlongPathParams,
PointCenterParams, PointEdgePlaneParams, PointThreePlanesParams, PointTwoEdgesParams, PointVertexParams,
PlaneAlongPathParams, PlaneAxisPointParams, PlanePerpendicularParams, PlaneTangentParams, PlaneThreePointsParams, PlaneTwoEdgesParams,
PointAlongPathParams, PointCenterParams, PointEdgePlaneParams, PointThreePlanesParams, PointTwoEdgesParams, PointVertexParams,
};
use crate::Session;
use crate::schema::features::FeatureResult;
@@ -24,6 +24,7 @@ fn schemas_and_the_key_check_agree() {
assert_keys(input_schema_for::<PointEdgePlaneParams>(), &["edge", "name", "participants", "plane"]);
assert_keys(input_schema_for::<PointAlongPathParams>(), &["name", "participants", "path", "t"]);
assert_keys(input_schema_for::<MidplaneParams>(), &["a", "b", "name", "participants"]);
assert_keys(input_schema_for::<PlaneAxisPointParams>(), &["axis", "name", "participants", "point"]);
assert_keys(input_schema_for::<PlaneTwoEdgesParams>(), &["a", "b", "name", "participants"]);
assert_keys(input_schema_for::<PlaneThreePointsParams>(), &["a", "b", "c", "name", "participants"]);
assert_keys(input_schema_for::<PlaneTangentParams>(), &["at", "face", "name", "participants"]);
@@ -88,6 +89,7 @@ fn construction_features_reply_with_feature_result() {
run("construct.axis.two_points", json!({"a": {"type": "point", "p": [0, 0, 0]}, "b": {"point": {"x": 1, "y": 2, "z": 3}}})),
run("construct.axis.edge", json!({"edge": {"edge": [5, 0, 0]}, "participants": []})),
run("construct.plane.midplane", json!({"a": "XY", "b": {"face": [5, 5, 10]}, "name": "Middle"})),
run("construct.plane.axis_point", json!({"axis":{"axis":"Z"},"point":{"point":[10,20,30]}})),
run("construct.plane.two_edges", json!({"a": {"edge": [5, 0, 0]}, "b": {"edge": [0, 5, 0]}})),
run("construct.plane.three_points", json!({"a": {"point": [0, 0, 0]}, "b": {"vertex": [10, 0, 0]}, "c": {"sketch": sketch, "point": point}})),
run("construct.plane.tangent", json!({"face": {"face": [35, 0, 5]}})),