commonMain.jetbrains.datalore.base.spatial.QuadKey.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of lets-plot-common Show documentation
Show all versions of lets-plot-common Show documentation
Lets-Plot JVM package without rendering part
/*
* Copyright (c) 2020. JetBrains s.r.o.
* Use of this source code is governed by the MIT license that can be found in the LICENSE file.
*/
package jetbrains.datalore.base.spatial
import jetbrains.datalore.base.typedGeometry.*
data class QuadKey(
val key: String
) {
operator fun plus(other: QuadKey): QuadKey {
return QuadKey(key + other.key)
}
val length = key.length
}
fun QuadKey.computeRect(): Rect {
val origin = this.computeOrigin(EARTH_RECT)
val dimension = EARTH_RECT.dimension / calulateQuadsCount(length).toDouble()
val flippedY = EARTH_RECT.scalarBottom - (origin.scalarY + dimension.scalarY - EARTH_RECT.scalarTop)
return Rect(origin.transform(newY = { flippedY }), dimension)
}
fun QuadKey.computeRect(rect: Rect): Rect {
return projectRect(rect)
}
fun QuadKey.projectRect(rect: Rect): Rect {
val origin = projectOrigin(rect)
val dimension = rect.dimension / calulateQuadsCount(length).toDouble()
return Rect(origin, dimension)
}
fun QuadKey.zoom() = length
fun QuadKey.computeOrigin(mapRect: Rect): Vec {
return projectOrigin(mapRect)
}
fun QuadKey.projectOrigin(mapRect: Rect): Vec {
var left = mapRect.scalarLeft
var top = mapRect.scalarTop
var width = mapRect.scalarWidth
var height = mapRect.scalarHeight
for (quadrant in key) {
width /= 2.0
height /= 2.0
if (quadrant == '1' || quadrant == '3') {
left += width
}
if (quadrant == '2' || quadrant == '3') {
top += height
}
}
return newVec(left, top)
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy