Skip to content

Commit

Permalink
Localized variables in the Parallel.For loop
Browse files Browse the repository at this point in the history
  • Loading branch information
mariuszhermansdorfer committed Sep 22, 2019
1 parent be125b9 commit c1c867a
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions SandWorm/SlopeCalculator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,17 @@ public static ushort[] CalculateSlope(double[] pixelArray, int width, int height
int i = rows * width + columns;
int j = (rows + 1) * width + columns;
slope = 0.0;
slope += Math.Abs((pixelArray[h - 1] - pixelArray[i])) / deltaXY; // NW pixel
slope += Math.Abs((pixelArray[h] - pixelArray[i])) / deltaY; //N pixel
slope += Math.Abs((pixelArray[h + 1] - pixelArray[i])) / deltaXY; //NE pixel
slope += Math.Abs((pixelArray[i - 1] - pixelArray[i])) / deltaX; //W pixel
slope += Math.Abs((pixelArray[i + 1] - pixelArray[i])) / deltaX; //E pixel
slope += Math.Abs((pixelArray[j - 1] - pixelArray[i])) / deltaXY; //SW pixel
slope += Math.Abs((pixelArray[j] - pixelArray[i])) / deltaY; //S pixel
slope += Math.Abs((pixelArray[j + 1] - pixelArray[i])) / deltaXY; //SE pixel
slopeValues[i] = (ushort)(slope * 12.5); // rather than dividing by 8 and multiplying by 100 we do it in one step
double parallelSlope = 0.0;
parallelSlope += Math.Abs((pixelArray[h - 1] - pixelArray[i])) / deltaXY; // NW pixel
parallelSlope += Math.Abs((pixelArray[h] - pixelArray[i])) / deltaY; //N pixel
parallelSlope += Math.Abs((pixelArray[h + 1] - pixelArray[i])) / deltaXY; //NE pixel
parallelSlope += Math.Abs((pixelArray[i - 1] - pixelArray[i])) / deltaX; //W pixel
parallelSlope += Math.Abs((pixelArray[i + 1] - pixelArray[i])) / deltaX; //E pixel
parallelSlope += Math.Abs((pixelArray[j - 1] - pixelArray[i])) / deltaXY; //SW pixel
parallelSlope += Math.Abs((pixelArray[j] - pixelArray[i])) / deltaY; //S pixel
parallelSlope += Math.Abs((pixelArray[j + 1] - pixelArray[i])) / deltaXY; //SE pixel
slopeValues[i] = (ushort)(parallelSlope * 12.5); // rather than dividing by 8 and multiplying by 100 we do it in one step
}
});
return slopeValues;
Expand Down

0 comments on commit c1c867a

Please sign in to comment.