def corner(self, prev_dir, curr_dir): # bezier circle estimate kappa = 4 * (math.sqrt(2) - 1) / 3 final = pointwise('add', self.moves[prev_dir], self.moves[curr_dir]) control1 = pointwise('mul', kappa, self.moves[prev_dir]) control2 = pointwise('sub', final, pointwise('mul', 1 - kappa, self.moves[curr_dir])) replacements = pointwise('div', control1 + control2 + final, 2.0) return 'c %s,%s %s,%s %s,%s ' % tuple(replacements)
def can_move(self, pos, direction): # we always keep the blob on the right n1 = self.neighbours[direction] n2 = self.neighbours[(direction + 1) % self.n_directions] value1 = self.get_value(*pointwise('add', pos, n1)) value2 = self.get_value(*pointwise('add', pos, n2)) return (value1 == 0 and value2 == 1)
def start_draw(self, pos, direction): start = pointwise('add', pos, pointwise('div', self.moves[direction], 2.0)) return '<path d="M %s %s ' % start
def move(self, pos, direction): offset = self.moves[direction] return pointwise('add', pos, offset)
def test_empty(self): self.assertEqual(pointwise('add', [], []), [])
def test_singleton(self): self.assertEqual(pointwise('add', [1, 1], 1), [2, 2])
def test_tuple(self): self.assertEqual(pointwise('add', [1, 1], (2, 2)), (3, 3))
def test_add(self): self.assertEqual(pointwise('add', [1, 1], [2, 2]), [3, 3])