FreeCAD

Форк
0
/
RotationPyImp.cpp 
782 строки · 24.7 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2008 Werner Mayer <wmayer[at]users.sourceforge.net>     *
3
 *                                                                         *
4
 *   This file is part of the FreeCAD CAx development system.              *
5
 *                                                                         *
6
 *   This library is free software; you can redistribute it and/or         *
7
 *   modify it under the terms of the GNU Library General Public           *
8
 *   License as published by the Free Software Foundation; either          *
9
 *   version 2 of the License, or (at your option) any later version.      *
10
 *                                                                         *
11
 *   This library  is distributed in the hope that it will be useful,      *
12
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
13
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
14
 *   GNU Library General Public License for more details.                  *
15
 *                                                                         *
16
 *   You should have received a copy of the GNU Library General Public     *
17
 *   License along with this library; see the file COPYING.LIB. If not,    *
18
 *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
19
 *   Suite 330, Boston, MA  02111-1307, USA                                *
20
 *                                                                         *
21
 ***************************************************************************/
22

23

24
#include "PreCompiled.h"
25

26
#include <Base/GeometryPyCXX.h>
27
#include <Base/Tools.h>
28
#include <Base/PyWrapParseTupleAndKeywords.h>
29

30
// inclusion of the generated files (generated out of RotationPy.xml)
31
#include "RotationPy.h"
32
#include "RotationPy.cpp"
33
#include "VectorPy.h"
34

35

36
using namespace Base;
37

38
// returns a string which represents the object e.g. when printed in python
39
std::string RotationPy::representation() const
40
{
41
    RotationPy::PointerType ptr = getRotationPtr();
42
    Py::Float q0(ptr->getValue()[0]);
43
    Py::Float q1(ptr->getValue()[1]);
44
    Py::Float q2(ptr->getValue()[2]);
45
    Py::Float q3(ptr->getValue()[3]);
46
    std::stringstream str;
47
    str << "Rotation (";
48
    str << static_cast<std::string>(q0.repr()) << ", " << static_cast<std::string>(q1.repr())
49
        << ", " << static_cast<std::string>(q2.repr()) << ", "
50
        << static_cast<std::string>(q3.repr());
51
    str << ")";
52

53
    return str.str();
54
}
55

56
PyObject* RotationPy::PyMake(PyTypeObject* /*unused*/, PyObject* /*unused*/, PyObject* /*unused*/)
57
{
58
    // create a new instance of RotationPy and the Twin object
59
    return new RotationPy(new Rotation);
60
}
61

62
// clang-format off
63
// constructor method
64
int RotationPy::PyInit(PyObject* args, PyObject* kwds)
65
{
66
    PyObject* o {};
67
    if (PyArg_ParseTuple(args, "")) {
68
        return 0;
69
    }
70

71
    PyErr_Clear();
72
    if (PyArg_ParseTuple(args, "O!", &(Base::RotationPy::Type), &o)) {
73
        Base::Rotation* rot = static_cast<Base::RotationPy*>(o)->getRotationPtr();
74
        getRotationPtr()->setValue(rot->getValue());
75
        return 0;
76
    }
77

78
    PyErr_Clear();
79
    double angle {};
80
    static const std::array<const char*, 3> kw_deg {"Axis", "Degree", nullptr};
81
    if (Base::Wrapped_ParseTupleAndKeywords(args,
82
                                            kwds,
83
                                            "O!d",
84
                                            kw_deg,
85
                                            &(Base::VectorPy::Type),
86
                                            &o,
87
                                            &angle)) {
88
        // NOTE: The last parameter defines the rotation angle in degree.
89
        getRotationPtr()->setValue(static_cast<Base::VectorPy*>(o)->value(),
90
                                   Base::toRadians<double>(angle));
91
        return 0;
92
    }
93

94
    PyErr_Clear();
95
    static const std::array<const char*, 3> kw_rad {"Axis", "Radian", nullptr};
96
    if (Base::Wrapped_ParseTupleAndKeywords(args,
97
                                            kwds,
98
                                            "O!d",
99
                                            kw_rad,
100
                                            &(Base::VectorPy::Type),
101
                                            &o,
102
                                            &angle)) {
103
        getRotationPtr()->setValue(static_cast<Base::VectorPy*>(o)->value(), angle);
104
        return 0;
105
    }
106

107
    PyErr_Clear();
108
    if (PyArg_ParseTuple(args, "O!", &(Base::MatrixPy::Type), &o)) {
109
        try {
110
            getRotationPtr()->setValue(static_cast<Base::MatrixPy*>(o)->value());
111
            return 0;
112
        }
113
        catch (const Base::Exception& e) {
114
            PyErr_SetString(e.getPyExceptionType(), e.what());
115
            return -1;
116
        }
117
    }
118

119
    PyErr_Clear();
120
    double q0 {};
121
    double q1 {};
122
    double q2 {};
123
    double q3 {};
124
    if (PyArg_ParseTuple(args, "dddd", &q0, &q1, &q2, &q3)) {
125
        getRotationPtr()->setValue(q0, q1, q2, q3);
126
        return 0;
127
    }
128

129
    PyErr_Clear();
130
    double y {};
131
    double p {};
132
    double r {};
133
    if (PyArg_ParseTuple(args, "ddd", &y, &p, &r)) {
134
        getRotationPtr()->setYawPitchRoll(y, p, r);
135
        return 0;
136
    }
137

138
    PyErr_Clear();
139
    const char* seq {};
140
    double a {};
141
    double b {};
142
    double c {};
143
    if (PyArg_ParseTuple(args, "sddd", &seq, &a, &b, &c)) {
144
        PY_TRY
145
        {
146
            getRotationPtr()->setEulerAngles(Rotation::eulerSequenceFromName(seq), a, b, c);
147
            return 0;
148
        }
149
        _PY_CATCH(return -1)
150
    }
151

152
    // NOLINTBEGIN
153
    double a11 = 1.0, a12 = 0.0, a13 = 0.0, a14 = 0.0;
154
    double a21 = 0.0, a22 = 1.0, a23 = 0.0, a24 = 0.0;
155
    double a31 = 0.0, a32 = 0.0, a33 = 1.0, a34 = 0.0;
156
    double a41 = 0.0, a42 = 0.0, a43 = 0.0, a44 = 1.0;
157
    // NOLINTEND
158

159
    // try read a 4x4 matrix
160
    PyErr_Clear();
161
    if (PyArg_ParseTuple(args,
162
                         "dddddddddddddddd",
163
                         &a11, &a12, &a13, &a14,
164
                         &a21, &a22, &a23, &a24,
165
                         &a31, &a32, &a33, &a34,
166
                         &a41, &a42, &a43, &a44)) {
167
        try {
168
            Matrix4D mtx(a11, a12, a13, a14,
169
                         a21, a22, a23, a24,
170
                         a31, a32, a33, a34,
171
                         a41, a42, a43, a44);
172
            getRotationPtr()->setValue(mtx);
173
            return 0;
174
        }
175
        catch (const Base::Exception& e) {
176
            PyErr_SetString(e.getPyExceptionType(), e.what());
177
            return -1;
178
        }
179
    }
180

181
    // try read a 3x3 matrix
182
    PyErr_Clear();
183
    if (PyArg_ParseTuple(args, "ddddddddd",
184
                         &a11, &a12, &a13,
185
                         &a21, &a22, &a23,
186
                         &a31, &a32, &a33)) {
187
        try {
188
            Matrix4D mtx(a11, a12, a13, a14,
189
                         a21, a22, a23, a24,
190
                         a31, a32, a33, a34,
191
                         a41, a42, a43, a44);
192
            getRotationPtr()->setValue(mtx);
193
            return 0;
194
        }
195
        catch (const Base::Exception& e) {
196
            PyErr_SetString(e.getPyExceptionType(), e.what());
197
            return -1;
198
        }
199
    }
200

201
    PyErr_Clear();
202
    PyObject* v1 {};
203
    PyObject* v2 {};
204
    if (PyArg_ParseTuple(args,
205
                         "O!O!",
206
                         &(Base::VectorPy::Type), &v1,
207
                         &(Base::VectorPy::Type), &v2)) {
208
        Py::Vector from(v1, false);
209
        Py::Vector to(v2, false);
210
        getRotationPtr()->setValue(from.toVector(), to.toVector());
211
        return 0;
212
    }
213

214
    PyErr_Clear();
215
    PyObject* v3 {};
216
    const char* priority = nullptr;
217
    if (PyArg_ParseTuple(args,
218
                         "O!O!O!|s",
219
                         &(Base::VectorPy::Type), &v1,
220
                         &(Base::VectorPy::Type), &v2,
221
                         &(Base::VectorPy::Type), &v3,
222
                         &priority)) {
223
        Py::Vector xdir(v1, false);
224
        Py::Vector ydir(v2, false);
225
        Py::Vector zdir(v3, false);
226
        if (!priority) {
227
            priority = "ZXY";
228
        }
229
        try {
230
            *getRotationPtr() = (Rotation::makeRotationByAxes(xdir.toVector(),
231
                                                              ydir.toVector(),
232
                                                              zdir.toVector(),
233
                                                              priority));
234
        }
235
        catch (Base::Exception& e) {
236
            std::string str;
237
            str += "FreeCAD exception thrown (";
238
            str += e.what();
239
            str += ")";
240
            PyErr_SetString(Base::PyExc_FC_GeneralError, str.c_str());
241
            return -1;
242
        }
243

244
        return 0;
245
    }
246

247
    PyErr_SetString(PyExc_TypeError,
248
                    "Rotation constructor accepts:\n"
249
                    "-- empty parameter list\n"
250
                    "-- Rotation object\n"
251
                    "-- four floats (a quaternion)\n"
252
                    "-- three floats (yaw, pitch, roll)\n"
253
                    "-- Vector (rotation axis) and float (rotation angle)\n"
254
                    "-- two Vectors (two axes)\n"
255
                    "-- Matrix object\n"
256
                    "-- 16 floats (4x4 matrix)\n"
257
                    "-- 9 floats (3x3 matrix)\n"
258
                    "-- 3 vectors + optional string");
259
    return -1;
260
}
261
// clang-format on
262

263
PyObject* RotationPy::richCompare(PyObject* v, PyObject* w, int op)
264
{
265
    if (PyObject_TypeCheck(v, &(RotationPy::Type)) && PyObject_TypeCheck(w, &(RotationPy::Type))) {
266
        Base::Rotation r1 = *static_cast<RotationPy*>(v)->getRotationPtr();
267
        Base::Rotation r2 = *static_cast<RotationPy*>(w)->getRotationPtr();
268

269
        PyObject* res = nullptr;
270
        if (op != Py_EQ && op != Py_NE) {
271
            PyErr_SetString(PyExc_TypeError, "no ordering relation is defined for Rotation");
272
            return nullptr;
273
        }
274
        if (op == Py_EQ) {
275
            res = (r1 == r2) ? Py_True : Py_False;
276
            Py_INCREF(res);
277
            return res;
278
        }
279
        res = (r1 != r2) ? Py_True : Py_False;
280
        Py_INCREF(res);
281
        return res;
282
    }
283
    // This always returns False
284
    Py_INCREF(Py_NotImplemented);
285
    return Py_NotImplemented;
286
}
287

288
PyObject* RotationPy::invert(PyObject* args)
289
{
290
    if (!PyArg_ParseTuple(args, "")) {
291
        return nullptr;
292
    }
293
    this->getRotationPtr()->invert();
294
    Py_Return;
295
}
296

297
PyObject* RotationPy::inverted(PyObject* args)
298
{
299
    if (!PyArg_ParseTuple(args, "")) {
300
        return nullptr;
301
    }
302
    Rotation mult = this->getRotationPtr()->inverse();
303
    return new RotationPy(new Rotation(mult));
304
}
305

306
PyObject* RotationPy::multiply(PyObject* args)
307
{
308
    PyObject* rot {};
309
    if (!PyArg_ParseTuple(args, "O!", &(RotationPy::Type), &rot)) {
310
        return nullptr;
311
    }
312
    Rotation mult = (*getRotationPtr()) * (*static_cast<RotationPy*>(rot)->getRotationPtr());
313
    return new RotationPy(new Rotation(mult));
314
}
315

316
PyObject* RotationPy::multVec(PyObject* args)
317
{
318
    PyObject* obj {};
319
    if (!PyArg_ParseTuple(args, "O!", &(VectorPy::Type), &obj)) {
320
        return nullptr;
321
    }
322
    Base::Vector3d vec(static_cast<VectorPy*>(obj)->value());
323
    getRotationPtr()->multVec(vec, vec);
324
    return new VectorPy(new Vector3d(vec));
325
}
326

327
PyObject* RotationPy::slerp(PyObject* args)
328
{
329
    PyObject* rot {};
330
    double t {};
331
    if (!PyArg_ParseTuple(args, "O!d", &(RotationPy::Type), &rot, &t)) {
332
        return nullptr;
333
    }
334
    Rotation* rot0 = this->getRotationPtr();
335
    Rotation* rot1 = static_cast<RotationPy*>(rot)->getRotationPtr();
336
    Rotation sl = Rotation::slerp(*rot0, *rot1, t);
337
    return new RotationPy(new Rotation(sl));
338
}
339

340
PyObject* RotationPy::setYawPitchRoll(PyObject* args)
341
{
342
    double A {};
343
    double B {};
344
    double C {};
345
    if (!PyArg_ParseTuple(args, "ddd", &A, &B, &C)) {
346
        return nullptr;
347
    }
348
    this->getRotationPtr()->setYawPitchRoll(A, B, C);
349
    Py_Return;
350
}
351

352
PyObject* RotationPy::getYawPitchRoll(PyObject* args)
353
{
354
    if (!PyArg_ParseTuple(args, "")) {
355
        return nullptr;
356
    }
357
    double A {};
358
    double B {};
359
    double C {};
360
    this->getRotationPtr()->getYawPitchRoll(A, B, C);
361

362
    Py::Tuple tuple(3);
363
    tuple.setItem(0, Py::Float(A));
364
    tuple.setItem(1, Py::Float(B));
365
    tuple.setItem(2, Py::Float(C));
366
    return Py::new_reference_to(tuple);
367
}
368

369
PyObject* RotationPy::setEulerAngles(PyObject* args)
370
{
371
    const char* seq {};
372
    double A {};
373
    double B {};
374
    double C {};
375
    if (!PyArg_ParseTuple(args, "sddd", &seq, &A, &B, &C)) {
376
        return nullptr;
377
    }
378

379
    try {
380
        getRotationPtr()->setEulerAngles(Rotation::eulerSequenceFromName(seq), A, B, C);
381
        Py_Return;
382
    }
383
    catch (const Base::Exception& e) {
384
        e.setPyException();
385
        return nullptr;
386
    }
387
}
388

389
PyObject* RotationPy::toEulerAngles(PyObject* args)
390
{
391
    const char* seq = nullptr;
392
    if (!PyArg_ParseTuple(args, "|s", &seq)) {
393
        return nullptr;
394
    }
395
    if (!seq) {
396
        Py::List res;
397
        for (int i = 1; i < Rotation::EulerSequenceLast; ++i) {
398
            res.append(Py::String(Rotation::eulerSequenceName((Rotation::EulerSequence)i)));
399
        }
400
        return Py::new_reference_to(res);
401
    }
402

403
    PY_TRY
404
    {
405
        double A {};
406
        double B {};
407
        double C {};
408
        this->getRotationPtr()->getEulerAngles(Rotation::eulerSequenceFromName(seq), A, B, C);
409

410
        Py::Tuple tuple(3);
411
        tuple.setItem(0, Py::Float(A));
412
        tuple.setItem(1, Py::Float(B));
413
        tuple.setItem(2, Py::Float(C));
414
        return Py::new_reference_to(tuple);
415
    }
416
    PY_CATCH
417
}
418

419
PyObject* RotationPy::toMatrix(PyObject* args)
420
{
421
    if (!PyArg_ParseTuple(args, "")) {
422
        return nullptr;
423
    }
424
    Base::Matrix4D mat;
425
    getRotationPtr()->getValue(mat);
426
    return new MatrixPy(new Matrix4D(mat));
427
}
428

429
PyObject* RotationPy::isSame(PyObject* args)
430
{
431
    PyObject* rot {};
432
    double tol = 0.0;
433
    if (!PyArg_ParseTuple(args, "O!|d", &(RotationPy::Type), &rot, &tol)) {
434
        return nullptr;
435
    }
436
    Base::Rotation rot1 = *getRotationPtr();
437
    Base::Rotation rot2 = *static_cast<RotationPy*>(rot)->getRotationPtr();
438
    bool same = tol > 0.0 ? rot1.isSame(rot2, tol) : rot1.isSame(rot2);
439
    return Py_BuildValue("O", (same ? Py_True : Py_False));
440
}
441

442
PyObject* RotationPy::isIdentity(PyObject* args)
443
{
444
    double tol = 0.0;
445
    if (!PyArg_ParseTuple(args, "|d", &tol)) {
446
        return nullptr;
447
    }
448
    bool null = tol > 0.0 ? getRotationPtr()->isIdentity(tol) : getRotationPtr()->isIdentity();
449
    return Py_BuildValue("O", (null ? Py_True : Py_False));
450
}
451

452
PyObject* RotationPy::isNull(PyObject* args)
453
{
454
    if (!PyArg_ParseTuple(args, "")) {
455
        return nullptr;
456
    }
457
    bool null = getRotationPtr()->isNull();
458
    return Py_BuildValue("O", (null ? Py_True : Py_False));
459
}
460

461
Py::Tuple RotationPy::getQ() const
462
{
463
    double q0 {};
464
    double q1 {};
465
    double q2 {};
466
    double q3 {};
467
    this->getRotationPtr()->getValue(q0, q1, q2, q3);
468

469
    Py::Tuple tuple(4);
470
    tuple.setItem(0, Py::Float(q0));
471
    tuple.setItem(1, Py::Float(q1));
472
    tuple.setItem(2, Py::Float(q2));
473
    tuple.setItem(3, Py::Float(q3));
474
    return tuple;
475
}
476

477
void RotationPy::setQ(Py::Tuple arg)
478
{
479
    double q0 = static_cast<double>(Py::Float(arg.getItem(0)));
480
    double q1 = static_cast<double>(Py::Float(arg.getItem(1)));
481
    double q2 = static_cast<double>(Py::Float(arg.getItem(2)));
482
    double q3 = static_cast<double>(Py::Float(arg.getItem(3)));
483
    this->getRotationPtr()->setValue(q0, q1, q2, q3);
484
}
485

486
Py::Object RotationPy::getRawAxis() const
487
{
488
    Base::Vector3d axis;
489
    double angle {};
490
    this->getRotationPtr()->getRawValue(axis, angle);
491
    return Py::Vector(axis);  // NOLINT
492
}
493

494
Py::Object RotationPy::getAxis() const
495
{
496
    Base::Vector3d axis;
497
    double angle {};
498
    this->getRotationPtr()->getValue(axis, angle);
499
    return Py::Vector(axis);  // NOLINT
500
}
501

502
void RotationPy::setAxis(Py::Object arg)
503
{
504
    Base::Vector3d axis;
505
    double angle {};
506
    this->getRotationPtr()->getValue(axis, angle);
507
    axis = Py::Vector(arg).toVector();
508
    this->getRotationPtr()->setValue(axis, angle);
509
}
510

511
Py::Float RotationPy::getAngle() const
512
{
513
    Base::Vector3d axis;
514
    double angle {};
515
    this->getRotationPtr()->getValue(axis, angle);
516
    return Py::Float(angle);
517
}
518

519
void RotationPy::setAngle(Py::Float arg)
520
{
521
    Base::Vector3d axis;
522
    double angle {};
523
    this->getRotationPtr()->getRawValue(axis, angle);
524
    angle = static_cast<double>(arg);
525
    this->getRotationPtr()->setValue(axis, angle);
526
}
527

528
PyObject* RotationPy::getCustomAttributes(const char* attr) const
529
{
530
    if (strcmp(attr, "Matrix") == 0) {
531
        Matrix4D mat;
532
        this->getRotationPtr()->getValue(mat);
533
        return new MatrixPy(mat);
534
    }
535
    if (strcmp(attr, "Yaw") == 0) {
536
        double A {};
537
        double B {};
538
        double C {};
539
        this->getRotationPtr()->getYawPitchRoll(A, B, C);
540
        return PyFloat_FromDouble(A);
541
    }
542
    if (strcmp(attr, "Pitch") == 0) {
543
        double A {};
544
        double B {};
545
        double C {};
546
        this->getRotationPtr()->getYawPitchRoll(A, B, C);
547
        return PyFloat_FromDouble(B);
548
    }
549
    if (strcmp(attr, "Roll") == 0) {
550
        double A {};
551
        double B {};
552
        double C {};
553
        this->getRotationPtr()->getYawPitchRoll(A, B, C);
554
        return PyFloat_FromDouble(C);
555
    }
556
    if (strcmp(attr, "toEuler") == 0) {
557
        // NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast)
558
        Py::Object self(const_cast<RotationPy*>(this), false);
559
        return Py::new_reference_to(self.getAttr("getYawPitchRoll"));
560
    }
561
    return nullptr;
562
}
563

564
int RotationPy::setCustomAttributes(const char* attr, PyObject* obj)
565
{
566
    if (strcmp(attr, "Matrix") == 0) {
567
        if (PyObject_TypeCheck(obj, &(MatrixPy::Type))) {
568
            try {
569
                this->getRotationPtr()->setValue(*static_cast<MatrixPy*>(obj)->getMatrixPtr());
570
                return 1;
571
            }
572
            catch (const Base::Exception& e) {
573
                PyErr_SetString(e.getPyExceptionType(), e.what());
574
                return -1;
575
            }
576
        }
577
    }
578
    else if (strcmp(attr, "Axes") == 0) {
579
        if (PySequence_Check(obj)) {
580
            Py::Sequence sequence(obj);
581
            if (sequence.size() == 2) {
582
                Py::Object vec1 = sequence.getItem(0);
583
                Py::Object vec2 = sequence.getItem(1);
584
                if (PyObject_TypeCheck(vec1.ptr(), &(VectorPy::Type))
585
                    && PyObject_TypeCheck(vec2.ptr(), &(VectorPy::Type))) {
586
                    Base::Vector3d* pt1 = static_cast<VectorPy*>(vec1.ptr())->getVectorPtr();
587
                    Base::Vector3d* pt2 = static_cast<VectorPy*>(vec2.ptr())->getVectorPtr();
588
                    this->getRotationPtr()->setValue(*pt1, *pt2);
589
                    return 1;
590
                }
591
            }
592
        }
593
    }
594
    else if (strcmp(attr, "Yaw") == 0) {
595
        if (PyNumber_Check(obj)) {
596
            double V = PyFloat_AsDouble(obj);
597
            double A {};
598
            double B {};
599
            double C {};
600
            this->getRotationPtr()->getYawPitchRoll(A, B, C);
601
            this->getRotationPtr()->setYawPitchRoll(V, B, C);
602
            return 1;
603
        }
604
    }
605
    else if (strcmp(attr, "Pitch") == 0) {
606
        if (PyNumber_Check(obj)) {
607
            double V = PyFloat_AsDouble(obj);
608
            double A {};
609
            double B {};
610
            double C {};
611
            this->getRotationPtr()->getYawPitchRoll(A, B, C);
612
            this->getRotationPtr()->setYawPitchRoll(A, V, C);
613
            return 1;
614
        }
615
    }
616
    else if (strcmp(attr, "Roll") == 0) {
617
        if (PyNumber_Check(obj)) {
618
            double V = PyFloat_AsDouble(obj);
619
            double A {};
620
            double B {};
621
            double C {};
622
            this->getRotationPtr()->getYawPitchRoll(A, B, C);
623
            this->getRotationPtr()->setYawPitchRoll(A, B, V);
624
            return 1;
625
        }
626
    }
627
    return 0;
628
}
629

630
PyObject* RotationPy::number_multiply_handler(PyObject* self, PyObject* other)
631
{
632
    if (PyObject_TypeCheck(self, &(RotationPy::Type))) {
633
        auto a = static_cast<RotationPy*>(self)->value();
634

635
        if (PyObject_TypeCheck(other, &(VectorPy::Type))) {
636
            Vector3d res;
637
            a.multVec(static_cast<VectorPy*>(other)->value(), res);
638
            return new VectorPy(res);
639
        }
640

641
        if (PyObject_TypeCheck(other, &(PlacementPy::Type))) {
642
            const auto& b = static_cast<PlacementPy*>(other)->value();
643
            return new PlacementPy(Placement(Vector3d(), a) * b);
644
        }
645

646
        if (PyObject_TypeCheck(other, &(RotationPy::Type))) {
647
            const auto& b = static_cast<RotationPy*>(other)->value();
648
            return new RotationPy(a * b);
649
        }
650

651
        if (PyObject_TypeCheck(other, &(MatrixPy::Type))) {
652
            const auto& b = static_cast<MatrixPy*>(other)->value();
653
            Matrix4D mat;
654
            a.getValue(mat);
655
            return new MatrixPy(mat * b);
656
        }
657
    }
658

659
    PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
660
    return nullptr;
661
}
662

663
PyObject* RotationPy::number_power_handler(PyObject* self, PyObject* other, PyObject* arg)
664
{
665
    if (!PyObject_TypeCheck(self, &(RotationPy::Type)) || !PyLong_Check(other) || arg != Py_None) {
666
        PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
667
        return nullptr;
668
    }
669

670
    Rotation a = static_cast<RotationPy*>(self)->value();
671
    long b = Py::Long(other);
672

673
    Vector3d axis;
674
    double rfAngle {};
675

676
    a.getRawValue(axis, rfAngle);
677
    rfAngle *= double(b);
678
    a.setValue(axis, rfAngle);
679

680
    return new RotationPy(a);
681
}
682

683
PyObject* RotationPy::number_add_handler(PyObject* /*self*/, PyObject* /*other*/)
684
{
685
    PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
686
    return nullptr;
687
}
688

689
PyObject* RotationPy::number_subtract_handler(PyObject* /*self*/, PyObject* /*other*/)
690
{
691
    PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
692
    return nullptr;
693
}
694

695
PyObject* RotationPy::number_divide_handler(PyObject* /*self*/, PyObject* /*other*/)
696
{
697
    PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
698
    return nullptr;
699
}
700

701
PyObject* RotationPy::number_remainder_handler(PyObject* /*self*/, PyObject* /*other*/)
702
{
703
    PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
704
    return nullptr;
705
}
706

707
PyObject* RotationPy::number_divmod_handler(PyObject* /*self*/, PyObject* /*other*/)
708
{
709
    PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
710
    return nullptr;
711
}
712

713
PyObject* RotationPy::number_negative_handler(PyObject* /*self*/)
714
{
715
    PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
716
    return nullptr;
717
}
718

719
PyObject* RotationPy::number_positive_handler(PyObject* /*self*/)
720
{
721
    PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
722
    return nullptr;
723
}
724

725
PyObject* RotationPy::number_absolute_handler(PyObject* /*self*/)
726
{
727
    PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
728
    return nullptr;
729
}
730

731
int RotationPy::number_nonzero_handler(PyObject* /*self*/)
732
{
733
    return 1;
734
}
735

736
PyObject* RotationPy::number_invert_handler(PyObject* /*self*/)
737
{
738
    PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
739
    return nullptr;
740
}
741

742
PyObject* RotationPy::number_lshift_handler(PyObject* /*self*/, PyObject* /*other*/)
743
{
744
    PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
745
    return nullptr;
746
}
747

748
PyObject* RotationPy::number_rshift_handler(PyObject* /*self*/, PyObject* /*other*/)
749
{
750
    PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
751
    return nullptr;
752
}
753

754
PyObject* RotationPy::number_and_handler(PyObject* /*self*/, PyObject* /*other*/)
755
{
756
    PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
757
    return nullptr;
758
}
759

760
PyObject* RotationPy::number_xor_handler(PyObject* /*self*/, PyObject* /*other*/)
761
{
762
    PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
763
    return nullptr;
764
}
765

766
PyObject* RotationPy::number_or_handler(PyObject* /*self*/, PyObject* /*other*/)
767
{
768
    PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
769
    return nullptr;
770
}
771

772
PyObject* RotationPy::number_int_handler(PyObject* /*self*/)
773
{
774
    PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
775
    return nullptr;
776
}
777

778
PyObject* RotationPy::number_float_handler(PyObject* /*self*/)
779
{
780
    PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
781
    return nullptr;
782
}
783

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.