Browse Source

Merge pull request #483 from wivlaro/vector-length-squared

Vector3::lengthSquared
Ivan Safrin 11 years ago
parent
commit
86d71b15f3
1 changed files with 9 additions and 0 deletions
  1. 9 0
      Core/Contents/Include/PolyVector3.h

+ 9 - 0
Core/Contents/Include/PolyVector3.h

@@ -159,6 +159,15 @@ namespace Polycode {
 			inline Number length () const {
 			inline Number length () const {
 				return sqrtf( x * x + y * y + z * z );
 				return sqrtf( x * x + y * y + z * z );
 			}
 			}
+
+			/**
+			* Returns square of the length of the vector.
+			* Cheaper to execute than length(), for use when you're just e.g. comparing vector lengths.
+			* @return Square length of the vector.
+			*/
+			inline Number lengthSquared() const {
+				return dot(*this);
+			}
 			
 			
 			inline Vector3 setLength(const Number newLength) {
 			inline Vector3 setLength(const Number newLength) {
 				Number oldLength = length();
 				Number oldLength = length();