Part: Use Base::toRadians to convert degree to radian

This commit is contained in:
wmayer
2024-10-22 14:16:18 +02:00
committed by Chris Hennes
parent 0b0bb18323
commit 14cd061809
5 changed files with 30 additions and 46 deletions

View File

@@ -81,6 +81,7 @@
#include <Base/GeometryPyCXX.h>
#include <Base/Interpreter.h>
#include <Base/PyWrapParseTupleAndKeywords.h>
#include <Base/Tools.h>
#include <Base/VectorPy.h>
#include "BSplineSurfacePy.h"
@@ -112,14 +113,6 @@
extern const char* BRepBuilderAPI_FaceErrorText(BRepBuilderAPI_FaceError fe);
#ifndef M_PI
#define M_PI 3.14159265358979323846 /* pi */
#endif
#ifndef M_PI_2
#define M_PI_2 1.57079632679489661923 /* pi/2 */
#endif
namespace Part {
PartExport void getPyShapes(PyObject* obj, std::vector<TopoShape>& shapes)
@@ -1427,7 +1420,9 @@ private:
circle.SetRadius(radius);
Handle(Geom_Circle) hCircle = new Geom_Circle (circle);
BRepBuilderAPI_MakeEdge aMakeEdge(hCircle, angle1*(M_PI/180), angle2*(M_PI/180));
BRepBuilderAPI_MakeEdge aMakeEdge(hCircle,
Base::toRadians<double>(angle1),
Base::toRadians<double>(angle2));
TopoDS_Edge edge = aMakeEdge.Edge();
return Py::asObject(new TopoShapeEdgePy(new TopoShape(edge)));
}
@@ -1457,7 +1452,10 @@ private:
Base::Vector3d vec = static_cast<Base::VectorPy*>(pDir)->value();
d.SetCoord(vec.x, vec.y, vec.z);
}
BRepPrimAPI_MakeSphere mkSphere(gp_Ax2(p,d), radius, angle1*(M_PI/180), angle2*(M_PI/180), angle3*(M_PI/180));
BRepPrimAPI_MakeSphere mkSphere(gp_Ax2(p,d), radius,
Base::toRadians<double>(angle1),
Base::toRadians<double>(angle2),
Base::toRadians<double>(angle3));
TopoDS_Shape shape = mkSphere.Shape();
return Py::asObject(new TopoShapeSolidPy(new TopoShape(shape)));
}
@@ -1487,7 +1485,8 @@ private:
Base::Vector3d vec = static_cast<Base::VectorPy*>(pDir)->value();
d.SetCoord(vec.x, vec.y, vec.z);
}
BRepPrimAPI_MakeCylinder mkCyl(gp_Ax2(p,d),radius, height, angle*(M_PI/180));
BRepPrimAPI_MakeCylinder mkCyl(gp_Ax2(p,d),radius, height,
Base::toRadians<double>(angle));
TopoDS_Shape shape = mkCyl.Shape();
return Py::asObject(new TopoShapeSolidPy(new TopoShape(shape)));
}
@@ -1517,7 +1516,8 @@ private:
Base::Vector3d vec = static_cast<Base::VectorPy*>(pDir)->value();
d.SetCoord(vec.x, vec.y, vec.z);
}
BRepPrimAPI_MakeCone mkCone(gp_Ax2(p,d),radius1, radius2, height, angle*(M_PI/180));
BRepPrimAPI_MakeCone mkCone(gp_Ax2(p,d),radius1, radius2, height,
Base::toRadians<double>(angle));
TopoDS_Shape shape = mkCone.Shape();
return Py::asObject(new TopoShapeSolidPy(new TopoShape(shape)));
}
@@ -1547,7 +1547,10 @@ private:
Base::Vector3d vec = static_cast<Base::VectorPy*>(pDir)->value();
d.SetCoord(vec.x, vec.y, vec.z);
}
BRepPrimAPI_MakeTorus mkTorus(gp_Ax2(p,d), radius1, radius2, angle1*(M_PI/180), angle2*(M_PI/180), angle*(M_PI/180));
BRepPrimAPI_MakeTorus mkTorus(gp_Ax2(p,d), radius1, radius2,
Base::toRadians<double>(angle1),
Base::toRadians<double>(angle2),
Base::toRadians<double>(angle));
const TopoDS_Shape& shape = mkTorus.Shape();
return Py::asObject(new TopoShapeSolidPy(new TopoShape(shape)));
}
@@ -1695,7 +1698,8 @@ private:
PyObject* shellType = Base::getTypeAsObject(&Part::TopoShapeShellPy::Type);
PyObject* faceType = Base::getTypeAsObject(&Part::TopoShapeFacePy::Type);
BRepPrimAPI_MakeRevolution mkRev(gp_Ax2(p,d),curve, vmin, vmax, angle*(M_PI/180));
BRepPrimAPI_MakeRevolution mkRev(gp_Ax2(p,d),curve, vmin, vmax,
Base::toRadians<double>(angle));
if (type == defaultType) {
TopoDS_Shape shape = mkRev.Solid();
return Py::asObject(new TopoShapeSolidPy(new TopoShape(shape)));

View File

@@ -39,10 +39,6 @@
# include <IntRes2d_IntersectionSegment.hxx>
#endif
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#include <App/FeaturePythonPyImp.h>
#include <App/PropertyLinks.h>
#include <Base/Reader.h>

View File

@@ -52,11 +52,6 @@
#include "PrimitiveFeature.h"
#include "PartFeaturePy.h"
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
namespace Part {
const App::PropertyQuantityConstraint::Constraints apexRange = {-89.9, 89.9, 0.1};
const App::PropertyQuantityConstraint::Constraints torusRangeV = {-180.0, 180.0, 1.0};
@@ -363,9 +358,9 @@ App::DocumentObjectExecReturn *Sphere::execute()
return new App::DocumentObjectExecReturn("Radius of sphere too small");
try {
BRepPrimAPI_MakeSphere mkSphere(Radius.getValue(),
Angle1.getValue()/180.0f*M_PI,
Angle2.getValue()/180.0f*M_PI,
Angle3.getValue()/180.0f*M_PI);
Base::toRadians<double>(Angle1.getValue()),
Base::toRadians<double>(Angle2.getValue()),
Base::toRadians<double>(Angle3.getValue()));
TopoDS_Shape ResultShape = mkSphere.Shape();
this->Shape.setValue(ResultShape);
}
@@ -426,9 +421,9 @@ App::DocumentObjectExecReturn *Ellipsoid::execute()
gp_Ax2 ax2(pnt,dir);
BRepPrimAPI_MakeSphere mkSphere(ax2,
Radius2.getValue(),
Angle1.getValue()/180.0f*M_PI,
Angle2.getValue()/180.0f*M_PI,
Angle3.getValue()/180.0f*M_PI);
Base::toRadians<double>(Angle1.getValue()),
Base::toRadians<double>(Angle2.getValue()),
Base::toRadians<double>(Angle3.getValue()));
Standard_Real scaleX = 1.0;
Standard_Real scaleZ = Radius1.getValue()/Radius2.getValue();
// issue #1798: A third radius has been introduced. To be backward
@@ -803,7 +798,7 @@ App::DocumentObjectExecReturn *Helix::execute()
Standard_Real nbTurns = myHeight / myPitch;
if (nbTurns > 1e4)
Standard_Failure::Raise("Number of turns too high (> 1e4)");
Standard_Real myRadiusTop = myRadius + myHeight * tan(myAngle/180.0f*M_PI);
Standard_Real myRadiusTop = myRadius + myHeight * tan(Base::toRadians<double>(myAngle));
this->Shape.setValue(TopoShape().makeSpiralHelix(myRadius, myRadiusTop, myHeight, nbTurns, mySegLen, myLocalCS));
// props.Mass() may seem a strange way to get the Length, but

View File

@@ -74,6 +74,7 @@
#include <Base/PyWrapParseTupleAndKeywords.h>
#include <Base/Rotation.h>
#include <Base/Stream.h>
#include <Base/Tools.h>
#include <Base/Vector3D.h>
#include <Base/VectorPy.h>
@@ -100,14 +101,6 @@
using namespace Part;
#ifndef M_PI
#define M_PI 3.14159265358979323846 /* pi */
#endif
#ifndef M_PI_2
#define M_PI_2 1.57079632679489661923 /* pi/2 */
#endif
static Py_hash_t _TopoShapeHash(PyObject* self)
{
if (!self) {
@@ -647,15 +640,15 @@ PyObject* TopoShapePy::extrude(PyObject *args)
PyObject* TopoShapePy::revolve(PyObject *args)
{
PyObject *pPos,*pDir;
double d=360;
if (!PyArg_ParseTuple(args, "O!O!|d", &(Base::VectorPy::Type), &pPos, &(Base::VectorPy::Type), &pDir,&d))
double angle=360;
if (!PyArg_ParseTuple(args, "O!O!|d", &(Base::VectorPy::Type), &pPos, &(Base::VectorPy::Type), &pDir,&angle))
return nullptr;
Base::Vector3d pos = static_cast<Base::VectorPy*>(pPos)->value();
Base::Vector3d dir = static_cast<Base::VectorPy*>(pDir)->value();
try {
return Py::new_reference_to(shape2pyshape(getTopoShapePtr()->makeElementRevolve(
gp_Ax1(gp_Pnt(pos.x, pos.y, pos.z), gp_Dir(dir.x, dir.y, dir.z)),
d * (M_PI / 180))));
Base::toRadians<double>(angle))));
}
catch (Standard_Failure& e) {
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
@@ -1081,7 +1074,7 @@ PyObject* TopoShapePy::rotate(PyObject *args)
gp_Ax1 axis(pos, dir);
gp_Trsf mov;
mov.SetRotation(axis, angle*(M_PI/180));
mov.SetRotation(axis, Base::toRadians<double>(angle));
TopLoc_Location loc(mov);
TopoDS_Shape shape = getTopoShapePtr()->getShape();
shape.Move(loc);

View File

@@ -48,10 +48,6 @@
FC_LOG_LEVEL_INIT("PartDesign",true,true)
#ifndef M_PI
# define M_PI 3.14159265358979323846
#endif
using namespace PartDesign;
namespace sp = std::placeholders;