Improved GetHeightsMul algorithm
This commit is contained in:
parent
7a424db8ab
commit
4ecdbb1c48
2 changed files with 10 additions and 5 deletions
|
|
@ -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.Config.Companion.MAP_START_OFFSET_Y
|
||||||
import com.mirenkov.ktheightmap.parser.KhmParser
|
import com.mirenkov.ktheightmap.parser.KhmParser
|
||||||
import kotlin.math.absoluteValue
|
import kotlin.math.absoluteValue
|
||||||
|
import kotlin.math.ceil
|
||||||
import kotlin.math.floor
|
import kotlin.math.floor
|
||||||
import kotlin.math.min
|
import kotlin.math.min
|
||||||
import kotlin.math.pow
|
import kotlin.math.pow
|
||||||
|
|
@ -257,7 +258,7 @@ fun DrawScope.drawPointInfo(
|
||||||
val latDiff = lat - pointLat
|
val latDiff = lat - pointLat
|
||||||
val lonDiff = lon - pointLon
|
val lonDiff = lon - pointLon
|
||||||
val distance = sqrt((latDiff).pow(2) + (lonDiff).pow(2))
|
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 array: Array<Pair<Float, Float>> = Array(valuesCount) { step ->
|
||||||
val interCoef = 1F - step.toFloat() / valuesCount
|
val interCoef = 1F - step.toFloat() / valuesCount
|
||||||
Pair(lon - lonDiff * interCoef, lat - latDiff * interCoef)
|
Pair(lon - lonDiff * interCoef, lat - latDiff * interCoef)
|
||||||
|
|
|
||||||
|
|
@ -122,10 +122,14 @@ class KhmParser {
|
||||||
|
|
||||||
return Pair(
|
return Pair(
|
||||||
UShortArray(coords.size) { i ->
|
UShortArray(coords.size) { i ->
|
||||||
if (cutOffsets[i] > 0) {
|
when {
|
||||||
|
(cutOffsets[i] > 0) -> {
|
||||||
dis.skipBytes(cutOffsets[i])
|
dis.skipBytes(cutOffsets[i])
|
||||||
dis.readUnsignedShort().toUShort()
|
dis.readUnsignedShort().toUShort()
|
||||||
} else 0u },
|
}
|
||||||
|
(cutOffsets[i] == 0) -> {dis.readUnsignedShort().toUShort()}
|
||||||
|
else -> 0u
|
||||||
|
} },
|
||||||
if (reversed) coords else coords.reversed().toTypedArray())
|
if (reversed) coords else coords.reversed().toTypedArray())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue