def ntest_lineSegment(self): L = LineSegment(Point(2, 8), Point(1, 9)) K = LineSegment.from_beziers(Bezier(2, 8), Bezier(-1, 9)) self.curve(L) self.curve(K) self.curve(L.reverse()) self.curve(L.portion(Interval(0.2, 0.4))) self.curve(L.subdivide(0.3)[0]) self.curve(L.subdivide(0.3)[1]) self.curve(L.derivative()) self.curve(L.transformed(Scale(30)*Translate(3, 9))) self.curve(LineSegment())
def test_quadraticBezier(self): Q = QuadraticBezier(Point(2, 8), Point(1, 9), Point(-2, 3)) R = QuadraticBezier.from_beziers(Bezier(2, 8, 4), Bezier(-1, 9, 9)) self.curve(Q) self.curve(R) self.curve(Q.reverse()) self.curve(Q.portion(interval=Interval(0.1, 0.9))) self.curve(Q.subdivide(0.8)[0]) self.curve(Q.subdivide(0.8)[1]) self.curve(Q.derivative()) self.curve(Q.transformed(Scale(-3)*Translate(4, 8))) self.curve(QuadraticBezier())
def test_cubicBezier(self): C = CubicBezier(Point(2, 0), Point(-1, 2.9), Point(-2, 3), Point(3, 1)) D = CubicBezier.from_beziers(Bezier(2, 8, 4, 7), Bezier(-1, 9, 9, 8)) print 343 self.curve(C) self.curve(D) self.curve(C.reverse()) #Some kind of numerical instability imo #~ self.curve(C.portion(Interval(0.1, 0.9))) self.curve(C.subdivide(0.8)[0]) self.curve(C.subdivide(0.8)[1]) self.curve(C.derivative()) self.curve(C.transformed(Scale(-3)*Translate(4, 8))) self.curve(CubicBezier())
def test_bezier(self): B = Bezier() C = Bezier(2) D = Bezier(2, 4) E = Bezier(1, 3, 9) F = Bezier(-2, 5, -1, 2) self.assertTrue( B.is_zero() ) self.assertTrue( C.is_constant() ) self.assertTrue( D.is_finite() ) C.clear() self.assertEqual(D.degree(), 1) self.assertEqual(E.at0(), 1) self.assertEqual(E.at1(), 9) self.assertEqual(E[2], 9) for i in range(11): t = i/10.0 self.assertAlmostEqual( D(t), lerp(t, 2, 4) ) self.assertAlmostEqual( D(t), D.value_at(t)) self.assertAlmostEqual( D.value_and_derivatives(t, 0)[0], D(t) ) self.assertAlmostEqual( D.value_and_derivatives(t, 1)[1], Bezier.derivative(D)(t) ) self.assertAlmostEqual( Bezier.integral(D).value_and_derivatives(t, 1)[1], D(t) ) #~ self.assertAlmostEqual( D.elevate_degree().reduce_degree()(t), D(t) ) self.assertAlmostEqual( (D+2)(t), D(t)+2 ) self.assertAlmostEqual( (D-1)(t), D(t)-1 ) self.assertAlmostEqual( (D*2)(t), D(t)*2 ) self.assertAlmostEqual( (D/4)(t), D(t)/4 ) self.assertTrue( Bezier.bounds_fast(F).Interval.contains(F(t)) ) self.assertTrue( Bezier.bounds_exact(F).Interval.contains(F(t)) ) self.assertTrue( Bezier.bounds_local(F, OptInterval(t-0.05, t+0.05)).Interval.contains(F(t)) ) for r in F.roots(): self.assertAlmostEqual(F(r), 0) #TODO: bug in 2geom? #~ for r in F.roots(Interval(0.1, 0.8)): #~ self.assertAlmostEqual(F(r), 0) #~ self.assertTrue( 0.1 <= r <= 0.8 ) self.assertIsInstance(F.forward_difference(1), Bezier) self.assertIsInstance(F.elevate_degree(), Bezier) self.assertIsInstance(E.reduce_degree(), Bezier) #F.reduce_degree() fails with # *** glibc detected *** python2: malloc(): memory corruption: self.assertIsInstance(F.elevate_to_degree(4), Bezier) self.assertIsInstance(F.deflate(), Bezier) S = F.to_SBasis() self.assertIsInstance(S, SBasis) for i in range(11): t = i/10.0 self.assertAlmostEqual(S(t), F(t))