Fixed reversing
This commit is contained in:
parent
6e47b724e8
commit
86a2dc3786
2 changed files with 8 additions and 11 deletions
|
|
@ -20,9 +20,6 @@ class KhmParser {
|
|||
private var header: HeightInfo? = null
|
||||
const val HEIGHT_FILE: String = "height.khm"
|
||||
|
||||
@OptIn(ExperimentalUnsignedTypes::class)
|
||||
var cachedHeights: Pair<UShortArray, Array<Pair<Float, Float>>>? = null
|
||||
|
||||
fun load(filePath: String, ctx: Context) {
|
||||
if (ctx.getFileStreamPath(HEIGHT_FILE).exists()) {
|
||||
return
|
||||
|
|
@ -84,11 +81,12 @@ class KhmParser {
|
|||
@OptIn(ExperimentalUnsignedTypes::class)
|
||||
fun getHeightsMul(ctx: Context, coords: Array<Pair<Float, Float>>): Pair<UShortArray, Array<Pair<Float, Float>>> {
|
||||
if (coords.isEmpty()) return Pair(ushortArrayOf(), coords)
|
||||
if (cachedHeights != null) return cachedHeights!!
|
||||
val dis = DataInputStream(ctx.openFileInput(HEIGHT_FILE))
|
||||
dis.use {
|
||||
val header = readHeader(dis)
|
||||
|
||||
val reversed = coords[0].first < coords[coords.size - 1].first
|
||||
|
||||
val glist: MutableMap<Pair<Float, Float>, Int> = mutableMapOf()
|
||||
|
||||
for (coord in coords) {
|
||||
|
|
@ -113,13 +111,13 @@ class KhmParser {
|
|||
} else break
|
||||
}
|
||||
|
||||
cachedHeights = Pair(UShortArray(coords.size) { i ->
|
||||
return Pair(
|
||||
UShortArray(coords.size) { i ->
|
||||
if (cutOffsets[i] > 0) {
|
||||
dis.skipBytes(cutOffsets[i])
|
||||
dis.readUnsignedShort().toUShort()
|
||||
} else 0u
|
||||
}, coords)
|
||||
return cachedHeights!!
|
||||
} else 0u },
|
||||
if (reversed) coords else coords.reversed().toTypedArray())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -54,11 +54,9 @@ fun MapCanvas(
|
|||
.pointerInput(Unit) {
|
||||
detectDragGestures (
|
||||
onDragEnd = {
|
||||
KhmParser.cachedHeights = null
|
||||
invokeHeightCalc = true
|
||||
},
|
||||
onDragCancel = {
|
||||
KhmParser.cachedHeights = null
|
||||
invokeHeightCalc = true
|
||||
}
|
||||
) { _, distance ->
|
||||
|
|
@ -223,7 +221,8 @@ fun MapCanvas(
|
|||
}
|
||||
val heightPair = KhmParser.getHeightsMul(ctx, array)
|
||||
val heights = heightPair.first
|
||||
val coords = heightPair.second.reversed()
|
||||
val coords = heightPair.second
|
||||
|
||||
for (step in 0 until coords.size) {
|
||||
val stepLat = coords[step].second
|
||||
val stepLon = coords[step].first
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue