mirror of
https://github.com/photoprism/photoprism.git
synced 2025-09-26 21:01:58 +08:00
Signed-off-by: Michael Mayer <michael@photoprism.app>
This commit is contained in:
25
pkg/geo/latlng/latlng.go
Normal file
25
pkg/geo/latlng/latlng.go
Normal file
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
Package latlng provides latitude and longitude functions and constants.
|
||||
|
||||
Copyright (c) 2018 - 2025 PhotoPrism UG. All rights reserved.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under Version 3 of the GNU Affero General Public License (the "AGPL"):
|
||||
<https://docs.photoprism.app/license/agpl>
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
The AGPL is supplemented by our Trademark and Brand Guidelines,
|
||||
which describe how our Brand Assets may be used:
|
||||
<https://www.photoprism.app/trademark>
|
||||
|
||||
Feel free to send an email to hello@photoprism.app if you have questions,
|
||||
want to support our work, or just want to say hello.
|
||||
|
||||
Additional information can be found in our Developer Guide:
|
||||
<https://docs.photoprism.app/developer-guide/>
|
||||
*/
|
||||
package latlng
|
15
pkg/geo/latlng/round.go
Normal file
15
pkg/geo/latlng/round.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package latlng
|
||||
|
||||
import "math"
|
||||
|
||||
var RoundDecimals = float64(10000000)
|
||||
|
||||
// Round rounds the given coordinate to six decimal places.
|
||||
func Round(c float64) float64 {
|
||||
return math.Round(c*RoundDecimals) / RoundDecimals
|
||||
}
|
||||
|
||||
// RoundCoords rounds the given latitude and longitude to six decimal places.
|
||||
func RoundCoords(lat, lng float64) (float64, float64) {
|
||||
return Round(lat), Round(lng)
|
||||
}
|
22
pkg/geo/latlng/round_test.go
Normal file
22
pkg/geo/latlng/round_test.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package latlng
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestRound(t *testing.T) {
|
||||
t.Run("Germany", func(t *testing.T) {
|
||||
assert.Equal(t, 48.5634483, Round(48.56344833333333))
|
||||
assert.Equal(t, 8.9968783, Round(8.996878333333333))
|
||||
})
|
||||
}
|
||||
|
||||
func TestRoundCoords(t *testing.T) {
|
||||
t.Run("Germany", func(t *testing.T) {
|
||||
lat, lng := RoundCoords(48.56344833333333, 8.996878333333333)
|
||||
assert.Equal(t, 48.5634483, lat)
|
||||
assert.Equal(t, 8.9968783, lng)
|
||||
})
|
||||
}
|
Reference in New Issue
Block a user