def test_bezier_patch(self, cpoints): cverts = [Vertex(p) for p in cpoints] bzr_patch = compile_bezier_patch(cverts) points = sample_func_2D(bzr_patch, 0.1) estimated_points = fit_bezier_patch(points, bezier_patch_2_tuple) estimaded_cverts = [Vertex(p) for p in estimated_points] if VERBOSE: print(".....................................") print(cverts) print(estimaded_cverts) print(".....................................") self.assertTrue(almost_equal_lists(cverts, estimaded_cverts))
def high_degree_approximation(verts): '''Split the verts into four sets (separated on the average) and approximate each of them.''' avgx = numpy.mean([v[0] for v in verts]) avgy = numpy.mean([v[1] for v in verts]) f1 = lambda v: v[0] <= avgx f2 = lambda v: v[1] <= avgy sub_verts = [None] * 4 sub_verts[0] = list(filter(lambda v: f1(v) and f2(v), verts)) sub_verts[1] = list(filter(lambda v: f1(v) and not f2(v), verts)) sub_verts[2] = list(filter(lambda v: not f1(v) and f2(v), verts)) sub_verts[3] = list(filter(lambda v: not f1(v) and not f2(v), verts)) sub_patches_cpoints = [0] * 4 for i,vs in enumerate(sub_verts): sub_patches_cpoints[i] = [Vertex(x) for x in mymath.fit_bezier_patch(vs, mymath.bezier_patch_2_tuple)] return sub_patches_cpoints
def high_degree_approximation(verts): '''Split the verts into four sets (separated on the average) and approximate each of them.''' avgx = numpy.mean([v[0] for v in verts]) avgy = numpy.mean([v[1] for v in verts]) f1 = lambda v: v[0] <= avgx f2 = lambda v: v[1] <= avgy sub_verts = [None] * 4 sub_verts[0] = list(filter(lambda v: f1(v) and f2(v), verts)) sub_verts[1] = list(filter(lambda v: f1(v) and not f2(v), verts)) sub_verts[2] = list(filter(lambda v: not f1(v) and f2(v), verts)) sub_verts[3] = list(filter(lambda v: not f1(v) and not f2(v), verts)) sub_patches_cpoints = [0] * 4 for i, vs in enumerate(sub_verts): sub_patches_cpoints[i] = [ Vertex(x) for x in mymath.fit_bezier_patch(vs, mymath.bezier_patch_2_tuple) ] return sub_patches_cpoints
def simple_approximation(verts, func): #Simply approximate the verts with the given function cpoints = mymath.fit_bezier_patch(verts, func) return [Vertex(cp) for cp in cpoints]
def test_double_patch(self): points = [Vertex(p) for p in two_patches_points] estimated_points = fit_bezier_patch(points, bezier_patch_2_tuple) print(estimated_points)