MCPcopy
hub / github.com/golang/geo / testCrossingEdgeQueryAllCrossings

Function testCrossingEdgeQueryAllCrossings

s2/crossing_edge_query_test.go:85–224  ·  view source on GitHub ↗
(t *testing.T, edges []Edge)

Source from the content-addressed store, hash-verified

83}
84
85func testCrossingEdgeQueryAllCrossings(t *testing.T, edges []Edge) {
86 s := &edgeVectorShape{}
87 for _, edge := range edges {
88 s.Add(edge.V0, edge.V1)
89 }
90
91 // Force more subdivision than usual to make the test more challenging.
92 index := NewShapeIndex()
93 index.maxEdgesPerCell = 1
94 index.Add(s)
95
96 // To check that candidates are being filtered reasonably, we count the
97 // total number of candidates that the total number of edge pairs that
98 // either intersect or are very close to intersecting.
99 var numCandidates, numNearbyPairs int
100
101 for _, edge := range edges {
102 a := edge.V0
103 b := edge.V1
104
105 query := NewCrossingEdgeQuery(index)
106 candidates := query.candidates(a, b, s)
107
108 // Verify that the EdgeMap version of candidates returns the same result.
109 edgeMap := query.candidatesEdgeMap(a, b)
110 if len(edgeMap) != 1 {
111 t.Errorf("there should be only one shape in this map, got %d", len(edgeMap))
112 // Skip the next part of the check since we expect only 1
113 // value, and you can't get just the first entry in a map.
114 continue
115 }
116 for k, v := range edgeMap {
117 if Shape(s) != k {
118 t.Errorf("element(%v) of edgeMap should be this shape", k)
119 }
120 if !reflect.DeepEqual(candidates, v) {
121 t.Errorf("edgeMap candidates for this shape = %v, want %v", v, candidates)
122 }
123 }
124 if len(candidates) == 0 {
125 t.Errorf("candidates should not be empty")
126 }
127
128 // Now check the actual candidates.
129 // Check the results are sorted
130 for k, v := range candidates {
131 if k < len(candidates)-1 {
132 if v > candidates[k+1] {
133 t.Errorf("candidates was not sorted. candidates[%d] = %v > candidates[%d] = %v", k, v, k+1, candidates[k+1])
134 }
135 }
136 }
137 if got := candidates[0]; got < 0 {
138 t.Errorf("the first element should not have a negative edge id")
139 }
140 if got, want := candidates[len(candidates)-1], s.NumEdges(); got >= want {
141 t.Errorf("candidates[%d] = %v, want < %v", len(candidates)-1, got, want)
142 }

Calls 15

AddMethod · 0.95
AddMethod · 0.95
candidatesMethod · 0.95
candidatesEdgeMapMethod · 0.95
NumEdgesMethod · 0.95
EdgeMethod · 0.95
CrossingsMethod · 0.95
CrossingsEdgeMapMethod · 0.95
NewShapeIndexFunction · 0.85
NewCrossingEdgeQueryFunction · 0.85
ShapeInterface · 0.85
CrossingSignFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…