io.data2viz.geo.clip.ClipBuffer.kt Maven / Gradle / Ivy
package io.data2viz.geo.clip
import io.data2viz.geo.projection.Stream
class ClipBuffer : Stream {
private val lines: MutableList> = mutableListOf()
private lateinit var line: MutableList
override fun point(x: Double, y: Double, z: Double) {
line.add(doubleArrayOf(x, y))
}
override fun lineStart() {
line = mutableListOf()
lines.add(line)
}
fun rejoin() {
if (lines.size > 1) {
val l = mutableListOf>()
l.add(lines.removeAt(lines.lastIndex))
l.add(lines.removeAt(0))
lines.addAll(l)
}
}
fun result(): List> {
val result = mutableListOf>()
result.addAll(lines)
lines.clear()
return result
}
}