/[escript]/trunk/pycad/test/python/run_pycad_test.py
ViewVC logotype

Contents of /trunk/pycad/test/python/run_pycad_test.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1045 - (show annotations)
Tue Mar 20 01:30:58 2007 UTC (13 years ago) by gross
File MIME type: text/x-python
File size: 214836 byte(s)
some modifications on the pycad implementation to make it easier to build
interfaces for other mesh generators. The script statement generation is now
done by the Design and not the Primitive classes.


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