commonMain.utilities.WeldAscending.kt Maven / Gradle / Ivy
The newest version!
package org.openrndr.extra.shapes.utilities
/**
* Weld values if their distance is less than [epsilon]
*/
fun List.weldAscending(epsilon: Double = 1E-6): List {
return if (size <= 1) {
this
} else {
val result = mutableListOf(first())
var lastPassed = first()
for (i in 1 until size) {
require(this[i] >= lastPassed) { "input list is not in ascending order" }
if (this[i] - lastPassed > epsilon) {
result.add(this[i])
lastPassed = this[i]
}
}
result
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy