All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.ru.casperix.path.custom.float_path.MapInfo.kt Maven / Gradle / Ivy

package ru.casperix.path.custom.float_path

import ru.casperix.math.vector.float32.Vector2f
import ru.casperix.math.vector.int32.Vector2i

class MapInfo(val map: SurfaceMap, val roadMap: MutableMap) {
    val roads get() = roadMap.keys

    fun nearRoad(target: Vector2f): Vector2f? {
        val pivot = target.toVector2i()
        val nearTiles = (-1..1).flatMap { x ->
            (-1..1).mapNotNull { y ->
                roadMap[pivot + Vector2i(x, y)]
            }
        }

        return nearTiles.minByOrNull { it.distTo(target) }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy