Closed Kevinpgalligan closed 6 months ago
This doesn't work for non-convex polygons:
(defpackage #:sketch-user
(:use #:cl #:sketch))
(in-package #:sketch-user)
(defparameter *points* (list 3 3
5 5
7 3
5 9))
(defsketch foo ((resizable t))
(with-fit (10 10 width height)
(with-pen (make-pen :fill +white+ :stroke +red+ :weight 0.1)
(apply #'polygon *points*))
(with-pen (make-pen :stroke +black+)
(mapcar (lambda (xy) (apply #'point xy)) (sketch::group *points* 2)))))
(make-instance 'foo)
Before this change:
After this change:
Ooh, nice catch. I think I accidentally made all of my test cases convex. I guess this would require testing for convexity and ordering the points accordingly.
It also has a problem with self-intersecting quads:
vs
Oh ya, I added a mention of that in the docs. But maybe not worth changing the behaviour for a short-term fix.
I don't think it's worth merging if it's going to break the current functionality, especially for concave polygons.
Agreed, I'll close for now, may or may not come back to this and add the necessary fix.
In the meantime, we should prob update the docs to say that polygon
expects rational coordinates.
Avoids calling the
2d-geometry
package if the polygon in question has 4 sides, since we can easily triangulate it by hand.Also added a comment to the
polygon
code example in the docs that describes the limitations of this drawing function.Testing:
(Can call
(trace 2d-geometry:make-polygon-from-coords)
to show that the heavyweight triangulation code is only getting called for the 5-sided polygon).