Remove tangentialArc(to), add tangentialArcToRelative
This commit is contained in:
@ -81,6 +81,7 @@ lazy_static! {
|
||||
Box::new(crate::std::sketch::Arc),
|
||||
Box::new(crate::std::sketch::TangentialArc),
|
||||
Box::new(crate::std::sketch::TangentialArcTo),
|
||||
Box::new(crate::std::sketch::TangentialArcToRelative),
|
||||
Box::new(crate::std::sketch::BezierCurve),
|
||||
Box::new(crate::std::sketch::Hole),
|
||||
Box::new(crate::std::patterns::PatternLinear2D),
|
||||
|
@ -1634,8 +1634,6 @@ pub enum TangentialArcData {
|
||||
/// Offset of the arc, in degrees.
|
||||
offset: f64,
|
||||
},
|
||||
/// A point where the arc should end. Must lie in the same plane as the current path pen position. Must not be colinear with current path pen position.
|
||||
Point([f64; 2]),
|
||||
}
|
||||
|
||||
/// Draw a tangential arc.
|
||||
@ -1728,13 +1726,6 @@ async fn inner_tangential_arc(
|
||||
.await?;
|
||||
(center, to.into(), ccw)
|
||||
}
|
||||
TangentialArcData::Point(to) => {
|
||||
args.batch_modeling_cmd(id, tan_arc_to(&sketch_group, &to)).await?;
|
||||
// TODO: Figure out these calculations.
|
||||
let ccw = false;
|
||||
let center = Point2d { x: 0.0, y: 0.0 };
|
||||
(center, to, ccw)
|
||||
}
|
||||
};
|
||||
|
||||
let current_path = Path::TangentialArc {
|
||||
@ -1804,6 +1795,24 @@ pub async fn tangential_arc_to(args: Args) -> Result<KclValue, KclError> {
|
||||
Ok(KclValue::new_user_val(new_sketch_group.meta.clone(), new_sketch_group))
|
||||
}
|
||||
|
||||
/// Draw a tangential arc to a a specified distance.
|
||||
pub async fn tangential_arc_to_relative(args: Args) -> Result<KclValue, KclError> {
|
||||
let src = args.source_range;
|
||||
|
||||
// Get arguments to function call
|
||||
let mut it = args.args.iter();
|
||||
let to: [f64; 2] = get_arg(&mut it, src)?.get_json()?;
|
||||
let sketch_group: SketchGroup = get_arg(&mut it, src)?.get_json()?;
|
||||
let tag = if let Ok(memory_item) = get_arg(&mut it, src) {
|
||||
memory_item.get_json_opt()?
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let new_sketch_group = inner_tangential_arc_to_relative(to, sketch_group, tag, args).await?;
|
||||
Ok(KclValue::new_user_val(new_sketch_group.meta.clone(), new_sketch_group))
|
||||
}
|
||||
|
||||
/// Starting at the current sketch's origin, draw a curved line segment along
|
||||
/// some part of an imaginary circle until it reaches the desired (x, y)
|
||||
/// coordinates.
|
||||
@ -1837,6 +1846,61 @@ async fn inner_tangential_arc_to(
|
||||
} else {
|
||||
tangent_info.center_or_tangent_point
|
||||
};
|
||||
do_tan_arc_to(to, sketch_group, tag, args, tan_previous_point, from).await
|
||||
}
|
||||
|
||||
/// Starting at the current path pen location, draw a curved line segment along
|
||||
/// some part of an imaginary circle until it reaches the desired (current.x + x, current.y + y)
|
||||
/// coordinates.
|
||||
///
|
||||
/// ```no_run
|
||||
/// const exampleSketch = startSketchOn('XZ')
|
||||
/// |> startProfileAt([0, 0], %)
|
||||
/// |> angledLine({
|
||||
/// angle: 60,
|
||||
/// length: 10,
|
||||
/// }, %)
|
||||
/// |> tangentialArcToRelative([15, 15], %)
|
||||
/// |> line([10, -15], %)
|
||||
/// |> close(%)
|
||||
///
|
||||
/// const example = extrude(10, exampleSketch)
|
||||
/// ```
|
||||
#[stdlib {
|
||||
name = "tangentialArcToRelative",
|
||||
}]
|
||||
async fn inner_tangential_arc_to_relative(
|
||||
to: [f64; 2],
|
||||
sketch_group: SketchGroup,
|
||||
tag: Option<TagDeclarator>,
|
||||
args: Args,
|
||||
) -> Result<SketchGroup, KclError> {
|
||||
let from: Point2d = sketch_group.current_pen_position()?;
|
||||
let tangent_info = sketch_group.get_tangential_info_from_paths();
|
||||
let tan_previous_point = if tangent_info.is_center {
|
||||
get_tangent_point_from_previous_arc(tangent_info.center_or_tangent_point, tangent_info.ccw, from.into())
|
||||
} else {
|
||||
tangent_info.center_or_tangent_point
|
||||
};
|
||||
do_tan_arc_to(
|
||||
[to[0] + from.x, to[1] + from.y],
|
||||
sketch_group,
|
||||
tag,
|
||||
args,
|
||||
tan_previous_point,
|
||||
from,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn do_tan_arc_to(
|
||||
to: [f64; 2],
|
||||
sketch_group: SketchGroup,
|
||||
tag: Option<TagDeclarator>,
|
||||
args: Args,
|
||||
tan_previous_point: [f64; 2],
|
||||
from: Point2d,
|
||||
) -> Result<SketchGroup, KclError> {
|
||||
let [to_x, to_y] = to;
|
||||
let result = get_tangential_arc_to_info(TangentialArcInfoInput {
|
||||
arc_start_point: [from.x, from.y],
|
||||
|
@ -4,45 +4,50 @@ let length = 120.0
|
||||
let hand_thickness = 24.0
|
||||
let corner_radius = 5.0
|
||||
|
||||
fn tarc = (p, sg) => {
|
||||
let p2 = [p[0] * corner_radius, p[1] * corner_radius]
|
||||
return tangentialArcToRelative(p2, sg)
|
||||
}
|
||||
|
||||
// At first I thought this was going to be symmetric,
|
||||
// but I measured intentionally to not be symmetric,
|
||||
// because your wrist isn't a perfect cylindrical surface
|
||||
let brace_base = startSketchAt([corner_radius, 0])
|
||||
|> line([width - corner_radius, 0.0], %)
|
||||
|> tangentialArc([corner_radius, corner_radius], %)
|
||||
|> tarc([1, 1], %)
|
||||
|> yLine(25.0 - corner_radius, %)
|
||||
|> tangentialArc([-corner_radius, corner_radius], %)
|
||||
|> tarc([-1, 1], %)
|
||||
|> xLine(-(d_wrist_circumference[0] - (corner_radius * 2)), %)
|
||||
|> tangentialArc([-corner_radius, corner_radius], %)
|
||||
|> tarc([-1, 1], %)
|
||||
|> yLine(length - 25.0 - 23.0 - (corner_radius * 2), %)
|
||||
|> tangentialArc([corner_radius, corner_radius], %)
|
||||
|> tarc([1, 1], %)
|
||||
|> xLine(15.0 - (corner_radius * 2), %)
|
||||
|> tangentialArc([corner_radius, corner_radius], %)
|
||||
|> tarc([1, 1], %)
|
||||
|> yLine(23.0 - corner_radius, %)
|
||||
|> tangentialArc([-corner_radius, corner_radius], %)
|
||||
|> tarc([-1, 1], %)
|
||||
|> xLine(-(hand_thickness + 15.0 + 15.0 - (corner_radius * 2)), %)
|
||||
|> tangentialArc([-corner_radius, -corner_radius], %)
|
||||
|> tarc([-1, -1], %)
|
||||
|> yLine(-(23.0 - corner_radius), %)
|
||||
|> tangentialArc([corner_radius, -corner_radius], %)
|
||||
|> tarc([1, -1], %)
|
||||
|> xLine(15.0 - (corner_radius * 2), %)
|
||||
|> tangentialArc([corner_radius, -corner_radius], %)
|
||||
|> tarc([1, -1], %)
|
||||
|> yLine(-(length - 25.0 - 23.0 - (corner_radius * 2)), %)
|
||||
|> tangentialArc([-corner_radius, -corner_radius], %)
|
||||
|> tarc([-1, -1], %)
|
||||
|> xLine(-(d_wrist_circumference[1] + d_wrist_circumference[2] + d_wrist_circumference[3] - hand_thickness - corner_radius), %)
|
||||
|> tangentialArc([-corner_radius, -corner_radius], %)
|
||||
|> tarc([-1, -1], %)
|
||||
|> yLine(-(25.0 - corner_radius), %)
|
||||
|> tangentialArc([corner_radius, -corner_radius], %)
|
||||
|> tarc([1, -1], %)
|
||||
|> close(%)
|
||||
|
||||
let inner = startSketchAt([0, 0])
|
||||
|> xLine(1.0, %)
|
||||
|> tangentialArc([corner_radius, corner_radius], %)
|
||||
|> tarc([1, 1], %)
|
||||
|> yLine(25.0 - (corner_radius * 2), %)
|
||||
|> tangentialArc([-corner_radius, corner_radius], %)
|
||||
|> tarc([-1, 1], %)
|
||||
|> xLine(-1.0, %)
|
||||
|> tangentialArc([-corner_radius, -corner_radius], %)
|
||||
|> tarc([-1, -1], %)
|
||||
|> yLine(-(25.0 - (corner_radius * 2)), %)
|
||||
|> tangentialArc([corner_radius, -corner_radius], %)
|
||||
|> tarc([1, -1], %)
|
||||
|> close(%)
|
||||
|
||||
let final = brace_base
|
||||
|
@ -186,7 +186,7 @@ async fn kcl_test_negative_args() {
|
||||
async fn kcl_test_basic_tangential_arc_with_point() {
|
||||
let code = r#"const boxSketch = startSketchAt([0, 0])
|
||||
|> line([0, 10], %)
|
||||
|> tangentialArc([-5, 5], %)
|
||||
|> tangentialArcToRelative([-5, 5], %)
|
||||
|> line([5, -15], %)
|
||||
|> extrude(10, %)
|
||||
"#;
|
||||
@ -715,7 +715,7 @@ async fn kcl_test_error_sketch_on_arc_face() {
|
||||
let code = r#"fn cube = (pos, scale) => {
|
||||
const sg = startSketchOn('XY')
|
||||
|> startProfileAt(pos, %)
|
||||
|> tangentialArc([0, scale], %, $here)
|
||||
|> tangentialArcToRelative([0, scale], %, $here)
|
||||
|> line([scale, 0], %)
|
||||
|> line([0, -scale], %)
|
||||
|
||||
|
Reference in New Issue
Block a user