[orx-noise] Add generated and verified documentation

This commit is contained in:
Edwin Jakobs
2025-01-19 11:01:54 +01:00
parent 342c144503
commit 3309bd91d5
16 changed files with 792 additions and 31 deletions

View File

@@ -5,12 +5,25 @@ import org.openrndr.math.Vector2
import org.openrndr.shape.Rectangle
import kotlin.random.Random
/**
* Generates a uniformly distributed random point within the `Rectangle`.
*
* @param random An optional random number generator to use. Defaults to `Random.Default`.
* @return A `Vector2` representing a random point within the `Rectangle`.
*/
fun Rectangle.uniform(random: Random = Random.Default): Vector2 {
val x = random.nextDouble() * width + corner.x
val y = random.nextDouble() * height + corner.y
return Vector2(x, y)
}
/**
* Generates a random point within the bounds of the `Rectangle` using a hash-based approach.
*
* @param seed An integer seed for the hash function, used to produce deterministic random results for the same seed.
* @param x An integer input to the hash function, adding further variation to the generated point.
* @return A `Vector2` representing a random point within the `Rectangle`, based on the provided `seed` and `x`.
*/
fun Rectangle.hash(seed: Int, x: Int): Vector2 {
val ux = uhash11(seed.toUInt() + uhash11(x.toUInt()))
val uy = uhash11(ux + x.toUInt())