def add_cubic_bezier_curve( self, anchor1: npt.ArrayLike, handle1: npt.ArrayLike, handle2: npt.ArrayLike, anchor2: npt.ArrayLike ): new_points = get_quadratic_approximation_of_cubic(anchor1, handle1, handle2, anchor2) self.append_points(new_points)
def add_cubic_bezier_curve_to(self, handle1, handle2, anchor): """ Add cubic bezier curve to the path. """ self.throw_error_if_no_points() quadratic_approx = get_quadratic_approximation_of_cubic( self.get_last_point(), handle1, handle2, anchor) if self.has_new_path_started(): self.append_points(quadratic_approx[1:]) else: self.append_points(quadratic_approx)
def change_anchor_mode(self, mode: str): assert(mode in ("jagged", "approx_smooth", "true_smooth")) nppc = self.n_points_per_curve for submob in self.family_members_with_points(): subpaths = submob.get_subpaths() submob.clear_points() for subpath in subpaths: anchors = np.vstack([subpath[::nppc], subpath[-1:]]) new_subpath = np.array(subpath) if mode == "approx_smooth": new_subpath[1::nppc] = get_smooth_quadratic_bezier_handle_points(anchors) elif mode == "true_smooth": h1, h2 = get_smooth_cubic_bezier_handle_points(anchors) new_subpath = get_quadratic_approximation_of_cubic(anchors[:-1], h1, h2, anchors[1:]) elif mode == "jagged": new_subpath[1::nppc] = 0.5 * (anchors[:-1] + anchors[1:]) submob.append_points(new_subpath) submob.refresh_triangulation() return self
def change_anchor_mode(self, mode): assert (mode in ["jagged", "smooth"]) nppc = self.n_points_per_curve for submob in self.family_members_with_points(): subpaths = submob.get_subpaths() submob.clear_points() for subpath in subpaths: anchors = np.vstack([subpath[::nppc], subpath[-1:]]) new_subpath = np.array(subpath) if mode == "smooth": # TOOD, it's not clear which of the two options below should be the default, # leaving option 1 here commented out as a temporary note. # Option 1: # new_subpath[1::nppc] = get_smooth_quadratic_bezier_handle_points(anchors) # Option 2: h1, h2 = get_smooth_cubic_bezier_handle_points(anchors) new_subpath = get_quadratic_approximation_of_cubic( anchors[:-1], h1, h2, anchors[1:]) elif mode == "jagged": new_subpath[1::nppc] = 0.5 * (anchors[:-1] + anchors[1:]) submob.append_points(new_subpath) submob.refresh_triangulation() return self