class TestBezier2: bezier_default = geo.Bezier2(next_point=geo.Point2(3, 2), handle1=geo.Vector2(1, 0), handle2=geo.Vector2(0, 1)) bezier_other = geo.Bezier2(next_point=geo.Point2(2, 3), handle1=geo.Vector2(0, 1), handle2=geo.Vector2(1, 0)) def test_constructor(self): assert self.bezier_default.next_point == geo.Point2(3, 2) assert self.bezier_default.handle1 == geo.Vector2(1, 0) assert self.bezier_default.handle2 == geo.Vector2(0, 1) def test_copy(self): bezier = copy(self.bezier_default) assert bezier == self.bezier_default assert bezier is not self.bezier_default def test_repr(self): assert (str(self.bezier_default) == 'Bezier2(handle1=<1.00, 0.00>, ' 'handle2=<0.00, 1.00>, ' 'next_point=<3.00, 2.00>)') def test_ne(self): assert self.bezier_default != self.bezier_other
def grid_cell_size(bbox, cell_width, cell_height, margin=0, min_padding=0): ''' Create a grid within a rectangle based off of a set width and height for the grid cells. :param bbox: The bounding box to create the grid within :param cell_width: The width of a grid cell :param padding: The height of a grid cell ''' width, height = bbox working_width = bbox.width - 2 * margin working_height = bbox.height - 2 * margin num_horiz = math.floor( (working_width + min_padding) / (cell_width + min_padding)) num_vert = math.floor( (working_height + min_padding) / (cell_height + min_padding)) padding_horiz = ((width - (2 * margin + num_horiz * cell_width + min_padding)) / (num_horiz - 1)) padding_vert = ((height - (2 * margin + num_vert * cell_height + min_padding)) / (num_vert - 1)) grid_pos = lambda x, y: geo.Vector2(margin + x * padding_horiz, margin + y * padding_vert) return [[ geo.Rectangle(grid_pos(x, y), cell_width, cell_height) for x in num_horiz ] for y in num_vert]
def grid_dimensions(bbox, num_horiz, num_vert, margin=0, padding=0): ''' Create a grid within a rectangle based off of the number of cells you want in the grid horizontally and vertically. :param bbox: The bounding box to create the grid within :param num_horiz: The number of grid cells to create horizontally :param num_vert: The number of grid cells to create vertically ''' width, height = bbox cell_width = (width - 2 * margin - (num_horiz - 1) * padding) / num_horiz cell_height = (height - 2 * margin - (num_vert - 1) * padding) / num_vert margin_offset = geo.Vector2(margin, margin) added_cells = lambda x, y: geo.Vector2(x * cell_width, y * cell_height) added_padding = lambda x, y: geo.Vector2(x * padding, y * padding) return [[ margin_offset + added_cells(x, y) + added_padding(x, y) for x in range(num_horiz) ] for y in range(num_vert)]
def test_linspace_vector2(): first = geo.Vector2(0, 0) second = geo.Vector2(1, 4) expected = [first, geo.Vector2(0.5, 2), second] actual = util.linspace_vector2(first, second, 3) assert actual == expected
def test_lerp_vector2_as_vector2(): first = geo.Vector2(0, 0) second = geo.Vector2(1, 4) expected = geo.Vector2(0.25, 1) actual = util.lerp_vector2(first, second, 0.25) assert actual == expected
def test_constructor(self): assert self.bezier_default.next_point == geo.Point2(3, 2) assert self.bezier_default.handle1 == geo.Vector2(1, 0) assert self.bezier_default.handle2 == geo.Vector2(0, 1)
def test_constructor(self): assert self.line_default.position == geo.Point2(1, 1) assert self.line_default.vector == geo.Vector2(2, 0) assert self.line_default.p1 == geo.Point2(1, 1) assert self.line_default.p2 == geo.Point2(3, 1)