geom icon indicating copy to clipboard operation
geom copied to clipboard

`thi.ng.geom.polygon/tesselate*` sometimes returns nil for certain pt orderings of polygons

Open harold opened this issue 3 years ago • 1 comments

Hi, first- thanks to all involved, this library continues to boggle the brain and delight the heart. I love it and am so grateful for all the efforts of all involved.

I was extruding some polygons, and sometimes the caps were missing, and I believe the root cause to be related to this:

> (def pts [[-0.040626499149128546 -2.1993343273656203]
            [-0.5189426962437235 -2.6776505244602133]
            [-0.9972588933383101 -3.155966721554806]
            [-1.6506509696110883 -2.9808908423766187]
            [-2.128967166705682 -3.4592070394712198]
            [-0.8221830141601257 -3.8093587978275822]
            [0.13444938002906096 -2.8527264036383966]])
#'pts
> (p/tessellate* (p/polygon2 pts))
nil ;; Uh oh!
> (def pt-n (count pts))
#'pt-n
> (p/tessellate* (p/polygon2 (take pt-n (drop 1 (cycle pts)))))
nil
> (p/tessellate* (p/polygon2 (take pt-n (drop 2 (cycle pts)))))
nil
> (p/tessellate* (p/polygon2 (take pt-n (drop 3 (cycle pts)))))
nil
;; But wait, then this happens (!)
> (p/tessellate* (p/polygon2 (take pt-n (drop 4 (cycle pts)))))
[[[-1.6506509696110883 -2.9808908423766187]
  [-2.128967166705682 -3.4592070394712198]
  [-0.8221830141601257 -3.8093587978275822]]
 [[-0.8221830141601257 -3.8093587978275822]
  [0.13444938002906096 -2.8527264036383966]
  [-0.040626499149128546 -2.1993343273656203]]
 [[-0.9972588933383101 -3.155966721554806]
  [-1.6506509696110883 -2.9808908423766187]
  [-0.8221830141601257 -3.8093587978275822]]
 [[-0.8221830141601257 -3.8093587978275822]
  [-0.040626499149128546 -2.1993343273656203]
  [-0.5189426962437235 -2.6776505244602133]]
 [[-0.5189426962437235 -2.6776505244602133]
  [-0.9972588933383101 -3.155966721554806]
  [-0.8221830141601257 -3.8093587978275822]]]
> (p/tessellate* (p/polygon2 (take pt-n (drop 5 (cycle pts)))))
nil
> (p/tessellate* (p/polygon2 (take pt-n (drop 6 (cycle pts)))))
[[[-0.8221830141601257 -3.8093587978275822]
  [0.13444938002906096 -2.8527264036383966]
  [-0.040626499149128546 -2.1993343273656203]]
 [[-0.9972588933383101 -3.155966721554806]
  [-1.6506509696110883 -2.9808908423766187]
  [-2.128967166705682 -3.4592070394712198]]
 [[-0.8221830141601257 -3.8093587978275822]
  [-0.040626499149128546 -2.1993343273656203]
  [-0.5189426962437235 -2.6776505244602133]]
 [[-0.9972588933383101 -3.155966721554806]
  [-2.128967166705682 -3.4592070394712198]
  [-0.8221830141601257 -3.8093587978275822]]
 [[-0.8221830141601257 -3.8093587978275822]
  [-0.5189426962437235 -2.6776505244602133]
  [-0.9972588933383101 -3.155966721554806]]]
> (p/tessellate* (p/polygon2 (take pt-n (drop 7 (cycle pts)))))
nil

IIUC (and that's a stretch!), the tessellation shouldn't depend on the where we start in the list of points?

I've got a workaround going based on the idea in that listing, so I'm off and running.

Regardless, thanks again for your time and consideration. Stay rad.

harold avatar Jan 22 '22 00:01 harold

Here's another interesting set of points for which no cycle start point computes a tessellation:

[[7.052863458971486 0.7518158535001843]
 [6.3994713826986995 0.9268917326783749]
 [6.574547261876895 0.2734996564055905]
 [7.2279393381496675 0.09842377722740307]
 [7.70625553524426 0.5767399743220022]
 [7.531179656066083 1.2301320505947784]
 [8.00949585316067 1.7084482476893659]
 [8.662887929433442 1.5333723685111784]
 [9.141204126528038 2.0116885656057786]
 [8.487812050255258 2.1867644447839596]
 [8.96612824734986 2.6650806418785526]
 [8.61597648899348 3.971864794424109]
 [7.309192336447924 4.322016552780477]
 [7.484268215626116 3.668624476507692]
 [8.13766029189888 3.4935485973295193]
 [8.31273617107707 2.840156521056736]
 [7.834419973982478 2.3618403239621504]
 [6.877787579793297 1.4052079297729614]]

harold avatar Jan 22 '22 03:01 harold