Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2e624ae9 authored by Fynn Godau's avatar Fynn Godau
Browse files

Apply review

parent a278b3d2
Loading
Loading
Loading
Loading
+36 −36
Original line number Diff line number Diff line
@@ -34,15 +34,14 @@ import com.mapbox.turf.TurfTransformation
import org.microg.gms.maps.mapbox.GoogleMapImpl
import com.google.android.gms.maps.model.CircleOptions as GmsCircleOptions

val NORTH_POLE = Point.fromLngLat(0.0, 90.0)
val SOUTH_POLE = Point.fromLngLat(0.0, -90.0)
val NORTH_POLE: Point = Point.fromLngLat(0.0, 90.0)
val SOUTH_POLE: Point = Point.fromLngLat(0.0, -90.0)

/**
 * Amount of points to be used in the polygon that approximates the circle.
 */
const val CIRCLE_POLYGON_STEPS = 256


class CircleImpl(private val map: GoogleMapImpl, private val id: String, options: GmsCircleOptions) : ICircleDelegate.Stub(), Markup<Fill, FillOptions> {
    private var center: LatLng = options.center
    private var radius: Double = options.radius // in meters
@@ -94,10 +93,10 @@ class CircleImpl(private val map: GoogleMapImpl, private val id: String, options
        ) * 1000 < radius
    }

    private fun makeOutlineLatLngs() =
        TurfMeta.coordAll(
    private fun makeOutlineLatLngs(): MutableList<Point> {
        val pointList = TurfMeta.coordAll(
            makePolygon(), wrapsAroundPoles()
        ).let {
        )
        // Circles around the poles are tricky to draw (https://github.com/mapbox/mapbox-gl-js/issues/11235).
        // We modify our lines such to match the way Mapbox / MapLibre draws them.
        // This results in a small gap somewhere in the line, but avoids an incorrect horizontal line.
@@ -106,33 +105,34 @@ class CircleImpl(private val map: GoogleMapImpl, private val id: String, options

        if (!centerPoint.equals(NORTH_POLE) && TurfMeasurement.distance(centerPoint, NORTH_POLE) * 1000 < radius) {
            // Wraps around North Pole
                for (i in 0 until it.size) {
            for (i in 0 until pointList.size) {
                // We want to have the north-most points at the start and end
                    if (it[0].latitude() > it[1].latitude() && it[it.size-1].latitude() > it[it.size-2].latitude()) {
                        return@let it
                if (pointList[0].latitude() > pointList[1].latitude() && pointList[pointList.size - 1].latitude() > pointList[pointList.size - 2].latitude()) {
                    return pointList
                } else {
                    // Cycle point list
                        val zero = it.removeFirst()
                        it.add(zero)
                    val zero = pointList.removeFirst()
                    pointList.add(zero)
                }
            }
        }

        if (!centerPoint.equals(SOUTH_POLE) && TurfMeasurement.distance(centerPoint, SOUTH_POLE) * 1000 < radius) {
            // Wraps around South Pole
                for (i in 0 until it.size) {
            for (i in 0 until pointList.size) {
                // We want to have the south-most points at the start and end
                    if (it[0].latitude() < it[1].latitude() && it[it.size-1].latitude() < it[it.size-2].latitude()) {
                        return@let it
                if (pointList[0].latitude() < pointList[1].latitude() && pointList[pointList.size - 1].latitude() < pointList[pointList.size - 2].latitude()) {
                    return pointList
                } else {
                    // Cycle point list
                        val last = it.removeAt(it.size - 1)
                        it.add(0, last)
                    val last = pointList.removeAt(pointList.size - 1)
                    pointList.add(0, last)
                }
            }
        }

            it
        // In this case no changes were made
        return pointList
    }

    private fun updateLatLngs() {