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

KCL: Patterns of patterns can use the original sketch/solid as target #5284

Merged
merged 5 commits into from
Feb 6, 2025

Conversation

adamchalmers
Copy link
Collaborator

@adamchalmers adamchalmers commented Feb 6, 2025

Right now, if you model something like this box with a button:

Screenshot 2025-02-06 at 3 08 03 PM

Let's say you want to pattern the button, and repeat it a second time. If you try, you'll actually pattern the entire model (box + button).

Screenshot 2025-02-06 at 3 08 52 PM

Why? Because right now, when you sketch on a face (like the button was), both the box and the button share the same ID. All extrusions from a solid will share the same ID, because they all refer to the same composite solid.

This is helpful in some ways -- arguably the solid is just one big complex shape now -- but it's not helpful in other ways. What if I want to only pattern the button? Luckily there's an original ID for the button part, which is still stored. So we just need a way to tell the pattern stdlib functions whether to use the target's main ID or its original ID. This PR adds a new optional bool, useOriginal, to patterns. It's false by default, to keep backwards-compatibility (make sure that old KCL code doesn't change).

This PR is based on #3914. It's based on work Serena and I are doing to fix a bug (engine does not allow patterning a 3D solid which was sketched on a face of another solid). @gserena01 our test program is now:

w = 400

case = startSketchOn('XY')
  |> startProfileAt([-w, -w], %)
  |> line(endAbsolute = [-w, w])
  |> line(endAbsolute = [w, -w])
  |> line(endAbsolute = [-w, -w])
  |> close()
  |> extrude(length = 200)

bump1 = startSketchOn(case, 'end')
  |> circle({ center = [-50, -50], radius = 40 }, %)
  |> extrude(length = 20)

// We pass in "bump1" here since we want to pattern just this object on the face.
useOriginal = true
target = bump1
transform = {
  axis = [1, 0, 0],
  instances = 3,
  distance = -100
}
patternLinear3d(transform, target, useOriginal)

If you change the useOriginal = true to false you can see the difference.

Copy link

qa-wolf bot commented Feb 6, 2025

QA Wolf here! As you write new code it's important that your test coverage is keeping up.
Click here to request test coverage for this PR!

Copy link

vercel bot commented Feb 6, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
modeling-app ✅ Ready (Inspect) Visit Preview Feb 6, 2025 5:13pm

@adamchalmers adamchalmers force-pushed the achalmers/original-id-pattern branch from 776c87b to 43a3465 Compare February 6, 2025 14:36
@adamchalmers adamchalmers force-pushed the achalmers/original-id-pattern branch from 43a3465 to 445e5fb Compare February 6, 2025 14:36
@adamchalmers adamchalmers marked this pull request as ready for review February 6, 2025 14:54
@adamchalmers adamchalmers requested a review from jessfraz February 6, 2025 14:54
Copy link

codecov bot commented Feb 6, 2025

Codecov Report

Attention: Patch coverage is 80.32787% with 12 lines in your changes missing coverage. Please review.

Project coverage is 86.04%. Comparing base (11cac0c) to head (9e243c4).
Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
src/wasm-lib/kcl/src/std/patterns.rs 86.00% 7 Missing ⚠️
src/wasm-lib/kcl/src/execution/geometry.rs 0.00% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5284      +/-   ##
==========================================
- Coverage   86.05%   86.04%   -0.02%     
==========================================
  Files          92       92              
  Lines       33204    33251      +47     
==========================================
+ Hits        28575    28610      +35     
- Misses       4629     4641      +12     
Flag Coverage Δ
wasm-lib 86.04% <80.32%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@KittyCAD KittyCAD deleted a comment from jtran Feb 6, 2025
@adamchalmers adamchalmers requested a review from jtran February 6, 2025 22:33
Copy link
Collaborator

@jtran jtran left a comment

Choose a reason for hiding this comment

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

If I were reading code that uses useOriginal, I think I'd always need to look up the docs. I was trying to think of another name that might make it clearer what the option does. useSketch? Not sure. I can't think of something better.

Comment on lines 429 to +433
/// The original id of the sketch. This stays the same even if the sketch is
/// is sketched on face etc.
pub artifact_id: ArtifactId,
#[ts(skip)]
pub original_id: uuid::Uuid,
Copy link
Collaborator

Choose a reason for hiding this comment

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

These two fields are technically a duplicate of each other. That's why I renamed it in #5205. I guess it's fine, though, because they're semantically representing two different things.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hmm. Yeah I'm OK leaving it because one might change in the future, but we could also come back and remove it. Whatever you'd prefer.

@adamchalmers adamchalmers merged commit 6ac9c49 into main Feb 6, 2025
31 of 33 checks passed
@adamchalmers adamchalmers deleted the achalmers/original-id-pattern branch February 6, 2025 23:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants