Upgrade to JDK 17. Add @JvmRecord annotations
This commit is contained in:
@@ -28,7 +28,7 @@ fun ShapeProvider.uniform(distanceToEdge: Double = 0.0, random: Random = Random.
|
||||
/**
|
||||
* Generate [sampleCount] uniformly distributed points inside the area of [ShapeProvider]
|
||||
*/
|
||||
fun ShapeProvider.uniform(sampleCount: Int) : List<Vector2> = shape.triangulation.uniform(sampleCount)
|
||||
fun ShapeProvider.uniform(sampleCount: Int, random: Random = Random.Default) : List<Vector2> = shape.triangulation.uniform(sampleCount, random)
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -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++
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user