@@ -208,6 +208,7 @@ fn map_plane_ref(m: &Mat, p: &mut PlaneRef) {
|
||||
}
|
||||
PlaneRef::Midplane { .. }
|
||||
| PlaneRef::TwoEdges { .. }
|
||||
| PlaneRef::AxisPoint { .. }
|
||||
| PlaneRef::ThreePoints { .. }
|
||||
| PlaneRef::AlongPath { .. }
|
||||
| PlaneRef::Perpendicular { .. } => {
|
||||
|
||||
@@ -316,7 +316,7 @@ fn checked_plane(p: &PlaneRef, depth: usize) -> crate::Result<()> {
|
||||
checked_geo(g, depth + 1)?;
|
||||
}
|
||||
}
|
||||
PlaneRef::Midplane { a, b } | PlaneRef::TwoEdges { a, b } => {
|
||||
PlaneRef::Midplane { a, b } | PlaneRef::TwoEdges { a, b } | PlaneRef::AxisPoint { axis: a, point: b } => {
|
||||
checked_geo(a, depth + 1)?;
|
||||
checked_geo(b, depth + 1)?;
|
||||
}
|
||||
|
||||
@@ -620,6 +620,16 @@ pub(crate) fn resolve_geo_plane(ctx: &Ctx, p: &PlaneRef) -> Result<Plane> {
|
||||
};
|
||||
Plane::new(o1, d1, n.cross(d1)).ok_or_else(degenerate)
|
||||
}
|
||||
PlaneRef::AxisPoint { axis, point: at } => {
|
||||
let (origin, dir) = line(ctx, axis)?;
|
||||
let dir = dir.normalized().ok_or_else(|| bad("the axis has no direction"))?;
|
||||
let delta = point(ctx, at)? - origin;
|
||||
let across = delta - dir * delta.dot(dir);
|
||||
if !across.len().is_finite() || across.len() < 1e-9 {
|
||||
return Err(bad("the point is on the axis: pick a point off the axis to define a unique plane"));
|
||||
}
|
||||
Plane::new(origin, dir, across).ok_or_else(degenerate)
|
||||
}
|
||||
PlaneRef::ThreePoints { a, b, c } => {
|
||||
let (pa, pb, pc) = (point(ctx, a)?, point(ctx, b)?, point(ctx, c)?);
|
||||
if (pb - pa).cross(pc - pa).len() < 1e-9 {
|
||||
@@ -768,7 +778,7 @@ impl PlaneRef {
|
||||
/// The references of a plane built from model geometry.
|
||||
pub fn refs_mut(&mut self) -> Vec<&mut GeoRef> {
|
||||
match self {
|
||||
PlaneRef::Midplane { a, b } | PlaneRef::TwoEdges { a, b } => vec![a.as_mut(), b.as_mut()],
|
||||
PlaneRef::Midplane { a, b } | PlaneRef::TwoEdges { a, b } | PlaneRef::AxisPoint { axis: a, point: b } => vec![a.as_mut(), b.as_mut()],
|
||||
PlaneRef::Perpendicular { plane, line } => vec![plane.as_mut(), line.as_mut()],
|
||||
PlaneRef::ThreePoints { a, b, c } => vec![a.as_mut(), b.as_mut(), c.as_mut()],
|
||||
PlaneRef::Tangent { face, .. } => vec![face.as_mut()],
|
||||
|
||||
@@ -97,6 +97,8 @@ pub enum PlaneRef {
|
||||
Midplane { a: Box<GeoRef>, b: Box<GeoRef> },
|
||||
/// Through two straight edges (lines) that lie in one plane.
|
||||
TwoEdges { a: Box<GeoRef>, b: Box<GeoRef> },
|
||||
/// Through a line (axis) and a point not on that line.
|
||||
AxisPoint { axis: Box<GeoRef>, point: Box<GeoRef> },
|
||||
/// Through three points.
|
||||
ThreePoints { a: Box<GeoRef>, b: Box<GeoRef>, c: Box<GeoRef> },
|
||||
/// Tangent to a face (cylinder, cone, sphere, torus) where the point `at` lies over it.
|
||||
@@ -3976,6 +3978,7 @@ impl Document {
|
||||
}
|
||||
PlaneRef::Midplane { .. }
|
||||
| PlaneRef::TwoEdges { .. }
|
||||
| PlaneRef::AxisPoint { .. }
|
||||
| PlaneRef::ThreePoints { .. }
|
||||
| PlaneRef::Tangent { .. }
|
||||
| PlaneRef::AlongPath { .. }
|
||||
|
||||
@@ -8198,6 +8198,7 @@ fn plane_reads_geometry(plane: &PlaneRef) -> bool {
|
||||
PlaneRef::ThroughPoint { .. }
|
||||
| PlaneRef::Midplane { .. }
|
||||
| PlaneRef::TwoEdges { .. }
|
||||
| PlaneRef::AxisPoint { .. }
|
||||
| PlaneRef::ThreePoints { .. }
|
||||
| PlaneRef::Tangent { .. }
|
||||
| PlaneRef::AlongPath { .. }
|
||||
|
||||
@@ -202,6 +202,7 @@ fn construction_names_follow_renames_in_every_definition() {
|
||||
let planes = [
|
||||
json!({"type": "midplane", "a": plane, "b": plane}),
|
||||
json!({"type": "two_edges", "a": axis, "b": axis}),
|
||||
json!({"type": "axis_point", "axis": axis, "point": point}),
|
||||
json!({"type": "three_points", "a": point, "b": point, "c": point}),
|
||||
json!({"type": "tangent", "face": plane, "at": [0, 0, 0]}),
|
||||
json!({"type": "along_path", "path": axis, "t": "0.5"}),
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
//! Construction planes can store an associative axis and off-axis point reference.
|
||||
//! Older designs keep their existing plane definitions unchanged. The last release
|
||||
//! asks for an update rather than opening a design with this new plane definition.
|
||||
@@ -406,7 +406,7 @@ impl PlaneRef {
|
||||
g.walk_feature_refs(f, depth + 1);
|
||||
}
|
||||
}
|
||||
Self::Midplane { a, b } | Self::TwoEdges { a, b } | Self::Perpendicular { plane: a, line: b } => {
|
||||
Self::Midplane { a, b } | Self::TwoEdges { a, b } | Self::AxisPoint { axis: a, point: b } | Self::Perpendicular { plane: a, line: b } => {
|
||||
a.walk_feature_refs(f, depth + 1);
|
||||
b.walk_feature_refs(f, depth + 1);
|
||||
}
|
||||
@@ -437,7 +437,7 @@ impl PlaneRef {
|
||||
g.walk_feature_refs_mut(f, depth + 1);
|
||||
}
|
||||
}
|
||||
Self::Midplane { a, b } | Self::TwoEdges { a, b } | Self::Perpendicular { plane: a, line: b } => {
|
||||
Self::Midplane { a, b } | Self::TwoEdges { a, b } | Self::AxisPoint { axis: a, point: b } | Self::Perpendicular { plane: a, line: b } => {
|
||||
a.walk_feature_refs_mut(f, depth + 1);
|
||||
b.walk_feature_refs_mut(f, depth + 1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user