Cleanup code #1795 and unify new api in vector types

This commit is contained in:
Wojtek Figat
2024-02-19 23:04:59 +01:00
parent 358220b0b5
commit 04da732da9
6 changed files with 71 additions and 46 deletions

View File

@@ -1381,6 +1381,19 @@ namespace FlaxEngine
return result;
}
/// <summary>
/// Snaps the input position into the grid.
/// </summary>
/// <param name="pos">The position to snap.</param>
/// <param name="gridSize">The size of the grid.</param>
/// <returns>The position snapped to the grid.</returns>
public static Vector2 SnapToGrid(Vector2 pos, Vector2 gridSize)
{
pos.X = Mathr.Ceil((pos.X - (gridSize.X * 0.5f)) / gridSize.Y) * gridSize.X;
pos.Y = Mathr.Ceil((pos.Y - (gridSize.Y * 0.5f)) / gridSize.X) * gridSize.Y;
return pos;
}
/// <summary>
/// Adds two vectors.
/// </summary>