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