///========================================================================================================================================== /// Mutators ///========================================================================================================================================== float LineSegment3D::SetLength(float newLength){ float currentLengthSquared = CalcLengthSquared(); if (currentLengthSquared != 0.0f){ float currentLength = sqrtf(currentLengthSquared); float scale = newLength / currentLength; ScaleFromEnd(scale); return currentLength; } return 0.0f; }
bool Vector4::operator == ( const Vector4& vectorToEqual ) const { if (CalcLengthSquared() == vectorToEqual.CalcLengthSquared()) { return true; } else { return false; } }
///--------------------------------------------------------------------------------- /// very slow ///--------------------------------------------------------------------------------- float Vector2::Normalize() { if( CalcLengthSquared() == 0.0f ) return 0.0f; float length = CalcLength(); if( length == 0.0f ) return 0.0f; float inverseLength = 1.0f / length; x *= inverseLength; y *= inverseLength; return length; }
primitiveType Vector4< primitiveType >::Normalize3D() { if( CalcLengthSquared() == (primitiveType) 0 ) return (primitiveType) 0; float length = CalcLength(); if( length == (primitiveType) 0 ) return (primitiveType) 0; float inverseLength = ( (primitiveType) 1 ) / length; x *= inverseLength; y *= inverseLength; z *= inverseLength; return length; }
///--------------------------------------------------------------------------------- /// ///--------------------------------------------------------------------------------- const Vector2 Vector2::Normalized() const { if (CalcLengthSquared() == 0.0f) return Vector2::ZERO; float length = CalcLength(); if (length == 0.0f) return Vector2::ZERO; Vector2 returnVec; float inverseLength = 1.0f / length; returnVec.x = x * inverseLength; returnVec.y = y * inverseLength; return returnVec; }
///--------------------------------------------------------------------------------- /// very slow ///--------------------------------------------------------------------------------- float Vector2::CalcLength() const { float length = sqrtf( CalcLengthSquared() ); return length; }
primitiveType Vector4< primitiveType >::CalcLength() const { primitiveType length = sqrt( CalcLengthSquared() ); return length; }