commonMain.jetbrains.datalore.plot.base.interact.HitShape.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of lets-plot-common Show documentation
Show all versions of lets-plot-common Show documentation
Lets-Plot JVM package without rendering part
/*
* 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