experimental test code for pdf+text
[PyX/mjg.git] / test / functional / test_connector.py
blob3fe7410a767ad12f8f5b663f2e1f973fa04a41ea
1 #!/usr/bin/env python
2 import sys; sys.path[:0] = ["../.."]
4 from pyx import *
5 from pyx.connector import *
8 startbox = box.polygon(corners=[[0,0], [1,0.2], [0.5,2]])
9 endbox = box.polygon(corners=[[10,3.8], [13,5.2], [12.5,4.0]])
11 def dotest(c, x, y, test):
12 c2 = c.insert(canvas.canvas([trafo.translate(x, y)]))
13 c2.stroke(startbox.path())
14 c2.stroke(endbox.path())
15 c2.stroke(path.circle( unit.pt * startbox.center[0], unit.pt * startbox.center[1], 0.1))
16 c2.stroke(path.circle( unit.pt * endbox.center[0], unit.pt * endbox.center[1], 0.1))
17 eval("%s(c2)" % test)
18 c.insert(c2)
21 def testline(c):
22 l = line(startbox, endbox)
23 c.stroke(l, [style.linewidth.THICK, color.rgb.red, deco.earrow.normal])
25 l = line(endbox, startbox, boxdists=[1,0])
26 c.stroke(l, [color.rgb.blue, deco.earrow.normal])
29 def testarc(c):
30 l = arc(endbox, startbox, boxdists=1)
31 c.stroke(l, [color.rgb.blue, deco.earrow.normal])
33 for a in [-135, -90, 0.0001, 45, 90]:
34 l = arc(startbox, endbox, relangle=a, boxdists=1)
35 c.stroke(l, [color.rgb.red, deco.earrow.normal])
37 for b in [-1.1, -0.4, 0.01, 0.5]:
38 l = arc(startbox, endbox, relbulge=b, boxdists=1)
39 c.stroke(l, [color.rgb.green, deco.earrow.normal])
41 l = arc(startbox, endbox, absbulge=5, relbulge=0, boxdists=1)
42 c.stroke(l, [color.rgb.blue, deco.earrow.normal])
45 def testcurve(c):
46 l = curve(endbox, startbox, boxdists=[1,0])
47 c.stroke(l, [color.rgb.blue, deco.earrow.normal])
49 for a in [ [ 90, 90, 1.0], \
50 [-90, 90, 1.0], \
51 [ 90, -90, 1.0], \
52 [-90, 0, 1.0], \
53 [ 20, 20, 2.0] ]:
54 l = curve(startbox, endbox, boxdists=0.8,
55 relangle1=a[0], relangle2=a[1], relbulge=a[2])
56 c.stroke(l, [color.rgb.red, deco.earrow.normal])
58 for a in [ [ 90, 90, 1.0], \
59 [-90, 90, 1.0] ]:
60 l = curve(startbox, endbox, boxdists=0.8,
61 absangle1=a[0], absangle2=a[1], relbulge=a[2])
62 c.stroke(l, [color.rgb.green, deco.earrow.normal])
65 def testtwolines(c):
66 l = twolines(endbox, startbox, relangle1=45, relangle2=45)
67 c.stroke(l, [color.rgb.blue, deco.earrow.normal])
69 for a in [ [0,90], [90,0] ]:
70 l = twolines(startbox, endbox, boxdists=0.8,
71 absangle1=a[0], absangle2=a[1])
72 c.stroke(l, [color.rgb.red, deco.earrow.normal])
74 for a in range(10,20,2):
75 l = twolines(startbox, endbox, boxdists=0.8,
76 absangle1=45, length2=a)
77 c.stroke(l, [color.rgb.green, deco.earrow.normal])
79 for a in range(5,20,2):
80 l = twolines(startbox, endbox, boxdists=0.8,
81 relangle1=45, length1=a)
82 c.stroke(l, [color.rgb.green, deco.earrow.normal])
85 c = canvas.canvas()
86 dotest(c, 0, 0, "testline")
87 dotest(c, 25, 0, "testarc")
88 dotest(c, 25,30, "testcurve")
89 dotest(c, 0,20, "testtwolines")
90 c.writeEPSfile("test_connector", paperformat="a4", rotated=0, fittosize=1)
91 c.writePDFfile("test_connector")