Skip to content

Commit dc86a58

Browse files
MB-70122: Use a better method to compute envelope intersects circle queries (#29)
- Switched from converting envelope to rectangle and then finding distance to directly finding the distance from the envelope - Theoretically should be faster than converting to a rectangle --------- Co-authored-by: Abhinav Dangeti <abhinav@couchbase.com>
1 parent b34bfe4 commit dc86a58

5 files changed

Lines changed: 15 additions & 12 deletions

File tree

.github/workflows/go.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
strategy:
2020
matrix:
2121
# Test on supported go compiler releases as well as the oldest version we support from go.mod.
22-
go: [ '1.21', 'oldstable', 'stable' ]
22+
go: [ '1.24', 'oldstable', 'stable' ]
2323
name: Go version ${{ matrix.go }}
2424
steps:
2525
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

.github/workflows/tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ jobs:
88
test:
99
strategy:
1010
matrix:
11-
go-version: [1.21.x, 1.22.x, 1.23.x]
11+
go-version: [1.23.x, 1.24.x, 1.25.x]
1212
platform: [ubuntu-latest, macos-latest, windows-latest]
1313
runs-on: ${{ matrix.platform }}
1414
steps:
1515
- name: Install Go
16-
uses: actions/setup-go@v1
16+
uses: actions/setup-go@v5
1717
with:
1818
go-version: ${{ matrix.go-version }}
1919
- name: Checkout code

geojson/geojson_shapes_impl.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1717,11 +1717,14 @@ func checkEnvelopeIntersectsShape(s2rect *s2.Rect, shapeIn,
17171717

17181718
// check if the other shape is a circle.
17191719
if c, ok := other.(*Circle); ok {
1720-
s2pgn := s2PolygonFromS2Rectangle(s2rect)
1721-
cp := c.s2cap.Center()
1722-
projected := s2pgn.Project(&cp)
1723-
distance := projected.Distance(cp)
1724-
return distance <= c.s2cap.Radius(), nil
1720+
// check if the distance of the center of the circle from the
1721+
// rectangle is less than the radius of the circle.
1722+
if s2rect.DistanceToLatLng(s2.LatLngFromPoint(c.s2cap.Center())) <=
1723+
c.s2cap.Radius() {
1724+
return true, nil
1725+
}
1726+
1727+
return false, nil
17251728
}
17261729

17271730
// check if the other shape is a envelope.

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ module github.com/blevesearch/geo
22

33
// This declares what language features we use and may be updated freely up to "oldstable".
44
// Update .github/workflows/go.yml when bumping this version.
5-
go 1.21.0
5+
go 1.24
66

77
require (
8-
github.com/blevesearch/bleve_index_api v1.2.8
8+
github.com/blevesearch/bleve_index_api v1.3.1
99
github.com/google/go-cmp v0.7.0
1010
github.com/json-iterator/go v0.0.0-20171115153421-f7279a603ede
1111
)

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
github.com/blevesearch/bleve_index_api v1.2.8 h1:Y98Pu5/MdlkRyLM0qDHostYo7i+Vv1cDNhqTeR4Sy6Y=
2-
github.com/blevesearch/bleve_index_api v1.2.8/go.mod h1:rKQDl4u51uwafZxFrPD1R7xFOwKnzZW7s/LSeK4lgo0=
1+
github.com/blevesearch/bleve_index_api v1.3.1 h1:LdH3CQgBbIZ5UI/5Pykz87e0jfeQtVnrdZ2WUBrHHwU=
2+
github.com/blevesearch/bleve_index_api v1.3.1/go.mod h1:xvd48t5XMeeioWQ5/jZvgLrV98flT2rdvEJ3l/ki4Ko=
33
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
44
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
55
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=

0 commit comments

Comments
 (0)