-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
geo/geogfn: implement ST_Azimuth({geometry,geometry}) #50188
Conversation
Thank you for contributing to CockroachDB. Please ensure you have followed the guidelines for creating a PR. My owl senses detect your PR is good for review. Please keep an eye out for any test failures in CI. I have added a few people who may be able to assist in reviewing: 🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan. |
f56dc8e
to
f5c0cce
Compare
Thank you for updating your pull request. My owl senses detect your PR is good for review. Please keep an eye out for any test failures in CI. 🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
quick comment request :)
pkg/geo/geomfn/azimuth_test.go
Outdated
zero = 0.0 | ||
aQuarterPi = 0.7853981633974483 | ||
towQuartersPi = 1.5707963267948966 | ||
threeQuartersPi = 2.356194490192344 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you mind moving these vars into the TestAzimuth
function? (unless we're planning to re-use them)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
pkg/geo/geomfn/azimuth.go
Outdated
return nil | ||
} | ||
|
||
azimuth := math.Mod(2*math.Pi+math.Pi/2-math.Atan2(b.Y()-a.Y(), b.X()-a.X()), 2*math.Pi) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you mind adding a comment of why we're adding 2*math.Pi, i.e. we always want a positive number?
some commentary on that math would also be nice :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
pkg/geo/geomfn/azimuth.go
Outdated
// Azimuth returns the azimuth in radians of the segment defined by the given point geometries. | ||
// The azimuth is angle is referenced from north, and is positive clockwise. | ||
// North = 0; East = π/2; South = π; West = 3π/2. | ||
func Azimuth(a *geom.Point, b *geom.Point) *float64 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually, do you mind moving the logic in geo_builtins such that Azimuth only takes in (a *geo.Geometry, b *geo.Geometry)
, to be consistent with the rest of the function signatures in here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
f5c0cce
to
e5429ec
Compare
Thank you for the review! |
Fixes cockroachdb#48887 Release note (sql change): This PR implement adds the `ST_Azimuth({geometry,geometry})` builtin.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for your contribution!
bors r+ |
Build failed (retrying...) |
Build failed (retrying...) |
Build succeeded |
Fixes #48887
Release note (sql change): This PR implement adds the ST_Azimuth({geometry,geometry})