public static double CalculateGradient(this GridArray <double> instance, int x, int y, Directions direction) { var vector = direction.GetVector(); //var farMultiplicator = direction.IsDiagonal() ? 2 : 3; var near = instance[x + vector.Item1, y + vector.Item2]; //var far = instance[x + vector.Item1 * farMultiplicator, y + vector.Item2 * farMultiplicator]; var far = instance[x - vector.Item1, y - vector.Item2]; return((far - near) / (2 * (direction.IsDiagonal() ? Math.Sqrt(2) * instance.CurrentSize : instance.CurrentSize))); }
public static (int, int) GetNeighbor <T>(this GridArray <T> instance, int x, int y, Directions direction) { return(x + direction.GetVector().Item1, y + direction.GetVector().Item2);
public static T GetNeighborValue <T>(this GridArray <T> instance, int x, int y, Directions direction) { return(instance[x + direction.GetVector().Item1, y + direction.GetVector().Item2]); }