/[escript]/branches/stage3.1/pycad/test/python/run_pycad_test.py
ViewVC logotype

Contents of /branches/stage3.1/pycad/test/python/run_pycad_test.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2945 - (show annotations)
Wed Feb 24 00:17:46 2010 UTC (8 years, 11 months ago) by jfenwick
File MIME type: text/x-python
File size: 231294 byte(s)
Bringing release stage up to trunk version 2944

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