mirror of
https://github.com/pocketbase/pocketbase.git
synced 2026-10-18 12:08:14 +02:00
clamped arccosine to [-1,1] to prevent rounding errors in geoDistance
This commit is contained in:
1 parent
dbea21f1b2
commit
df4e6eeb35
4 files changed
+63
-28
No files matched your search
@@ -49,11 +49,14 @@ var TokenFunctions = map[string]func(
|
||||
|
||||
return &ResolverResult{
|
||||
NullFallback: NullFallbackDisabled,
|
||||
Identifier: `(6371 * acos(` +
|
||||
// the clamping is to prevent floating point rounding errors for values like
|
||||
// "1.0002" that could occur for example when comparing identical points
|
||||
// (see the NULL note for arccosine in https://sqlite.org/lang_mathfunc.html#overview)
|
||||
Identifier: `(6371 * acos(min(1, max(-1, ` +
|
||||
`cos(radians(` + latA + `)) * cos(radians(` + latB + `)) * ` +
|
||||
`cos(radians(` + lonB + `) - radians(` + lonA + `)) + ` +
|
||||
`sin(radians(` + latA + `)) * sin(radians(` + latB + `))` +
|
||||
`))`,
|
||||
`))))`,
|
||||
Params: mergeParams(resolvedArgs[0].Params, resolvedArgs[1].Params, resolvedArgs[2].Params, resolvedArgs[3].Params),
|
||||
}, nil
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user