Files
wanderer/plugins/sdk/polyline/polyline.go
slothful-vassal 485ec53f6d feat: add plugin system (#1034)
* feat: add plugin system

* fix db docker build

* fix hammerhead readme, add strava subscription news to docs

* fixes and sdk improvements

* fix: reduce Meilisearch load, debounce federation sync (#1012)

* optimize meili trail index

* several fixes

---------

Co-authored-by: Flomp <Flomp@users.noreply.github.com>

* Bump svelte from 5.55.5 to 5.56.0 in /docs (#1032)

Bumps [svelte](https://github.com/sveltejs/svelte/tree/HEAD/packages/svelte) from 5.55.5 to 5.56.0.
- [Release notes](https://github.com/sveltejs/svelte/releases)
- [Changelog](https://github.com/sveltejs/svelte/blob/main/packages/svelte/CHANGELOG.md)
- [Commits](https://github.com/sveltejs/svelte/commits/svelte@5.56.0/packages/svelte)

---
updated-dependencies:
- dependency-name: svelte
  dependency-version: 5.56.0
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Flomp <Flomp@users.noreply.github.com>

* Release v0.19.2 (#1035)

* chore: release v0.19.2

* add changelog

---------

Co-authored-by: Flomp <26000991+Flomp@users.noreply.github.com>
Co-authored-by: Christian Beutel <>

* speed up plugin sync and several small fixes

* concepts for security improvements and process stability

* improve concept

* security concept implemented

* remove insecure TLS

* worker concept implemented

* fixes and cleanup

* fixes

* docu

* mermaid, namings

* WASM plugin host improvements, plugin logging

* fix db migration

* Improve plugin config and category mapping UI

* fixes

* further fixes

* remove manual test sync

* fix db migration and strava mapping

* type added, UI improvements

* fix plugin card toggle clickable area

* optimize synch status card layout

* plugin type 'trails' instead of 'integration'

* session auth validation in UI

* fix komoot date and waypoints

* improve category mapping

* fix send to hammerhead: trail name

* plugin setup error handling improved

* fix review findings

* re-mapping added

* rename remote_category

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: Flomp <Flomp@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Flomp <26000991+Flomp@users.noreply.github.com>
2026-06-22 15:00:44 +02:00

126 lines
2.5 KiB
Go

package polyline
import (
"fmt"
"math"
)
func Decode(encoded string, precision float64) ([][2]float64, error) {
if precision == 0 {
return nil, fmt.Errorf("precision must not be zero")
}
var coords [][2]float64
index := 0
lat := 0
lon := 0
for index < len(encoded) {
dlat, next, err := decodeValue(encoded, index)
if err != nil {
return nil, err
}
index = next
dlon, next, err := decodeValue(encoded, index)
if err != nil {
return nil, err
}
index = next
lat += dlat
lon += dlon
coords = append(coords, [2]float64{float64(lat) / precision, float64(lon) / precision})
}
return coords, nil
}
func DecodeValues(encoded string, precision float64) ([]float64, error) {
if precision == 0 {
return nil, fmt.Errorf("precision must not be zero")
}
var values []float64
index := 0
value := 0
for index < len(encoded) {
delta, next, err := decodeValue(encoded, index)
if err != nil {
return nil, err
}
index = next
value += delta
values = append(values, float64(value)/precision)
}
return values, nil
}
func NormalizeCoordinateScale(coords [][2]float64) {
if len(coords) == 0 {
return
}
maxLat := 0.0
maxLon := 0.0
for _, coord := range coords {
if abs := math.Abs(coord[0]); abs > maxLat {
maxLat = abs
}
if abs := math.Abs(coord[1]); abs > maxLon {
maxLon = abs
}
}
for (maxLat > 90 || maxLon > 180) && maxLat > 0 && maxLon > 0 {
for i := range coords {
coords[i][0] /= 10
coords[i][1] /= 10
}
maxLat /= 10
maxLon /= 10
}
}
func ShouldSwapCoordinates(coords [][2]float64) bool {
validAsLat := 0
validAsLon := 0
for _, coord := range coords {
if validLatLon(coord[0], coord[1]) {
validAsLat++
}
if validLatLon(coord[1], coord[0]) {
validAsLon++
}
}
return validAsLon > validAsLat
}
func ProportionalIndex(i int, sourceLen int, targetLen int) int {
if targetLen <= 1 || sourceLen <= 1 {
return 0
}
j := int(math.Round(float64(i) * float64(targetLen-1) / float64(sourceLen-1)))
if j < 0 {
return 0
}
if j >= targetLen {
return targetLen - 1
}
return j
}
func validLatLon(lat float64, lon float64) bool {
return lat >= -90 && lat <= 90 && lon >= -180 && lon <= 180
}
func decodeValue(encoded string, index int) (int, int, error) {
result := 0
shift := uint(0)
for {
if index >= len(encoded) {
return 0, index, fmt.Errorf("invalid polyline encoding")
}
b := int(encoded[index]) - 63
index++
result |= (b & 0x1F) << shift
shift += 5
if b < 0x20 {
break
}
}
return (result >> 1) ^ (-(result & 1)), index, nil
}