Fix for #20 - auto-scale for single point

This commit is contained in:
Alexander Nozik 2023-05-11 09:39:08 +03:00
parent a059697f5c
commit 2bc595d97d
3 changed files with 17 additions and 4 deletions

View File

@ -157,6 +157,14 @@ fun doubleObstacle() {
}
}
@Composable
@Preview
fun singleElement() {
SchemeView {
points(listOf(XY(1f,1f)))
}
}
@Composable
@Preview
@ -165,6 +173,7 @@ fun playground() {
"Close starting points",
"Single obstacle",
"Two obstacles",
"Single element"
)
var currentExample by remember { mutableStateOf(examples.first()) }
@ -182,6 +191,7 @@ fun playground() {
examples[0] -> closePoints()
examples[1] -> singleObstacle()
examples[2] -> doubleObstacle()
examples[3] -> singleElement()
}
}
}

View File

@ -63,7 +63,7 @@ public class MapViewScope internal constructor(
canvasSize.width.value / rectangle.longitudeDelta.radians,
canvasSize.height.value / rectangle.latitudeDelta.radians
) * 2 * PI / mapTileProvider.tileSize
)
).coerceIn(0.0..22.0)
return space.ViewPoint(rectangle.center, zoom.toFloat())
}

View File

@ -26,12 +26,15 @@ public class XYViewScope(
)
override fun computeViewPoint(rectangle: Rectangle<XY>): ViewPoint<XY> {
val scale = min(
val scale: Float = min(
canvasSize.width.value / rectangle.width,
canvasSize.height.value / rectangle.height
)
return XYViewPoint(rectangle.center, scale)
return if(scale.isInfinite()){
XYViewPoint(rectangle.center, 1f)
} else {
XYViewPoint(rectangle.center, scale)
}
}
override fun ViewPoint<XY>.moveBy(x: Dp, y: Dp): ViewPoint<XY> {