Base: extend Placement/Rotation API

* Add Placement::isSame() and expose to Python
* Add Placement::multRight/Placement::multLeft
* Fix PlacementPy::rotate
* Add Rotation::multRight/Rotation::multLeft
* Add a test feature FeatureTestPlacement for uni tests
* Add unit tests
This commit is contained in:
wmayer
2022-08-09 11:54:05 +02:00
parent 6067b18774
commit 91ea39a5c0
11 changed files with 217 additions and 20 deletions

View File

@@ -171,27 +171,23 @@ PyObject* PlacementPy::rotate(PyObject *args, PyObject *kwds)
Vector3d axis;
PyObject* pyComp = Py_False;
if (!PyArg_ParseTupleAndKeywords(args, kwds, "(ddd)(ddd)d|$O!", keywords, &center.x, &center.y, &center.z,
if (!PyArg_ParseTupleAndKeywords(args, kwds, "(ddd)(ddd)d|O!", keywords, &center.x, &center.y, &center.z,
&axis.x, &axis.y, &axis.z, &angle, &PyBool_Type, &pyComp))
return nullptr;
try {
/*
* if comp is False, we retain the original behaviour that - contrary to the documentation - generates
* if comp is False, we retain the original behaviour that - contrary to the (old) documentation - generates
* Placements different from TopoShape.rotate() to ensure compatibility for existing code
*/
bool comp = Base::asBoolean(pyComp);
if (!comp) {
(*getPlacementPtr()) *= Placement(
Vector3d(),Rotation(axis,toRadians<double>(angle)),center);
} else
{
getPlacementPtr()->multRight(Placement(Vector3d(), Rotation(axis, toRadians<double>(angle)), center));
}
else {
// multiply new Placement the same way TopoShape.rotate() does
Placement p = *getPlacementPtr();
*getPlacementPtr() = Placement(
Vector3d(),Rotation(axis,toRadians<double>(angle)),center) * p;
getPlacementPtr()->multLeft(Placement(Vector3d(), Rotation(axis, toRadians<double>(angle)), center));
}
Py_Return;
@@ -285,6 +281,19 @@ PyObject* PlacementPy::isIdentity(PyObject *args)
return Py_BuildValue("O", (none ? Py_True : Py_False));
}
PyObject* PlacementPy::isSame(PyObject *args)
{
PyObject* plm;
double tol = 0.0;
if (!PyArg_ParseTuple(args, "O!|d", &PlacementPy::Type, &plm, &tol))
return nullptr;
Base::Placement plm1 = * getPlacementPtr();
Base::Placement plm2 = * static_cast<PlacementPy*>(plm)->getPlacementPtr();
bool same = tol > 0.0 ? plm1.isSame(plm2, tol) : plm1.isSame(plm2);
return Py_BuildValue("O", (same ? Py_True : Py_False));
}
Py::Object PlacementPy::getBase() const
{
return Py::Vector(getPlacementPtr()->getPosition());