public void Build(IMap<float> heightMap) { if (level == 0) { // a leaf node. int limitX = Math.Min(heightMap.Width, x + size + 1); int limitY = Math.Min(heightMap.Height, y + size + 1); heightMap.MinMax(x, y, limitX - x, limitY - y, out minHeight, out maxHeight); } else { childTopLeft.Build(heightMap); minHeight = childTopLeft.minHeight; maxHeight = childTopLeft.maxHeight; if (childTopRight != null) { childTopRight.Build(heightMap); minHeight = MathHelper.Min(minHeight, childTopRight.minHeight); maxHeight = MathHelper.Max(maxHeight, childTopRight.maxHeight); } if (childBottomLeft != null) { childBottomLeft.Build(heightMap); minHeight = MathHelper.Min(minHeight, childBottomLeft.minHeight); maxHeight = MathHelper.Max(maxHeight, childBottomLeft.maxHeight); } if (childBottomRight != null) { childBottomRight.Build(heightMap); minHeight = MathHelper.Min(minHeight, childBottomRight.minHeight); maxHeight = MathHelper.Max(maxHeight, childBottomRight.maxHeight); } } }