def test_bezier_point(self): p1 = (30, 20) p2 = (80, 5) p3 = (80, 75) p4 = (30, 75) self.assertEqual(bezier_point(p1, p2, p3, p4, 0.5), Point(67.5, 41.875, 0)) self.assertEqual(bezier_point(p1, p2, p3, p4, 0.9), Point(43.5, 73.055, 0))
def add_vertex(self, vertex): """Add a vertex to the current shape :param vertex: The (next) vertex to add to the current shape. :type vertex: tuple | list | p5.Vector | np.ndarray """ self.vertices.append(Point(*vertex))
def get_curve_vertices(verts): if len(verts) == 0: return [] s = 1 - curves.curve_tightness_amount shape_vertices = [(verts[1][0], verts[1][1], 0.0)] steps = curves.curve_resolution for i in range(1, len(verts) - 2): v = verts[i] start = (shape_vertices[len(shape_vertices) - 1][0], shape_vertices[len(shape_vertices) - 1][1]) c1 = [ v[0] + (s * verts[i + 1][0] - s * verts[i - 1][0]) / 6, v[1] + (s * verts[i + 1][1] - s * verts[i - 1][1]) / 6 ] c2 = [ verts[i + 1][0] + (s * verts[i][0] - s * verts[i + 2][0]) / 6, verts[i + 1][1] + (s * verts[i][1] - s * verts[i + 2][1]) / 6 ] stop = [verts[i + 1][0], verts[i + 1][1]] for i in range(steps + 1): t = i / steps p = curves.bezier_point(start, c1, c2, stop, t) shape_vertices.append(Point(*p)) return shape_vertices
def test_curve_tangent(self): p1 = (73, 24) p2 = (73, 61) p3 = (15, 65) p4 = (15, 65) self.assertEqual(curve_tangent(p1, p2, p3, p4, 0.5), Point(-72.5, 0.375, 0))
def test_curve_point(self): p1 = (73, 24) p2 = (73, 61) p3 = (15, 65) p4 = (15, 65) self.assertEqual(curve_point(p1, p2, p3, p4, 0.5), Point(44.0, 65.3125, 0))
def test_bezier_tangent(self): p1 = (30, 20) p2 = (80, 5) p3 = (80, 75) p4 = (30, 75) self.assertEqual(bezier_tangent(p1, p2, p3, p4, 0.5), Point(0.0, 93.75, 0))
def update_vertex(self, idx, vertex): """Edit an individual vertex. :param idx: index of the vertex to be edited :type idx: int :param vertex: The (next) vertex to add to the current shape. :type vertex: tuple | list | p5.Vector | np.ndarray """ self.vertices[idx] = Point(*vertex)
def get_quadratic_vertices(verts, vert_types): if len(verts) == 0: return [] shape_vertices = [] steps = curves.curve_resolution for i in range(len(verts)): if vert_types[i] == 1 or vert_types[i] == 2: shape_vertices.append((verts[i][0], verts[i][1], 0.0)) else: start = (shape_vertices[len(shape_vertices) - 1][0], shape_vertices[len(shape_vertices) - 1][1]) control = [verts[i][0], verts[i][1]] stop = [verts[i][2], verts[i][3]] for i in range(steps + 1): t = i / steps p = curves.quadratic_point(start, control, stop, t) shape_vertices.append(Point(*p)) return shape_vertices
def test_quadratic_point(self): p1 = (20, 20) p2 = (80, 20) p3 = (50, 50) self.assertEqual(quadratic_point(p1, p2, p3, 0.5), Point(57.5, 27.5, 0))