From 5462f43baefdf839d7d2e5036d2ec3c95d888c02 Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Sun, 24 Mar 2013 16:07:51 +0000 Subject: Fixed rounding error in MultiStepMap BioGen, introduced in rev 1289. git-svn-id: http://mc-server.googlecode.com/svn/trunk@1307 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/Noise.h | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'source/Noise.h') diff --git a/source/Noise.h b/source/Noise.h index 68428d33e..9a129d81f 100644 --- a/source/Noise.h +++ b/source/Noise.h @@ -85,6 +85,54 @@ extern void IntArrayLinearInterpolate2D( +/// Linearly interpolates values in the array between the anchor points; universal data type +template void ArrayLinearInterpolate2D( + TYPE * a_Array, + int a_SizeX, int a_SizeY, // Dimensions of the array + int a_AnchorStepX, int a_AnchorStepY // Distances between the anchor points in each direction +) +{ + // First interpolate columns where the anchor points are: + int LastYCell = a_SizeY - a_AnchorStepY; + for (int y = 0; y < LastYCell; y += a_AnchorStepY) + { + int Idx = a_SizeX * y; + for (int x = 0; x < a_SizeX; x += a_AnchorStepX) + { + TYPE StartValue = a_Array[Idx]; + TYPE EndValue = a_Array[Idx + a_SizeX * a_AnchorStepY]; + TYPE Diff = EndValue - StartValue; + for (int CellY = 1; CellY < a_AnchorStepY; CellY++) + { + a_Array[Idx + a_SizeX * CellY] = StartValue + Diff * CellY / a_AnchorStepY; + } // for CellY + Idx += a_AnchorStepX; + } // for x + } // for y + + // Now interpolate in rows, each row has values in the anchor columns + int LastXCell = a_SizeX - a_AnchorStepX; + for (int y = 0; y < a_SizeY; y++) + { + int Idx = a_SizeX * y; + for (int x = 0; x < LastXCell; x += a_AnchorStepX) + { + TYPE StartValue = a_Array[Idx]; + TYPE EndValue = a_Array[Idx + a_AnchorStepX]; + TYPE Diff = EndValue - StartValue; + for (int CellX = 1; CellX < a_AnchorStepX; CellX++) + { + a_Array[Idx + CellX] = StartValue + CellX * Diff / a_AnchorStepX; + } // for CellY + Idx += a_AnchorStepX; + } + } +} + + + + + #if NOISE_USE_INLINE #include "Noise.inc" #endif -- cgit v1.2.3