diff --git a/src/Base/Builder3D.cpp b/src/Base/Builder3D.cpp index 617682a00..94a61c121 100644 --- a/src/Base/Builder3D.cpp +++ b/src/Base/Builder3D.cpp @@ -426,6 +426,17 @@ void InventorBuilder::endPoints(void) result << Base::blanks(indent) << "]" << std::endl; indent -= 2; result << Base::blanks(indent) << "}" << std::endl; +} + +/** + * Adds an SoPointSet node after creating an SoCordinate3 node with + * beginPoints() and endPoints(). + * @see startPoints() + * @see beginPoints() + * @see endPoints() + */ +void InventorBuilder::addPointSet(void) +{ result << Base::blanks(indent) << "PointSet { } " << std::endl; } diff --git a/src/Base/Builder3D.h b/src/Base/Builder3D.h index 0f2a2a359..0181790cf 100644 --- a/src/Base/Builder3D.h +++ b/src/Base/Builder3D.h @@ -164,6 +164,8 @@ public: void addPoint(const Vector3f &vec); /// ends the points set operation void endPoints(void); + /// add an SoPointSet node + void addPointSet(void); //@} /** @name Line/Direction handling */ diff --git a/src/Base/Vector3D.cpp b/src/Base/Vector3D.cpp index fbc197f55..03239a858 100644 --- a/src/Base/Vector3D.cpp +++ b/src/Base/Vector3D.cpp @@ -194,7 +194,7 @@ Vector3<_Precision>& Vector3<_Precision>::ProjToPlane (const Vector3<_Precision> const Vector3<_Precision> &rclNorm) { Vector3<_Precision> clTemp(rclNorm); - *this = *this - (clTemp *= ((*this - rclBase) * clTemp)); + *this = *this - (clTemp *= ((*this - rclBase) * clTemp) / clTemp.Sqr()); return *this; } @@ -202,7 +202,7 @@ template _Precision Vector3<_Precision>::DistanceToPlane (const Vector3<_Precision> &rclBase, const Vector3<_Precision> &rclNorm) const { - return (*this - rclBase) * rclNorm; + return ((*this - rclBase) * rclNorm) / rclNorm.Length(); } template @@ -361,7 +361,7 @@ template Vector3<_Precision> & Vector3<_Precision>::Normalize (void) { _Precision fLen = Length (); - if (fLen != 0.0f) { + if (fLen != (_Precision)0.0 && fLen != (_Precision)1.0) { x /= fLen; y /= fLen; z /= fLen; diff --git a/src/Base/VectorPy.xml b/src/Base/VectorPy.xml index 55d35848e..4171ac2a1 100644 --- a/src/Base/VectorPy.xml +++ b/src/Base/VectorPy.xml @@ -73,6 +73,11 @@ Deliver the distance of the point to a given line + + + Deliver the distance of the point to a given line segment + + Deliver the distance of the point to a given plane diff --git a/src/Base/VectorPyImp.cpp b/src/Base/VectorPyImp.cpp index ee19a947f..b5546ca7a 100644 --- a/src/Base/VectorPyImp.cpp +++ b/src/Base/VectorPyImp.cpp @@ -401,6 +401,31 @@ PyObject* VectorPy::distanceToLine(PyObject *args) return Py::new_reference_to(dist); } +PyObject* VectorPy::distanceToLineSegment(PyObject *args) +{ + PyObject *base, *line; + if (!PyArg_ParseTuple(args, "OO",&base, &line)) + return 0; + if (!PyObject_TypeCheck(base, &(VectorPy::Type))) { + PyErr_SetString(PyExc_TypeError, "First arg must be Vector"); + return 0; + } + if (!PyObject_TypeCheck(line, &(VectorPy::Type))) { + PyErr_SetString(PyExc_TypeError, "Second arg must be Vector"); + return 0; + } + + VectorPy* base_vec = static_cast(base); + VectorPy* line_vec = static_cast(line); + + VectorPy::PointerType this_ptr = reinterpret_cast(_pcTwinPointer); + VectorPy::PointerType base_ptr = reinterpret_cast(base_vec->_pcTwinPointer); + VectorPy::PointerType line_ptr = reinterpret_cast(line_vec->_pcTwinPointer); + + Vector3d v = this_ptr->DistanceToLineSegment(*base_ptr, *line_ptr); + return new VectorPy(v); +} + PyObject* VectorPy::distanceToPlane(PyObject *args) { PyObject *base, *line; diff --git a/src/Mod/Points/App/PointsPyImp.cpp b/src/Mod/Points/App/PointsPyImp.cpp index e596a45e6..75df742c8 100644 --- a/src/Mod/Points/App/PointsPyImp.cpp +++ b/src/Mod/Points/App/PointsPyImp.cpp @@ -120,6 +120,7 @@ PyObject* PointsPy::writeInventor(PyObject * args) for (Points::PointKernel::const_iterator it = kernel->begin(); it != kernel->end(); ++it) builder.addPoint((float)it->x,(float)it->y,(float)it->z); builder.endPoints(); + builder.addPointSet(); builder.close(); return Py::new_reference_to(Py::String(result.str()));