/[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 2627 - (show annotations)
Mon Aug 24 01:57:34 2009 UTC (10 years, 1 month ago) by gross
File MIME type: text/x-python
File size: 235631 byte(s)
some bugs in pycad fixed.

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