prevent double call of _cleanup, which harms usefiles (and is a bad idea in general)
[PyX.git] / test / functional / test_bbox.py
blob41242de99d143371b3f8389a55240cb2cf22c2ee
1 #!/usr/bin/env python
2 import sys; sys.path[:0] = ["../.."]
4 from pyx import *
5 from pyx.path import *
7 def bboxrect(cmd):
8 return cmd.bbox().rect()
10 def drawpathwbbox(c, p):
11 c.stroke(p, [color.rgb.red])
12 np = p.normpath()
13 c.stroke(np, [color.rgb.green, style.linestyle.dashed])
14 c.stroke(bboxrect(p))
16 def testarcbbox(c):
17 for phi in range(0,360,30):
18 drawpathwbbox(c,path(arc(phi*0.1, phi*0.1, 1, 0, phi)))
20 for phi in range(0,360,30):
21 drawpathwbbox(c,path(arc(phi*0.1, 5+phi*0.1, 1, phi, 360)))
23 for phi in range(0,360,30):
24 drawpathwbbox(c,path(arc(phi*0.1, 10+phi*0.1, 1, phi, phi+30)))
26 for phi in range(0,360,30):
27 drawpathwbbox(c,path(arc(phi*0.1, 15+phi*0.1, 1, phi, phi+120)))
29 for phi in range(0,360,30):
30 drawpathwbbox(c,path(arc(phi*0.1, 20+phi*0.1, 1, phi, phi+210)))
32 for phi in range(0,360,30):
33 drawpathwbbox(c,path(arc(phi*0.1, 25+phi*0.1, 1, phi, phi+300)))
35 for phi in range(0,360,30):
36 drawpathwbbox(c,path(arc(phi*0.1, 30+phi*0.1, 1, phi, phi+390)))
39 for phi in range(0,360,30):
40 drawpathwbbox(c,path(moveto(20+phi*0.1, phi*0.09),
41 arc(20+phi*0.1, phi*0.1, 1, 0, phi)))
43 for phi in range(0,360,30):
44 drawpathwbbox(c,path(moveto(20+phi*0.1, 5+phi*0.11),
45 arc(20+phi*0.1, 5+phi*0.1, 1, 0, phi)))
47 for phi in range(0,360,30):
48 drawpathwbbox(c,path(moveto(20+phi*0.1, 10+phi*0.09),
49 arcn(20+phi*0.1, 10+phi*0.1, 1, 0, phi)))
51 for phi in range(0,360,30):
52 drawpathwbbox(c,path(moveto(20+phi*0.1, 15+phi*0.11),
53 arcn(20+phi*0.1, 15+phi*0.1, 1, 0, phi)))
55 for phi in range(0,360,30):
56 drawpathwbbox(c,path(moveto(50+phi*0.1, phi*0.09),
57 arc(50+phi*0.1, phi*0.1, 1, 0, phi),
58 rlineto(1,1)))
60 for phi in range(0,360,30):
61 drawpathwbbox(c,path(moveto(50+phi*0.1, 5+phi*0.11),
62 arc(50+phi*0.1, 5+phi*0.1, 1, 0, phi),
63 rlineto(1,1)))
65 for phi in range(0,360,30):
66 drawpathwbbox(c,path(moveto(50+phi*0.1, 10+phi*0.09),
67 arcn(50+phi*0.1, 10+phi*0.1, 1, 0, phi),
68 rlineto(1,1)))
70 for phi in range(0,360,30):
71 drawpathwbbox(c,path(moveto(50+phi*0.1, 15+phi*0.11),
72 arcn(50+phi*0.1, 15+phi*0.1, 1, 0, phi),
73 rlineto(1,1)))
76 def testcurvetobbox(c):
77 drawpathwbbox(c,path(moveto(10,60), curveto(12,66,14,65,12,69)))
80 def testtrafobbox(c):
81 sc=c.insert(canvas.canvas([trafo.translate(0,40).rotated(10)]))
83 p=path(moveto(10,10), curveto(12,16,14,15,12,19)); drawpathwbbox(sc,p)
84 p=path(moveto(5,17), curveto(6,18, 5,16, 7,15)); drawpathwbbox(sc,p)
87 def testclipbbox(c):
88 clip = canvas.clip(rect(11,-9,10,5))
90 p1 = path(moveto(10,-10), curveto(12,-4, 14,-5, 12,-1));
91 p2 = path(moveto(12,-8), curveto(6,-2, 5,-4, 7,-5));
93 # just a simple test for clipping
94 sc = c.insert(canvas.canvas([clip]))
95 drawpathwbbox(sc, p1)
96 drawpathwbbox(sc, p2)
98 # more complicated operations
100 # 1. transformation followed by clipping:
101 # in this case, the clipping path will be evaluated in the
102 # context of the already transformed canvas, so that the
103 # actually displayed portion of the path should be the same
104 sc = c.insert(canvas.canvas([trafo.translate(5,0), clip]))
105 drawpathwbbox(sc, p1)
106 drawpathwbbox(sc, p2)
108 # 2. clipping followed by transformation
109 # in this case, the clipping path will not be transformed, so
110 # that the display portionof the path should change
111 sc = c.insert(canvas.canvas([clip, trafo.translate(1,1)]))
112 drawpathwbbox(sc, p1)
113 drawpathwbbox(sc, p2)
116 c = canvas.canvas()
117 testarcbbox(c)
118 testcurvetobbox(c)
119 testtrafobbox(c)
120 testclipbbox(c)
121 c.writeEPSfile("test_bbox", page_paperformat=document.paperformat.A4, page_rotated=1, page_fittosize=1)
122 c.writePDFfile("test_bbox")
123 c.writeSVGfile("test_bbox")