From c8907ff5e6739c2d64e0982c1de3c335e9c6b63c Mon Sep 17 00:00:00 2001 From: Davis King Date: Mon, 8 Dec 2014 19:56:31 -0500 Subject: [PATCH] Added a length_squared() member to vector. --- dlib/geometry/vector.h | 15 +++++++++++++++ dlib/geometry/vector_abstract.h | 7 +++++++ 2 files changed, 22 insertions(+) diff --git a/dlib/geometry/vector.h b/dlib/geometry/vector.h index 7f2e50c26..74acd293f 100644 --- a/dlib/geometry/vector.h +++ b/dlib/geometry/vector.h @@ -345,6 +345,14 @@ namespace dlib // --------------------------------------- + double length_squared( + ) const + { + return (double)(x()*x() + y()*y() + z()*z()); + } + + // --------------------------------------- + typename vc_rebind::type normalize ( ) const { @@ -697,6 +705,13 @@ namespace dlib // --------------------------------------- + double length_squared( + ) const + { + return (double)(x()*x() + y()*y()); + } + + // --------------------------------------- typename vc_rebind::type normalize ( ) const diff --git a/dlib/geometry/vector_abstract.h b/dlib/geometry/vector_abstract.h index d5c865c95..c4bbc45cb 100644 --- a/dlib/geometry/vector_abstract.h +++ b/dlib/geometry/vector_abstract.h @@ -152,6 +152,13 @@ namespace dlib - returns the length of the vector !*/ + double length_squared( + ) const; + /*! + ensures + - returns length()*length() + !*/ + T& x ( ); /*!