Index: binaries/data/mods/public/maps/random/rmgen/math.js =================================================================== --- binaries/data/mods/public/maps/random/rmgen/math.js +++ binaries/data/mods/public/maps/random/rmgen/math.js @@ -89,7 +89,7 @@ } /** - * Returns the topleft and bottomright coordinate of the given two points. + * Returns the topright and bottomleft coordinate of the given two points. */ function getBoundingBox(points) { Index: binaries/data/mods/public/maps/random/rmgen/placer/centered/DiskPlacer.js =================================================================== --- binaries/data/mods/public/maps/random/rmgen/placer/centered/DiskPlacer.js +++ binaries/data/mods/public/maps/random/rmgen/placer/centered/DiskPlacer.js @@ -3,7 +3,7 @@ */ function DiskPlacer(radius, centerPosition = undefined) { - this.radiusSquared = Math.square(radius); + this.radius = radius; this.centerPosition = undefined; if (centerPosition) @@ -18,12 +18,21 @@ DiskPlacer.prototype.place = function(constraint) { let points = []; + let radiusSquared = Math.square(this.radius); + let mapBounds = g_Map.getBounds(); - for (let x = 0; x < g_Map.getSize(); ++x) - for (let y = 0; y < g_Map.getSize(); ++y) + let bottomLeft = Vector2D.max( + new Vector2D(mapBounds.left, mapBounds.bottom), + new Vector2D(this.centerPosition.x - this.radius - 1, this.centerPosition.y - this.radius - 1).round()); + let topRight = Vector2D.min( + new Vector2D(mapBounds.right, mapBounds.top), + new Vector2D(this.centerPosition.x + this.radius + 1, this.centerPosition.y + this.radius + 1).round()); + + for (let x = bottomLeft.x; x < topRight.x; ++x) + for (let y = bottomLeft.y; y < topRight.y; ++y) { let point = new Vector2D(x, y); - if (this.centerPosition.distanceToSquared(point) <= this.radiusSquared && constraint.allows(point)) + if (this.centerPosition.distanceToSquared(point) <= radiusSquared && constraint.allows(point)) points.push(point); }