You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

29 lines
902 B

package example.map
import androidx.compose.ui.graphics.ImageBitmap
import kotlin.math.roundToInt
class TileImage(
val platformSpecificData: ImageBitmap,
val offsetX: Int = 0,
val offsetY: Int = 0,
val cropSize: Int = TILE_SIZE,
) {
fun lightweightDuplicate(offsetX: Int, offsetY: Int, cropSize: Int): TileImage =
TileImage(
platformSpecificData,
offsetX = offsetX,
offsetY = offsetY,
cropSize = cropSize
)
}
fun TileImage.cropAndRestoreSize(x: Int, y: Int, targetSize: Int): TileImage {
val scale: Float = targetSize.toFloat() / TILE_SIZE
val newSize = maxOf(1, (cropSize * scale).roundToInt())
val dx = x * newSize / targetSize
val dy = y * newSize / targetSize
val newX = offsetX + dx
val newY = offsetY + dy
return lightweightDuplicate(newX % TILE_SIZE, newY % TILE_SIZE, newSize)
}