         id = t.id
         continue if id == tid || seen[id]
         tp = others[id]
-        continue unless tp and gd[tp] <= distance
+        continue unless tp
+        d3 = gd[tp]
+        continue unless d3 and d3 <= distance
         sin3 = gd[ tp + 1 ]
         seg3 = gd[ tp + 3 ]
         keep = if seg3 == seg1 or seg3 == seg2

abs    = Math.abs
acos   = Math.acos
cos    = Math.cos
max    = Math.max
min    = Math.min
random = Math.random


degrees = (radians) -> 360 * radians / TAU

div = ( n, d ) -> floor n / d

# randomization utility
shuffle = (ar, dup=false) ->
  ar = [].concat ar if dup
