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

commonMain.jetbrains.datalore.plot.base.stat.Contour.kt Maven / Gradle / Ivy

There is a newer version: 4.5.3-alpha1
Show newest version
/*
 * Copyright (c) 2019. JetBrains s.r.o.
 * Use of this source code is governed by the MIT license that can be found in the LICENSE file.
 */

package jetbrains.datalore.plot.base.stat

import jetbrains.datalore.base.geometry.DoubleVector
import jetbrains.datalore.plot.base.DataFrame

internal class Contour private constructor() {

    private val myContourX = ArrayList()
    private val myContourY = ArrayList()
    private val myContourLevel = ArrayList()
    private val myContourGroup = ArrayList()

    private var myGroup = 0.0

    private val dataFrame: DataFrame
        get() = DataFrame.Builder()
                .putNumeric(Stats.X, myContourX)
                .putNumeric(Stats.Y, myContourY)
                .putNumeric(Stats.LEVEL, myContourLevel)
                .putNumeric(Stats.GROUP, myContourGroup)
                .build()

    fun add(polygon: List, fillLevel: Double) {
        for (p in polygon) {
            myContourX.add(p.x)
            myContourY.add(p.y)
            myContourLevel.add(fillLevel)
            myContourGroup.add(myGroup)
        }
        // each polygon in its own group
        myGroup += 1.0
    }

    companion object {

        fun getPathDataFrame(
                levels: List, pathListByLevel: Map>>): DataFrame {
            val contour = Contour()
            for (level in levels) {
                val paths = pathListByLevel[level]!!
                for (path in paths) {
                    contour.add(path, level)
                }
            }
            return contour.dataFrame
        }

        fun getPolygonDataFrame(
                fillLevels: List, polygonListByFillLevel: Map>): DataFrame {
            val contour = Contour()

            for (fillLevel in fillLevels) {
                val polygon = polygonListByFillLevel[fillLevel]!!
                contour.add(polygon, fillLevel)
            }

            return contour.dataFrame
        }
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy