def test_sample_triangle(): """ We sample a triangle, and assert that the barycentric coordinates of the resulting points are all positive, hence the points lie inside the triangle. """ triangle = np.array([ [0, 0], [1, 0], [0, 1] ]) d = 30 points = sample_triangle(triangle, d) bary_coords = barycentric_coordinates(triangle, points) assert np.all(bary_coords[bary_coords > 0])
def test_non_zero_splines_evaluation_multiple_quadratic(): """ Computes all the non-zero quadratic basis splines at a set of points, and asserts that for each point, the basis functions sum to one. """ triangle = np.array([[0, 0], [1, 0], [0, 1]]) d = 2 points = sample_triangle(triangle, 30) bary_coords = barycentric_coordinates(triangle, points) k = determine_sub_triangle(bary_coords) s = evaluate_non_zero_basis_splines(d, bary_coords, k) expected_sum = np.ones((len(points))) computed_sum = s.sum(axis=1) np.testing.assert_almost_equal(expected_sum, computed_sum)
def test_spline_function_evaluation_multiple_linear(): """ Evaluates the linear spline function with all coefficients equal to one, and assert that the value is indeed 1 for all points. """ triangle = np.array([ [0, 0], [1, 0], [0, 1] ]) d = 1 c = np.ones(10) f = SplineFunction(coefficients=c, degree=d, triangle=triangle) points = sample_triangle(triangle, 30) expected_values = np.ones(len(points)) computed_values = f(points) np.testing.assert_almost_equal(expected_values, computed_values)
def test_spline_function_evaluation_multiple_quadratic(): """ Computes all the non-zero quadratic basis splines at a set of points, and asserts that for each point, the basis functions sum to one. """ triangle = np.array([ [0, 0], [1, 0], [0, 1] ]) d = 2 c = np.ones(12) f = SplineFunction(coefficients=c, degree=d, triangle=triangle) points = sample_triangle(triangle, 30) expected_values = np.ones(len(points)) computed_values = f(points) np.testing.assert_almost_equal(expected_values, computed_values)