commonMain.org.jetbrains.letsPlot.livemap.mapengine.RenderHelper.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of livemap-jvm Show documentation
Show all versions of livemap-jvm Show documentation
A part of the Lets-Plot library.
The newest version!
/*
* Copyright (c) 2023. JetBrains s.r.o.
* Use of this source code is governed by the MIT license that can be found in the LICENSE file.
*/
package org.jetbrains.letsPlot.livemap.mapengine
import org.jetbrains.letsPlot.commons.intern.typedGeometry.Scalar
import org.jetbrains.letsPlot.commons.intern.typedGeometry.Vec
import org.jetbrains.letsPlot.livemap.Client
import org.jetbrains.letsPlot.livemap.World
import org.jetbrains.letsPlot.livemap.core.Transforms
import org.jetbrains.letsPlot.livemap.mapengine.viewport.Viewport
class RenderHelper(
private val viewport: Viewport
) {
private val dimWorldToClientTransform = Transforms.scale(::zoomFactor)
val zoomFactor get() = Transforms.zoomFactor(viewport.zoom)
fun dimToScreen(p: Vec): Vec {
return Vec(
dimWorldToClientTransform.apply(p.x),
dimWorldToClientTransform.apply(p.y)
)
}
fun posToWorld(p: Vec): Vec {
return viewport.getMapCoord(p)
}
fun dimToWorld(clientDimension: Double): Scalar {
return Scalar(dimWorldToClientTransform.invert(clientDimension))
}
fun dimToWorld(clientDimension: Scalar): Scalar {
return dimToWorld(clientDimension.value)
}
fun dimToClient(worldDimension: Double): Scalar {
return Scalar(dimWorldToClientTransform.apply(worldDimension))
}
fun dimToClient(worldDimension: Scalar): Scalar {
return dimToClient(worldDimension.value)
}
}