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 new join methods for when polyline angles are too sharp. #168

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Kevinpgalligan
Copy link
Contributor

@Kevinpgalligan Kevinpgalligan commented Apr 16, 2024

Attempting to fix the polyline bug, see: #53

Visual artifacts were appearing for polylines with sharp corners. This is a known problem when using the miter method of joining 2 lines. The join points are calculated by extending the left and right sides of the lines until they intersect. If there's a small angle between the lines, however, the intersection points go to infinity and beyond (they're almost parallel), creating visual artifacts.

The solution implemented here is to switch to a different join method when there's a small angle between the lines. I arbitrarily chose a cutoff of 20 degrees to switch from meter join to bevel join. I find that the transition from miter to bevel is too jarring if the cutoff angle is smaller than that, but I'm open to changing it. I also added a cutoff of 2 degrees to switch from the bevel method to a "simple" join, because bevel also gets buggy when the lines are parallel-ish.

In the future, we could make the cutoff angles configurable. It would also be possible to allow the user the choose the join they want, and add more joins like rounded.

Will share some of the experimenting I've done to confirm the fix.

@Kevinpgalligan
Copy link
Contributor Author

Kevinpgalligan commented Apr 16, 2024

Testing.

(defsketch polytest
            ((width 520)
             (height 110))
          (with-pen (make-pen :stroke +white+ :weight 2)
            (loop for i from 0
                  for gap in '(0 5 10 25 50)
                  do (polyline (+ 10 (* i 100)) 10
                               (+ 10 (* i 100) (/ gap 2)) 100
                               (+ 10 (* i 100) gap) 10))))

Miter join is used on the right, bevel is used to the left of that, and the "simple" join is used (at least) on the far left.

polyline-debug

Here's what it was like before. Note that for small enough angles, the line width isn't consistent and the edge is so pointy that it goes off the screen.

old-polyline-debug

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.

None yet

1 participant