From 3e31effa802dea070376640805bd93a3d4f73d7a Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Tue, 4 Oct 2022 15:06:00 +0300 Subject: [PATCH] Fix failing test --- .../center/sciprog/maps/compose/MapFeature.kt | 24 +++++++++++++++---- .../center/sciprog/maps/compose/MapViewJvm.kt | 15 +++++++++--- .../sciprog/maps/coordinates/GmcRectangle.kt | 2 ++ .../sciprog/maps/coordinates/DistanceTest.kt | 2 +- 4 files changed, 35 insertions(+), 8 deletions(-) diff --git a/maps-kt-compose/src/commonMain/kotlin/center/sciprog/maps/compose/MapFeature.kt b/maps-kt-compose/src/commonMain/kotlin/center/sciprog/maps/compose/MapFeature.kt index 7f22970..d3487a1 100644 --- a/maps-kt-compose/src/commonMain/kotlin/center/sciprog/maps/compose/MapFeature.kt +++ b/maps-kt-compose/src/commonMain/kotlin/center/sciprog/maps/compose/MapFeature.kt @@ -57,6 +57,21 @@ public class MapDrawFeature( MapDrawFeature(newCoordinates, zoomRange, drawFeature) } +//public class MapPathFeature( +// public val rectangle: GmcRectangle, +// public val path: Path, +// public val brush: Brush, +// public val style: DrawStyle = Fill, +// public val targetRect: Rect = path.getBounds(), +// override val zoomRange: IntRange = defaultZoomRange, +//) : DraggableMapFeature { +// override fun withCoordinates(newCoordinates: GeodeticMapCoordinates): MapFeature = +// MapPathFeature(rectangle.moveTo(newCoordinates), path, brush, style, targetRect, zoomRange) +// +// override fun getBoundingBox(zoom: Double): GmcRectangle = rectangle +// +//} + public class MapPointsFeature( public val points: List, override val zoomRange: IntRange = defaultZoomRange, @@ -64,9 +79,7 @@ public class MapPointsFeature( public val color: Color = Color.Red, public val pointMode: PointMode = PointMode.Points, ) : MapFeature { - override fun getBoundingBox(zoom: Double): GmcRectangle { - return GmcRectangle(points.first(), points.last()) - } + override fun getBoundingBox(zoom: Double): GmcRectangle = GmcRectangle(points.first(), points.last()) } public class MapCircleFeature( @@ -118,8 +131,11 @@ public class MapArcFeature( public val arcLength: Angle, override val zoomRange: IntRange = defaultZoomRange, public val color: Color = Color.Red, -) : MapFeature { +) : DraggableMapFeature { override fun getBoundingBox(zoom: Double): GmcRectangle = oval + + override fun withCoordinates(newCoordinates: GeodeticMapCoordinates): MapFeature = + MapArcFeature(oval.moveTo(newCoordinates), startAngle, arcLength, zoomRange, color) } public class MapBitmapImageFeature( diff --git a/maps-kt-compose/src/jvmMain/kotlin/center/sciprog/maps/compose/MapViewJvm.kt b/maps-kt-compose/src/jvmMain/kotlin/center/sciprog/maps/compose/MapViewJvm.kt index 3251b1e..66fcdab 100644 --- a/maps-kt-compose/src/jvmMain/kotlin/center/sciprog/maps/compose/MapViewJvm.kt +++ b/maps-kt-compose/src/jvmMain/kotlin/center/sciprog/maps/compose/MapViewJvm.kt @@ -268,6 +268,7 @@ public actual fun MapView( } is MapBitmapImageFeature -> drawImage(feature.image, feature.position.toOffset()) + is MapVectorImageFeature -> { val offset = feature.position.toOffset() val size = feature.size.toSize() @@ -302,6 +303,14 @@ public actual fun MapView( } } +// is MapPathFeature -> { +// val offset = feature.rectangle.center.toOffset() - feature.targetRect.center +// translate(offset.x, offset.y) { +// sca +// drawPath(feature.path, brush = feature.brush, style = feature.style) +// } +// } + is MapPointsFeature -> { val points = feature.points.map { it.toOffset() } drawPoints( @@ -312,9 +321,9 @@ public actual fun MapView( ) } - else -> { - logger.error { "Unrecognized feature type: ${feature::class}" } - } +// else -> { +// logger.error { "Unrecognized feature type: ${feature::class}" } +// } } } diff --git a/maps-kt-core/src/commonMain/kotlin/center/sciprog/maps/coordinates/GmcRectangle.kt b/maps-kt-core/src/commonMain/kotlin/center/sciprog/maps/coordinates/GmcRectangle.kt index 9181f98..d60136e 100644 --- a/maps-kt-core/src/commonMain/kotlin/center/sciprog/maps/coordinates/GmcRectangle.kt +++ b/maps-kt-core/src/commonMain/kotlin/center/sciprog/maps/coordinates/GmcRectangle.kt @@ -46,6 +46,8 @@ public data class GmcRectangle( } } +public fun GmcRectangle.moveTo(newCenter: Gmc): GmcRectangle = GmcRectangle.square(newCenter, height = latitudeDelta, width = longitudeDelta) + public val GmcRectangle.center: GeodeticMapCoordinates get() = GeodeticMapCoordinates( (a.latitude + b.latitude) / 2, diff --git a/maps-kt-core/src/commonTest/kotlin/center/sciprog/maps/coordinates/DistanceTest.kt b/maps-kt-core/src/commonTest/kotlin/center/sciprog/maps/coordinates/DistanceTest.kt index 9fc96e0..e956e31 100644 --- a/maps-kt-core/src/commonTest/kotlin/center/sciprog/maps/coordinates/DistanceTest.kt +++ b/maps-kt-core/src/commonTest/kotlin/center/sciprog/maps/coordinates/DistanceTest.kt @@ -20,7 +20,7 @@ internal class DistanceTest { val distance = curve.distance assertEquals(632.035426877, distance.kilometers, 0.0001) - assertEquals((-0.6947937116552751).radians, curve.forward.bearing) + assertEquals(-0.6947937116552751, curve.forward.bearing.radians.value, 0.0001) } @Test