File tree Expand file tree Collapse file tree 5 files changed +11
-29
lines changed Expand file tree Collapse file tree 5 files changed +11
-29
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ package s2
17
17
import (
18
18
"fmt"
19
19
"io"
20
+ "slices"
20
21
"sort"
21
22
22
23
"github.com/golang/geo/s1"
@@ -404,13 +405,7 @@ func (cu *CellUnion) Contains(o CellUnion) bool {
404
405
405
406
// Intersects reports whether this CellUnion intersects any of the CellIDs of the given CellUnion.
406
407
func (cu * CellUnion ) Intersects (o CellUnion ) bool {
407
- for _ , c := range * cu {
408
- if o .IntersectsCellID (c ) {
409
- return true
410
- }
411
- }
412
-
413
- return false
408
+ return slices .ContainsFunc (* cu , o .IntersectsCellID )
414
409
}
415
410
416
411
// lowerBound returns the index in this CellUnion to the first element whose value
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ package s2
16
16
17
17
import (
18
18
"math"
19
+ "slices"
19
20
"testing"
20
21
21
22
"github.com/golang/geo/s1"
@@ -95,12 +96,7 @@ func TestConvexHullAntipodalPoints(t *testing.T) {
95
96
}
96
97
97
98
func loopHasVertex (l * Loop , p Point ) bool {
98
- for _ , v := range l .vertices {
99
- if v == p {
100
- return true
101
- }
102
- }
103
- return false
99
+ return slices .Contains (l .vertices , p )
104
100
}
105
101
106
102
func TestConvexHullQueryEmptyLoop (t * testing.T ) {
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ import (
18
18
"fmt"
19
19
"io"
20
20
"math"
21
+ "slices"
21
22
)
22
23
23
24
// Polygon represents a sequence of zero or more loops; recall that the
@@ -880,12 +881,7 @@ func (p *Polygon) Intersects(o *Polygon) bool {
880
881
}
881
882
882
883
if ! p .hasHoles && ! o .hasHoles {
883
- for _ , l := range o .loops {
884
- if p .anyLoopIntersects (l ) {
885
- return true
886
- }
887
- }
888
- return false
884
+ return slices .ContainsFunc (o .loops , p .anyLoopIntersects )
889
885
}
890
886
891
887
// Polygon A is disjoint from B if A excludes the entire boundary of B and B
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ import (
18
18
"fmt"
19
19
"io"
20
20
"math"
21
+ "slices"
21
22
22
23
"github.com/golang/geo/s1"
23
24
)
@@ -135,10 +136,8 @@ func (p *Polyline) IntersectsCell(cell Cell) bool {
135
136
// We only need to check whether the cell contains vertex 0 for correctness,
136
137
// but these tests are cheap compared to edge crossings so we might as well
137
138
// check all the vertices.
138
- for _ , v := range * p {
139
- if cell .ContainsPoint (v ) {
140
- return true
141
- }
139
+ if slices .ContainsFunc (* p , cell .ContainsPoint ) {
140
+ return true
142
141
}
143
142
144
143
cellVertices := []Point {
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ package s2
16
16
17
17
import (
18
18
"math"
19
+ "slices"
19
20
"sort"
20
21
"sync"
21
22
"sync/atomic"
@@ -100,12 +101,7 @@ func (c *clippedShape) numEdges() int {
100
101
func (c * clippedShape ) containsEdge (id int ) bool {
101
102
// Linear search is fast because the number of edges per shape is typically
102
103
// very small (less than 10).
103
- for _ , e := range c .edges {
104
- if e == id {
105
- return true
106
- }
107
- }
108
- return false
104
+ return slices .Contains (c .edges , id )
109
105
}
110
106
111
107
// ShapeIndexCell stores the index contents for a particular CellID.
You can’t perform that action at this time.
0 commit comments