def surf(): """ Generate surface for testing """ surf = spline.Surface() surf.degree_u = 2 surf.degree_v = 2 surf.num_ctrlpts_u = 5 surf.num_ctrlpts_v = 5 x = np.arange(0.0, 5.0) y = np.arange(0.0, 5.0) ys, xs = np.meshgrid(x, y) theta = np.linspace(0, 2 * np.pi, len(xs.flatten())) z = np.sin(theta) ctrlpt_array = np.column_stack((xs.flatten(), ys.flatten(), z)) surf.control_points = ctrlpt_array uvec = knots.generate_uniform(surf.degree_u, surf.num_ctrlpts_u) vvec = knots.generate_uniform(surf.degree_v, surf.num_ctrlpts_v) surf.knot_vector_u = uvec surf.knot_vector_v = vvec return surf
def test_knot_vector_v(surf): vvec = knots.generate_uniform(surf.degree_v, surf.num_ctrlpts_v) condition = np.allclose(vvec, surf.knot_vector_v) assert condition
def test_knot_vector_u(surf): uvec = knots.generate_uniform(surf.degree_u, surf.num_ctrlpts_u) condition = np.allclose(uvec, surf.knot_vector_u) assert condition
def test_generate2(): degree = 3 num_ctrlpts = 4 expected = np.array([0, 0, 0, 0, 1, 1, 1, 1]) generated = knots.generate_uniform(degree, num_ctrlpts) condition = np.allclose(generated, expected) assert condition
def test_generate3(): degree = 2 num_ctrlpts = 6 expected = np.array([0, 0, 0, 0.25, 0.5, 0.75, 1, 1, 1]) generated = knots.generate_uniform(degree, num_ctrlpts) condition = np.allclose(generated, expected) assert condition
def test_surf_knot_vector_guard_v(): with pytest.raises(Exception): x = np.arange(0.0, 5.0) y = np.arange(0.0, 5.0) ys, xs = np.meshgrid(x, y) ctrlpt_array = np.column_stack((xs.flatten(), ys.flatten(), np.zeros(len(xs.flatten())))) surf = spline.Surface() surf.degree_u = 2 surf.degree_v = 2 num_ctrlpts = 5 knot_vec = knots.generate_uniform(surf.degree_v, num_ctrlpts) surf.knot_vector_v = knot_vec