Move edge functions to KCL (#7259)
Signed-off-by: Nick Cameron <nrc@ncameron.org>
This commit is contained in:
@ -1,14 +1,16 @@
|
||||
//! Edge helper functions.
|
||||
|
||||
use anyhow::Result;
|
||||
use kcl_derive_docs::stdlib;
|
||||
use kcmc::{each_cmd as mcmd, ok_response::OkModelingCmdResponse, websocket::OkWebSocketResponseData, ModelingCmd};
|
||||
use kittycad_modeling_cmds as kcmc;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::{
|
||||
errors::{KclError, KclErrorDetails},
|
||||
execution::{types::RuntimeType, ExecState, ExtrudeSurface, KclValue, TagIdentifier},
|
||||
execution::{
|
||||
types::{ArrayLen, RuntimeType},
|
||||
ExecState, ExtrudeSurface, KclValue, TagIdentifier,
|
||||
},
|
||||
std::Args,
|
||||
};
|
||||
|
||||
@ -23,42 +25,6 @@ pub async fn get_opposite_edge(exec_state: &mut ExecState, args: Args) -> Result
|
||||
})
|
||||
}
|
||||
|
||||
/// Get the opposite edge to the edge given.
|
||||
///
|
||||
/// ```no_run
|
||||
/// exampleSketch = startSketchOn(XZ)
|
||||
/// |> startProfile(at = [0, 0])
|
||||
/// |> line(end = [10, 0])
|
||||
/// |> angledLine(
|
||||
/// angle = 60,
|
||||
/// length = 10,
|
||||
/// )
|
||||
/// |> angledLine(
|
||||
/// angle = 120,
|
||||
/// length = 10,
|
||||
/// )
|
||||
/// |> line(end = [-10, 0])
|
||||
/// |> angledLine(
|
||||
/// angle = 240,
|
||||
/// length = 10,
|
||||
/// tag = $referenceEdge,
|
||||
/// )
|
||||
/// |> close()
|
||||
///
|
||||
/// example = extrude(exampleSketch, length = 5)
|
||||
/// |> fillet(
|
||||
/// radius = 3,
|
||||
/// tags = [getOppositeEdge(referenceEdge)],
|
||||
/// )
|
||||
/// ```
|
||||
#[stdlib {
|
||||
name = "getOppositeEdge",
|
||||
unlabeled_first = true,
|
||||
args = {
|
||||
edge = { docs = "The tag of the edge you want to find the opposite edge of." },
|
||||
},
|
||||
tags = ["sketch"]
|
||||
}]
|
||||
async fn inner_get_opposite_edge(
|
||||
edge: TagIdentifier,
|
||||
exec_state: &mut ExecState,
|
||||
@ -106,42 +72,6 @@ pub async fn get_next_adjacent_edge(exec_state: &mut ExecState, args: Args) -> R
|
||||
})
|
||||
}
|
||||
|
||||
/// Get the next adjacent edge to the edge given.
|
||||
///
|
||||
/// ```no_run
|
||||
/// exampleSketch = startSketchOn(XZ)
|
||||
/// |> startProfile(at = [0, 0])
|
||||
/// |> line(end = [10, 0])
|
||||
/// |> angledLine(
|
||||
/// angle = 60,
|
||||
/// length = 10,
|
||||
/// )
|
||||
/// |> angledLine(
|
||||
/// angle = 120,
|
||||
/// length = 10,
|
||||
/// )
|
||||
/// |> line(end = [-10, 0])
|
||||
/// |> angledLine(
|
||||
/// angle = 240,
|
||||
/// length = 10,
|
||||
/// tag = $referenceEdge,
|
||||
/// )
|
||||
/// |> close()
|
||||
///
|
||||
/// example = extrude(exampleSketch, length = 5)
|
||||
/// |> fillet(
|
||||
/// radius = 3,
|
||||
/// tags = [getNextAdjacentEdge(referenceEdge)],
|
||||
/// )
|
||||
/// ```
|
||||
#[stdlib {
|
||||
name = "getNextAdjacentEdge",
|
||||
unlabeled_first = true,
|
||||
args = {
|
||||
edge = { docs = "The tag of the edge you want to find the next adjacent edge of." },
|
||||
},
|
||||
tags = ["sketch"]
|
||||
}]
|
||||
async fn inner_get_next_adjacent_edge(
|
||||
edge: TagIdentifier,
|
||||
exec_state: &mut ExecState,
|
||||
@ -198,42 +128,6 @@ pub async fn get_previous_adjacent_edge(exec_state: &mut ExecState, args: Args)
|
||||
})
|
||||
}
|
||||
|
||||
/// Get the previous adjacent edge to the edge given.
|
||||
///
|
||||
/// ```no_run
|
||||
/// exampleSketch = startSketchOn(XZ)
|
||||
/// |> startProfile(at = [0, 0])
|
||||
/// |> line(end = [10, 0])
|
||||
/// |> angledLine(
|
||||
/// angle = 60,
|
||||
/// length = 10,
|
||||
/// )
|
||||
/// |> angledLine(
|
||||
/// angle = 120,
|
||||
/// length = 10,
|
||||
/// )
|
||||
/// |> line(end = [-10, 0])
|
||||
/// |> angledLine(
|
||||
/// angle = 240,
|
||||
/// length = 10,
|
||||
/// tag = $referenceEdge,
|
||||
/// )
|
||||
/// |> close()
|
||||
///
|
||||
/// example = extrude(exampleSketch, length = 5)
|
||||
/// |> fillet(
|
||||
/// radius = 3,
|
||||
/// tags = [getPreviousAdjacentEdge(referenceEdge)],
|
||||
/// )
|
||||
/// ```
|
||||
#[stdlib {
|
||||
name = "getPreviousAdjacentEdge",
|
||||
unlabeled_first = true,
|
||||
args = {
|
||||
edge = { docs = "The tag of the edge you want to find the previous adjacent edge of." },
|
||||
},
|
||||
tags = ["sketch"]
|
||||
}]
|
||||
async fn inner_get_previous_adjacent_edge(
|
||||
edge: TagIdentifier,
|
||||
exec_state: &mut ExecState,
|
||||
@ -280,7 +174,11 @@ async fn inner_get_previous_adjacent_edge(
|
||||
|
||||
/// Get the shared edge between two faces.
|
||||
pub async fn get_common_edge(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
|
||||
let faces: Vec<TagIdentifier> = args.get_kw_arg("faces")?;
|
||||
let faces: Vec<TagIdentifier> = args.get_kw_arg_typed(
|
||||
"faces",
|
||||
&RuntimeType::Array(Box::new(RuntimeType::tag_identifier()), ArrayLen::Known(2)),
|
||||
exec_state,
|
||||
)?;
|
||||
|
||||
let edge = inner_get_common_edge(faces, exec_state, args.clone()).await?;
|
||||
Ok(KclValue::Uuid {
|
||||
@ -289,38 +187,6 @@ pub async fn get_common_edge(exec_state: &mut ExecState, args: Args) -> Result<K
|
||||
})
|
||||
}
|
||||
|
||||
/// Get the shared edge between two faces.
|
||||
///
|
||||
/// ```no_run
|
||||
/// // Get an edge shared between two faces, created after a chamfer.
|
||||
///
|
||||
/// scale = 20
|
||||
/// part001 = startSketchOn(XY)
|
||||
/// |> startProfile(at = [0, 0])
|
||||
/// |> line(end = [0, scale])
|
||||
/// |> line(end = [scale, 0])
|
||||
/// |> line(end = [0, -scale])
|
||||
/// |> close(tag = $line0)
|
||||
/// |> extrude(length = 20, tagEnd = $end0)
|
||||
/// // We tag the chamfer to reference it later.
|
||||
/// |> chamfer(length = 10, tags = [getOppositeEdge(line0)], tag = $chamfer0)
|
||||
///
|
||||
/// // Get the shared edge between the chamfer and the extrusion.
|
||||
/// commonEdge = getCommonEdge(faces = [chamfer0, end0])
|
||||
///
|
||||
/// // Chamfer the shared edge.
|
||||
/// // TODO: uncomment this when ssi for fillets lands
|
||||
/// // chamfer(part001, length = 5, tags = [commonEdge])
|
||||
/// ```
|
||||
#[stdlib {
|
||||
name = "getCommonEdge",
|
||||
feature_tree_operation = false,
|
||||
unlabeled_first = false,
|
||||
args = {
|
||||
faces = { docs = "The tags of the faces you want to find the common edge between" },
|
||||
},
|
||||
tags = ["sketch"]
|
||||
}]
|
||||
async fn inner_get_common_edge(
|
||||
faces: Vec<TagIdentifier>,
|
||||
exec_state: &mut ExecState,
|
||||
|
@ -77,10 +77,6 @@ lazy_static! {
|
||||
Box::new(crate::std::sketch::Subtract2D),
|
||||
Box::new(crate::std::patterns::PatternLinear2D),
|
||||
Box::new(crate::std::patterns::PatternCircular2D),
|
||||
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::sweep::Sweep),
|
||||
Box::new(crate::std::loft::Loft),
|
||||
Box::new(crate::std::assert::Assert),
|
||||
@ -213,10 +209,6 @@ pub(crate) fn std_fn(path: &str, fn_name: &str) -> (crate::std::StdFn, StdFnProp
|
||||
|e, a| Box::pin(crate::std::math::leg_angle_y(e, a)),
|
||||
StdFnProps::default("std::math::legAngY"),
|
||||
),
|
||||
("sketch", "circle") => (
|
||||
|e, a| Box::pin(crate::std::shapes::circle(e, a)),
|
||||
StdFnProps::default("std::sketch::circle"),
|
||||
),
|
||||
("prelude", "helix") => (
|
||||
|e, a| Box::pin(crate::std::helix::helix(e, a)),
|
||||
StdFnProps::default("std::helix").include_in_feature_tree(),
|
||||
@ -237,10 +229,6 @@ pub(crate) fn std_fn(path: &str, fn_name: &str) -> (crate::std::StdFn, StdFnProp
|
||||
|e, a| Box::pin(crate::std::transform::scale(e, a)),
|
||||
StdFnProps::default("std::transform::scale"),
|
||||
),
|
||||
("sketch", "revolve") => (
|
||||
|e, a| Box::pin(crate::std::revolve::revolve(e, a)),
|
||||
StdFnProps::default("std::sketch::revolve").include_in_feature_tree(),
|
||||
),
|
||||
("prelude", "offsetPlane") => (
|
||||
|e, a| Box::pin(crate::std::planes::offset_plane(e, a)),
|
||||
StdFnProps::default("std::offsetPlane").include_in_feature_tree(),
|
||||
@ -309,10 +297,34 @@ pub(crate) fn std_fn(path: &str, fn_name: &str) -> (crate::std::StdFn, StdFnProp
|
||||
|e, a| Box::pin(crate::std::clone::clone(e, a)),
|
||||
StdFnProps::default("std::clone").include_in_feature_tree(),
|
||||
),
|
||||
("sketch", "circle") => (
|
||||
|e, a| Box::pin(crate::std::shapes::circle(e, a)),
|
||||
StdFnProps::default("std::sketch::circle"),
|
||||
),
|
||||
("sketch", "patternTransform2d") => (
|
||||
|e, a| Box::pin(crate::std::patterns::pattern_transform_2d(e, a)),
|
||||
StdFnProps::default("std::sketch::patternTransform2d"),
|
||||
),
|
||||
("sketch", "revolve") => (
|
||||
|e, a| Box::pin(crate::std::revolve::revolve(e, a)),
|
||||
StdFnProps::default("std::sketch::revolve").include_in_feature_tree(),
|
||||
),
|
||||
("sketch", "getCommonEdge") => (
|
||||
|e, a| Box::pin(crate::std::edge::get_common_edge(e, a)),
|
||||
StdFnProps::default("std::sketch::getCommonEdge"),
|
||||
),
|
||||
("sketch", "getNextAdjacentEdge") => (
|
||||
|e, a| Box::pin(crate::std::edge::get_next_adjacent_edge(e, a)),
|
||||
StdFnProps::default("std::sketch::getNextAdjacentEdge"),
|
||||
),
|
||||
("sketch", "getOppositeEdge") => (
|
||||
|e, a| Box::pin(crate::std::edge::get_opposite_edge(e, a)),
|
||||
StdFnProps::default("std::sketch::revolve"),
|
||||
),
|
||||
("sketch", "getPreviousAdjacentEdge") => (
|
||||
|e, a| Box::pin(crate::std::edge::get_previous_adjacent_edge(e, a)),
|
||||
StdFnProps::default("std::sketch::getPreviousAdjacentEdge"),
|
||||
),
|
||||
("appearance", "hexString") => (
|
||||
|e, a| Box::pin(crate::std::appearance::hex_string(e, a)),
|
||||
StdFnProps::default("std::appearance::hexString"),
|
||||
|
Reference in New Issue
Block a user