Changeset View
Changeset View
Standalone View
Standalone View
source/maths/FixedVector2D.h
Show First 20 Lines • Show All 111 Lines • ▼ Show 20 Lines | fixed Length() const | ||||
CheckU32CastOverflow(d, i32, L"Overflow in CFixedVector2D::Length() part 2") | CheckU32CastOverflow(d, i32, L"Overflow in CFixedVector2D::Length() part 2") | ||||
fixed r; | fixed r; | ||||
r.SetInternalValue((i32)d); | r.SetInternalValue((i32)d); | ||||
return r; | return r; | ||||
} | } | ||||
/** | /** | ||||
* Returns the squared length of the vector. | |||||
*/ | |||||
fixed LengthSquared() const | |||||
{ | |||||
return this->Dot(*this); | |||||
bb: should we do it like this, or manually calculating | |||||
} | |||||
/** | |||||
* Returns -1, 0, +1 depending on whether length is less/equal/greater | * Returns -1, 0, +1 depending on whether length is less/equal/greater | ||||
* than the argument. | * than the argument. | ||||
* Avoids sqrting and overflowing. | * Avoids sqrting and overflowing. | ||||
*/ | */ | ||||
int CompareLength(fixed cmp) const | int CompareLength(fixed cmp) const | ||||
{ | { | ||||
i32 x = X.GetInternalValue(); // abs(x) <= 2^31 | i32 x = X.GetInternalValue(); // abs(x) <= 2^31 | ||||
i32 y = Y.GetInternalValue(); | i32 y = Y.GetInternalValue(); | ||||
▲ Show 20 Lines • Show All 104 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
should we do it like this, or manually calculating