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

Function TestContainsPointQueryContainingShapes

s2/contains_point_query_test.go:139–175  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

137}
138
139func TestContainsPointQueryContainingShapes(t *testing.T) {
140 const numVerticesPerLoop = 10
141 maxLoopRadius := kmToAngle(10)
142 centerCap := CapFromCenterAngle(randomPoint(), maxLoopRadius)
143 index := NewShapeIndex()
144
145 for range 100 {
146 index.Add(RegularLoop(samplePointFromCap(centerCap), s1.Angle(randomFloat64())*maxLoopRadius, numVerticesPerLoop))
147 }
148
149 query := NewContainsPointQuery(index, VertexModelSemiOpen)
150
151 for i := range 100 {
152 p := samplePointFromCap(centerCap)
153 var want []Shape
154
155 for j := int32(0); j < int32(len(index.shapes)); j++ {
156 shape := index.Shape(j)
157 // All the shapes we added were of type loop.
158 loop := shape.(*Loop)
159 if loop.ContainsPoint(p) {
160 if !query.ShapeContains(shape, p) {
161 t.Errorf("index.Shape(%d).ContainsPoint(%v) = true, but query.ShapeContains(%v) = false", j, p, p)
162 }
163 want = append(want, shape)
164 } else {
165 if query.ShapeContains(shape, p) {
166 t.Errorf("query.ShapeContains(shape, %v) = true, but the original loop does not contain the point.", p)
167 }
168 }
169 }
170 got := query.ContainingShapes(p)
171 if !reflect.DeepEqual(got, want) {
172 t.Errorf("%d query.ContainingShapes(%v) = %+v, want %+v", i, p, got, want)
173 }
174 }
175}
176
177// TODO(roberts): Remaining tests
178// TestContainsPointQueryVisitIncidentEdges

Callers

nothing calls this directly

Calls 14

AddMethod · 0.95
ShapeMethod · 0.95
ShapeContainsMethod · 0.95
ContainingShapesMethod · 0.95
AngleTypeAlias · 0.92
kmToAngleFunction · 0.85
CapFromCenterAngleFunction · 0.85
randomPointFunction · 0.85
NewShapeIndexFunction · 0.85
RegularLoopFunction · 0.85
samplePointFromCapFunction · 0.85
randomFloat64Function · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…