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

commonMain.jetbrains.datalore.plot.base.interact.HitShape.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.interact

import jetbrains.datalore.base.geometry.DoubleRectangle
import jetbrains.datalore.base.geometry.DoubleVector

open class HitShape private constructor(val kind: Kind, private val shape: Any) {

    val point: DoubleCircle
        get() = shape as DoubleCircle

    val rect: DoubleRectangle
        get() = shape as DoubleRectangle

    open val points: List
        get() = throw IllegalStateException("Not applicable to $kind")

    enum class Kind {
        POINT, RECT, POLYGON, PATH
    }

    class DoubleCircle(val center: DoubleVector, val radius: Double)

    companion object {
        fun point(p: DoubleVector, radius: Double): HitShape {
            return HitShape(Kind.POINT, DoubleCircle(p, radius))
        }

        fun rect(r: DoubleRectangle): HitShape {
            return HitShape(Kind.RECT, r)
        }

        fun path(points: List): HitShape {
            return shapeWithPath(Kind.PATH, points)
        }

        fun polygon(points: List): HitShape {
            return shapeWithPath(Kind.POLYGON, points)
        }

        private fun shapeWithPath(kind: Kind, points: List): HitShape {
            return object : HitShape(kind, points) {
                override val points: List
                    get() = points
            }
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy