def test_segment_vertical_lineto_rel(self): segment = SVGPathSegment('v') self.assertTrue(not segment.isvalid()) self.assertTrue(not segment.isabsolute()) self.assertTrue(segment.isrelative()) self.assertEqual((), segment.values) self.assertEqual((None, None), segment.end) d = segment.tostring() self.assertEqual('', d) segment = SVGPathSegment('v', -50) self.assertTrue(segment.isvalid()) self.assertTrue(not segment.isabsolute()) self.assertTrue(segment.isrelative()) self.assertEqual((-50,), segment.values) self.assertEqual((0, -50), segment.end) d = segment.tostring() self.assertEqual('v-50', d) segment = SVGPathSegment() segment.set_vertical_lineto_rel(150) self.assertTrue(segment.isvalid()) self.assertTrue(not segment.isabsolute()) self.assertTrue(segment.isrelative()) self.assertEqual((150,), segment.values) self.assertEqual((0, 150), segment.end) d = segment.tostring() self.assertEqual('v150', d)
def test_segment_lineto_abs(self): segment = SVGPathSegment('L') self.assertTrue(not segment.isvalid()) self.assertTrue(segment.isabsolute()) self.assertTrue(not segment.isrelative()) self.assertEqual((), segment.values) self.assertEqual((None, None), segment.end) d = segment.tostring() self.assertEqual('', d) segment = SVGPathSegment() segment.set_lineto_abs(100, 50) self.assertTrue(segment.isvalid()) self.assertTrue(segment.isabsolute()) self.assertTrue(not segment.isrelative()) self.assertEqual((100, 50), segment.values) self.assertEqual((100, 50), segment.end) d = segment.tostring() self.assertEqual('L100,50', d) segment = SVGPathSegment('L', -50, 0) self.assertTrue(segment.isvalid()) self.assertTrue(segment.isabsolute()) self.assertTrue(not segment.isrelative()) self.assertEqual((-50, 0), segment.values) self.assertEqual((-50, 0), segment.end) d = segment.tostring() self.assertEqual('L-50,0', d)
def test_segment_moveto_rel(self): segment = SVGPathSegment('m') self.assertTrue(not segment.isvalid()) self.assertTrue(not segment.isabsolute()) self.assertTrue(segment.isrelative()) self.assertEqual((), segment.values) self.assertEqual((None, None), segment.end) exp = segment.tostring() self.assertEqual('', exp) segment = SVGPathSegment('m', 100, 50) self.assertTrue(segment.isvalid()) self.assertTrue(not segment.isabsolute()) self.assertTrue(segment.isrelative()) self.assertEqual((100, 50), segment.values) self.assertEqual((100, 50), segment.end) exp = segment.tostring() self.assertEqual('m100,50', exp) segment = SVGPathSegment() segment.set_moveto_rel(100, 100) segment.set_moveto_rel(50, 0) # overwrite self.assertTrue(segment.isvalid()) self.assertTrue(not segment.isabsolute()) self.assertTrue(segment.isrelative()) self.assertEqual((50, 0), segment.values) self.assertEqual((50, 0), segment.end) exp = segment.tostring() self.assertEqual('m50,0', exp)
def test_segment_arcto_rel(self): segment = SVGPathSegment('a') self.assertTrue(not segment.isvalid()) self.assertTrue(not segment.isabsolute()) self.assertTrue(segment.isrelative()) self.assertEqual((), segment.values) self.assertEqual((None, None), segment.end) d = segment.tostring() self.assertEqual('', d) segment = SVGPathSegment('a', 100, 50, 0, 0, 0, 100, 50) self.assertTrue(segment.isvalid()) self.assertTrue(not segment.isabsolute()) self.assertTrue(segment.isrelative()) self.assertEqual((100, 50, 0, 0, 0, 100, 50), segment.values) self.assertEqual((100, 50), segment.end) d = segment.tostring() self.assertEqual('a100,50 0 0 0 100,50', d) segment = SVGPathSegment() segment.set_elliptical_arc_rel(100, 50, 0, 0, 0, 100, 50) self.assertTrue(segment.isvalid()) self.assertTrue(not segment.isabsolute()) self.assertTrue(segment.isrelative()) self.assertEqual((100, 50, 0, 0, 0, 100, 50), segment.values) self.assertEqual((100, 50), segment.end) d = segment.tostring() self.assertEqual('a100,50 0 0 0 100,50', d)
def test_segment_horizontal_lineto_rel(self): segment = SVGPathSegment('h') self.assertTrue(not segment.isvalid()) self.assertTrue(not segment.isabsolute()) self.assertTrue(segment.isrelative()) self.assertEqual((), segment.values) self.assertEqual((None, None), segment.end) d = segment.tostring() self.assertEqual('', d) segment = SVGPathSegment('h', 100) self.assertTrue(segment.isvalid()) self.assertTrue(not segment.isabsolute()) self.assertTrue(segment.isrelative()) self.assertEqual((100,), segment.values) self.assertEqual((100, 0), segment.end) d = segment.tostring() self.assertEqual('h100', d) segment = SVGPathSegment() segment.set_horizontal_lineto_rel(50) self.assertTrue(segment.isvalid()) self.assertTrue(not segment.isabsolute()) self.assertTrue(segment.isrelative()) self.assertEqual((50,), segment.values) self.assertEqual((50, 0), segment.end) d = segment.tostring() self.assertEqual('h50', d)
def test_segment_quadratic_curveto_abs(self): # See also: quad01.html segment = SVGPathSegment('Q') self.assertTrue(not segment.isvalid()) self.assertTrue(segment.isabsolute()) self.assertTrue(not segment.isrelative()) self.assertEqual((), segment.values) self.assertEqual((None, None), segment.end) d = segment.tostring() self.assertEqual('', d) # "M200,300 Q400,50 600,300 T1000,300" # "Q400,50 600,300" segment = SVGPathSegment('Q', 400, 50, 600, 300) self.assertTrue(segment.isvalid()) self.assertTrue(segment.isabsolute()) self.assertTrue(not segment.isrelative()) self.assertEqual((400, 50, 600, 300), segment.values) self.assertEqual((600, 300), segment.end) d = segment.tostring() self.assertEqual('Q400,50 600,300', d) segment = SVGPathSegment() segment.set_quadratic_curveto_abs(400, 50, 600, 300) self.assertTrue(segment.isvalid()) self.assertTrue(segment.isabsolute()) self.assertTrue(not segment.isrelative()) self.assertEqual((400, 50, 600, 300), segment.values) self.assertEqual((600, 300), segment.end) d = segment.tostring() self.assertEqual('Q400,50 600,300', d)
def test_segment_arcto_abs(self): segment = SVGPathSegment('A') self.assertTrue(not segment.isvalid()) self.assertTrue(segment.isabsolute()) self.assertTrue(not segment.isrelative()) self.assertEqual((), segment.values) self.assertEqual((None, None), segment.end) d = segment.tostring() self.assertEqual('', d) segment = SVGPathSegment('A', 160, 80, 0, 0, 1, 200, 280) self.assertTrue(segment.isvalid()) self.assertTrue(segment.isabsolute()) self.assertTrue(not segment.isrelative()) self.assertEqual((160, 80, 0, 0, 1, 200, 280), segment.values) self.assertEqual((200, 280), segment.end) d = segment.tostring() self.assertEqual('A160,80 0 0 1 200,280', d) segment = SVGPathSegment() segment.set_elliptical_arc_abs(160, 80, 0, 0, 1, 200, 280) self.assertTrue(segment.isvalid()) self.assertTrue(segment.isabsolute()) self.assertTrue(not segment.isrelative()) self.assertEqual((160, 80, 0, 0, 1, 200, 280), segment.values) self.assertEqual((200, 280), segment.end) d = segment.tostring() self.assertEqual('A160,80 0 0 1 200,280', d)
def test_segment_smooth_quadratic_curveto_rel(self): # See also: quad02.html segment = SVGPathSegment('t') self.assertTrue(not segment.isvalid()) self.assertTrue(not segment.isabsolute()) self.assertTrue(segment.isrelative()) self.assertEqual((), segment.values) self.assertEqual((None, None), segment.end) d = segment.tostring() self.assertEqual('', d) segment = SVGPathSegment('t', 400, 0) self.assertTrue(segment.isvalid()) self.assertTrue(not segment.isabsolute()) self.assertTrue(segment.isrelative()) self.assertEqual((400, 0), segment.values) self.assertEqual((400, 0), segment.end) d = segment.tostring() expected = 't400,0' self.assertEqual(expected, d) segment = SVGPathSegment() segment.set_smooth_quadratic_curveto_rel(400, 0) self.assertTrue(segment.isvalid()) self.assertTrue(not segment.isabsolute()) self.assertTrue(segment.isrelative()) self.assertEqual((400, 0), segment.values) self.assertEqual((400, 0), segment.end) d = segment.tostring() expected = 't400,0' self.assertEqual(expected, d) segment2 = PathSegment.toabsolute(segment, 600, 300, 0) d = segment2.tostring() expected = 'T1000,300' self.assertEqual(expected, d) self.assertTrue(id(segment) != id(segment2)) # "m200,300 q200,-250 400,0 t400,0 400,0" # "M200,300 Q400,50 600,300 T1000,300 1400,300" # "m200,300 q200,-250 400,0 t400,0 400,0" # See test_quad02_path01_normalize(), test_quad02_path03_normalize() segment2 = PathSegment.normalize(segment, 600, 300, 0)[0] d = segment2.tostring() expected = 'C600,300 733.333,300 1000,300' self.assertEqual(expected, d) self.assertTrue(id(segment) != id(segment2)) segment2 = PathSegment.normalize(segment, 600, 300, 0, x1=800, y1=550)[0] d = segment2.tostring() expected = 'C733.333,466.667 866.667,466.667 1000,300' self.assertEqual(expected, d) self.assertTrue(id(segment) != id(segment2))
def test_segment_smooth_curveto_rel(self): segment = SVGPathSegment('s') self.assertTrue(not segment.isvalid()) self.assertTrue(not segment.isabsolute()) self.assertTrue(segment.isrelative()) self.assertEqual((), segment.values) self.assertEqual((None, None), segment.end) d = segment.tostring() self.assertEqual('', d) # "s125,100 150,0" segment = SVGPathSegment('s', 125, 100, 150, 0) self.assertTrue(segment.isvalid()) self.assertTrue(not segment.isabsolute()) self.assertTrue(segment.isrelative()) self.assertEqual((125, 100, 150, 0), segment.values) self.assertEqual((150, 0), segment.end) d = segment.tostring() expected = 's125,100 150,0' self.assertEqual(expected, d) segment = SVGPathSegment() segment.set_smooth_curveto_rel(125, 100, 150, 0) self.assertTrue(segment.isvalid()) self.assertTrue(not segment.isabsolute()) self.assertTrue(segment.isrelative()) self.assertEqual((125, 100, 150, 0), segment.values) self.assertEqual((150, 0), segment.end) d = segment.tostring() expected = 's125,100 150,0' self.assertEqual(expected, d) segment2 = PathSegment.toabsolute(segment, 750, 800, 0) d = segment2.tostring() expected = 'S875,900 900,800' self.assertEqual(expected, d) segment2 = PathSegment.normalize(segment, 750, 800, 0)[0] d = segment2.tostring() expected = 'C750,800 875,900 900,800' self.assertEqual(expected, d) self.assertTrue(id(segment) != id(segment2)) # x1=750+750-725=775 # y1=800+800-700=900 segment2 = PathSegment.normalize(segment, 750, 800, 0, x1=775, y1=900)[0] d = segment2.tostring() expected = 'C775,900 875,900 900,800' self.assertEqual(expected, d) self.assertTrue(id(segment) != id(segment2))
def test_segment_bearing_abs(self): segment = SVGPathSegment('B') self.assertTrue(not segment.isvalid()) self.assertTrue(segment.isabsolute()) self.assertTrue(not segment.isrelative()) self.assertEqual((), segment.values) self.assertEqual((None, None), segment.end) exp = segment.tostring() self.assertEqual('', exp) segment = SVGPathSegment('B') bearing = segment.get_bearing(-90) self.assertEqual(-90, bearing) self.assertEqual((), segment.values) self.assertEqual((None, None), segment.end) segment = SVGPathSegment() segment.set_bearing_abs(-45) bearing = segment.get_bearing(-90) self.assertEqual(-45, bearing) self.assertEqual(segment.values, (-45,)) self.assertEqual((None, None), segment.end) segment = SVGPathSegment('B', 45) self.assertEqual((45,), segment.values) bearing = segment.get_bearing(-90) self.assertEqual(45, bearing) segment = SVGPathSegment('B', -45) exp = segment.tostring() self.assertEqual('B-45', exp)
def test_segment_smooth_quadratic_curveto_abs(self): segment = SVGPathSegment('T') self.assertTrue(not segment.isvalid()) self.assertTrue(segment.isabsolute()) self.assertTrue(not segment.isrelative()) self.assertEqual((), segment.values) self.assertEqual((None, None), segment.end) d = segment.tostring() self.assertEqual('', d) # "M200,300 Q400,50 600,300 T1000,300" # "T1000,300" segment = SVGPathSegment('T', 1000, 300) self.assertTrue(segment.isvalid()) self.assertTrue(segment.isabsolute()) self.assertTrue(not segment.isrelative()) self.assertEqual((1000, 300), segment.values) self.assertEqual((1000, 300), segment.end) d = segment.tostring() self.assertEqual('T1000,300', d) segment = SVGPathSegment() segment.set_smooth_quadratic_curveto_abs(1000, 300) self.assertTrue(segment.isvalid()) self.assertTrue(segment.isabsolute()) self.assertTrue(not segment.isrelative()) self.assertEqual((1000, 300), segment.values) self.assertEqual((1000, 300), segment.end) d = segment.tostring() self.assertEqual('T1000,300', d) # "M200,300" # "C333.333,133.333 466.667,133.333 600,300" # "C733.333,466.667 866.667,466.667 1000,300" # See test_quad02_path01_normalize() segment2 = PathSegment.normalize(segment, 600, 300, 0)[0] d = segment2.tostring() expected = 'C600,300 733.333,300 1000,300' self.assertEqual(expected, d) self.assertTrue(id(segment) != id(segment2)) segment2 = PathSegment.normalize(segment, 600, 300, 0, x1=800, y1=550)[0] d = segment2.tostring() expected = 'C733.333,466.667 866.667,466.667 1000,300' self.assertEqual(expected, d) self.assertTrue(id(segment) != id(segment2))
def test_segment_null(self): segment = SVGPathSegment() self.assertTrue(not segment.isvalid()) self.assertIsNone(segment.type) self.assertIsNone(segment.isabsolute()) self.assertIsNone(segment.isrelative()) self.assertEqual((), segment.values) self.assertEqual((None, None), segment.end)
def test_segment_quadratic_curveto_rel(self): # See also: quad01.html segment = SVGPathSegment('q') self.assertTrue(not segment.isvalid()) self.assertTrue(not segment.isabsolute()) self.assertTrue(segment.isrelative()) self.assertEqual((), segment.values) self.assertEqual((None, None), segment.end) d = segment.tostring() self.assertEqual('', d) # "M200,300 Q400,50 600,300 T1000,300 1400,300" # "m200,300 q200,-250 400,0 t400,0 400,0" segment = SVGPathSegment('q', 200, -250, 400, 0) self.assertTrue(segment.isvalid()) self.assertTrue(not segment.isabsolute()) self.assertTrue(segment.isrelative()) self.assertEqual((200, -250, 400, 0), segment.values) self.assertEqual((400, 0), segment.end) d = segment.tostring() expected = 'q200,-250 400,0' self.assertEqual(expected, d) segment = SVGPathSegment() segment.set_quadratic_curveto_rel(200, -250, 400, 0) self.assertTrue(segment.isvalid()) self.assertTrue(not segment.isabsolute()) self.assertTrue(segment.isrelative()) self.assertEqual((200, -250, 400, 0), segment.values) self.assertEqual((400, 0), segment.end) d = segment.tostring() expected = 'q200,-250 400,0' self.assertEqual(expected, d) segment2 = PathSegment.toabsolute(segment, 200, 300, 0) d = segment2.tostring() expected = 'Q400,50 600,300' self.assertEqual(expected, d) self.assertTrue(id(segment) != id(segment2)) segment2 = PathSegment.normalize(segment, 200, 300, 0)[0] d = segment2.tostring() expected = 'C333.333,133.333 466.667,133.333 600,300' self.assertEqual(expected, d) self.assertTrue(id(segment) != id(segment2))
def test_segment_curveto_rel(self): # See also: cubic02_01.html segment = SVGPathSegment('c') self.assertTrue(not segment.isvalid()) self.assertTrue(not segment.isabsolute()) self.assertTrue(segment.isrelative()) self.assertEqual((), segment.values) self.assertEqual((None, None), segment.end) d = segment.tostring() self.assertEqual('', d) # "m600,800 c25,-100 125,-100 150,0 s125,100 150,0" segment = SVGPathSegment('c', 25, -100, 125, -100, 150, 0) self.assertTrue(segment.isvalid()) self.assertTrue(not segment.isabsolute()) self.assertTrue(segment.isrelative()) self.assertEqual((25, -100, 125, -100, 150, 0), segment.values) self.assertEqual((150, 0), segment.end) d = segment.tostring() expected = 'c25,-100 125,-100 150,0' self.assertEqual(expected, d) segment = SVGPathSegment() segment.set_curveto_rel(25, -100, 125, -100, 150, 0) self.assertTrue(segment.isvalid()) self.assertTrue(not segment.isabsolute()) self.assertTrue(segment.isrelative()) self.assertEqual((25, -100, 125, -100, 150, 0), segment.values) self.assertEqual((150, 0), segment.end) d = segment.tostring() expected = 'c25,-100 125,-100 150,0' self.assertEqual(expected, d) segment2 = PathSegment.toabsolute(segment, 600, 800, 0) d = segment2.tostring() expected = 'C625,700 725,700 750,800' self.assertEqual(expected, d) self.assertTrue(id(segment) != id(segment2)) segment2 = PathSegment.normalize(segment, 600, 800, 0)[0] d = segment2.tostring() expected = 'C625,700 725,700 750,800' self.assertEqual(expected, d) self.assertTrue(id(segment) != id(segment2))
def test_segment_curveto_abs(self): # See also: cubic01.html segment = SVGPathSegment('C') self.assertTrue(not segment.isvalid()) self.assertTrue(segment.isabsolute()) self.assertTrue(not segment.isrelative()) self.assertEqual((), segment.values) self.assertEqual((None, None), segment.end) d = segment.tostring() self.assertEqual('', d) # "M100,200 C100,100 250,100 250,200 S400,300 400,200" # "C100,100 250,100 250,200" segment = SVGPathSegment('C', 100, 100, 250, 100, 250, 200) self.assertTrue(segment.isvalid()) self.assertTrue(segment.isabsolute()) self.assertTrue(not segment.isrelative()) self.assertEqual((100, 100, 250, 100, 250, 200), segment.values) self.assertEqual((250, 200), segment.end) d = segment.tostring() expected = 'C100,100 250,100 250,200' self.assertEqual(expected, d) segment = SVGPathSegment() segment.set_curveto_abs(100, 100, 250, 100, 250, 200) self.assertTrue(segment.isvalid()) self.assertTrue(segment.isabsolute()) self.assertTrue(not segment.isrelative()) self.assertEqual((100, 100, 250, 100, 250, 200), segment.values) self.assertEqual((250, 200), segment.end) d = segment.tostring() expected = 'C100,100 250,100 250,200' self.assertEqual(expected, d) segment2 = PathSegment.normalize(segment, 100, 200, 0)[0] d = segment2.tostring() self.assertEqual(expected, d) self.assertTrue(id(segment) != id(segment2))
def test_segment_smooth_curveto_abs(self): segment = SVGPathSegment('S') self.assertTrue(not segment.isvalid()) self.assertTrue(segment.isabsolute()) self.assertTrue(not segment.isrelative()) self.assertEqual((), segment.values) self.assertEqual((None, None), segment.end) d = segment.tostring() self.assertEqual('', d) # "S400,300 400,200" segment = SVGPathSegment('S', 400, 300, 400, 200) self.assertTrue(segment.isvalid()) self.assertTrue(segment.isabsolute()) self.assertTrue(not segment.isrelative()) self.assertEqual((400, 300, 400, 200), segment.values) self.assertEqual((400, 200), segment.end) d = segment.tostring() expected = 'S400,300 400,200' self.assertEqual(expected, d) segment = SVGPathSegment() segment.set_smooth_curveto_abs(400, 300, 400, 200) self.assertTrue(segment.isvalid()) self.assertTrue(segment.isabsolute()) self.assertTrue(not segment.isrelative()) self.assertEqual((400, 300, 400, 200), segment.values) self.assertEqual((400, 200), segment.end) d = segment.tostring() expected = 'S400,300 400,200' self.assertEqual(expected, d) segment2 = PathSegment.normalize(segment, 250, 200, 0)[0] d = segment2.tostring() expected = 'C250,200 400,300 400,200' self.assertEqual(expected, d) self.assertTrue(id(segment) != id(segment2))