[orx-noise] Optimization. Reduce attempt-count in shape.uniform (#289)

This commit is contained in:
Abe Pazos
2023-02-12 20:56:16 +01:00
committed by GitHub
parent e3c3ab7c87
commit 2fd444604b
2 changed files with 62 additions and 2 deletions

View File

@@ -13,7 +13,8 @@ fun ShapeProvider.uniform(distanceToEdge: Double = 0.0, random: Random = Random.
val shape = shape
require(!shape.empty)
var attempts = 0
return Vector2.uniformSequence(shape.bounds, random).first {
val innerBounds = shape.bounds.offsetEdges(-distanceToEdge.coerceAtLeast(0.0))
return Vector2.uniformSequence(innerBounds, random).first {
attempts++
require(attempts < 100)
if (distanceToEdge == 0.0) {
@@ -139,4 +140,4 @@ fun ShapeProvider.scatter(
} > distanceToEdge
}
}
}
}