Int2 Distance Bug?

Working with the Int2 type and noticed the distance operation, which returns a float, seems to return an integer length, even when it should be calculating the length of a diagonal line.
By comparison when working with Vector2 you get the correct distance of 1.41 ish.

Int2 DistanceLength.vl (11.3 KB)

This is because the Length node (that Distance uses internally) returns an integer when it has an Int2 as input.

I’m not sure if this is a bug? Maybe there’s some maths reason for this.
On the surface it doesn’t seem to be the correct distance for computer graphics purposes.

Workaround is simple, turn it into vector2 first.

This is from the stride Int2 class, where length stays in the same number category, I don’t know why our node outputs a float: stride/sources/core/Stride.Core.Mathematics/Int2.cs at a243fdc84327afe4e99a56c589df0c18fff11bd2 · stride3d/stride · GitHub

or use LengthSquared and Sqrt. if you only need to compare lengths, the squared version should be preferred anyways, because it avoids the expensive sqrt operation.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.