@@ -256,9 +256,10 @@ func NewGeoJsonLinestring(points [][]float64) index.GeoJSON {
256256
257257func (ls * LineString ) init () {
258258 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+ }
262263 ls .pl = s2 .PolylineFromLatLngs (latlngs )
263264 }
264265}
@@ -1088,9 +1089,11 @@ func checkLineStringsIntersectsShape(pls []*s2.Polyline, shapeIn,
10881089 if c , ok := other .(* Circle ); ok {
10891090 centre := c .s2cap .Center ()
10901091 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+ }
10941097 }
10951098
10961099 return false , nil
@@ -1099,18 +1102,20 @@ func checkLineStringsIntersectsShape(pls []*s2.Polyline, shapeIn,
10991102 // check if the other shape is a envelope.
11001103 if e , ok := other .(* Envelope ); ok {
11011104 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+ }
11141119 }
11151120 }
11161121 }
0 commit comments