mapwidget.qml: return early instead of doing branching

The centerOn*() functions can just return early
for invalid input, instead of branching the conditions.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
This commit is contained in:
Lubomir I. Ivanov 2017-11-27 17:13:57 +02:00
parent 1d80b08a8f
commit 837ed67d86

View file

@ -151,73 +151,73 @@ Item {
stopZoomAnimations() stopZoomAnimations()
if (!coordIsValid(coord)) { if (!coordIsValid(coord)) {
console.warn("MapWidget.qml: centerOnCoordinate(): !coordIsValid()") console.warn("MapWidget.qml: centerOnCoordinate(): !coordIsValid()")
} else { return
var newZoomOutFound = false
var zoomStored = zoomLevel
var centerStored = QtPositioning.coordinate(center.latitude, center.longitude)
newZoomOut = zoomLevel
newCenter = coord
zoomLevel = Math.floor(zoomLevel)
while (zoomLevel > minimumZoomLevel) {
var pt = fromCoordinate(coord)
if (pointIsVisible(pt)) {
newZoomOut = zoomLevel
newZoomOutFound = true
break
}
zoomLevel -= 1.0
}
if (!newZoomOutFound)
newZoomOut = defaultZoomOut
zoomLevel = zoomStored
center = centerStored
newZoom = zoomStored
mapAnimationZoomIn.restart()
} }
var newZoomOutFound = false
var zoomStored = zoomLevel
var centerStored = QtPositioning.coordinate(center.latitude, center.longitude)
newZoomOut = zoomLevel
newCenter = coord
zoomLevel = Math.floor(zoomLevel)
while (zoomLevel > minimumZoomLevel) {
var pt = fromCoordinate(coord)
if (pointIsVisible(pt)) {
newZoomOut = zoomLevel
newZoomOutFound = true
break
}
zoomLevel -= 1.0
}
if (!newZoomOutFound)
newZoomOut = defaultZoomOut
zoomLevel = zoomStored
center = centerStored
newZoom = zoomStored
mapAnimationZoomIn.restart()
} }
function centerOnRectangle(topLeft, bottomRight, centerRect) { function centerOnRectangle(topLeft, bottomRight, centerRect) {
stopZoomAnimations() stopZoomAnimations()
if (newCenter.latitude === 0.0 && newCenter.longitude === 0.0) { if (newCenter.latitude === 0.0 && newCenter.longitude === 0.0) {
// Do nothing // Do nothing
} else { return
var centerStored = QtPositioning.coordinate(center.latitude, center.longitude)
var zoomStored = zoomLevel
var newZoomOutFound = false
newCenter = centerRect
// calculate zoom out
newZoomOut = zoomLevel
while (zoomLevel > minimumZoomLevel) {
var ptCenter = fromCoordinate(centerStored)
var ptCenterRect = fromCoordinate(centerRect)
if (pointIsVisible(ptCenter) && pointIsVisible(ptCenterRect)) {
newZoomOut = zoomLevel
newZoomOutFound = true
break
}
zoomLevel -= 1.0
}
if (!newZoomOutFound)
newZoomOut = defaultZoomOut
// calculate zoom in
center = newCenter
zoomLevel = Math.floor(maximumZoomLevel)
var diagonalRect = topLeft.distanceTo(bottomRight)
while (zoomLevel > minimumZoomLevel) {
var c0 = toCoordinate(Qt.point(0.0, 0.0))
var c1 = toCoordinate(Qt.point(width, height))
if (c0.distanceTo(c1) > diagonalRect) {
newZoom = zoomLevel - 2.0
break
}
zoomLevel -= 1.0
}
if (newZoom > defaultZoomIn)
newZoom = defaultZoomIn
zoomLevel = zoomStored
center = centerStored
mapAnimationZoomIn.restart()
} }
var centerStored = QtPositioning.coordinate(center.latitude, center.longitude)
var zoomStored = zoomLevel
var newZoomOutFound = false
newCenter = centerRect
// calculate zoom out
newZoomOut = zoomLevel
while (zoomLevel > minimumZoomLevel) {
var ptCenter = fromCoordinate(centerStored)
var ptCenterRect = fromCoordinate(centerRect)
if (pointIsVisible(ptCenter) && pointIsVisible(ptCenterRect)) {
newZoomOut = zoomLevel
newZoomOutFound = true
break
}
zoomLevel -= 1.0
}
if (!newZoomOutFound)
newZoomOut = defaultZoomOut
// calculate zoom in
center = newCenter
zoomLevel = Math.floor(maximumZoomLevel)
var diagonalRect = topLeft.distanceTo(bottomRight)
while (zoomLevel > minimumZoomLevel) {
var c0 = toCoordinate(Qt.point(0.0, 0.0))
var c1 = toCoordinate(Qt.point(width, height))
if (c0.distanceTo(c1) > diagonalRect) {
newZoom = zoomLevel - 2.0
break
}
zoomLevel -= 1.0
}
if (newZoom > defaultZoomIn)
newZoom = defaultZoomIn
zoomLevel = zoomStored
center = centerStored
mapAnimationZoomIn.restart()
} }
function deselectMapLocation() { function deselectMapLocation() {