def test_abscissae(): pts = np.random.random_sample([7, 2]) knots = [0, 0, 0, 2, 3, 4, 5, 5, 5] K = Knots(knots, degree=3) computed = K.abscissae() expected = np.array([0, 2 / 3, 5 / 3, 3, 4, 14 / 3, 5]) # values from Sederberg ยง6.14 npt.assert_allclose(computed, expected)
def test_sum_to_one(): """ Check that the basis functions sum up to one. """ w = [0, 0, 0, 1 / 3, 2 / 3, 1, 1, 1] wk = Knots(w, degree=3) basis = [wk.get_basis(i) for i in range(6)] vals = [] for b in basis: vals_b = [] for s in b: l, r = s.interval ts = np.linspace(l, r) vals_b.append(s(ts)) vals.append(vals_b) avals = np.array(vals) npt.assert_allclose(np.sum(avals[:, :, :, 1], axis=0), 1.)
def test_knot_range(long_knots): knots = long_knots k = Knots(np.arange(10)) assert len(k.knot_range()) == 0
def long_knots(): values = np.array([1., 2., 3., 4., 5., 6., 7.]) knots = Knots(values, degree=3) return knots
def test_intervals(): knots = np.array([0, 0, .5, 1, 1]) K = Knots(knots, degree=3) intervals = list(K.intervals()) assert len(intervals) == K.nb_curves
def test_info(): knots = Knots([0, 0, .5, 1, 1], degree=2) assert knots.degree == 2 assert knots.nb_curves == 2 assert len(knots.knot_range()) == knots.nb_curves
def knots(): return Knots(np.array([0., 0, 1, 1]), degree=2)