little refactoring

This commit is contained in:
Alexey 2025-08-25 15:41:31 +03:00
commit 3f2b3eec45
3 changed files with 12 additions and 7 deletions

View file

@ -4,10 +4,10 @@
<selectionStates> <selectionStates>
<SelectionState runConfigName="app"> <SelectionState runConfigName="app">
<option name="selectionMode" value="DROPDOWN" /> <option name="selectionMode" value="DROPDOWN" />
<DropdownSelection timestamp="2025-08-21T11:17:37.943341883Z"> <DropdownSelection timestamp="2025-08-25T12:35:44.992136184Z">
<Target type="DEFAULT_BOOT"> <Target type="DEFAULT_BOOT">
<handle> <handle>
<DeviceId pluginId="PhysicalDevice" identifier="serial=96DX21GPR" /> <DeviceId pluginId="LocalEmulator" identifier="path=/home/secondbeam/.config/.android/avd/Virtual_Pixel_3.avd" />
</handle> </handle>
</Target> </Target>
</DropdownSelection> </DropdownSelection>

View file

@ -91,7 +91,8 @@ fun MapCanvas(
val tileY = tileOffsetY + cellY val tileY = tileOffsetY + cellY
val localOffsetY = TILE_SIZE * (cellY - 1) val localOffsetY = TILE_SIZE * (cellY - 1)
val bitmap = tiles.find { it.x == tileX && it.y == tileY && it.level == level }?.toBitmap() val tile = tiles.find { it.x == tileX && it.y == tileY && it.level == level }!!
val bitmap = tile.toBitmap()
val totalOffset = Offset(localOffsetX, localOffsetY) - offset val totalOffset = Offset(localOffsetX, localOffsetY) - offset
bitmap?.let { bitmap?.let {
@ -114,10 +115,8 @@ fun MapCanvas(
text = buildAnnotatedString { text = buildAnnotatedString {
withStyle(ParagraphStyle(textAlign = TextAlign.Center)) { withStyle(ParagraphStyle(textAlign = TextAlign.Center)) {
withStyle(SpanStyle(color = gridColor)) { withStyle(SpanStyle(color = gridColor)) {
val mapSize = (1 shl (level - 1)).toDouble() val mercX = tile.mercateX()
val mappedY = (tileY.toDouble() - (mapSize / 2.0)) val mercY = tile.mercateY()
val mercX = SphereMercator.sx2lon((tileX * TILE_SIZE).toDouble(), level) - 180.0
val mercY = -SphereMercator.sy2lat(mappedY * TILE_SIZE, level - 1)
append("%.6f, %.6f,\n%d, %d".format(mercX, mercY, tileX, tileY)) append("%.6f, %.6f,\n%d, %d".format(mercX, mercY, tileX, tileY))
} }
} }
@ -125,6 +124,8 @@ fun MapCanvas(
topLeft = totalOffset, topLeft = totalOffset,
size = Size(TILE_SIZE, TILE_SIZE) size = Size(TILE_SIZE, TILE_SIZE)
) )
} }
} }
} }

View file

@ -46,4 +46,8 @@ class Tile {
bitmap = BitmapFactory.decodeByteArray(ba, 0, ba.size) bitmap = BitmapFactory.decodeByteArray(ba, 0, ba.size)
return bitmap return bitmap
} }
fun mercateX(): Double = SphereMercator.sx2lon((x * TILE_SIZE).toDouble(), level) - 180.0
fun mercateY(): Double = -SphereMercator.sy2lat((y.toDouble() - ((1 shl (level - 1)).toDouble() / 2.0)) * TILE_SIZE, level - 1)
} }