/[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 2419 - (show annotations)
Thu May 14 01:56:18 2009 UTC (12 years, 1 month ago) by jfenwick
File MIME type: text/x-python
File size: 229213 byte(s)
Use os.path.join instead of os.sep in tests
If you can read this message it means svn commit mails are working again.
... Or you are looking at the logs
1
2 ########################################################
3 #
4 # Copyright (c) 2003-2008 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-2008 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 numarray
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 numarray.array([x[1] * y[2] - x[2] * y[1], x[2] * y[0] - x[0] * y[2], x[0] * y[1] - x[1] * y[0]])
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(numarray.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,numarray.NumArray),"s0 is not a numarray object.")
59 self.failUnless(self.__distance(s0,numarray.array([2,0,0]))<self.ABS_TOL,"s0 is wrong.")
60 s1=t([0,1,0])
61 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
62 self.failUnless(self.__distance(s1,numarray.array([1,1,0]))<self.ABS_TOL,"s1 is wrong.")
63 s2=t([0,0,1])
64 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
65 self.failUnless(self.__distance(s2,numarray.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,numarray.NumArray),"s0 is not a numarray object.")
70 self.failUnless(self.__distance(s0,numarray.array([1,1,0]))<self.ABS_TOL,"s0 is wrong.")
71 s1=t([0,1,0])
72 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
73 self.failUnless(self.__distance(s1,numarray.array([0,2,0]))<self.ABS_TOL,"s1 is wrong.")
74 s2=t([0,0,1])
75 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
76 self.failUnless(self.__distance(s2,numarray.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,numarray.NumArray),"s0 is not a numarray object.")
81 self.failUnless(self.__distance(s0,numarray.array([1,0,1]))<self.ABS_TOL,"s0 is wrong.")
82 s1=t([0,1,0])
83 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
84 self.failUnless(self.__distance(s1,numarray.array([0,1,1]))<self.ABS_TOL,"s1 is wrong.")
85 s2=t([0,0,1])
86 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
87 self.failUnless(self.__distance(s2,numarray.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,numarray.NumArray),"s0 is not a numarray object.")
92 self.failUnless(self.__distance(s0,numarray.array([2,0,0]))<self.ABS_TOL,"s0 is wrong.")
93 s1=t([0,1,0])
94 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
95 self.failUnless(self.__distance(s1,numarray.array([0,2,0]))<self.ABS_TOL,"s1 is wrong.")
96 s2=t([0,0,1])
97 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
98 self.failUnless(self.__distance(s2,numarray.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,numarray.NumArray),"s0 is not a numarray object.")
103 self.failUnless(self.__distance(s0,numarray.array([0.5,0,0]))<self.ABS_TOL,"s0 is wrong.")
104 s1=t([0,1,0])
105 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
106 self.failUnless(self.__distance(s1,numarray.array([0,0.5,0]))<self.ABS_TOL,"s1 is wrong.")
107 s2=t([0,0,1])
108 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
109 self.failUnless(self.__distance(s2,numarray.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,numarray.NumArray),"s0 is not a numarray object.")
114 self.failUnless(self.__distance(s0,numarray.array([1,0,0]))<self.ABS_TOL,"s0 is wrong.")
115 s0_1=t([0,0,0])
116 self.failUnless(isinstance(s0_1,numarray.NumArray),"s0_1 is not a numarray object.")
117 self.failUnless(self.__distance(s0_1,numarray.array([-1.,0,0]))<self.ABS_TOL,"s0_1 is wrong.")
118 s1=t([0,1,0])
119 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
120 self.failUnless(self.__distance(s1,numarray.array([-1,2,0]))<self.ABS_TOL,"s1 is wrong.")
121 s2=t([0,0,1])
122 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
123 self.failUnless(self.__distance(s2,numarray.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,numarray.NumArray),"s0 is not a numarray object.")
128 self.failUnless(self.__distance(s0,numarray.array([1.,0,0]))<self.ABS_TOL,"s0 is wrong.")
129 s0_1=t([0,0,0])
130 self.failUnless(isinstance(s0_1,numarray.NumArray),"s0_1 is not a numarray object.")
131 self.failUnless(self.__distance(s0_1,numarray.array([.5,0,0]))<self.ABS_TOL,"s0_1 is wrong.")
132 s1=t([0,1,0])
133 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
134 self.failUnless(self.__distance(s1,numarray.array([0.5,0.5,0]))<self.ABS_TOL,"s1 is wrong.")
135 s2=t([0,0,1])
136 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
137 self.failUnless(self.__distance(s2,numarray.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,numarray.NumArray),"s0 is not a numarray object.")
142 self.failUnless(self.__distance(s0,numarray.array([2.,-1.,0]))<self.ABS_TOL,"s0 is wrong.")
143 s1_1=t([0,0,0])
144 self.failUnless(isinstance(s1_1,numarray.NumArray),"s1_1 is not a numarray object.")
145 self.failUnless(self.__distance(s1_1,numarray.array([0.,-1.,0]))<self.ABS_TOL,"s1_1 is wrong.")
146 s1=t([0,1,0])
147 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
148 self.failUnless(self.__distance(s1,numarray.array([0.,1.,0]))<self.ABS_TOL,"s1 is wrong.")
149 s2=t([0,0,1])
150 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
151 self.failUnless(self.__distance(s2,numarray.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,numarray.NumArray),"s0 is not a numarray object.")
156 self.failUnless(self.__distance(s0,numarray.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,numarray.NumArray),"s1_1 is not a numarray object.")
159 self.failUnless(self.__distance(s1_1,numarray.array([0,0.5,0]))<self.ABS_TOL,"s1_1 is wrong.")
160 s1=t([0,1,0])
161 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
162 self.failUnless(self.__distance(s1,numarray.array([0.,1.,0]))<self.ABS_TOL,"s1 is wrong.")
163 s2=t([0,0,1])
164 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
165 self.failUnless(self.__distance(s2,numarray.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,numarray.NumArray),"s0 is not a numarray object.")
170 self.failUnless(self.__distance(s0,numarray.array([2.,0.,-1.]))<self.ABS_TOL,"s0 is wrong.")
171 s2_1=t([0,0,0])
172 self.failUnless(isinstance(s2_1,numarray.NumArray),"s2_1 is not a numarray object.")
173 self.failUnless(self.__distance(s2_1,numarray.array([0.,0.,-1.]))<self.ABS_TOL,"s2_1 is wrong.")
174 s1=t([0,1,0])
175 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
176 self.failUnless(self.__distance(s1,numarray.array([0.,2.,-1.]))<self.ABS_TOL,"s1 is wrong.")
177 s2=t([0,0,1])
178 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
179 self.failUnless(self.__distance(s2,numarray.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,numarray.NumArray),"s0 is not a numarray object.")
184 self.failUnless(self.__distance(s0,numarray.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,numarray.NumArray),"s2_1 is not a numarray object.")
187 self.failUnless(self.__distance(s2_1,numarray.array([0,0,0.5]))<self.ABS_TOL,"s2_1 is wrong.")
188 s1=t([0,1,0])
189 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
190 self.failUnless(self.__distance(s1,numarray.array([0.,0.5,0.5]))<self.ABS_TOL,"s1 is wrong.")
191 s2=t([0,0,1])
192 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
193 self.failUnless(self.__distance(s2,numarray.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,numarray.NumArray),"s0 is not a numarray object.")
198 self.failUnless(self.__distance(s0,numarray.array([-1.,0,0.]))<self.ABS_TOL,"s0 is wrong.")
199 s1=t([0,1,0])
200 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
201 self.failUnless(self.__distance(s1,numarray.array([0,1,0]))<self.ABS_TOL,"s1 is wrong.")
202 s2=t([0,0,1])
203 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
204 self.failUnless(self.__distance(s2,numarray.array([0,0,1]))<self.ABS_TOL,"s2 is wrong.")
205 s=t([1,2,3])
206 self.failUnless(isinstance(s,numarray.NumArray),"s is not a numarray object.")
207 self.failUnless(self.__distance(s,numarray.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,numarray.NumArray),"s0 is not a numarray object.")
212 self.failUnless(self.__distance(s0,numarray.array([3.,0,0.]))<self.ABS_TOL,"s0 is wrong.")
213 s1=t([0,1,0])
214 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
215 self.failUnless(self.__distance(s1,numarray.array([4,1,0]))<self.ABS_TOL,"s1 is wrong.")
216 s2=t([0,0,1])
217 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
218 self.failUnless(self.__distance(s2,numarray.array([4,0,1]))<self.ABS_TOL,"s2 is wrong.")
219 s=t([1,2,3])
220 self.failUnless(isinstance(s,numarray.NumArray),"s is not a numarray object.")
221 self.failUnless(self.__distance(s,numarray.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,numarray.NumArray),"s0 is not a numarray object.")
226 self.failUnless(self.__distance(s0,numarray.array([3.,0,0.]))<self.ABS_TOL,"s0 is wrong.")
227 s1=t([0,1,0])
228 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
229 self.failUnless(self.__distance(s1,numarray.array([4,1,0]))<self.ABS_TOL,"s1 is wrong.")
230 s2=t([0,0,1])
231 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
232 self.failUnless(self.__distance(s2,numarray.array([4,0,1]))<self.ABS_TOL,"s2 is wrong.")
233 s=t([1,2,3])
234 self.failUnless(isinstance(s,numarray.NumArray),"s is not a numarray object.")
235 self.failUnless(self.__distance(s,numarray.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,numarray.NumArray),"s0 is not a numarray object.")
240 self.failUnless(self.__distance(s0,numarray.array([1.,0,0.]))<self.ABS_TOL,"s0 is wrong.")
241 s1=t([0,1,0])
242 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
243 self.failUnless(self.__distance(s1,numarray.array([0,-1,0]))<self.ABS_TOL,"s1 is wrong.")
244 s2=t([0,0,1])
245 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
246 self.failUnless(self.__distance(s2,numarray.array([0,0,1]))<self.ABS_TOL,"s2 is wrong.")
247 s=t([1,2,3])
248 self.failUnless(isinstance(s,numarray.NumArray),"s is not a numarray object.")
249 self.failUnless(self.__distance(s,numarray.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,numarray.NumArray),"s0 is not a numarray object.")
254 self.failUnless(self.__distance(s0,numarray.array([1.,4,0.]))<self.ABS_TOL,"s0 is wrong.")
255 s1=t([0,1,0])
256 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
257 self.failUnless(self.__distance(s1,numarray.array([0,3,0]))<self.ABS_TOL,"s1 is wrong.")
258 s2=t([0,0,1])
259 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
260 self.failUnless(self.__distance(s2,numarray.array([0,4,1]))<self.ABS_TOL,"s2 is wrong.")
261 s=t([1,2,3])
262 self.failUnless(isinstance(s,numarray.NumArray),"s is not a numarray object.")
263 self.failUnless(self.__distance(s,numarray.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,numarray.NumArray),"s0 is not a numarray object.")
268 self.failUnless(self.__distance(s0,numarray.array([1.,4,0.]))<self.ABS_TOL,"s0 is wrong.")
269 s1=t([0,1,0])
270 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
271 self.failUnless(self.__distance(s1,numarray.array([0,3,0]))<self.ABS_TOL,"s1 is wrong.")
272 s2=t([0,0,1])
273 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
274 self.failUnless(self.__distance(s2,numarray.array([0,4,1]))<self.ABS_TOL,"s2 is wrong.")
275 s=t([1,2,3])
276 self.failUnless(isinstance(s,numarray.NumArray),"s is not a numarray object.")
277 self.failUnless(self.__distance(s,numarray.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,numarray.NumArray),"s0 is not a numarray object.")
282 self.failUnless(self.__distance(s0,numarray.array([1.,0,0.]))<self.ABS_TOL,"s0 is wrong.")
283 s1=t([0,1,0])
284 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
285 self.failUnless(self.__distance(s1,numarray.array([0,1,0]))<self.ABS_TOL,"s1 is wrong.")
286 s2=t([0,0,1])
287 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
288 self.failUnless(self.__distance(s2,numarray.array([0,0,-1]))<self.ABS_TOL,"s2 is wrong.")
289 s=t([1,2,3])
290 self.failUnless(isinstance(s,numarray.NumArray),"s is not a numarray object.")
291 self.failUnless(self.__distance(s,numarray.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,numarray.NumArray),"s0 is not a numarray object.")
296 self.failUnless(self.__distance(s0,numarray.array([1.,0,4.]))<self.ABS_TOL,"s0 is wrong.")
297 s1=t([0,1,0])
298 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
299 self.failUnless(self.__distance(s1,numarray.array([0,1,4]))<self.ABS_TOL,"s1 is wrong.")
300 s2=t([0,0,1])
301 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
302 self.failUnless(self.__distance(s2,numarray.array([0,0,3]))<self.ABS_TOL,"s2 is wrong.")
303 s=t([1,2,3])
304 self.failUnless(isinstance(s,numarray.NumArray),"s is not a numarray object.")
305 self.failUnless(self.__distance(s,numarray.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,numarray.NumArray),"s0 is not a numarray object.")
310 self.failUnless(self.__distance(s0,numarray.array([1.,0,4.]))<self.ABS_TOL,"s0 is wrong.")
311 s1=t([0,1,0])
312 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
313 self.failUnless(self.__distance(s1,numarray.array([0,1,4]))<self.ABS_TOL,"s1 is wrong.")
314 s2=t([0,0,1])
315 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
316 self.failUnless(self.__distance(s2,numarray.array([0,0,3]))<self.ABS_TOL,"s2 is wrong.")
317 s=t([1,2,3])
318 self.failUnless(isinstance(s,numarray.NumArray),"s is not a numarray object.")
319 self.failUnless(self.__distance(s,numarray.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,numarray.NumArray),"s0 is not a numarray object.")
324 self.failUnless(self.__distance(s0,numarray.array([1.,0,0.]))<self.ABS_TOL,"s0 is wrong.")
325 s1=t([0,1,0])
326 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
327 self.failUnless(self.__distance(s1,numarray.array([0.,0,1.]))<self.ABS_TOL,"s1 is wrong.")
328 s2=t([0,0,1])
329 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
330 self.failUnless(self.__distance(s2,numarray.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,numarray.NumArray),"s0 is not a numarray object.")
335 self.failUnless(self.__distance(s0,numarray.array([1.,0,0.]))<self.ABS_TOL,"s0 is wrong.")
336 s1=t([0,1,0])
337 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
338 self.failUnless(abs(numarray.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(numarray.dot(_cross(s1,[0,1,0]),numarray.array([1.,0.,0.]))<0.,"s1 has wrong orientation.")
341 s2=t([0,0,1])
342 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
343 self.failUnless(abs(numarray.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(numarray.dot(_cross(s2,[0,0,1]),numarray.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,numarray.NumArray),"s0 is not a numarray object.")
350 self.failUnless(self.__distance(s0,numarray.array([1.,0,0.]))<self.ABS_TOL,"s0 is wrong.")
351 s1=t([0,1,0])
352 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
353 self.failUnless(abs(numarray.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(numarray.dot(_cross(s1,[0,1,0]),numarray.array([1.,0.,0.]))>0.,"s1 has wrong orientation.")
356 s2=t([0,0,1])
357 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
358 self.failUnless(abs(numarray.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(numarray.dot(_cross(s2,[0,0,1]),numarray.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,numarray.NumArray),"s0 is not a numarray object.")
365 self.failUnless(self.__distance(s0,numarray.array([1.,0,0.]))<self.ABS_TOL,"s0 is wrong.")
366 s1=t([0,1,0])
367 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
368 self.failUnless(self.__distance(s1,numarray.array([0.,0,-1.]))<self.ABS_TOL,"s1 is wrong.")
369 s2=t([0,0,1])
370 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
371 self.failUnless(self.__distance(s2,numarray.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,numarray.NumArray),"s0 is not a numarray object.")
376 self.failUnless(self.__distance(s0,numarray.array([1.,0,0.]))<self.ABS_TOL,"s0 is wrong.")
377 s1=t([0,1,0])
378 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
379 self.failUnless(abs(numarray.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(numarray.dot(_cross(s1,[0,1,0]),numarray.array([-1.,0.,0.]))<0.,"s1 has wrong orientation.")
382 s2=t([0,0,1])
383 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
384 self.failUnless(abs(numarray.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(numarray.dot(_cross(s2,[0,0,1]),numarray.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,numarray.NumArray),"s0 is not a numarray object.")
391 self.failUnless(self.__distance(s0,numarray.array([1.,0,0.]))<self.ABS_TOL,"s0 is wrong.")
392 s1=t([0,1,0])
393 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
394 self.failUnless(abs(numarray.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(numarray.dot(_cross(s1,[0,1,0]),numarray.array([-1.,0.,0.]))>0.,"s1 has wrong orientation.")
397 s2=t([0,0,1])
398 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
399 self.failUnless(abs(numarray.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(numarray.dot(_cross(s2,[0,0,1]),numarray.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,numarray.NumArray),"s0 is not a numarray object.")
406 self.failUnless(self.__distance(s0,numarray.array([0.,0,-1.]))<self.ABS_TOL,"s0 is wrong.")
407 s1=t([0,5,0])
408 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
409 self.failUnless(self.__distance(s1,numarray.array([0.,5,0.]))<self.ABS_TOL,"s1 is wrong.")
410 s2=t([0,0,1])
411 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
412 self.failUnless(self.__distance(s2,numarray.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,numarray.NumArray),"s0 is not a numarray object.")
417 self.failUnless(abs(numarray.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(numarray.dot(_cross(s0,[1,0,0]),numarray.array([0.,1.,0.]))<0.,"s0 has wrong orientation.")
420 s1=t([0,5,0])
421 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
422 self.failUnless(self.__distance(s1,numarray.array([0.,5,0.]))<self.ABS_TOL,"s1 is wrong.")
423 s2=t([0,0,1])
424 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
425 self.failUnless(abs(numarray.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(numarray.dot(_cross(s2,[0,0,1]),numarray.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,numarray.NumArray),"s0 is not a numarray object.")
432 self.failUnless(abs(numarray.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(numarray.dot(_cross(s0,[1,0,0]),numarray.array([0.,1.,0.]))>0.,"s0 has wrong orientation.")
435 s1=t([0,1,0])
436 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
437 self.failUnless(self.__distance(s1,numarray.array([0.,1,0.]))<self.ABS_TOL,"s1 is wrong.")
438 s2=t([0,0,1])
439 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
440 self.failUnless(abs(numarray.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(numarray.dot(_cross(s2,[0,0,1]),numarray.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,numarray.NumArray),"s0 is not a numarray object.")
447 self.failUnless(self.__distance(s0,numarray.array([0.,0,1.]))<self.ABS_TOL,"s0 is wrong.")
448 s1=t([0,5,0])
449 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
450 self.failUnless(self.__distance(s1,numarray.array([0.,5,0.]))<self.ABS_TOL,"s1 is wrong.")
451 s2=t([0,0,1])
452 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
453 self.failUnless(self.__distance(s2,numarray.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,numarray.NumArray),"s0 is not a numarray object.")
458 self.failUnless(abs(numarray.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(numarray.dot(_cross(s0,[1,0,0]),numarray.array([0.,-1.,0.]))<0.,"s0 has wrong orientation.")
461 s1=t([0,1,0])
462 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
463 self.failUnless(self.__distance(s1,numarray.array([0.,1,0.]))<self.ABS_TOL,"s1 is wrong.")
464 s2=t([0,0,1])
465 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
466 self.failUnless(abs(numarray.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(numarray.dot(_cross(s2,[0,0,1]),numarray.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,numarray.NumArray),"s0 is not a numarray object.")
473 self.failUnless(abs(numarray.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(numarray.dot(_cross(s0,[1,0,0]),numarray.array([0.,-1.,0.]))>0.,"s0 has wrong orientation.")
476 s1=t([0,1,0])
477 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
478 self.failUnless(self.__distance(s1,numarray.array([0.,1,0.]))<self.ABS_TOL,"s1 is wrong.")
479 s2=t([0,0,1])
480 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
481 self.failUnless(abs(numarray.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(numarray.dot(_cross(s2,[0,0,1]),numarray.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,numarray.NumArray),"s0 is not a numarray object.")
488 self.failUnless(self.__distance(s0,numarray.array([0.,1,0.]))<self.ABS_TOL,"s0 is wrong.")
489 s1=t([0,5,0])
490 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
491 self.failUnless(self.__distance(s1,numarray.array([-5.,0,0.]))<self.ABS_TOL,"s1 is wrong.")
492 s2=t([0,0,1])
493 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
494 self.failUnless(self.__distance(s2,numarray.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,numarray.NumArray),"s0 is not a numarray object.")
499 self.failUnless(abs(numarray.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(numarray.dot(_cross(s0,[1,0,0]),numarray.array([0.,0.,1.]))<0.,"s0 has wrong orientation.")
502 s1=t([0,5,0])
503 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
504 self.failUnless(abs(numarray.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(numarray.dot(_cross(s1,[0,5,0]),numarray.array([0.,0.,1.]))<0.,"s1 has wrong orientation.")
507 s2=t([0,0,1])
508 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
509 self.failUnless(self.__distance(s2,numarray.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,numarray.NumArray),"s0 is not a numarray object.")
514 self.failUnless(abs(numarray.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(numarray.dot(_cross(s0,[1,0,0]),numarray.array([0.,0.,1.]))>0.,"s0 has wrong orientation.")
517 s1=t([0,5,0])
518 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
519 self.failUnless(abs(numarray.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(numarray.dot(_cross(s1,[0,1,0]),numarray.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,numarray.NumArray),"s0 is not a numarray object.")
526 self.failUnless(self.__distance(s0,numarray.array([0.,-1,0.]))<self.ABS_TOL,"s0 is wrong.")
527 s1=t([0,5,0])
528 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
529 self.failUnless(self.__distance(s1,numarray.array([5.,0,0.]))<self.ABS_TOL,"s1 is wrong.")
530 s2=t([0,0,1])
531 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
532 self.failUnless(self.__distance(s2,numarray.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,numarray.NumArray),"s0 is not a numarray object.")
537 self.failUnless(abs(numarray.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(numarray.dot(_cross(s0,[1,0,0]),numarray.array([0.,0.,-1.]))<0.,"s0 has wrong orientation.")
540 s1=t([0,1,0])
541 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
542 self.failUnless(abs(numarray.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(numarray.dot(_cross(s1,[0,1,0]),numarray.array([0.,0.,-1.]))<0.,"s1 has wrong orientation.")
545 s2=t([0,0,1])
546 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
547 self.failUnless(self.__distance(s2,numarray.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,numarray.NumArray),"s0 is not a numarray object.")
552 self.failUnless(abs(numarray.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(numarray.dot(_cross(s0,[1,0,0]),numarray.array([0.,0.,-1.]))>0.,"s0 has wrong orientation.")
555 s1=t([0,1,0])
556 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
557 self.failUnless(abs(numarray.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(numarray.dot(_cross(s1,[0,1,0]),numarray.array([0.,0.,-1.]))>0.,"s1 has wrong orientation.")
560 s2=t([0,0,1])
561 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
562 self.failUnless(self.__distance(s2,numarray.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,numarray.NumArray),"s0 is not a numarray object.")
567 self.failUnless(self.__distance(s0,numarray.array([1.,1,1.]))<self.ABS_TOL,"s0 is wrong.")
568 s1=t([0,1,0])
569 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
570 self.failUnless(self.__distance(s1,numarray.array([0.,1,2.]))<self.ABS_TOL,"s1 is wrong.")
571 s2=t([0,0,1])
572 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
573 self.failUnless(self.__distance(s2,numarray.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,numarray.NumArray),"s0 is not a numarray object.")
578 self.failUnless(self.__distance(s0,numarray.array([1.,0,0.]))<self.ABS_TOL,"s0 is wrong.")
579 s1=t([0,1,0])
580 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
581 self.failUnless(self.__distance(s1,numarray.array([1.,1,1.]))<self.ABS_TOL,"s1 is wrong.")
582 s2=t([0,0,1])
583 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
584 self.failUnless(self.__distance(s2,numarray.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,numarray.NumArray),"s0 is not a numarray object.")
589 self.failUnless(self.__distance(s0,numarray.array([1.,2,0.]))<self.ABS_TOL,"s0 is wrong.")
590 s1=t([0,1,0])
591 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
592 self.failUnless(self.__distance(s1,numarray.array([0.,1,0.]))<self.ABS_TOL,"s1 is wrong.")
593 s2=t([0,0,1])
594 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
595 self.failUnless(self.__distance(s2,numarray.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,numarray.NumArray),"s0 is not a numarray object.")
600 self.failUnless(abs(numarray.dot(s0,s0)-2.)<self.ABS_TOL,"s0 length is wrong.")
601 self.failUnless(abs(numarray.dot(s0,numarray.array([1,-1,0])))<self.ABS_TOL,"s0 angle is wrong.")
602 self.failUnless(numarray.dot(_cross(s0,[1,-1,0]),numarray.array([1.,1.,1.]))<0.,"s0 has wrong orientation.")
603 s1=t([0,1,-1])
604 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
605 self.failUnless(abs(numarray.dot(s1,s1)-2.)<self.ABS_TOL,"s1 length is wrong.")
606 self.failUnless(abs(numarray.dot(s1,numarray.array([0,1,-1])))<self.ABS_TOL,"s1 angle is wrong.")
607 self.failUnless(numarray.dot(_cross(s1,[0,1,-1]),numarray.array([1.,1.,1.]))<0.,"s1 has wrong orientation.")
608 s2=t([-1,0,1])
609 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
610 self.failUnless(abs(numarray.dot(s2,s2)-2.)<self.ABS_TOL,"s2 length is wrong.")
611 self.failUnless(abs(numarray.dot(s2,numarray.array([-1,0,1])))<self.ABS_TOL,"s2 angle is wrong.")
612 self.failUnless(numarray.dot(_cross(s2,[-1,0,1]),numarray.array([1.,1.,1.]))<0.,"s2 has wrong orientation.")
613 s3=t([1,1,1])
614 self.failUnless(isinstance(s3,numarray.NumArray),"s3 is not a numarray object.")
615 self.failUnless(self.__distance(s3,numarray.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,numarray.NumArray),"coordinates are not a numarray 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,numarray.NumArray),"new coordinates are not a numarray 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(numarray.array([-1.,-2.,-3.])),"colocation with numarray 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+numarray.array([1,1,1])
716 self.failUnless(shift_p.isColocated(Point(2,3.,4)),"applying shift by numarray failed")
717 self.failUnless(not shift_p.getID() == p.getID(),"shift by numarray has same Id")
718 self.failUnless(shift_p.getLocalScale()==3.,"shift by numarray 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-numarray.array([1,1,1])
726 self.failUnless(shift_p.isColocated(Point(0,1,2.)),"applying shift by -numarray failed")
727 self.failUnless(not shift_p.getID() == p.getID(),"shift by -numarray has same Id")
728 self.failUnless(shift_p.getLocalScale()==3.,"shift by -numarray 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+=numarray.array([1,1,1])
734 self.failUnless(p.isColocated(Point(3,4,5)),"modification by numarray 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-=numarray.array([1,1,1])
741 self.failUnless(p.isColocated(Point(1,2.,3)),"modification by -numarray 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 def test_ReverseLineSegment(self):
1189 p0=Point(0,0,0,0.1)
1190 p1=Point(1,1,1,0.2)
1191 p4=Point(1,2,3)
1192
1193 self.failUnlessRaises(TypeError,Line,p0)
1194 self.failUnlessRaises(TypeError,Line,p0,p1,p4)
1195
1196 CC0=Line(p0,p1)
1197 c=-CC0
1198
1199 self.failUnless(c.hasSameOrientation(c),"has not same orientation like itself")
1200 self.failUnless(not c.hasSameOrientation(-c),"has same orientation like -itself")
1201
1202 self.failUnless(len(c) == 2, "wrong spline curve length")
1203 self.failUnless(c.getStartPoint()==p1, "wrong start point of spline curve")
1204 self.failUnless(c.getEndPoint()==p0, "wrong end point of spline curve")
1205
1206 self.failUnless(not c.isColocated(p1),"spline is colocated with point.")
1207 self.failUnless(not c.isColocated(Line(p0,p4)),"spline is colocated with spline with different point.")
1208 self.failUnless(c.isColocated(Line(p0,p1)),"spline is not colocated with spline with same points.")
1209 self.failUnless(c.isColocated(Line(p1,p0)),"spline is not colocated with spline with same points but opposite direction.")
1210 self.failUnless(not c.isColocated(Curve(p0,p1,p4)),"spline curve is identified with curve.")
1211
1212 co=c.getControlPoints()
1213 self.failUnless(co[0]==p1, "1st control point is wrong.")
1214 self.failUnless(co[1]==p0, "2nd control point is wrong.")
1215
1216 c.setLocalScale(3.)
1217 co=c.getControlPoints()
1218 self.failUnless(co[0].getLocalScale() == 3., "new local scale of 1st control point is wrong.")
1219 self.failUnless(co[1].getLocalScale() == 3., "new local scale of 2nd control point is wrong.")
1220
1221 h=c.getPrimitives()
1222 self.failUnless(len(h) == 3, "number of primitives in history is wrong.")
1223 self.failUnless(p0 in h, "missing p0 in history.")
1224 self.failUnless(p1 in h, "missing p1 in history.")
1225 self.failUnless(CC0 in h, "missing spline curve in history.")
1226
1227 cp=c.copy()
1228 cpcp=cp.getControlPoints()
1229 self.failUnless(not cp == c, "copy returns same spline curve.")
1230 self.failUnless(c.isColocated(cp),"spline curve is not colocated with its copy.")
1231 self.failUnless(not p0 == cpcp[0],"1st point of deep copy and source are the same.")
1232 self.failUnless(not p1 == cpcp[1],"2st point of deep copy and source are the same.")
1233
1234 c.modifyBy(Dilation(-1.))
1235 cp=c.getControlPoints()
1236 self.failUnless(c.isColocated(Line(Point(0,0,0),Point(-1,-1,-1))),"inplace dilation is wrong.")
1237 self.failUnless(p1 == cp[0],"1st new point after Dilation.")
1238 self.failUnless(p0 == cp[1],"2nd new point after Dilation.")
1239
1240 dc=c.apply(Dilation(-1.))
1241 dccp=dc.getControlPoints()
1242 self.failUnless(dc.isColocated(Line(Point(0,0,0),Point(1,1,1))),"dilation is wrong.")
1243 self.failUnless(not p0 == dccp[0],"1st point of Dilation is identical to source.")
1244 self.failUnless(dccp[0].isColocated(Point(1,1,1)),"1st point of Dilation is is wrongly located.")
1245 self.failUnless(not p1 == dccp[1],"2nd point of Dilation is identical to source.")
1246 self.failUnless(dccp[1].isColocated(Point(0,0,0)),"2st point of Dilation is is wrongly located.")
1247
1248 def test_Arc(self):
1249 center=Point(0,0,0,0.1)
1250 p_start=Point(1,1,1,0.2)
1251 p_end=Point(1,2,3)
1252 p4=Point(10,2,3)
1253
1254 self.failUnlessRaises(TypeError,Arc,Primitive())
1255
1256 c=Arc(center,p_start,p_end)
1257
1258 self.failUnless(c.getCenterPoint()==center, "wrong center point")
1259 self.failUnless(c.getStartPoint()==p_start, "wrong start point")
1260 self.failUnless(c.getEndPoint()==p_end, "wrong end point")
1261
1262 self.failUnless(c.hasSameOrientation(c),"has not same orientation like itself")
1263 self.failUnless(not c.hasSameOrientation(-c),"has same orientation like -itself")
1264
1265 self.failUnless(not c.isColocated(p4),"spline is colocated with point.")
1266 self.failUnless(not c.isColocated(Arc(p4,p_start,p_end)),"spline is colocated with spline with differnt center point.")
1267 self.failUnless(not c.isColocated(Arc(center,p4,p_end)),"spline is colocated with spline with differnt start point.")
1268 self.failUnless(not c.isColocated(Arc(center,p_start,p4)),"spline is colocated with spline with differnt end point.")
1269 self.failUnless(c.isColocated(Arc(center,p_start,p_end)),"spline is not colocated with spline with same points.")
1270 self.failUnless(c.isColocated(Arc(center,p_end,p_start)),"spline is not colocated with spline with same points but opposite direction.")
1271 self.failUnless(not c.isColocated(Curve(center,p_start,p_end)),"spline curve is identified with curve.")
1272
1273 h=c.getPrimitives()
1274 self.failUnless(len(h) == 4, "number of primitives in history is wrong.")
1275 self.failUnless(center in h, "missing center in history.")
1276 self.failUnless(p_start in h, "missing p_start in history.")
1277 self.failUnless(p_end in h, "missing p_end in history.")
1278 self.failUnless(c in h, "missing spline curve in history.")
1279
1280
1281 c.setLocalScale(3.)
1282 self.failUnless(c.getCenterPoint().getLocalScale() == 3., "new local scale of center point is wrong.")
1283 self.failUnless(c.getStartPoint().getLocalScale() == 3., "new local scale of start point is wrong.")
1284 self.failUnless(c.getEndPoint().getLocalScale() == 3., "new local scale of end point is wrong.")
1285
1286 cp=c.copy()
1287 self.failUnless(isinstance(cp,Arc), "copy returns is not an arc.")
1288 self.failUnless(not cp == c, "copy returns same arc.")
1289 self.failUnless(cp.isColocated(Arc(center,p_start,p_end)),"arc is not colocated with its copy.")
1290 self.failUnless(not cp.getCenterPoint()==center, "deep copy has same center point like source")
1291 self.failUnless(not cp.getStartPoint()==p_start, "deep copy has same start point like source")
1292 self.failUnless(not cp.getEndPoint()==p_end, "deep copy has same end point like source")
1293
1294 c.modifyBy(Dilation(-1.))
1295 self.failUnless(c.isColocated(Arc(Point(0,0,0),Point(-1,-1,-1),Point(-1,-2,-3))),"inplace dilation is wrong.")
1296 self.failUnless(c.getCenterPoint() == center,"wrong center point after dilation.")
1297 self.failUnless(c.getStartPoint() == p_start,"wrong start point after dilation.")
1298 self.failUnless(c.getEndPoint() == p_end,"wrong end point after dilation.")
1299
1300 dc=c.apply(Dilation(-1.))
1301 self.failUnless(dc.isColocated(Arc(Point(0,0,0),Point(1,1,1),Point(1,2,3))),"dilation is wrong.")
1302 self.failUnless(not dc.getCenterPoint() == center,"center point of dilation is identical to source.")
1303 self.failUnless(dc.getCenterPoint().isColocated(Point(0,0,0)),"center point of dilation is wrong.")
1304 self.failUnless(not dc.getStartPoint() == p_start,"start point of dilation is identical to source.")
1305 self.failUnless(dc.getStartPoint().isColocated(Point(1,1,1)),"start point of dilation is wrong.")
1306 self.failUnless(not dc.getEndPoint() == p_end,"end point of dilation is identical to source.")
1307 self.failUnless(dc.getEndPoint().isColocated(Point(1,2,3)),"end point of dilation is wrong.")
1308
1309 def test_ReverseArc(self):
1310 center=Point(0,0,0,0.1)
1311 p_start=Point(1,1,1,0.2)
1312 p_end=Point(1,2,3)
1313 p4=Point(10,2,3)
1314
1315 self.failUnlessRaises(TypeError,Arc,Primitive())
1316
1317 CC0=Arc(center,p_start,p_end)
1318 c=-CC0
1319
1320 self.failUnless(c.getCenterPoint()==center, "wrong center point")
1321 self.failUnless(c.getStartPoint()==p_end, "wrong start point")
1322 self.failUnless(c.getEndPoint()==p_start, "wrong end point")
1323
1324 self.failUnless(c.hasSameOrientation(c),"has not same orientation like itself")
1325 self.failUnless(not c.hasSameOrientation(-c),"has same orientation like -itself")
1326
1327 self.failUnless(not c.isColocated(p4),"spline is colocated with point.")
1328 self.failUnless(not c.isColocated(Arc(p4,p_start,p_end)),"spline is colocated with spline with differnt center point.")
1329 self.failUnless(not c.isColocated(Arc(center,p4,p_end)),"spline is colocated with spline with differnt start point.")
1330 self.failUnless(not c.isColocated(Arc(center,p_start,p4)),"spline is colocated with spline with differnt end point.")
1331 self.failUnless(c.isColocated(Arc(center,p_start,p_end)),"spline is not colocated with spline with same points.")
1332 self.failUnless(c.isColocated(Arc(center,p_end,p_start)),"spline is not colocated with spline with same points but opposite direction.")
1333 self.failUnless(not c.isColocated(Curve(center,p_start,p_end)),"spline curve is identified with curve.")
1334
1335 h=c.getPrimitives()
1336 self.failUnless(len(h) == 4, "number of primitives in history is wrong.")
1337 self.failUnless(center in h, "missing center in history.")
1338 self.failUnless(p_start in h, "missing p_start in history.")
1339 self.failUnless(p_end in h, "missing p_end in history.")
1340 self.failUnless(CC0 in h, "missing spline curve in history.")
1341
1342
1343 c.setLocalScale(3.)
1344 self.failUnless(c.getCenterPoint().getLocalScale() == 3., "new local scale of center point is wrong.")
1345 self.failUnless(c.getStartPoint().getLocalScale() == 3., "new local scale of start point is wrong.")
1346 self.failUnless(c.getEndPoint().getLocalScale() == 3., "new local scale of end point is wrong.")
1347
1348 cp=c.copy()
1349 self.failUnless(isinstance(cp,ReverseArc), "copy returns is not an arc.")
1350 self.failUnless(not cp == c, "copy returns same arc.")
1351 self.failUnless(cp.isColocated(Arc(center,p_end,p_start)),"arc is not colocated with its copy.")
1352 self.failUnless(not cp.getCenterPoint()==center, "deep copy has same center point like source")
1353 self.failUnless(not cp.getStartPoint()==p_start, "deep copy has same start point like source")
1354 self.failUnless(not cp.getEndPoint()==p_end, "deep copy has same end point like source")
1355
1356 c.modifyBy(Dilation(-1.))
1357 self.failUnless(c.isColocated(Arc(Point(0,0,0),Point(-1,-1,-1),Point(-1,-2,-3))),"inplace dilation is wrong.")
1358 self.failUnless(c.getCenterPoint() == center,"wrong center point after dilation.")
1359 self.failUnless(c.getStartPoint() == p_end,"wrong start point after dilation.")
1360 self.failUnless(c.getEndPoint() == p_start,"wrong end point after dilation.")
1361
1362 dc=c.apply(Dilation(-1.))
1363 self.failUnless(dc.isColocated(Arc(Point(0,0,0),Point(1,1,1),Point(1,2,3))),"dilation is wrong.")
1364 self.failUnless(not dc.getCenterPoint() == center,"center point of dilation is identical to source.")
1365 self.failUnless(dc.getCenterPoint().isColocated(Point(0,0,0)),"center point of dilation is wrong.")
1366 self.failUnless(not dc.getStartPoint() == p_start,"start point of dilation is identical to source.")
1367 self.failUnless(dc.getStartPoint().isColocated(Point(1,2,3)),"start point of dilation is wrong.")
1368 self.failUnless(not dc.getEndPoint() == p_end,"end point of dilation is identical to source.")
1369 self.failUnless(dc.getEndPoint().isColocated(Point(1,1,1)),"end point of dilation is wrong.")
1370
1371 def test_Ellipse(self):
1372 center=Point(0,0,0,0.1)
1373 main_axis_point=Point(0,1,0,0.1)
1374 p_start=Point(1,1,1,0.2)
1375 p_end=Point(1,2,3)
1376 p4=Point(10,2,3)
1377
1378 self.failUnlessRaises(TypeError,Ellipse,Primitive())
1379 self.failUnlessRaises(TypeError,Ellipse,center,center,p_start,p_end)
1380 self.failUnlessRaises(TypeError,Ellipse,center,main_axis_point,p_start,p_start)
1381
1382
1383 c=Ellipse(center,main_axis_point,p_start,p_end)
1384
1385 self.failUnless(c.getCenterPoint()==center, "wrong center point")
1386 self.failUnless(c.getStartPoint()==p_start, "wrong start point")
1387 self.failUnless(c.getEndPoint()==p_end, "wrong end point")
1388 self.failUnless(c.getPointOnMainAxis()==main_axis_point, "wrong point on main axis")
1389
1390 self.failUnless(c.hasSameOrientation(c),"has not same orientation like itself")
1391 self.failUnless(not c.hasSameOrientation(-c),"has same orientation like -itself")
1392
1393 self.failUnless(not c.isColocated(p4),"spline is colocated with point.")
1394 self.failUnless(not c.isColocated(Ellipse(center,main_axis_point,p4,p_end)),"spline is colocated with spline with differnt start point.")
1395 self.failUnless(not c.isColocated(Ellipse(center,main_axis_point,p_start,p4)),"spline is colocated with spline with differnt end point.")
1396 self.failUnless(not c.isColocated(Ellipse(center,p4,p_start,p_end)),"spline is colocated with spline with differnt main axis point.")
1397 self.failUnless(not c.isColocated(Ellipse(p4,main_axis_point,p_start,p_end)),"spline is colocated with spline with differnt center.")
1398 self.failUnless(c.isColocated(Ellipse(center,main_axis_point,p_start,p_end)),"spline is not colocated with spline with same points.")
1399 self.failUnless(c.isColocated(Ellipse(center,main_axis_point,p_start,p_end)),"spline is not colocated with spline with same points.")
1400 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.")
1401 self.failUnless(not c.isColocated(Curve(center,main_axis_point,p_start,p_end)),"spline curve is identified with curve.")
1402
1403 h=c.getPrimitives()
1404 self.failUnless(len(h) == 5, "number of primitives in history is wrong.")
1405 self.failUnless(center in h, "missing center in history.")
1406 self.failUnless(p_start in h, "missing p_start in history.")
1407 self.failUnless(p_end in h, "missing p_end in history.")
1408 self.failUnless(main_axis_point in h, "missing main_axis_point in history.")
1409 self.failUnless(c in h, "missing spline curve in history.")
1410
1411
1412 c.setLocalScale(3.)
1413 self.failUnless(c.getCenterPoint().getLocalScale() == 3., "new local scale of center point is wrong.")
1414 self.failUnless(c.getStartPoint().getLocalScale() == 3., "new local scale of start point is wrong.")
1415 self.failUnless(c.getEndPoint().getLocalScale() == 3., "new local scale of end point is wrong.")
1416 self.failUnless(c.getPointOnMainAxis().getLocalScale() == 3., "new local scale of point on main axis is wrong.")
1417
1418 cp=c.copy()
1419 self.failUnless(isinstance(cp,Ellipse), "copy returns is not an arc.")
1420 self.failUnless(not cp == c, "copy returns same arc.")
1421 self.failUnless(cp.isColocated(Ellipse(center,main_axis_point,p_start,p_end)),"arc is not colocated with its copy.")
1422 self.failUnless(not cp.getCenterPoint()==center, "deep copy has same center point like source")
1423 self.failUnless(not cp.getStartPoint()==p_start, "deep copy has same start point like source")
1424 self.failUnless(not cp.getEndPoint()==p_end, "deep copy has same end point like source")
1425 self.failUnless(not cp.getPointOnMainAxis()==main_axis_point, "deep copy has same point on main axis like source")
1426
1427 c.modifyBy(Dilation(-1.))
1428 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.")
1429 self.failUnless(c.getCenterPoint() == center,"wrong center point after dilation.")
1430 self.failUnless(c.getStartPoint() == p_start,"wrong start point after dilation.")
1431 self.failUnless(c.getEndPoint() == p_end,"wrong end point after dilation.")
1432 self.failUnless(c.getPointOnMainAxis() == main_axis_point,"wrong point on main axis after dilation.")
1433
1434 #=====================
1435 dc=c.apply(Dilation(-1.))
1436 self.failUnless(dc.isColocated(Ellipse(Point(0,0,0),Point(0,1,0),Point(1,1,1),Point(1,2,3))),"dilation is wrong.")
1437 self.failUnless(not dc.getCenterPoint() == center,"center point of dilation is identical to source.")
1438 self.failUnless(dc.getCenterPoint().isColocated(Point(0,0,0)),"center point of dilation is wrong.")
1439 self.failUnless(not dc.getStartPoint() == p_start,"start point of dilation is identical to source.")
1440 self.failUnless(dc.getStartPoint().isColocated(Point(1,1,1)),"start point of dilation is wrong.")
1441 self.failUnless(not dc.getEndPoint() == p_end,"end point of dilation is identical to source.")
1442 self.failUnless(dc.getEndPoint().isColocated(Point(1,2,3)),"end point of dilation is wrong.")
1443 self.failUnless(not dc.getPointOnMainAxis() == main_axis_point,"point on main axis is identical to source.")
1444 self.failUnless(dc.getPointOnMainAxis().isColocated(Point(0,1,0)),"point on main axis of dilation is wrong.")
1445
1446 def test_ReverseEllipse(self):
1447 center=Point(0,0,0,0.1)
1448 main_axis_point=Point(0,1,0,0.1)
1449 p_start=Point(1,1,1,0.2)
1450 p_end=Point(1,2,3)
1451 p4=Point(10,2,3)
1452
1453 self.failUnlessRaises(TypeError,Ellipse,Primitive())
1454
1455 CC0=Ellipse(center,main_axis_point,p_start,p_end)
1456 c=-CC0
1457
1458 self.failUnless(c.getCenterPoint()==center, "wrong center point")
1459 self.failUnless(c.getStartPoint()==p_end, "wrong start point")
1460 self.failUnless(c.getEndPoint()==p_start, "wrong end point")
1461 self.failUnless(c.getPointOnMainAxis()==main_axis_point, "wrong point on main axis")
1462
1463 self.failUnless(c.hasSameOrientation(c),"has not same orientation like itself")
1464 self.failUnless(not c.hasSameOrientation(-c),"has same orientation like -itself")
1465
1466 self.failUnless(not c.isColocated(p4),"spline is colocated with point.")
1467 self.failUnless(not c.isColocated(Ellipse(center,main_axis_point,p4,p_start)),"spline is colocated with spline with differnt start point.")
1468 self.failUnless(not c.isColocated(Ellipse(center,main_axis_point,p_end,p4)),"spline is colocated with spline with differnt end point.")
1469 self.failUnless(not c.isColocated(Ellipse(center,p4,p_end,p_start)),"spline is colocated with spline with differnt main axis point.")
1470 self.failUnless(not c.isColocated(Ellipse(p4,main_axis_point,p_end,p_start)),"spline is colocated with spline with differnt center.")
1471 self.failUnless(c.isColocated(Ellipse(center,main_axis_point,p_end,p_start)),"spline is not colocated with spline with same points.")
1472 self.failUnless(c.isColocated(Ellipse(center,main_axis_point,p_end,p_start)),"spline is not colocated with spline with same points.")
1473 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.")
1474 self.failUnless(not c.isColocated(Curve(center,main_axis_point,p_start,p_end)),"spline curve is identified with curve.")
1475
1476 h=c.getPrimitives()
1477 self.failUnless(len(h) == 5, "number of primitives in history is wrong.")
1478 self.failUnless(center in h, "missing center in history.")
1479 self.failUnless(p_start in h, "missing p_start in history.")
1480 self.failUnless(p_end in h, "missing p_end in history.")
1481 self.failUnless(main_axis_point in h, "missing main_axis_point in history.")
1482 self.failUnless(CC0 in h, "missing spline curve in history.")
1483
1484
1485 c.setLocalScale(3.)
1486 self.failUnless(c.getCenterPoint().getLocalScale() == 3., "new local scale of center point is wrong.")
1487 self.failUnless(c.getStartPoint().getLocalScale() == 3., "new local scale of start point is wrong.")
1488 self.failUnless(c.getEndPoint().getLocalScale() == 3., "new local scale of end point is wrong.")
1489 self.failUnless(c.getPointOnMainAxis().getLocalScale() == 3., "new local scale of point on main axis is wrong.")
1490
1491 cp=c.copy()
1492 self.failUnless(isinstance(cp,ReverseEllipse), "copy returns is not an arc.")
1493 self.failUnless(not cp == c, "copy returns same arc.")
1494 self.failUnless(cp.isColocated(Ellipse(center,main_axis_point,p_end,p_start)),"arc is not colocated with its copy.")
1495 self.failUnless(not cp.getCenterPoint()==center, "deep copy has same center point like source")
1496 self.failUnless(not cp.getStartPoint()==p_start, "deep copy has same start point like source")
1497 self.failUnless(not cp.getEndPoint()==p_end, "deep copy has same end point like source")
1498 self.failUnless(not cp.getPointOnMainAxis()==main_axis_point, "deep copy has same point on main axis like source")
1499
1500 c.modifyBy(Dilation(-1.))
1501 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.")
1502 self.failUnless(c.getCenterPoint() == center,"wrong center point after dilation.")
1503 self.failUnless(c.getStartPoint() == p_end,"wrong start point after dilation.")
1504 self.failUnless(c.getEndPoint() == p_start,"wrong end point after dilation.")
1505 self.failUnless(c.getPointOnMainAxis() == main_axis_point,"wrong point on main axis after dilation.")
1506
1507 dc=c.apply(Dilation(-1.))
1508 self.failUnless(dc.isColocated(Ellipse(Point(0,0,0),Point(0,1,0),Point(1,1,1),Point(1,2,3))),"dilation is wrong.")
1509 self.failUnless(not dc.getCenterPoint() == center,"center point of dilation is identical to source.")
1510 self.failUnless(dc.getCenterPoint().isColocated(Point(0,0,0)),"center point of dilation is wrong.")
1511 self.failUnless(not dc.getStartPoint() == p_start,"start point of dilation is identical to source.")
1512 self.failUnless(dc.getStartPoint().isColocated(Point(1,2,3)),"start point of dilation is wrong.")
1513 self.failUnless(not dc.getEndPoint() == p_end,"end point of dilation is identical to source.")
1514 self.failUnless(dc.getEndPoint().isColocated(Point(1,1,1)),"end point of dilation is wrong.")
1515 self.failUnless(not dc.getPointOnMainAxis() == main_axis_point,"point on main axis is identical to source.")
1516 self.failUnless(dc.getPointOnMainAxis().isColocated(Point(0,1,0)),"point on main axis of dilation is wrong.")
1517
1518 def test_CurveLoop(self):
1519 p0=Point(0,0,0,0.1)
1520 p1=Point(1,1,1,0.2)
1521 p2=Point(2,2,2,0.3)
1522 p3=Point(3,3,3,0.4)
1523 p4=Point(1,2,3)
1524 p5=Point(10,20,3)
1525 p6=Point(1,2,30)
1526
1527 l01=Line(p0,p1)
1528 l12=Arc(p3,p1,p2)
1529 l20=Spline(p2,p4,p0)
1530
1531 lx=Line(p2,p3)
1532 ly=Line(p3,p1)
1533
1534 c=CurveLoop(l01,l12,l20)
1535 # self.failUnlessRaises(ValueError,CurveLoop,l01,lx,l20)
1536 # self.failUnlessRaises(ValueError,CurveLoop,l01,l20,l20)
1537 # self.failUnlessRaises(ValueError,CurveLoop,l01,l20,ly)
1538
1539 c=CurveLoop(l01,l20,l12)
1540 self.failUnless(c.hasSameOrientation(c),"has not same orientation like itself")
1541 self.failUnless(not c.hasSameOrientation(-c),"has same orientation like -itself")
1542
1543 self.failUnless(not c.isColocated(p4),"CurveLoop is colocated with point.")
1544 self.failUnless(c.isColocated(c),"CurveLoop is not colocated with its self.")
1545 self.failUnless(c.isColocated(CurveLoop(l01,l12,l20)),"CurveLoop is not colocated with its copy.")
1546 self.failUnless(c.isColocated(CurveLoop(l20,l01,l12)),"CurveLoop is not colocated with its copy with shifted points.")
1547 self.failUnless(c.isColocated(CurveLoop(l20,l12,l01)),"CurveLoop is not colocated with its copy with shuffled points.")
1548 self.failUnless(not c.isColocated(CurveLoop(lx,ly,l12)),"CurveLoop is colocated with different CurveLoop.")
1549
1550 self.failUnless(len(c) == 3, "wrong length")
1551
1552 c.setLocalScale(3.)
1553 self.failUnless(p0.getLocalScale()==3., "p0 has wrong local scale.")
1554 self.failUnless(p1.getLocalScale()==3., "p1 has wrong local scale.")
1555 self.failUnless(p2.getLocalScale()==3., "p2 has wrong local scale.")
1556 self.failUnless(p4.getLocalScale()==3., "p4 has wrong local scale.")
1557
1558
1559 cc=c.getCurves()
1560 self.failUnless(len(cc) == 3, "too many curves.")
1561 self.failUnless(l01 in cc, "l01 is missing")
1562 self.failUnless(l12 in cc, "l12 is missing")
1563 self.failUnless(l20 in cc, "l20 is missing")
1564
1565 p=c.getPrimitives()
1566 self.failUnless(len(p) == 9, "too many primitives.")
1567 self.failUnless(l01 in p, "l01 is missing")
1568 self.failUnless(l12 in p, "l21 is missing")
1569 self.failUnless(l20 in p, "l20 is missing")
1570 self.failUnless(p0 in p, "p0 is missing")
1571 self.failUnless(p1 in p, "p1 is missing")
1572 self.failUnless(p2 in p, "p2 is missing")
1573 self.failUnless(p3 in p, "p3 is missing")
1574 self.failUnless(p4 in p, "p4 is missing")
1575
1576 cp=c.copy()
1577 self.failUnless(isinstance(cp,CurveLoop), "copy returns is not an arc.")
1578 self.failUnless(not cp == c, "copy equals source")
1579 self.failUnless(cp.isColocated(c),"copy is not colocated with its source.")
1580 cc=cp.getCurves()
1581 self.failUnless(len(cc) == 3, "too many primitives in copy.")
1582 self.failUnless(not l01 in cc,"copy uses l01.")
1583 self.failUnless(not l12 in cc,"copy uses l12.")
1584 self.failUnless(not l20 in cc,"copy uses l20.")
1585
1586 p0_m=Point(0,0,0)
1587 p1_m=Point(-1,-1,-1)
1588 p2_m=Point(-2,-2,-2)
1589 p3_m=Point(-3,-3,-3)
1590 p4_m=Point(-1,-2,-3)
1591
1592 l01_m=Line(p0_m,p1_m)
1593 l12_m=Arc(p3_m,p1_m,p2_m)
1594 l20_m=Spline(p2_m,p4_m,p0_m)
1595
1596 dc=c.apply(Dilation(-1.))
1597 self.failUnless(dc.isColocated(CurveLoop(l01_m,l12_m,l20_m)),"dilation is wrong.")
1598 cc=dc.getCurves()
1599 self.failUnless(len(cc) == 3, "too many primitives in dilation result.")
1600 self.failUnless(not l01 in cc,"l01 is in dilation result.")
1601 self.failUnless(not l12 in cc,"l12 is in dilation result.")
1602 self.failUnless(not l20 in cc,"l20 is in dilation result.")
1603
1604 c.modifyBy(Dilation(-1.))
1605 self.failUnless(c.isColocated(CurveLoop(l01_m,l12_m,l20_m)),"inplace dilation is wrong.")
1606 cc=c.getCurves()
1607 self.failUnless(len(cc) == 3, "too many primitives in modified object.")
1608 self.failUnless(l01 in cc,"l01 missed in modified object.")
1609 self.failUnless(cc[cc.index(l01)].hasSameOrientation(l01),"l01 in modified object has wrong orientation.")
1610 self.failUnless(l12 in cc,"l12 missed in modified object.")
1611 self.failUnless(cc[cc.index(l12)].hasSameOrientation(l12),"l12 in modified object has wrong orientation.")
1612 self.failUnless(l20 in cc,"l20 missed in modified object.")
1613 self.failUnless(cc[cc.index(l20)].hasSameOrientation(l20),"l20 in modified object has wrong orientation.")
1614
1615 def test_ReverseCurveLoop(self):
1616 p0=Point(0,0,0,0.1)
1617 p1=Point(1,1,1,0.2)
1618 p2=Point(2,2,2,0.3)
1619 p3=Point(3,3,3,0.4)
1620 p4=Point(1,2,3)
1621 p5=Point(10,20,3)
1622 p6=Point(1,2,30)
1623
1624 l01=Line(p0,p1)
1625 l12=Arc(p3,p1,p2)
1626 l20=Spline(p2,p4,p0)
1627
1628 lx=Line(p2,p3)
1629 ly=Line(p3,p1)
1630
1631 CC0=CurveLoop(l01,l20,l12)
1632 c=-CC0
1633
1634 self.failUnless(c.hasSameOrientation(c),"has not same orientation like itself")
1635 self.failUnless(not c.hasSameOrientation(-c),"has same orientation like -itself")
1636
1637 self.failUnless(not c.isColocated(p4),"-CurveLoop is colocated with point.")
1638 self.failUnless(c.isColocated(c),"-CurveLoop is not colocated with its self.")
1639 self.failUnless(c.isColocated(CurveLoop(l01,l12,l20)),"-CurveLoop is not colocated with its copy.")
1640 self.failUnless(c.isColocated(CurveLoop(l20,l01,l12)),"-CurveLoop is not colocated with its copy with shifted points.")
1641 self.failUnless(c.isColocated(CurveLoop(l20,l12,l01)),"-CurveLoop is not colocated with its copy with shuffled points.")
1642 self.failUnless(not c.isColocated(CurveLoop(lx,ly,l12)),"-CurveLoop is colocated with different CurveLoop.")
1643
1644 self.failUnless(len(c) == 3, "wrong length")
1645
1646 c.setLocalScale(3.)
1647 self.failUnless(p0.getLocalScale()==3., "p0 has wrong local scale.")
1648 self.failUnless(p1.getLocalScale()==3., "p1 has wrong local scale.")
1649 self.failUnless(p2.getLocalScale()==3., "p2 has wrong local scale.")
1650 self.failUnless(p4.getLocalScale()==3., "p4 has wrong local scale.")
1651
1652
1653 cc=c.getCurves()
1654 self.failUnless(len(cc) == 3, "too many curves.")
1655 self.failUnless(l01 in cc, "l01 is missing")
1656 self.failUnless(l12 in cc, "l12 is missing")
1657 self.failUnless(l20 in cc, "l20 is missing")
1658
1659 p=c.getPrimitives()
1660 self.failUnless(len(p) == 9, "too many primitives.")
1661 self.failUnless(l01 in p, "l01 is missing")
1662 self.failUnless(l12 in p, "l21 is missing")
1663 self.failUnless(l20 in p, "l20 is missing")
1664 self.failUnless(p0 in p, "p0 is missing")
1665 self.failUnless(p1 in p, "p1 is missing")
1666 self.failUnless(p2 in p, "p2 is missing")
1667 self.failUnless(p3 in p, "p3 is missing")
1668 self.failUnless(p4 in p, "p4 is missing")
1669
1670 cp=c.copy()
1671 self.failUnless(isinstance(cp,ReverseCurveLoop), "copy returns is not an ReverseCurveLoop.")
1672 self.failUnless(not cp == c, "copy equals source")
1673 self.failUnless(cp.isColocated(c),"copy is not colocated with its source.")
1674 cc=cp.getCurves()
1675 self.failUnless(len(cc) == 3, "too many primitives in copy.")
1676 self.failUnless(not l01 in cc,"copy uses l01.")
1677 self.failUnless(not l12 in cc,"copy uses l12.")
1678 self.failUnless(not l20 in cc,"copy uses l20.")
1679
1680 p0_m=Point(0,0,0)
1681 p1_m=Point(-1,-1,-1)
1682 p2_m=Point(-2,-2,-2)
1683 p3_m=Point(-3,-3,-3)
1684 p4_m=Point(-1,-2,-3)
1685
1686 l01_m=Line(p0_m,p1_m)
1687 l12_m=Arc(p3_m,p1_m,p2_m)
1688 l20_m=Spline(p2_m,p4_m,p0_m)
1689
1690 dc=c.apply(Dilation(-1.))
1691 self.failUnless(dc.isColocated(CurveLoop(l01_m,l12_m,l20_m)),"dilation is wrong.")
1692 cc=dc.getCurves()
1693 self.failUnless(len(cc) == 3, "too many primitives in dilation result.")
1694 self.failUnless(not l01 in cc,"l01 is in dilation result.")
1695 self.failUnless(not l12