-
Notifications
You must be signed in to change notification settings - Fork 142
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
Round join and all cap styles #414
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d29a503
[flatten] Simplify Cubic representation
armansito bac1799
[flatten] Implement round join style
armansito ab9dd6a
[flatten] Support cap styles
armansito bae1d1a
[flatten] Fix infinite arc subdivision case
armansito 6e6d02a
Add additional documentation around `flatten_arc`
armansito File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not obvious from this comment how the direction is chosen. It must be based on the value of
angle
, but it feels like 'pacman' style arcs will be difficult.I worry that if n_lines is big, the arc would draw the full way around, but if n_lines is small, it would end up drawing the closing part, rather than the full way around
I'm not sure that this is coherent - my last maths education was many years ago.
Maybe this would only be an issue if n_lines is 1, which is impossible?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The direction of the arc is always a counter-clockwise rotation starting from
begin
, towardsend
, centered atcenter
, and will be subtended byangle
(which is assumed to be positive). Ifangle
terminates the arc before it smoothly reachesend
, a line will be drawn from the end of the arc towardsend
. I will document this.n_lines
only depends on the radius of the arc and the chosen tolerance. Forn_lines
to betheta
must be close toacos
can't return that by definition. If you somehow gotn_lines == 1
, basically no arc would be drawn and you'd get a line connectingbegin
andend
.Realistically,$2$ if the absolute value of
n_lines
could be as low asx
is very small, which can happen iftol
andradius
are close to each other (the code preventsradius
from being smaller thantol
, so that case isn't possible). You'd only get into that situation with a sub-pixel radius. At that scale, the coarseness of the approximation won't be easily noticeable. If you increased the tolerance to make this possible at larger radii, withn_lines == 2
you'd get a shape resembling a wedge/triangle (I tested this locally, which works as you'd expect).That said, this function is meant for drawing caps and joins where$\le\pi$ and the
angle
begin
,center
, andend
points are chosen carefully (so that the angle and winding make sense).Though there is something that should get fixed: I think selecting
1u
whentheta <= EPS
is the wrong thing to do and this is a bug. That happens when the subdivision count tends to infinity. It's probably better to define aMAX_LINES
and return that instead.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To illustrate what I mean, here is what the code draws if I center the center of a round join directly below the join control point and hardcode an angle of$343.77\degree$ :
n_lines == 1
:n_lines == 2
:n_lines == 3
:n_lines == 6
:n_lines == 100
:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the very detailed reply!
I hadn't clocked the additional invariants being maintained by the callers
Those pictures are very cool as well!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm glad they were helpful 🙂. I updated the comment above
flatten_arc
in latest commit.