/[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 2344 - (show annotations)
Mon Mar 30 02:13:58 2009 UTC (10 years, 5 months ago) by jfenwick
File MIME type: text/x-python
File size: 229113 byte(s)
Change __url__ to launchpad site

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