private int interpolateHeight(int x, int z, float ratio) {
    int low, highX, highZ;
    float intX, intZ;
    float scaledX = x * ratio;
    float scaledZ = z * ratio;
    float interpolation;

    low = heightMap.getTrueHeightAtPoint((int) scaledX, (int) scaledZ);

    if (scaledX + 1 >= size) {
      return low;
    }

    highX = heightMap.getTrueHeightAtPoint((int) scaledX + 1, (int) scaledZ);

    interpolation = scaledX - (int) scaledX;
    intX = ((highX - low) * interpolation) + low;

    if (scaledZ + 1 >= size) {
      return low;
    }

    highZ = heightMap.getTrueHeightAtPoint((int) scaledX, (int) scaledZ + 1);

    interpolation = scaledZ - (int) scaledZ;
    intZ = ((highZ - low) * interpolation) + low;

    return (int) ((intX + intZ) / 2f);
  }
 /**
  * Constructor instantiates a new <code>ProceduralTexture</code> object initializing the list for
  * textures and the height map.
  *
  * @param heightMap the height map to use for the texture generation.
  */
 public ProceduralTextureGenerator(AbstractHeightMap heightMap) {
   textureList = new ArrayList<TextureTile>();
   this.heightMap = heightMap;
   this.size = heightMap.getSize();
 }