commonMain.ovh.plrapps.mapcompose.api.UtilsApi.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mapcompose-mp-desktop Show documentation
Show all versions of mapcompose-mp-desktop Show documentation
A Compose Multiplatform library to display tiled maps, with support for markers, paths, and rotation
The newest version!
@file:Suppress("unused")
package ovh.plrapps.mapcompose.api
import ovh.plrapps.mapcompose.ui.state.MapState
import ovh.plrapps.mapcompose.utils.*
/**
* Given a [point] with known normalized coordinates, rotate it by [angleDegree] around the current
* centroid.
*/
suspend fun MapState.rotatePoint(point: Point, angleDegree: AngleDegree): Point {
return with(zoomPanRotateState) {
awaitLayout()
val xAxisScale = fullHeight / fullWidth.toDouble()
val scaledCenterX = centroidX / xAxisScale
val xR = rotateCenteredX(
point.x / xAxisScale, point.y, scaledCenterX, centroidY, angleDegree.toRad()
) * xAxisScale
val yR = rotateCenteredY(
point.x / xAxisScale, point.y, scaledCenterX, centroidY, angleDegree.toRad()
)
Point(xR, yR)
}
}