Upgrade to JDK 17. Add @JvmRecord annotations

This commit is contained in:
Edwin Jakobs
2024-06-01 07:31:44 +02:00
parent 06f593053b
commit 78fbff54c5
38 changed files with 94 additions and 33 deletions

View File

@@ -2,14 +2,15 @@ package org.openrndr.extra.noise
import org.openrndr.math.Vector2
import org.openrndr.shape.Triangle
import kotlin.random.Random
/**
* Generate [count] uniform samples from a list of [Triangle]s
*/
fun List<Triangle>.uniform(count: Int): List<Vector2> {
fun List<Triangle>.uniform(count: Int, random: Random = Random.Default): List<Vector2> {
val totalArea = this.sumOf { it.area }
val randoms = (0 until count).map {
Double.uniform(0.0, totalArea)
Double.uniform(0.0, totalArea, random = random)
}.sorted()
val result = mutableListOf<Vector2>()
var idx = 0
@@ -17,7 +18,7 @@ fun List<Triangle>.uniform(count: Int): List<Vector2> {
for (t in this) {
sum += t.area
while (idx < randoms.lastIndex && sum > randoms[idx]) {
result.add(t.randomPoint())
result.add(t.randomPoint(random))
idx++
}
}