All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.data2viz.geo.clip.ClipBuffer.kt Maven / Gradle / Ivy

There is a newer version: 0.8.0-RC5
Show newest version
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
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy