-
Notifications
You must be signed in to change notification settings - Fork 12
/
test_pyganja.py
173 lines (137 loc) · 6.69 KB
/
test_pyganja.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
import unittest
from pyganja import *
class TestCEFDrawing(unittest.TestCase):
def test_draw_lines(self):
from clifford.tools.g3c import random_line
draw([random_line() for i in range(10)], static=True, color=Color.RED)
def test_print_scene(self):
from clifford.tools.g3c import random_line
gs = GanjaScene()
gs.add_objects([random_line() for i in range(2)])
print(gs)
class TestCGADrawing(unittest.TestCase):
def test_pyganja_facet(self):
from clifford.tools.g3c import random_conformal_point
from pyganja import GanjaScene
gs = GanjaScene()
point_list = [random_conformal_point() for i in range(3)]
#gs.add_objects(point_list)
gs.add_facet(point_list)
point_list = [random_conformal_point() for i in range(3)]
#gs.add_objects(point_list)
#gs.add_facet(point_list,color=int('AAFF0000',16))
facet_list = [[random_conformal_point() for i in range(3)] for i in range(10)]
#gs.add_facets(facet_list,color=int('AA0000FF',16))
draw(gs, scale=0.05, browser_window=True)
print(gs)
class TestG3Drawing(unittest.TestCase):
def test_draw_points(self):
from clifford.tools.g3 import random_euc_mv
from clifford.g3 import layout
gs = GanjaScene()
gs.add_objects([random_euc_mv().value[0:8] for i in range(10)], static=False)
with open('test_file.html', 'w') as test_file:
test_file.write(generate_full_html(str(gs), sig=layout.sig, grid=True, scale=1.0, gl=True))
render_cef_script(str(gs), sig=layout.sig, grid=True, scale=1.0, gl=False)
class TestPGA3DDrawing(unittest.TestCase):
def setUp(self):
from clifford.pga import layout, blades
self.layout = layout
self.blades = blades
def random_point(self):
import numpy as np
return self.blades["e123"] + sum(
c * self.blades[b] for c, b in zip(np.random.randn(3), ["e023", "e013", "e012"]))
def test_draw_points(self):
gs = GanjaScene()
gs.add_objects([self.random_point() for i in range(10)], static=False)
with open('test_file.html', 'w') as test_file:
test_file.write(generate_full_html(str(gs), sig=self.layout.sig, grid=True, scale=1.0, gl=True))
draw(gs, sig=self.layout.sig, grid=True, scale=1.0, gl=True)
def test_draw_lines(self):
def random_line():
return (self.random_point().dual()^self.random_point().dual()).dual()
gs = GanjaScene()
gs.add_objects([random_line() for i in range(10)], static=False)
with open('test_file.html', 'w') as test_file:
test_file.write(generate_full_html(str(gs), sig=self.layout.sig, grid=True, scale=1.0, gl=True))
draw(gs, sig=self.layout.sig, grid=True, scale=1.0, gl=True)
def test_draw_planes(self):
gs = GanjaScene()
gs.add_objects([self.random_point().dual() for i in range(10)], static=False)
with open('test_file.html', 'w') as test_file:
test_file.write(generate_full_html(str(gs), sig=self.layout.sig, grid=True, scale=1.0, gl=True))
draw(gs, sig=self.layout.sig, grid=True, scale=1.0, gl=True)
class TestPGA2DDrawing(unittest.TestCase):
def setUp(self):
from clifford import Cl
layout, blades = Cl(2, 0, 1, firstIdx=0)
self.layout = layout
self.blades = blades
def random_point(self):
import numpy as np
return sum(c * self.blades[b] + self.blades['e0'] for c, b in zip(np.random.randn(2), ["e1", "e2"])).dual()
def test_draw_points(self):
gs = GanjaScene()
gs.add_objects([self.random_point() for i in range(10)], static=False)
print(self.random_point())
with open('test_file.html', 'w') as test_file:
test_file.write(generate_full_html(str(gs), sig=self.layout.sig, grid=True, scale=1.0, gl=False))
draw(gs, sig=self.layout.sig, grid=True, scale=1.0, gl=False)
def test_draw_lines(self):
def random_line():
return (self.random_point().dual()^self.random_point().dual()).dual()
gs = GanjaScene()
gs.add_objects([random_line() for i in range(10)], static=False)
with open('test_file.html', 'w') as test_file:
test_file.write(generate_full_html(str(gs), sig=self.layout.sig, grid=True, scale=1.0, gl=False))
draw(gs, sig=self.layout.sig, grid=True, scale=1.0, gl=False)
class TestCGA2DDrawing(unittest.TestCase):
def setUp(self):
from clifford.g2c import layout, blades, einf, up
self.layout = layout
self.blades = blades
self.einf = einf
self.up = up
def random_point(self):
import numpy as np
return self.up(sum(c * self.blades[b] for c, b in zip(np.random.randn(2), ["e1", "e2"])))
def test_draw_points(self):
gs = GanjaScene()
gs.add_objects([self.random_point() for i in range(10)], static=False)
print(self.random_point())
with open('test_file.html', 'w') as test_file:
test_file.write(generate_full_html(str(gs), sig=self.layout.sig, grid=True, scale=1.0))
draw(gs, sig=self.layout.sig, grid=True, scale=1.0)
def test_draw_lines(self):
def random_line():
return self.random_point()^self.random_point()^self.einf
gs = GanjaScene()
gs.add_objects([random_line() for i in range(10)], static=False)
with open('test_file.html', 'w') as test_file:
test_file.write(generate_full_html(str(gs), sig=self.layout.sig, grid=True, scale=1.0))
draw(gs, sig=self.layout.sig, grid=True, scale=1.0)
def test_draw_circles(self):
def random_circle():
return self.random_point()^self.random_point()^self.random_point()
gs = GanjaScene()
gs.add_objects([random_circle() for i in range(10)], static=False)
with open('test_file.html', 'w') as test_file:
test_file.write(generate_full_html(str(gs), sig=self.layout.sig, grid=True, scale=1.0))
draw(gs, sig=self.layout.sig, grid=True, scale=1.0)
class TestGanjaSceneOps(unittest.TestCase):
def test_scene_addition(self):
from clifford.tools.g3c import random_line, random_circle
a = GanjaScene()
a.add_objects([random_line() for i in range(10)], color=Color.RED)
b = GanjaScene()
b.add_objects([random_circle() for i in range(10)], color=Color.BLUE)
draw(a + b, scale=0.01)
class TestPGADrawing(unittest.TestCase):
def test_draw_lines(self):
from clifford.pga import layout, blades
p = 0.5*blades['e1'] + 0.5*blades['e2'] + 1.0*blades['e0']
print(p)
draw([p], sig=layout.sig)
if __name__ == '__main__':
unittest.main()