@@ -256,9 +256,10 @@ func NewGeoJsonLinestring(points [][]float64) index.GeoJSON {
256
256
257
257
func (ls * LineString ) init () {
258
258
if ls .pl == nil {
259
- latlngs := make ([]s2.LatLng , 2 )
260
- latlngs [0 ] = s2 .LatLngFromDegrees (ls .Vertices [0 ][1 ], ls .Vertices [0 ][0 ])
261
- latlngs [1 ] = s2 .LatLngFromDegrees (ls .Vertices [1 ][1 ], ls .Vertices [1 ][0 ])
259
+ latlngs := make ([]s2.LatLng , len (ls .Vertices ))
260
+ for i , vertex := range ls .Vertices {
261
+ latlngs [i ] = s2 .LatLngFromDegrees (vertex [1 ], vertex [0 ])
262
+ }
262
263
ls .pl = s2 .PolylineFromLatLngs (latlngs )
263
264
}
264
265
}
@@ -1088,9 +1089,11 @@ func checkLineStringsIntersectsShape(pls []*s2.Polyline, shapeIn,
1088
1089
if c , ok := other .(* Circle ); ok {
1089
1090
centre := c .s2cap .Center ()
1090
1091
for _ , pl := range pls {
1091
- edge := pl .Edge (0 )
1092
- distance := s2 .DistanceFromSegment (centre , edge .V0 , edge .V1 )
1093
- return distance <= c .s2cap .Radius (), nil
1092
+ for i := 0 ; i < pl .NumEdges (); i ++ {
1093
+ edge := pl .Edge (i )
1094
+ distance := s2 .DistanceFromSegment (centre , edge .V0 , edge .V1 )
1095
+ return distance <= c .s2cap .Radius (), nil
1096
+ }
1094
1097
}
1095
1098
1096
1099
return false , nil
@@ -1099,18 +1102,20 @@ func checkLineStringsIntersectsShape(pls []*s2.Polyline, shapeIn,
1099
1102
// check if the other shape is a envelope.
1100
1103
if e , ok := other .(* Envelope ); ok {
1101
1104
for _ , pl := range pls {
1102
- edge := pl .Edge (0 )
1103
- latlng1 := s2 .LatLngFromPoint (edge .V0 )
1104
- latlng2 := s2 .LatLngFromPoint (edge .V1 )
1105
- a := []float64 {latlng1 .Lng .Degrees (), latlng1 .Lat .Degrees ()}
1106
- b := []float64 {latlng2 .Lng .Degrees (), latlng2 .Lat .Degrees ()}
1107
- for j := 0 ; j < 4 ; j ++ {
1108
- v1 := e .r .Vertex (j )
1109
- v2 := e .r .Vertex ((j + 1 ) % 4 )
1110
- c := []float64 {v1 .Lng .Degrees (), v1 .Lat .Degrees ()}
1111
- d := []float64 {v2 .Lng .Degrees (), v2 .Lat .Degrees ()}
1112
- if doIntersect (a , b , c , d ) {
1113
- return true , nil
1105
+ for i := 0 ; i < pl .NumEdges (); i ++ {
1106
+ edge := pl .Edge (i )
1107
+ latlng1 := s2 .LatLngFromPoint (edge .V0 )
1108
+ latlng2 := s2 .LatLngFromPoint (edge .V1 )
1109
+ a := []float64 {latlng1 .Lng .Degrees (), latlng1 .Lat .Degrees ()}
1110
+ b := []float64 {latlng2 .Lng .Degrees (), latlng2 .Lat .Degrees ()}
1111
+ for j := 0 ; j < 4 ; j ++ {
1112
+ v1 := e .r .Vertex (j )
1113
+ v2 := e .r .Vertex ((j + 1 ) % 4 )
1114
+ c := []float64 {v1 .Lng .Degrees (), v1 .Lat .Degrees ()}
1115
+ d := []float64 {v2 .Lng .Degrees (), v2 .Lat .Degrees ()}
1116
+ if doIntersect (a , b , c , d ) {
1117
+ return true , nil
1118
+ }
1114
1119
}
1115
1120
}
1116
1121
}
0 commit comments