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

commonMain.ovh.plrapps.mapcompose.api.UtilsApi.kt Maven / Gradle / Ivy

Go to download

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)
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy