function TVector3D.Distance(const AVector3D: TVector3D): Single;
function TVector3D.Distance(const AVector3D: TVector3D): Single;
begin
Result := Sqr(AVector3D.X - Self.X) + Sqr(AVector3D.Y - Self.Y) + Sqr(AVector3D.Z - Self.Z);
end;
Just... what?
(For those who don't know, this is what it's supposed to be: http://en.wikipedia.org/wiki/Euclidean_vector#Length
and this is what it is: http://gamedev.stackexchange.com/questions/23709/are-there-any-disadvantages-of-using-distance-squared-checks-rather-than-distanc or this http://stackoverflow.com/questions/8077982/fastest-way-to-compute-distance-squared
It's a common optimisation to avoid the sqrt() when you're just comparing distances - is something closer than something else, without the numerical distance value itself mattering, ie only for comparisons. But a public function on a vector called Distance() should return the distance.)
XE4, btw.
http://en.wikipedia.org/wiki/Euclidean_vector#Length
begin
Result := Sqr(AVector3D.X - Self.X) + Sqr(AVector3D.Y - Self.Y) + Sqr(AVector3D.Z - Self.Z);
end;
Just... what?
(For those who don't know, this is what it's supposed to be: http://en.wikipedia.org/wiki/Euclidean_vector#Length
and this is what it is: http://gamedev.stackexchange.com/questions/23709/are-there-any-disadvantages-of-using-distance-squared-checks-rather-than-distanc or this http://stackoverflow.com/questions/8077982/fastest-way-to-compute-distance-squared
It's a common optimisation to avoid the sqrt() when you're just comparing distances - is something closer than something else, without the numerical distance value itself mattering, ie only for comparisons. But a public function on a vector called Distance() should return the distance.)
XE4, btw.
http://en.wikipedia.org/wiki/Euclidean_vector#Length
Heh yeah that's quite retarded. FWIW it's fixed in XE5, where it's now reads Result := (AVector - Self).Length;
ReplyDeleteIt'd be nice for it to have both DistanceSqr and LengthSqr though, as there are many cases where you need to square the length or just need to compare relative distances.