def test_sBasisCurve(self): S = SBasisCurve(SBasis(0, 2), SBasis(3, 7)*SBasis(1, 8)) a = SBasis(3, 9)*SBasis(4, 6) b = SBasis(2, 0) c = a(b) self.curve(S) self.curve(S.derivative()) self.curve(S.reverse()) self.curve(S.transformed( Scale(4) )) self.curve(S.transformed( Zoom(9, Translate(3, 6)) )) self.curve(SBasisCurve(a*b*c, a+b+c)) self.curve(S.derivative().derivative())
def test_scale(self): S = Scale() T = Scale( Point (3, 8) ) U = Scale( -3, 1) V = Scale(sqrt(2)) self.assertTrue( Affine(T).is_scale() ) self.assertTrue( Affine(T).is_nonzero_scale() ) self.assertTrue( Affine(V).is_nonzero_uniform_scale()) self.assertEqual( (T*V).vector(), T.vector()*sqrt(2) ) self.assertEqual( (T*U)[0], T[0]*U[0] ) self.assertAlmostEqual( 1/U.inverse()[1], U[1] ) r = Rect.from_points( Point(0, 2), Point(4, 8) ) self.assertAlmostEqual((r*V).area(), 2*r.area()) self.assertFalse(Affine(U).preserves_area()) self.assertTrue(Affine(V).preserves_angles()) self.affine(Affine(T), Affine(U)) self.affine(Affine(U), Affine(V)) self.affine(Affine(V), Affine(T))
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 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_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_scale(self): S = Scale() T = Scale(Point(3, 8)) U = Scale(-3, 1) V = Scale(sqrt(2)) self.assertTrue(Affine(T).is_scale()) self.assertTrue(Affine(T).is_nonzero_scale()) self.assertTrue(Affine(V).is_nonzero_uniform_scale()) self.assertEqual((T * V).vector(), T.vector() * sqrt(2)) self.assertEqual((T * U)[0], T[0] * U[0]) self.assertAlmostEqual(1 / U.inverse()[1], U[1]) r = Rect.from_points(Point(0, 2), Point(4, 8)) self.assertAlmostEqual((r * V).area(), 2 * r.area()) self.assertFalse(Affine(U).preserves_area()) self.assertTrue(Affine(V).preserves_angles()) self.affine(Affine(T), Affine(U)) self.affine(Affine(U), Affine(V)) self.affine(Affine(V), Affine(T))