Description
The LengthSquared
property of the Vector2Int
struct provides the squared length of the integer vector. This property is useful for performance optimization when comparing distances, as it avoids the computational cost of calculating the square root, which is required for the Length
property. By using squared values, you can efficiently compare distances without needing the exact length.
Usage
Use the LengthSquared
property when you need to compare the magnitude of vectors without requiring the actual length. This is particularly useful in scenarios where performance is critical, such as in game development or real-time simulations.
Example
Vector2Int vector = new Vector2Int(3, 4);
int squaredLength = vector.LengthSquared;
// Output: 25
// Explanation: The squared length is calculated as (3 * 3) + (4 * 4) = 9 + 16 = 25.