commonMain.jetbrains.datalore.plot.base.scale.MapperUtil.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.scale
import jetbrains.datalore.base.interval.DoubleSpan
import jetbrains.datalore.plot.base.ContinuousTransform
import jetbrains.datalore.plot.base.ScaleMapper
import kotlin.math.max
import kotlin.math.min
object MapperUtil {
fun map(r: DoubleSpan, mapper: ScaleMapper): DoubleSpan {
val a = mapper(r.lowerEnd)!!
val b = mapper(r.upperEnd)!!
return DoubleSpan(min(a, b), max(a, b))
}
fun rangeWithLimitsAfterTransform(
dataRange: DoubleSpan,
trans: ContinuousTransform
): DoubleSpan {
check(trans.isInDomain(dataRange.lowerEnd)) {
"[${trans::class.simpleName}] Lower end ${dataRange.lowerEnd} is outside of transform's domain."
}
check(trans.isInDomain(dataRange.upperEnd)) {
"[${trans::class.simpleName}] Upper end ${dataRange.upperEnd} is outside of transform's domain."
}
val transformedLimits = listOf(
trans.apply(trans.definedLimits().first),
trans.apply(trans.definedLimits().second),
trans.apply(dataRange.lowerEnd),
trans.apply(dataRange.upperEnd),
)
return DoubleSpan.encloseAll(transformedLimits)
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy