From 25bf33077e9eb4a0dce33e32aef0f32451719e35 Mon Sep 17 00:00:00 2001 From: wmayer Date: Wed, 13 Dec 2017 16:58:12 +0100 Subject: [PATCH] rename Placement.isNull to Placement.isIdentity implement Rotation.isNull and Rotation.isIdentity --- src/Base/PlacementPy.xml | 4 ++-- src/Base/PlacementPyImp.cpp | 8 +++----- src/Base/Rotation.cpp | 9 +++++++++ src/Base/Rotation.h | 1 + src/Base/RotationPy.xml | 10 +++++++++- src/Base/RotationPyImp.cpp | 12 +++++++++--- 6 files changed, 33 insertions(+), 11 deletions(-) diff --git a/src/Base/PlacementPy.xml b/src/Base/PlacementPy.xml index 9916fc4829..943dc87945 100644 --- a/src/Base/PlacementPy.xml +++ b/src/Base/PlacementPy.xml @@ -76,10 +76,10 @@ Placement(Base, Axis, Angle) -- define position and rotation - + - isNull() -> Bool + isIdentity() -> Bool returns True if the placement has no displacement and no rotation diff --git a/src/Base/PlacementPyImp.cpp b/src/Base/PlacementPyImp.cpp index 3f1096513d..76a19833a5 100644 --- a/src/Base/PlacementPyImp.cpp +++ b/src/Base/PlacementPyImp.cpp @@ -200,16 +200,14 @@ PyObject* PlacementPy::inverse(PyObject * args) return new PlacementPy(new Placement(p)); } -PyObject* PlacementPy::isNull(PyObject *args) +PyObject* PlacementPy::isIdentity(PyObject *args) { if (!PyArg_ParseTuple(args, "")) return NULL; + Base::Vector3d nullvec(0,0,0); Base::Vector3d pos = getPlacementPtr()->getPosition(); Base::Rotation rot = getPlacementPtr()->getRotation(); - Base::Vector3d nullvec(0,0,0); - Base::Rotation nullrot(0,0,0,1); - Base::Rotation nullrotinv(0,0,0,-1); - bool null = (pos == nullvec) & ((rot == nullrot) | (rot == nullrotinv)); + bool null = (pos == nullvec) && (rot.isIdentity()); return Py_BuildValue("O", (null ? Py_True : Py_False)); } diff --git a/src/Base/Rotation.cpp b/src/Base/Rotation.cpp index 3799367cc4..cdcb66e2f3 100644 --- a/src/Base/Rotation.cpp +++ b/src/Base/Rotation.cpp @@ -658,6 +658,15 @@ void Rotation::getYawPitchRoll(double& y, double& p, double& r) const r = (r/D_PI)*180; } +bool Rotation::isIdentity() const +{ + return ((this->quat[0] == 0 && + this->quat[1] == 0 && + this->quat[2] == 0) && + (this->quat[3] == 1 || + this->quat[3] == -1); +} + bool Rotation::isNull() const { return (this->quat[0] == 0 && diff --git a/src/Base/Rotation.h b/src/Base/Rotation.h index a7cd8fedc2..a39e9bd5be 100644 --- a/src/Base/Rotation.h +++ b/src/Base/Rotation.h @@ -63,6 +63,7 @@ public: void setYawPitchRoll(double y, double p, double r); /// Euler angles in yaw,pitch,roll notation void getYawPitchRoll(double& y, double& p, double& r) const; + bool isIdentity() const; bool isNull() const; //@} diff --git a/src/Base/RotationPy.xml b/src/Base/RotationPy.xml index 9d8a010e09..4106d55762 100644 --- a/src/Base/RotationPy.xml +++ b/src/Base/RotationPy.xml @@ -84,10 +84,18 @@ isNull() -> Bool - returns True if the rotation equals the unity matrix + returns True if all Q values are zero + + + + isIdentity() -> Bool + returns True if the rotation equals the unity matrix + + + The rotation elements (as quaternion) diff --git a/src/Base/RotationPyImp.cpp b/src/Base/RotationPyImp.cpp index 5eac5abf92..6b7f642d57 100644 --- a/src/Base/RotationPyImp.cpp +++ b/src/Base/RotationPyImp.cpp @@ -282,13 +282,19 @@ PyObject* RotationPy::isSame(PyObject *args) return Py_BuildValue("O", (same ? Py_True : Py_False)); } +PyObject* RotationPy::isIdentity(PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")) + return NULL; + bool null = getRotationPtr()->isIdentity(); + return Py_BuildValue("O", (null ? Py_True : Py_False)); +} + PyObject* RotationPy::isNull(PyObject *args) { if (!PyArg_ParseTuple(args, "")) return NULL; - Base::Rotation rot = * getRotationPtr(); - Base::Rotation nullrot(0,0,0,1); - bool null = rot.isSame(nullrot); + bool null = getRotationPtr()->isNull(); return Py_BuildValue("O", (null ? Py_True : Py_False)); }