Skip to content

Commit

Permalink
Fix bearing of the puck being reset on settings change. (#1144)
Browse files Browse the repository at this point in the history
Fix bearing of the puck being reset on settings change.
  • Loading branch information
yunikkk authored Feb 23, 2022
1 parent 767d6cf commit e6d089f
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ mapView.location2.puckBearingEnabled = false
* Avoid possible crash at program exit caused by dummy tracer accessed after the destruction. ([#1160](https://github.com/mapbox/mapbox-maps-android/pull/1160))
* Fix crash for the case when a map event is handled by an Observer of a destructed map. ([#1160](https://github.com/mapbox/mapbox-maps-android/pull/1160))
* Fix shimmering artifact when pitched raster tiles with compressed textures are rendered. ([#1160](https://github.com/mapbox/mapbox-maps-android/pull/1160))
* Fix bearing of the puck reseted on settings change. ([#1144](https://github.com/mapbox/mapbox-maps-android/pull/1144))

## Dependencies
* Bump gl-native to 10.4.0-beta.1, mapbox-common to v21.2.0-beta.1 ([#1160](https://github.com/mapbox/mapbox-maps-android/pull/1160))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ internal class LocationIndicatorLayerWrapper(layerId: String) : LocationLayerWra
layerProperties["id"] = Value(layerId)
layerProperties["type"] = Value("location-indicator")
layerProperties["location-transition"] = buildTransition(delay = 0, duration = 0)
layerProperties["bearing-transition"] = buildTransition(delay = 0, duration = 0)
layerProperties["perspective-compensation"] = Value(0.9)
layerProperties["image-pitch-displacement"] = Value(4.0)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ internal class LocationPuckManager(
animationManager.setLocationLayerRenderer(locationLayerRenderer)
animationManager.applyPulsingAnimationSettings(settings)
animationManager.applySettings2(settings2)
locationLayerRenderer.addLayers(positionManager)
lastLocation?.let {
updateCurrentPosition(it)
}
updateCurrentBearing(lastBearing)
locationLayerRenderer.addLayers(positionManager)
locationLayerRenderer.initializeComponents(style)
styleScaling(settings)
if (lastLocation != null && settings.enabled) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class LocationIndicatorLayerWrapperTest {
@Test
fun testInitialProperties() {
val value = layer.toValue()
assertEquals("{image-pitch-displacement=4.0, location-transition={duration=0, delay=0}, perspective-compensation=0.9, id=indicatorLayerId, type=location-indicator}", value.toString())
assertEquals("{bearing-transition={duration=0, delay=0}, image-pitch-displacement=4.0, location-transition={duration=0, delay=0}, perspective-compensation=0.9, id=indicatorLayerId, type=location-indicator}", value.toString())
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,13 @@ import com.mapbox.maps.plugin.locationcomponent.animators.PuckAnimatorManager
import com.mapbox.maps.plugin.locationcomponent.generated.LocationComponentSettings
import com.mapbox.maps.plugin.locationcomponent.generated.LocationComponentSettings2
import com.mapbox.maps.util.captureVararg
import io.mockk.CapturingSlot
import io.mockk.every
import io.mockk.mockk
import io.mockk.mockkStatic
import io.mockk.verify
import io.mockk.verifyOrder
import org.junit.Assert.assertArrayEquals
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import io.mockk.*
import org.junit.Assert.*
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import kotlin.math.abs

@RunWith(RobolectricTestRunner::class)
class LocationPuckManagerTest {
Expand Down Expand Up @@ -257,10 +250,19 @@ class LocationPuckManagerTest {
every { Value.fromJson(any()) } returns ExpectedFactory.createValue(Value("expression"))
locationPuckManager.styleScaling(settings)
verify { locationLayerRenderer.styleScaling(capture(valueSlot)) }
assertEquals(
"[interpolate, [exponential, 0.5], [zoom], 0.5, [literal, [$MODEL_SCALE_CONSTANT, $MODEL_SCALE_CONSTANT, $MODEL_SCALE_CONSTANT]], 22.0, [literal, [1.0, 1.0, 1.0]]]",
valueSlot.captured.toString()
)
val value = valueSlot.captured.toString()
assertTrue(value.startsWith("[interpolate, [exponential, 0.5], [zoom], 0.5, [literal, ["))
assertTrue(value.endsWith("]], 22.0, [literal, [1.0, 1.0, 1.0]]]"))
value
.replace("[interpolate, [exponential, 0.5], [zoom], 0.5, [literal, [", "")
.replace("]], 22.0, [literal, [1.0, 1.0, 1.0]]]", "")
.split(", ")
.map { it.toDouble() }
.forEach {
val absoluteDifference: Float = abs(it - MODEL_SCALE_CONSTANT).toFloat()
val maxUlp = Math.ulp(it).coerceAtLeast(Math.ulp(MODEL_SCALE_CONSTANT)).toFloat()
assert(absoluteDifference < 2 * maxUlp)
}
}

@Test
Expand Down

0 comments on commit e6d089f

Please sign in to comment.