Esempio n. 1
0
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)
Esempio n. 2
0
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)
Esempio n. 3
0
class TestBezierKnots(unittest.TestCase):
    def setUp(self):
        self.knots = Knots(np.array([0.,0,1,1]), degree=2)

    def test_intervals(self):
        intervals = list(self.knots.intervals())
        self.assertEqual(len(intervals), self.knots.nb_curves)

    def test_left_knot(self):
        self.assertEqual(self.knots.left_knot(.2), 1)
        self.assertEqual(self.knots.left_knot(.8), 1)
Esempio n. 4
0
class TestDoubleQuadKnots(unittest.TestCase):
    def setUp(self):
        self.knots = Knots([0,0,.5,1,1], degree=2)

    def test_info(self):
        self.assertEqual(self.knots.degree, 2)
        self.assertEqual(self.knots.nb_curves,2)
        self.assertEqual(len(self.knots.knot_range()), self.knots.nb_curves)
Esempio n. 5
0
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.)
Esempio n. 6
0
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.)
Esempio n. 7
0
class TestBigKnot(unittest.TestCase):
    def setUp(self):
        self.knots = Knots(np.array([1.,2.,3.,4.,5.,6.,7.]), degree=3)

    def test_left_knot(self):
        self.assertEqual(self.knots.left_knot(3.8), 2)
        self.assertEqual(self.knots.left_knot(3.2), 2)
        self.assertEqual(self.knots.left_knot(4.8), 3)
        self.assertEqual(self.knots.left_knot(4.0), 3)
        self.assertEqual(self.knots.left_knot(4.0-1e-14), 3)
        with self.assertRaises(ValueError):
            self.knots.left_knot(2.5)
        with self.assertRaises(ValueError):
            self.knots.left_knot(5.5)

    def test_knot_range(self):
        k = Knots(np.arange(10))
        self.assertEqual(len(k.knot_range()), 0)
Esempio n. 8
0
 def setUp(self):
     self.values = np.array([1.,2.,3.,4.,5.,6.,7.])
     self.knots = Knots(self.values, degree=3)
Esempio n. 9
0
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
Esempio n. 10
0
def test_knot_range(long_knots):
    knots = long_knots
    k = Knots(np.arange(10))
    assert len(k.knot_range()) == 0
Esempio n. 11
0
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
Esempio n. 12
0
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
Esempio n. 13
0
 def test_knot_range(self):
     k = Knots(np.arange(10))
     self.assertEqual(len(k.knot_range()), 0)
Esempio n. 14
0
 def setUp(self):
     self.knots = Knots(np.array([1.,2.,3.,4.,5.,6.,7.]), degree=3)
Esempio n. 15
0
 def test_intervals(self):
     K = Knots(self.knots, degree=3)
     intervals = list(K.intervals())
     self.assertEqual(len(intervals), K.nb_curves)
Esempio n. 16
0
 def setUp(self):
     self.knots = Knots([0,0,.5,1,1], degree=2)
Esempio n. 17
0
def knots():
    return Knots(np.array([0., 0, 1, 1]), degree=2)
Esempio n. 18
0
 def setUp(self):
     self.knots = Knots(np.array([0.,0,1,1]), degree=2)
Esempio n. 19
0
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
Esempio n. 20
0
def long_knots():
    values = np.array([1., 2., 3., 4., 5., 6., 7.])
    knots = Knots(values, degree=3)
    return knots
Esempio n. 21
0
def test_knot_range(long_knots):
    knots = long_knots
    k = Knots(np.arange(10))
    assert len(k.knot_range()) == 0