Skip to content

Commit 03d44b5

Browse files
draft: replaced old intersects logic
1 parent 44b143d commit 03d44b5

File tree

2 files changed

+5
-18
lines changed

2 files changed

+5
-18
lines changed

geojson/geojson_s2_util.go

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -142,18 +142,11 @@ func rectangleIntersectsWithLineStrings(s2rect *s2.Rect,
142142
polylines []*s2.Polyline) bool {
143143
for _, pl := range polylines {
144144
for i := 0; i < pl.NumEdges(); i++ {
145-
edgeA := pl.Edge(i)
146-
a := []float64{edgeA.V0.X, edgeA.V0.Y}
147-
b := []float64{edgeA.V1.X, edgeA.V1.Y}
148-
149145
for j := 0; j < 4; j++ {
150-
v1 := s2.PointFromLatLng(s2rect.Vertex(j))
151-
v2 := s2.PointFromLatLng(s2rect.Vertex((j + 1) % 4))
152-
153-
c := []float64{v1.X, v1.Y}
154-
d := []float64{v2.X, v2.Y}
146+
pgnLine := s2.PolylineFromLatLngs([]s2.LatLng{s2rect.Vertex(j),
147+
s2rect.Vertex((j + 1) % 4)})
155148

156-
if doIntersect(a, b, c, d) {
149+
if pl.Intersects(pgnLine) {
157150
return true
158151
}
159152
}

geojson/geojson_shapes_impl.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,17 +1145,11 @@ func checkLineStringsIntersectsShape(pls []*s2.Polyline, shapeIn,
11451145
if e, ok := other.(*Envelope); ok {
11461146
for _, pl := range pls {
11471147
for i := 0; i < pl.NumEdges(); i++ {
1148-
edge := pl.Edge(i)
1149-
latlng1 := s2.LatLngFromPoint(edge.V0)
1150-
latlng2 := s2.LatLngFromPoint(edge.V1)
1151-
a := []float64{latlng1.Lng.Degrees(), latlng1.Lat.Degrees()}
1152-
b := []float64{latlng2.Lng.Degrees(), latlng2.Lat.Degrees()}
11531148
for j := 0; j < 4; j++ {
11541149
v1 := e.r.Vertex(j)
11551150
v2 := e.r.Vertex((j + 1) % 4)
1156-
c := []float64{v1.Lng.Degrees(), v1.Lat.Degrees()}
1157-
d := []float64{v2.Lng.Degrees(), v2.Lat.Degrees()}
1158-
if doIntersect(a, b, c, d) {
1151+
pgnLine := s2.PolylineFromLatLngs([]s2.LatLng{v1, v2})
1152+
if pl.Intersects(pgnLine) {
11591153
return true, nil
11601154
}
11611155
}

0 commit comments

Comments
 (0)