Add explicit API for core

This commit is contained in:
Alexander Nozik 2022-07-23 10:40:36 +03:00
parent 14b3142f43
commit 09dfdcc84a
No known key found for this signature in database
GPG Key ID: F7FCF2DD25C71357
4 changed files with 25 additions and 19 deletions

View File

@ -6,6 +6,7 @@ plugins {
val ktorVersion: String by rootProject.extra
kotlin {
explicitApi = org.jetbrains.kotlin.gradle.dsl.ExplicitApiMode.Warning
jvm {
compilations.all {
kotlinOptions.jvmTarget = "11"

View File

@ -1,34 +1,39 @@
package centre.sciprog.maps
import kotlin.math.*
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min
class GmcBox(val a: GeodeticMapCoordinates, val b: GeodeticMapCoordinates)
public class GmcBox(public val a: GeodeticMapCoordinates, public val b: GeodeticMapCoordinates)
fun GmcBox(latitudes: ClosedFloatingPointRange<Double>, longitudes: ClosedFloatingPointRange<Double>) = GmcBox(
public fun GmcBox(
latitudes: ClosedFloatingPointRange<Double>,
longitudes: ClosedFloatingPointRange<Double>,
): GmcBox = GmcBox(
GeodeticMapCoordinates.ofRadians(latitudes.start, longitudes.start),
GeodeticMapCoordinates.ofRadians(latitudes.endInclusive, longitudes.endInclusive)
)
val GmcBox.center
public val GmcBox.center: GeodeticMapCoordinates
get() = GeodeticMapCoordinates.ofRadians(
(a.latitude + b.latitude) / 2,
(a.longitude + b.longitude) / 2
)
val GmcBox.left get() = min(a.longitude, b.longitude)
val GmcBox.right get() = max(a.longitude, b.longitude)
public val GmcBox.left: Double get() = min(a.longitude, b.longitude)
public val GmcBox.right: Double get() = max(a.longitude, b.longitude)
val GmcBox.top get() = max(a.latitude, b.latitude)
val GmcBox.bottom get() = min(a.latitude, b.latitude)
public val GmcBox.top: Double get() = max(a.latitude, b.latitude)
public val GmcBox.bottom: Double get() = min(a.latitude, b.latitude)
//TODO take curvature into account
val GmcBox.width get() = abs(a.longitude - b.longitude)
val GmcBox.height get() = abs(a.latitude - b.latitude)
public val GmcBox.width: Double get() = abs(a.longitude - b.longitude)
public val GmcBox.height: Double get() = abs(a.latitude - b.latitude)
/**
* Compute a minimal bounding box including all given boxes. Return null if collection is empty
*/
fun Collection<GmcBox>.wrapAll(): GmcBox? {
public fun Collection<GmcBox>.wrapAll(): GmcBox? {
if (isEmpty()) return null
//TODO optimize computation
val minLat = minOf { it.bottom }

View File

@ -5,14 +5,14 @@ import kotlin.math.pow
/**
* Observable position on the map. Includes observation coordinate and [zoom] factor
*/
data class MapViewPoint(
public data class MapViewPoint(
val focus: GeodeticMapCoordinates,
val zoom: Double,
) {
val scaleFactor by lazy { WebMercatorProjection.scaleFactor(zoom) }
val scaleFactor: Double by lazy { WebMercatorProjection.scaleFactor(zoom) }
}
fun MapViewPoint.move(delta: GeodeticMapCoordinates): MapViewPoint {
public fun MapViewPoint.move(delta: GeodeticMapCoordinates): MapViewPoint {
val newCoordinates = GeodeticMapCoordinates.ofRadians(
(focus.latitude + delta.latitude).coerceIn(
-MercatorProjection.MAXIMUM_LATITUDE,
@ -23,7 +23,7 @@ fun MapViewPoint.move(delta: GeodeticMapCoordinates): MapViewPoint {
return MapViewPoint(newCoordinates, zoom)
}
fun MapViewPoint.zoom(
public fun MapViewPoint.zoom(
zoomDelta: Double,
invariant: GeodeticMapCoordinates = focus,
): MapViewPoint = if (invariant == focus) {

View File

@ -14,7 +14,7 @@ public object WebMercatorProjection {
/**
* Compute radians to projection coordinates ratio for given [zoom] factor
*/
public fun scaleFactor(zoom: Double) = 256.0 / 2 / PI * 2.0.pow(zoom)
public fun scaleFactor(zoom: Double): Double = 256.0 / 2 / PI * 2.0.pow(zoom)
public fun toGeodetic(mercator: WebMercatorCoordinates): GeodeticMapCoordinates {
val scaleFactor = scaleFactor(mercator.zoom.toDouble())