Vector Utilities - BluePixelDev/utilkit GitHub Wiki
Vec2 Utilities
Utilities to extend and simplify working with Vector2
.
Operations
v.SetX(5); // Sets X component to 5
v.SetY(10); // Sets Y component to 10
v.AddX(2); // Adds 2 to X
v.AddY(3); // Adds 3 to Y
v.SubX(1); // Subtracts 1 from X
v.SubY(4); // Subtracts 4 from Y
Math Methods
v.Vec3(z: 1); // Converts to Vector3 with optional Z value
v.Multiply(new Vector2(2, 3)); // Element-wise multiplication
v.Divide(new Vector2(2, 3)); // Element-wise division
v.Abs(); // Returns absolute value of each component
v.Sign(); // Returns the sign (-1, 0, 1) of each component
v.OneMinus(); // Returns new Vector2(1 - x, 1 - y)
v.Round(); // Rounds each component
v.Clamp(0, 1); // Clamps all values between min and max
v.Clamp(new Vector2(0, 0), new Vector2(5, 5)); // Vector-based clamping
Random
Vector2 v = Vec2Util.RandomVector2(0, 10); // Random x/y from 0 to 10
Vec3 Utilities
Utilities to extend and simplify working with Vector3
.
Operations
v.SetX(1); v.SetY(2); v.SetZ(3); // Set individual axes
v.Add(new Vector2(1, 1)); // Add Vector2 to x/y
v.AddX(1); v.AddY(2); v.AddZ(3); // Add to individual axes
v.Sub(new Vector2(1, 1)); // Subtract Vector2 from x/y
v.SubX(1); v.SubY(2); v.SubZ(3); // Subtract from individual axes
Math Methods
v.Mul(2); // Multiply all components by 2
v.Mul(new Vector3(2, 2, 2)); // Element-wise multiply
v.Div(2); // Divide all components by 2
v.Div(new Vector3(2, 2, 2)); // Element-wise divide
v.Abs(); // Absolute value of components
v.Sign(); // Sign of each component
v.OneMinus(); // 1 - value for each component
v.Round(); // Rounds each component
v.Clamp(0, 1); // Clamps values between min and max
v.Clamp(new Vector3(0, 0, 0), new Vector3(1, 1, 1)); // Vector-based clamp
Conversion
Vector2 v2 = v.Vec2(); // Converts Vector3 to Vector2 (drops Z)
Random
Vector3 randomVec = Vec3Util.RandomVector3(0, 10); // Random in range
Vector3 unitVec = Vec3Util.RandomUnitVector3(); // Random unit vector