{ return intersects(dst, lineSegment, plane); }
+// Distance of a line segment to a point
+template<typename T>
+inline T
+distSqr(const SGLineSegment<T>& lineSeg, const SGVec3<T>& p)
+{
+ SGVec3<T> ps = p - lineSeg.getStart();
+
+ T psdotdir = dot(ps, lineSeg.getDirection());
+ if (psdotdir <= 0)
+ return dot(ps, ps);
+
+ SGVec3<T> pe = p - lineSeg.getEnd();
+ if (0 <= dot(pe, lineSeg.getDirection()))
+ return dot(pe, pe);
+
+ return dot(ps, ps) - psdotdir*psdotdir/dot(lineSeg.getDirection(), lineSeg.getDirection());
+}
+// make it symmetric
+template<typename T>
+inline T
+distSqr(const SGVec3<T>& p, const SGLineSegment<T>& lineSeg)
+{ return distSqr(lineSeg, p); }
+// with sqrt
+template<typename T>
+inline T
+dist(const SGVec3<T>& p, const SGLineSegment<T>& lineSeg)
+{ return sqrt(distSqr(lineSeg, p)); }
+template<typename T>
+inline T
+dist(const SGLineSegment<T>& lineSeg, const SGVec3<T>& p)
+{ return sqrt(distSqr(lineSeg, p)); }
+
template<typename T>
inline bool
intersects(const SGRay<T>& ray, const SGSphere<T>& sphere)
{ data()[0] = d[0]; data()[1] = d[1]; data()[2] = d[2]; }
explicit SGVec3(const osg::Vec3d& d)
{ data()[0] = d[0]; data()[1] = d[1]; data()[2] = d[2]; }
+ explicit SGVec3(const SGVec2<T>& v2, const T& v3 = 0)
+ { data()[0] = v2[0]; data()[1] = v2[1]; data()[2] = v3; }
/// Access by index, the index is unchecked
const T& operator()(unsigned i) const
{ data()[0] = d[0]; data()[1] = d[1]; data()[2] = d[2]; data()[3] = d[3]; }
explicit SGVec4(const osg::Vec4d& d)
{ data()[0] = d[0]; data()[1] = d[1]; data()[2] = d[2]; data()[3] = d[3]; }
+ explicit SGVec4(const SGVec3<T>& v3, const T& v4 = 0)
+ { data()[0] = v3[0]; data()[1] = v3[1]; data()[2] = v3[2]; data()[3] = v4; }
/// Access by index, the index is unchecked