Move operations on solids to be declared in KCL (#6462)

* Declare chamfer in KCL

Signed-off-by: Nick Cameron <nrc@ncameron.org>

* Ignore more in the simulation tests

Signed-off-by: Nick Cameron <nrc@ncameron.org>

* Declare fillet in KCL

Signed-off-by: Nick Cameron <nrc@ncameron.org>

* Move shell and hollow to KCL

Signed-off-by: Nick Cameron <nrc@ncameron.org>

---------

Signed-off-by: Nick Cameron <nrc@ncameron.org>
This commit is contained in:
Nick Cameron
2025-04-28 14:20:38 +12:00
committed by GitHub
parent 4439229ad2
commit efba773635
147 changed files with 6136 additions and 48096 deletions

View File

@ -1,7 +1,6 @@
//! Standard library chamfers.
use anyhow::Result;
use kcl_derive_docs::stdlib;
use kcmc::{each_cmd as mcmd, length_unit::LengthUnit, shared::CutType, ModelingCmd};
use kittycad_modeling_cmds as kcmc;
@ -31,81 +30,6 @@ pub async fn chamfer(exec_state: &mut ExecState, args: Args) -> Result<KclValue,
Ok(KclValue::Solid { value })
}
/// Cut a straight transitional edge along a tagged path.
///
/// Chamfer is similar in function and use to a fillet, except
/// a fillet will blend the transition along an edge, rather than cut
/// a sharp, straight transitional edge.
///
/// ```no_run
/// // Chamfer a mounting plate.
/// width = 20
/// length = 10
/// thickness = 1
/// chamferLength = 2
///
/// mountingPlateSketch = startSketchOn(XY)
/// |> startProfile(at = [-width/2, -length/2])
/// |> line(endAbsolute = [width/2, -length/2], tag = $edge1)
/// |> line(endAbsolute = [width/2, length/2], tag = $edge2)
/// |> line(endAbsolute = [-width/2, length/2], tag = $edge3)
/// |> close(tag = $edge4)
///
/// mountingPlate = extrude(mountingPlateSketch, length = thickness)
/// |> chamfer(
/// length = chamferLength,
/// tags = [
/// getNextAdjacentEdge(edge1),
/// getNextAdjacentEdge(edge2),
/// getNextAdjacentEdge(edge3),
/// getNextAdjacentEdge(edge4)
/// ],
/// )
/// ```
///
/// ```no_run
/// // Sketch on the face of a chamfer.
/// fn cube(pos, scale) {
/// sg = startSketchOn(XY)
/// |> startProfile(at = pos)
/// |> line(end = [0, scale])
/// |> line(end = [scale, 0])
/// |> line(end = [0, -scale])
///
/// return sg
/// }
///
/// part001 = cube([0,0], 20)
/// |> close(tag = $line1)
/// |> extrude(length = 20)
/// // We tag the chamfer to reference it later.
/// |> chamfer(
/// length = 10,
/// tags = [getOppositeEdge(line1)],
/// tag = $chamfer1,
/// )
///
/// sketch001 = startSketchOn(part001, face = chamfer1)
/// |> startProfile(at = [10, 10])
/// |> line(end = [2, 0])
/// |> line(end = [0, 2])
/// |> line(end = [-2, 0])
/// |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
/// |> close()
/// |> extrude(length = 10)
/// ```
#[stdlib {
name = "chamfer",
feature_tree_operation = true,
keywords = true,
unlabeled_first = true,
args = {
solid = { docs = "The solid whose edges should be chamfered" },
length = { docs = "The length of the chamfer" },
tags = { docs = "The paths you want to chamfer" },
tag = { docs = "Create a new tag which refers to this chamfer"},
}
}]
async fn inner_chamfer(
solid: Box<Solid>,
length: TyF64,

View File

@ -2,7 +2,6 @@
use anyhow::Result;
use indexmap::IndexMap;
use kcl_derive_docs::stdlib;
use kcmc::{each_cmd as mcmd, length_unit::LengthUnit, shared::CutType, ModelingCmd};
use kittycad_modeling_cmds as kcmc;
use schemars::JsonSchema;
@ -75,75 +74,6 @@ pub async fn fillet(exec_state: &mut ExecState, args: Args) -> Result<KclValue,
Ok(KclValue::Solid { value })
}
/// Blend a transitional edge along a tagged path, smoothing the sharp edge.
///
/// Fillet is similar in function and use to a chamfer, except
/// a chamfer will cut a sharp transition along an edge while fillet
/// will smoothly blend the transition.
///
/// ```no_run
/// width = 20
/// length = 10
/// thickness = 1
/// filletRadius = 2
///
/// mountingPlateSketch = startSketchOn("XY")
/// |> startProfile(at = [-width/2, -length/2])
/// |> line(endAbsolute = [width/2, -length/2], tag = $edge1)
/// |> line(endAbsolute = [width/2, length/2], tag = $edge2)
/// |> line(endAbsolute = [-width/2, length/2], tag = $edge3)
/// |> close(tag = $edge4)
///
/// mountingPlate = extrude(mountingPlateSketch, length = thickness)
/// |> fillet(
/// radius = filletRadius,
/// tags = [
/// getNextAdjacentEdge(edge1),
/// getNextAdjacentEdge(edge2),
/// getNextAdjacentEdge(edge3),
/// getNextAdjacentEdge(edge4)
/// ],
/// )
/// ```
///
/// ```no_run
/// width = 20
/// length = 10
/// thickness = 1
/// filletRadius = 1
///
/// mountingPlateSketch = startSketchOn("XY")
/// |> startProfile(at = [-width/2, -length/2])
/// |> line(endAbsolute = [width/2, -length/2], tag = $edge1)
/// |> line(endAbsolute = [width/2, length/2], tag = $edge2)
/// |> line(endAbsolute = [-width/2, length/2], tag = $edge3)
/// |> close(tag = $edge4)
///
/// mountingPlate = extrude(mountingPlateSketch, length = thickness)
/// |> fillet(
/// radius = filletRadius,
/// tolerance = 0.000001,
/// tags = [
/// getNextAdjacentEdge(edge1),
/// getNextAdjacentEdge(edge2),
/// getNextAdjacentEdge(edge3),
/// getNextAdjacentEdge(edge4)
/// ],
/// )
/// ```
#[stdlib {
name = "fillet",
feature_tree_operation = true,
keywords = true,
unlabeled_first = true,
args = {
solid = { docs = "The solid whose edges should be filletted" },
radius = { docs = "The radius of the fillet" },
tags = { docs = "The paths you want to fillet" },
tolerance = { docs = "The tolerance for this fillet" },
tag = { docs = "Create a new tag which refers to this fillet"},
}
}]
async fn inner_fillet(
solid: Box<Solid>,
radius: TyF64,

View File

@ -101,14 +101,10 @@ lazy_static! {
Box::new(crate::std::array::Map),
Box::new(crate::std::array::Push),
Box::new(crate::std::array::Pop),
Box::new(crate::std::chamfer::Chamfer),
Box::new(crate::std::fillet::Fillet),
Box::new(crate::std::edge::GetOppositeEdge),
Box::new(crate::std::edge::GetNextAdjacentEdge),
Box::new(crate::std::edge::GetPreviousAdjacentEdge),
Box::new(crate::std::edge::GetCommonEdge),
Box::new(crate::std::shell::Shell),
Box::new(crate::std::shell::Hollow),
Box::new(crate::std::sweep::Sweep),
Box::new(crate::std::loft::Loft),
Box::new(crate::std::math::Acos),
@ -212,6 +208,22 @@ pub(crate) fn std_fn(path: &str, fn_name: &str) -> (crate::std::StdFn, StdFnProp
|e, a| Box::pin(crate::std::planes::offset_plane(e, a)),
StdFnProps::default("std::offsetPlane").include_in_feature_tree(),
),
("solid", "fillet") => (
|e, a| Box::pin(crate::std::fillet::fillet(e, a)),
StdFnProps::default("std::solid::fillet").include_in_feature_tree(),
),
("solid", "chamfer") => (
|e, a| Box::pin(crate::std::chamfer::chamfer(e, a)),
StdFnProps::default("std::solid::chamfer").include_in_feature_tree(),
),
("solid", "shell") => (
|e, a| Box::pin(crate::std::shell::shell(e, a)),
StdFnProps::default("std::solid::shell").include_in_feature_tree(),
),
("solid", "hollow") => (
|e, a| Box::pin(crate::std::shell::hollow(e, a)),
StdFnProps::default("std::solid::hollow").include_in_feature_tree(),
),
_ => unreachable!(),
}
}

View File

@ -1,14 +1,16 @@
//! Standard library shells.
use anyhow::Result;
use kcl_derive_docs::stdlib;
use kcmc::{each_cmd as mcmd, length_unit::LengthUnit, ModelingCmd};
use kittycad_modeling_cmds as kcmc;
use super::args::TyF64;
use crate::{
errors::{KclError, KclErrorDetails},
execution::{types::RuntimeType, ExecState, KclValue, Solid},
execution::{
types::{ArrayLen, RuntimeType},
ExecState, KclValue, Solid,
},
std::{sketch::FaceTag, Args},
};
@ -16,169 +18,16 @@ use crate::{
pub async fn shell(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
let solids = args.get_unlabeled_kw_arg_typed("solids", &RuntimeType::solids(), exec_state)?;
let thickness: TyF64 = args.get_kw_arg_typed("thickness", &RuntimeType::length(), exec_state)?;
let faces = args.get_kw_arg("faces")?;
let faces = args.get_kw_arg_typed(
"faces",
&RuntimeType::Array(Box::new(RuntimeType::tag()), ArrayLen::NonEmpty),
exec_state,
)?;
let result = inner_shell(solids, thickness, faces, exec_state, args).await?;
Ok(result.into())
}
/// Remove volume from a 3-dimensional shape such that a wall of the
/// provided thickness remains, taking volume starting at the provided
/// face, leaving it open in that direction.
///
/// ```no_run
/// // Remove the end face for the extrusion.
/// firstSketch = startSketchOn(XY)
/// |> startProfile(at = [-12, 12])
/// |> line(end = [24, 0])
/// |> line(end = [0, -24])
/// |> line(end = [-24, 0])
/// |> close()
/// |> extrude(length = 6)
///
/// // Remove the end face for the extrusion.
/// shell(
/// firstSketch,
/// faces = [END],
/// thickness = 0.25,
/// )
/// ```
///
/// ```no_run
/// // Remove the start face for the extrusion.
/// firstSketch = startSketchOn(-XZ)
/// |> startProfile(at = [-12, 12])
/// |> line(end = [24, 0])
/// |> line(end = [0, -24])
/// |> line(end = [-24, 0])
/// |> close()
/// |> extrude(length = 6)
///
/// // Remove the start face for the extrusion.
/// shell(
/// firstSketch,
/// faces = [START],
/// thickness = 0.25,
/// )
/// ```
///
/// ```no_run
/// // Remove a tagged face and the end face for the extrusion.
/// firstSketch = startSketchOn(XY)
/// |> startProfile(at = [-12, 12])
/// |> line(end = [24, 0])
/// |> line(end = [0, -24])
/// |> line(end = [-24, 0], tag = $myTag)
/// |> close()
/// |> extrude(length = 6)
///
/// // Remove a tagged face for the extrusion.
/// shell(
/// firstSketch,
/// faces = [myTag],
/// thickness = 0.25,
/// )
/// ```
///
/// ```no_run
/// // Remove multiple faces at once.
/// firstSketch = startSketchOn(XY)
/// |> startProfile(at = [-12, 12])
/// |> line(end = [24, 0])
/// |> line(end = [0, -24])
/// |> line(end = [-24, 0], tag = $myTag)
/// |> close()
/// |> extrude(length = 6)
///
/// // Remove a tagged face and the end face for the extrusion.
/// shell(
/// firstSketch,
/// faces = [myTag, END],
/// thickness = 0.25,
/// )
/// ```
///
/// ```no_run
/// // Shell a sketch on face.
/// size = 100
/// case = startSketchOn(-XZ)
/// |> startProfile(at = [-size, -size])
/// |> line(end = [2 * size, 0])
/// |> line(end = [0, 2 * size])
/// |> tangentialArc(endAbsolute = [-size, size])
/// |> close()
/// |> extrude(length = 65)
///
/// thing1 = startSketchOn(case, face = END)
/// |> circle( center = [-size / 2, -size / 2], radius = 25 )
/// |> extrude(length = 50)
///
/// thing2 = startSketchOn(case, face = END)
/// |> circle( center = [size / 2, -size / 2], radius = 25 )
/// |> extrude(length = 50)
///
/// // We put "case" in the shell function to shell the entire object.
/// shell(case, faces = [START], thickness = 5)
/// ```
///
/// ```no_run
/// // Shell a sketch on face object on the end face.
/// size = 100
/// case = startSketchOn(XY)
/// |> startProfile(at = [-size, -size])
/// |> line(end = [2 * size, 0])
/// |> line(end = [0, 2 * size])
/// |> tangentialArc(endAbsolute = [-size, size])
/// |> close()
/// |> extrude(length = 65)
///
/// thing1 = startSketchOn(case, face = END)
/// |> circle( center = [-size / 2, -size / 2], radius = 25 )
/// |> extrude(length = 50)
///
/// thing2 = startSketchOn(case, face = END)
/// |> circle( center = [size / 2, -size / 2], radius = 25 )
/// |> extrude(length = 50)
///
/// // We put "thing1" in the shell function to shell the end face of the object.
/// shell(thing1, faces = [END], thickness = 5)
/// ```
///
/// ```no_run
/// // Shell sketched on face objects on the end face, include all sketches to shell
/// // the entire object.
///
/// size = 100
/// case = startSketchOn(XY)
/// |> startProfile(at = [-size, -size])
/// |> line(end = [2 * size, 0])
/// |> line(end = [0, 2 * size])
/// |> tangentialArc(endAbsolute = [-size, size])
/// |> close()
/// |> extrude(length = 65)
///
/// thing1 = startSketchOn(case, face = END)
/// |> circle( center = [-size / 2, -size / 2], radius = 25 )
/// |> extrude(length = 50)
///
/// thing2 = startSketchOn(case, face = END)
/// |> circle( center = [size / 2, -size / 2], radius = 25)
/// |> extrude(length = 50)
///
/// // We put "thing1" and "thing2" in the shell function to shell the end face of the object.
/// shell([thing1, thing2], faces = [END], thickness = 5)
/// ```
#[stdlib {
name = "shell",
feature_tree_operation = true,
keywords = true,
unlabeled_first = true,
args = {
solids = { docs = "Which solid (or solids) to shell out"},
thickness = {docs = "The thickness of the shell"},
faces = {docs = "The faces you want removed"},
}
}]
async fn inner_shell(
solids: Vec<Solid>,
thickness: TyF64,
@ -253,66 +102,6 @@ pub async fn hollow(exec_state: &mut ExecState, args: Args) -> Result<KclValue,
Ok(KclValue::Solid { value })
}
/// Make the inside of a 3D object hollow.
///
/// Remove volume from a 3-dimensional shape such that a wall of the
/// provided thickness remains around the exterior of the shape.
///
/// ```no_run
/// // Hollow a basic sketch.
/// firstSketch = startSketchOn(XY)
/// |> startProfile(at = [-12, 12])
/// |> line(end = [24, 0])
/// |> line(end = [0, -24])
/// |> line(end = [-24, 0])
/// |> close()
/// |> extrude(length = 6)
/// |> hollow(thickness = 0.25)
/// ```
///
/// ```no_run
/// // Hollow a basic sketch.
/// firstSketch = startSketchOn(-XZ)
/// |> startProfile(at = [-12, 12])
/// |> line(end = [24, 0])
/// |> line(end = [0, -24])
/// |> line(end = [-24, 0])
/// |> close()
/// |> extrude(length = 6)
/// |> hollow(thickness = 0.5)
/// ```
///
/// ```no_run
/// // Hollow a sketch on face object.
/// size = 100
/// case = startSketchOn(-XZ)
/// |> startProfile(at = [-size, -size])
/// |> line(end = [2 * size, 0])
/// |> line(end = [0, 2 * size])
/// |> tangentialArc(endAbsolute = [-size, size])
/// |> close()
/// |> extrude(length = 65)
///
/// thing1 = startSketchOn(case, face = END)
/// |> circle( center = [-size / 2, -size / 2], radius = 25 )
/// |> extrude(length = 50)
///
/// thing2 = startSketchOn(case, face = END)
/// |> circle( center = [size / 2, -size / 2], radius = 25 )
/// |> extrude(length = 50)
///
/// hollow(case, thickness = 0.5)
/// ```
#[stdlib {
name = "hollow",
feature_tree_operation = true,
keywords = true,
unlabeled_first = true,
args = {
solid = { docs = "Which solid to shell out" },
thickness = {docs = "The thickness of the shell" },
}
}]
async fn inner_hollow(
solid: Box<Solid>,
thickness: TyF64,