/[escript]/trunk/pycad/test/python/run_pycad_test.py
ViewVC logotype

Contents of /trunk/pycad/test/python/run_pycad_test.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 932 - (show annotations)
Fri Jan 19 09:27:15 2007 UTC (14 years, 4 months ago) by gross
File MIME type: text/x-python
File size: 178219 byte(s)
Design added. The loops tests are switched off to allow faults.
1 # $Id: run_visualization_interface.py 798 2006-08-04 01:05:36Z gross $
2
3 __copyright__=""" Copyright (c) 2006 by ACcESS MNRF
4 http://www.access.edu.au
5 Primary Business: Queensland, Australia"""
6 __license__="""Licensed under the Open Software License version 3.0
7 http://www.opensource.org/licenses/osl-3.0.php"""
8
9 import os
10 import sys
11 import unittest
12 import math
13 import numarray
14 from esys.pycad import *
15
16 try:
17 PYCAD_TEST_DATA=os.environ['PYCAD_TEST_DATA']
18 except KeyError:
19 PYCAD_TEST_DATA='.'
20
21 try:
22 PYCAD_WORKDIR=os.environ['PYCAD_WORKDIR']
23 except KeyError:
24 PYCAD_WORKDIR='.'
25
26 PYCAD_TEST_MESH_PATH=PYCAD_TEST_DATA+"/data_meshes/"
27 PYCAD_WORKDIR_PATH=PYCAD_WORKDIR+"/"
28
29 def _cross(x, y):
30 return numarray.array([x[1] * y[2] - x[2] * y[1], x[2] * y[0] - x[0] * y[2], x[0] * y[1] - x[1] * y[0]])
31
32
33 class Test_PyCAD_Transformations(unittest.TestCase):
34 ABS_TOL=1.e-8
35 def __distance(self,x,y):
36 return math.sqrt(numarray.dot(x-y,x-y))
37 def test_Translation_x(self):
38 t=Translation([1,0,0])
39 s0=t([1,0,0])
40 self.failUnless(isinstance(s0,numarray.NumArray),"s0 is not a numarray object.")
41 self.failUnless(self.__distance(s0,numarray.array([2,0,0]))<self.ABS_TOL,"s0 is wrong.")
42 s1=t([0,1,0])
43 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
44 self.failUnless(self.__distance(s1,numarray.array([1,1,0]))<self.ABS_TOL,"s1 is wrong.")
45 s2=t([0,0,1])
46 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
47 self.failUnless(self.__distance(s2,numarray.array([1,0,1]))<self.ABS_TOL,"s2 is wrong.")
48 def test_Translation_y(self):
49 t=Translation([0,1,0])
50 s0=t([1,0,0])
51 self.failUnless(isinstance(s0,numarray.NumArray),"s0 is not a numarray object.")
52 self.failUnless(self.__distance(s0,numarray.array([1,1,0]))<self.ABS_TOL,"s0 is wrong.")
53 s1=t([0,1,0])
54 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
55 self.failUnless(self.__distance(s1,numarray.array([0,2,0]))<self.ABS_TOL,"s1 is wrong.")
56 s2=t([0,0,1])
57 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
58 self.failUnless(self.__distance(s2,numarray.array([0,1,1]))<self.ABS_TOL,"s2 is wrong.")
59 def test_Translation_z(self):
60 t=Translation([0,0,1])
61 s0=t([1,0,0])
62 self.failUnless(isinstance(s0,numarray.NumArray),"s0 is not a numarray object.")
63 self.failUnless(self.__distance(s0,numarray.array([1,0,1]))<self.ABS_TOL,"s0 is wrong.")
64 s1=t([0,1,0])
65 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
66 self.failUnless(self.__distance(s1,numarray.array([0,1,1]))<self.ABS_TOL,"s1 is wrong.")
67 s2=t([0,0,1])
68 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
69 self.failUnless(self.__distance(s2,numarray.array([0,0,2]))<self.ABS_TOL,"s2 is wrong.")
70 def test_Dilation_0_two(self):
71 t=Dilation(2.)
72 s0=t([1,0,0])
73 self.failUnless(isinstance(s0,numarray.NumArray),"s0 is not a numarray object.")
74 self.failUnless(self.__distance(s0,numarray.array([2,0,0]))<self.ABS_TOL,"s0 is wrong.")
75 s1=t([0,1,0])
76 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
77 self.failUnless(self.__distance(s1,numarray.array([0,2,0]))<self.ABS_TOL,"s1 is wrong.")
78 s2=t([0,0,1])
79 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
80 self.failUnless(self.__distance(s2,numarray.array([0,0,2]))<self.ABS_TOL,"s2 is wrong.")
81 def test_Dilation_0_half(self):
82 t=Dilation(0.5)
83 s0=t([1,0,0])
84 self.failUnless(isinstance(s0,numarray.NumArray),"s0 is not a numarray object.")
85 self.failUnless(self.__distance(s0,numarray.array([0.5,0,0]))<self.ABS_TOL,"s0 is wrong.")
86 s1=t([0,1,0])
87 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
88 self.failUnless(self.__distance(s1,numarray.array([0,0.5,0]))<self.ABS_TOL,"s1 is wrong.")
89 s2=t([0,0,1])
90 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
91 self.failUnless(self.__distance(s2,numarray.array([0,0,0.5]))<self.ABS_TOL,"s2 is wrong.")
92 def test_Dilation_x_two(self):
93 t=Dilation(2.,[1.,0.,0.])
94 s0=t([1,0,0])
95 self.failUnless(isinstance(s0,numarray.NumArray),"s0 is not a numarray object.")
96 self.failUnless(self.__distance(s0,numarray.array([1,0,0]))<self.ABS_TOL,"s0 is wrong.")
97 s0_1=t([0,0,0])
98 self.failUnless(isinstance(s0_1,numarray.NumArray),"s0_1 is not a numarray object.")
99 self.failUnless(self.__distance(s0_1,numarray.array([-1.,0,0]))<self.ABS_TOL,"s0_1 is wrong.")
100 s1=t([0,1,0])
101 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
102 self.failUnless(self.__distance(s1,numarray.array([-1,2,0]))<self.ABS_TOL,"s1 is wrong.")
103 s2=t([0,0,1])
104 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
105 self.failUnless(self.__distance(s2,numarray.array([-1.,0,2]))<self.ABS_TOL,"s2 is wrong.")
106 def test_Dilation_x_half(self):
107 t=Dilation(0.5,[1.,0.,0.])
108 s0=t([1,0,0])
109 self.failUnless(isinstance(s0,numarray.NumArray),"s0 is not a numarray object.")
110 self.failUnless(self.__distance(s0,numarray.array([1.,0,0]))<self.ABS_TOL,"s0 is wrong.")
111 s0_1=t([0,0,0])
112 self.failUnless(isinstance(s0_1,numarray.NumArray),"s0_1 is not a numarray object.")
113 self.failUnless(self.__distance(s0_1,numarray.array([.5,0,0]))<self.ABS_TOL,"s0_1 is wrong.")
114 s1=t([0,1,0])
115 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
116 self.failUnless(self.__distance(s1,numarray.array([0.5,0.5,0]))<self.ABS_TOL,"s1 is wrong.")
117 s2=t([0,0,1])
118 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
119 self.failUnless(self.__distance(s2,numarray.array([0.5,0,0.5]))<self.ABS_TOL,"s2 is wrong.")
120 def test_Dilation_y_two(self):
121 t=Dilation(2.,[0.,1.,0.])
122 s0=t([1,0,0])
123 self.failUnless(isinstance(s0,numarray.NumArray),"s0 is not a numarray object.")
124 self.failUnless(self.__distance(s0,numarray.array([2.,-1.,0]))<self.ABS_TOL,"s0 is wrong.")
125 s1_1=t([0,0,0])
126 self.failUnless(isinstance(s1_1,numarray.NumArray),"s1_1 is not a numarray object.")
127 self.failUnless(self.__distance(s1_1,numarray.array([0.,-1.,0]))<self.ABS_TOL,"s1_1 is wrong.")
128 s1=t([0,1,0])
129 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
130 self.failUnless(self.__distance(s1,numarray.array([0.,1.,0]))<self.ABS_TOL,"s1 is wrong.")
131 s2=t([0,0,1])
132 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
133 self.failUnless(self.__distance(s2,numarray.array([0.,-1.,2]))<self.ABS_TOL,"s2 is wrong.")
134 def test_Dilation_y_half(self):
135 t=Dilation(0.5,[0.,1.,0.])
136 s0=t([1,0,0])
137 self.failUnless(isinstance(s0,numarray.NumArray),"s0 is not a numarray object.")
138 self.failUnless(self.__distance(s0,numarray.array([0.5,0.5,0]))<self.ABS_TOL,"s0 is wrong.")
139 s1_1=t([0,0,0])
140 self.failUnless(isinstance(s1_1,numarray.NumArray),"s1_1 is not a numarray object.")
141 self.failUnless(self.__distance(s1_1,numarray.array([0,0.5,0]))<self.ABS_TOL,"s1_1 is wrong.")
142 s1=t([0,1,0])
143 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
144 self.failUnless(self.__distance(s1,numarray.array([0.,1.,0]))<self.ABS_TOL,"s1 is wrong.")
145 s2=t([0,0,1])
146 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
147 self.failUnless(self.__distance(s2,numarray.array([0.,0.5,0.5]))<self.ABS_TOL,"s2 is wrong.")
148 def test_Dilation_z_two(self):
149 t=Dilation(2.,[0.,0.,1.])
150 s0=t([1,0,0])
151 self.failUnless(isinstance(s0,numarray.NumArray),"s0 is not a numarray object.")
152 self.failUnless(self.__distance(s0,numarray.array([2.,0.,-1.]))<self.ABS_TOL,"s0 is wrong.")
153 s2_1=t([0,0,0])
154 self.failUnless(isinstance(s2_1,numarray.NumArray),"s2_1 is not a numarray object.")
155 self.failUnless(self.__distance(s2_1,numarray.array([0.,0.,-1.]))<self.ABS_TOL,"s2_1 is wrong.")
156 s1=t([0,1,0])
157 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
158 self.failUnless(self.__distance(s1,numarray.array([0.,2.,-1.]))<self.ABS_TOL,"s1 is wrong.")
159 s2=t([0,0,1])
160 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
161 self.failUnless(self.__distance(s2,numarray.array([0.,0.,1.]))<self.ABS_TOL,"s2 is wrong.")
162 def test_Dilation_z_half(self):
163 t=Dilation(0.5,[0.,0.,1.])
164 s0=t([1,0,0])
165 self.failUnless(isinstance(s0,numarray.NumArray),"s0 is not a numarray object.")
166 self.failUnless(self.__distance(s0,numarray.array([0.5,0.,0.5]))<self.ABS_TOL,"s0 is wrong.")
167 s2_1=t([0,0,0])
168 self.failUnless(isinstance(s2_1,numarray.NumArray),"s2_1 is not a numarray object.")
169 self.failUnless(self.__distance(s2_1,numarray.array([0,0,0.5]))<self.ABS_TOL,"s2_1 is wrong.")
170 s1=t([0,1,0])
171 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
172 self.failUnless(self.__distance(s1,numarray.array([0.,0.5,0.5]))<self.ABS_TOL,"s1 is wrong.")
173 s2=t([0,0,1])
174 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
175 self.failUnless(self.__distance(s2,numarray.array([0.,0.,1.]))<self.ABS_TOL,"s2 is wrong.")
176 def test_Reflection_x_offset0(self):
177 t=Reflection([1.,0.,0.])
178 s0=t([1,0,0])
179 self.failUnless(isinstance(s0,numarray.NumArray),"s0 is not a numarray object.")
180 self.failUnless(self.__distance(s0,numarray.array([-1.,0,0.]))<self.ABS_TOL,"s0 is wrong.")
181 s1=t([0,1,0])
182 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
183 self.failUnless(self.__distance(s1,numarray.array([0,1,0]))<self.ABS_TOL,"s1 is wrong.")
184 s2=t([0,0,1])
185 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
186 self.failUnless(self.__distance(s2,numarray.array([0,0,1]))<self.ABS_TOL,"s2 is wrong.")
187 s=t([1,2,3])
188 self.failUnless(isinstance(s,numarray.NumArray),"s is not a numarray object.")
189 self.failUnless(self.__distance(s,numarray.array([-1.,2,3]))<self.ABS_TOL,"s is wrong.")
190 def test_Reflection_x_offset2(self):
191 t=Reflection([-2.,0.,0.],offset=-4)
192 s0=t([1,0,0])
193 self.failUnless(isinstance(s0,numarray.NumArray),"s0 is not a numarray object.")
194 self.failUnless(self.__distance(s0,numarray.array([3.,0,0.]))<self.ABS_TOL,"s0 is wrong.")
195 s1=t([0,1,0])
196 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
197 self.failUnless(self.__distance(s1,numarray.array([4,1,0]))<self.ABS_TOL,"s1 is wrong.")
198 s2=t([0,0,1])
199 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
200 self.failUnless(self.__distance(s2,numarray.array([4,0,1]))<self.ABS_TOL,"s2 is wrong.")
201 s=t([1,2,3])
202 self.failUnless(isinstance(s,numarray.NumArray),"s is not a numarray object.")
203 self.failUnless(self.__distance(s,numarray.array([3.,2,3]))<self.ABS_TOL,"s is wrong.")
204 def test_Reflection_x_offset2_vector(self):
205 t=Reflection([1.,0.,0.],offset=[2,0,0])
206 s0=t([1,0,0])
207 self.failUnless(isinstance(s0,numarray.NumArray),"s0 is not a numarray object.")
208 self.failUnless(self.__distance(s0,numarray.array([3.,0,0.]))<self.ABS_TOL,"s0 is wrong.")
209 s1=t([0,1,0])
210 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
211 self.failUnless(self.__distance(s1,numarray.array([4,1,0]))<self.ABS_TOL,"s1 is wrong.")
212 s2=t([0,0,1])
213 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
214 self.failUnless(self.__distance(s2,numarray.array([4,0,1]))<self.ABS_TOL,"s2 is wrong.")
215 s=t([1,2,3])
216 self.failUnless(isinstance(s,numarray.NumArray),"s is not a numarray object.")
217 self.failUnless(self.__distance(s,numarray.array([3.,2,3]))<self.ABS_TOL,"s is wrong.")
218 def test_Reflection_y_offset0(self):
219 t=Reflection([0.,1.,0.])
220 s0=t([1,0,0])
221 self.failUnless(isinstance(s0,numarray.NumArray),"s0 is not a numarray object.")
222 self.failUnless(self.__distance(s0,numarray.array([1.,0,0.]))<self.ABS_TOL,"s0 is wrong.")
223 s1=t([0,1,0])
224 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
225 self.failUnless(self.__distance(s1,numarray.array([0,-1,0]))<self.ABS_TOL,"s1 is wrong.")
226 s2=t([0,0,1])
227 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
228 self.failUnless(self.__distance(s2,numarray.array([0,0,1]))<self.ABS_TOL,"s2 is wrong.")
229 s=t([1,2,3])
230 self.failUnless(isinstance(s,numarray.NumArray),"s is not a numarray object.")
231 self.failUnless(self.__distance(s,numarray.array([1.,-2,3]))<self.ABS_TOL,"s is wrong.")
232 def test_Reflection_y_offset2(self):
233 t=Reflection([0.,-2.,0.],offset=-4)
234 s0=t([1,0,0])
235 self.failUnless(isinstance(s0,numarray.NumArray),"s0 is not a numarray object.")
236 self.failUnless(self.__distance(s0,numarray.array([1.,4,0.]))<self.ABS_TOL,"s0 is wrong.")
237 s1=t([0,1,0])
238 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
239 self.failUnless(self.__distance(s1,numarray.array([0,3,0]))<self.ABS_TOL,"s1 is wrong.")
240 s2=t([0,0,1])
241 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
242 self.failUnless(self.__distance(s2,numarray.array([0,4,1]))<self.ABS_TOL,"s2 is wrong.")
243 s=t([1,2,3])
244 self.failUnless(isinstance(s,numarray.NumArray),"s is not a numarray object.")
245 self.failUnless(self.__distance(s,numarray.array([1.,2,3]))<self.ABS_TOL,"s is wrong.")
246 def test_Reflection_y_offset2_vector(self):
247 t=Reflection([0.,1.,0.],offset=[0,2,0])
248 s0=t([1,0,0])
249 self.failUnless(isinstance(s0,numarray.NumArray),"s0 is not a numarray object.")
250 self.failUnless(self.__distance(s0,numarray.array([1.,4,0.]))<self.ABS_TOL,"s0 is wrong.")
251 s1=t([0,1,0])
252 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
253 self.failUnless(self.__distance(s1,numarray.array([0,3,0]))<self.ABS_TOL,"s1 is wrong.")
254 s2=t([0,0,1])
255 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
256 self.failUnless(self.__distance(s2,numarray.array([0,4,1]))<self.ABS_TOL,"s2 is wrong.")
257 s=t([1,2,3])
258 self.failUnless(isinstance(s,numarray.NumArray),"s is not a numarray object.")
259 self.failUnless(self.__distance(s,numarray.array([1.,2,3]))<self.ABS_TOL,"s is wrong.")
260 def test_Reflection_z_offset0(self):
261 t=Reflection([0.,0.,1.])
262 s0=t([1,0,0])
263 self.failUnless(isinstance(s0,numarray.NumArray),"s0 is not a numarray object.")
264 self.failUnless(self.__distance(s0,numarray.array([1.,0,0.]))<self.ABS_TOL,"s0 is wrong.")
265 s1=t([0,1,0])
266 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
267 self.failUnless(self.__distance(s1,numarray.array([0,1,0]))<self.ABS_TOL,"s1 is wrong.")
268 s2=t([0,0,1])
269 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
270 self.failUnless(self.__distance(s2,numarray.array([0,0,-1]))<self.ABS_TOL,"s2 is wrong.")
271 s=t([1,2,3])
272 self.failUnless(isinstance(s,numarray.NumArray),"s is not a numarray object.")
273 self.failUnless(self.__distance(s,numarray.array([1.,2,-3]))<self.ABS_TOL,"s is wrong.")
274 def test_Reflection_z_offset2(self):
275 t=Reflection([0.,0.,-2.],offset=-4)
276 s0=t([1,0,0])
277 self.failUnless(isinstance(s0,numarray.NumArray),"s0 is not a numarray object.")
278 self.failUnless(self.__distance(s0,numarray.array([1.,0,4.]))<self.ABS_TOL,"s0 is wrong.")
279 s1=t([0,1,0])
280 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
281 self.failUnless(self.__distance(s1,numarray.array([0,1,4]))<self.ABS_TOL,"s1 is wrong.")
282 s2=t([0,0,1])
283 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
284 self.failUnless(self.__distance(s2,numarray.array([0,0,3]))<self.ABS_TOL,"s2 is wrong.")
285 s=t([1,2,3])
286 self.failUnless(isinstance(s,numarray.NumArray),"s is not a numarray object.")
287 self.failUnless(self.__distance(s,numarray.array([1.,2,1]))<self.ABS_TOL,"s is wrong.")
288 def test_Reflection_z_offset2_vector(self):
289 t=Reflection([0.,0.,1.],offset=[0,0,2])
290 s0=t([1,0,0])
291 self.failUnless(isinstance(s0,numarray.NumArray),"s0 is not a numarray object.")
292 self.failUnless(self.__distance(s0,numarray.array([1.,0,4.]))<self.ABS_TOL,"s0 is wrong.")
293 s1=t([0,1,0])
294 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
295 self.failUnless(self.__distance(s1,numarray.array([0,1,4]))<self.ABS_TOL,"s1 is wrong.")
296 s2=t([0,0,1])
297 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
298 self.failUnless(self.__distance(s2,numarray.array([0,0,3]))<self.ABS_TOL,"s2 is wrong.")
299 s=t([1,2,3])
300 self.failUnless(isinstance(s,numarray.NumArray),"s is not a numarray object.")
301 self.failUnless(self.__distance(s,numarray.array([1.,2,1]))<self.ABS_TOL,"s is wrong.")
302 def test_Rotatation_x_90_0(self):
303 t=Rotatation(axis=[1.,0.,0.],point=[1.,0.,0.],angle=90*DEG)
304 s0=t([1,0,0])
305 self.failUnless(isinstance(s0,numarray.NumArray),"s0 is not a numarray object.")
306 self.failUnless(self.__distance(s0,numarray.array([1.,0,0.]))<self.ABS_TOL,"s0 is wrong.")
307 s1=t([0,1,0])
308 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
309 self.failUnless(self.__distance(s1,numarray.array([0.,0,1.]))<self.ABS_TOL,"s1 is wrong.")
310 s2=t([0,0,1])
311 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
312 self.failUnless(self.__distance(s2,numarray.array([0.,-1.,0.]))<self.ABS_TOL,"s2 is wrong.")
313 def test_Rotatation_x_30_0(self):
314 t=Rotatation(axis=[1.,0.,0.],point=[1.,0.,0.],angle=30*DEG)
315 s0=t([1,0,0])
316 self.failUnless(isinstance(s0,numarray.NumArray),"s0 is not a numarray object.")
317 self.failUnless(self.__distance(s0,numarray.array([1.,0,0.]))<self.ABS_TOL,"s0 is wrong.")
318 s1=t([0,1,0])
319 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
320 self.failUnless(abs(numarray.dot(s1,s1)-1.)<self.ABS_TOL,"s1 length is wrong.")
321 self.failUnless(abs(s1[1]-math.cos(30*DEG))<self.ABS_TOL,"s1 angle is wrong.")
322 self.failUnless(numarray.dot(_cross(s1,[0,1,0]),numarray.array([1.,0.,0.]))<0.,"s1 has wrong orientation.")
323 s2=t([0,0,1])
324 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
325 self.failUnless(abs(numarray.dot(s2,s2)-1.)<self.ABS_TOL,"s2 length is wrong.")
326 self.failUnless(abs(s2[2]-math.cos(30*DEG))<self.ABS_TOL,"s2 angle is wrong.")
327 self.failUnless(numarray.dot(_cross(s2,[0,0,1]),numarray.array([1.,0.,0.]))<0.,"s2 has wrong orientation.")
328 def test_Rotatation_x_330_0(self):
329 t=Rotatation(axis=[1.,0.,0.],point=[1.,0.,0.],angle=330*DEG)
330 s0=t([1,0,0])
331 self.failUnless(isinstance(s0,numarray.NumArray),"s0 is not a numarray object.")
332 self.failUnless(self.__distance(s0,numarray.array([1.,0,0.]))<self.ABS_TOL,"s0 is wrong.")
333 s1=t([0,1,0])
334 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
335 self.failUnless(abs(numarray.dot(s1,s1)-1.)<self.ABS_TOL,"s1 length is wrong.")
336 self.failUnless(abs(s1[1]-math.cos(330*DEG))<self.ABS_TOL,"s1 angle is wrong.")
337 self.failUnless(numarray.dot(_cross(s1,[0,1,0]),numarray.array([1.,0.,0.]))>0.,"s1 has wrong orientation.")
338 s2=t([0,0,1])
339 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
340 self.failUnless(abs(numarray.dot(s2,s2)-1.)<self.ABS_TOL,"s2 length is wrong.")
341 self.failUnless(abs(s2[2]-math.cos(330*DEG))<self.ABS_TOL,"s2 angle is wrong.")
342 self.failUnless(numarray.dot(_cross(s2,[0,0,1]),numarray.array([1.,0.,0.]))>0.,"s2 has wrong orientation.")
343 def test_Rotatation_x_90(self):
344 t=Rotatation(axis=[-1.,0.,0.],point=[2.,0.,0.],angle=90*DEG)
345 s0=t([1,0,0])
346 self.failUnless(isinstance(s0,numarray.NumArray),"s0 is not a numarray object.")
347 self.failUnless(self.__distance(s0,numarray.array([1.,0,0.]))<self.ABS_TOL,"s0 is wrong.")
348 s1=t([0,1,0])
349 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
350 self.failUnless(self.__distance(s1,numarray.array([0.,0,-1.]))<self.ABS_TOL,"s1 is wrong.")
351 s2=t([0,0,1])
352 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
353 self.failUnless(self.__distance(s2,numarray.array([0.,1.,0.]))<self.ABS_TOL,"s2 is wrong.")
354 def test_Rotatation_x_30(self):
355 t=Rotatation(axis=[-1.,0.,0.],point=[1.,0.,0.],angle=30*DEG)
356 s0=t([1,0,0])
357 self.failUnless(isinstance(s0,numarray.NumArray),"s0 is not a numarray object.")
358 self.failUnless(self.__distance(s0,numarray.array([1.,0,0.]))<self.ABS_TOL,"s0 is wrong.")
359 s1=t([0,1,0])
360 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
361 self.failUnless(abs(numarray.dot(s1,s1)-1.)<self.ABS_TOL,"s1 length is wrong.")
362 self.failUnless(abs(s1[1]-math.cos(30*DEG))<self.ABS_TOL,"s1 angle is wrong.")
363 self.failUnless(numarray.dot(_cross(s1,[0,1,0]),numarray.array([-1.,0.,0.]))<0.,"s1 has wrong orientation.")
364 s2=t([0,0,1])
365 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
366 self.failUnless(abs(numarray.dot(s2,s2)-1.)<self.ABS_TOL,"s2 length is wrong.")
367 self.failUnless(abs(s2[2]-math.cos(30*DEG))<self.ABS_TOL,"s2 angle is wrong.")
368 self.failUnless(numarray.dot(_cross(s2,[0,0,1]),numarray.array([-1.,0.,0.]))<0.,"s2 has wrong orientation.")
369 def test_Rotatation_x_330(self):
370 t=Rotatation(axis=[-1.,0.,0.],point=[1.,0.,0.],angle=330*DEG)
371 s0=t([1,0,0])
372 self.failUnless(isinstance(s0,numarray.NumArray),"s0 is not a numarray object.")
373 self.failUnless(self.__distance(s0,numarray.array([1.,0,0.]))<self.ABS_TOL,"s0 is wrong.")
374 s1=t([0,1,0])
375 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
376 self.failUnless(abs(numarray.dot(s1,s1)-1.)<self.ABS_TOL,"s1 length is wrong.")
377 self.failUnless(abs(s1[1]-math.cos(330*DEG))<self.ABS_TOL,"s1 angle is wrong.")
378 self.failUnless(numarray.dot(_cross(s1,[0,1,0]),numarray.array([-1.,0.,0.]))>0.,"s1 has wrong orientation.")
379 s2=t([0,0,1])
380 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
381 self.failUnless(abs(numarray.dot(s2,s2)-1.)<self.ABS_TOL,"s2 length is wrong.")
382 self.failUnless(abs(s2[2]-math.cos(330*DEG))<self.ABS_TOL,"s2 angle is wrong.")
383 self.failUnless(numarray.dot(_cross(s2,[0,0,1]),numarray.array([-1.,0.,0.]))>0.,"s2 has wrong orientation.")
384 def test_Rotatation_y_90_0(self):
385 t=Rotatation(axis=[0.,1.,0.],point=[0.,1.,0.],angle=90*DEG)
386 s0=t([1,0,0])
387 self.failUnless(isinstance(s0,numarray.NumArray),"s0 is not a numarray object.")
388 self.failUnless(self.__distance(s0,numarray.array([0.,0,-1.]))<self.ABS_TOL,"s0 is wrong.")
389 s1=t([0,5,0])
390 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
391 self.failUnless(self.__distance(s1,numarray.array([0.,5,0.]))<self.ABS_TOL,"s1 is wrong.")
392 s2=t([0,0,1])
393 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
394 self.failUnless(self.__distance(s2,numarray.array([1,0.,0.]))<self.ABS_TOL,"s2 is wrong.")
395 def test_Rotatation_y_30_0(self):
396 t=Rotatation(axis=[0.,1.,0.],point=[0.,1.,0.],angle=30*DEG)
397 s0=t([1,0,0])
398 self.failUnless(isinstance(s0,numarray.NumArray),"s0 is not a numarray object.")
399 self.failUnless(abs(numarray.dot(s0,s0)-1.)<self.ABS_TOL,"s0 length is wrong.")
400 self.failUnless(abs(s0[0]-math.cos(30*DEG))<self.ABS_TOL,"s0 angle is wrong.")
401 self.failUnless(numarray.dot(_cross(s0,[1,0,0]),numarray.array([0.,1.,0.]))<0.,"s0 has wrong orientation.")
402 s1=t([0,5,0])
403 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
404 self.failUnless(self.__distance(s1,numarray.array([0.,5,0.]))<self.ABS_TOL,"s1 is wrong.")
405 s2=t([0,0,1])
406 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
407 self.failUnless(abs(numarray.dot(s2,s2)-1.)<self.ABS_TOL,"s2 length is wrong.")
408 self.failUnless(abs(s2[2]-math.cos(30*DEG))<self.ABS_TOL,"s2 angle is wrong.")
409 self.failUnless(numarray.dot(_cross(s2,[0,0,1]),numarray.array([0.,1.,0.]))<0.,"s2 has wrong orientation.")
410 def test_Rotatation_y_330_0(self):
411 t=Rotatation(axis=[0.,1.,0.],point=[0.,1.,0.],angle=330*DEG)
412 s0=t([1,0,0])
413 self.failUnless(isinstance(s0,numarray.NumArray),"s0 is not a numarray object.")
414 self.failUnless(abs(numarray.dot(s0,s0)-1.)<self.ABS_TOL,"s0 length is wrong.")
415 self.failUnless(abs(s0[0]-math.cos(330*DEG))<self.ABS_TOL,"s0 angle is wrong.")
416 self.failUnless(numarray.dot(_cross(s0,[1,0,0]),numarray.array([0.,1.,0.]))>0.,"s0 has wrong orientation.")
417 s1=t([0,1,0])
418 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
419 self.failUnless(self.__distance(s1,numarray.array([0.,1,0.]))<self.ABS_TOL,"s1 is wrong.")
420 s2=t([0,0,1])
421 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
422 self.failUnless(abs(numarray.dot(s2,s2)-1.)<self.ABS_TOL,"s2 length is wrong.")
423 self.failUnless(abs(s2[2]-math.cos(330*DEG))<self.ABS_TOL,"s2 angle is wrong.")
424 self.failUnless(numarray.dot(_cross(s2,[0,0,1]),numarray.array([0.,1.,0.]))>0.,"s2 has wrong orientation.")
425 def test_Rotatation_y_90(self):
426 t=Rotatation(axis=[0.,-1.,0.],point=[0.,2.,0.],angle=90*DEG)
427 s0=t([1,0,0])
428 self.failUnless(isinstance(s0,numarray.NumArray),"s0 is not a numarray object.")
429 self.failUnless(self.__distance(s0,numarray.array([0.,0,1.]))<self.ABS_TOL,"s0 is wrong.")
430 s1=t([0,5,0])
431 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
432 self.failUnless(self.__distance(s1,numarray.array([0.,5,0.]))<self.ABS_TOL,"s1 is wrong.")
433 s2=t([0,0,1])
434 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
435 self.failUnless(self.__distance(s2,numarray.array([-1,0.,0.]))<self.ABS_TOL,"s2 is wrong.")
436 def test_Rotatation_y_30(self):
437 t=Rotatation(axis=[0.,-1.,0.],point=[0.,2.,0.],angle=30*DEG)
438 s0=t([1,0,0])
439 self.failUnless(isinstance(s0,numarray.NumArray),"s0 is not a numarray object.")
440 self.failUnless(abs(numarray.dot(s0,s0)-1.)<self.ABS_TOL,"s0 length is wrong.")
441 self.failUnless(abs(s0[0]-math.cos(30*DEG))<self.ABS_TOL,"s0 angle is wrong.")
442 self.failUnless(numarray.dot(_cross(s0,[1,0,0]),numarray.array([0.,-1.,0.]))<0.,"s0 has wrong orientation.")
443 s1=t([0,1,0])
444 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
445 self.failUnless(self.__distance(s1,numarray.array([0.,1,0.]))<self.ABS_TOL,"s1 is wrong.")
446 s2=t([0,0,1])
447 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
448 self.failUnless(abs(numarray.dot(s2,s2)-1.)<self.ABS_TOL,"s2 length is wrong.")
449 self.failUnless(abs(s2[2]-math.cos(30*DEG))<self.ABS_TOL,"s2 angle is wrong.")
450 self.failUnless(numarray.dot(_cross(s2,[0,0,1]),numarray.array([0.,-1.,0.]))<0.,"s2 has wrong orientation.")
451 def test_Rotatation_y_330(self):
452 t=Rotatation(axis=[0.,-1.,0.],point=[0.,2.,0.],angle=330*DEG)
453 s0=t([1,0,0])
454 self.failUnless(isinstance(s0,numarray.NumArray),"s0 is not a numarray object.")
455 self.failUnless(abs(numarray.dot(s0,s0)-1.)<self.ABS_TOL,"s0 length is wrong.")
456 self.failUnless(abs(s0[0]-math.cos(330*DEG))<self.ABS_TOL,"s0 angle is wrong.")
457 self.failUnless(numarray.dot(_cross(s0,[1,0,0]),numarray.array([0.,-1.,0.]))>0.,"s0 has wrong orientation.")
458 s1=t([0,1,0])
459 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
460 self.failUnless(self.__distance(s1,numarray.array([0.,1,0.]))<self.ABS_TOL,"s1 is wrong.")
461 s2=t([0,0,1])
462 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
463 self.failUnless(abs(numarray.dot(s2,s2)-1.)<self.ABS_TOL,"s2 length is wrong.")
464 self.failUnless(abs(s2[2]-math.cos(330*DEG))<self.ABS_TOL,"s2 angle is wrong.")
465 self.failUnless(numarray.dot(_cross(s2,[0,0,1]),numarray.array([0.,-1.,0.]))>0.,"s2 has wrong orientation.")
466 def test_Rotatation_z_90_0(self):
467 t=Rotatation(axis=[0.,0.,1.],point=[0.,0.,1.],angle=90*DEG)
468 s0=t([1,0,0])
469 self.failUnless(isinstance(s0,numarray.NumArray),"s0 is not a numarray object.")
470 self.failUnless(self.__distance(s0,numarray.array([0.,1,0.]))<self.ABS_TOL,"s0 is wrong.")
471 s1=t([0,5,0])
472 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
473 self.failUnless(self.__distance(s1,numarray.array([-5.,0,0.]))<self.ABS_TOL,"s1 is wrong.")
474 s2=t([0,0,1])
475 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
476 self.failUnless(self.__distance(s2,numarray.array([0.,0,1.]))<self.ABS_TOL,"s2 is wrong.")
477 def test_Rotatation_z_30_0(self):
478 t=Rotatation(axis=[0.,0.,1.],point=[0.,0.,1.],angle=30*DEG)
479 s0=t([1,0,0])
480 self.failUnless(isinstance(s0,numarray.NumArray),"s0 is not a numarray object.")
481 self.failUnless(abs(numarray.dot(s0,s0)-1.)<self.ABS_TOL,"s0 length is wrong.")
482 self.failUnless(abs(s0[0]-math.cos(30*DEG))<self.ABS_TOL,"s0 angle is wrong.")
483 self.failUnless(numarray.dot(_cross(s0,[1,0,0]),numarray.array([0.,0.,1.]))<0.,"s0 has wrong orientation.")
484 s1=t([0,5,0])
485 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
486 self.failUnless(abs(numarray.dot(s1,s1)-5.**2)<self.ABS_TOL,"s1 length is wrong.")
487 self.failUnless(abs(s1[1]/5.-math.cos(30*DEG))<self.ABS_TOL,"s1 angle is wrong.")
488 self.failUnless(numarray.dot(_cross(s1,[0,5,0]),numarray.array([0.,0.,1.]))<0.,"s1 has wrong orientation.")
489 s2=t([0,0,1])
490 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
491 self.failUnless(self.__distance(s2,numarray.array([0.,0,1.]))<self.ABS_TOL,"s2 is wrong.")
492 def test_Rotatation_z_330_0(self):
493 t=Rotatation(axis=[0.,0.,1.],point=[0.,0.,1.],angle=330*DEG)
494 s0=t([1,0,0])
495 self.failUnless(isinstance(s0,numarray.NumArray),"s0 is not a numarray object.")
496 self.failUnless(abs(numarray.dot(s0,s0)-1.)<self.ABS_TOL,"s0 length is wrong.")
497 self.failUnless(abs(s0[0]-math.cos(330*DEG))<self.ABS_TOL,"s0 angle is wrong.")
498 self.failUnless(numarray.dot(_cross(s0,[1,0,0]),numarray.array([0.,0.,1.]))>0.,"s0 has wrong orientation.")
499 s1=t([0,5,0])
500 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
501 self.failUnless(abs(numarray.dot(s1,s1)-5.**2)<self.ABS_TOL,"s1 length is wrong.")
502 self.failUnless(abs(s1[1]/5.-math.cos(330*DEG))<self.ABS_TOL,"s1 angle is wrong.")
503 self.failUnless(numarray.dot(_cross(s1,[0,1,0]),numarray.array([0.,0.,1.]))>0.,"s1 has wrong orientation.")
504 def test_Rotatation_z_90(self):
505 t=Rotatation(axis=[0.,0.,-1.],point=[0.,0.,2.],angle=90*DEG)
506 s0=t([1,0,0])
507 self.failUnless(isinstance(s0,numarray.NumArray),"s0 is not a numarray object.")
508 self.failUnless(self.__distance(s0,numarray.array([0.,-1,0.]))<self.ABS_TOL,"s0 is wrong.")
509 s1=t([0,5,0])
510 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
511 self.failUnless(self.__distance(s1,numarray.array([5.,0,0.]))<self.ABS_TOL,"s1 is wrong.")
512 s2=t([0,0,1])
513 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
514 self.failUnless(self.__distance(s2,numarray.array([0.,0,1.]))<self.ABS_TOL,"s2 is wrong.")
515 def test_Rotatation_z_30(self):
516 t=Rotatation(axis=[0.,0.,-1.],point=[0.,0.,2.],angle=30*DEG)
517 s0=t([1,0,0])
518 self.failUnless(isinstance(s0,numarray.NumArray),"s0 is not a numarray object.")
519 self.failUnless(abs(numarray.dot(s0,s0)-1.)<self.ABS_TOL,"s0 length is wrong.")
520 self.failUnless(abs(s0[0]-math.cos(30*DEG))<self.ABS_TOL,"s0 angle is wrong.")
521 self.failUnless(numarray.dot(_cross(s0,[1,0,0]),numarray.array([0.,0.,-1.]))<0.,"s0 has wrong orientation.")
522 s1=t([0,1,0])
523 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
524 self.failUnless(abs(numarray.dot(s1,s1)-1.)<self.ABS_TOL,"s1 length is wrong.")
525 self.failUnless(abs(s1[1]-math.cos(30*DEG))<self.ABS_TOL,"s1 angle is wrong.")
526 self.failUnless(numarray.dot(_cross(s1,[0,1,0]),numarray.array([0.,0.,-1.]))<0.,"s1 has wrong orientation.")
527 s2=t([0,0,1])
528 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
529 self.failUnless(self.__distance(s2,numarray.array([0.,0,1.]))<self.ABS_TOL,"s2 is wrong.")
530 def test_Rotatation_z_330(self):
531 t=Rotatation(axis=[0.,0.,-1.],point=[0.,0.,2.],angle=330*DEG)
532 s0=t([1,0,0])
533 self.failUnless(isinstance(s0,numarray.NumArray),"s0 is not a numarray object.")
534 self.failUnless(abs(numarray.dot(s0,s0)-1.)<self.ABS_TOL,"s0 length is wrong.")
535 self.failUnless(abs(s0[0]-math.cos(330*DEG))<self.ABS_TOL,"s0 angle is wrong.")
536 self.failUnless(numarray.dot(_cross(s0,[1,0,0]),numarray.array([0.,0.,-1.]))>0.,"s0 has wrong orientation.")
537 s1=t([0,1,0])
538 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
539 self.failUnless(abs(numarray.dot(s1,s1)-1.)<self.ABS_TOL,"s1 length is wrong.")
540 self.failUnless(abs(s1[1]-math.cos(30*DEG))<self.ABS_TOL,"s1 angle is wrong.")
541 self.failUnless(numarray.dot(_cross(s1,[0,1,0]),numarray.array([0.,0.,-1.]))>0.,"s1 has wrong orientation.")
542 s2=t([0,0,1])
543 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
544 self.failUnless(self.__distance(s2,numarray.array([0.,0,1.]))<self.ABS_TOL,"s2 is wrong.")
545 def test_Rotatation_x_90_1(self):
546 t=Rotatation(point=[0.,0.,1.],axis=[1.,0.,0.],angle=90*DEG)
547 s0=t([1,0,0])
548 self.failUnless(isinstance(s0,numarray.NumArray),"s0 is not a numarray object.")
549 self.failUnless(self.__distance(s0,numarray.array([1.,1,1.]))<self.ABS_TOL,"s0 is wrong.")
550 s1=t([0,1,0])
551 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
552 self.failUnless(self.__distance(s1,numarray.array([0.,1,2.]))<self.ABS_TOL,"s1 is wrong.")
553 s2=t([0,0,1])
554 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
555 self.failUnless(self.__distance(s2,numarray.array([0.,0,1.]))<self.ABS_TOL,"s2 is wrong.")
556 def test_Rotatation_y_90_1(self):
557 t=Rotatation(point=[1.,0.,0.],axis=[0.,1.,0.],angle=90*DEG)
558 s0=t([1,0,0])
559 self.failUnless(isinstance(s0,numarray.NumArray),"s0 is not a numarray object.")
560 self.failUnless(self.__distance(s0,numarray.array([1.,0,0.]))<self.ABS_TOL,"s0 is wrong.")
561 s1=t([0,1,0])
562 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
563 self.failUnless(self.__distance(s1,numarray.array([1.,1,1.]))<self.ABS_TOL,"s1 is wrong.")
564 s2=t([0,0,1])
565 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
566 self.failUnless(self.__distance(s2,numarray.array([2.,0,1.]))<self.ABS_TOL,"s2 is wrong.")
567 def test_Rotatation_z_90_1(self):
568 t=Rotatation(point=[0.,1.,0.],axis=[0.,0.,1.],angle=90*DEG)
569 s0=t([1,0,0])
570 self.failUnless(isinstance(s0,numarray.NumArray),"s0 is not a numarray object.")
571 self.failUnless(self.__distance(s0,numarray.array([1.,2,0.]))<self.ABS_TOL,"s0 is wrong.")
572 s1=t([0,1,0])
573 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
574 self.failUnless(self.__distance(s1,numarray.array([0.,1,0.]))<self.ABS_TOL,"s1 is wrong.")
575 s2=t([0,0,1])
576 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
577 self.failUnless(self.__distance(s2,numarray.array([1.,1,1.]))<self.ABS_TOL,"s2 is wrong.")
578 def test_Rotatation_diag_90_0(self):
579 t=Rotatation(axis=[1.,1.,1.],angle=90*DEG)
580 s0=t([1,-1,0])
581 self.failUnless(isinstance(s0,numarray.NumArray),"s0 is not a numarray object.")
582 self.failUnless(abs(numarray.dot(s0,s0)-2.)<self.ABS_TOL,"s0 length is wrong.")
583 self.failUnless(abs(numarray.dot(s0,numarray.array([1,-1,0])))<self.ABS_TOL,"s0 angle is wrong.")
584 self.failUnless(numarray.dot(_cross(s0,[1,-1,0]),numarray.array([1.,1.,1.]))<0.,"s0 has wrong orientation.")
585 s1=t([0,1,-1])
586 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
587 self.failUnless(abs(numarray.dot(s1,s1)-2.)<self.ABS_TOL,"s1 length is wrong.")
588 self.failUnless(abs(numarray.dot(s1,numarray.array([0,1,-1])))<self.ABS_TOL,"s1 angle is wrong.")
589 self.failUnless(numarray.dot(_cross(s1,[0,1,-1]),numarray.array([1.,1.,1.]))<0.,"s1 has wrong orientation.")
590 s2=t([-1,0,1])
591 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
592 self.failUnless(abs(numarray.dot(s2,s2)-2.)<self.ABS_TOL,"s2 length is wrong.")
593 self.failUnless(abs(numarray.dot(s2,numarray.array([-1,0,1])))<self.ABS_TOL,"s2 angle is wrong.")
594 self.failUnless(numarray.dot(_cross(s2,[-1,0,1]),numarray.array([1.,1.,1.]))<0.,"s2 has wrong orientation.")
595 s3=t([1,1,1])
596 self.failUnless(isinstance(s3,numarray.NumArray),"s3 is not a numarray object.")
597 self.failUnless(self.__distance(s3,numarray.array([1.,1,1.]))<self.ABS_TOL,"s3 is wrong.")
598
599 class Test_PyCAD_Primitives(unittest.TestCase):
600 def setUp(self):
601 resetGlobalPrimitiveIdCounter()
602
603 def test_Primitive(self):
604 p=Primitive()
605
606 id=p.getID()
607 self.failUnless(isinstance(id,int),"id number is not an integer")
608 self.failUnless(not id==Primitive().getID(),"id number is not unique")
609
610 self.failUnless(p==p.getUnderlyingPrimitive(),"getUnderlyingPrimitive does not return self.")
611
612 def test_ReversePrimitive(self):
613 p=Primitive()
614
615 rp=ReversePrimitive(p)
616 self.failUnless(p.getID()==rp.getID(),"reverse primitive does not have same id like source")
617 self.failUnless(p==rp.getUnderlyingPrimitive(),"getUnderlyingPrimitive does return source.")
618 self.failUnless(p == -rp,"reverse or reverse does not return source.")
619
620 def test_Point(self):
621 p=Point(1.,2.,3.,local_scale=9.)
622
623 id=p.getID()
624 self.failUnless(isinstance(id,int),"id number is not an integer")
625 self.failUnless(not id==Primitive().getID(),"id number is not unique")
626
627 # check reverse point
628 self.failUnless(p == -p,"reverse is not working.")
629
630 # check history:
631 hs=p.getPrimitives()
632 self.failUnless(len(hs)==1,"history must have length 1.")
633 self.failUnless(p in hs,"history must contain point p")
634
635 # check incolved points:
636 ps=p.getConstructionPoints()
637 self.failUnless(len(ps)==1,"point set must have length 1.")
638 self.failUnless(p in ps,"point set must contain point p")
639
640 # check coordinates:
641 c=p.getCoordinates()
642 self.failUnless(isinstance(c,numarray.NumArray),"coordinates are not a numarray object.")
643 self.failUnless(c[0]==1.,"x coordinate is not 1.")
644 self.failUnless(c[1]==2.,"y coordinate is not 2.")
645 self.failUnless(c[2]==3.,"z coordinate is not 3.")
646
647 # reset coordinates:
648 p.setCoordinates([-1.,-2.,-3.])
649 c=p.getCoordinates()
650 self.failUnless(isinstance(c,numarray.NumArray),"new coordinates are not a numarray object.")
651 self.failUnless(c[0]==-1.,"new x coordinate is not -1.")
652 self.failUnless(c[1]==-2.,"new y coordinate is not -2.")
653 self.failUnless(c[2]==-3.,"new z coordinate is not -3.")
654
655 # check for a colocated point:
656 self.failUnless(p.isColocated(Point(-1.,-2.,-3.)),"colocation not detected.")
657 self.failUnless(not p.isColocated(numarray.array([-1.,-2.,-3.])),"colocation with numarray representation not detected.")
658 self.failUnless(not p.isColocated(Point(1.,-2.,-3.)),"false colocation detected.")
659 self.failUnless(not p.isColocated(Point(0.,0.,0.)),"false colocation with origin detected.")
660
661 # check for local length scale
662 l=p.getLocalScale()
663 self.failUnless(l==9.,"refinement scale is not 9.")
664
665 # check for new local length scale
666 p.setLocalScale(3.)
667 l=p.getLocalScale()
668 self.failUnless(l==3.,"new refinement scale is not 3.")
669
670 # negative value shouldn't work.
671 self.failUnlessRaises(ValueError,p.setLocalScale,-3.)
672
673 # copy:
674 an_other_p=p.copy()
675 self.failUnless(isinstance(an_other_p ,Point),"copy is not a point")
676 self.failUnless(not an_other_p.getID() == p.getID(),"copy has same Id")
677 self.failUnless(p.isColocated(an_other_p),"p is not colocated with its copy.")
678 self.failUnless(an_other_p.isColocated(p),"the copy is not colocated with p.")
679 self.failUnless(an_other_p.getLocalScale()==3.,"copy has wrong local scale.")
680
681 # modify by Transformation:
682 p.modifyBy(Dilation(-1))
683 self.failUnless(p.isColocated(Point(1.,2.,3.)),"in-place transformation failed")
684
685 # apply Transformation:
686 dil_p=p.apply(Dilation(4))
687 self.failUnless(dil_p.isColocated(Point(4.,8.,12.)),"applying transformation failed")
688 self.failUnless(not dil_p.getID() == p.getID(),"transformed point has same Id")
689 self.failUnless(dil_p.getLocalScale()==3.,"transformed point has wrong local scale.")
690
691 # overloaded add:
692 shift_p=p+[1,1,1]
693 self.failUnless(shift_p.isColocated(Point(2,3.,4)),"applying shift by list failed")
694 self.failUnless(not shift_p.getID() == p.getID(),"shift by list has same Id")
695 self.failUnless(shift_p.getLocalScale()==3.,"shift by list has wrong local scale.")
696
697 shift_p=p+numarray.array([1,1,1])
698 self.failUnless(shift_p.isColocated(Point(2,3.,4)),"applying shift by numarray failed")
699 self.failUnless(not shift_p.getID() == p.getID(),"shift by numarray has same Id")
700 self.failUnless(shift_p.getLocalScale()==3.,"shift by numarray has wrong local scale.")
701 # overloaded minus
702 shift_p=p-[1,1,1]
703 self.failUnless(shift_p.isColocated(Point(0,1,2.)),"applying shift by -list failed")
704 self.failUnless(not shift_p.getID() == p.getID(),"shift by -list has same Id")
705 self.failUnless(shift_p.getLocalScale()==3.,"shift by -list has wrong local scale.")
706
707 shift_p=p-numarray.array([1,1,1])
708 self.failUnless(shift_p.isColocated(Point(0,1,2.)),"applying shift by -numarray failed")
709 self.failUnless(not shift_p.getID() == p.getID(),"shift by -numarray has same Id")
710 self.failUnless(shift_p.getLocalScale()==3.,"shift by -numarray has wrong local scale.")
711 # overloaded inplace add:
712 p+=[1,1,1]
713 self.failUnless(p.isColocated(Point(2,3.,4)),"modification by list shift failed")
714
715 p+=numarray.array([1,1,1])
716 self.failUnless(p.isColocated(Point(3,4,5)),"modification by numarray shift failed")
717
718 # overloaded inplace add:
719 p-=[1,1,1]
720 self.failUnless(p.isColocated(Point(2,3,4)),"modification by -list shift failed")
721
722 p-=numarray.array([1,1,1])
723 self.failUnless(p.isColocated(Point(1,2.,3)),"modification by -numarray shift failed")
724
725 #overloaded multiplication:
726 mult_p=2*p
727 self.failUnless(mult_p.isColocated(Point(2,4,6)),"applying int factor failed")
728 self.failUnless(not mult_p.getID() == p.getID(),"shift by int factor has same Id")
729 self.failUnless(mult_p.getLocalScale()==3.,"shift by int factor has wrong local scale.")
730
731 mult_p=2.*p
732 self.failUnless(mult_p.isColocated(Point(2,4,6)),"applying float factor failed")
733 self.failUnless(not mult_p.getID() == p.getID(),"shift by float factor has same Id")
734 self.failUnless(mult_p.getLocalScale()==3.,"shift by float factor has wrong local scale.")
735
736 mult_p=Dilation(2)*p
737 self.failUnless(mult_p.isColocated(Point(2,4,6)),"applying Dilation factor failed")
738 self.failUnless(not mult_p.getID() == p.getID(),"shift by Dilation factor has same Id")
739 self.failUnless(mult_p.getLocalScale()==3.,"shift by Dilation factor has wrong local scale.")
740
741 #overloaded inplace multiplication:
742 p*=2
743 self.failUnless(p.isColocated(Point(2,4,6)),"applying in-place int factor failed")
744
745 p*=2.
746 self.failUnless(p.isColocated(Point(4,8,12)),"applying in-place float factor failed")
747
748 p*=Dilation(2)
749 self.failUnless(p.isColocated(Point(8,16,24)),"applying in-place Dilation factor failed")
750
751 # get gmsh code
752 code=p.getGmshCommand(2.)
753 self.failUnless("Point(1) = {8.0 , 16.0, 24.0 , 6.0 };"== code, "wrong gmsh code")
754
755 def test_Spline(self):
756 p0=Point(0,0,0,0.1)
757 p1=Point(1,1,1,0.2)
758 p2=Point(2,2,2,0.3)
759 p3=Point(3,3,3,0.4)
760 p4=Point(1,2,3)
761
762 self.failUnlessRaises(ValueError,Spline,p0)
763 c=Spline(p0,p1,p2,p3)
764
765 self.failUnless(len(c) == 4, "wrong spline curve length")
766 self.failUnless(c.getStartPoint()==p0, "wrong start point of spline curve")
767 self.failUnless(c.getEndPoint()==p3, "wrong end point of spline curve")
768
769 self.failUnless(c.hasSameOrientation(c),"has not same orientation like itself")
770 self.failUnless(not c.hasSameOrientation(-c),"has same orientation like -itself")
771
772 self.failUnless(not c.isColocated(p1),"spline is colocated with point.")
773 self.failUnless(not c.isColocated(Spline(p0,p1,p2)),"spline is colocated with spline of different length.")
774 self.failUnless(not c.isColocated(Spline(p0,p1,p4,p3)),"spline is colocated with spline with different point.")
775 self.failUnless(c.isColocated(Spline(p0,p1,p2,p3)),"spline is not colocated with spline with same points.")
776 self.failUnless(c.isColocated(Spline(p3,p2,p1,p0)),"spline is not colocated with spline with same points but opposite direction.")
777 self.failUnless(not c.isColocated(Curve(p0,p1,p2,p3)),"spline curve is identified with curve.")
778
779 co=c.getControlPoints()
780 self.failUnless(co[0]==p0, "1st control point is wrong.")
781 self.failUnless(co[1]==p1, "2nd control point is wrong.")
782 self.failUnless(co[2]==p2, "3rd control point is wrong.")
783 self.failUnless(co[3]==p3, "4th control point is wrong.")
784
785 c.setLocalScale(3.)
786 co=c.getControlPoints()
787 self.failUnless(co[0].getLocalScale() == 3., "new local scale of 1st control point is wrong.")
788 self.failUnless(co[1].getLocalScale() == 3., "new local scale of 2nd control point is wrong.")
789 self.failUnless(co[2].getLocalScale() == 3., "new local scale of 3rd control point is wrong.")
790 self.failUnless(co[3].getLocalScale() == 3., "new local scale of 4th control point is wrong.")
791
792 code=c.getGmshCommand()
793 self.failUnless(code == "Spline(6) = {1, 2, 3, 4};", "gmsh command wrong.")
794
795 h=c.getPrimitives()
796 self.failUnless(len(h) == 5, "number of primitives in history is wrong.")
797 self.failUnless(p0 in h, "missing p0 in history.")
798 self.failUnless(p1 in h, "missing p1 in history.")
799 self.failUnless(p2 in h, "missing p2 in history.")
800 self.failUnless(p3 in h, "missing p3 in history.")
801 self.failUnless(c in h, "missing spline curve in history.")
802
803 cp=c.copy()
804 cpcp=cp.getControlPoints()
805 self.failUnless(not cp == c, "copy returns same spline curve.")
806 self.failUnless(c.isColocated(cp),"spline curve is not colocated with its copy.")
807 self.failUnless(not p0 == cpcp[0],"1st point of deep copy and source are the same.")
808 self.failUnless(not p1 == cpcp[1],"2st point of deep copy and source are the same.")
809 self.failUnless(not p2 == cpcp[2],"3st point of deep copy and source are the same.")
810 self.failUnless(not p3 == cpcp[3],"4st point of deep copy and source are the same.")
811
812 c.modifyBy(Dilation(-1.))
813 cp=c.getControlPoints()
814 self.failUnless(c.isColocated(Spline(Point(0,0,0),Point(-1,-1,-1),Point(-2,-2,-2),Point(-3,-3,-3))),"inplace dilation is wrong.")
815 self.failUnless(p0 == cp[0],"1st new point after Dilation.")
816 self.failUnless(p1 == cp[1],"2nd new point after Dilation.")
817 self.failUnless(p2 == cp[2],"3rd new point after Dilation.")
818 self.failUnless(p3 == cp[3],"4th new point after Dilation.")
819
820 dc=c.apply(Dilation(-1.))
821 dccp=dc.getControlPoints()
822 self.failUnless(dc.isColocated(Spline(Point(0,0,0),Point(1,1,1),Point(2,2,2),Point(3,3,3))),"dilation is wrong.")
823 self.failUnless(not p0 == dccp[0],"1st point of Dilation is identical to source.")
824 self.failUnless(dccp[0].isColocated(Point(0,0,0)),"1st point of Dilation is is wrongly located.")
825 self.failUnless(not p1 == dccp[1],"2nd point of Dilation is identical to source.")
826 self.failUnless(dccp[1].isColocated(Point(1,1,1)),"1st point of Dilation is is wrongly located.")
827 self.failUnless(not p2 == dccp[2],"3rd point of Dilation is identical to source.")
828 self.failUnless(dccp[2].isColocated(Point(2,2,2)),"1st point of Dilation is is wrongly located.")
829 self.failUnless(not p3 == dccp[3],"4th point of Dilation is identical to source.")
830 self.failUnless(dccp[3].isColocated(Point(3,3,3)),"1st point of Dilation is is wrongly located.")
831
832 def test_ReverseSpline(self):
833 p0=Point(0,0,0,0.1)
834 p1=Point(1,1,1,0.2)
835 p2=Point(2,2,2,0.3)
836 p3=Point(3,3,3,0.4)
837 p4=Point(1,2,3)
838
839 CC0=Spline(p0,p1,p2,p3)
840 c=-CC0
841
842 self.failUnless(len(c) == 4, "wrong reverse spline curve length")
843 self.failUnless(c.getStartPoint()==p3, "wrong start point of reverse spline curve")
844 self.failUnless(c.getEndPoint()==p0, "wrong end point of reverse spline curve")
845
846 self.failUnless(c.hasSameOrientation(c),"has not same orientation like itself")
847 self.failUnless(not c.hasSameOrientation(-c),"has same orientation like -itself")
848
849 self.failUnless(not c.isColocated(p1),"reverse spline is colocated with point.")
850 self.failUnless(not c.isColocated(Spline(p0,p1,p2)),"reverse spline is colocated with spline of different length.")
851 self.failUnless(not c.isColocated(Spline(p0,p1,p4,p3)),"reverse spline is colocated with spline with different point.")
852 self.failUnless(c.isColocated(Spline(p0,p1,p2,p3)),"reverse spline is not colocated with spline with same points but opposite direction.")
853 self.failUnless(c.isColocated(Spline(p3,p2,p1,p0)),"reverse spline is not colocated with spline with same points.")
854 self.failUnless(not c.isColocated(Curve(p0,p1,p2,p3)),"spline curve is identified with curve.")
855
856 co=c.getControlPoints()
857 self.failUnless(co[0]==p3, "1st control point is wrong.")
858 self.failUnless(co[1]==p2, "2nd control point is wrong.")
859 self.failUnless(co[2]==p1, "3rd control point is wrong.")
860 self.failUnless(co[3]==p0, "4th control point is wrong.")
861
862 c.setLocalScale(3.)
863 co=c.getControlPoints()
864 self.failUnless(co[0].getLocalScale() == 3., "new local scale of 1st control point is wrong.")
865 self.failUnless(co[1].getLocalScale() == 3., "new local scale of 2nd control point is wrong.")
866 self.failUnless(co[2].getLocalScale() == 3., "new local scale of 3rd control point is wrong.")
867 self.failUnless(co[3].getLocalScale() == 3., "new local scale of 4th control point is wrong.")
868
869 code=c.getGmshCommand()
870 self.failUnless(code == "Spline(6) = {1, 2, 3, 4};", "gmsh command wrong.")
871
872 h=c.getPrimitives()
873 self.failUnless(len(h) == 5, "number of primitives in history is wrong.")
874 self.failUnless(p0 in h, "missing p0 in history.")
875 self.failUnless(p1 in h, "missing p1 in history.")
876 self.failUnless(p2 in h, "missing p2 in history.")
877 self.failUnless(p3 in h, "missing p3 in history.")
878 self.failUnless(CC0 in h, "missing spline curve in history.")
879
880 cp=c.copy()
881 cpcp=cp.getControlPoints()
882 self.failUnless(not cp == c, "copy returns same spline curve.")
883 self.failUnless(not cp == CC0, "copy returns same spline curve.")
884 self.failUnless(c.isColocated(cp),"spline curve is not colocated with its copy.")
885 self.failUnless(not p3 == cpcp[0],"1st point of deep copy and souce are the same.")
886 self.failUnless(not p2 == cpcp[1],"2st point of deep copy and source are the same.")
887 self.failUnless(not p1 == cpcp[2],"3st point of deep copy and source are the same.")
888 self.failUnless(not p0 == cpcp[3],"4st point of deep copy and source are the same.")
889
890 c.modifyBy(Dilation(-1.))
891 cp=c.getControlPoints()
892 self.failUnless(c.isColocated(Spline(Point(0,0,0),Point(-1,-1,-1),Point(-2,-2,-2),Point(-3,-3,-3))),"inplace dilation is wrong.")
893 self.failUnless(p3 == cp[0],"1st new point after Dilation.")
894 self.failUnless(p2 == cp[1],"2nd new point after Dilation.")
895 self.failUnless(p1 == cp[2],"3rd new point after Dilation.")
896 self.failUnless(p0 == cp[3],"4th new point after Dilation.")
897
898 dc=c.apply(Dilation(-1.))
899 dccp=dc.getControlPoints()
900 self.failUnless(dc.isColocated(Spline(Point(0,0,0),Point(1,1,1),Point(2,2,2),Point(3,3,3))),"dilation is wrong.")
901 self.failUnless(dccp[0].isColocated(Point(3,3,3)),"1st point of Dilation is is wrongly located.")
902 self.failUnless(dccp[1].isColocated(Point(2,2,2)),"1st point of Dilation is is wrongly located.")
903 self.failUnless(dccp[2].isColocated(Point(1,1,1)),"1st point of Dilation is is wrongly located.")
904 self.failUnless(dccp[3].isColocated(Point(0,0,0)),"1st point of Dilation is is wrongly located.")
905
906 def test_BezierCurve(self):
907 p0=Point(0,0,0,0.1)
908 p1=Point(1,1,1,0.2)
909 p2=Point(2,2,2,0.3)
910 p3=Point(3,3,3,0.4)
911 p4=Point(1,2,3)
912
913 self.failUnlessRaises(ValueError,BezierCurve,p0)
914 c=BezierCurve(p0,p1,p2,p3)
915
916 self.failUnless(len(c) == 4, "wrong spline curve length")
917 self.failUnless(c.getStartPoint()==p0, "wrong start point of spline curve")
918 self.failUnless(c.getEndPoint()==p3, "wrong end point of spline curve")
919
920 self.failUnless(not c.isColocated(p1),"spline is colocated with point.")
921 self.failUnless(not c.isColocated(BezierCurve(p0,p1,p2)),"spline is colocated with spline of different length.")
922 self.failUnless(not c.isColocated(BezierCurve(p0,p1,p4,p3)),"spline is colocated with spline with different point.")
923 self.failUnless(c.isColocated(BezierCurve(p0,p1,p2,p3)),"spline is not colocated with spline with same points.")
924 self.failUnless(c.isColocated(BezierCurve(p3,p2,p1,p0)),"spline is not colocated with spline with same points but opposite direction.")
925 self.failUnless(not c.isColocated(Curve(p0,p1,p2,p3)),"spline curve is identified with curve.")
926
927 co=c.getControlPoints()
928 self.failUnless(co[0]==p0, "1st control point is wrong.")
929 self.failUnless(co[1]==p1, "2nd control point is wrong.")
930 self.failUnless(co[2]==p2, "3rd control point is wrong.")
931 self.failUnless(co[3]==p3, "4th control point is wrong.")
932
933 c.setLocalScale(3.)
934 co=c.getControlPoints()
935 self.failUnless(co[0].getLocalScale() == 3., "new local scale of 1st control point is wrong.")
936 self.failUnless(co[1].getLocalScale() == 3., "new local scale of 2nd control point is wrong.")
937 self.failUnless(co[2].getLocalScale() == 3., "new local scale of 3rd control point is wrong.")
938 self.failUnless(co[3].getLocalScale() == 3., "new local scale of 4th control point is wrong.")
939
940 code=c.getGmshCommand()
941 self.failUnless(code == "Bezier(6) = {1, 2, 3, 4};", "gmsh command wrong.")
942
943 h=c.getPrimitives()
944 self.failUnless(len(h) == 5, "number of primitives in history is wrong.")
945 self.failUnless(p0 in h, "missing p0 in history.")
946 self.failUnless(p1 in h, "missing p1 in history.")
947 self.failUnless(p2 in h, "missing p2 in history.")
948 self.failUnless(p3 in h, "missing p3 in history.")
949 self.failUnless(c in h, "missing spline curve in history.")
950
951 cp=c.copy()
952 cpcp=cp.getControlPoints()
953 self.failUnless(not cp == c, "copy returns same spline curve.")
954 self.failUnless(c.isColocated(cp),"spline curve is not colocated with its copy.")
955 self.failUnless(not p0 == cpcp[0],"1st point of deep copy and source are the same.")
956 self.failUnless(not p1 == cpcp[1],"2st point of deep copy and source are the same.")
957 self.failUnless(not p2 == cpcp[2],"3st point of deep copy and source are the same.")
958 self.failUnless(not p3 == cpcp[3],"4st point of deep copy and source are the same.")
959
960 c.modifyBy(Dilation(-1.))
961 cp=c.getControlPoints()
962 self.failUnless(c.isColocated(BezierCurve(Point(0,0,0),Point(-1,-1,-1),Point(-2,-2,-2),Point(-3,-3,-3))),"inplace dilation is wrong.")
963 self.failUnless(p0 == cp[0],"1st new point after Dilation.")
964 self.failUnless(p1 == cp[1],"2nd new point after Dilation.")
965 self.failUnless(p2 == cp[2],"3rd new point after Dilation.")
966 self.failUnless(p3 == cp[3],"4th new point after Dilation.")
967
968 dc=c.apply(Dilation(-1.))
969 dccp=dc.getControlPoints()
970 self.failUnless(dc.isColocated(BezierCurve(Point(0,0,0),Point(1,1,1),Point(2,2,2),Point(3,3,3))),"dilation is wrong.")
971 self.failUnless(not p0 == dccp[0],"1st point of Dilation is identical to source.")
972 self.failUnless(not p1 == dccp[1],"2nd point of Dilation is identical to source.")
973 self.failUnless(not p2 == dccp[2],"3rd point of Dilation is identical to source.")
974 self.failUnless(not p3 == dccp[3],"4th point of Dilation is identical to source.")
975
976 def test_BSpline(self):
977 p0=Point(0,0,0,0.1)
978 p1=Point(1,1,1,0.2)
979 p2=Point(2,2,2,0.3)
980 p3=Point(3,3,3,0.4)
981 p4=Point(1,2,3)
982
983 self.failUnlessRaises(ValueError,BSpline,p0)
984 c=BSpline(p0,p1,p2,p3)
985
986 self.failUnless(len(c) == 4, "wrong spline curve length")
987 self.failUnless(c.getStartPoint()==p0, "wrong start point of spline curve")
988 self.failUnless(c.getEndPoint()==p3, "wrong end point of spline curve")
989
990 self.failUnless(c.hasSameOrientation(c),"has not same orientation like itself")
991 self.failUnless(not c.hasSameOrientation(-c),"has same orientation like -itself")
992
993 self.failUnless(not c.isColocated(p1),"spline is colocated with point.")
994 self.failUnless(not c.isColocated(BSpline(p0,p1,p2)),"spline is colocated with spline of different length.")
995 self.failUnless(not c.isColocated(BSpline(p0,p1,p4,p3)),"spline is colocated with spline with different point.")
996 self.failUnless(c.isColocated(BSpline(p0,p1,p2,p3)),"spline is not colocated with spline with same points.")
997 self.failUnless(c.isColocated(BSpline(p3,p2,p1,p0)),"spline is not colocated with spline with same points but opposite direction.")
998 self.failUnless(not c.isColocated(Curve(p0,p1,p2,p3)),"spline curve is identified with curve.")
999
1000 co=c.getControlPoints()
1001 self.failUnless(co[0]==p0, "1st control point is wrong.")
1002 self.failUnless(co[1]==p1, "2nd control point is wrong.")
1003 self.failUnless(co[2]==p2, "3rd control point is wrong.")
1004 self.failUnless(co[3]==p3, "4th control point is wrong.")
1005
1006 c.setLocalScale(3.)
1007 co=c.getControlPoints()
1008 self.failUnless(co[0].getLocalScale() == 3., "new local scale of 1st control point is wrong.")
1009 self.failUnless(co[1].getLocalScale() == 3., "new local scale of 2nd control point is wrong.")
1010 self.failUnless(co[2].getLocalScale() == 3., "new local scale of 3rd control point is wrong.")
1011 self.failUnless(co[3].getLocalScale() == 3., "new local scale of 4th control point is wrong.")
1012
1013 code=c.getGmshCommand()
1014 self.failUnless(code == "BSpline(6) = {1, 2, 3, 4};", "gmsh command wrong.")
1015
1016 h=c.getPrimitives()
1017 self.failUnless(len(h) == 5, "number of primitives in history is wrong.")
1018 self.failUnless(p0 in h, "missing p0 in history.")
1019 self.failUnless(p1 in h, "missing p1 in history.")
1020 self.failUnless(p2 in h, "missing p2 in history.")
1021 self.failUnless(p3 in h, "missing p3 in history.")
1022 self.failUnless(c in h, "missing spline curve in history.")
1023
1024 cp=c.copy()
1025 cpcp=cp.getControlPoints()
1026 self.failUnless(not cp == c, "copy returns same spline curve.")
1027 self.failUnless(c.isColocated(cp),"spline curve is not colocated with its copy.")
1028 self.failUnless(not p0 == cpcp[0],"1st point of deep copy and source are the same.")
1029 self.failUnless(not p1 == cpcp[1],"2st point of deep copy and source are the same.")
1030 self.failUnless(not p2 == cpcp[2],"3st point of deep copy and source are the same.")
1031 self.failUnless(not p3 == cpcp[3],"4st point of deep copy and source are the same.")
1032
1033 c.modifyBy(Dilation(-1.))
1034 cp=c.getControlPoints()
1035 self.failUnless(c.isColocated(BSpline(Point(0,0,0),Point(-1,-1,-1),Point(-2,-2,-2),Point(-3,-3,-3))),"inplace dilation is wrong.")
1036 self.failUnless(p0 == cp[0],"1st new point after Dilation.")
1037 self.failUnless(p1 == cp[1],"2nd new point after Dilation.")
1038 self.failUnless(p2 == cp[2],"3rd new point after Dilation.")
1039 self.failUnless(p3 == cp[3],"4th new point after Dilation.")
1040
1041 dc=c.apply(Dilation(-1.))
1042 dccp=dc.getControlPoints()
1043 self.failUnless(dc.isColocated(BSpline(Point(0,0,0),Point(1,1,1),Point(2,2,2),Point(3,3,3))),"dilation is wrong.")
1044 self.failUnless(not p0 == dccp[0],"1st point of Dilation is identical to source.")
1045 self.failUnless(dccp[0].isColocated(Point(0,0,0)),"1st point of Dilation is is wrongly located.")
1046 self.failUnless(not p1 == dccp[1],"2nd point of Dilation is identical to source.")
1047 self.failUnless(dccp[1].isColocated(Point(1,1,1)),"1st point of Dilation is is wrongly located.")
1048 self.failUnless(not p2 == dccp[2],"3rd point of Dilation is identical to source.")
1049 self.failUnless(dccp[2].isColocated(Point(2,2,2)),"1st point of Dilation is is wrongly located.")
1050 self.failUnless(not p3 == dccp[3],"4th point of Dilation is identical to source.")
1051 self.failUnless(dccp[3].isColocated(Point(3,3,3)),"1st point of Dilation is is wrongly located.")
1052
1053 def test_ReverseBSpline(self):
1054 p0=Point(0,0,0,0.1)
1055 p1=Point(1,1,1,0.2)
1056 p2=Point(2,2,2,0.3)
1057 p3=Point(3,3,3,0.4)
1058 p4=Point(1,2,3)
1059
1060 CC0=BSpline(p0,p1,p2,p3)
1061 c=-CC0
1062
1063 self.failUnless(len(c) == 4, "wrong spline curve length")
1064 self.failUnless(c.getStartPoint()==p3, "wrong start point of spline curve")
1065 self.failUnless(c.getEndPoint()==p0, "wrong end point of spline curve")
1066
1067 self.failUnless(c.hasSameOrientation(c),"has not same orientation like itself")
1068 self.failUnless(not c.hasSameOrientation(-c),"has same orientation like -itself")
1069
1070 self.failUnless(not c.isColocated(p1),"spline is colocated with point.")
1071 self.failUnless(not c.isColocated(BSpline(p0,p1,p2)),"spline is colocated with spline of different length.")
1072 self.failUnless(not c.isColocated(BSpline(p0,p1,p4,p3)),"spline is colocated with spline with different point.")
1073 self.failUnless(c.isColocated(BSpline(p0,p1,p2,p3)),"spline is not colocated with spline with same points.")
1074 self.failUnless(c.isColocated(BSpline(p3,p2,p1,p0)),"spline is not colocated with spline with same points but opposite direction.")
1075 self.failUnless(not c.isColocated(Curve(p0,p1,p2,p3)),"spline curve is identified with curve.")
1076
1077 co=c.getControlPoints()
1078 self.failUnless(co[0]==p3, "1st control point is wrong.")
1079 self.failUnless(co[1]==p2, "2nd control point is wrong.")
1080 self.failUnless(co[2]==p1, "3rd control point is wrong.")
1081 self.failUnless(co[3]==p0, "4th control point is wrong.")
1082
1083 c.setLocalScale(3.)
1084 co=c.getControlPoints()
1085 self.failUnless(co[0].getLocalScale() == 3., "new local scale of 1st control point is wrong.")
1086 self.failUnless(co[1].getLocalScale() == 3., "new local scale of 2nd control point is wrong.")
1087 self.failUnless(co[2].getLocalScale() == 3., "new local scale of 3rd control point is wrong.")
1088 self.failUnless(co[3].getLocalScale() == 3., "new local scale of 4th control point is wrong.")
1089
1090 code=c.getGmshCommand()
1091 self.failUnless(code == "BSpline(6) = {1, 2, 3, 4};", "gmsh command wrong.")
1092
1093 h=c.getPrimitives()
1094 self.failUnless(len(h) == 5, "number of primitives in history is wrong.")
1095 self.failUnless(p0 in h, "missing p0 in history.")
1096 self.failUnless(p1 in h, "missing p1 in history.")
1097 self.failUnless(p2 in h, "missing p2 in history.")
1098 self.failUnless(p3 in h, "missing p3 in history.")
1099 self.failUnless(CC0 in h, "missing spline curve in history.")
1100
1101 cp=c.copy()
1102 cpcp=cp.getControlPoints()
1103 self.failUnless(not cp == c, "copy returns same spline curve.")
1104 self.failUnless(c.isColocated(cp),"spline curve is not colocated with its copy.")
1105 self.failUnless(not p0 == cpcp[0],"1st point of deep copy and source are the same.")
1106 self.failUnless(not p1 == cpcp[1],"2st point of deep copy and source are the same.")
1107 self.failUnless(not p2 == cpcp[2],"3st point of deep copy and source are the same.")
1108 self.failUnless(not p3 == cpcp[3],"4st point of deep copy and source are the same.")
1109
1110 c.modifyBy(Dilation(-1.))
1111 cp=c.getControlPoints()
1112 self.failUnless(c.isColocated(BSpline(Point(0,0,0),Point(-1,-1,-1),Point(-2,-2,-2),Point(-3,-3,-3))),"inplace dilation is wrong.")
1113 self.failUnless(p3 == cp[0],"1st new point after Dilation.")
1114 self.failUnless(p2 == cp[1],"2nd new point after Dilation.")
1115 self.failUnless(p1 == cp[2],"3rd new point after Dilation.")
1116 self.failUnless(p0 == cp[3],"4th new point after Dilation.")
1117
1118 dc=c.apply(Dilation(-1.))
1119 dccp=dc.getControlPoints()
1120 self.failUnless(dc.isColocated(BSpline(Point(0,0,0),Point(1,1,1),Point(2,2,2),Point(3,3,3))),"dilation is wrong.")
1121 self.failUnless(not p0 == dccp[0],"1st point of Dilation is identical to source.")
1122 self.failUnless(dccp[0].isColocated(Point(3,3,3)),"1st point of Dilation is is wrongly located.")
1123 self.failUnless(not p1 == dccp[1],"2nd point of Dilation is identical to source.")
1124 self.failUnless(dccp[1].isColocated(Point(2,2,2)),"1st point of Dilation is is wrongly located.")
1125 self.failUnless(not p2 == dccp[2],"3rd point of Dilation is identical to source.")
1126 self.failUnless(dccp[2].isColocated(Point(1,1,1)),"1st point of Dilation is is wrongly located.")
1127 self.failUnless(not p3 == dccp[3],"4th point of Dilation is identical to source.")
1128 self.failUnless(dccp[3].isColocated(Point(0,0,0)),"1st point of Dilation is is wrongly located.")
1129
1130 def test_LineSegment(self):
1131 p0=Point(0,0,0,0.1)
1132 p1=Point(1,1,1,0.2)
1133 p4=Point(1,2,3)
1134
1135 self.failUnlessRaises(TypeError,Line,p0)
1136 self.failUnlessRaises(TypeError,Line,p0,p1,p4)
1137
1138 c=Line(p0,p1)
1139
1140 self.failUnless(len(c) == 2, "wrong spline curve length")
1141 self.failUnless(c.getStartPoint()==p0, "wrong start point of spline curve")
1142 self.failUnless(c.getEndPoint()==p1, "wrong end point of spline curve")
1143
1144 self.failUnless(c.hasSameOrientation(c),"has not same orientation like itself")
1145 self.failUnless(not c.hasSameOrientation(-c),"has same orientation like -itself")
1146
1147 self.failUnless(not c.isColocated(p1),"spline is colocated with point.")
1148 self.failUnless(not c.isColocated(Line(p0,p4)),"spline is colocated with spline with different point.")
1149 self.failUnless(c.isColocated(Line(p0,p1)),"spline is not colocated with spline with same points.")
1150 self.failUnless(c.isColocated(Line(p1,p0)),"spline is not colocated with spline with same points but opposite direction.")
1151 self.failUnless(not c.isColocated(Curve(p0,p1,p4)),"spline curve is identified with curve.")
1152
1153 co=c.getControlPoints()
1154 self.failUnless(co[0]==p0, "1st control point is wrong.")
1155 self.failUnless(co[1]==p1, "2nd control point is wrong.")
1156
1157 c.setLocalScale(3.)
1158 co=c.getControlPoints()
1159 self.failUnless(co[0].getLocalScale() == 3., "new local scale of 1st control point is wrong.")
1160 self.failUnless(co[1].getLocalScale() == 3., "new local scale of 2nd control point is wrong.")
1161
1162 code=c.getGmshCommand()
1163 self.failUnless(code == "Line(4) = {1, 2};", "gmsh command wrong.")
1164
1165 h=c.getPrimitives()
1166 self.failUnless(len(h) == 3, "number of primitives in history is wrong.")
1167 self.failUnless(p0 in h, "missing p0 in history.")
1168 self.failUnless(p1 in h, "missing p1 in history.")
1169 self.failUnless(c in h, "missing spline curve in history.")
1170
1171 cp=c.copy()
1172 cpcp=cp.getControlPoints()
1173 self.failUnless(not cp == c, "copy returns same spline curve.")
1174 self.failUnless(c.isColocated(cp),"spline curve is not colocated with its copy.")
1175 self.failUnless(not p0 == cpcp[0],"1st point of deep copy and source are the same.")
1176 self.failUnless(not p1 == cpcp[1],"2st point of deep copy and source are the same.")
1177
1178 c.modifyBy(Dilation(-1.))
1179 cp=c.getControlPoints()
1180 self.failUnless(c.isColocated(Line(Point(0,0,0),Point(-1,-1,-1))),"inplace dilation is wrong.")
1181 self.failUnless(p0 == cp[0],"1st new point after Dilation.")
1182 self.failUnless(p1 == cp[1],"2nd new point after Dilation.")
1183
1184 dc=c.apply(Dilation(-1.))
1185 dccp=dc.getControlPoints()
1186 self.failUnless(dc.isColocated(Line(Point(0,0,0),Point(1,1,1))),"dilation is wrong.")
1187 self.failUnless(not p0 == dccp[0],"1st point of Dilation is identical to source.")
1188 self.failUnless(dccp[0].isColocated(Point(0,0,0)),"1st point of Dilation is is wrongly located.")
1189 self.failUnless(not p1 == dccp[1],"2nd point of Dilation is identical to source.")
1190 self.failUnless(dccp[1].isColocated(Point(1,1,1)),"2st point of Dilation is is wrongly located.")
1191
1192 def test_ReverseLineSegment(self):
1193 p0=Point(0,0,0,0.1)
1194 p1=Point(1,1,1,0.2)
1195 p4=Point(1,2,3)
1196
1197 self.failUnlessRaises(TypeError,Line,p0)
1198 self.failUnlessRaises(TypeError,Line,p0,p1,p4)
1199
1200 CC0=Line(p0,p1)
1201 c=-CC0
1202
1203 self.failUnless(c.hasSameOrientation(c),"has not same orientation like itself")
1204 self.failUnless(not c.hasSameOrientation(-c),"has same orientation like -itself")
1205
1206 self.failUnless(len(c) == 2, "wrong spline curve length")
1207 self.failUnless(c.getStartPoint()==p1, "wrong start point of spline curve")
1208 self.failUnless(c.getEndPoint()==p0, "wrong end point of spline curve")
1209
1210 self.failUnless(not c.isColocated(p1),"spline is colocated with point.")
1211 self.failUnless(not c.isColocated(Line(p0,p4)),"spline is colocated with spline with different point.")
1212 self.failUnless(c.isColocated(Line(p0,p1)),"spline is not colocated with spline with same points.")
1213 self.failUnless(c.isColocated(Line(p1,p0)),"spline is not colocated with spline with same points but opposite direction.")
1214 self.failUnless(not c.isColocated(Curve(p0,p1,p4)),"spline curve is identified with curve.")
1215
1216 co=c.getControlPoints()
1217 self.failUnless(co[0]==p1, "1st control point is wrong.")
1218 self.failUnless(co[1]==p0, "2nd control point is wrong.")
1219
1220 c.setLocalScale(3.)
1221 co=c.getControlPoints()
1222 self.failUnless(co[0].getLocalScale() == 3., "new local scale of 1st control point is wrong.")
1223 self.failUnless(co[1].getLocalScale() == 3., "new local scale of 2nd control point is wrong.")
1224
1225 code=c.getGmshCommand()
1226 self.failUnless(code == "Line(4) = {1, 2};", "gmsh command wrong.")
1227
1228 h=c.getPrimitives()
1229 self.failUnless(len(h) == 3, "number of primitives in history is wrong.")
1230 self.failUnless(p0 in h, "missing p0 in history.")
1231 self.failUnless(p1 in h, "missing p1 in history.")
1232 self.failUnless(CC0 in h, "missing spline curve in history.")
1233
1234 cp=c.copy()
1235 cpcp=cp.getControlPoints()
1236 self.failUnless(not cp == c, "copy returns same spline curve.")
1237 self.failUnless(c.isColocated(cp),"spline curve is not colocated with its copy.")
1238 self.failUnless(not p0 == cpcp[0],"1st point of deep copy and source are the same.")
1239 self.failUnless(not p1 == cpcp[1],"2st point of deep copy and source are the same.")
1240
1241 c.modifyBy(Dilation(-1.))
1242 cp=c.getControlPoints()
1243 self.failUnless(c.isColocated(Line(Point(0,0,0),Point(-1,-1,-1))),"inplace dilation is wrong.")
1244 self.failUnless(p1 == cp[0],"1st new point after Dilation.")
1245 self.failUnless(p0 == cp[1],"2nd new point after Dilation.")
1246
1247 dc=c.apply(Dilation(-1.))
1248 dccp=dc.getControlPoints()
1249 self.failUnless(dc.isColocated(Line(Point(0,0,0),Point(1,1,1))),"dilation is wrong.")
1250 self.failUnless(not p0 == dccp[0],"1st point of Dilation is identical to source.")
1251 self.failUnless(dccp[0].isColocated(Point(1,1,1)),"1st point of Dilation is is wrongly located.")
1252 self.failUnless(not p1 == dccp[1],"2nd point of Dilation is identical to source.")
1253 self.failUnless(dccp[1].isColocated(Point(0,0,0)),"2st point of Dilation is is wrongly located.")
1254
1255 def test_Arc(self):
1256 center=Point(0,0,0,0.1)
1257 p_start=Point(1,1,1,0.2)
1258 p_end=Point(1,2,3)
1259 p4=Point(10,2,3)
1260
1261 self.failUnlessRaises(TypeError,Arc,Primitive())
1262
1263 c=Arc(center,p_start,p_end)
1264
1265 self.failUnless(c.getCenterPoint()==center, "wrong center point")
1266 self.failUnless(c.getStartPoint()==p_start, "wrong start point")
1267 self.failUnless(c.getEndPoint()==p_end, "wrong end point")
1268
1269 self.failUnless(c.hasSameOrientation(c),"has not same orientation like itself")
1270 self.failUnless(not c.hasSameOrientation(-c),"has same orientation like -itself")
1271
1272 code=c.getGmshCommand()
1273 self.failUnless(code == "Circle(6) = {2, 1, 3};", "gmsh command wrong.")
1274
1275 self.failUnless(not c.isColocated(p4),"spline is colocated with point.")
1276 self.failUnless(not c.isColocated(Arc(p4,p_start,p_end)),"spline is colocated with spline with differnt center point.")
1277 self.failUnless(not c.isColocated(Arc(center,p4,p_end)),"spline is colocated with spline with differnt start point.")
1278 self.failUnless(not c.isColocated(Arc(center,p_start,p4)),"spline is colocated with spline with differnt end point.")
1279 self.failUnless(c.isColocated(Arc(center,p_start,p_end)),"spline is not colocated with spline with same points.")
1280 self.failUnless(c.isColocated(Arc(center,p_end,p_start)),"spline is not colocated with spline with same points but opposite direction.")
1281 self.failUnless(not c.isColocated(Curve(center,p_start,p_end)),"spline curve is identified with curve.")
1282
1283 h=c.getPrimitives()
1284 self.failUnless(len(h) == 4, "number of primitives in history is wrong.")
1285 self.failUnless(center in h, "missing center in history.")
1286 self.failUnless(p_start in h, "missing p_start in history.")
1287 self.failUnless(p_end in h, "missing p_end in history.")
1288 self.failUnless(c in h, "missing spline curve in history.")
1289
1290
1291 c.setLocalScale(3.)
1292 self.failUnless(c.getCenterPoint().getLocalScale() == 3., "new local scale of center point is wrong.")
1293 self.failUnless(c.getStartPoint().getLocalScale() == 3., "new local scale of start point is wrong.")
1294 self.failUnless(c.getEndPoint().getLocalScale() == 3., "new local scale of end point is wrong.")
1295
1296 cp=c.copy()
1297 self.failUnless(isinstance(cp,Arc), "copy returns is not an arc.")
1298 self.failUnless(not cp == c, "copy returns same arc.")
1299 self.failUnless(cp.isColocated(Arc(center,p_start,p_end)),"arc is not colocated with its copy.")
1300 self.failUnless(not cp.getCenterPoint()==center, "deep copy has same center point like source")
1301 self.failUnless(not cp.getStartPoint()==p_start, "deep copy has same start point like source")
1302 self.failUnless(not cp.getEndPoint()==p_end, "deep copy has same end point like source")
1303
1304 c.modifyBy(Dilation(-1.))
1305 self.failUnless(c.isColocated(Arc(Point(0,0,0),Point(-1,-1,-1),Point(-1,-2,-3))),"inplace dilation is wrong.")
1306 self.failUnless(c.getCenterPoint() == center,"wrong center point after dilation.")
1307 self.failUnless(c.getStartPoint() == p_start,"wrong start point after dilation.")
1308 self.failUnless(c.getEndPoint() == p_end,"wrong end point after dilation.")
1309
1310 dc=c.apply(Dilation(-1.))
1311 self.failUnless(dc.isColocated(Arc(Point(0,0,0),Point(1,1,1),Point(1,2,3))),"dilation is wrong.")
1312 self.failUnless(not dc.getCenterPoint() == center,"center point of dilation is identical to source.")
1313 self.failUnless(dc.getCenterPoint().isColocated(Point(0,0,0)),"center point of dilation is wrong.")
1314 self.failUnless(not dc.getStartPoint() == p_start,"start point of dilation is identical to source.")
1315 self.failUnless(dc.getStartPoint().isColocated(Point(1,1,1)),"start point of dilation is wrong.")
1316 self.failUnless(not dc.getEndPoint() == p_end,"end point of dilation is identical to source.")
1317 self.failUnless(dc.getEndPoint().isColocated(Point(1,2,3)),"end point of dilation is wrong.")
1318
1319 def test_ReverseArc(self):
1320 center=Point(0,0,0,0.1)
1321 p_start=Point(1,1,1,0.2)
1322 p_end=Point(1,2,3)
1323 p4=Point(10,2,3)
1324
1325 self.failUnlessRaises(TypeError,Arc,Primitive())
1326
1327 CC0=Arc(center,p_start,p_end)
1328 c=-CC0
1329
1330 self.failUnless(c.getCenterPoint()==center, "wrong center point")
1331 self.failUnless(c.getStartPoint()==p_end, "wrong start point")
1332 self.failUnless(c.getEndPoint()==p_start, "wrong end point")
1333
1334 self.failUnless(c.hasSameOrientation(c),"has not same orientation like itself")
1335 self.failUnless(not c.hasSameOrientation(-c),"has same orientation like -itself")
1336
1337 code=c.getGmshCommand()
1338 self.failUnless(code == "Circle(6) = {2, 1, 3};", "gmsh command wrong.")
1339
1340 self.failUnless(not c.isColocated(p4),"spline is colocated with point.")
1341 self.failUnless(not c.isColocated(Arc(p4,p_start,p_end)),"spline is colocated with spline with differnt center point.")
1342 self.failUnless(not c.isColocated(Arc(center,p4,p_end)),"spline is colocated with spline with differnt start point.")
1343 self.failUnless(not c.isColocated(Arc(center,p_start,p4)),"spline is colocated with spline with differnt end point.")
1344 self.failUnless(c.isColocated(Arc(center,p_start,p_end)),"spline is not colocated with spline with same points.")
1345 self.failUnless(c.isColocated(Arc(center,p_end,p_start)),"spline is not colocated with spline with same points but opposite direction.")
1346 self.failUnless(not c.isColocated(Curve(center,p_start,p_end)),"spline curve is identified with curve.")
1347
1348 h=c.getPrimitives()
1349 self.failUnless(len(h) == 4, "number of primitives in history is wrong.")
1350 self.failUnless(center in h, "missing center in history.")
1351 self.failUnless(p_start in h, "missing p_start in history.")
1352 self.failUnless(p_end in h, "missing p_end in history.")
1353 self.failUnless(CC0 in h, "missing spline curve in history.")
1354
1355
1356 c.setLocalScale(3.)
1357 self.failUnless(c.getCenterPoint().getLocalScale() == 3., "new local scale of center point is wrong.")
1358 self.failUnless(c.getStartPoint().getLocalScale() == 3., "new local scale of start point is wrong.")
1359 self.failUnless(c.getEndPoint().getLocalScale() == 3., "new local scale of end point is wrong.")
1360
1361 cp=c.copy()
1362 self.failUnless(isinstance(cp,ReverseArc), "copy returns is not an arc.")
1363 self.failUnless(not cp == c, "copy returns same arc.")
1364 self.failUnless(cp.isColocated(Arc(center,p_end,p_start)),"arc is not colocated with its copy.")
1365 self.failUnless(not cp.getCenterPoint()==center, "deep copy has same center point like source")
1366 self.failUnless(not cp.getStartPoint()==p_start, "deep copy has same start point like source")
1367 self.failUnless(not cp.getEndPoint()==p_end, "deep copy has same end point like source")
1368
1369 c.modifyBy(Dilation(-1.))
1370 self.failUnless(c.isColocated(Arc(Point(0,0,0),Point(-1,-1,-1),Point(-1,-2,-3))),"inplace dilation is wrong.")
1371 self.failUnless(c.getCenterPoint() == center,"wrong center point after dilation.")
1372 self.failUnless(c.getStartPoint() == p_end,"wrong start point after dilation.")
1373 self.failUnless(c.getEndPoint() == p_start,"wrong end point after dilation.")
1374
1375 dc=c.apply(Dilation(-1.))
1376 self.failUnless(dc.isColocated(Arc(Point(0,0,0),Point(1,1,1),Point(1,2,3))),"dilation is wrong.")
1377 self.failUnless(not dc.getCenterPoint() == center,"center point of dilation is identical to source.")
1378 self.failUnless(dc.getCenterPoint().isColocated(Point(0,0,0)),"center point of dilation is wrong.")
1379 self.failUnless(not dc.getStartPoint() == p_start,"start point of dilation is identical to source.")
1380 self.failUnless(dc.getStartPoint().isColocated(Point(1,2,3)),"start point of dilation is wrong.")
1381 self.failUnless(not dc.getEndPoint() == p_end,"end point of dilation is identical to source.")
1382 self.failUnless(dc.getEndPoint().isColocated(Point(1,1,1)),"end point of dilation is wrong.")
1383
1384 def test_CurveLoop(self):
1385 p0=Point(0,0,0,0.1)
1386 p1=Point(1,1,1,0.2)
1387 p2=Point(2,2,2,0.3)
1388 p3=Point(3,3,3,0.4)
1389 p4=Point(1,2,3)
1390 p5=Point(10,20,3)
1391 p6=Point(1,2,30)
1392
1393 l01=Line(p0,p1)
1394 l12=Arc(p3,p1,p2)
1395 l20=Spline(p2,p4,p0)
1396
1397 lx=Line(p2,p3)
1398 ly=Line(p3,p1)
1399
1400 c=CurveLoop(l01,l12,l20)
1401 # self.failUnlessRaises(ValueError,CurveLoop,l01,lx,l20)
1402 # self.failUnlessRaises(ValueError,CurveLoop,l01,l20,l20)
1403 # self.failUnlessRaises(ValueError,CurveLoop,l01,l20,ly)
1404
1405 c=CurveLoop(l01,l20,l12)
1406 self.failUnless(c.hasSameOrientation(c),"has not same orientation like itself")
1407 self.failUnless(not c.hasSameOrientation(-c),"has same orientation like -itself")
1408
1409 code=c.getGmshCommand()
1410 self.failUnless(code == "Line Loop(14) = {8, 10, 9};", "gmsh command wrong.")
1411
1412 self.failUnless(not c.isColocated(p4),"CurveLoop is colocated with point.")
1413 self.failUnless(c.isColocated(c),"CurveLoop is not colocated with its self.")
1414 self.failUnless(c.isColocated(CurveLoop(l01,l12,l20)),"CurveLoop is not colocated with its copy.")
1415 self.failUnless(c.isColocated(CurveLoop(l20,l01,l12)),"CurveLoop is not colocated with its copy with shifted points.")
1416 self.failUnless(c.isColocated(CurveLoop(l20,l12,l01)),"CurveLoop is not colocated with its copy with shuffled points.")
1417 self.failUnless(not c.isColocated(CurveLoop(lx,ly,l12)),"CurveLoop is colocated with different CurveLoop.")
1418
1419 self.failUnless(len(c) == 3, "wrong length")
1420
1421 c.setLocalScale(3.)
1422 self.failUnless(p0.getLocalScale()==3., "p0 has wrong local scale.")
1423 self.failUnless(p1.getLocalScale()==3., "p1 has wrong local scale.")
1424 self.failUnless(p2.getLocalScale()==3., "p2 has wrong local scale.")
1425 self.failUnless(p4.getLocalScale()==3., "p4 has wrong local scale.")
1426
1427
1428 cc=c.getCurves()
1429 self.failUnless(len(cc) == 3, "too many curves.")
1430 self.failUnless(l01 in cc, "l01 is missing")
1431 self.failUnless(l12 in cc, "l12 is missing")
1432 self.failUnless(l20 in cc, "l20 is missing")
1433
1434 p=c.getPrimitives()
1435 self.failUnless(len(p) == 9, "too many primitives.")
1436 self.failUnless(l01 in p, "l01 is missing")
1437 self.failUnless(l12 in p, "l21 is missing")
1438 self.failUnless(l20 in p, "l20 is missing")
1439 self.failUnless(p0 in p, "p0 is missing")
1440 self.failUnless(p1 in p, "p1 is missing")
1441 self.failUnless(p2 in p, "p2 is missing")
1442 self.failUnless(p3 in p, "p3 is missing")
1443 self.failUnless(p4 in p, "p4 is missing")
1444
1445 cp=c.copy()
1446 self.failUnless(isinstance(cp,CurveLoop), "copy returns is not an arc.")
1447 self.failUnless(not cp == c, "copy equals source")
1448 self.failUnless(cp.isColocated(c),"copy is not colocated with its source.")
1449 cc=cp.getCurves()
1450 self.failUnless(len(cc) == 3, "too many primitives in copy.")
1451 self.failUnless(not l01 in cc,"copy uses l01.")
1452 self.failUnless(not l12 in cc,"copy uses l12.")
1453 self.failUnless(not l20 in cc,"copy uses l20.")
1454
1455 p0_m=Point(0,0,0)
1456 p1_m=Point(-1,-1,-1)
1457 p2_m=Point(-2,-2,-2)
1458 p3_m=Point(-3,-3,-3)
1459 p4_m=Point(-1,-2,-3)
1460
1461 l01_m=Line(p0_m,p1_m)
1462 l12_m=Arc(p3_m,p1_m,p2_m)
1463 l20_m=Spline(p2_m,p4_m,p0_m)
1464
1465 dc=c.apply(Dilation(-1.))
1466 self.failUnless(dc.isColocated(CurveLoop(l01_m,l12_m,l20_m)),"dilation is wrong.")
1467 cc=dc.getCurves()
1468 self.failUnless(len(cc) == 3, "too many primitives in dilation result.")
1469 self.failUnless(not l01 in cc,"l01 is in dilation result.")
1470 self.failUnless(not l12 in cc,"l12 is in dilation result.")
1471 self.failUnless(not l20 in cc,"l20 is in dilation result.")
1472
1473 c.modifyBy(Dilation(-1.))
1474 self.failUnless(c.isColocated(CurveLoop(l01_m,l12_m,l20_m)),"inplace dilation is wrong.")
1475 cc=c.getCurves()
1476 self.failUnless(len(cc) == 3, "too many primitives in modified object.")
1477 self.failUnless(l01 in cc,"l01 missed in modified object.")
1478 self.failUnless(cc[cc.index(l01)].hasSameOrientation(l01),"l01 in modified object has wrong orientation.")
1479 self.failUnless(l12 in cc,"l12 missed in modified object.")
1480 self.failUnless(cc[cc.index(l12)].hasSameOrientation(l12),"l12 in modified object has wrong orientation.")
1481 self.failUnless(l20 in cc,"l20 missed in modified object.")
1482 self.failUnless(cc[cc.index(l20)].hasSameOrientation(l20),"l20 in modified object has wrong orientation.")
1483
1484 def test_ReverseCurveLoop(self):
1485 p0=Point(0,0,0,0.1)
1486 p1=Point(1,1,1,0.2)
1487 p2=Point(2,2,2,0.3)
1488 p3=Point(3,3,3,0.4)
1489 p4=Point(1,2,3)
1490 p5=Point(10,20,3)
1491 p6=Point(1,2,30)
1492
1493 l01=Line(p0,p1)
1494 l12=Arc(p3,p1,p2)
1495 l20=Spline(p2,p4,p0)
1496
1497 lx=Line(p2,p3)
1498 ly=Line(p3,p1)
1499
1500 CC0=CurveLoop(l01,l20,l12)
1501 c=-CC0
1502
1503 self.failUnless(c.hasSameOrientation(c),"has not same orientation like itself")
1504 self.failUnless(not c.hasSameOrientation(-c),"has same orientation like -itself")
1505
1506 code=c.getGmshCommand()
1507 self.failUnless(code == "Line Loop(13) = {8, 10, 9};", "gmsh command wrong.")
1508
1509
1510 self.failUnless(not c.isColocated(p4),"-CurveLoop is colocated with point.")
1511 self.failUnless(c.isColocated(c),"-CurveLoop is not colocated with its self.")
1512 self.failUnless(c.isColocated(CurveLoop(l01,l12,l20)),"-CurveLoop is not colocated with its copy.")
1513 self.failUnless(c.isColocated(CurveLoop(l20,l01,l12)),"-CurveLoop is not colocated with its copy with shifted points.")
1514 self.failUnless(c.isColocated(CurveLoop(l20,l12,l01)),"-CurveLoop is not colocated with its copy with shuffled points.")
1515 self.failUnless(not c.isColocated(CurveLoop(lx,ly,l12)),"-CurveLoop is colocated with different CurveLoop.")
1516
1517 self.failUnless(len(c) == 3, "wrong length")
1518
1519 c.setLocalScale(3.)
1520 self.failUnless(p0.getLocalScale()==3., "p0 has wrong local scale.")
1521 self.failUnless(p1.getLocalScale()==3., "p1 has wrong local scale.")
1522 self.failUnless(p2.getLocalScale()==3., "p2 has wrong local scale.")
1523 self.failUnless(p4.getLocalScale()==3., "p4 has wrong local scale.")
1524
1525
1526 cc=c.getCurves()
1527 self.failUnless(len(cc) == 3, "too many curves.")
1528 self.failUnless(l01 in cc, "l01 is missing")
1529 self.failUnless(l12 in cc, "l12 is missing")
1530 self.failUnless(l20 in cc, "l20 is missing")
1531
1532 p=c.getPrimitives()
1533 self.failUnless(len(p) == 9, "too many primitives.")
1534 self.failUnless(l01 in p, "l01 is missing")
1535 self.failUnless(l12 in p, "l21 is missing")
1536 self.failUnless(l20 in p, "l20 is missing")
1537 self.failUnless(p0 in p, "p0 is missing")
1538 self.failUnless(p1 in p, "p1 is missing")
1539 self.failUnless(p2 in p, "p2 is missing")
1540 self.failUnless(p3 in p, "p3 is missing")
1541 self.failUnless(p4 in p, "p4 is missing")
1542
1543 cp=c.copy()
1544 self.failUnless(isinstance(cp,ReverseCurveLoop), "copy returns is not an ReverseCurveLoop.")
1545 self.failUnless(not cp == c, "copy equals source")
1546 self.failUnless(cp.isColocated(c),"copy is not colocated with its source.")
1547 cc=cp.getCurves()
1548 self.failUnless(len(cc) == 3, "too many primitives in copy.")
1549 self.failUnless(not l01 in cc,"copy uses l01.")
1550 self.failUnless(not l12 in cc,"copy uses l12.")
1551 self.failUnless(not l20 in cc,"copy uses l20.")
1552
1553 p0_m=Point(0,0,0)
1554 p1_m=Point(-1,-1,-1)
1555 p2_m=Point(-2,-2,-2)
1556 p3_m=Point(-3,-3,-3)
1557 p4_m=Point(-1,-2,-3)
1558
1559 l01_m=Line(p0_m,p1_m)
1560 l12_m=Arc(p3_m,p1_m,p2_m)
1561 l20_m=Spline(p2_m,p4_m,p0_m)
1562
1563 dc=c.apply(Dilation(-1.))
1564 self.failUnless(dc.isColocated(CurveLoop(l01_m,l12_m,l20_m)),"dilation is wrong.")
1565 cc=dc.getCurves()
1566 self.failUnless(len(cc) == 3, "too many primitives in dilation result.")
1567 self.failUnless(not l01 in cc,"l01 is in dilation result.")
1568 self.failUnless(not l12 in cc,"l12 is in dilation result.")
1569 self.failUnless(not l20 in cc,"l20 is in dilation result.")
1570
1571 c.modifyBy(Dilation(-1.))
1572 self.failUnless(c.isColocated(CurveLoop(l01_m,l12_m,l20_m)),"inplace dilation is wrong.")
1573 cc=c.getCurves()
1574 self.failUnless(len(cc) == 3, "too many primitives in modified object.")
1575 self.failUnless(l01 in cc,"l01 missed in modified object.")
1576 self.failUnless(cc[cc.index(l01)].hasSameOrientation(-l01),"l01 in modified object has wrong orientation.")
1577 self.failUnless(l12 in cc,"l12 missed in modified object.")
1578 self.failUnless(cc[cc.index(l12)].hasSameOrientation(-l12),"l12 in modified object has wrong orientation.")
1579 self.failUnless(l20 in cc,"l20 missed in modified object.")
1580 self.failUnless(cc[cc.index(l20)].hasSameOrientation(-l20),"l20 in modified object has wrong orientation.")
1581
1582 def test_RuledSurface(self):
1583 p0=Point(0,0,0,0.1)
1584 p1=Point(1,1,1,0.2)
1585 p2=Point(2,2,2,0.3)
1586 p3=Point(3,3,3,0.4)
1587 p4=Point(1,2,3)
1588 p5=Point(10,20,3)
1589 p6=Point(1,2,30)
1590
1591 l01=Line(p0,p1)
1592 l12_1=Arc(p3,p1,p2)
1593 l12_2_1=Spline(p1,p3,p4)
1594 l12_2_2=Spline(p4,p5,p2)
1595 l12_3=Line(p1,p2)
1596 l20=Spline(p2,p4,p0)
1597
1598 cl1=CurveLoop(l01,l12_1,l20)
1599 cl2=CurveLoop(l01,l12_2_1,l12_2_2,l20)
1600 cl3=CurveLoop(l01,l12_3,l20)
1601
1602 self.failUnlessRaises(TypeError,RuledSurface,l01)
1603
1604 s=RuledSurface(cl1)
1605
1606 cl=s.getBoundaryLoop()
1607 self.failUnless(cl == cl1, " wrong boundary loops")
1608 self.failUnless(cl.hasSameOrientation(cl1),"cl1 has incorrect orientation.")
1609
1610 self.failUnless(s.hasSameOrientation(s),"has not same orientation like itself")
1611 self.failUnless(not s.hasSameOrientation(-s),"has same orientation like -itself")
1612
1613 crvs=s.getBoundary()
1614 self.failUnless(len(crvs) == 3, "too many boundary corves.")
1615 self.failUnless(l01 in crvs, "l01 is missing in boundary")
1616 self.failUnless(crvs[crvs.index(l01)].hasSameOrientation(l01),"l01 has incorrect orientation.")
1617 self.failUnless(l12_1 in crvs, "l21 is missing in boundary")
1618 self.failUnless(crvs[crvs.index(l12_1)].hasSameOrientation(l12_1),"l12_1 has incorrect orientation.")
1619 self.failUnless(l20 in crvs, "l20 is missing in boundary")
1620 self.failUnless(crvs[crvs.index(l20)].hasSameOrientation(l20),"l12_1 has incorrect orientation.")
1621
1622
1623 code=s.getGmshCommand()
1624 self.failUnless(code == "Ruled Surface(17) = {14};", "gmsh command wrong.")
1625
1626 self.failUnless(not s.isColocated(p4),"RuledSurface is colocated with point.")
1627 self.failUnless(s.isColocated(s),"RuledSurface is not colocated with its self.")
1628 self.failUnless(s.isColocated(RuledSurface(cl1)),"RuledSurface is not colocated with its copy.")
1629 self.failUnless(not s.isColocated(RuledSurface(cl2)),"RuledSurface is colocated with different length")
1630 self.failUnless(not s.isColocated(RuledSurface(cl3)),"RuledSurface is colocated with same length.")
1631
1632 s.setLocalScale(3.)
1633 self.failUnless(p0.getLocalScale()==3., "p0 has wrong local scale.")
1634 self.failUnless(p1.getLocalScale()==3., "p1 has wrong local scale.")
1635 self.failUnless(p2.getLocalScale()==3., "p2 has wrong local scale.")
1636 self.failUnless(p4.getLocalScale()==3., "p4 has wrong local scale.")
1637
1638 p=s.getPrimitives()
1639 self.failUnless(len(p) == 10, "too many primitives.")
1640 self.failUnless(cl1 in p, "cl1 is missing")
1641 self.failUnless(l01 in p, "l01 is missing")
1642 self.failUnless(l12_1 in p, "l21 is missing")
1643 self.failUnless(l20 in p, "l20 is missing")
1644 self.failUnless(p0 in p, "p0 is missing")
1645 self.failUnless(p1 in p, "p1 is missing")
1646 self.failUnless(p2 in p, "p2 is missing")
1647 self.failUnless(p3 in p, "p3 is missing")
1648 self.failUnless(p4 in p, "p4 is missing")
1649
1650 sp=s.copy()
1651 self.failUnless(isinstance(sp,RuledSurface), "copy returns is not a RuledSurface.")
1652 self.failUnless(not sp == s, "copy equals source")
1653 self.failUnless(sp.isColocated(s),"copy is not colocated with its source.")
1654 cbl=sp.getBoundaryLoop()
1655 self.failUnless(not cbl == cl1,"copy uses cl1.")
1656 cp=sp.getPrimitives()
1657 self.failUnless(len(cp) == 10, "copy as too many primitives.")
1658 self.failUnless(not cl1 in cp, "copy is using cl1")
1659 self.failUnless(not l01 in cp, "copy is using l01")
1660 self.failUnless(not l12_1 in cp, "copy is using l21")
1661 self.failUnless(not l20 in cp, "copy is using l20")
1662 self.failUnless(not p0 in cp, "copy is using p0")
1663 self.failUnless(not p1 in cp, "copy is using p1")
1664 self.failUnless(not p2 in cp, "copy is using p2")
1665 self.failUnless(not p3 in cp, "copy is using p3")
1666 self.failUnless(not p4 in cp, "copy is using p4")
1667 del cp
1668
1669 p0_m=Point(0,0,0)
1670 p1_m=Point(-1,-1,-1)
1671 p2_m=Point(-2,-2,-2)
1672 p3_m=Point(-3,-3,-3)
1673 p4_m=Point(-1,-2,-3)
1674
1675 l01_m=Line(p0_m,p1_m)
1676 l12_m=Arc(p3_m,p1_m,p2_m)
1677 l20_m=Spline(p2_m,p4_m,p0_m)
1678
1679 ds=s.apply(Dilation(-1.))
1680 self.failUnless(ds.isColocated(RuledSurface(CurveLoop(l01_m,l12_m,l20_m))),"dilation is wrong.")
1681 cbl=ds.getBoundaryLoop()
1682 self.failUnless(not cbl == cl1,"dilation uses cl1.")
1683 cp=ds.getPrimitives()
1684 self.failUnless(len(cp) == 10, "dilation as too many primitives.")
1685 self.failUnless(not cl1 in cp, "dilation is using cl1")
1686 self.failUnless(not l01 in cp, "dilation is using l01")
1687 self.failUnless(not l12_1 in cp, "dilation is using l21")
1688 self.failUnless(not l20 in cp, "dilation is using l20")
1689 self.failUnless(not p0 in cp, "dilation is using p0")
1690 self.failUnless(not p1 in cp, "dilation is using p1")
1691 self.failUnless(not p2 in cp, "dilation is using p2")
1692 self.failUnless(not p3 in cp, "dilation is using p3")
1693 self.failUnless(not p4 in cp, "dilation is using p4")
1694
1695 s.modifyBy(Dilation(-1.))
1696 self.failUnless(s.isColocated(RuledSurface(CurveLoop(l01_m,l12_m,l20_m))),"inplace dilation is wrong.")
1697
1698 p=s.getPrimitives()
1699 self.failUnless(len(p) == 10, "inplace dilation has too many primitives.")
1700 self.failUnless(cl1 in p, "inplace dilation cl1 is missing")
1701 self.failUnless(l01 in p, "inplace dilation l01 is missing")
1702 self.failUnless(l12_1 in p, "inplace dilation l21 is missing")
1703 self.failUnless(l20 in p, "inplace dilation l20 is missing")
1704 self.failUnless(p0 in p, "inplace dilation p0 is missing")
1705 self.failUnless(p1 in p, "inplace dilation p1 is missing")
1706 self.failUnless(p2 in p, "inplace dilation p2 is missing")
1707 self.failUnless(p3 in p, "inplace dilation p3 is missing")
1708 self.failUnless(p4 in p, "inplace dilation p4 is missing")
1709
1710 p=s.getBoundary()
1711 self.failUnless(len(p) == 3, "inplace dilation has too many boundary curves.")
1712 self.failUnless(l01 in p, "inplace dilation l01 is missing in boundary curves.")
1713 self.failUnless(p[p.index(l01)].hasSameOrientation(l01),"l01 in getBoundary after dilation has incorrect orientation.")
1714 self.failUnless(l12_1 in p, "inplace dilation l21 is missing")
1715 self.failUnless(p[p.index(l12_1)].hasSameOrientation(l12_1),"l12_1 in getBoundary after dilation has incorrect orientation.")
1716 self.failUnless(l20 in p, "inplace dilation l20 is missing")
1717 self.failUnless(p[p.index(l20)].hasSameOrientation(l20),"l20 in getBoundary after dilation has incorrect orientation.")
1718
1719 p=s.getBoundaryLoop()
1720 self.failUnless(cl1 == p, "inplace dilation s.getBoundaryLoop does not return cl1")
1721 self.failUnless(p.hasSameOrientation(cl1),"cl1 in getBoundaryLoop after dilation has incorrect orientation.")
1722
1723 def test_ReverseRuledSurface(self):
1724 p0=Point(0,0,0,0.1)
1725 p1=Point(1,1,1,0.2)
1726 p2=Point(2,2,2,0.3)
1727 p3=Point(3,3,3,0.4)
1728 p4=Point(1,2,3)
1729 p5=Point(10,20,3)
1730 p6=Point(1,2