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