Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'relative: bool' to tanArcTo, remove 'to' mode from tanArc #3705

Closed
wants to merge 12 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion docs/kcl/std.json
Original file line number Diff line number Diff line change
Expand Up @@ -223895,6 +223895,14 @@
},
"required": true
},
{
"name": "relative",
"type": "bool",
"schema": {
"type": "boolean"
},
"required": true
},
{
"name": "sketch_group",
"type": "SketchGroup",
Expand Down Expand Up @@ -230575,7 +230583,7 @@
"unpublished": false,
"deprecated": false,
"examples": [
"const exampleSketch = startSketchOn('XZ')\n |> startProfileAt([0, 0], %)\n |> angledLine({ angle: 60, length: 10 }, %)\n |> tangentialArcTo([15, 15], %)\n |> line([10, -15], %)\n |> close(%)\n\nconst example = extrude(10, exampleSketch)"
"const exampleSketch = startSketchOn('XZ')\n |> startProfileAt([0, 0], %)\n |> angledLine({ angle: 60, length: 10 }, %)\n |> tangentialArcTo([15, 15], false, %)\n |> line([10, -15], %)\n |> close(%)\n\nconst example = extrude(10, exampleSketch)"
]
},
{
Expand Down
5 changes: 3 additions & 2 deletions docs/kcl/tangentialArcTo.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ 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.

```js
tangentialArcTo(to: [number], sketch_group: SketchGroup, tag?: TagDeclarator) -> SketchGroup
tangentialArcTo(to: [number], relative: bool, sketch_group: SketchGroup, tag?: TagDeclarator) -> SketchGroup
```

### Examples
Expand All @@ -18,7 +18,7 @@ tangentialArcTo(to: [number], sketch_group: SketchGroup, tag?: TagDeclarator) ->
const exampleSketch = startSketchOn('XZ')
|> startProfileAt([0, 0], %)
|> angledLine({ angle: 60, length: 10 }, %)
|> tangentialArcTo([15, 15], %)
|> tangentialArcTo([15, 15], false, %)
|> line([10, -15], %)
|> close(%)

Expand All @@ -30,6 +30,7 @@ const example = extrude(10, exampleSketch)
### Arguments

* `to`: `[number]` (REQUIRED)
* `relative`: `bool` (REQUIRED)
* `sketch_group`: `SketchGroup` - A sketch group is a collection of paths. (REQUIRED)
```js
{
Expand Down
4 changes: 2 additions & 2 deletions e2e/playwright/snapshot-tests.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ test.describe(
await page.mouse.click(startXPx + PUR * 30, 500 - PUR * 20)

code += `
|> tangentialArcTo([21.7, -2.44], %)`
|> tangentialArcTo([21.7, -2.44], false, %)`
await expect(u.codeLocator).toHaveText(code)

// click tangential arc tool again to unequip it
Expand Down Expand Up @@ -697,7 +697,7 @@ test.describe(
await page.mouse.click(startXPx + PUR * 30, 500 - PUR * 20)

code += `
|> tangentialArcTo([551.2, -62.01], %)`
|> tangentialArcTo([551.2, -62.01], false, %)`
await expect(u.codeLocator).toHaveText(code)

await page
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion e2e/playwright/storageStates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export const TEST_CODE_GIZMO = `const part001 = startSketchOn('XZ')
intersectTag: a,
offset: 0
}, %)
|> tangentialArcTo([13.14 + 0, 13.14], %)
|> tangentialArcTo([13.14 + 0, 13.14], false, %)
|> close(%)
|> extrude(5 + 7, %)
`
Expand Down
27 changes: 15 additions & 12 deletions e2e/playwright/testing-segment-overlays.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ test.describe('Testing segment overlays', () => {
intersectTag: a,
offset: 9
}, %)
|> tangentialArcTo([5 + 3.14 + 13, 20 + 3.14], %)
|> tangentialArcTo([5 + 3.14 + 13, 20 + 3.14], false, %)
`
)
})
Expand Down Expand Up @@ -438,7 +438,7 @@ const part001 = startSketchOn('XZ')
intersectTag: a,
offset: 9
}, %)
|> tangentialArcTo([3.14 + 13, 3.14], %)
|> tangentialArcTo([3.14 + 13, 3.14], false, %)
`
)
localStorage.setItem('disableAxis', 'true')
Expand Down Expand Up @@ -566,7 +566,7 @@ const part001 = startSketchOn('XZ')
intersectTag: a,
offset: 9
}, %)
|> tangentialArcTo([3.14 + 13, 1.14], %)
|> tangentialArcTo([3.14 + 13, 1.14], false, %)
`
)
localStorage.setItem('disableAxis', 'true')
Expand Down Expand Up @@ -722,7 +722,7 @@ const part001 = startSketchOn('XZ')
intersectTag: a,
offset: 9
}, %)
|> tangentialArcTo([3.14 + 13, -3.14], %)
|> tangentialArcTo([3.14 + 13, -3.14], false, %)
`
)
localStorage.setItem('disableAxis', 'true')
Expand Down Expand Up @@ -755,9 +755,10 @@ const part001 = startSketchOn('XZ')
await clickConstrained({
hoverPos: { x: tangentialArcTo.x, y: tangentialArcTo.y },
constraintType: 'xAbsolute',
expectBeforeUnconstrained: 'tangentialArcTo([3.14 + 13, -3.14], %)',
expectAfterUnconstrained: 'tangentialArcTo([16.14, -3.14], %)',
expectFinal: 'tangentialArcTo([xAbs001, -3.14], %)',
expectBeforeUnconstrained:
'tangentialArcTo([3.14 + 13, -3.14], false, %)',
expectAfterUnconstrained: 'tangentialArcTo([16.14, -3.14], false, %)',
expectFinal: 'tangentialArcTo([xAbs001, -3.14], false, %)',
ang: ang + 180,
steps: 6,
locator: '[data-overlay-toolbar-index="12"]',
Expand All @@ -766,9 +767,11 @@ const part001 = startSketchOn('XZ')
await clickUnconstrained({
hoverPos: { x: tangentialArcTo.x, y: tangentialArcTo.y },
constraintType: 'yAbsolute',
expectBeforeUnconstrained: 'tangentialArcTo([xAbs001, -3.14], %)',
expectAfterUnconstrained: 'tangentialArcTo([xAbs001, yAbs001], %)',
expectFinal: 'tangentialArcTo([xAbs001, -3.14], %)',
expectBeforeUnconstrained:
'tangentialArcTo([xAbs001, -3.14], false, %)',
expectAfterUnconstrained:
'tangentialArcTo([xAbs001, yAbs001], false, %)',
expectFinal: 'tangentialArcTo([xAbs001, -3.14], false, %)',
ang: ang + 180,
steps: 10,
locator: '[data-overlay-toolbar-index="12"]',
Expand Down Expand Up @@ -835,7 +838,7 @@ const part001 = startSketchOn('XZ')
intersectTag: a,
offset: 9
}, %)
|> tangentialArcTo([3.14 + 13, 1.14], %)
|> tangentialArcTo([3.14 + 13, 1.14], false, %)
`
)
localStorage.setItem('disableAxis', 'true')
Expand Down Expand Up @@ -866,7 +869,7 @@ const part001 = startSketchOn('XZ')
let ang = await u.getAngle(`[data-overlay-index="${12}"]`)
await deleteSegmentSequence({
hoverPos: { x: segmentToDelete.x, y: segmentToDelete.y },
codeToBeDeleted: 'tangentialArcTo([3.14 + 13, 1.14], %)',
codeToBeDeleted: 'tangentialArcTo([3.14 + 13, 1.14], false, %)',
stdLibFnName: 'tangentialArcTo',
ang: ang + 180,
steps: 6,
Expand Down
4 changes: 2 additions & 2 deletions e2e/playwright/testing-selections.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ const sketch002 = startSketchOn(launderExtrudeThroughVar, seg02)
intersectTag: a,
offset: 0
}, %)
|> tangentialArcTo([13.14 + 0, 13.14], %)
|> tangentialArcTo([13.14 + 0, 13.14], false, %)
|> close(%)
|> extrude(5 + 7, %)
`
Expand Down Expand Up @@ -683,7 +683,7 @@ const extrude001 = extrude(10, sketch001)`
},
{
pos: [1107, 161],
expectedCode: 'tangentialArcTo([167.95, -28.85], %)',
expectedCode: 'tangentialArcTo([167.95, -28.85], false, %)',
},
] as const
await page.addInitScript(
Expand Down
4 changes: 2 additions & 2 deletions src/lang/modifyAst.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@
intersectTag: a,
offset: 0 + 0
}, %)
|> tangentialArcTo([3.14 + 0, 13.14 + 0], %)`
|> tangentialArcTo([3.14 + 0, 13.14 + 0], false, %)`
test.each([
[' line([3 + 0, 4], %)', 'arrayIndex', 1],
[
Expand Down Expand Up @@ -626,7 +626,7 @@
'objectProperty',
'offset',
],
['tangentialArcTo([3.14 + 0, 13.14], %)', 'arrayIndex', 1],
['tangentialArcTo([3.14 + 0, 13.14], false, %)', 'arrayIndex', 1],
])('stdlib fn: %s', async (expectedFinish, key, value) => {
const ast = parse(code)
if (err(ast)) throw ast
Expand All @@ -648,7 +648,7 @@
)
if (!mod) return new Error('mod is undefined')
const recastCode = recast(mod.modifiedAst)
expect(recastCode).toContain(expectedFinish)

Check failure on line 651 in src/lang/modifyAst.test.ts

View workflow job for this annotation

GitHub Actions / build-test-web

src/lang/modifyAst.test.ts > Testing removeSingleConstraintInfo > with mostly object notation > stdlib fn: tangentialArcTo([3.14 + 0, 13.14], false, %)

AssertionError: expected 'const part001 = startSketchOn(\'-XZ\'…' to contain 'tangentialArcTo([3.14 + 0, 13.14], fa…' - Expected + Received - tangentialArcTo([3.14 + 0, 13.14], false, %) + const part001 = startSketchOn('-XZ') + |> startProfileAt([0, 0], %) + |> line([3 + 0, 4 + 0], %) + |> angledLine({ angle: 3 + 0, length: 3.14 + 0 }, %) + |> lineTo([6.14 + 0, 3.14 + 0], %) + |> xLineTo(8 + 0, %) + |> yLineTo(5 + 0, %) + |> yLine(3.14 + 0, %, $a) + |> xLine(3.14 + 0, %) + |> angledLineOfXLength({ angle: 3 + 0, length: 3.14 + 0 }, %) + |> angledLineOfYLength({ angle: 30 + 0, length: 3 + 0 }, %) + |> angledLineToX({ angle: 12.14 + 0, to: 12 + 0 }, %) + |> angledLineToY({ angle: 30 + 0, to: 10.14 + 0 }, %) + |> angledLineThatIntersects({ + angle: 3.14 + 0, + intersectTag: a, + offset: 0 + 0 + }, %) + |> tangentialArcTo([3.14 + 0, 13.14], %, %) + ❯ src/lang/modifyAst.test.ts:651:26
})
})
describe('with array notation', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/lang/modifyAst.ts
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ export function splitPathAtPipeExpression(pathToNode: PathToNode): {
return splitPathAtPipeExpression(pathToNode.slice(0, -1))
}

export function createLiteral(value: string | number): Literal {
export function createLiteral(value: string | number | boolean): Literal {
return {
type: 'Literal',
start: 0,
Expand Down
6 changes: 3 additions & 3 deletions src/lang/std/sketch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ describe('testing getConstraintInfo', () => {
intersectTag: 'a',
offset: 0
}, %)
|> tangentialArcTo([3.14, 13.14], %)`
|> tangentialArcTo([3.14, 13.14], false, %)`
const ast = parse(code)
test.each([
[
Expand Down Expand Up @@ -629,7 +629,7 @@ describe('testing getConstraintInfo', () => {
intersectTag: 'a',
offset: 0
}, %)
|> tangentialArcTo([3.14, 13.14], %)`
|> tangentialArcTo([3.14, 13.14], false, %)`
const ast = parse(code)
test.each([
[
Expand Down Expand Up @@ -783,7 +783,7 @@ describe('testing getConstraintInfo', () => {
intersectTag: 'a',
offset: 0 + 0
}, %)
|> tangentialArcTo([3.14 + 0, 13.14 + 0], %)`
|> tangentialArcTo([3.14 + 0, 13.14 + 0], false, %)`
const ast = parse(code)
test.each([
[
Expand Down
9 changes: 5 additions & 4 deletions src/lang/std/sketch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ function singleRawValueHelper(
]
}

function getTag(index = 2): SketchLineHelper['getTag'] {
function getTag(index = 3): SketchLineHelper['getTag'] {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry if I wasn't clear. I think we want to revert this change because it applies to all AST functions, not just tanArcTo.

Suggested change
function getTag(index = 3): SketchLineHelper['getTag'] {
function getTag(index = 2): SketchLineHelper['getTag'] {

return (callExp: CallExpression) => {
if (callExp.type !== 'CallExpression')
return new Error('Not a CallExpression')
Expand Down Expand Up @@ -812,6 +812,7 @@ export const tangentialArcTo: SketchLineHelper = {
}
const newLine = createCallExpression('tangentialArcTo', [
createArrayExpression([toX, toY]),
createLiteral(false),
createPipeSubstitution(),
])
if (pipe.type === 'PipeExpression') {
Expand Down Expand Up @@ -849,8 +850,8 @@ export const tangentialArcTo: SketchLineHelper = {
pathToNode,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Above and below here are AST mod stuff specific to tangentialArcTo, so I suspect we need to change more stuff in this block.

}
},
getTag: getTag(),
addTag: addTag(),
getTag: getTag(3),
addTag: addTag(3),
getConstraintInfo: (callExp: CallExpression, code, pathToNode) => {
if (callExp.type !== 'CallExpression') return []
const firstArg = callExp.arguments?.[0]
Expand Down Expand Up @@ -1860,7 +1861,7 @@ function isAngleLiteral(lineArugement: Expr): boolean {

type addTagFn = (a: AddTagInfo) => { modifiedAst: Program; tag: string } | Error

function addTag(tagIndex = 2): addTagFn {
function addTag(tagIndex = 3): addTagFn {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert here also.

Suggested change
function addTag(tagIndex = 3): addTagFn {
function addTag(tagIndex = 2): addTagFn {

return ({ node, pathToNode }) => {
const _node = { ...node }
const callExpr = getNodeFromPath<CallExpression>(
Expand Down
4 changes: 4 additions & 0 deletions src/wasm-lib/kcl/src/std/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,9 @@ where
{
fn from_args(args: &'a Args, i: usize) -> Result<Self, KclError> {
let Some(arg) = args.args.get(i) else { return Ok(None) };
if crate::ast::types::KclNone::from_mem_item(arg).is_some() {
return Ok(None);
}
let Some(val) = T::from_mem_item(arg) else {
return Err(KclError::Semantic(KclErrorDetails {
message: format!(
Expand Down Expand Up @@ -620,6 +623,7 @@ impl_from_arg_via_json!(crate::std::polar::PolarCoordsData);
impl_from_arg_via_json!(SketchGroup);
impl_from_arg_via_json!(FaceTag);
impl_from_arg_via_json!(String);
impl_from_arg_via_json!(crate::ast::types::KclNone);
impl_from_arg_via_json!(u32);
impl_from_arg_via_json!(u64);
impl_from_arg_via_json!(f64);
Expand Down
43 changes: 16 additions & 27 deletions src/wasm-lib/kcl/src/std/sketch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::{
errors::{KclError, KclErrorDetails},
executor::{
BasePath, ExtrudeGroup, Face, GeoMeta, KclValue, Path, Plane, PlaneType, Point2d, Point3d, SketchGroup,
SketchGroupSet, SketchSurface, SourceRange, TagEngineInfo, TagIdentifier, UserVal,
SketchGroupSet, SketchSurface, TagEngineInfo, TagIdentifier, UserVal,
},
std::{
utils::{
Expand Down Expand Up @@ -1775,32 +1775,12 @@ fn tan_arc_to(sketch_group: &SketchGroup, to: &[f64; 2]) -> ModelingCmd {
}
}

fn too_few_args(source_range: SourceRange) -> KclError {
KclError::Syntax(KclErrorDetails {
source_ranges: vec![source_range],
message: "too few arguments".to_owned(),
})
}

fn get_arg<I: Iterator>(it: &mut I, src: SourceRange) -> Result<I::Item, KclError> {
it.next().ok_or_else(|| too_few_args(src))
}

/// Draw a tangential arc to a specific point.
pub async fn tangential_arc_to(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 (to, relative, sketch_group, tag): ([f64; 2], bool, SketchGroup, Option<TagDeclarator>) =
super::args::FromArgs::from_args(&args, 0)?;

let new_sketch_group = inner_tangential_arc_to(to, sketch_group, tag, args).await?;
let new_sketch_group = inner_tangential_arc_to(to, relative, sketch_group, tag, args).await?;
Ok(KclValue::new_user_val(new_sketch_group.meta.clone(), new_sketch_group))
}

Expand All @@ -1815,7 +1795,7 @@ pub async fn tangential_arc_to(args: Args) -> Result<KclValue, KclError> {
/// angle: 60,
/// length: 10,
/// }, %)
/// |> tangentialArcTo([15, 15], %)
/// |> tangentialArcTo([15, 15], false, %)
/// |> line([10, -15], %)
/// |> close(%)
///
Expand All @@ -1826,6 +1806,7 @@ pub async fn tangential_arc_to(args: Args) -> Result<KclValue, KclError> {
}]
async fn inner_tangential_arc_to(
to: [f64; 2],
relative: bool,
sketch_group: SketchGroup,
tag: Option<TagDeclarator>,
args: Args,
Expand All @@ -1840,12 +1821,20 @@ async fn inner_tangential_arc_to(
let [to_x, to_y] = to;
let result = get_tangential_arc_to_info(TangentialArcInfoInput {
arc_start_point: [from.x, from.y],
arc_end_point: to,
arc_end_point: if relative {
[to_x + from.x, to_y + from.y]
} else {
[to_x, to_y]
},
tan_previous_point,
obtuse: true,
});

let delta = [to_x - from.x, to_y - from.y];
let delta = if relative {
[to_x, to_y]
} else {
[to_x - from.x, to_y - from.y]
};
let id = uuid::Uuid::new_v4();
args.batch_modeling_cmd(id, tan_arc_to(&sketch_group, &delta)).await?;

Expand Down
1 change: 1 addition & 0 deletions src/wasm-lib/kcl/src/std/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,7 @@ pub struct TangentialArcInfoInput {
}

/// Structure to hold the output data from calculating tangential arc information.
#[derive(Debug)]
pub struct TangentialArcInfoOutput {
/// The center point of the arc.
pub center: Coords2d,
Expand Down
Loading
Loading