-
Notifications
You must be signed in to change notification settings - Fork 179
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
returned cap from CapBound for Polyline is too big #38
Comments
/cc @rsned |
While truing to write small reproducer, i discover that when i use built-in CapBound, there is zero point, erroneously inserted at start of polyline , and that is reason for huge cap differences. |
Here is benchmark, proposed change is faster!(i don't expect such difference):
package main
import (
"math/rand"
"testing"
"github.com/golang/geo/s2"
)
///////////////////////////////////atoi
const N = 200
var polyline s2.Polyline
func init() {
const s = 100000
for i := 0; i < N; i++ {
t := float64(rand.Int63n(90*s)) / s
g := float64(rand.Int63n(180*s)) / s
polyline = append(polyline, s2.PointFromLatLng(s2.LatLngFromDegrees(t, g)))
}
}
func BenchmarkCap1(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = polyline.CapBound()
}
}
func BenchmarkCap2(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = CapBound(polyline)
}
}
func CapBound(p s2.Polyline) s2.Cap {
c := s2.EmptyCap()
for _, v := range p {
c.AddPoint(v)
}
return c
} |
The C++ code uses code like S2Cap S2Polyline::GetCapBound() const {
return GetRectBound().GetCapBound();
} It is unlikely we will diverge from C++ algorithmically. But note that I believe your code may be incorrect for large polylines. If an edge of the polyline is long enough, adding its endpoints to a cap progressively may end up with a cap that doesn't include the line in its entirety. |
Hi,
i have case that performance using CapBound is in times slower compared to suggested replacement.
geo/s2/polyline.go
Line 91 in fb250ae
Please change from
to
The text was updated successfully, but these errors were encountered: