Debian Codegraph @

src/python/PyImathTest/main.cpp

raw
1 //
2 // SPDX-License-Identifier: BSD-3-Clause
3 // Copyright Contributors to the OpenEXR Project.
4 //
5
6 #ifdef NDEBUG
7 # undef NDEBUG
8 #endif
9
10 #include <boost/python.hpp>
11 #include <boost/python/handle.hpp>
12 #include <boost/python/object.hpp>
13 #include <ImathMath.h>
14 #include <PyImathBox.h>
15 #include <PyImathColor.h>
16 #include <PyImathEuler.h>
17 #include <PyImathFrustum.h>
18 #include <PyImathLine.h>
19 #include <PyImathMatrix.h>
20 #include <PyImathPlane.h>
21 #include <PyImathQuat.h>
22 #include <PyImathRandom.h>
23 #include <PyImathVec.h>
24 #include <PyImathShear.h>
25
26 #include <testStringTable.h>
27
28 using namespace boost::python;
29
30 #define TEST(x) if (argc < 2 || !strcmp (argv[1], #x)) x();
31
32 PyObject *
33 wrapTester (PyObject * /* self */, PyObject *args)
34 {
35 try {
36
37 char *type;
38 if (PyArg_ParseTuple (args, "s", &type))
39 {
40 std::string typeStr (type);
41
42 if (typeStr == "Box2i")
43 return PyImath::Box2i::wrap (Imath::Box2i (Imath::V2i (1, 2),
44 Imath::V2i (3, 4)));
45 else if (typeStr == "Box2f")
46 return PyImath::Box2f::wrap (Imath::Box2f (Imath::V2f (1.1f, 2.2f),
47 Imath::V2f (3.3f, 4.4f)));
48 else if (typeStr == "Box2d")
49 return PyImath::Box2d::wrap (Imath::Box2d (Imath::V2d (1.1, 2.2),
50 Imath::V2d (3.3, 4.4)));
51
52 if (typeStr == "Box3i")
53 return PyImath::Box3i::wrap (Imath::Box3i (Imath::V3i (1, 2, 3),
54 Imath::V3i (4, 5, 6)));
55 else if (typeStr == "Box3f")
56 return PyImath::Box3f::wrap (Imath::Box3f (Imath::V3f (1.1f, 2.2f, 3.3f),
57 Imath::V3f (4.4f, 5.5f, 6.6f)));
58 else if (typeStr == "Box3d")
59 return PyImath::Box3d::wrap (Imath::Box3d (Imath::V3d (1.1, 2.2, 3.3),
60 Imath::V3d (4.4, 5.5, 6.6)));
61
62 else if (typeStr == "Color3c")
63 return PyImath::Color3c::wrap (Imath::Color3c (1, 2, 3));
64 else if (typeStr == "Color3f")
65 return PyImath::Color3f::wrap (Imath::Color3f (1.1f, 2.2f, 3.3f));
66
67 else if (typeStr == "Color4c")
68 return PyImath::Color4c::wrap (Imath::Color4c (1, 2, 3, 4));
69 else if (typeStr == "Color4f")
70 return PyImath::Color4f::wrap (Imath::Color4f (1.1f, 2.2f, 3.3f, 4.4f));
71
72 else if (typeStr == "Eulerf")
73 return PyImath::Eulerf::wrap (Imath::Eulerf (Imath::V3f (1.1f, 2.2f, 3.3f),
74 Imath::Eulerf::XZY));
75 else if (typeStr == "Eulerd")
76 return PyImath::Eulerd::wrap (Imath::Eulerd (Imath::V3d (1.1f, 2.2f, 3.3f),
77 Imath::Eulerd::XZY));
78
79 else if (typeStr == "Frustumf")
80 return PyImath::Frustumf::wrap (Imath::Frustumf (1.1f, 2.2f, 3.3f,
81 4.4f, 5.5f, 6.6f));
82 else if (typeStr == "Frustumd")
83 return PyImath::Frustumd::wrap (Imath::Frustumd (1.1, 2.2, 3.3,
84 4.4, 5.5, 6.6));
85
86 else if (typeStr == "Line3f")
87 return PyImath::Line3f::wrap (Imath::Line3f (Imath::V3f (1.1f, 2.2f, 3.3f),
88 Imath::V3f (4.4f, 5.5f, 6.6f)));
89 else if (typeStr == "Line3d")
90 return PyImath::Line3d::wrap (Imath::Line3d (Imath::V3d (1.1, 2.2, 3.3),
91 Imath::V3d (4.4, 5.5, 6.6)));
92
93 else if (typeStr == "M33f")
94 return PyImath::M33f::wrap (Imath::M33f (1.1f, 2.2f, 3.3f,
95 4.4f, 5.5f, 6.6f,
96 7.7f, 8.8f, 9.9f));
97 else if (typeStr == "M33d")
98 return PyImath::M33d::wrap (Imath::M33d (1.1, 2.2, 3.3,
99 4.4, 5.5, 6.6,
100 7.7, 8.8, 9.9));
101
102 else if (typeStr == "M44f")
103 return PyImath::M44f::wrap (Imath::M44f (1.1f, 2.2f, 3.3f, 4.4f,
104 5.5f, 6.6f, 7.7f, 8.8f,
105 9.9f, 10.10f, 11.11f, 12.12f,
106 13.13f, 14.14f, 15.15f, 16.16f));
107 else if (typeStr == "M44d")
108 return PyImath::M44d::wrap (Imath::M44d (1.1, 2.2, 3.3, 4.4,
109 5.5, 6.6, 7.7, 8.8,
110 9.9, 10.10, 11.11, 12.12,
111 13.13, 14.14, 15.15, 16.16));
112
113 else if (typeStr == "Plane3f")
114 return PyImath::Plane3f::wrap (Imath::Plane3f (Imath::V3f (1.1f, 2.2f, 3.3f), 4.4f));
115 else if (typeStr == "Plane3d")
116 return PyImath::Plane3d::wrap (Imath::Plane3d (Imath::V3d (1.1, 2.2, 3.3), 4.4));
117
118 else if (typeStr == "Quatf")
119 return PyImath::Quatf::wrap (Imath::Quatf (1.1f, 2.2f, 3.3f, 4.4f));
120 else if (typeStr == "Quatd")
121 return PyImath::Quatd::wrap (Imath::Quatd (1.1, 2.2, 3.3, 4.4));
122
123 else if (typeStr == "Rand32")
124 return PyImath::Rand32::wrap (Imath::Rand32 ());
125 else if (typeStr == "Rand48")
126 return PyImath::Rand48::wrap (Imath::Rand48 ());
127
128 else if (typeStr == "Shear6f")
129 return PyImath::Shear6f::wrap (Imath::Shear6f (1.1f, 2.2f, 3.3f,
130 4.4f, 5.5f, 6.6f));
131 else if (typeStr == "Shear6d")
132 return PyImath::Shear6d::wrap (Imath::Shear6d (1.1, 2.2, 3.3,
133 4.4, 5.5, 6.6));
134
135 else if (typeStr == "V2i")
136 return PyImath::V2i::wrap (Imath::V2i (1, 2));
137 else if (typeStr == "V2f")
138 return PyImath::V2f::wrap (Imath::V2f (1.1f, 2.2f));
139 else if (typeStr == "V2d")
140 return PyImath::V2d::wrap (Imath::V2d (1.1, 2.2));
141
142 else if (typeStr == "V3i")
143 return PyImath::V3i::wrap (Imath::V3i (1, 2, 3));
144 else if (typeStr == "V3f")
145 return PyImath::V3f::wrap (Imath::V3f (1.1f, 2.2f, 3.3f));
146 else if (typeStr == "V3d")
147 return PyImath::V3d::wrap (Imath::V3d (1.1, 2.2, 3.3));
148 }
149 PyErr_Clear();
150
151 PyErr_SetString(PyExc_TypeError, "wrap testing failed");
152 }
153 catch (const boost::python::error_already_set& e) \
154 { \
155 return 0; \
156 } \
157 catch (...) \
158 { \
159 boost::python::handle_exception(); \
160 return 0; \
161 }
162
163 return 0;
164 }
165
166 PyMethodDef methods[] =
167 {
168 {"wrap", (PyCFunction) wrapTester, METH_VARARGS, ""}, {0, 0}
169 };
170
171 void
172 initWrapTester ()
173 {
174 #if PY_MAJOR_VERSION >= 3
175 static struct PyModuleDef moduleDef =
176 {
177 PyModuleDef_HEAD_INIT,
178 "wrap",
179 "wrap module",
180 -1,
181 methods
182 };
183
184 PyObject* module = PyModule_Create(&moduleDef);
185 assert (module != 0);
186 // I (jyost) don't know if there's a better way to do the following,
187 // but this works. (I did look at the docs and try various things to
188 // see if I could find a better way, and this is what I landed on.)
189 auto sysModule = PyImport_AddModule("sys");
190 auto sysModuleDict = PyModule_GetDict(sysModule);
191 auto modulesDict = PyDict_GetItemString(sysModuleDict, "modules");
192 PyDict_SetItemString(modulesDict, moduleDef.m_name, module);
193 #else
194 PyObject *module = Py_InitModule ("wrap", methods);
195 assert (module != 0);
196 #endif
197 }
198
199
200 void
201 testBox2 ()
202 {
203 object mainModule ((handle<> (borrowed (PyImport_AddModule ("__main__")))));
204 object mainNamespace = mainModule.attr ("__dict__");
205
206 std::cerr << "Testing Box2*:\n";
207
208 std::string code =
209 "from imath import *\n"
210 "b2i = Box2i ((1, 2), (3, 4))\n"
211 "b2f = Box2f ((5.5, 6.6), (7.7, 8.8))\n"
212 "b2d = Box2d ((9.9, 10.10), (11.11, 12.12))\n"
213 "t2i = ((1, 2), (3, 4))\n"
214 "t2V2i = (V2i (1, 2), V2i (3, 4))\n"
215 "t2iMix = (V2i (1, 2), (3, 4))\n"
216 "t2f = ((5.5, 6.6), (7.7, 8.8))\n"
217 "t2V2f = (V2f (5.5, 6.6), V2f (7.7, 8.8))\n"
218 "t2fMix = (V2f (5.5, 6.6), (7.7, 8.8))\n"
219 "t2V2d = (V2d (9.9, 10.10), V2d (11.11, 12.12))\n"
220 "t2dMix = (V2d (9.9, 10.10), (11.11, 12.12))\n"
221 "i = 1\n"
222 "from wrap import *\n"
223 "w = wrap ('Box2i')\n"
224 "assert w == Box2i ((1, 2), (3, 4))\n"
225 "w = wrap ('Box2f')\n"
226 "assert w.min().equalWithAbsError ((1.1, 2.2), 1e-7)\n"
227 "assert w.max().equalWithAbsError ((3.3, 4.4), 1e-7)\n"
228 "w = wrap ('Box2d')\n"
229 "assert w.min().equalWithAbsError ((1.1, 2.2), 1e-7)\n"
230 "assert w.max().equalWithAbsError ((3.3, 4.4), 1e-7)\n";
231
232 handle<> ignored (PyRun_String (code.c_str(), Py_file_input,
233 mainNamespace.ptr(), mainNamespace.ptr()));
234 //
235
236 extract <object> eb2i (mainNamespace ["b2i"]);
237 assert (eb2i.check());
238
239 PyObject *b2iObj = eb2i().ptr();
240 assert (b2iObj != 0);
241
242 extract <object> eb2f (mainNamespace ["b2f"]);
243 assert (eb2f.check());
244
245 PyObject *b2fObj = eb2f().ptr();
246 assert (b2fObj != 0);
247
248 extract <object> eb2d (mainNamespace ["b2d"]);
249 assert (eb2d.check());
250
251 PyObject *b2dObj = eb2d().ptr();
252 assert (b2dObj != 0);
253
254 extract <object> et2i (mainNamespace["t2i"]);
255 assert (et2i.check());
256
257 PyObject *t2iObj = et2i().ptr();
258 assert (t2iObj != 0);
259
260 extract <object> et2V2i (mainNamespace["t2V2i"]);
261 assert (et2V2i.check());
262
263 PyObject *t2V2iObj = et2V2i().ptr();
264 assert (t2V2iObj != 0);
265
266 extract <object> et2iMix (mainNamespace["t2iMix"]);
267 assert (et2iMix.check());
268
269 PyObject *t2iMixObj = et2iMix().ptr();
270 assert (t2iMixObj != 0);
271
272 extract <object> et2f (mainNamespace["t2f"]);
273 assert (et2f.check());
274
275 PyObject *t2fObj = et2f().ptr();
276 assert (t2fObj != 0);
277
278 extract <object> et2V2f (mainNamespace["t2V2f"]);
279 assert (et2V2f.check());
280
281 PyObject *t2V2fObj = et2V2f().ptr();
282 assert (t2V2fObj != 0);
283
284 extract <object> et2fMix (mainNamespace["t2fMix"]);
285 assert (et2fMix.check());
286
287 PyObject *t2fMixObj = et2fMix().ptr();
288 assert (t2fMixObj != 0);
289
290 extract <object> et2V2d (mainNamespace["t2V2d"]);
291 assert (et2V2d.check());
292
293 PyObject *t2V2dObj = et2V2d().ptr();
294 assert (t2V2dObj != 0);
295
296 extract <object> et2dMix (mainNamespace["t2dMix"]);
297 assert (et2dMix.check());
298
299 PyObject *t2dMixObj = et2dMix().ptr();
300 assert (t2dMixObj != 0);
301
302 extract <object> ei (mainNamespace["i"]);
303 assert (ei.check());
304
305 PyObject *iObj = ei().ptr();
306 assert (iObj != 0);
307
308 //
309
310 std::cerr << "Testing Box2i:\n";
311
312 Imath::Box2i b2iAsB2i;
313 assert (PyImath::Box2i::convert (b2iObj, &b2iAsB2i) == 1);
314 assert (b2iAsB2i == Imath::Box2i (Imath::V2i (1, 2),
315 Imath::V2i (3, 4)));
316
317 Imath::Box2i b2fAsB2i;
318 assert (PyImath::Box2i::convert (b2fObj, &b2fAsB2i) == 1);
319 assert (b2fAsB2i == Imath::Box2i (Imath::V2i (5, 6),
320 Imath::V2i (7, 8)));
321
322 Imath::Box2i b2dAsB2i;
323 assert (PyImath::Box2i::convert (b2dObj, &b2dAsB2i) == 1);
324 assert (b2dAsB2i == Imath::Box2i (Imath::V2i (9, 10),
325 Imath::V2i (11, 12)));
326
327 Imath::Box2i t2iAsB2i;
328 assert (PyImath::Box2i::convert (t2iObj, &t2iAsB2i) == 1);
329 assert (t2iAsB2i == Imath::Box2i (Imath::V2i (1, 2),
330 Imath::V2i (3, 4)));
331
332 Imath::Box2i t2V2iAsB2i;
333 assert (PyImath::Box2i::convert (t2V2iObj, &t2V2iAsB2i) == 1);
334 assert (t2V2iAsB2i == Imath::Box2i (Imath::V2i (1, 2),
335 Imath::V2i (3, 4)));
336
337 Imath::Box2i t2iMixAsB2i;
338 assert (PyImath::Box2i::convert (t2iMixObj, &t2iMixAsB2i) == 1);
339 assert (t2iMixAsB2i == Imath::Box2i (Imath::V2i (1, 2),
340 Imath::V2i (3, 4)));
341
342 Imath::Box2i t2fAsB2i;
343 assert (PyImath::Box2i::convert (t2fObj, &t2fAsB2i) == 1);
344 assert (t2fAsB2i == Imath::Box2i (Imath::V2i (5, 6),
345 Imath::V2i (7, 8)));
346
347 Imath::Box2i t2V2fAsB2i;
348 assert (PyImath::Box2i::convert (t2V2fObj, &t2V2fAsB2i) == 1);
349 assert (t2V2fAsB2i == Imath::Box2i (Imath::V2i (5, 6),
350 Imath::V2i (7, 8)));
351
352 Imath::Box2i t2fMixAsB2i;
353 assert (PyImath::Box2i::convert (t2fMixObj, &t2fMixAsB2i) == 1);
354 assert (t2fMixAsB2i == Imath::Box2i (Imath::V2i (5, 6),
355 Imath::V2i (7, 8)));
356
357 Imath::Box2i t2V2dAsB2i;
358 assert (PyImath::Box2i::convert (t2V2dObj, &t2V2dAsB2i) == 1);
359 assert (t2V2dAsB2i == Imath::Box2i (Imath::V2i (9, 10),
360 Imath::V2i (11, 12)));
361
362 Imath::Box2i t2dMixAsB2i;
363 assert (PyImath::Box2i::convert (t2dMixObj, &t2dMixAsB2i) == 1);
364 assert (t2dMixAsB2i == Imath::Box2i (Imath::V2i (9, 10),
365 Imath::V2i (11, 12)));
366
367 Imath::Box2i iAsB2i;
368 assert (PyImath::Box2i::convert (iObj, &iAsB2i) == 0);
369
370 std::cerr << "ok\n";
371
372 //
373
374 std::cerr << "Testing Box2f:\n";
375
376 Imath::Box2f b2iAsB2f;
377 assert (PyImath::Box2f::convert (b2iObj, &b2iAsB2f) == 1);
378 assert (b2iAsB2f.min.equalWithAbsError (Imath::V2f (1.0f, 2.0f), 1e-7));
379 assert (b2iAsB2f.max.equalWithAbsError (Imath::V2f (3.0f, 4.0f), 1e-7));
380
381 Imath::Box2f b2fAsB2f;
382 assert (PyImath::Box2f::convert (b2fObj, &b2fAsB2f) == 1);
383 assert (b2fAsB2f.min.equalWithAbsError (Imath::V2f (5.5f, 6.6f), 1e-7));
384 assert (b2fAsB2f.max.equalWithAbsError (Imath::V2f (7.7f, 8.8f), 1e-7));
385
386 Imath::Box2f b2dAsB2f;
387 assert (PyImath::Box2f::convert (b2dObj, &b2dAsB2f) == 1);
388 assert (b2dAsB2f.min.equalWithAbsError (Imath::V2f (9.9f, 10.10f), 1e-7));
389 assert (b2dAsB2f.max.equalWithAbsError (Imath::V2f (11.11f, 12.12f), 1e-7));
390
391 Imath::Box2f t2iAsB2f;
392 assert (PyImath::Box2f::convert (t2iObj, &t2iAsB2f) == 1);
393 assert (t2iAsB2f.min.equalWithAbsError (Imath::V2f (1.0f, 2.0f), 1e-7));
394 assert (t2iAsB2f.max.equalWithAbsError (Imath::V2f (3.0f, 4.0f), 1e-7));
395
396 Imath::Box2f t2V2iAsB2f;
397 assert (PyImath::Box2f::convert (t2V2iObj, &t2V2iAsB2f) == 1);
398 assert (t2V2iAsB2f.min.equalWithAbsError (Imath::V2f (1.0f, 2.0f), 1e-7));
399 assert (t2V2iAsB2f.max.equalWithAbsError (Imath::V2f (3.0f, 4.0f), 1e-7));
400
401 Imath::Box2f t2iMixAsB2f;
402 assert (PyImath::Box2f::convert (t2iMixObj, &t2iMixAsB2f) == 1);
403 assert (t2iMixAsB2f.min.equalWithAbsError (Imath::V2f (1.0f, 2.0f), 1e-7));
404 assert (t2iMixAsB2f.max.equalWithAbsError (Imath::V2f (3.0, 4.0f), 1e-7));
405
406 Imath::Box2f t2fAsB2f;
407 assert (PyImath::Box2f::convert (t2fObj, &t2fAsB2f) == 1);
408 assert (t2fAsB2f.min.equalWithAbsError (Imath::V2f (5.5f, 6.6f), 1e-7));
409 assert (t2fAsB2f.max.equalWithAbsError (Imath::V2f (7.7f, 8.8f), 1e-7));
410
411 Imath::Box2f t2V2fAsB2f;
412 assert (PyImath::Box2f::convert (t2V2fObj, &t2V2fAsB2f) == 1);
413 assert (t2V2fAsB2f.min.equalWithAbsError (Imath::V2f (5.5f, 6.6f), 1e-7));
414 assert (t2V2fAsB2f.max.equalWithAbsError (Imath::V2f (7.7f, 8.8f), 1e-7));
415
416 Imath::Box2f t2fMixAsB2f;
417 assert (PyImath::Box2f::convert (t2fMixObj, &t2fMixAsB2f) == 1);
418 assert (t2fMixAsB2f.min.equalWithAbsError (Imath::V2f (5.5f, 6.6f), 1e-7));
419 assert (t2fMixAsB2f.max.equalWithAbsError (Imath::V2f (7.7f, 8.8f), 1e-7));
420
421 Imath::Box2f t2V2dAsB2f;
422 assert (PyImath::Box2f::convert (t2V2dObj, &t2V2dAsB2f) == 1);
423 assert (t2V2dAsB2f.min.equalWithAbsError (Imath::V2f (9.9f, 10.10f), 1e-7));
424 assert (t2V2dAsB2f.max.equalWithAbsError (Imath::V2f (11.11, 12.12f), 1e-7));
425
426 Imath::Box2f t2dMixAsB2f;
427 assert (PyImath::Box2f::convert (t2dMixObj, &t2dMixAsB2f) == 1);
428 assert (t2dMixAsB2f.min.equalWithAbsError (Imath::V2f (9.9f, 10.10f), 1e-7));
429 assert (t2dMixAsB2f.max.equalWithAbsError (Imath::V2f (11.11f, 12.12f), 1e-7));
430
431 Imath::Box2f iAsB2f;
432 assert (PyImath::Box2f::convert (iObj, &iAsB2f) == 0);
433
434 std::cerr << "ok\n";
435
436 //
437
438 std::cerr << "Testing Box2d:\n";
439
440 Imath::Box2d b2iAsB2d;
441 assert (PyImath::Box2d::convert (b2iObj, &b2iAsB2d) == 1);
442 assert (b2iAsB2d.min.equalWithAbsError (Imath::V2d (1.0, 2.0), 1e-7));
443 assert (b2iAsB2d.max.equalWithAbsError (Imath::V2d (3.0, 4.0), 1e-7));
444
445 Imath::Box2d b2fAsB2d;
446 assert (PyImath::Box2d::convert (b2fObj, &b2fAsB2d) == 1);
447 assert (b2fAsB2d.min.equalWithAbsError (Imath::V2d (5.5, 6.6), 1e-7));
448 assert (b2fAsB2d.max.equalWithAbsError (Imath::V2d (7.7, 8.8), 1e-6));
449
450 Imath::Box2d b2dAsB2d;
451 assert (PyImath::Box2d::convert (b2dObj, &b2dAsB2d) == 1);
452 assert (b2dAsB2d.min.equalWithAbsError (Imath::V2d (9.9, 10.10), 1e-6));
453 assert (b2dAsB2d.max.equalWithAbsError (Imath::V2d (11.11, 12.12), 1e-6));
454
455 Imath::Box2d t2iAsB2d;
456 assert (PyImath::Box2d::convert (t2iObj, &t2iAsB2d) == 1);
457 assert (t2iAsB2d.min.equalWithAbsError (Imath::V2d (1.0, 2.0), 1e-7));
458 assert (t2iAsB2d.max.equalWithAbsError (Imath::V2d (3.0, 4.0), 1e-7));
459
460 Imath::Box2d t2V2iAsB2d;
461 assert (PyImath::Box2d::convert (t2V2iObj, &t2V2iAsB2d) == 1);
462 assert (t2V2iAsB2d.min.equalWithAbsError (Imath::V2d (1.0, 2.0), 1e-7));
463 assert (t2V2iAsB2d.max.equalWithAbsError (Imath::V2d (3.0, 4.0), 1e-7));
464
465 Imath::Box2d t2iMixAsB2d;
466 assert (PyImath::Box2d::convert (t2iMixObj, &t2iMixAsB2d) == 1);
467 assert (t2iMixAsB2d.min.equalWithAbsError (Imath::V2d (1.0, 2.0), 1e-7));
468 assert (t2iMixAsB2d.max.equalWithAbsError (Imath::V2d (3.0, 4.0), 1e-7));
469
470 Imath::Box2d t2fAsB2d;
471 assert (PyImath::Box2d::convert (t2fObj, &t2fAsB2d) == 1);
472 assert (t2fAsB2d.min.equalWithAbsError (Imath::V2d (5.5, 6.6), 1e-7));
473 assert (t2fAsB2d.max.equalWithAbsError (Imath::V2d (7.7, 8.8), 1e-7));
474
475 Imath::Box2d t2V2fAsB2d;
476 assert (PyImath::Box2d::convert (t2V2fObj, &t2V2fAsB2d) == 1);
477 assert (t2V2fAsB2d.min.equalWithAbsError (Imath::V2d (5.5, 6.6), 1e-7));
478 assert (t2V2fAsB2d.max.equalWithAbsError (Imath::V2d (7.7, 8.8), 1e-6));
479
480 Imath::Box2d t2fMixAsB2d;
481 assert (PyImath::Box2d::convert (t2fMixObj, &t2fMixAsB2d) == 1);
482 assert (t2fMixAsB2d.min.equalWithAbsError (Imath::V2d (5.5, 6.6), 1e-7));
483 assert (t2fMixAsB2d.max.equalWithAbsError (Imath::V2d (7.7, 8.8), 1e-7));
484
485 Imath::Box2d t2V2dAsB2d;
486 assert (PyImath::Box2d::convert (t2V2dObj, &t2V2dAsB2d) == 1);
487 assert (t2V2dAsB2d.min.equalWithAbsError (Imath::V2d (9.9, 10.10), 1e-7));
488 assert (t2V2dAsB2d.max.equalWithAbsError (Imath::V2d (11.11, 12.12), 1e-7));
489
490 Imath::Box2d t2dMixAsB2d;
491 assert (PyImath::Box2d::convert (t2dMixObj, &t2dMixAsB2d) == 1);
492 assert (t2dMixAsB2d.min.equalWithAbsError (Imath::V2d (9.9, 10.10), 1e-7));
493 assert (t2dMixAsB2d.max.equalWithAbsError (Imath::V2d (11.11, 12.12), 1e-7));
494
495 Imath::Box2d iAsB2d;
496 assert (PyImath::Box2d::convert (iObj, &iAsB2d) == 0);
497
498 std::cerr << "ok\n";
499 }
500
501
502 void
503 testBox3 ()
504 {
505 object mainModule ((handle<> (borrowed (PyImport_AddModule ("__main__")))));
506 object mainNamespace = mainModule.attr ("__dict__");
507
508 std::cerr << "Testing Box3*:\n";
509
510 std::string code =
511 "from imath import *\n"
512 "b3i = Box3i ((1, 2, 3), (4, 5, 6))\n"
513 "b3f = Box3f ((7.7, 8.8, 9.9), (10.10, 11.11, 12.12))\n"
514 "b3d = Box3d ((13.13, 14.14, 15.15), (16.16, 17.17, 18.18))\n"
515 "t2i = ((1, 2, 3), (4, 5, 6))\n"
516 "t2V3i = (V3i (1, 2, 3), V3i (4, 5, 6))\n"
517 "t2iMix = (V3i (1, 2, 3), (4, 5, 6))\n"
518 "t2f = ((7.7, 8.8, 9.9), (10.10, 11.11, 12.12))\n"
519 "t2V3f = (V3f (7.7, 8.8, 9.9), V3f (10.10, 11.11, 12.12))\n"
520 "t2fMix = (V3f (7.7, 8.8, 9.9), (10.10, 11.11, 12.12))\n"
521 "t2V3d = (V3d (13.13, 14.14, 15.15), V3d (16.16, 17.17, 18.18))\n"
522 "t2dMix = (V3d (13.13, 14.14, 15.15), (16.16, 17.17, 18.18))\n"
523 "i = 1\n"
524 "from wrap import *\n"
525 "w = wrap ('Box3i')\n"
526 "assert w == Box3i ((1, 2, 3), (4, 5, 6))\n"
527 "w = wrap ('Box3f')\n"
528 "assert w.min().equalWithAbsError ((1.1, 2.2, 3.3), 1e-7)\n"
529 "assert w.max().equalWithAbsError ((4.4, 5.5, 6.6), 1e-7)\n"
530 "w = wrap ('Box3d')\n"
531 "assert w.min().equalWithAbsError ((1.1, 2.2, 3.3), 1e-7)\n"
532 "assert w.max().equalWithAbsError ((4.4, 5.5, 6.6), 1e-7)\n";
533
534 handle<> ignored (PyRun_String (code.c_str(), Py_file_input,
535 mainNamespace.ptr(), mainNamespace.ptr()));
536
537 //
538
539 extract <object> eb3i (mainNamespace ["b3i"]);
540 assert (eb3i.check());
541
542 PyObject *b3iObj = eb3i().ptr();
543 assert (b3iObj != 0);
544
545 extract <object> eb3f (mainNamespace ["b3f"]);
546 assert (eb3f.check());
547
548 PyObject *b3fObj = eb3f().ptr();
549 assert (b3fObj != 0);
550
551 extract <object> eb3d (mainNamespace ["b3d"]);
552 assert (eb3d.check());
553
554 PyObject *b3dObj = eb3d().ptr();
555 assert (b3dObj != 0);
556
557 extract <object> et2i (mainNamespace["t2i"]);
558 assert (et2i.check());
559
560 PyObject *t2iObj = et2i().ptr();
561 assert (t2iObj != 0);
562
563 extract <object> et2V3i (mainNamespace["t2V3i"]);
564 assert (et2V3i.check());
565
566 PyObject *t2V3iObj = et2V3i().ptr();
567 assert (t2V3iObj != 0);
568
569 extract <object> et2iMix (mainNamespace["t2iMix"]);
570 assert (et2iMix.check());
571
572 PyObject *t2iMixObj = et2iMix().ptr();
573 assert (t2iMixObj != 0);
574
575 extract <object> et2f (mainNamespace["t2f"]);
576 assert (et2f.check());
577
578 PyObject *t2fObj = et2f().ptr();
579 assert (t2fObj != 0);
580
581 extract <object> et2V3f (mainNamespace["t2V3f"]);
582 assert (et2V3f.check());
583
584 PyObject *t2V3fObj = et2V3f().ptr();
585 assert (t2V3fObj != 0);
586
587 extract <object> et2fMix (mainNamespace["t2fMix"]);
588 assert (et2fMix.check());
589
590 PyObject *t2fMixObj = et2fMix().ptr();
591 assert (t2fMixObj != 0);
592
593 extract <object> et2V3d (mainNamespace["t2V3d"]);
594 assert (et2V3d.check());
595
596 PyObject *t2V3dObj = et2V3d().ptr();
597 assert (t2V3dObj != 0);
598
599 extract <object> et2dMix (mainNamespace["t2dMix"]);
600 assert (et2dMix.check());
601
602 PyObject *t2dMixObj = et2dMix().ptr();
603 assert (t2dMixObj != 0);
604
605 extract <object> ei (mainNamespace["i"]);
606 assert (ei.check());
607
608 PyObject *iObj = ei().ptr();
609 assert (iObj != 0);
610
611 //
612
613 std::cerr << "Testing Box3i:\n";
614
615 Imath::Box3i b3iAsB3i;
616 assert (PyImath::Box3i::convert (b3iObj, &b3iAsB3i) == 1);
617 assert (b3iAsB3i == Imath::Box3i (Imath::V3i (1, 2, 3),
618 Imath::V3i (4, 5, 6)));
619
620 Imath::Box3i b3fAsB3i;
621 assert (PyImath::Box3i::convert (b3fObj, &b3fAsB3i) == 1);
622 assert (b3fAsB3i == Imath::Box3i (Imath::V3i (7, 8, 9),
623 Imath::V3i (10, 11, 12)));
624
625 Imath::Box3i b3dAsB3i;
626 assert (PyImath::Box3i::convert (b3dObj, &b3dAsB3i) == 1);
627 assert (b3dAsB3i == Imath::Box3i (Imath::V3i (13, 14, 15),
628 Imath::V3i (16, 17, 18)));
629
630 Imath::Box3i t2iAsB3i;
631 assert (PyImath::Box3i::convert (t2iObj, &t2iAsB3i) == 1);
632 assert (t2iAsB3i == Imath::Box3i (Imath::V3i (1, 2, 3),
633 Imath::V3i (4, 5, 6)));
634
635 Imath::Box3i t2V3iAsB3i;
636 assert (PyImath::Box3i::convert (t2V3iObj, &t2V3iAsB3i) == 1);
637 assert (t2V3iAsB3i == Imath::Box3i (Imath::V3i (1, 2, 3),
638 Imath::V3i (4, 5, 6)));
639
640 Imath::Box3i t2iMixAsB3i;
641 assert (PyImath::Box3i::convert (t2iMixObj, &t2iMixAsB3i) == 1);
642 assert (t2iMixAsB3i == Imath::Box3i (Imath::V3i (1, 2, 3),
643 Imath::V3i (4, 5, 6)));
644
645 Imath::Box3i t2fAsB3i;
646 assert (PyImath::Box3i::convert (t2fObj, &t2fAsB3i) == 1);
647 assert (t2fAsB3i == Imath::Box3i (Imath::V3i (7, 8, 9),
648 Imath::V3i (10, 11, 12)));
649
650 Imath::Box3i t2V3fAsB3i;
651 assert (PyImath::Box3i::convert (t2V3fObj, &t2V3fAsB3i) == 1);
652 assert (t2V3fAsB3i == Imath::Box3i (Imath::V3i (7, 8, 9),
653 Imath::V3i (10, 11, 12)));
654
655 Imath::Box3i t2fMixAsB3i;
656 assert (PyImath::Box3i::convert (t2fMixObj, &t2fMixAsB3i) == 1);
657 assert (t2fMixAsB3i == Imath::Box3i (Imath::V3i (7, 8, 9),
658 Imath::V3i (10, 11, 12)));
659
660 Imath::Box3i t2V3dAsB3i;
661 assert (PyImath::Box3i::convert (t2V3dObj, &t2V3dAsB3i) == 1);
662 assert (t2V3dAsB3i == Imath::Box3i (Imath::V3i (13, 14, 15),
663 Imath::V3i (16, 17, 18)));
664
665 Imath::Box3i t2dMixAsB3i;
666 assert (PyImath::Box3i::convert (t2dMixObj, &t2dMixAsB3i) == 1);
667 assert (t2dMixAsB3i == Imath::Box3i (Imath::V3i (13, 14, 15),
668 Imath::V3i (16, 17, 18)));
669
670 Imath::Box3i iAsB3i;
671 assert (PyImath::Box3i::convert (iObj, &iAsB3i) == 0);
672
673 std::cerr << "ok\n";
674
675 //
676
677 std::cerr << "Testing Box3f:\n";
678
679 Imath::Box3f b3iAsB3f;
680 assert (PyImath::Box3f::convert (b3iObj, &b3iAsB3f) == 1);
681 assert (b3iAsB3f.min.equalWithAbsError (Imath::V3f (1.0f, 2.0f, 3.0f), 1e-7));
682 assert (b3iAsB3f.max.equalWithAbsError (Imath::V3f (4.0f, 5.0f, 6.0f), 1e-7));
683
684 Imath::Box3f b3fAsB3f;
685 assert (PyImath::Box3f::convert (b3fObj, &b3fAsB3f) == 1);
686 assert (b3fAsB3f.min.equalWithAbsError (Imath::V3f (7.7f, 8.8f, 9.9f), 1e-7));
687 assert (b3fAsB3f.max.equalWithAbsError (Imath::V3f (10.10f, 11.11f, 12.12f), 1e-7));
688
689 Imath::Box3f b3dAsB3f;
690 assert (PyImath::Box3f::convert (b3dObj, &b3dAsB3f) == 1);
691 assert (b3dAsB3f.min.equalWithAbsError (Imath::V3f (13.13f, 14.14f, 15.15f), 1e-7));
692 assert (b3dAsB3f.max.equalWithAbsError (Imath::V3f (16.16f, 17.17f, 18.18f), 1e-7));
693
694 Imath::Box3f t2iAsB3f;
695 assert (PyImath::Box3f::convert (t2iObj, &t2iAsB3f) == 1);
696 assert (t2iAsB3f.min.equalWithAbsError (Imath::V3f (1.0f, 2.0f, 3.0f), 1e-7));
697 assert (t2iAsB3f.max.equalWithAbsError (Imath::V3f (4.0f, 5.0f, 6.0f), 1e-7));
698
699 Imath::Box3f t2V3iAsB3f;
700 assert (PyImath::Box3f::convert (t2V3iObj, &t2V3iAsB3f) == 1);
701 assert (t2V3iAsB3f.min.equalWithAbsError (Imath::V3f (1.0f, 2.0f, 3.0f), 1e-7));
702 assert (t2V3iAsB3f.max.equalWithAbsError (Imath::V3f (4.0f, 5.0f, 6.0f), 1e-7));
703
704 Imath::Box3f t2iMixAsB3f;
705 assert (PyImath::Box3f::convert (t2iMixObj, &t2iMixAsB3f) == 1);
706 assert (t2iMixAsB3f.min.equalWithAbsError (Imath::V3f (1.0f, 2.0f, 3.0f), 1e-7));
707 assert (t2iMixAsB3f.max.equalWithAbsError (Imath::V3f (4.0f, 5.0f, 6.0f), 1e-7));
708
709 Imath::Box3f t2fAsB3f;
710 assert (PyImath::Box3f::convert (t2fObj, &t2fAsB3f) == 1);
711 assert (t2fAsB3f.min.equalWithAbsError (Imath::V3f (7.7f, 8.8f, 9.9f), 1e-7));
712 assert (t2fAsB3f.max.equalWithAbsError (Imath::V3f (10.10f, 11.11f, 12.12f), 1e-7));
713
714 Imath::Box3f t2V3fAsB3f;
715 assert (PyImath::Box3f::convert (t2V3fObj, &t2V3fAsB3f) == 1);
716 assert (t2V3fAsB3f.min.equalWithAbsError (Imath::V3f (7.7f, 8.8f, 9.9f), 1e-7));
717 assert (t2V3fAsB3f.max.equalWithAbsError (Imath::V3f (10.10f, 11.11f, 12.12f), 1e-7));
718
719 Imath::Box3f t2fMixAsB3f;
720 assert (PyImath::Box3f::convert (t2fMixObj, &t2fMixAsB3f) == 1);
721 assert (t2fMixAsB3f.min.equalWithAbsError (Imath::V3f (7.7f, 8.8f, 9.9f), 1e-7));
722 assert (t2fMixAsB3f.max.equalWithAbsError (Imath::V3f (10.10f, 11.11f, 12.12f), 1e-7));
723
724 Imath::Box3f t2V3dAsB3f;
725 assert (PyImath::Box3f::convert (t2V3dObj, &t2V3dAsB3f) == 1);
726 assert (t2V3dAsB3f.min.equalWithAbsError (Imath::V3f (13.13f, 14.14f, 15.15f), 1e-7));
727 assert (t2V3dAsB3f.max.equalWithAbsError (Imath::V3f (16.16f, 17.17f, 18.18f), 1e-7));
728
729 Imath::Box3f t2dMixAsB3f;
730 assert (PyImath::Box3f::convert (t2dMixObj, &t2dMixAsB3f) == 1);
731 assert (t2dMixAsB3f.min.equalWithAbsError (Imath::V3f (13.13f, 14.14f, 15.15f), 1e-7));
732 assert (t2dMixAsB3f.max.equalWithAbsError (Imath::V3f (16.16f, 17.17f, 18.18f), 1e-7));
733
734 Imath::Box3f iAsB3f;
735 assert (PyImath::Box3f::convert (iObj, &iAsB3f) == 0);
736
737 std::cerr << "ok\n";
738
739 //
740
741 std::cerr << "Testing Box3d:\n";
742
743 Imath::Box3d b3iAsB3d;
744 assert (PyImath::Box3d::convert (b3iObj, &b3iAsB3d) == 1);
745 assert (b3iAsB3d.min.equalWithAbsError (Imath::V3d (1.0, 2.0, 3.0), 1e-7));
746 assert (b3iAsB3d.max.equalWithAbsError (Imath::V3d (4.0, 5.0, 6.0), 1e-7));
747
748 Imath::Box3d b3fAsB3d;
749 assert (PyImath::Box3d::convert (b3fObj, &b3fAsB3d) == 1);
750 assert (b3fAsB3d.min.equalWithAbsError (Imath::V3d (7.7, 8.8, 9.9), 1e-6));
751 assert (b3fAsB3d.max.equalWithAbsError (Imath::V3d (10.10, 11.11, 12.12), 1e-6));
752
753 Imath::Box3d b3dAsB3d;
754 assert (PyImath::Box3d::convert (b3dObj, &b3dAsB3d) == 1);
755 assert (b3dAsB3d.min.equalWithAbsError (Imath::V3d (13.13, 14.14, 15.15), 1e-6));
756 assert (b3dAsB3d.max.equalWithAbsError (Imath::V3d (16.16, 17.17, 18.18), 1e-6));
757
758 Imath::Box3d t2iAsB3d;
759 assert (PyImath::Box3d::convert (t2iObj, &t2iAsB3d) == 1);
760 assert (t2iAsB3d.min.equalWithAbsError (Imath::V3d (1.0, 2.0, 3.0), 1e-7));
761 assert (t2iAsB3d.max.equalWithAbsError (Imath::V3d (4.0, 5.0, 6.0), 1e-7));
762
763 Imath::Box3d t2V3iAsB3d;
764 assert (PyImath::Box3d::convert (t2V3iObj, &t2V3iAsB3d) == 1);
765 assert (t2V3iAsB3d.min.equalWithAbsError (Imath::V3d (1.0, 2.0, 3.0), 1e-7));
766 assert (t2V3iAsB3d.max.equalWithAbsError (Imath::V3d (4.0, 5.0, 6.0), 1e-7));
767
768 Imath::Box3d t2iMixAsB3d;
769 assert (PyImath::Box3d::convert (t2iMixObj, &t2iMixAsB3d) == 1);
770 assert (t2iMixAsB3d.min.equalWithAbsError (Imath::V3d (1.0, 2.0, 3.0), 1e-7));
771 assert (t2iMixAsB3d.max.equalWithAbsError (Imath::V3d (4.0, 5.0, 6.0), 1e-7));
772
773 Imath::Box3d t2fAsB3d;
774 assert (PyImath::Box3d::convert (t2fObj, &t2fAsB3d) == 1);
775 assert (t2fAsB3d.min.equalWithAbsError (Imath::V3d (7.7, 8.8, 9.9), 1e-7));
776 assert (t2fAsB3d.max.equalWithAbsError (Imath::V3d (10.10, 11.11, 12.12), 1e-7));
777
778 Imath::Box3d t2V3fAsB3d;
779 assert (PyImath::Box3d::convert (t2V3fObj, &t2V3fAsB3d) == 1);
780 assert (t2V3fAsB3d.min.equalWithAbsError (Imath::V3d (7.7, 8.8, 9.9), 1e-6));
781 assert (t2V3fAsB3d.max.equalWithAbsError (Imath::V3d (10.10, 11.11, 12.12), 1e-6));
782
783 Imath::Box3d t2fMixAsB3d;
784 assert (PyImath::Box3d::convert (t2fMixObj, &t2fMixAsB3d) == 1);
785 assert (t2fMixAsB3d.min.equalWithAbsError (Imath::V3d (7.7, 8.8, 9.9), 1e-6));
786 assert (t2fMixAsB3d.max.equalWithAbsError (Imath::V3d (10.10, 11.11, 12.12), 1e-6));
787
788 Imath::Box3d t2V3dAsB3d;
789 assert (PyImath::Box3d::convert (t2V3dObj, &t2V3dAsB3d) == 1);
790 assert (t2V3dAsB3d.min.equalWithAbsError (Imath::V3d (13.13, 14.14, 15.15), 1e-7));
791 assert (t2V3dAsB3d.max.equalWithAbsError (Imath::V3d (16.16, 17.17, 18.18), 1e-7));
792
793 Imath::Box3d t2dMixAsB3d;
794 assert (PyImath::Box3d::convert (t2dMixObj, &t2dMixAsB3d) == 1);
795 assert (t2dMixAsB3d.min.equalWithAbsError (Imath::V3d (13.13, 14.14, 15.15), 1e-7));
796 assert (t2dMixAsB3d.max.equalWithAbsError (Imath::V3d (16.16, 17.17, 18.18), 1e-7));
797
798 Imath::Box3d iAsB3d;
799 assert (PyImath::Box3d::convert (iObj, &iAsB3d) == 0);
800
801 std::cerr << "ok\n";
802 }
803
804
805 void
806 testC3 ()
807 {
808 object mainModule ((handle<> (borrowed (PyImport_AddModule ("__main__")))));
809 object mainNamespace = mainModule.attr ("__dict__");
810
811 std::cerr << "Testing C3*:\n";
812
813 std::string code =
814 "from imath import *\n"
815 "c3c = Color3c (1, 2, 3)\n"
816 "c3f = Color3f (1.1, 2.2, 3.3)\n"
817 "t3c = (4, 5, 6)\n"
818 "t3f = (4.4, 5.5, 6.6)\n"
819 "v3i = V3i (7, 8, 9)\n"
820 "v3f = V3f (10.10, 11.11, 12.12)\n"
821 "v3d = V3f (13.13, 14.14, 15.15)\n"
822 "l3c = [16, 17, 18]\n"
823 "l3f = [19.19, 20.20, 21.21]\n"
824 "i = 1\n"
825 "from wrap import *\n"
826 "w = wrap ('Color3c')\n"
827 "assert w == Color3c (1, 2, 3)\n"
828 "w = wrap ('Color3f')\n"
829 "assert equal (w[0], 1.1, 1e-6)\n"
830 "assert equal (w[1], 2.2, 1e-6)\n"
831 "assert equal (w[2], 3.3, 1e-6)\n";
832
833 handle<> ignored (PyRun_String (code.c_str(), Py_file_input,
834 mainNamespace.ptr(), mainNamespace.ptr()));
835
836 //
837
838 extract <object> ec3c (mainNamespace ["c3c"]);
839 assert (ec3c.check());
840
841 PyObject *c3cObj = ec3c().ptr();
842 assert (c3cObj != 0);
843
844 extract <object> ec3f (mainNamespace ["c3f"]);
845 assert (ec3f.check());
846
847 PyObject *c3fObj = ec3f().ptr();
848 assert (c3fObj != 0);
849
850 extract <object> et3c (mainNamespace ["t3c"]);
851 assert (et3c.check());
852
853 PyObject *t3cObj = et3c().ptr();
854 assert (t3cObj != 0);
855
856 extract <object> et3f (mainNamespace ["t3f"]);
857 assert (et3f.check());
858
859 PyObject *t3fObj = et3f().ptr();
860 assert (t3fObj != 0);
861
862 extract <object> ev3i (mainNamespace ["v3i"]);
863 assert (ev3i.check());
864
865 PyObject *v3iObj = ev3i().ptr();
866 assert (v3iObj != 0);
867
868 extract <object> ev3f (mainNamespace ["v3f"]);
869 assert (ev3f.check());
870
871 PyObject *v3fObj = ev3f().ptr();
872 assert (v3fObj != 0);
873
874 extract <object> ev3d (mainNamespace ["v3d"]);
875 assert (ev3d.check());
876
877 PyObject *v3dObj = ev3d().ptr();
878 assert (v3dObj != 0);
879
880 extract <object> el3c (mainNamespace ["l3c"]);
881 assert (el3c.check());
882
883 PyObject *l3cObj = el3c().ptr();
884 assert (l3cObj != 0);
885
886 extract <object> el3f (mainNamespace ["l3f"]);
887 assert (el3f.check());
888
889 PyObject *l3fObj = el3f().ptr();
890 assert (l3fObj != 0);
891
892 extract <object> ei (mainNamespace["i"]);
893 assert (ei.check());
894
895 PyObject *iObj = ei().ptr();
896 assert (iObj != 0);
897
898 //
899
900 std::cerr << "Testing C3c:\n";
901
902 Imath::C3c c3cAsC3c;
903 assert (PyImath::C3c::convert (c3cObj, &c3cAsC3c) == 1);
904 assert (c3cAsC3c == Imath::C3c (1, 2, 3));
905
906 Imath::C3c c3fAsC3c;
907 assert (PyImath::C3c::convert (c3fObj, &c3fAsC3c) == 1);
908 assert (c3fAsC3c == Imath::C3c (1, 2, 3));
909
910 Imath::C3c t3cAsC3c;
911 assert (PyImath::C3c::convert (t3cObj, &t3cAsC3c) == 1);
912 assert (t3cAsC3c == Imath::C3c (4, 5, 6));
913
914 Imath::C3c t3fAsC3c;
915 assert (PyImath::C3c::convert (t3fObj, &t3fAsC3c) == 1);
916 assert (t3fAsC3c == Imath::C3c (4, 5, 6));
917
918 Imath::C3c v3iAsC3c;
919 assert (PyImath::C3c::convert (v3iObj, &v3iAsC3c) == 1);
920 assert (v3iAsC3c == Imath::C3c (7, 8, 9));
921
922 Imath::C3c v3fAsC3c;
923 assert (PyImath::C3c::convert (v3fObj, &v3fAsC3c) == 1);
924 assert (v3fAsC3c == Imath::C3c (10, 11, 12));
925
926 Imath::C3c v3dAsC3c;
927 assert (PyImath::C3c::convert (v3dObj, &v3dAsC3c) == 1);
928 assert (v3dAsC3c == Imath::C3c (13, 14, 15));
929
930 Imath::C3c l3cAsC3c;
931 assert (PyImath::C3c::convert (l3cObj, &l3cAsC3c) == 1);
932 assert (l3cAsC3c == Imath::C3c (16, 17, 18));
933
934 Imath::C3c l3fAsC3c;
935 assert (PyImath::C3c::convert (l3fObj, &l3fAsC3c) == 1);
936 assert (l3fAsC3c == Imath::C3c (19, 20, 21));
937
938 Imath::C3c iAsC3c;
939 assert (PyImath::C3c::convert (iObj, &iAsC3c) == 0);
940
941 std::cerr << "ok\n";
942
943 //
944
945 std::cerr << "Testing C3f:\n";
946
947 Imath::C3f c3cAsC3f;
948 assert (PyImath::C3f::convert (c3cObj, &c3cAsC3f) == 1);
949 assert (c3cAsC3f.equalWithAbsError (Imath::C3f (1.0f, 2.0f, 3.0f), 1e-7));
950
951 Imath::C3f c3fAsC3f;
952 assert (PyImath::C3f::convert (c3fObj, &c3fAsC3f) == 1);
953 assert (c3fAsC3f.equalWithAbsError (Imath::C3f (1.1f, 2.2f, 3.3f), 1e-7));
954
955 Imath::C3f t3cAsC3f;
956 assert (PyImath::C3f::convert (t3cObj, &t3cAsC3f) == 1);
957 assert (t3cAsC3f.equalWithAbsError (Imath::C3f (4.0f, 5.0f, 6.0f), 1e-7));
958
959 Imath::C3f t3fAsC3f;
960 assert (PyImath::C3f::convert (t3fObj, &t3fAsC3f) == 1);
961 assert (t3fAsC3f.equalWithAbsError (Imath::C3f (4.4f, 5.5f, 6.6f), 1e-7));
962
963 Imath::C3f v3iAsC3f;
964 assert (PyImath::C3f::convert (v3iObj, &v3iAsC3f) == 1);
965 assert (v3iAsC3f.equalWithAbsError (Imath::C3f (7.0f, 8.0f, 9.0f), 1e-7));
966
967 Imath::C3f v3fAsC3f;
968 assert (PyImath::C3f::convert (v3fObj, &v3fAsC3f) == 1);
969 assert (v3fAsC3f.equalWithAbsError (Imath::C3f (10.10f, 11.11f, 12.12f), 1e-7));
970
971 Imath::C3f v3dAsC3f;
972 assert (PyImath::C3f::convert (v3dObj, &v3dAsC3f) == 1);
973 assert (v3dAsC3f.equalWithAbsError (Imath::C3f (13.13f, 14.14f, 15.15f), 1e-7));
974
975 Imath::C3f l3cAsC3f;
976 assert (PyImath::C3f::convert (l3cObj, &l3cAsC3f) == 1);
977 assert (l3cAsC3f == Imath::C3f (16.0, 17.0, 18.0));
978
979 Imath::C3f l3fAsC3f;
980 assert (PyImath::C3f::convert (l3fObj, &l3fAsC3f) == 1);
981 assert (l3fAsC3f == Imath::C3f (19.19, 20.20, 21.21));
982
983 Imath::C3f iAsC3f;
984 assert (PyImath::C3f::convert (iObj, &iAsC3f) == 0);
985
986 std::cerr << "ok\n";
987 }
988
989
990 void
991 testC4 ()
992 {
993 object mainModule ((handle<> (borrowed (PyImport_AddModule ("__main__")))));
994 object mainNamespace = mainModule.attr ("__dict__");
995
996 std::cerr << "Testing C4*:\n";
997
998 std::string code =
999 "from imath import *\n"
1000 "c4c = Color4c (1, 2, 3, 4)\n"
1001 "c4f = Color4f (1.1, 2.2, 3.3, 4.4)\n"
1002 "t4c = (5, 6, 7, 8)\n"
1003 "t4f = (5.5, 6.6, 7.7, 8.8)\n"
1004 "l4c = [9, 10, 11, 12]\n"
1005 "l4f = [13.13, 14.14, 15.15, 16.16]\n"
1006 "i = 1\n"
1007 "from wrap import *\n"
1008 "w = wrap ('Color4c')\n"
1009 "assert w == Color4c (1, 2, 3, 4)\n"
1010 "w = wrap ('Color4f')\n"
1011 "assert equal (w[0], 1.1, 1e-7)\n"
1012 "assert equal (w[1], 2.2, 1e-7)\n"
1013 "assert equal (w[2], 3.3, 1e-7)\n"
1014 "assert equal (w[3], 4.4, 1e-7)\n";
1015
1016 handle<> ignored (PyRun_String (code.c_str(), Py_file_input,
1017 mainNamespace.ptr(), mainNamespace.ptr()));
1018
1019 //
1020
1021 extract <object> ec4c (mainNamespace ["c4c"]);
1022 assert (ec4c.check());
1023
1024 PyObject *c4cObj = ec4c().ptr();
1025 assert (c4cObj != 0);
1026
1027 extract <object> ec4f (mainNamespace ["c4f"]);
1028 assert (ec4f.check());
1029
1030 PyObject *c4fObj = ec4f().ptr();
1031 assert (c4fObj != 0);
1032
1033 extract <object> et4c (mainNamespace ["t4c"]);
1034 assert (et4c.check());
1035
1036 PyObject *t4cObj = et4c().ptr();
1037 assert (t4cObj != 0);
1038
1039 extract <object> et4f (mainNamespace ["t4f"]);
1040 assert (et4f.check());
1041
1042 PyObject *t4fObj = et4f().ptr();
1043 assert (t4fObj != 0);
1044
1045 extract <object> el4c (mainNamespace ["l4c"]);
1046 assert (el4c.check());
1047
1048 PyObject *l4cObj = el4c().ptr();
1049 assert (l4cObj != 0);
1050
1051 extract <object> el4f (mainNamespace ["l4f"]);
1052 assert (el4f.check());
1053
1054 PyObject *l4fObj = el4f().ptr();
1055 assert (l4fObj != 0);
1056
1057 extract <object> ei (mainNamespace["i"]);
1058 assert (ei.check());
1059
1060 PyObject *iObj = ei().ptr();
1061 assert (iObj != 0);
1062
1063 //
1064
1065 std::cerr << "Testing C4c:\n";
1066
1067 Imath::C4c c4cAsC4c;
1068 assert (PyImath::C4c::convert (c4cObj, &c4cAsC4c) == 1);
1069 assert (c4cAsC4c == Imath::C4c (1, 2, 3, 4));
1070
1071 Imath::C4c c4fAsC4c;
1072 assert (PyImath::C4c::convert (c4fObj, &c4fAsC4c) == 1);
1073 assert (c4fAsC4c == Imath::C4c (1, 2, 3, 4));
1074
1075 Imath::C4c t4cAsC4c;
1076 assert (PyImath::C4c::convert (t4cObj, &t4cAsC4c) == 1);
1077 assert (t4cAsC4c == Imath::C4c (5, 6, 7, 8));
1078
1079 Imath::C4c t4fAsC4c;
1080 assert (PyImath::C4c::convert (t4fObj, &t4fAsC4c) == 1);
1081 assert (t4fAsC4c == Imath::C4c (5, 6, 7, 8));
1082
1083 Imath::C4c l4cAsC4c;
1084 assert (PyImath::C4c::convert (l4cObj, &l4cAsC4c) == 1);
1085 assert (l4cAsC4c == Imath::C4c (9, 10, 11, 12));
1086
1087 Imath::C4c l4fAsC4c;
1088 assert (PyImath::C4c::convert (l4fObj, &l4fAsC4c) == 1);
1089 assert (l4fAsC4c == Imath::C4c (13, 14, 15, 16));
1090
1091 Imath::C4c iAsC4c;
1092 assert (PyImath::C4c::convert (iObj, &iAsC4c) == 0);
1093
1094 std::cerr << "ok\n";
1095
1096 //
1097
1098 std::cerr << "Testing C4f:\n";
1099
1100 Imath::C4f c4cAsC4f;
1101 assert (PyImath::C4f::convert (c4cObj, &c4cAsC4f) == 1);
1102 assert (Imath::equalWithAbsError (c4cAsC4f[0], 1.0f, 1e-7f));
1103 assert (Imath::equalWithAbsError (c4cAsC4f[1], 2.0f, 1e-7f));
1104 assert (Imath::equalWithAbsError (c4cAsC4f[2], 3.0f, 1e-7f));
1105 assert (Imath::equalWithAbsError (c4cAsC4f[3], 4.0f, 1e-7f));
1106
1107 Imath::C4f c4fAsC4f;
1108 assert (PyImath::C4f::convert (c4fObj, &c4fAsC4f) == 1);
1109 assert (Imath::equalWithAbsError (c4fAsC4f[0], 1.1f, 1e-7f));
1110 assert (Imath::equalWithAbsError (c4fAsC4f[1], 2.2f, 1e-7f));
1111 assert (Imath::equalWithAbsError (c4fAsC4f[2], 3.3f, 1e-7f));
1112 assert (Imath::equalWithAbsError (c4fAsC4f[3], 4.4f, 1e-7f));
1113
1114 Imath::C4f t4cAsC4f;
1115 assert (PyImath::C4f::convert (t4cObj, &t4cAsC4f) == 1);
1116 assert (Imath::equalWithAbsError (t4cAsC4f[0], 5.0f, 1e-7f));
1117 assert (Imath::equalWithAbsError (t4cAsC4f[1], 6.0f, 1e-7f));
1118 assert (Imath::equalWithAbsError (t4cAsC4f[2], 7.0f, 1e-7f));
1119 assert (Imath::equalWithAbsError (t4cAsC4f[3], 8.0f, 1e-7f));
1120
1121 Imath::C4f t4fAsC4f;
1122 assert (PyImath::C4f::convert (t4fObj, &t4fAsC4f) == 1);
1123 assert (Imath::equalWithAbsError (t4fAsC4f[0], 5.5f, 1e-7f));
1124 assert (Imath::equalWithAbsError (t4fAsC4f[1], 6.6f, 1e-7f));
1125 assert (Imath::equalWithAbsError (t4fAsC4f[2], 7.7f, 1e-7f));
1126 assert (Imath::equalWithAbsError (t4fAsC4f[3], 8.8f, 1e-7f));
1127
1128 Imath::C4f l4cAsC4f;
1129 assert (PyImath::C4f::convert (l4cObj, &l4cAsC4f) == 1);
1130 assert (Imath::equalWithAbsError (l4cAsC4f[0], 9.0f, 1e-7f));
1131 assert (Imath::equalWithAbsError (l4cAsC4f[1], 10.0f, 1e-7f));
1132 assert (Imath::equalWithAbsError (l4cAsC4f[2], 11.0f, 1e-7f));
1133 assert (Imath::equalWithAbsError (l4cAsC4f[3], 12.0f, 1e-7f));
1134
1135 Imath::C4f l4fAsC4f;
1136 assert (PyImath::C4f::convert (l4fObj, &l4fAsC4f) == 1);
1137 assert (Imath::equalWithAbsError (l4fAsC4f[0], 13.13f, 1e-7f));
1138 assert (Imath::equalWithAbsError (l4fAsC4f[1], 14.14f, 1e-7f));
1139 assert (Imath::equalWithAbsError (l4fAsC4f[2], 15.15f, 1e-7f));
1140 assert (Imath::equalWithAbsError (l4fAsC4f[3], 16.16f, 1e-7f));
1141
1142 Imath::C4f iAsC4f;
1143 assert (PyImath::C4f::convert (iObj, &iAsC4f) == 0);
1144
1145 std::cerr << "ok\n";
1146 }
1147
1148
1149 void
1150 testEuler ()
1151 {
1152 object mainModule ((handle<> (borrowed (PyImport_AddModule ("__main__")))));
1153 object mainNamespace = mainModule.attr ("__dict__");
1154
1155 std::cerr << "Testing Euler*:\n";
1156
1157 std::string code =
1158 "from imath import *\n"
1159 "ef = Eulerf (V3f(1.1, 2.2, 3.3), EULER_XZY)\n"
1160 "ed = Eulerd (V3d(4.4, 5.5, 6.6), EULER_ZYX)\n"
1161 "i = 1\n"
1162 "from wrap import *\n"
1163 "w = wrap ('Eulerf')\n"
1164 "assert equal (w.x, 1.1, 1e-6)\n"
1165 "assert equal (w.y, 2.2, 1e-6)\n"
1166 "assert equal (w.z, 3.3, 1e-6)\n"
1167 "assert w.order() == EULER_XZY\n"
1168 "w = wrap ('Eulerd')\n"
1169 "assert equal (w.x, 1.1, 1e-6)\n"
1170 "assert equal (w.y, 2.2, 1e-6)\n"
1171 "assert equal (w.z, 3.3, 1e-6)\n"
1172 "assert w.order() == EULER_XZY\n";
1173
1174 handle<> ignored (PyRun_String (code.c_str(), Py_file_input,
1175 mainNamespace.ptr(), mainNamespace.ptr()));
1176
1177 //
1178
1179 extract <object> eef (mainNamespace["ef"]);
1180 assert (eef.check());
1181
1182 PyObject *efObj = eef().ptr();
1183 assert (efObj != 0);
1184
1185 extract <object> eed (mainNamespace["ed"]);
1186 assert (eed.check());
1187
1188 PyObject *edObj = eed().ptr();
1189 assert (edObj != 0);
1190
1191 extract <object> ei (mainNamespace["i"]);
1192 assert (ei.check());
1193
1194 PyObject *iObj = ei().ptr();
1195 assert (iObj != 0);
1196
1197 //
1198
1199 std::cerr << "Testing Eulerf:\n";
1200
1201 Imath::Eulerf efAsEf;
1202 assert (PyImath::Eulerf::convert (efObj, &efAsEf) == 1);
1203 Imath::Eulerf eff (Imath::V3f (1.1f, 2.2f, 3.3f), Imath::Eulerf::XZY);
1204 assert (efAsEf.order() == eff.order());
1205 assert (efAsEf.toMatrix44().equalWithAbsError (eff.toMatrix44(), 1e-7));
1206
1207 Imath::Eulerf edAsEf;
1208 assert (PyImath::Eulerf::convert (edObj, &edAsEf) == 1);
1209 Imath::Eulerf edf (Imath::V3f (4.4f, 5.5f, 6.6f), Imath::Eulerf::ZYX);
1210 assert (edAsEf.order() == edf.order());
1211 assert (edAsEf.toMatrix44().equalWithAbsError (edf.toMatrix44(), 1e-6));
1212
1213 Imath::Eulerf iAsEf;
1214 assert (PyImath::Eulerf::convert (iObj, &iAsEf) == 0);
1215
1216 std::cerr << "ok\n";
1217
1218 //
1219
1220 std::cerr << "Testing Eulerd:\n";
1221
1222 Imath::Eulerd efAsEd;
1223 assert (PyImath::Eulerd::convert (efObj, &efAsEd) == 1);
1224 Imath::Eulerd efd (Imath::V3d (1.1, 2.2, 3.3), Imath::Eulerd::XZY);
1225 assert (efAsEd.order() == efd.order());
1226 assert (efAsEd.toMatrix44().equalWithAbsError (efd.toMatrix44(), 1e-7));
1227
1228 Imath::Eulerd edAsEd;
1229 assert (PyImath::Eulerd::convert (edObj, &edAsEd) == 1);
1230 Imath::Eulerd edd (Imath::V3d (4.4, 5.5, 6.6), Imath::Eulerd::ZYX);
1231 assert (edAsEd.order() == edd.order());
1232 assert (edAsEd.toMatrix44().equalWithAbsError (edd.toMatrix44(), 1e-6));
1233
1234 Imath::Eulerd iAsEd;
1235 assert (PyImath::Eulerd::convert (iObj, &iAsEd) == 0);
1236
1237 std::cerr << "ok\n";
1238 }
1239
1240
1241 void
1242 testFrustum ()
1243 {
1244 object mainModule ((handle<> (borrowed (PyImport_AddModule ("__main__")))));
1245 object mainNamespace = mainModule.attr ("__dict__");
1246
1247 std::cerr << "Testing Frustum*:\n";
1248
1249 std::string code =
1250 "from imath import *\n"
1251 "ff = Frustumf (-1.0, -100.0, -2.0, 2.0, 3.0, -3.0, 0)\n"
1252 "fd = Frustumf (-2.0, -50.0, -3.0, 3.0, 2.0, -2.0, 1)\n"
1253 "i = 1\n"
1254 "from wrap import *\n"
1255 "w = wrap ('Frustumf')\n"
1256 "assert equal (w.nearPlane(), 1.1, 1e-7)\n"
1257 "assert equal (w.farPlane(), 2.2, 1e-7)\n"
1258 "assert equal (w.left(), 3.3, 1e-7)\n"
1259 "assert equal (w.right(), 4.4, 1e-7)\n"
1260 "assert equal (w.top(), 5.5, 1e-7)\n"
1261 "assert equal (w.bottom(), 6.6, 1e-7)\n"
1262 "assert w.orthographic() == 0\n"
1263 "w = wrap ('Frustumd')\n"
1264 "assert equal (w.nearPlane(), 1.1, 1e-6)\n"
1265 "assert equal (w.farPlane(), 2.2, 1e-7)\n"
1266 "assert equal (w.left(), 3.3, 1e-7)\n"
1267 "assert equal (w.right(), 4.4, 1e-7)\n"
1268 "assert equal (w.top(), 5.5, 1e-7)\n"
1269 "assert equal (w.bottom(), 6.6, 1e-7)\n"
1270 "assert w.orthographic() == 0\n";
1271
1272 handle<> ignored (PyRun_String (code.c_str(), Py_file_input,
1273 mainNamespace.ptr(), mainNamespace.ptr()));
1274
1275 //
1276
1277 extract <object> eff (mainNamespace["ff"]);
1278 assert (eff.check());
1279
1280 PyObject *ffObj = eff().ptr();
1281 assert (ffObj != 0);
1282
1283 extract <object> efd (mainNamespace["fd"]);
1284 assert (efd.check());
1285
1286 PyObject *fdObj = efd().ptr();
1287 assert (fdObj != 0);
1288
1289 extract <object> ei (mainNamespace["i"]);
1290 assert (ei.check());
1291
1292 PyObject *iObj = ei().ptr();
1293 assert (iObj != 0);
1294
1295 //
1296
1297 std::cerr << "Testing Frustumf:\n";
1298
1299 Imath::Frustumf ffAsFf;
1300 assert (PyImath::Frustumf::convert (ffObj, &ffAsFf) == 1);
1301 assert (Imath::equalWithAbsError (ffAsFf.nearPlane(), -1.0f, 1e-7f));
1302 assert (Imath::equalWithAbsError (ffAsFf.farPlane(), -100.0f, 1e-7f));
1303 assert (Imath::equalWithAbsError (ffAsFf.left(), -2.0f, 1e-7f));
1304 assert (Imath::equalWithAbsError (ffAsFf.right(), 2.0f, 1e-7f));
1305 assert (Imath::equalWithAbsError (ffAsFf.top(), 3.0f, 1e-7f));
1306 assert (Imath::equalWithAbsError (ffAsFf.bottom(), -3.0f, 1e-7f));
1307 assert (ffAsFf.orthographic() == false);
1308
1309 Imath::Frustumf fdAsFf;
1310 assert (PyImath::Frustumf::convert (fdObj, &fdAsFf) == 1);
1311 assert (Imath::equalWithAbsError (fdAsFf.nearPlane(), -2.0f, 1e-7f));
1312 assert (Imath::equalWithAbsError (fdAsFf.farPlane(), -50.0f, 1e-7f));
1313 assert (Imath::equalWithAbsError (fdAsFf.left(), -3.0f, 1e-7f));
1314 assert (Imath::equalWithAbsError (fdAsFf.right(), 3.0f, 1e-7f));
1315 assert (Imath::equalWithAbsError (fdAsFf.top(), 2.0f, 1e-7f));
1316 assert (Imath::equalWithAbsError (fdAsFf.bottom(), -2.0f, 1e-7f));
1317 assert (fdAsFf.orthographic() == true);
1318
1319 Imath::Frustumf iAsFf;
1320 assert (PyImath::Frustumf::convert (iObj, &iAsFf) == 0);
1321
1322 std::cerr << "ok\n";
1323
1324 //
1325
1326 std::cerr << "Testing Frustumd:\n";
1327
1328 Imath::Frustumd ffAsFd;
1329 assert (PyImath::Frustumd::convert (ffObj, &ffAsFd) == 1);
1330 assert (Imath::equalWithAbsError (ffAsFd.nearPlane(), -1.0, 1e-7));
1331 assert (Imath::equalWithAbsError (ffAsFd.farPlane(), -100.0, 1e-7));
1332 assert (Imath::equalWithAbsError (ffAsFd.left(), -2.0, 1e-7));
1333 assert (Imath::equalWithAbsError (ffAsFd.right(), 2.0, 1e-7));
1334 assert (Imath::equalWithAbsError (ffAsFd.top(), 3.0, 1e-7));
1335 assert (Imath::equalWithAbsError (ffAsFd.bottom(), -3.0, 1e-7));
1336 assert (ffAsFd.orthographic() == false);
1337
1338 Imath::Frustumd fdAsFd;
1339 assert (PyImath::Frustumd::convert (fdObj, &fdAsFd) == 1);
1340 assert (Imath::equalWithAbsError (fdAsFd.nearPlane(), -2.0, 1e-7));
1341 assert (Imath::equalWithAbsError (fdAsFd.farPlane(), -50.0, 1e-7));
1342 assert (Imath::equalWithAbsError (fdAsFd.left(), -3.0, 1e-7));
1343 assert (Imath::equalWithAbsError (fdAsFd.right(), 3.0, 1e-7));
1344 assert (Imath::equalWithAbsError (fdAsFd.top(), 2.0, 1e-7));
1345 assert (Imath::equalWithAbsError (fdAsFd.bottom(), -2.0, 1e-7));
1346 assert (fdAsFd.orthographic() == true);
1347
1348 Imath::Frustumf iAsFd;
1349 assert (PyImath::Frustumf::convert (iObj, &iAsFd) == 0);
1350
1351 std::cerr << "ok\n";
1352 }
1353
1354
1355 void
1356 testLine ()
1357 {
1358 object mainModule ((handle<> (borrowed (PyImport_AddModule ("__main__")))));
1359 object mainNamespace = mainModule.attr ("__dict__");
1360
1361 std::cerr << "Testing Line*:\n";
1362
1363 std::string code =
1364 "from imath import *\n"
1365 "l3f = Line3f (V3f (1.1, 2.2, 3.3), V3f (4.4, 5.5, 6.6))\n"
1366 "l3d = Line3d (V3d (7.7, 8.8, 9.9), V3d (10.10, 11.11, 12.12))\n"
1367 "i = 1\n"
1368 "from wrap import *\n"
1369 "w = wrap ('Line3f')\n"
1370 "p1 = V3f (1.1, 2.2, 3.3)\n"
1371 "p2 = V3f (4.4, 5.5, 6.6)\n"
1372 "d = (p2 - p1).normalize()\n"
1373 "assert w.pos().equalWithAbsError (p1, 1e-6)\n"
1374 "assert w.dir().equalWithAbsError (d, 1e-6)\n"
1375 "w = wrap ('Line3d')\n"
1376 "p1 = V3d (1.1, 2.2, 3.3)\n"
1377 "p2 = V3d (4.4, 5.5, 6.6)\n"
1378 "d = (p2 - p1).normalize()\n"
1379 "assert w.pos().equalWithAbsError (p1, 1e-6)\n"
1380 "assert w.dir().equalWithAbsError (d, 1e-6)\n";
1381
1382 handle<> ignored (PyRun_String (code.c_str(), Py_file_input,
1383 mainNamespace.ptr(), mainNamespace.ptr()));
1384
1385 //
1386
1387 extract <object> el3f (mainNamespace["l3f"]);
1388 assert (el3f.check());
1389
1390 PyObject *l3fObj = el3f().ptr();
1391 assert (l3fObj != 0);
1392
1393 extract <object> el3d (mainNamespace["l3d"]);
1394 assert (el3d.check());
1395
1396 PyObject *l3dObj = el3d().ptr();
1397 assert (l3dObj != 0);
1398
1399 extract <object> ei (mainNamespace["i"]);
1400 assert (ei.check());
1401
1402 PyObject *iObj = ei().ptr();
1403 assert (iObj != 0);
1404
1405 //
1406
1407 std::cerr << "Testing Line3f:\n";
1408
1409 Imath::Line3f l3fAsL3f;
1410 assert (PyImath::Line3f::convert (l3fObj, &l3fAsL3f) == 1);
1411 Imath::V3f l3fP1f (1.1f, 2.2f, 3.3f);
1412 Imath::V3f l3fP2f (4.4f, 5.5f, 6.6f);
1413 Imath::V3f l3fPosf = l3fP1f;
1414 Imath::V3f l3fDirf = (l3fP2f - l3fP1f).normalize();
1415 assert (l3fAsL3f.pos.equalWithAbsError (l3fPosf, 1e-7));
1416 assert (l3fAsL3f.dir.equalWithAbsError (l3fDirf, 1e-7));
1417
1418 Imath::Line3f l3dAsL3f;
1419 assert (PyImath::Line3f::convert (l3dObj, &l3dAsL3f) == 1);
1420 Imath::V3f l3dP1f (7.7f, 8.8f, 9.9f);
1421 Imath::V3f l3dP2f (10.10f, 11.11f, 12.12f);
1422 Imath::V3f l3dPosf = l3dP1f;
1423 Imath::V3f l3dDirf = (l3dP2f - l3dP1f).normalize();
1424 assert (l3dAsL3f.pos.equalWithAbsError (l3dPosf, 1e-7));
1425 assert (l3dAsL3f.dir.equalWithAbsError (l3dDirf, 1e-6));
1426
1427 Imath::Line3f iAsL3f;
1428 assert (PyImath::Line3f::convert (iObj, &iAsL3f) == 0);
1429
1430 std::cerr << "ok\n";
1431
1432 //
1433
1434 std::cerr << "Testing Line3d:\n";
1435
1436 Imath::Line3d l3fAsL3d;
1437 assert (PyImath::Line3d::convert (l3fObj, &l3fAsL3d) == 1);
1438 Imath::V3d l3fP1d (1.1, 2.2, 3.3);
1439 Imath::V3d l3fP2d (4.4, 5.5, 6.6);
1440 Imath::V3d l3fPosd = l3fP1d;
1441 Imath::V3d l3fDird = (l3fP2d - l3fP1d).normalize();
1442 assert (l3fAsL3d.pos.equalWithAbsError (l3fPosd, 1e-7));
1443 assert (l3fAsL3d.dir.equalWithAbsError (l3fDird, 1e-7));
1444
1445 Imath::Line3d l3dAsL3d;
1446 assert (PyImath::Line3d::convert (l3dObj, &l3dAsL3d) == 1);
1447 Imath::V3d l3dP1d (7.7, 8.8, 9.9);
1448 Imath::V3d l3dP2d (10.10, 11.11, 12.12);
1449 Imath::V3d l3dPosd = l3dP1d;
1450 Imath::V3d l3dDird = (l3dP2d - l3dP1d).normalize();
1451 assert (l3dAsL3d.pos.equalWithAbsError (l3dPosd, 1e-7));
1452 assert (l3dAsL3d.dir.equalWithAbsError (l3dDird, 1e-7));
1453
1454 Imath::Line3d iAsL3d;
1455 assert (PyImath::Line3d::convert (iObj, &iAsL3d) == 0);
1456
1457 std::cerr << "ok\n";
1458 }
1459
1460
1461 void
1462 testM33 ()
1463 {
1464 object mainModule ((handle<> (borrowed (PyImport_AddModule ("__main__")))));
1465 object mainNamespace = mainModule.attr ("__dict__");
1466
1467 std::cerr << "Testing M33*:\n";
1468
1469 std::string code =
1470 "from imath import *\n"
1471 "m33f = M33f ((1.1, 2.2, 3.3),\n"
1472 " (4.4, 5.5, 6.6),\n"
1473 " (7.7, 8.8, 9.9))\n"
1474 "m33d = M33d ((10.10, 11.11, 12.12),\n"
1475 " (13.13, 14.14, 15.15),\n"
1476 " (16.16, 17.17, 18.18))\n"
1477 "i = 1\n"
1478 "from wrap import *\n"
1479 "w = wrap ('M33f')\n"
1480 "assert w.equalWithAbsError (m33f, 1e-6)\n"
1481 "w = wrap ('M33d')\n"
1482 "m33d2 = M33d (m33f)\n"
1483 "assert w.equalWithAbsError (m33d2, 1e-6)\n";
1484
1485 handle<> ignored (PyRun_String (code.c_str(), Py_file_input,
1486 mainNamespace.ptr(), mainNamespace.ptr()));
1487
1488 //
1489
1490 extract <object> em33f (mainNamespace["m33f"]);
1491 assert (em33f.check());
1492
1493 PyObject *m33fObj = em33f().ptr();
1494 assert (m33fObj != 0);
1495
1496 extract <object> em33d (mainNamespace["m33d"]);
1497 assert (em33d.check());
1498
1499 PyObject *m33dObj = em33d().ptr();
1500 assert (m33dObj != 0);
1501
1502 extract <object> ei (mainNamespace["i"]);
1503 assert (ei.check());
1504
1505 PyObject *iObj = ei().ptr();
1506 assert (iObj != 0);
1507
1508 //
1509
1510 std::cerr << "Testing M33f:\n";
1511
1512 Imath::M33f m33fAsM33f;
1513 assert (PyImath::M33f::convert (m33fObj, &m33fAsM33f) == 1);
1514 Imath::M33f m33ff (1.1f, 2.2f, 3.3f,
1515 4.4f, 5.5f, 6.6f,
1516 7.7f, 8.8f, 9.9f);
1517 assert (m33fAsM33f.equalWithAbsError (m33ff, 1e-7));
1518
1519 Imath::M33f m33dAsM33f;
1520 assert (PyImath::M33f::convert (m33dObj, &m33dAsM33f) == 1);
1521 Imath::M33f m33df (10.10f, 11.11f, 12.12f,
1522 13.13f, 14.14f, 15.15f,
1523 16.16f, 17.17f, 18.18f);
1524 assert (m33dAsM33f.equalWithAbsError (m33df, 1e-7));
1525
1526 Imath::M33f iAsM33f;
1527 assert (PyImath::M33f::convert (iObj, &iAsM33f) == 0);
1528
1529 std::cerr << "ok\n";
1530
1531 //
1532
1533 std::cerr << "Testing M33d:\n";
1534
1535 Imath::M33d m33fAsM33d;
1536 assert (PyImath::M33d::convert (m33fObj, &m33fAsM33d) == 1);
1537 Imath::M33d m33fd (1.1, 2.2, 3.3,
1538 4.4, 5.5, 6.6,
1539 7.7, 8.8, 9.9);
1540 assert (m33fAsM33d.equalWithAbsError (m33fd, 1e-6));
1541
1542 Imath::M33d m33dAsM33d;
1543 assert (PyImath::M33d::convert (m33dObj, &m33dAsM33d) == 1);
1544 Imath::M33d m33dd (10.10, 11.11, 12.12,
1545 13.13, 14.14, 15.15,
1546 16.16, 17.17, 18.18);
1547 assert (m33dAsM33d.equalWithAbsError (m33dd, 1e-7));
1548
1549 Imath::M33d iAsM33d;
1550 assert (PyImath::M33d::convert (iObj, &iAsM33d) == 0);
1551
1552 std::cerr << "ok\n";
1553 }
1554
1555
1556 void
1557 testM44 ()
1558 {
1559 object mainModule ((handle<> (borrowed (PyImport_AddModule ("__main__")))));
1560 object mainNamespace = mainModule.attr ("__dict__");
1561
1562 std::cerr << "Testing M44*:\n";
1563
1564 std::string code =
1565 "from imath import *\n"
1566 "m44f = M44f ((1.1, 2.2, 3.3, 4.4),\n"
1567 " (5.5, 6.6, 7.7, 8.8),\n"
1568 " (9.9, 10.10, 11.11, 12.12),\n"
1569 " (13.13, 14.14, 15.15, 16.16))\n"
1570 "m44d = M44d ((17.17, 18.18, 19.19, 20.20),\n"
1571 " (21.21, 22.22, 23.23, 24.24),\n"
1572 " (25.25, 26.26, 27.27, 28.28),\n"
1573 " (29.29, 30.30, 31.31, 32.32))\n"
1574 "i = 1\n"
1575 "from wrap import *\n"
1576 "w = wrap ('M44f')\n"
1577 "assert w.equalWithAbsError (m44f, 1e-6)\n"
1578 "w = wrap ('M44d')\n"
1579 "m44d2 = M44d (m44f)\n"
1580 "assert w.equalWithAbsError (m44d2, 1e-6)\n";
1581
1582 handle<> ignored (PyRun_String (code.c_str(), Py_file_input,
1583 mainNamespace.ptr(), mainNamespace.ptr()));
1584
1585 //
1586
1587 extract <object> em44f (mainNamespace["m44f"]);
1588 assert (em44f.check());
1589
1590 PyObject *m44fObj = em44f().ptr();
1591 assert (m44fObj != 0);
1592
1593 extract <object> em44d (mainNamespace["m44d"]);
1594 assert (em44d.check());
1595
1596 PyObject *m44dObj = em44d().ptr();
1597 assert (m44dObj != 0);
1598
1599 extract <object> ei (mainNamespace["i"]);
1600 assert (ei.check());
1601
1602 PyObject *iObj = ei().ptr();
1603 assert (iObj != 0);
1604
1605 //
1606
1607 std::cerr << "Testing M44f:\n";
1608
1609 Imath::M44f m44fAsM44f;
1610 assert (PyImath::M44f::convert (m44fObj, &m44fAsM44f) == 1);
1611 Imath::M44f m44ff (1.1f, 2.2f, 3.3f, 4.4f,
1612 5.5f, 6.6f, 7.7f, 8.8f,
1613 9.9f, 10.10f, 11.11f, 12.12f,
1614 13.13f, 14.14f, 15.15f, 16.16f);
1615 assert (m44fAsM44f.equalWithAbsError (m44ff, 1e-7f));
1616
1617 Imath::M44f m44dAsM44f;
1618 assert (PyImath::M44f::convert (m44dObj, &m44dAsM44f) == 1);
1619 Imath::M44f m44df (17.17f, 18.18f, 19.19f, 20.20f,
1620 21.21f, 22.22f, 23.23f, 24.24f,
1621 25.25f, 26.26f, 27.27f, 28.28f,
1622 29.29f, 30.30f, 31.31f, 32.32f);
1623 assert (m44dAsM44f.equalWithAbsError (m44df, 1e-7f));
1624
1625 Imath::M44f iAsM44f;
1626 assert (PyImath::M44f::convert (iObj, &iAsM44f) == 0);
1627
1628 std::cerr << "ok\n";
1629
1630 //
1631
1632 std::cerr << "Testing M44d:\n";
1633
1634 Imath::M44d m44fAsM44d;
1635 assert (PyImath::M44d::convert (m44fObj, &m44fAsM44d) == 1);
1636 Imath::M44d m44fd (1.1, 2.2, 3.3, 4.4,
1637 5.5, 6.6, 7.7, 8.8,
1638 9.9, 10.10, 11.11, 12.12,
1639 13.13, 14.14, 15.15, 16.16);
1640 assert (m44fAsM44d.equalWithAbsError (m44fd, 1e-6));
1641
1642 Imath::M44d m44dAsM44d;
1643 assert (PyImath::M44d::convert (m44dObj, &m44dAsM44d) == 1);
1644 Imath::M44d m44dd (17.17, 18.18, 19.19, 20.20,
1645 21.21, 22.22, 23.23, 24.24,
1646 25.25, 26.26, 27.27, 28.28,
1647 29.29, 30.30, 31.31, 32.32);
1648 assert (m44dAsM44d.equalWithAbsError (m44dd, 1e-7));
1649
1650 Imath::M44d iAsM44d;
1651 assert (PyImath::M44d::convert (iObj, &iAsM44d) == 0);
1652
1653 std::cerr << "ok\n";
1654 }
1655
1656
1657 void
1658 testPlane ()
1659 {
1660 object mainModule ((handle<> (borrowed (PyImport_AddModule ("__main__")))));
1661 object mainNamespace = mainModule.attr ("__dict__");
1662
1663 std::cerr << "Testing Plane*:\n";
1664
1665 std::string code =
1666 "from imath import *\n"
1667 "p3f = Plane3f (V3f (1.1, 2.2, 3.3), 4.4)\n"
1668 "p3d = Plane3d (V3d (5.5, 6.6, 7.7), 8.8)\n"
1669 "i = 1\n"
1670 "from wrap import *\n"
1671 "w = wrap ('Plane3f')\n"
1672 "n = V3f (1.1, 2.2, 3.3).normalize()\n"
1673 "assert w.normal().equalWithAbsError (n, 1e-7)\n"
1674 "assert equal (w.distance(), 4.4, 1e-7)\n"
1675 "w = wrap ('Plane3d')\n"
1676 "n = V3d (1.1, 2.2, 3.3).normalize()\n"
1677 "assert w.normal().equalWithAbsError (n, 1e-7)\n"
1678 "assert equal (w.distance(), 4.4, 1e-7)\n";
1679
1680 handle<> ignored (PyRun_String (code.c_str(), Py_file_input,
1681 mainNamespace.ptr(), mainNamespace.ptr()));
1682
1683 //
1684
1685 extract <object> ep3f (mainNamespace["p3f"]);
1686 assert (ep3f.check());
1687
1688 PyObject *p3fObj = ep3f().ptr();
1689 assert (p3fObj != 0);
1690
1691 extract <object> ep3d (mainNamespace["p3d"]);
1692 assert (ep3d.check());
1693
1694 PyObject *p3dObj = ep3d().ptr();
1695 assert (p3dObj != 0);
1696
1697 extract <object> ei (mainNamespace["i"]);
1698 assert (ei.check());
1699
1700 PyObject *iObj = ei().ptr();
1701 assert (iObj != 0);
1702
1703 //
1704
1705 std::cerr << "Testing Plane3f:\n";
1706
1707 Imath::Plane3f p3fAsP3f;
1708 assert (PyImath::Plane3f::convert (p3fObj, &p3fAsP3f) == 1);
1709 Imath::V3f p3fnf (1.1f, 2.2f, 3.3f);
1710 p3fnf.normalize();
1711 assert (p3fAsP3f.normal.equalWithAbsError (p3fnf, 1e-6f));
1712 assert (Imath::equalWithAbsError (p3fAsP3f.distance, 4.4f, 1e-7f));
1713
1714 Imath::Plane3f p3dAsP3f;
1715 assert (PyImath::Plane3f::convert (p3dObj, &p3dAsP3f) == 1);
1716 Imath::V3f p3dnf (5.5f, 6.6f, 7.7f);
1717 p3dnf.normalize();
1718 assert (p3dAsP3f.normal.equalWithAbsError (p3dnf, 1e-7f));
1719 assert (Imath::equalWithAbsError (p3dAsP3f.distance, 8.8f, 1e-7f));
1720
1721 Imath::Plane3f iAsP3f;
1722 assert (PyImath::Plane3f::convert (iObj, &iAsP3f) == 0);
1723
1724 std::cerr << "ok\n";
1725
1726 //
1727
1728 std::cerr << "Testing Plane3d:\n";
1729
1730 Imath::Plane3d p3fAsP3d;
1731 assert (PyImath::Plane3d::convert (p3fObj, &p3fAsP3d) == 1);
1732 Imath::V3d p3fnd (1.1, 2.2, 3.3);
1733 p3fnd.normalize();
1734 assert (p3fAsP3d.normal.equalWithAbsError (p3fnd, 1e-7));
1735 assert (Imath::equalWithAbsError (p3fAsP3d.distance, 4.4, 1e-7));
1736
1737 Imath::Plane3d p3dAsP3d;
1738 assert (PyImath::Plane3d::convert (p3dObj, &p3dAsP3d) == 1);
1739 Imath::V3d p3dnd (5.5, 6.6, 7.7);
1740 p3dnd.normalize();
1741 assert (p3dAsP3d.normal.equalWithAbsError (p3dnd, 1e-7));
1742 assert (Imath::equalWithAbsError (p3dAsP3d.distance, 8.8, 1e-7));
1743
1744 Imath::Plane3d iAsP3d;
1745 assert (PyImath::Plane3d::convert (iObj, &iAsP3d) == 0);
1746
1747 std::cerr << "ok\n";
1748 }
1749
1750
1751 void
1752 testQuat ()
1753 {
1754 object mainModule ((handle<> (borrowed (PyImport_AddModule ("__main__")))));
1755 object mainNamespace = mainModule.attr ("__dict__");
1756
1757 std::cerr << "Testing Quat*:\n";
1758
1759 std::string code =
1760 "from imath import *\n"
1761 "qf = Quatf (1.1, 2.2, 3.3, 4.4)\n"
1762 "qd = Quatd (5.5, V3d (6.6, 7.7, 8.8))\n"
1763 "t = (9.9, 10.10, 11.11, 12.12)\n"
1764 "i = 1\n"
1765 "from wrap import *\n"
1766 "w = wrap ('Quatf')\n"
1767 "assert equal (w.r(), 1.1, 1e-7)\n"
1768 "assert w.v().equalWithAbsError (V3f (2.2, 3.3, 4.4), 1e-7)\n"
1769 "w = wrap ('Quatd')\n"
1770 "assert equal (w.r(), 1.1, 1e-7)\n"
1771 "assert w.v().equalWithAbsError (V3d (2.2, 3.3, 4.4), 1e-7)\n";
1772
1773 handle<> ignored (PyRun_String (code.c_str(), Py_file_input,
1774 mainNamespace.ptr(), mainNamespace.ptr()));
1775
1776 //
1777
1778 extract <object> eqf (mainNamespace["qf"]);
1779 assert (eqf.check());
1780
1781 PyObject *qfObj = eqf().ptr();
1782 assert (qfObj != 0);
1783
1784 extract <object> eqd (mainNamespace["qd"]);
1785 assert (eqd.check());
1786
1787 PyObject *qdObj = eqd().ptr();
1788 assert (qdObj != 0);
1789
1790 extract <object> et (mainNamespace["t"]);
1791 assert (et.check());
1792
1793 PyObject *tObj = et().ptr();
1794 assert (tObj != 0);
1795
1796 extract <object> ei (mainNamespace["i"]);
1797 assert (ei.check());
1798
1799 PyObject *iObj = ei().ptr();
1800 assert (iObj != 0);
1801
1802 //
1803
1804 std::cerr << "Testing Quatf:\n";
1805
1806 Imath::Quatf qfAsQf;
1807 assert (PyImath::Quatf::convert (qfObj, &qfAsQf) == 1);
1808 assert (Imath::equalWithAbsError (qfAsQf.r, 1.1f, 1e-7f));
1809 assert (qfAsQf.v.equalWithAbsError (Imath::V3f (2.2f, 3.3f, 4.4f), 1e-7f));
1810
1811 Imath::Quatf qdAsQf;
1812 assert (PyImath::Quatf::convert (qdObj, &qdAsQf) == 1);
1813 assert (Imath::equalWithAbsError (qdAsQf.r, 5.5f, 1e-7f));
1814 assert (qdAsQf.v.equalWithAbsError (Imath::V3f (6.6f, 7.7f, 8.8f), 1e-7f));
1815
1816 Imath::Quatf tAsQf;
1817 assert (PyImath::Quatf::convert (tObj, &tAsQf) == 1);
1818 assert (Imath::equalWithAbsError (tAsQf.r, 9.9f, 1e-7f));
1819 assert (tAsQf.v.equalWithAbsError (Imath::V3f (10.10f, 11.11f, 12.12f), 1e-7f));
1820
1821 Imath::Quatf iAsQf;
1822 assert (PyImath::Quatf::convert (iObj, &iAsQf) == 0);
1823
1824 std::cerr << "ok\n";
1825
1826 //
1827
1828 std::cerr << "Testing Quatd:\n";
1829
1830 Imath::Quatd qfAsQd;
1831 assert (PyImath::Quatd::convert (qfObj, &qfAsQd) == 1);
1832 assert (Imath::equalWithAbsError (qfAsQd.r, 1.1, 1e-7));
1833 assert (qfAsQd.v.equalWithAbsError (Imath::V3d (2.2, 3.3, 4.4), 1e-7));
1834
1835 Imath::Quatd qdAsQd;
1836 assert (PyImath::Quatd::convert (qdObj, &qdAsQd) == 1);
1837 assert (Imath::equalWithAbsError (qdAsQd.r, 5.5, 1e-7));
1838 assert (qdAsQd.v.equalWithAbsError (Imath::V3d (6.6, 7.7, 8.8), 1e-7));
1839
1840 Imath::Quatd tAsQd;
1841 assert (PyImath::Quatd::convert (tObj, &tAsQd) == 1);
1842 assert (Imath::equalWithAbsError (tAsQd.r, 9.9, 1e-7));
1843 assert (tAsQd.v.equalWithAbsError (Imath::V3d (10.10, 11.11, 12.12), 1e-7));
1844
1845 Imath::Quatd iAsQd;
1846 assert (PyImath::Quatd::convert (iObj, &iAsQd) == 0);
1847
1848 std::cerr << "ok\n";
1849 }
1850
1851
1852 void
1853 testRandom ()
1854 {
1855 object mainModule ((handle<> (borrowed (PyImport_AddModule ("__main__")))));
1856 object mainNamespace = mainModule.attr ("__dict__");
1857
1858 std::cerr << "Testing Random*:\n";
1859
1860 std::string code =
1861 "from imath import *\n"
1862 "from wrap import *\n"
1863 "w = wrap ('Rand32')\n"
1864 "r1 = w.nextf()\n"
1865 "r2 = w.nextf()\n"
1866 "assert r1 != r2\n"
1867 "w = wrap ('Rand48')\n"
1868 "r1 = w.nextf()\n"
1869 "r2 = w.nextf()\n"
1870 "assert r1 != r2\n";
1871
1872 handle<> ignored (PyRun_String (code.c_str(), Py_file_input,
1873 mainNamespace.ptr(), mainNamespace.ptr()));
1874
1875 //
1876
1877 std::cerr << "Testing Rand32:\n";
1878
1879 std::cerr << "ok\n";
1880
1881 //
1882
1883 std::cerr << "Testing Rand48:\n";
1884
1885 std::cerr << "ok\n";
1886 }
1887
1888
1889 void
1890 testShear ()
1891 {
1892 object mainModule ((handle<> (borrowed (PyImport_AddModule ("__main__")))));
1893 object mainNamespace = mainModule.attr ("__dict__");
1894
1895 std::cerr << "Testing Shear6*:\n";
1896
1897 std::string code =
1898 "from imath import *\n"
1899 "s6f = Shear6f (1.1, 2.2, 3.3, 4.4, 5.5, 6.6)\n"
1900 "s6d = Shear6d (7.7, 8.8, 9.9, 10.10, 11.11, 12.12)\n"
1901 "t3 = (13.13, 14.14, 15.15)\n"
1902 "t6 = (16.16, 17.17, 18.18, 19.19, 20.20, 21.21)\n"
1903 "v3i = V3i (22, 23, 24)\n"
1904 "v3f = V3f (25.25, 26.26, 27.27)\n"
1905 "v3d = V3d (28.28, 29.29, 30.30)\n"
1906 "i = 1\n"
1907 "from wrap import *\n"
1908 "w = wrap ('Shear6f')\n"
1909 "assert w.equalWithAbsError (s6f, 1e-6)\n"
1910 "w = wrap ('Shear6d')\n"
1911 "s6d2 = Shear6d (s6f)\n"
1912 "assert w.equalWithAbsError (s6d2, 1e-6)\n";
1913
1914 handle<> ignored (PyRun_String (code.c_str(), Py_file_input,
1915 mainNamespace.ptr(), mainNamespace.ptr()));
1916
1917 //
1918
1919 extract <object> es6f (mainNamespace["s6f"]);
1920 assert (es6f.check());
1921 PyObject *s6fObj = es6f().ptr();
1922 assert (s6fObj != 0);
1923
1924 extract <object> es6d (mainNamespace["s6d"]);
1925 assert (es6d.check());
1926
1927 PyObject *s6dObj = es6d().ptr();
1928 assert (s6dObj != 0);
1929
1930 extract <object> et3 (mainNamespace["t3"]);
1931 assert (et3.check());
1932
1933 PyObject *t3Obj = et3().ptr();
1934 assert (t3Obj != 0);
1935
1936 extract <object> et6 (mainNamespace["t6"]);
1937 assert (et6.check());
1938
1939 PyObject *t6Obj = et6().ptr();
1940 assert (t6Obj != 0);
1941
1942 extract <object> ev3i (mainNamespace ["v3i"]);
1943 assert (ev3i.check());
1944
1945 PyObject *v3iObj = ev3i().ptr();
1946 assert (v3iObj != 0);
1947
1948 extract <object> ev3f (mainNamespace ["v3f"]);
1949 assert (ev3f.check());
1950
1951 PyObject *v3fObj = ev3f().ptr();
1952 assert (v3fObj != 0);
1953
1954 extract <object> ev3d (mainNamespace ["v3d"]);
1955 assert (ev3d.check());
1956
1957 PyObject *v3dObj = ev3d().ptr();
1958 assert (v3dObj != 0);
1959
1960 extract <object> ei (mainNamespace["i"]);
1961 assert (ei.check());
1962
1963 PyObject *iObj = ei().ptr();
1964 assert (iObj != 0);
1965
1966 //
1967
1968 std::cerr << "Testing Shear6f:\n";
1969
1970 Imath::Shear6f s6fAsS6f;
1971 assert (PyImath::Shear6f::convert (s6fObj, &s6fAsS6f) == 1);
1972 Imath::Shear6f s6ff (1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f);
1973 assert (s6fAsS6f.equalWithAbsError (s6ff, 1e-7f));
1974
1975 Imath::Shear6f s6dAsS6f;
1976 assert (PyImath::Shear6f::convert (s6dObj, &s6dAsS6f) == 1);
1977 Imath::Shear6f s6df (7.7f, 8.8f, 9.9f, 10.10f, 11.11f, 12.12f);
1978 assert (s6dAsS6f.equalWithAbsError (s6df, 1e-7f));
1979
1980 Imath::Shear6f t3AsS6f;
1981 assert (PyImath::Shear6f::convert (t3Obj, &t3AsS6f) == 1);
1982 Imath::Shear6f t3f (13.13f, 14.14f, 15.15f, 0, 0, 0);
1983 assert (t3AsS6f.equalWithAbsError (t3f, 1e-7f));
1984
1985 Imath::Shear6f t6AsS6f;
1986 assert (PyImath::Shear6f::convert (t6Obj, &t6AsS6f) == 1);
1987 Imath::Shear6f t6f (16.16f, 17.17f, 18.18f, 19.19f, 20.20f, 21.21f);
1988 assert (t6AsS6f.equalWithAbsError (t6f, 1e-7f));
1989
1990 Imath::Shear6f v3iAsS6f;
1991 assert (PyImath::Shear6f::convert (v3iObj, &v3iAsS6f) == 1);
1992 Imath::Shear6f v3if (22.0f, 23.0f, 24.0f, 0, 0, 0);
1993 assert (v3iAsS6f.equalWithAbsError (v3if, 1e-7f));
1994
1995 Imath::Shear6f v3fAsS6f;
1996 assert (PyImath::Shear6f::convert (v3fObj, &v3fAsS6f) == 1);
1997 Imath::Shear6f v3ff (25.25f, 26.26f, 27.27f, 0, 0, 0);
1998 assert (v3fAsS6f.equalWithAbsError (v3ff, 1e-7f));
1999
2000 Imath::Shear6f v3dAsS6f;
2001 assert (PyImath::Shear6f::convert (v3dObj, &v3dAsS6f) == 1);
2002 Imath::Shear6f v3df (28.28f, 29.29f, 30.30f, 0, 0, 0);
2003 assert (v3dAsS6f.equalWithAbsError (v3df, 1e-7f));
2004
2005 Imath::Shear6f iAsS6f;
2006 assert (PyImath::Shear6f::convert (iObj, &iAsS6f) == 0);
2007
2008 std::cerr << "ok\n";
2009
2010 //
2011
2012 std::cerr << "Testing Shear6d:\n";
2013
2014 Imath::Shear6d s6fAsS6d;
2015 assert (PyImath::Shear6d::convert (s6fObj, &s6fAsS6d) == 1);
2016 Imath::Shear6d s6fd (1.1, 2.2, 3.3, 4.4, 5.5, 6.6);
2017 assert (s6fAsS6d.equalWithAbsError (s6fd, 1e-7));
2018
2019 Imath::Shear6d s6dAsS6d;
2020 assert (PyImath::Shear6d::convert (s6dObj, &s6dAsS6d) == 1);
2021 Imath::Shear6d s6dd (7.7, 8.8, 9.9, 10.10, 11.11, 12.12);
2022 assert (s6dAsS6d.equalWithAbsError (s6dd, 1e-7));
2023
2024 Imath::Shear6d t3AsS6d;
2025 assert (PyImath::Shear6d::convert (t3Obj, &t3AsS6d) == 1);
2026 Imath::Shear6d t3d (13.13, 14.14, 15.15, 0, 0, 0);
2027 assert (t3AsS6d.equalWithAbsError (t3d, 1e-7));
2028
2029 Imath::Shear6d t6AsS6d;
2030 assert (PyImath::Shear6d::convert (t6Obj, &t6AsS6d) == 1);
2031 Imath::Shear6d t6d (16.16, 17.17, 18.18, 19.19, 20.20, 21.21);
2032 assert (t6AsS6d.equalWithAbsError (t6d, 1e-7));
2033
2034 Imath::Shear6d v3iAsS6d;
2035 assert (PyImath::Shear6d::convert (v3iObj, &v3iAsS6d) == 1);
2036 Imath::Shear6d v3id (22.0, 23.0, 24.0, 0, 0, 0);
2037 assert (v3iAsS6d.equalWithAbsError (v3id, 1e-7));
2038
2039 Imath::Shear6d v3fAsS6d;
2040 assert (PyImath::Shear6d::convert (v3fObj, &v3fAsS6d) == 1);
2041 Imath::Shear6d v3fd (25.25, 26.26, 27.27, 0, 0, 0);
2042 assert (v3fAsS6d.equalWithAbsError (v3fd, 1e-6));
2043
2044 Imath::Shear6d v3dAsS6d;
2045 assert (PyImath::Shear6d::convert (v3dObj, &v3dAsS6d) == 1);
2046 Imath::Shear6d v3dd (28.28, 29.29, 30.30, 0, 0, 0);
2047 assert (v3dAsS6d.equalWithAbsError (v3dd, 1e-7));
2048
2049 Imath::Shear6d iAsS6d;
2050 assert (PyImath::Shear6d::convert (iObj, &iAsS6d) == 0);
2051
2052 std::cerr << "ok\n";
2053 }
2054
2055
2056 void
2057 testV2 ()
2058 {
2059 object mainModule ((handle<> (borrowed (PyImport_AddModule ("__main__")))));
2060 object mainNamespace = mainModule.attr ("__dict__");
2061
2062 std::cerr << "Testing V2*:\n";
2063
2064 std::string code =
2065 "from imath import *\n"
2066 "v2i = V2i (1, 2)\n"
2067 "v2f = V2f (3.3, 4.4)\n"
2068 "v2d = V2d (5.5, 6.6)\n"
2069 "t = (7, 8)\n"
2070 "i = 1\n"
2071 "from wrap import *\n"
2072 "w = wrap ('V2i')\n"
2073 "assert w == V2i (1, 2)\n"
2074 "w = wrap ('V2f')\n"
2075 "assert w.equalWithAbsError (V2f (1.1, 2.2), 1e-7)\n"
2076 "w = wrap ('V2d')\n"
2077 "assert w.equalWithAbsError (V2d (1.1, 2.2), 1e-7)\n";
2078
2079 handle<> ignored (PyRun_String (code.c_str(), Py_file_input,
2080 mainNamespace.ptr(), mainNamespace.ptr()));
2081
2082 //
2083
2084 extract <object> ev2i (mainNamespace ["v2i"]);
2085 assert (ev2i.check());
2086
2087 PyObject *v2iObj = ev2i().ptr();
2088 assert (v2iObj != 0);
2089
2090 extract <object> ev2f (mainNamespace ["v2f"]);
2091 assert (ev2f.check());
2092
2093 PyObject *v2fObj = ev2f().ptr();
2094 assert (v2fObj != 0);
2095
2096 extract <object> ev2d (mainNamespace ["v2d"]);
2097 assert (ev2d.check());
2098
2099 PyObject *v2dObj = ev2d().ptr();
2100 assert (v2dObj != 0);
2101
2102 extract <object> et (mainNamespace["t"]);
2103 assert (et.check());
2104
2105 PyObject *tObj = et().ptr();
2106 assert (tObj != 0);
2107
2108 extract <object> ei (mainNamespace["i"]);
2109 assert (ei.check());
2110
2111 PyObject *iObj = ei().ptr();
2112 assert (iObj != 0);
2113
2114 //
2115
2116 std::cerr << "Testing V2i:\n";
2117
2118 Imath::V2i v2iAsV2i;
2119 assert (PyImath::V2i::convert (v2iObj, &v2iAsV2i) == 1);
2120 assert (v2iAsV2i == Imath::V2i (1, 2));
2121
2122 Imath::V2i v2fAsV2i;
2123 assert (PyImath::V2i::convert (v2fObj, &v2fAsV2i) == 1);
2124 assert (v2fAsV2i == Imath::V2i (3, 4));
2125
2126 Imath::V2i v2dAsV2i;
2127 assert (PyImath::V2i::convert (v2dObj, &v2dAsV2i) == 1);
2128 assert (v2dAsV2i == Imath::V2i (5, 6));
2129
2130 Imath::V2i tAsV2i;
2131 assert (PyImath::V2i::convert (tObj, &tAsV2i) == 1);
2132 assert (tAsV2i == Imath::V2i (7, 8));
2133
2134 Imath::V2i iAsV2i;
2135 assert (PyImath::V2i::convert (iObj, &iAsV2i) == 0);
2136
2137 std::cerr << "ok\n";
2138
2139 //
2140
2141 std::cerr << "Testing V2f:\n";
2142
2143 Imath::V2f v2iAsV2f;
2144 assert (PyImath::V2f::convert (v2iObj, &v2iAsV2f) == 1);
2145 assert (v2iAsV2f.equalWithAbsError (Imath::V2f (1.0f, 2.0f), 1e-7));
2146
2147 Imath::V2f v2fAsV2f;
2148 assert (PyImath::V2f::convert (v2fObj, &v2fAsV2f) == 1);
2149 assert (v2fAsV2f.equalWithAbsError (Imath::V2f (3.3f, 4.4f), 1e-7));
2150
2151 Imath::V2f v2dAsV2f;
2152 assert (PyImath::V2f::convert (v2dObj, &v2dAsV2f) == 1);
2153 assert (v2dAsV2f.equalWithAbsError (Imath::V2f (5.5f, 6.6f), 1e-7));
2154
2155 Imath::V2f tAsV2f;
2156 assert (PyImath::V2f::convert (tObj, &tAsV2f) == 1);
2157 assert (tAsV2f.equalWithAbsError (Imath::V2f (7.0f, 8.0f), 1e-7));
2158
2159 Imath::V2f iAsV2f;
2160 assert (PyImath::V2f::convert (iObj, &iAsV2f) == 0);
2161
2162 std::cerr << "ok\n";
2163
2164 //
2165
2166 std::cerr << "Testing V2d:\n";
2167
2168 Imath::V2d v2iAsV2d;
2169 assert (PyImath::V2d::convert (v2iObj, &v2iAsV2d) == 1);
2170 assert (v2iAsV2d.equalWithAbsError (Imath::V2d (1.0, 2.0), 1e-7));
2171
2172 Imath::V2d v2fAsV2d;
2173 assert (PyImath::V2d::convert (v2fObj, &v2fAsV2d) == 1);
2174 assert (v2fAsV2d.equalWithAbsError (Imath::V2f (3.3, 4.4), 1e-7));
2175
2176 Imath::V2d v2dAsV2d;
2177 assert (PyImath::V2d::convert (v2dObj, &v2dAsV2d) == 1);
2178 assert (v2dAsV2d.equalWithAbsError (Imath::V2f (5.5, 6.6), 1e-7));
2179
2180 Imath::V2d tAsV2d;
2181 assert (PyImath::V2d::convert (tObj, &tAsV2d) == 1);
2182 assert (tAsV2d.equalWithAbsError (Imath::V2d (7.0, 8.0), 1e-7));
2183
2184 Imath::V2d iAsV2d;
2185 assert (PyImath::V2d::convert (iObj, &iAsV2d) == 0);
2186
2187 std::cerr << "ok\n";
2188 }
2189
2190
2191 void
2192 testV3 ()
2193 {
2194 object mainModule ((handle<> (borrowed (PyImport_AddModule ("__main__")))));
2195 object mainNamespace = mainModule.attr ("__dict__");
2196
2197 std::cerr << "Testing V3*:\n";
2198
2199 std::string code =
2200 "from imath import *\n"
2201 "v3i = V3i (1, 2, 3)\n"
2202 "v3f = V3f (4.4, 5.5, 6.6)\n"
2203 "v3d = V3d (7.7, 8.8, 9.9)\n"
2204 "t = (10, 11, 12)\n"
2205 "i = 1\n"
2206 "from wrap import *\n"
2207 "w = wrap ('V3i')\n"
2208 "assert w == V3i (1, 2, 3)\n"
2209 "w = wrap ('V3f')\n"
2210 "assert w.equalWithAbsError (V3f (1.1, 2.2, 3.3), 1e-7)\n"
2211 "w = wrap ('V3d')\n"
2212 "assert w.equalWithAbsError (V3d (1.1, 2.2, 3.3), 1e-7)\n";
2213
2214 handle<> ignored (PyRun_String (code.c_str(), Py_file_input,
2215 mainNamespace.ptr(), mainNamespace.ptr()));
2216
2217 //
2218
2219 extract <object> ev3i (mainNamespace ["v3i"]);
2220 assert (ev3i.check());
2221
2222 PyObject *v3iObj = ev3i().ptr();
2223 assert (v3iObj != 0);
2224
2225 extract <object> ev3f (mainNamespace ["v3f"]);
2226 assert (ev3f.check());
2227
2228 PyObject *v3fObj = ev3f().ptr();
2229 assert (v3fObj != 0);
2230
2231 extract <object> ev3d (mainNamespace ["v3d"]);
2232 assert (ev3d.check());
2233
2234 PyObject *v3dObj = ev3d().ptr();
2235 assert (v3dObj != 0);
2236
2237 extract <object> et (mainNamespace["t"]);
2238 assert (et.check());
2239
2240 PyObject *tObj = et().ptr();
2241 assert (tObj != 0);
2242
2243 extract <object> ei (mainNamespace["i"]);
2244 assert (ei.check());
2245
2246 PyObject *iObj = ei().ptr();
2247 assert (iObj != 0);
2248
2249 //
2250
2251 std::cerr << "Testing V3i:\n";
2252
2253 Imath::V3i v3iAsV3i;
2254 assert (PyImath::V3i::convert (v3iObj, &v3iAsV3i) == 1);
2255 assert (v3iAsV3i == Imath::V3i (1, 2, 3));
2256
2257 Imath::V3i v3fAsV3i;
2258 assert (PyImath::V3i::convert (v3fObj, &v3fAsV3i) == 1);
2259 assert (v3fAsV3i == Imath::V3i (4, 5, 6));
2260
2261 Imath::V3d v3iAsV3d;
2262 assert (PyImath::V3d::convert (v3iObj, &v3iAsV3d) == 1);
2263 assert (v3iAsV3d.equalWithAbsError (Imath::V3d (1.0, 2.0, 3.0), 1e-7));
2264
2265 Imath::V3i tAsV3i;
2266 assert (PyImath::V3i::convert (tObj, &tAsV3i) == 1);
2267 assert (tAsV3i == Imath::V3i (10, 11, 12));
2268
2269 Imath::V3i iAsV3i;
2270 assert (PyImath::V3i::convert (iObj, &iAsV3i) == 0);
2271
2272 std::cerr << "ok\n";
2273
2274 //
2275
2276 std::cerr << "Testing V3f:\n";
2277
2278 Imath::V3f v3iAsV3f;
2279 assert (PyImath::V3f::convert (v3iObj, &v3iAsV3f) == 1);
2280 assert (v3iAsV3f.equalWithAbsError (Imath::V3f (1.0f, 2.0f, 3.0f), 1e-7));
2281
2282 Imath::V3f v3fAsV3f;
2283 assert (PyImath::V3f::convert (v3fObj, &v3fAsV3f) == 1);
2284 assert (v3fAsV3f.equalWithAbsError (Imath::V3f (4.4f, 5.5f, 6.6f), 1e-7));
2285
2286 Imath::V3f v3dAsV3f;
2287 assert (PyImath::V3f::convert (v3dObj, &v3dAsV3f) == 1);
2288 assert (v3dAsV3f.equalWithAbsError (Imath::V3f (7.7f, 8.8f, 9.9f), 1e-7));
2289
2290 Imath::V3f tAsV3f;
2291 assert (PyImath::V3f::convert (tObj, &tAsV3f) == 1);
2292 assert (tAsV3f.equalWithAbsError (Imath::V3f (10.0f, 11.0f, 12.0f), 1e-7));
2293
2294 Imath::V3f iAsV3f;
2295 assert (PyImath::V3f::convert (iObj, &iAsV3f) == 0);
2296
2297 std::cerr << "ok\n";
2298
2299 //
2300
2301 std::cerr << "Testing V3d:\n";
2302
2303 Imath::V3i v3dAsV3i;
2304 assert (PyImath::V3i::convert (v3dObj, &v3dAsV3i) == 1);
2305 assert (v3dAsV3i == Imath::V3i (7, 8, 9));
2306
2307 Imath::V3d v3fAsV3d;
2308 assert (PyImath::V3d::convert (v3fObj, &v3fAsV3d) == 1);
2309 assert (v3fAsV3d.equalWithAbsError (Imath::V3f (4.4, 5.5, 6.6), 1e-7));
2310
2311 Imath::V3d v3dAsV3d;
2312 assert (PyImath::V3d::convert (v3dObj, &v3dAsV3d) == 1);
2313 assert (v3dAsV3d.equalWithAbsError (Imath::V3f (7.7, 8.8, 9.9), 1e-6));
2314
2315 Imath::V3d tAsV3d;
2316 assert (PyImath::V3d::convert (tObj, &tAsV3d) == 1);
2317 assert (tAsV3d.equalWithAbsError (Imath::V3d (10.0, 11.0, 12.0), 1e-7));
2318
2319 Imath::V3d iAsV3d;
2320 assert (PyImath::V3d::convert (iObj, &iAsV3d) == 0);
2321
2322 std::cerr << "ok\n";
2323 }
2324
2325 int
2326 main (int argc, char *argv[])
2327 {
2328 Py_Initialize();
2329 if (Py_IsInitialized())
2330 {
2331 initWrapTester();
2332
2333 TEST (testBox2);
2334 TEST (testBox3);
2335 TEST (testC3);
2336 TEST (testC4);
2337 TEST (testEuler);
2338 TEST (testFrustum);
2339 TEST (testLine);
2340 TEST (testM33);
2341 TEST (testM44);
2342 TEST (testPlane);
2343 TEST (testQuat);
2344 TEST (testRandom);
2345 TEST (testShear);
2346 TEST (testV2);
2347 TEST (testV3);
2348
2349 Py_Finalize();
2350 }
2351
2352 TEST (testStringTable);
2353
2354 return 0;
2355 }