package refactoring

This commit is contained in:
Alexander Nozik 2022-07-23 11:24:37 +03:00
parent cdee88573d
commit 2c87ba7638
No known key found for this signature in database
GPG Key ID: F7FCF2DD25C71357
23 changed files with 60 additions and 53 deletions

View File

@ -10,8 +10,8 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.window.Window import androidx.compose.ui.window.Window
import androidx.compose.ui.window.application import androidx.compose.ui.window.application
import center.sciprog.maps.compose.* import center.sciprog.maps.compose.*
import center.sciprog.maps.GeodeticMapCoordinates import center.sciprog.maps.coordinates.GeodeticMapCoordinates
import center.sciprog.maps.MapViewPoint import center.sciprog.maps.coordinates.MapViewPoint
import io.ktor.client.HttpClient import io.ktor.client.HttpClient
import io.ktor.client.engine.cio.CIO import io.ktor.client.engine.cio.CIO
import kotlinx.coroutines.delay import kotlinx.coroutines.delay

View File

@ -18,7 +18,7 @@ kotlin {
sourceSets { sourceSets {
val jvmMain by getting { val jvmMain by getting {
dependencies { dependencies {
implementation(projects.schemeKt) implementation(projects.mapsKtScheme)
implementation(compose.desktop.currentOs) implementation(compose.desktop.currentOs)
implementation("ch.qos.logback:logback-classic:1.2.11") implementation("ch.qos.logback:logback-classic:1.2.11")
} }

View File

@ -7,7 +7,7 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.painterResource
import androidx.compose.ui.window.Window import androidx.compose.ui.window.Window
import androidx.compose.ui.window.application import androidx.compose.ui.window.application
import center.sciprog.scheme.* import center.sciprog.maps.scheme.*
@Composable @Composable
@Preview @Preview

View File

@ -1,5 +1,4 @@
import org.jetbrains.compose.compose import org.jetbrains.compose.compose
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
plugins { plugins {
kotlin("multiplatform") kotlin("multiplatform")
@ -10,17 +9,19 @@ plugins {
val ktorVersion: String by rootProject.extra val ktorVersion: String by rootProject.extra
kotlin { kotlin {
explicitApi = org.jetbrains.kotlin.gradle.dsl.ExplicitApiMode.Warning
jvm { jvm {
compilations.all { compilations.all {
kotlinOptions.jvmTarget = "11" kotlinOptions.jvmTarget = "11"
} }
} }
sourceSets { sourceSets {
commonMain{ commonMain {
dependencies{ dependencies {
api(projects.mapsKtCore) api(projects.mapsKtCoordinates)
api(compose.foundation) api(compose.foundation)
api("io.ktor:ktor-client-core:$ktorVersion") api("io.ktor:ktor-client-core:$ktorVersion")
api("io.github.microutils:kotlin-logging:2.1.23")
} }
} }
val jvmMain by getting val jvmMain by getting

View File

@ -8,7 +8,7 @@ import androidx.compose.ui.graphics.drawscope.DrawScope
import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.unit.DpSize import androidx.compose.ui.unit.DpSize
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import center.sciprog.maps.GeodeticMapCoordinates import center.sciprog.maps.coordinates.GeodeticMapCoordinates
typealias FeatureId = String typealias FeatureId = String

View File

@ -1,8 +1,6 @@
package center.sciprog.maps.compose package center.sciprog.maps.compose
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ImageBitmap import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.graphics.drawscope.DrawScope import androidx.compose.ui.graphics.drawscope.DrawScope
@ -12,9 +10,9 @@ import androidx.compose.ui.graphics.vector.rememberVectorPainter
import androidx.compose.ui.unit.DpSize import androidx.compose.ui.unit.DpSize
import androidx.compose.ui.unit.IntSize import androidx.compose.ui.unit.IntSize
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import center.sciprog.maps.GeodeticMapCoordinates import center.sciprog.maps.coordinates.GeodeticMapCoordinates
import center.sciprog.maps.GmcBox import center.sciprog.maps.coordinates.GmcBox
import center.sciprog.maps.wrapAll import center.sciprog.maps.coordinates.wrapAll
//TODO replace zoom range with zoom-based representation change //TODO replace zoom range with zoom-based representation change
sealed class MapFeature(val zoomRange: IntRange) { sealed class MapFeature(val zoomRange: IntRange) {

View File

@ -4,7 +4,7 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.DpSize import androidx.compose.ui.unit.DpSize
import center.sciprog.maps.* import center.sciprog.maps.coordinates.*
import kotlin.math.PI import kotlin.math.PI
import kotlin.math.log2 import kotlin.math.log2
import kotlin.math.min import kotlin.math.min
@ -60,7 +60,7 @@ internal fun GmcBox.computeViewPoint(mapTileProvider: MapTileProvider): (canvasS
} }
@Composable @Composable
fun MapView( public fun MapView(
mapTileProvider: MapTileProvider, mapTileProvider: MapTileProvider,
box: GmcBox, box: GmcBox,
features: Map<FeatureId, MapFeature> = emptyMap(), features: Map<FeatureId, MapFeature> = emptyMap(),

View File

@ -16,7 +16,7 @@ import androidx.compose.ui.graphics.nativeCanvas
import androidx.compose.ui.graphics.toArgb import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.input.pointer.* import androidx.compose.ui.input.pointer.*
import androidx.compose.ui.unit.* import androidx.compose.ui.unit.*
import center.sciprog.maps.* import center.sciprog.maps.coordinates.*
import kotlinx.coroutines.CancellationException import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import mu.KotlinLogging import mu.KotlinLogging
@ -33,7 +33,7 @@ private fun Color.toPaint(): Paint = Paint().apply {
private fun IntRange.intersect(other: IntRange) = max(first, other.first)..min(last, other.last) private fun IntRange.intersect(other: IntRange) = max(first, other.first)..min(last, other.last)
internal fun MapViewPoint.move(deltaX: Double, deltaY: Double): MapViewPoint { internal fun MapViewPoint.move(deltaX: Double, deltaY: Double): MapViewPoint {
val newCoordinates = center.sciprog.maps.GeodeticMapCoordinates.ofRadians( val newCoordinates = center.sciprog.maps.coordinates.GeodeticMapCoordinates.ofRadians(
(focus.latitude + deltaY / scaleFactor).coerceIn( (focus.latitude + deltaY / scaleFactor).coerceIn(
-MercatorProjection.MAXIMUM_LATITUDE, -MercatorProjection.MAXIMUM_LATITUDE,
MercatorProjection.MAXIMUM_LATITUDE MercatorProjection.MAXIMUM_LATITUDE

View File

@ -15,13 +15,4 @@ kotlin {
js(IR) { js(IR) {
browser() browser()
} }
sourceSets {
commonMain {
dependencies {
api("io.github.microutils:kotlin-logging:2.1.23")
}
}
val jvmMain by getting
val jvmTest by getting
}
} }

View File

@ -0,0 +1,11 @@
package center.sciprog.maps.coordinates
/**
* A marker interface for flat coordinates
*/
public interface Coordinates2D
public interface CoordinateBox<T: Coordinates2D>{
public val a: T
public val b :T
}

View File

@ -1,11 +1,14 @@
package center.sciprog.maps package center.sciprog.maps.coordinates
import kotlin.math.PI import kotlin.math.PI
/** /**
* Geodetic coordinated * Geodetic coordinated
*/ */
public class GeodeticMapCoordinates private constructor(public val latitude: Double, public val longitude: Double) { public class GeodeticMapCoordinates private constructor(
public val latitude: Double,
public val longitude: Double,
): Coordinates2D {
override fun equals(other: Any?): Boolean { override fun equals(other: Any?): Boolean {
if (this === other) return true if (this === other) return true
@ -43,9 +46,6 @@ public class GeodeticMapCoordinates private constructor(public val latitude: Dou
} }
} }
internal typealias Gmc = GeodeticMapCoordinates
//public interface GeoToScreenConversion { //public interface GeoToScreenConversion {
// public fun getScreenX(gmc: GeodeticMapCoordinates): Double // public fun getScreenX(gmc: GeodeticMapCoordinates): Double
// public fun getScreenY(gmc: GeodeticMapCoordinates): Double // public fun getScreenY(gmc: GeodeticMapCoordinates): Double

View File

@ -1,10 +1,13 @@
package center.sciprog.maps package center.sciprog.maps.coordinates
import kotlin.math.abs import kotlin.math.abs
import kotlin.math.max import kotlin.math.max
import kotlin.math.min import kotlin.math.min
public class GmcBox(public val a: GeodeticMapCoordinates, public val b: GeodeticMapCoordinates) public data class GmcBox(
public override val a: GeodeticMapCoordinates,
public override val b: GeodeticMapCoordinates,
) : CoordinateBox<GeodeticMapCoordinates>
public fun GmcBox( public fun GmcBox(
latitudes: ClosedFloatingPointRange<Double>, latitudes: ClosedFloatingPointRange<Double>,

View File

@ -1,4 +1,4 @@
package center.sciprog.maps package center.sciprog.maps.coordinates
import kotlin.math.pow import kotlin.math.pow

View File

@ -3,7 +3,7 @@
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/ */
package center.sciprog.maps package center.sciprog.maps.coordinates
import kotlin.math.* import kotlin.math.*

View File

@ -3,7 +3,7 @@
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/ */
package center.sciprog.maps package center.sciprog.maps.coordinates
import kotlin.math.* import kotlin.math.*

View File

@ -1,6 +1,5 @@
import org.jetbrains.compose.compose import org.jetbrains.compose.compose
import org.jetbrains.compose.desktop.application.dsl.TargetFormat import org.jetbrains.compose.desktop.application.dsl.TargetFormat
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins { plugins {
kotlin("multiplatform") kotlin("multiplatform")
@ -24,8 +23,9 @@ kotlin {
withJava() withJava()
} }
sourceSets { sourceSets {
commonMain{ commonMain {
dependencies{ dependencies {
api(projects.mapsKtCoordinates)
api("io.github.microutils:kotlin-logging:2.1.23") api("io.github.microutils:kotlin-logging:2.1.23")
api(compose.foundation) api(compose.foundation)
} }

View File

@ -1,12 +1,17 @@
package center.sciprog.scheme package center.sciprog.maps.scheme
import center.sciprog.maps.coordinates.CoordinateBox
import center.sciprog.maps.coordinates.Coordinates2D
import kotlin.math.abs import kotlin.math.abs
import kotlin.math.max import kotlin.math.max
import kotlin.math.min import kotlin.math.min
data class SchemeCoordinates(val x: Float, val y: Float) data class SchemeCoordinates(val x: Float, val y: Float) : Coordinates2D
data class SchemeCoordinateBox(val a: SchemeCoordinates, val b: SchemeCoordinates) data class SchemeCoordinateBox(
override val a: SchemeCoordinates,
override val b: SchemeCoordinates,
) : CoordinateBox<SchemeCoordinates>
val SchemeCoordinateBox.top get() = max(a.y, b.y) val SchemeCoordinateBox.top get() = max(a.y, b.y)
val SchemeCoordinateBox.bottom get() = min(a.y, b.y) val SchemeCoordinateBox.bottom get() = min(a.y, b.y)

View File

@ -1,4 +1,4 @@
package center.sciprog.scheme package center.sciprog.maps.scheme
import kotlin.math.pow import kotlin.math.pow

View File

@ -1,4 +1,4 @@
package center.sciprog.scheme package center.sciprog.maps.scheme
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateMapOf import androidx.compose.runtime.mutableStateMapOf
@ -10,7 +10,7 @@ import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.unit.DpSize import androidx.compose.ui.unit.DpSize
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import center.sciprog.scheme.SchemeFeature.Companion.defaultScaleRange import center.sciprog.maps.scheme.SchemeFeature.Companion.defaultScaleRange
typealias FeatureId = String typealias FeatureId = String

View File

@ -1,4 +1,4 @@
package center.sciprog.scheme package center.sciprog.maps.scheme
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
@ -10,7 +10,7 @@ import androidx.compose.ui.graphics.vector.rememberVectorPainter
import androidx.compose.ui.unit.DpSize import androidx.compose.ui.unit.DpSize
import androidx.compose.ui.unit.IntSize import androidx.compose.ui.unit.IntSize
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import center.sciprog.scheme.SchemeFeature.Companion.defaultScaleRange import center.sciprog.maps.scheme.SchemeFeature.Companion.defaultScaleRange
internal typealias FloatRange = ClosedFloatingPointRange<Float> internal typealias FloatRange = ClosedFloatingPointRange<Float>
@ -19,8 +19,6 @@ sealed class SchemeFeature(val scaleRange: FloatRange) {
companion object { companion object {
val defaultScaleRange = 0f..Float.MAX_VALUE val defaultScaleRange = 0f..Float.MAX_VALUE
const val DEFAULT_RENDERING_ORDER = 0
const val BACKGROUND_RENDERING_ORDER = 1000
} }
} }

View File

@ -1,4 +1,4 @@
package center.sciprog.scheme package center.sciprog.maps.scheme
import androidx.compose.foundation.Canvas import androidx.compose.foundation.Canvas
import androidx.compose.foundation.gestures.drag import androidx.compose.foundation.gestures.drag

View File

Before

Width:  |  Height:  |  Size: 469 KiB

After

Width:  |  Height:  |  Size: 469 KiB

View File

@ -21,10 +21,10 @@ pluginManagement {
include( include(
":maps-kt-core", ":maps-kt-coordinates",
":maps-kt-compose", ":maps-kt-compose",
":demo:maps", ":demo:maps",
":scheme-kt", ":maps-kt-scheme",
":demo:scheme" ":demo:scheme"
) )