diff --git a/changes.txt b/changes.txt index 8db07c76..6fa8a504 100644 --- a/changes.txt +++ b/changes.txt @@ -1,6 +1,7 @@ -------------------------- Changes in 1.9 (not yet released) +- line3d::getClosestPoint can now chose between using line or line segment - MY3D loader deprecated and disabled by default as MY3D tools can't be found on the web anymore. Also could always be used as external loader. - createCylinderMesh, createArrowMesh and createConeMesh in GeometryCreator tessellation numbers now for full instead of semi-circle. Double your tessellation numbers to get same results as in 1.8 diff --git a/include/line2d.h b/include/line2d.h index 8656d43f..7c633047 100644 --- a/include/line2d.h +++ b/include/line2d.h @@ -297,7 +297,7 @@ class line2d //! Get the closest point on this line to a point /** \param point: Starting search at this point \param checkOnlySegments: Default (true) is to return a point on the line-segment (between begin and end) of the line. - When set to false the function will check for the first the closest point on the the line even when outside the segment. */ + When set to false the function will check for the closest point on the the line even when outside the segment. */ vector2d getClosestPoint(const vector2d& point, bool checkOnlySegments=true) const { vector2d c((f64)(point.X-start.X), (f64)(point.Y- start.Y)); diff --git a/include/line3d.h b/include/line3d.h index e61f9b0a..5fb282c6 100644 --- a/include/line3d.h +++ b/include/line3d.h @@ -85,19 +85,26 @@ class line3d //! Get the closest point on this line to a point /** \param point The point to compare to. + \param checkOnlySegments: Default (true) is to return a point on the line-segment (between begin and end) of the line. + When set to false the function will check for the closest point on the the line even when outside the segment. \return The nearest point which is part of the line. */ - vector3d getClosestPoint(const vector3d& point) const + vector3d getClosestPoint(const vector3d& point, bool checkOnlySegments=true) const { vector3d c = point - start; vector3d v = end - start; T d = (T)v.getLength(); + if ( d == 0 ) // line is just a single point + return start; v /= d; T t = v.dotProduct(c); - if (t < (T)0.0) - return start; - if (t > d) - return end; + if ( checkOnlySegments ) + { + if (t < (T)0.0) + return start; + if (t > d) + return end; + } v *= t; return start + v;