def test_transform_matching_dimensions(self): expected = square((0, 0), 2) actual = square((0, 0), 2) T = np.array([ [1, 0], [0, 1] ]) np.apply_along_axis(transform(T), 1, actual) self.assertEqual(expected.tolist(), actual.tolist())
def test_transform_smaller_coordinate(self): expected = square((0, 0), 2) actual = square((0, 0), 2) T = np.array([ [1, 0, 0], [0, 1, 0], [0, 0, 1] ]) actual = np.apply_along_axis(transform(T), 1, actual) self.assertEqual(expected.tolist(), actual.tolist())
def __init__(self, axes, origin=None, scale=1, add_coords=None, style=None, convert_2d=None, label_vertices=False): """Construct an instance.""" self._sequence = Sequence() if convert_2d is None: self._convert_2d = self._first_two_coordinates else: self._convert_2d = convert_2d self._square = utility.square(origin, scale, add_coords=add_coords) if style: self._patch = patches.Polygon(self._square[:, :2], **style) else: self._patch = patches.Polygon(self._square[:, :2]) axes.add_patch(self._patch) self._labels = [] if label_vertices: for (x, y), label in zip(self._patch.get_xy(), ["BL", "TL", "TR", "BR"]): text = axes.text(x, y, label) text.set_clip_on(True) self._labels.append(text) self._update_index = 0
def test_transform_affine_translation(self): expected = [[0, 1], [0, 3], [2, 1], [2, 3]] actual = square((0, 0), 2) T = np.array([ [1, 0, 1], # Translate 1 unit right [0, 1, 2], # and 2 units up [0, 0, 1] ]) actual = np.apply_along_axis(transform(T), 1, actual) self.assertCountEqual(expected, actual.tolist())
def test_square_four_dimensional(self): expected = [[-1, -1, 0, 1], [-1, 1, 0, 1], [1, -1, 0, 1], [1, 1, 0, 1]] actual = square((0, 0), 2, add_coords=[0, 1]) self.assertCountEqual(expected, actual.tolist())
def test_square_homogenous(self): expected = [[-1, -1, 1], [-1, 1, 1], [1, -1, 1], [1, 1, 1]] actual = square((0, 0), 2, add_coords=[1]) self.assertCountEqual(expected, actual.tolist())
def test_square(self): expected = [[-1, -1], [-1, 1], [1, -1], [1, 1]] actual = square((0, 0), 2) # Square with width/height 2 centered around (0, 0) self.assertCountEqual(expected, actual.tolist())