Skip to content

Commit a132095

Browse files
authored
[sdk-base] add default parameters to coordinate conversion functions (#491)
1 parent 702e7f9 commit a132095

2 files changed

Lines changed: 101 additions & 9 deletions

File tree

sdk-base/src/main/java/com/mapbox/maps/plugin/delegates/MapCameraManagerDelegate.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ interface MapCameraManagerDelegate {
2828
*/
2929
fun cameraForCoordinateBounds(
3030
bounds: CoordinateBounds,
31-
padding: EdgeInsets,
32-
bearing: Double?,
33-
pitch: Double?
31+
padding: EdgeInsets = EdgeInsets(0.0, 0.0, 0.0, 0.0),
32+
bearing: Double? = null,
33+
pitch: Double? = null
3434
): CameraOptions
3535

3636
/**
@@ -45,9 +45,9 @@ interface MapCameraManagerDelegate {
4545
*/
4646
fun cameraForCoordinates(
4747
coordinates: List<Point>,
48-
padding: EdgeInsets,
49-
bearing: Double?,
50-
pitch: Double?
48+
padding: EdgeInsets = EdgeInsets(0.0, 0.0, 0.0, 0.0),
49+
bearing: Double? = null,
50+
pitch: Double? = null
5151
): CameraOptions
5252

5353
/**
@@ -83,9 +83,9 @@ interface MapCameraManagerDelegate {
8383
*/
8484
fun cameraForGeometry(
8585
geometry: Geometry,
86-
padding: EdgeInsets,
87-
bearing: Double?,
88-
pitch: Double?
86+
padding: EdgeInsets = EdgeInsets(0.0, 0.0, 0.0, 0.0),
87+
bearing: Double? = null,
88+
pitch: Double? = null
8989
): CameraOptions
9090

9191
/**

sdk/src/test/java/com/mapbox/maps/MapboxMapTest.kt

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,56 @@ class MapboxMapTest {
457457
verify { nativeMap.cameraForCoordinateBounds(bounds, edgeInsets, 0.0, 1.0) }
458458
}
459459

460+
@Test
461+
fun cameraForCoordinateBoundsOverload() {
462+
val bounds = mockk<CoordinateBounds>()
463+
mapboxMap.cameraForCoordinateBounds(bounds)
464+
verify {
465+
nativeMap.cameraForCoordinateBounds(
466+
bounds,
467+
EdgeInsets(0.0, 0.0, 0.0, 0.0),
468+
null,
469+
null
470+
)
471+
}
472+
}
473+
474+
@Test
475+
fun cameraForCoordinateBoundsOverloadPadding() {
476+
val bounds = mockk<CoordinateBounds>()
477+
val padding = EdgeInsets(1.1, 1.3, 1.4, 1.2)
478+
mapboxMap.cameraForCoordinateBounds(bounds, padding)
479+
verify { nativeMap.cameraForCoordinateBounds(bounds, padding, null, null) }
480+
}
481+
482+
@Test
483+
fun cameraForCoordinateBoundsOverloadBearing() {
484+
val bounds = mockk<CoordinateBounds>()
485+
mapboxMap.cameraForCoordinateBounds(bounds, bearing = 2.0)
486+
verify {
487+
nativeMap.cameraForCoordinateBounds(
488+
bounds,
489+
EdgeInsets(0.0, 0.0, 0.0, 0.0),
490+
2.0,
491+
null
492+
)
493+
}
494+
}
495+
496+
@Test
497+
fun cameraForCoordinateBoundsOverloadPitch() {
498+
val bounds = mockk<CoordinateBounds>()
499+
mapboxMap.cameraForCoordinateBounds(bounds, pitch = 2.0)
500+
verify {
501+
nativeMap.cameraForCoordinateBounds(
502+
bounds,
503+
EdgeInsets(0.0, 0.0, 0.0, 0.0),
504+
null,
505+
2.0
506+
)
507+
}
508+
}
509+
460510
@Test
461511
fun coordinateBoundsForCamera() {
462512
val cameraOptions = mockk<CameraOptions>()
@@ -495,6 +545,27 @@ class MapboxMapTest {
495545
verify { nativeMap.cameraForCoordinates(points, edgeInsets, 0.0, 1.0) }
496546
}
497547

548+
@Test
549+
fun cameraForCoordinatesOverload() {
550+
val points = mockk<List<Point>>()
551+
mapboxMap.cameraForCoordinates(points)
552+
verify { nativeMap.cameraForCoordinates(points, EdgeInsets(0.0, 0.0, 0.0, 0.0), null, null) }
553+
}
554+
555+
@Test
556+
fun cameraForCoordinatesOverloadBearing() {
557+
val points = mockk<List<Point>>()
558+
mapboxMap.cameraForCoordinates(points, bearing = 2.0)
559+
verify { nativeMap.cameraForCoordinates(points, EdgeInsets(0.0, 0.0, 0.0, 0.0), 2.0, null) }
560+
}
561+
562+
@Test
563+
fun cameraForCoordinatesOverloadPitch() {
564+
val points = mockk<List<Point>>()
565+
mapboxMap.cameraForCoordinates(points, pitch = 2.0)
566+
verify { nativeMap.cameraForCoordinates(points, EdgeInsets(0.0, 0.0, 0.0, 0.0), null, 2.0) }
567+
}
568+
498569
@Test
499570
fun cameraForGeometry() {
500571
val point = mockk<Point>()
@@ -503,6 +574,27 @@ class MapboxMapTest {
503574
verify { nativeMap.cameraForGeometry(point, edgeInsets, 0.0, 1.0) }
504575
}
505576

577+
@Test
578+
fun cameraForGeometryOverload() {
579+
val point = mockk<Point>()
580+
mapboxMap.cameraForGeometry(point)
581+
verify { nativeMap.cameraForGeometry(point, EdgeInsets(0.0, 0.0, 0.0, 0.0), null, null) }
582+
}
583+
584+
@Test
585+
fun cameraForGeometryOverloadBearing() {
586+
val point = mockk<Point>()
587+
mapboxMap.cameraForGeometry(point, bearing = 2.0)
588+
verify { nativeMap.cameraForGeometry(point, EdgeInsets(0.0, 0.0, 0.0, 0.0), 2.0, null) }
589+
}
590+
591+
@Test
592+
fun cameraForGeometryOverloadPitch() {
593+
val point = mockk<Point>()
594+
mapboxMap.cameraForGeometry(point, pitch = 2.0)
595+
verify { nativeMap.cameraForGeometry(point, EdgeInsets(0.0, 0.0, 0.0, 0.0), null, 2.0) }
596+
}
597+
506598
@Test
507599
fun pixelForCoordinate() {
508600
val point = mockk<Point>()

0 commit comments

Comments
 (0)