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

angle results are hard to predict and control #712

Closed
knuesel opened this issue Oct 8, 2024 · 3 comments · Fixed by #729
Closed

angle results are hard to predict and control #712

knuesel opened this issue Oct 8, 2024 · 3 comments · Fixed by #729
Assignees
Labels
bug 🐛 Something isn't working
Milestone

Comments

@knuesel
Copy link

knuesel commented Oct 8, 2024

The angle API is a bit tricky to use in programmatic drawing, where the angle value is not known statically. One must play with inner and mark to get the right result depending on the angle value. For example I often need figures for different trigonometric angles:

#let trig-angle(alpha) = cetz.canvas(length: 2cm, {
  import cetz.draw: *

  let O = (0, 0)
  let P = (1, 0)
  let Q = (alpha, 1)

  line(O, P, mark: (end: ">"))
  line(O, Q, mark: (end: ">"))
  cetz.angle.angle(O, P, Q, mark: (end: ">"), label: [#alpha], label-radius: 150%)
  rect((-1, 0), (1, 0), stroke: none) // for bounding box
})

#for alpha in (60deg, 240deg, -60deg, -240deg) {
  box(trig-angle(alpha))
}

image

The first drawing (60deg) is what I expected, but the others all require different fixes:

  • For 240deg I need inner: false
  • For -60deg I must replace end: ">" with start: ">"
  • For -240deg I need both of the above

(Here I could implement the four cases with conditional logic, but in general the angle can be specified by all sorts of coordinates with no explicit angle value.)

What would you think of the following changes to the API:

  • make angle(O, A, B) always draw from OA to OB (this makes the effect of mark start and end more predictable)

  • allow inner: auto, in which case the angle is drawn counterclockwise for positive values, and clockwise for negative values (I think this should be the default, but having this opt-in would be fine)

@johannes-wolf johannes-wolf added the bug 🐛 Something isn't working label Oct 8, 2024
@johannes-wolf johannes-wolf self-assigned this Oct 8, 2024
@johannes-wolf johannes-wolf added this to the 0.3.1 milestone Oct 9, 2024
@johannes-wolf
Copy link
Member

johannes-wolf commented Oct 19, 2024

I've created a PR #729. Could you please validate that it fulfils your expectations. I did not implement the auto behaviour, as it is not clear to me, when the angle would be negative. Do you mean if it is > 180deg?

@johannes-wolf johannes-wolf modified the milestones: 0.3.1, 0.3.2 Oct 19, 2024
@knuesel
Copy link
Author

knuesel commented Oct 22, 2024

Thanks! I'm going to comment on that PR then.

@knuesel
Copy link
Author

knuesel commented Oct 22, 2024

(By negative angle I meant clockwise, but then indeed the whole sentence doesn't make sense, sorry! But I'll elaborate in the PR comments)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants