Improved GetHeightsMul algorithm

This commit is contained in:
Alexey 2025-11-11 13:04:45 +03:00
commit 4ecdbb1c48
2 changed files with 10 additions and 5 deletions

View file

@ -33,6 +33,7 @@ import com.mirenkov.ktheightmap.Config.Companion.MAP_START_OFFSET_X
import com.mirenkov.ktheightmap.Config.Companion.MAP_START_OFFSET_Y
import com.mirenkov.ktheightmap.parser.KhmParser
import kotlin.math.absoluteValue
import kotlin.math.ceil
import kotlin.math.floor
import kotlin.math.min
import kotlin.math.pow
@ -257,7 +258,7 @@ fun DrawScope.drawPointInfo(
val latDiff = lat - pointLat
val lonDiff = lon - pointLon
val distance = sqrt((latDiff).pow(2) + (lonDiff).pow(2))
val valuesCount = min(floor(distance / valueDistance).toInt(),1000)
val valuesCount = min(ceil(distance / valueDistance).toInt(), 1000)
val array: Array<Pair<Float, Float>> = Array(valuesCount) { step ->
val interCoef = 1F - step.toFloat() / valuesCount
Pair(lon - lonDiff * interCoef, lat - latDiff * interCoef)

View file

@ -122,10 +122,14 @@ class KhmParser {
return Pair(
UShortArray(coords.size) { i ->
if (cutOffsets[i] > 0) {
when {
(cutOffsets[i] > 0) -> {
dis.skipBytes(cutOffsets[i])
dis.readUnsignedShort().toUShort()
} else 0u },
}
(cutOffsets[i] == 0) -> {dis.readUnsignedShort().toUShort()}
else -> 0u
} },
if (reversed) coords else coords.reversed().toTypedArray())
}
}