def polys(self):
if self._poly_cache is None:
- print "===="
self._poly_cache = [
rp.poly(self._body, self._ray_filter) for rp in self._rays
if rp.within_limits(*self._angle_limits)
]
- print "===="
-
return self._poly_cache
def pygame_polys(self, surface):
if self._pygame_poly_cache is None:
- print "REGEN ...", self._angle_limits
self._pygame_poly_cache = [
[
pymunk.pygame_util.to_pygame(v, surface)
def within_limits(self, start_limit, end_limit):
if start_limit is None or end_limit is None:
return True
- print "----"
- print "LIM: ", start_limit, end_limit
- print "ANG: ", self.start.angle, self.end.angle
- n1 = self.start.normalized()
- n2 = self.end.normalized()
- s = pymunk.Vec2d(1, 0).rotated(start_limit)
- e = pymunk.Vec2d(1, 0).rotated(end_limit)
- n1bet = s.dot(e) < s.dot(n1) and s.dot(e) < s.dot(n1)
- n2bet = s.dot(e) < e.dot(n2) and s.dot(e) < e.dot(n2)
- print "DOTS n1: ", n1.dot(n2), n1.dot(s), n2.dot(s)
- print "DOTS n2: ", n1.dot(n2), n1.dot(e), n2.dot(e)
- print "BET: ", n1bet, n2bet
- if n1bet:
- print "TRUE\n----"
+
+ def between(n):
+ if start_limit < end_limit:
+ return start_limit <= n <= end_limit
+ return (start_limit <= n) or (n <= end_limit)
+
+ start_within = between(self.start.angle)
+ end_within = between(self.end.angle)
+ if start_within or end_within:
return True
return False