Merge remote-tracking branch 'origin/main' into jess/cleaned-imports

This commit is contained in:
Paul Tagliamonte
2025-04-10 10:10:48 -04:00
289 changed files with 37694 additions and 40553 deletions

View File

@ -1221,11 +1221,11 @@ identifierGuy = 5
part001 = startSketchOn(XY)
|> startProfileAt([-1.2, 4.83], %)
|> line(end = [2.8, 0])
|> angledLine([100 + 100, 3.01], %)
|> angledLine([abc, 3.02], %)
|> angledLine([def(yo), 3.03], %)
|> angledLine([ghi(2), 3.04], %)
|> angledLine([jkl(yo) + 2, 3.05], %)
|> angledLine(angle = 100 + 100, length = 3.01)
|> angledLine(angle = abc, length = 3.02)
|> angledLine(angle = def(yo), length = 3.03)
|> angledLine(angle = ghi(2), length = 3.04)
|> angledLine(angle = jkl(yo) + 2, length = 3.05)
|> close()
yo2 = hmm([identifierGuy + 5])"#;
@ -2204,10 +2204,10 @@ let w = f() + f()
let ast = r#"fn bar(t) {
return startSketchOn(XY)
|> startProfileAt([0,0], %)
|> angledLine({
|> angledLine(
angle = -60,
length = segLen(t),
}, %)
)
|> line(end = [0, 0])
|> close()
}

View File

@ -104,21 +104,15 @@ const Part001 = startSketchOn('XY')
|> startProfileAt([pipeLargeDia - (thickness / 2), 38], %)
|> line([thickness, 0], %)
|> line([0, -1], %)
|> angledLineToX({
angle: 60,
to: pipeSmallDia + thickness
}, %)
|> angledLine(angle = 60, endAbsoluteX = pipeSmallDia + thickness)
|> line([0, -pipeLength], %)
|> angledLineToX({
angle: -60,
to: pipeLargeDia + thickness
}, %)
|> angledLine(angle = -60, endAbsoluteX = pipeLargeDia + thickness)
|> line([0, -1], %)
|> line([-thickness, 0], %)
|> line([0, 1], %)
|> angledLineToX({ angle: 120, to: pipeSmallDia }, %)
|> angledLine(angle = 120, endAbsoluteX = pipeSmallDia)
|> line([0, pipeLength], %)
|> angledLineToX({ angle: 60, to: pipeLargeDia }, %)
|> angledLine(angle = 60, endAbsoluteX = pipeLargeDia)
|> close()
|> revolve({ axis = Y }, %)
"
@ -140,21 +134,15 @@ const part001 = startSketchOn('XY')
|> startProfileAt([pipeLargeDia - (thickness / 2), 38], %)
|> line([thickness, 0], %)
|> line([0, -1], %)
|> angledLineToX({
angle: 60,
to: pipeSmallDia + thickness
}, %)
|> angledLine(angle = 60, endAbsoluteX = pipeSmallDia + thickness)
|> line([0, -pipeLength], %)
|> angledLineToX({
angle: -60,
to: pipeLargeDia + thickness
}, %)
|> angledLine(angle = -60, endAbsoluteX = pipeLargeDia + thickness)
|> line([0, -1], %)
|> line([-thickness, 0], %)
|> line([0, 1], %)
|> angledLineToX({ angle: 120, to: pipeSmallDia }, %)
|> angledLine(angle = 120, endAbsoluteX = pipeSmallDia)
|> line([0, pipeLength], %)
|> angledLineToX({ angle: 60, to: pipeLargeDia }, %)
|> angledLine(angle = 60, endAbsoluteX = pipeLargeDia)
|> close()
|> revolve({ axis = Y }, %)
"

View File

@ -4482,10 +4482,10 @@ e
/// ```
/// exampleSketch = startSketchOn("XZ")
/// |> startProfileAt([0, 0], %)
/// |> angledLine({
/// angle = 30,
/// length = 3 / cos(toRadians(30)),
/// }, %)
/// |> angledLine(
/// angle = 30,
/// length = 3 / cos(toRadians(30)),
/// )
/// |> yLine(endAbsolute = 0)
/// |> close(%)
///

View File

@ -1243,24 +1243,6 @@ impl<'a> FromKclValue<'a> for FaceTag {
}
}
impl<'a> FromKclValue<'a> for super::sketch::AngledLineToData {
fn from_kcl_val(arg: &'a KclValue) -> Option<Self> {
// Deserialize from an {angle, to} object.
let case1 = || {
let obj = arg.as_object()?;
let_field_of!(obj, to);
let_field_of!(obj, angle);
Some(Self { angle, to })
};
// Deserialize from an [angle, to] array.
let case2 = || {
let [angle, to] = arg.as_point2d()?;
Some(Self { angle, to })
};
case1().or_else(case2)
}
}
impl<'a> FromKclValue<'a> for super::sketch::ArcData {
fn from_kcl_val(arg: &'a KclValue) -> Option<Self> {
let obj = arg.as_object()?;
@ -1580,24 +1562,6 @@ impl<'a> FromKclValue<'a> for super::axis_or_reference::Axis3dOrEdgeReference {
}
}
impl<'a> FromKclValue<'a> for super::sketch::AngledLineData {
fn from_kcl_val(arg: &'a KclValue) -> Option<Self> {
let case1 = |arg: &KclValue| {
let obj = arg.as_object()?;
let_field_of!(obj, angle);
let_field_of!(obj, length);
Some(Self::AngleAndLengthNamed { angle, length })
};
let case2 = |arg: &KclValue| {
let array = arg.as_array()?;
let ang = array.first()?.as_f64()?;
let len = array.get(1)?.as_f64()?;
Some(Self::AngleAndLengthPair([ang, len]))
};
case1(arg).or_else(|| case2(arg))
}
}
impl<'a> FromKclValue<'a> for i64 {
fn from_kcl_val(arg: &'a KclValue) -> Option<Self> {
match arg {

View File

@ -29,19 +29,20 @@ pub async fn get_opposite_edge(exec_state: &mut ExecState, args: Args) -> Result
/// exampleSketch = startSketchOn('XZ')
/// |> startProfileAt([0, 0], %)
/// |> line(end = [10, 0])
/// |> angledLine({
/// angle = 60,
/// length = 10,
/// }, %)
/// |> angledLine({
/// angle = 120,
/// length = 10,
/// }, %)
/// |> angledLine(
/// angle = 60,
/// length = 10,
/// )
/// |> angledLine(
/// angle = 120,
/// length = 10,
/// )
/// |> line(end = [-10, 0])
/// |> angledLine({
/// angle = 240,
/// length = 10,
/// }, %, $referenceEdge)
/// |> angledLine(
/// angle = 240,
/// length = 10,
/// tag = $referenceEdge,
/// )
/// |> close()
///
/// example = extrude(exampleSketch, length = 5)
@ -102,19 +103,20 @@ pub async fn get_next_adjacent_edge(exec_state: &mut ExecState, args: Args) -> R
/// exampleSketch = startSketchOn('XZ')
/// |> startProfileAt([0, 0], %)
/// |> line(end = [10, 0])
/// |> angledLine({
/// angle = 60,
/// length = 10,
/// }, %)
/// |> angledLine({
/// angle = 120,
/// length = 10,
/// }, %)
/// |> angledLine(
/// angle = 60,
/// length = 10,
/// )
/// |> angledLine(
/// angle = 120,
/// length = 10,
/// )
/// |> line(end = [-10, 0])
/// |> angledLine({
/// angle = 240,
/// length = 10,
/// }, %, $referenceEdge)
/// |> angledLine(
/// angle = 240,
/// length = 10,
/// tag = $referenceEdge,
/// )
/// |> close()
///
/// example = extrude(exampleSketch, length = 5)
@ -188,19 +190,20 @@ pub async fn get_previous_adjacent_edge(exec_state: &mut ExecState, args: Args)
/// exampleSketch = startSketchOn('XZ')
/// |> startProfileAt([0, 0], %)
/// |> line(end = [10, 0])
/// |> angledLine({
/// angle = 60,
/// length = 10,
/// }, %)
/// |> angledLine({
/// angle = 120,
/// length = 10,
/// }, %)
/// |> angledLine(
/// angle = 60,
/// length = 10,
/// )
/// |> angledLine(
/// angle = 120,
/// length = 10,
/// )
/// |> line(end = [-10, 0])
/// |> angledLine({
/// angle = 240,
/// length = 10,
/// }, %, $referenceEdge)
/// |> angledLine(
/// angle = 240,
/// length = 10,
/// tag = $referenceEdge,
/// )
/// |> close()
///
/// example = extrude(exampleSketch, length = 5)

View File

@ -117,10 +117,10 @@ pub async fn sqrt(_exec_state: &mut ExecState, args: Args) -> Result<KclValue, K
/// ```no_run
/// exampleSketch = startSketchOn("XZ")
/// |> startProfileAt([0, 0], %)
/// |> angledLine({
/// |> angledLine(
/// angle = 50,
/// length = sqrt(2500),
/// }, %)
/// )
/// |> yLine(endAbsolute = 0)
/// |> close()
///
@ -150,15 +150,15 @@ pub async fn abs(_exec_state: &mut ExecState, args: Args) -> Result<KclValue, Kc
/// sketch001 = startSketchOn('XZ')
/// |> startProfileAt([0, 0], %)
/// |> line(end = [8, 0])
/// |> angledLine({
/// |> angledLine(
/// angle = abs(myAngle),
/// length = 5,
/// }, %)
/// )
/// |> line(end = [-5, 0])
/// |> angledLine({
/// |> angledLine(
/// angle = myAngle,
/// length = 5,
/// }, %)
/// )
/// |> close()
///
/// baseExtrusion = extrude(sketch001, length = 5)
@ -276,10 +276,10 @@ pub async fn min(exec_state: &mut ExecState, args: Args) -> Result<KclValue, Kcl
/// ```no_run
/// exampleSketch = startSketchOn("XZ")
/// |> startProfileAt([0, 0], %)
/// |> angledLine({
/// |> angledLine(
/// angle = 70,
/// length = min(15, 31, 4, 13, 22)
/// }, %)
/// )
/// |> line(end = [20, 0])
/// |> close()
///
@ -321,10 +321,10 @@ pub async fn max(exec_state: &mut ExecState, args: Args) -> Result<KclValue, Kcl
/// ```no_run
/// exampleSketch = startSketchOn("XZ")
/// |> startProfileAt([0, 0], %)
/// |> angledLine({
/// |> angledLine(
/// angle = 70,
/// length = max(15, 31, 4, 13, 22)
/// }, %)
/// )
/// |> line(end = [20, 0])
/// |> close()
///
@ -372,10 +372,10 @@ pub async fn pow(_exec_state: &mut ExecState, args: Args) -> Result<KclValue, Kc
/// ```no_run
/// exampleSketch = startSketchOn("XZ")
/// |> startProfileAt([0, 0], %)
/// |> angledLine({
/// |> angledLine(
/// angle = 50,
/// length = pow(5, 2),
/// }, %)
/// )
/// |> yLine(endAbsolute = 0)
/// |> close()
///
@ -402,10 +402,10 @@ pub async fn acos(_exec_state: &mut ExecState, args: Args) -> Result<KclValue, K
/// ```no_run
/// sketch001 = startSketchOn('XZ')
/// |> startProfileAt([0, 0], %)
/// |> angledLine({
/// |> angledLine(
/// angle = toDegrees(acos(0.5)),
/// length = 10,
/// }, %)
/// )
/// |> line(end = [5, 0])
/// |> line(endAbsolute = [12, 0])
/// |> close()
@ -433,10 +433,10 @@ pub async fn asin(_exec_state: &mut ExecState, args: Args) -> Result<KclValue, K
/// ```no_run
/// sketch001 = startSketchOn('XZ')
/// |> startProfileAt([0, 0], %)
/// |> angledLine({
/// |> angledLine(
/// angle = toDegrees(asin(0.5)),
/// length = 20,
/// }, %)
/// )
/// |> yLine(endAbsolute = 0)
/// |> close()
///
@ -463,10 +463,10 @@ pub async fn atan(_exec_state: &mut ExecState, args: Args) -> Result<KclValue, K
/// ```no_run
/// sketch001 = startSketchOn('XZ')
/// |> startProfileAt([0, 0], %)
/// |> angledLine({
/// |> angledLine(
/// angle = toDegrees(atan(1.25)),
/// length = 20,
/// }, %)
/// )
/// |> yLine(endAbsolute = 0)
/// |> close()
///
@ -493,10 +493,10 @@ pub async fn atan2(_exec_state: &mut ExecState, args: Args) -> Result<KclValue,
/// ```no_run
/// sketch001 = startSketchOn('XZ')
/// |> startProfileAt([0, 0], %)
/// |> angledLine({
/// |> angledLine(
/// angle = toDegrees(atan2(1.25, 2)),
/// length = 20,
/// }, %)
/// )
/// |> yLine(endAbsolute = 0)
/// |> close()
///
@ -657,10 +657,10 @@ pub async fn e(_exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclE
/// ```no_run
/// exampleSketch = startSketchOn("XZ")
/// |> startProfileAt([0, 0], %)
/// |> angledLine({
/// |> angledLine(
/// angle = 30,
/// length = 2 * e() ^ 2,
/// }, %)
/// )
/// |> yLine(endAbsolute = 0)
/// |> close()
///
@ -689,10 +689,10 @@ pub async fn tau(_exec_state: &mut ExecState, args: Args) -> Result<KclValue, Kc
/// ```no_run
/// exampleSketch = startSketchOn("XZ")
/// |> startProfileAt([0, 0], %)
/// |> angledLine({
/// |> angledLine(
/// angle = 50,
/// length = 10 * tau(),
/// }, %)
/// )
/// |> yLine(endAbsolute = 0)
/// |> close()
///
@ -720,10 +720,10 @@ pub async fn to_radians(_exec_state: &mut ExecState, args: Args) -> Result<KclVa
/// ```no_run
/// exampleSketch = startSketchOn("XZ")
/// |> startProfileAt([0, 0], %)
/// |> angledLine({
/// |> angledLine(
/// angle = 50,
/// length = 70 * cos(toRadians(45)),
/// }, %)
/// )
/// |> yLine(endAbsolute = 0)
/// |> close()
///
@ -750,10 +750,10 @@ pub async fn to_degrees(_exec_state: &mut ExecState, args: Args) -> Result<KclVa
/// ```no_run
/// exampleSketch = startSketchOn("XZ")
/// |> startProfileAt([0, 0], %)
/// |> angledLine({
/// |> angledLine(
/// angle = 50,
/// length = 70 * cos(toDegrees(pi()/4)),
/// }, %)
/// )
/// |> yLine(endAbsolute = 0)
/// |> close()
///

View File

@ -75,11 +75,7 @@ lazy_static! {
Box::new(crate::std::sketch::Line),
Box::new(crate::std::sketch::XLine),
Box::new(crate::std::sketch::YLine),
Box::new(crate::std::sketch::AngledLineToX),
Box::new(crate::std::sketch::AngledLineToY),
Box::new(crate::std::sketch::AngledLine),
Box::new(crate::std::sketch::AngledLineOfXLength),
Box::new(crate::std::sketch::AngledLineOfYLength),
Box::new(crate::std::sketch::AngledLineThatIntersects),
Box::new(crate::std::sketch::StartSketchOn),
Box::new(crate::std::sketch::StartProfileAt),

View File

@ -388,18 +388,19 @@ pub async fn segment_length(exec_state: &mut ExecState, args: Args) -> Result<Kc
/// ```no_run
/// exampleSketch = startSketchOn("XZ")
/// |> startProfileAt([0, 0], %)
/// |> angledLine({
/// |> angledLine(
/// angle = 60,
/// length = 10,
/// }, %, $thing)
/// tag = $thing,
/// )
/// |> tangentialArc({
/// offset = -120,
/// radius = 5,
/// }, %)
/// |> angledLine({
/// |> angledLine(
/// angle = -60,
/// length = segLen(thing),
/// }, %)
/// )
/// |> close()
///
/// example = extrude(exampleSketch, length = 5)
@ -440,9 +441,9 @@ pub async fn segment_angle(exec_state: &mut ExecState, args: Args) -> Result<Kcl
/// |> line(end = [10, 0])
/// |> line(end = [5, 10], tag = $seg01)
/// |> line(end = [-10, 0])
/// |> angledLine([segAng(seg01), 10], %)
/// |> angledLine(angle = segAng(seg01), length = 10)
/// |> line(end = [-10, 0])
/// |> angledLine([segAng(seg01), -15], %)
/// |> angledLine(angle = segAng(seg01), length = -15)
/// |> close()
///
/// example = extrude(exampleSketch, length = 4)
@ -485,10 +486,10 @@ pub async fn tangent_to_end(exec_state: &mut ExecState, args: Args) -> Result<Kc
/// |> startProfileAt([0, 0], %)
/// |> line(end = [20, 0])
/// |> tangentialArcToRelative([0, 10], %, $arc1)
/// |> angledLine({
/// angle: tangentToEnd(arc1),
/// length: 20,
/// }, %)
/// |> angledLine(
/// angle = tangentToEnd(arc1),
/// length = 20,
/// )
/// |> tangentialArcToRelative([0, -10], %)
/// |> close()
///
@ -501,10 +502,10 @@ pub async fn tangent_to_end(exec_state: &mut ExecState, args: Args) -> Result<Kc
/// |> startProfileAt([0, 0], %)
/// |> line(end = [0, 20])
/// |> tangentialArcTo([10, 20], %, $arc1)
/// |> angledLine({
/// angle: tangentToEnd(arc1),
/// length: 20,
/// }, %)
/// |> angledLine(
/// angle = tangentToEnd(arc1),
/// length = 20,
/// )
/// |> tangentialArcToRelative([-10, 0], %)
/// |> close()
///
@ -515,10 +516,10 @@ pub async fn tangent_to_end(exec_state: &mut ExecState, args: Args) -> Result<Kc
/// rectangleSketch = startSketchOn('XZ')
/// |> startProfileAt([0, 0], %)
/// |> line(end = [10, 0], tag = $seg1)
/// |> angledLine({
/// angle: tangentToEnd(seg1),
/// length: 10,
/// }, %)
/// |> angledLine(
/// angle = tangentToEnd(seg1),
/// length = 10,
/// )
/// |> line(end = [0, 10])
/// |> line(end = [-20, 0])
/// |> close()
@ -533,7 +534,7 @@ pub async fn tangent_to_end(exec_state: &mut ExecState, args: Args) -> Result<Kc
/// end: [10, 10],
/// interior: [5, 1]
/// }, %, $arc1)
/// |> angledLine([tangentToEnd(arc1), 20], %)
/// |> angledLine(angle = tangentToEnd(arc1), length = 20)
/// |> close()
/// ```
///
@ -543,7 +544,7 @@ pub async fn tangent_to_end(exec_state: &mut ExecState, args: Args) -> Result<Kc
///
/// triangleSketch = startSketchOn("XY")
/// |> startProfileAt([-5, 0], %)
/// |> angledLine([tangentToEnd(circ), 10], %)
/// |> angledLine(angle = tangentToEnd(circ), length = 10)
/// |> line(end = [-15, 0])
/// |> close()
/// ```
@ -593,10 +594,10 @@ pub async fn angle_to_match_length_x(exec_state: &mut ExecState, args: Args) ->
/// sketch001 = startSketchOn('XZ')
/// |> startProfileAt([0, 0], %)
/// |> line(end = [2, 5], tag = $seg01)
/// |> angledLineToX([
/// -angleToMatchLengthX(seg01, 7, %),
/// 10
/// ], %)
/// |> angledLine(
/// angle = -angleToMatchLengthX(seg01, 7, %),
/// endAbsoluteX = 10,
/// )
/// |> close()
///
/// extrusion = extrude(sketch001, length = 5)
@ -657,10 +658,10 @@ pub async fn angle_to_match_length_y(exec_state: &mut ExecState, args: Args) ->
/// sketch001 = startSketchOn('XZ')
/// |> startProfileAt([0, 0], %)
/// |> line(end = [1, 2], tag = $seg01)
/// |> angledLine({
/// |> angledLine(
/// angle = angleToMatchLengthY(seg01, 15, %),
/// length = 5,
/// }, %)
/// )
/// |> yLine(endAbsolute = 0)
/// |> close()
///

View File

@ -96,7 +96,6 @@ pub const NEW_TAG_KW: &str = "tag";
/// Draw a line to a point.
pub async fn line(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
// let (to, sketch, tag): ([f64; 2], Sketch, Option<TagNode>) = args.get_data_and_sketch_and_tag()?;
let sketch =
args.get_unlabeled_kw_arg_typed("sketch", &RuntimeType::Primitive(PrimitiveType::Sketch), exec_state)?;
let end = args.get_kw_arg_opt("end")?;
@ -284,16 +283,16 @@ pub async fn x_line(exec_state: &mut ExecState, args: Args) -> Result<KclValue,
/// exampleSketch = startSketchOn(XZ)
/// |> startProfileAt([0, 0], %)
/// |> xLine(length = 15)
/// |> angledLine({
/// |> angledLine(
/// angle = 80,
/// length = 15,
/// }, %)
/// )
/// |> line(end = [8, -10])
/// |> xLine(length = 10)
/// |> angledLine({
/// |> angledLine(
/// angle = 120,
/// length = 30,
/// }, %)
/// )
/// |> xLine(length = -15)
/// |> close()
///
@ -353,10 +352,10 @@ pub async fn y_line(exec_state: &mut ExecState, args: Args) -> Result<KclValue,
/// exampleSketch = startSketchOn(XZ)
/// |> startProfileAt([0, 0], %)
/// |> yLine(length = 15)
/// |> angledLine({
/// |> angledLine(
/// angle = 30,
/// length = 15,
/// }, %)
/// )
/// |> line(end = [8, -10])
/// |> yLine(length = -5)
/// |> close()
@ -396,28 +395,31 @@ async fn inner_y_line(
.await
}
/// Data to draw an angled line.
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema)]
#[ts(export)]
#[serde(rename_all = "camelCase", untagged)]
pub enum AngledLineData {
/// An angle and length with explicitly named parameters
AngleAndLengthNamed {
/// The angle of the line (in degrees).
angle: f64,
/// The length of the line.
length: f64,
},
/// An angle and length given as a pair
AngleAndLengthPair([f64; 2]),
}
/// Draw an angled line.
pub async fn angled_line(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
let (data, sketch, tag): (AngledLineData, Sketch, Option<TagNode>) =
args.get_data_and_sketch_and_tag(exec_state)?;
let sketch =
args.get_unlabeled_kw_arg_typed("sketch", &RuntimeType::Primitive(PrimitiveType::Sketch), exec_state)?;
let angle = args.get_kw_arg("angle")?;
let length = args.get_kw_arg_opt("length")?;
let length_x = args.get_kw_arg_opt("lengthX")?;
let length_y = args.get_kw_arg_opt("lengthY")?;
let end_absolute_x = args.get_kw_arg_opt("endAbsoluteX")?;
let end_absolute_y = args.get_kw_arg_opt("endAbsoluteY")?;
let tag = args.get_kw_arg_opt(NEW_TAG_KW)?;
let new_sketch = inner_angled_line(data, sketch, tag, exec_state, args).await?;
let new_sketch = inner_angled_line(
sketch,
angle,
length,
length_x,
length_y,
end_absolute_x,
end_absolute_y,
tag,
exec_state,
args,
)
.await?;
Ok(KclValue::Sketch {
value: Box::new(new_sketch),
})
@ -430,10 +432,10 @@ pub async fn angled_line(exec_state: &mut ExecState, args: Args) -> Result<KclVa
/// exampleSketch = startSketchOn(XZ)
/// |> startProfileAt([0, 0], %)
/// |> yLine(endAbsolute = 15)
/// |> angledLine({
/// |> angledLine(
/// angle = 30,
/// length = 15,
/// }, %)
/// )
/// |> line(end = [8, -10])
/// |> yLine(endAbsolute = 0)
/// |> close()
@ -442,24 +444,94 @@ pub async fn angled_line(exec_state: &mut ExecState, args: Args) -> Result<KclVa
/// ```
#[stdlib {
name = "angledLine",
keywords = true,
unlabeled_first = true,
args = {
sketch = { docs = "Which sketch should this path be added to?"},
angle = { docs = "Which angle should the line be drawn at?" },
length = { docs = "Draw the line this distance along the given angle. Only one of `length`, `lengthX`, `lengthY`, `lengthAbsoluteEndX`, `lengthAbsoluteEndY` can be given."},
length_x = { docs = "Draw the line this distance along the X axis. Only one of `length`, `lengthX`, `lengthY`, `lengthAbsoluteEndX`, `lengthAbsoluteEndY` can be given."},
length_y = { docs = "Draw the line this distance along the Y axis. Only one of `length`, `lengthX`, `lengthY`, `lengthAbsoluteEndX`, `lengthAbsoluteEndY` can be given."},
end_absolute_x = { docs = "Draw the line along the given angle until it reaches this point along the X axis. Only one of `length`, `lengthX`, `lengthY`, `lengthAbsoluteEndX`, `lengthAbsoluteEndY` can be given."},
end_absolute_y = { docs = "Draw the line along the given angle until it reaches this point along the Y axis. Only one of `length`, `lengthX`, `lengthY`, `lengthAbsoluteEndX`, `lengthAbsoluteEndY` can be given."},
tag = { docs = "Create a new tag which refers to this line"},
}
}]
#[allow(clippy::too_many_arguments)]
async fn inner_angled_line(
data: AngledLineData,
sketch: Sketch,
angle: f64,
length: Option<f64>,
length_x: Option<f64>,
length_y: Option<f64>,
end_absolute_x: Option<f64>,
end_absolute_y: Option<f64>,
tag: Option<TagNode>,
exec_state: &mut ExecState,
args: Args,
) -> Result<Sketch, KclError> {
let options_given = [length, length_x, length_y, end_absolute_x, end_absolute_y]
.iter()
.filter(|x| x.is_some())
.count();
if options_given > 1 {
return Err(KclError::Type(KclErrorDetails {
message: " one of `length`, `lengthX`, `lengthY`, `lengthAbsoluteEndX`, `lengthAbsoluteEndY` can be given"
.to_string(),
source_ranges: vec![args.source_range],
}));
}
if let Some(length_x) = length_x {
return inner_angled_line_of_x_length(angle, length_x, sketch, tag, exec_state, args).await;
}
if let Some(length_y) = length_y {
return inner_angled_line_of_y_length(angle, length_y, sketch, tag, exec_state, args).await;
}
let angle_degrees = angle;
match (length, length_x, length_y, end_absolute_x, end_absolute_y) {
(Some(length), None, None, None, None) => {
inner_angled_line_length(sketch, angle_degrees, length, tag, exec_state, args).await
}
(None, Some(length_x), None, None, None) => {
inner_angled_line_of_x_length(angle_degrees, length_x, sketch, tag, exec_state, args).await
}
(None, None, Some(length_y), None, None) => {
inner_angled_line_of_y_length(angle_degrees, length_y, sketch, tag, exec_state, args).await
}
(None, None, None, Some(end_absolute_x), None) => {
inner_angled_line_to_x(angle_degrees, end_absolute_x, sketch, tag, exec_state, args).await
}
(None, None, None, None, Some(end_absolute_y)) => {
inner_angled_line_to_y(angle_degrees, end_absolute_y, sketch, tag, exec_state, args).await
}
(None, None, None, None, None) => Err(KclError::Type(KclErrorDetails {
message: "One of `length`, `lengthX`, `lengthY`, `lengthAbsoluteEndX`, `lengthAbsoluteEndY` must be given"
.to_string(),
source_ranges: vec![args.source_range],
})),
_ => Err(KclError::Type(KclErrorDetails {
message:
"Only One of `length`, `lengthX`, `lengthY`, `lengthAbsoluteEndX`, `lengthAbsoluteEndY` can be given"
.to_string(),
source_ranges: vec![args.source_range],
})),
}
}
async fn inner_angled_line_length(
sketch: Sketch,
angle_degrees: f64,
length: f64,
tag: Option<TagNode>,
exec_state: &mut ExecState,
args: Args,
) -> Result<Sketch, KclError> {
let from = sketch.current_pen_position()?;
let (angle, length) = match data {
AngledLineData::AngleAndLengthNamed { angle, length } => (angle, length),
AngledLineData::AngleAndLengthPair(pair) => (pair[0], pair[1]),
};
//double check me on this one - mike
let delta: [f64; 2] = [
length * f64::cos(angle.to_radians()),
length * f64::sin(angle.to_radians()),
length * f64::cos(angle_degrees.to_radians()),
length * f64::sin(angle_degrees.to_radians()),
];
let relative = true;
@ -501,123 +573,53 @@ async fn inner_angled_line(
Ok(new_sketch)
}
/// Draw an angled line of a given x length.
pub async fn angled_line_of_x_length(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
let (data, sketch, tag): (AngledLineData, Sketch, Option<TagNode>) =
args.get_data_and_sketch_and_tag(exec_state)?;
let new_sketch = inner_angled_line_of_x_length(data, sketch, tag, exec_state, args).await?;
Ok(KclValue::Sketch {
value: Box::new(new_sketch),
})
}
/// Create a line segment from the current 2-dimensional sketch origin
/// along some angle (in degrees) for some relative length in the 'x' dimension.
///
/// ```no_run
/// sketch001 = startSketchOn(XZ)
/// |> startProfileAt([0, 0], %)
/// |> angledLineOfXLength({ angle = 45, length = 10 }, %, $edge1)
/// |> angledLineOfXLength({ angle = -15, length = 20 }, %, $edge2)
/// |> line(end = [0, -5])
/// |> close(tag = $edge3)
///
/// extrusion = extrude(sketch001, length = 10)
/// ```
#[stdlib {
name = "angledLineOfXLength",
}]
async fn inner_angled_line_of_x_length(
data: AngledLineData,
angle_degrees: f64,
length: f64,
sketch: Sketch,
tag: Option<TagNode>,
exec_state: &mut ExecState,
args: Args,
) -> Result<Sketch, KclError> {
let (angle, length) = match data {
AngledLineData::AngleAndLengthNamed { angle, length } => (angle, length),
AngledLineData::AngleAndLengthPair(pair) => (pair[0], pair[1]),
};
if angle.abs() == 270.0 {
if angle_degrees.abs() == 270.0 {
return Err(KclError::Type(KclErrorDetails {
message: "Cannot have an x constrained angle of 270 degrees".to_string(),
source_ranges: vec![args.source_range],
}));
}
if angle.abs() == 90.0 {
if angle_degrees.abs() == 90.0 {
return Err(KclError::Type(KclErrorDetails {
message: "Cannot have an x constrained angle of 90 degrees".to_string(),
source_ranges: vec![args.source_range],
}));
}
let to = get_y_component(Angle::from_degrees(angle), length);
let to = get_y_component(Angle::from_degrees(angle_degrees), length);
let new_sketch = straight_line(StraightLineParams::relative(to.into(), sketch, tag), exec_state, args).await?;
Ok(new_sketch)
}
/// Data to draw an angled line to a point.
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema)]
#[ts(export)]
#[serde(rename_all = "camelCase")]
pub struct AngledLineToData {
/// The angle of the line.
pub angle: f64,
/// The point to draw to.
pub to: f64,
}
/// Draw an angled line to a given x coordinate.
pub async fn angled_line_to_x(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
let (data, sketch, tag): (AngledLineToData, Sketch, Option<TagNode>) =
args.get_data_and_sketch_and_tag(exec_state)?;
let new_sketch = inner_angled_line_to_x(data, sketch, tag, exec_state, args).await?;
Ok(KclValue::Sketch {
value: Box::new(new_sketch),
})
}
/// Create a line segment from the current 2-dimensional sketch origin
/// along some angle (in degrees) for some length, ending at the provided value
/// in the 'x' dimension.
///
/// ```no_run
/// exampleSketch = startSketchOn(XZ)
/// |> startProfileAt([0, 0], %)
/// |> angledLineToX({ angle = 30, to = 10 }, %)
/// |> line(end = [0, 10])
/// |> line(end = [-10, 0])
/// |> close()
///
/// example = extrude(exampleSketch, length = 10)
/// ```
#[stdlib {
name = "angledLineToX",
}]
async fn inner_angled_line_to_x(
data: AngledLineToData,
angle_degrees: f64,
x_to: f64,
sketch: Sketch,
tag: Option<TagNode>,
exec_state: &mut ExecState,
args: Args,
) -> Result<Sketch, KclError> {
let from = sketch.current_pen_position()?;
let AngledLineToData { angle, to: x_to } = data;
if angle.abs() == 270.0 {
if angle_degrees.abs() == 270.0 {
return Err(KclError::Type(KclErrorDetails {
message: "Cannot have an x constrained angle of 270 degrees".to_string(),
source_ranges: vec![args.source_range],
}));
}
if angle.abs() == 90.0 {
if angle_degrees.abs() == 90.0 {
return Err(KclError::Type(KclErrorDetails {
message: "Cannot have an x constrained angle of 90 degrees".to_string(),
source_ranges: vec![args.source_range],
@ -625,7 +627,7 @@ async fn inner_angled_line_to_x(
}
let x_component = x_to - from.x;
let y_component = x_component * f64::tan(angle.to_radians());
let y_component = x_component * f64::tan(angle_degrees.to_radians());
let y_to = from.y + y_component;
let new_sketch = straight_line(
@ -637,115 +639,53 @@ async fn inner_angled_line_to_x(
Ok(new_sketch)
}
/// Draw an angled line of a given y length.
pub async fn angled_line_of_y_length(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
let (data, sketch, tag): (AngledLineData, Sketch, Option<TagNode>) =
args.get_data_and_sketch_and_tag(exec_state)?;
let new_sketch = inner_angled_line_of_y_length(data, sketch, tag, exec_state, args).await?;
Ok(KclValue::Sketch {
value: Box::new(new_sketch),
})
}
/// Create a line segment from the current 2-dimensional sketch origin
/// along some angle (in degrees) for some relative length in the 'y' dimension.
///
/// ```no_run
/// exampleSketch = startSketchOn(XZ)
/// |> startProfileAt([0, 0], %)
/// |> line(end = [10, 0])
/// |> angledLineOfYLength({ angle = 45, length = 10 }, %)
/// |> line(end = [0, 10])
/// |> angledLineOfYLength({ angle = 135, length = 10 }, %)
/// |> line(end = [-10, 0])
/// |> line(end = [0, -30])
///
/// example = extrude(exampleSketch, length = 10)
/// ```
#[stdlib {
name = "angledLineOfYLength",
}]
async fn inner_angled_line_of_y_length(
data: AngledLineData,
angle_degrees: f64,
length: f64,
sketch: Sketch,
tag: Option<TagNode>,
exec_state: &mut ExecState,
args: Args,
) -> Result<Sketch, KclError> {
let (angle, length) = match data {
AngledLineData::AngleAndLengthNamed { angle, length } => (angle, length),
AngledLineData::AngleAndLengthPair(pair) => (pair[0], pair[1]),
};
if angle.abs() == 0.0 {
if angle_degrees.abs() == 0.0 {
return Err(KclError::Type(KclErrorDetails {
message: "Cannot have a y constrained angle of 0 degrees".to_string(),
source_ranges: vec![args.source_range],
}));
}
if angle.abs() == 180.0 {
if angle_degrees.abs() == 180.0 {
return Err(KclError::Type(KclErrorDetails {
message: "Cannot have a y constrained angle of 180 degrees".to_string(),
source_ranges: vec![args.source_range],
}));
}
let to = get_x_component(Angle::from_degrees(angle), length);
let to = get_x_component(Angle::from_degrees(angle_degrees), length);
let new_sketch = straight_line(StraightLineParams::relative(to.into(), sketch, tag), exec_state, args).await?;
Ok(new_sketch)
}
/// Draw an angled line to a given y coordinate.
pub async fn angled_line_to_y(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
let (data, sketch, tag): (AngledLineToData, Sketch, Option<TagNode>) =
args.get_data_and_sketch_and_tag(exec_state)?;
let new_sketch = inner_angled_line_to_y(data, sketch, tag, exec_state, args).await?;
Ok(KclValue::Sketch {
value: Box::new(new_sketch),
})
}
/// Create a line segment from the current 2-dimensional sketch origin
/// along some angle (in degrees) for some length, ending at the provided value
/// in the 'y' dimension.
///
/// ```no_run
/// exampleSketch = startSketchOn(XZ)
/// |> startProfileAt([0, 0], %)
/// |> angledLineToY({ angle = 60, to = 20 }, %)
/// |> line(end = [-20, 0])
/// |> angledLineToY({ angle = 70, to = 10 }, %)
/// |> close()
///
/// example = extrude(exampleSketch, length = 10)
/// ```
#[stdlib {
name = "angledLineToY",
}]
async fn inner_angled_line_to_y(
data: AngledLineToData,
angle_degrees: f64,
y_to: f64,
sketch: Sketch,
tag: Option<TagNode>,
exec_state: &mut ExecState,
args: Args,
) -> Result<Sketch, KclError> {
let from = sketch.current_pen_position()?;
let AngledLineToData { angle, to: y_to } = data;
if angle.abs() == 0.0 {
if angle_degrees.abs() == 0.0 {
return Err(KclError::Type(KclErrorDetails {
message: "Cannot have a y constrained angle of 0 degrees".to_string(),
source_ranges: vec![args.source_range],
}));
}
if angle.abs() == 180.0 {
if angle_degrees.abs() == 180.0 {
return Err(KclError::Type(KclErrorDetails {
message: "Cannot have a y constrained angle of 180 degrees".to_string(),
source_ranges: vec![args.source_range],
@ -753,7 +693,7 @@ async fn inner_angled_line_to_y(
}
let y_component = y_to - from.y;
let x_component = y_component / f64::tan(angle.to_radians());
let x_component = y_component / f64::tan(angle_degrees.to_radians());
let x_to = from.x + x_component;
let new_sketch = straight_line(
@ -811,7 +751,7 @@ pub async fn angled_line_that_intersects(exec_state: &mut ExecState, args: Args)
#[stdlib {
name = "angledLineThatIntersects",
}]
async fn inner_angled_line_that_intersects(
pub async fn inner_angled_line_that_intersects(
data: AngledLineThatIntersectsData,
sketch: Sketch,
tag: Option<TagNode>,
@ -1381,9 +1321,9 @@ pub async fn profile_start_x(exec_state: &mut ExecState, args: Args) -> Result<K
/// ```no_run
/// sketch001 = startSketchOn(XY)
/// |> startProfileAt([5, 2], %)
/// |> angledLine([-26.6, 50], %)
/// |> angledLine([90, 50], %)
/// |> angledLineToX({ angle = 30, to = profileStartX(%) }, %)
/// |> angledLine(angle = -26.6, length = 50)
/// |> angledLine(angle = 90, length = 50)
/// |> angledLine(angle = 30, endAbsoluteX = profileStartX(%))
/// ```
#[stdlib {
name = "profileStartX"
@ -1406,8 +1346,8 @@ pub async fn profile_start_y(exec_state: &mut ExecState, args: Args) -> Result<K
/// ```no_run
/// sketch001 = startSketchOn(XY)
/// |> startProfileAt([5, 2], %)
/// |> angledLine({ angle = -60, length = 14 }, %)
/// |> angledLineToY({ angle = 30, to = profileStartY(%) }, %)
/// |> angledLine(angle = -60, length = 14 )
/// |> angledLine(angle = 30, endAbsoluteY = profileStartY(%))
/// ```
#[stdlib {
name = "profileStartY"
@ -1430,8 +1370,8 @@ pub async fn profile_start(exec_state: &mut ExecState, args: Args) -> Result<Kcl
/// ```no_run
/// sketch001 = startSketchOn(XY)
/// |> startProfileAt([5, 2], %)
/// |> angledLine({ angle = 120, length = 50 }, %, $seg01)
/// |> angledLine({ angle = segAng(seg01) + 120, length = 50 }, %)
/// |> angledLine(angle = 120, length = 50 , tag = $seg01)
/// |> angledLine(angle = segAng(seg01) + 120, length = 50 )
/// |> line(end = profileStart(%))
/// |> close()
/// |> extrude(length = 20)
@ -1800,15 +1740,15 @@ pub async fn tangential_arc(exec_state: &mut ExecState, args: Args) -> Result<Kc
/// ```no_run
/// exampleSketch = startSketchOn(XZ)
/// |> startProfileAt([0, 0], %)
/// |> angledLine({
/// |> angledLine(
/// angle = 60,
/// length = 10,
/// }, %)
/// )
/// |> tangentialArc({ radius = 10, offset = -120 }, %)
/// |> angledLine({
/// |> angledLine(
/// angle = -60,
/// length = 10,
/// }, %)
/// )
/// |> close()
///
/// example = extrude(exampleSketch, length = 10)
@ -1934,10 +1874,10 @@ pub async fn tangential_arc_to_relative(exec_state: &mut ExecState, args: Args)
/// ```no_run
/// exampleSketch = startSketchOn(XZ)
/// |> startProfileAt([0, 0], %)
/// |> angledLine({
/// |> angledLine(
/// angle = 60,
/// length = 10,
/// }, %)
/// )
/// |> tangentialArcTo([15, 15], %)
/// |> line(end = [10, -15])
/// |> close()
@ -2001,10 +1941,10 @@ async fn inner_tangential_arc_to(
/// ```no_run
/// exampleSketch = startSketchOn(XZ)
/// |> startProfileAt([0, 0], %)
/// |> angledLine({
/// |> angledLine(
/// angle = 45,
/// length = 10,
/// }, %)
/// )
/// |> tangentialArcToRelative([0, -10], %)
/// |> line(end = [-10, 0])
/// |> close()

View File

@ -105,20 +105,20 @@ pub async fn sweep(exec_state: &mut ExecState, args: Args) -> Result<KclValue, K
/// |> sweep(path = helixPath)
/// ```
///
/// ```
/// ```no_run
/// // Sweep two sketches along the same path.
///
/// sketch001 = startSketchOn(XY)
/// rectangleSketch = startProfileAt([-200, 23.86], sketch001)
/// |> angledLine([0, 73.47], %, $rectangleSegmentA001)
/// |> angledLine([
/// segAng(rectangleSegmentA001) - 90,
/// 50.61
/// ], %)
/// |> angledLine([
/// segAng(rectangleSegmentA001),
/// -segLen(rectangleSegmentA001)
/// ], %)
/// |> angledLine(angle = 0, length = 73.47, tag = $rectangleSegmentA001)
/// |> angledLine(
/// angle = segAng(rectangleSegmentA001) - 90,
/// length = 50.61,
/// )
/// |> angledLine(
/// angle = segAng(rectangleSegmentA001),
/// length = -segLen(rectangleSegmentA001),
/// )
/// |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
/// |> close()
///

View File

@ -113,15 +113,15 @@ pub async fn scale(exec_state: &mut ExecState, args: Args) -> Result<KclValue, K
///
/// sketch001 = startSketchOn('XY')
/// rectangleSketch = startProfileAt([-200, 23.86], sketch001)
/// |> angledLine([0, 73.47], %, $rectangleSegmentA001)
/// |> angledLine([
/// segAng(rectangleSegmentA001) - 90,
/// 50.61
/// ], %)
/// |> angledLine([
/// segAng(rectangleSegmentA001),
/// -segLen(rectangleSegmentA001)
/// ], %)
/// |> angledLine(angle = 0, length = 73.47, tag = $rectangleSegmentA001)
/// |> angledLine(
/// angle = segAng(rectangleSegmentA001) - 90,
/// length = 50.61,
/// )
/// |> angledLine(
/// angle = segAng(rectangleSegmentA001),
/// length = -segLen(rectangleSegmentA001),
/// )
/// |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
/// |> close()
///
@ -301,15 +301,15 @@ pub async fn translate(exec_state: &mut ExecState, args: Args) -> Result<KclValu
///
/// sketch001 = startSketchOn('XY')
/// rectangleSketch = startProfileAt([-200, 23.86], sketch001)
/// |> angledLine([0, 73.47], %, $rectangleSegmentA001)
/// |> angledLine([
/// segAng(rectangleSegmentA001) - 90,
/// 50.61
/// ], %)
/// |> angledLine([
/// segAng(rectangleSegmentA001),
/// -segLen(rectangleSegmentA001)
/// ], %)
/// |> angledLine(angle = 0, length = 73.47, tag = $rectangleSegmentA001)
/// |> angledLine(
/// angle = segAng(rectangleSegmentA001) - 90,
/// length = 50.61,
/// )
/// |> angledLine(
/// angle = segAng(rectangleSegmentA001),
/// length = -segLen(rectangleSegmentA001),
/// )
/// |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
/// |> close()
///
@ -699,15 +699,15 @@ pub async fn rotate(exec_state: &mut ExecState, args: Args) -> Result<KclValue,
///
/// sketch001 = startSketchOn('XY')
/// rectangleSketch = startProfileAt([-200, 23.86], sketch001)
/// |> angledLine([0, 73.47], %, $rectangleSegmentA001)
/// |> angledLine([
/// segAng(rectangleSegmentA001) - 90,
/// 50.61
/// ], %)
/// |> angledLine([
/// segAng(rectangleSegmentA001),
/// -segLen(rectangleSegmentA001)
/// ], %)
/// |> angledLine(angle = 0, length = 73.47, tag = $rectangleSegmentA001)
/// |> angledLine(
/// angle = segAng(rectangleSegmentA001) - 90,
/// length = 50.61,
/// )
/// |> angledLine(
/// angle = segAng(rectangleSegmentA001),
/// length = -segLen(rectangleSegmentA001),
/// )
/// |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
/// |> close()
///

View File

@ -1203,7 +1203,7 @@ fn o(c_x, c_y) {
angle_start = 45 + a,
angle_end = 225 - a
}, %)
|> angledLine([45, o_r - i_r], %)
|> angledLine(angle = 45, length = o_r - i_r)
|> arc({
radius = i_r,
angle_start = 225 - a,
@ -1219,7 +1219,7 @@ fn o(c_x, c_y) {
angle_start = 225 + a,
angle_end = 360 + 45 - a
}, %)
|> angledLine([225, o_r - i_r], %)
|> angledLine(angle = 225, length = o_r - i_r)
|> arc({
radius = i_r,
angle_start = 45 - a,
@ -2234,14 +2234,8 @@ myAng2 = 134
part001 = startSketchOn(XY)
|> startProfileAt([0, 0], %)
|> line([1, 3.82], %, $seg01) // ln-should-get-tag
|> angledLineToX([
-angleToMatchLengthX(seg01, myVar, %),
myVar
], %) // ln-lineTo-xAbsolute should use angleToMatchLengthX helper
|> angledLineToY([
-angleToMatchLengthY(seg01, myVar, %),
myVar
], %) // ln-lineTo-yAbsolute should use angleToMatchLengthY helper"#;
|> angledLine(angle = -angleToMatchLengthX(seg01, myVar, %), length = myVar) // ln-lineTo-xAbsolute should use angleToMatchLengthX helper
|> angledLine(angle = -angleToMatchLengthY(seg01, myVar, %), length = myVar) // ln-lineTo-yAbsolute should use angleToMatchLengthY helper"#;
let program = crate::parsing::top_level_parse(some_program_string).unwrap();
let recasted = program.recast(&Default::default(), 0);
@ -2258,14 +2252,8 @@ myAng2 = 134
part001 = startSketchOn(XY)
|> startProfileAt([0, 0], %)
|> line([1, 3.82], %, $seg01) // ln-should-get-tag
|> angledLineToX([
-angleToMatchLengthX(seg01, myVar, %),
myVar
], %) // ln-lineTo-xAbsolute should use angleToMatchLengthX helper
|> angledLineToY([
-angleToMatchLengthY(seg01, myVar, %),
myVar
], %) // ln-lineTo-yAbsolute should use angleToMatchLengthY helper
|> angledLine(angle = -angleToMatchLengthX(seg01, myVar, %), length = myVar) // ln-lineTo-xAbsolute should use angleToMatchLengthX helper
|> angledLine(angle = -angleToMatchLengthY(seg01, myVar, %), length = myVar) // ln-lineTo-yAbsolute should use angleToMatchLengthY helper
"#;
let program = crate::parsing::top_level_parse(some_program_string).unwrap();