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 rectangle from corner tool #1500

Closed
Tracked by #1548
franknoirot opened this issue Feb 23, 2024 · 5 comments · Fixed by #2005
Closed
Tracked by #1548

Add rectangle from corner tool #1500

franknoirot opened this issue Feb 23, 2024 · 5 comments · Fixed by #2005
Labels
enhancement New feature or request sketch

Comments

@franknoirot
Copy link
Collaborator

franknoirot commented Feb 23, 2024

Add a sketch tool that generates a rectangle for the user.

User flow

  1. In sketch mode, click the Rectangle tool
  2. Click anywhere on the sketch plane to lay your first corner
  3. Move the mouse around to find the place for the second corner
  4. During this, a rectangle made of dashed lines will span between your first point and the mouse's position
  5. Click to finish the rectangle

Code generation

I might be thinking about this wrong @Irev-Dev but I think we should still have these be line segments being generated, so that each of their edges are individually taggable. I would also recommend we stay away from using horizontal or vertical line definitions, as it would make the rectangle impossible to rotate or tweak later. I think the code generated should be a rectangle defined relative to itself:

const rect001_start_angle = 0
const rect001_width = 13
const rect001_height = 4
const rect001 = startProfileAt([1, 3], sketch001)
  |> angledLine({
       angle: rect001_start_angle,
       length: rect001_width,
       tag: 'a'
     }, %)
  |> angledLine({
       angle: rect001_start_angle + 90,
       length: -rect001_height,
       tag: 'b'
     }, %)
  |> angledLine({
       angle: rect001_start_angle,
       length: -rect001_width,
       tag: 'c'
     }, %)
  |> close(%)

Additional resources

An icon has been made and is available in Figma here.

@franknoirot
Copy link
Collaborator Author

I should note that I'm also totally cool if a rectangle function gets added to stdlib and we just generate that. I'm not sure how we're planning on maintaining that "taggability" rule when calling stdlib functions though.

@franknoirot franknoirot added the enhancement New feature or request label Feb 23, 2024
@Irev-Dev
Copy link
Collaborator

Irev-Dev commented Feb 27, 2024

I like the individual segments approach. However I think that the use of variables is not great, if we can follow the same pattern of other segments that is not constraining completely when its added (unless we're talking snapping logic)

I think better code is

  |> startProfileAt([1, 3], %)
  |> angledLine({ angle: 45, length: 13, tag: 'a' }, %)
  |> angledLine({
       angle: segAng('a', %) - 90,
       length: 4,
       tag: 'b'
     }, %)
  |> angledLine({
       angle: segAng('a', %),
       length: -segLen('a', %),
       tag: 'c'
     }, %)
  |> close(%)

Because it its still constrained as a rectangle, but not its editable dimensions, (angle, length height)

Screenshare.-.2024-02-27.8_40_38.PM.mp4

Though I think we need to get those constraint symbols in hey, because why the the segments are not editable isn't clear

  |> angledLine({
       angle: segAng('a', %),
       length: -segLen('a', %),
       tag: 'c'
     }, %)

Is fully constrained so that can't be edited.

@franknoirot
Copy link
Collaborator Author

Sick I didn't know about the segLen function that's excellent.

Yeah you're right we need those soon. I'll make an issue: I have a few details I want to discuss before we implement them.

This was referenced Feb 28, 2024
@franknoirot
Copy link
Collaborator Author

I've got a little baby branch started @Irev-Dev just with the icon, toolbar, and rough state machine setup.

I'm not quite sure how to tweak things such that we can setupScene but have 4 draft lines be generated/updated on mouseMove, right now this assumes only the last line is a draft line.

@franknoirot
Copy link
Collaborator Author

@Irev-Dev had a good idea for how to tweak setupSketch: have it take an already-added-to AST instead of having it do that transformation internally. That way the various sketch tools like Line can add their relevant code mods before calling it, and just tell setupSketch which segments will need to be draft lines (we didn't pin down exactly how to amend that).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request sketch
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants