Fix SnapToGrid to skip when grid component is 0

This commit is contained in:
Wojtek Figat
2025-01-30 17:26:34 +01:00
parent fc98b5f1f0
commit 4057dc189d
4 changed files with 20 additions and 10 deletions

View File

@@ -1263,8 +1263,10 @@ namespace FlaxEngine
/// <returns>The position snapped to the grid.</returns>
public static Double2 SnapToGrid(Double2 pos, Double2 gridSize)
{
pos.X = Mathd.Ceil((pos.X - (gridSize.X * 0.5)) / gridSize.Y) * gridSize.X;
pos.Y = Mathd.Ceil((pos.Y - (gridSize.Y * 0.5)) / gridSize.X) * gridSize.Y;
if (Mathd.Abs(gridSize.X) > Mathd.Epsilon)
pos.X = Mathd.Ceil((pos.X - (gridSize.X * 0.5)) / gridSize.Y) * gridSize.X;
if (Mathd.Abs(gridSize.Y) > Mathd.Epsilon)
pos.Y = Mathd.Ceil((pos.Y - (gridSize.Y * 0.5)) / gridSize.X) * gridSize.Y;
return pos;
}