From 7e7b3f505d688fffd3a3c41deab1e0da50987981 Mon Sep 17 00:00:00 2001 From: evgeniysergeev Date: Sun, 24 Apr 2016 09:18:54 +0300 Subject: [PATCH] SpatiallyPartitioned fixup for d2 BoundsToBinRowsAndCols fixup for negative width or height Using Math.Min and Math.Max utils instead of '?:' --- OpenRA.Game/Primitives/SpatiallyPartitioned.cs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/OpenRA.Game/Primitives/SpatiallyPartitioned.cs b/OpenRA.Game/Primitives/SpatiallyPartitioned.cs index 9114f9baa0..04013b9c46 100644 --- a/OpenRA.Game/Primitives/SpatiallyPartitioned.cs +++ b/OpenRA.Game/Primitives/SpatiallyPartitioned.cs @@ -33,7 +33,7 @@ namespace OpenRA.Primitives void ValidateBounds(Rectangle bounds) { - if (bounds.Width <= 0 || bounds.Height <= 0) + if (bounds.Width == 0 || bounds.Height == 0) throw new ArgumentException("bounds must be non-empty.", "bounds"); } @@ -69,10 +69,15 @@ namespace OpenRA.Primitives void BoundsToBinRowsAndCols(Rectangle bounds, out int minRow, out int maxRow, out int minCol, out int maxCol) { - minRow = Math.Max(0, bounds.Top / binSize); - minCol = Math.Max(0, bounds.Left / binSize); - maxRow = Math.Min(rows, Exts.IntegerDivisionRoundingAwayFromZero(bounds.Bottom, binSize)); - maxCol = Math.Min(cols, Exts.IntegerDivisionRoundingAwayFromZero(bounds.Right, binSize)); + var top = Math.Min(bounds.Top, bounds.Bottom); + var bottom = Math.Max(bounds.Top, bounds.Bottom); + var left = Math.Min(bounds.Left, bounds.Right); + var right = Math.Max(bounds.Left, bounds.Right); + + minRow = Math.Max(0, top / binSize); + minCol = Math.Max(0, left / binSize); + maxRow = Math.Min(rows, Exts.IntegerDivisionRoundingAwayFromZero(bottom, binSize)); + maxCol = Math.Min(cols, Exts.IntegerDivisionRoundingAwayFromZero(right, binSize)); } void MutateBins(T actor, Rectangle bounds, Action, T, Rectangle> action)