OverflowException
OverflowException
AwesomeNamespace.UniformPoissonDiskSampler.Sample (UnityEngine.Vector2 topLeft, UnityEngine.Vector2 lowerRight, System.Nullable`1[T] rejectionDistance, System.Single minimumDistance, System.Int32 pointsPerIteration) (at Assets/PanoramaTerrainTools/ToolExtended/UniformPoissonDiskSampler.cs:61)
почему settings.GridWidth318settings.GridHeight-325 вызывает Исключение переполнения ? Ошибка в этой строчке:
var state = new State
{
Grid = new UnityEngine.Vector2?[settings.GridWidth, settings.GridHeight],
ActivePoints = new List<UnityEngine.Vector2>(),
Points = new List<UnityEngine.Vector2>()
};
Весь метод :
struct State
{
public UnityEngine.Vector2?[,] Grid;
public List<UnityEngine.Vector2> ActivePoints, Points;
}
static List<UnityEngine.Vector2> Sample(UnityEngine.Vector2 topLeft, UnityEngine.Vector2 lowerRight, float? rejectionDistance, float minimumDistance, int pointsPerIteration)
{
var settings = new Settings
{
TopLeft = topLeft, LowerRight = lowerRight,
Dimensions = lowerRight - topLeft,
Center = (topLeft + lowerRight) / 2,
CellSize = minimumDistance / SquareRootTwo,
MinimumDistance = minimumDistance,
RejectionSqDistance = rejectionDistance == null ? null : rejectionDistance * rejectionDistance
};
settings.GridWidth = (int) (settings.Dimensions.x / settings.CellSize) + 1;
settings.GridHeight = (int) (settings.Dimensions.y / settings.CellSize) + 1;
Debug.Log("settings.GridWidth"+settings.GridWidth+"settings.GridHeight"+settings.GridHeight);
var state = new State
{
Grid = new UnityEngine.Vector2?[settings.GridWidth, settings.GridHeight],
ActivePoints = new List<UnityEngine.Vector2>(),
Points = new List<UnityEngine.Vector2>()
};
AddFirstPoint(ref settings, ref state);
while (state.ActivePoints.Count != 0)
{
var listIndex = RandomHelper.Random.Next(state.ActivePoints.Count);
var point = state.ActivePoints[listIndex];
var found = false;
for (var k = 0; k < pointsPerIteration; k++)
found |= AddNextPoint(point, ref settings, ref state);
if (!found)
state.ActivePoints.RemoveAt(listIndex);
}
return state.Points;
}