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

Function TestLoopTurningAngle

s2/loop_test.go:1514–1584  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1512}
1513
1514func TestLoopTurningAngle(t *testing.T) {
1515 tests := []struct {
1516 loop *Loop
1517 want float64
1518 }{
1519 {EmptyLoop(), 2 * math.Pi},
1520 {FullLoop(), -2 * math.Pi},
1521 {northHemi3, 0},
1522 {westHemi, 0},
1523 {candyCane, 4.69364376125922},
1524 {lineTriangle, 2 * math.Pi},
1525 {skinnyChevron, 2 * math.Pi},
1526 }
1527
1528 for _, test := range tests {
1529 if got := test.loop.TurningAngle(); !float64Near(got, test.want, epsilon) {
1530 t.Errorf("%v.TurningAngle() = %v, want %v", test.loop, got, test.want)
1531 }
1532
1533 // Check that the turning angle is *identical* when the vertex order is
1534 // rotated, and that the sign is inverted when the vertices are reversed.
1535 expected := test.loop.TurningAngle()
1536 loopCopy := cloneLoop(test.loop)
1537 for i := 0; i < len(test.loop.vertices); i++ {
1538 loopCopy.Invert()
1539 if got := loopCopy.TurningAngle(); got != -expected {
1540 t.Errorf("loop.Invert().TurningAngle() = %v, want %v", got, -expected)
1541 }
1542 // Invert it back to normal.
1543 loopCopy.Invert()
1544
1545 loopCopy = rotate(loopCopy)
1546 if got := loopCopy.TurningAngle(); got != expected {
1547 t.Errorf("loop.TurningAngle() = %v, want %v", got, expected)
1548 }
1549 }
1550 }
1551
1552 // Build a narrow spiral loop starting at the north pole. This is designed
1553 // to test that the error in TurningAngle is linear in the number of
1554 // vertices even when the partial sum of the turning angles gets very large.
1555 // The spiral consists of two arms defining opposite sides of the loop.
1556 const armPoints = 10000 // Number of vertices in each "arm"
1557 const armRadius = 0.01 // Radius of spiral.
1558 var vertices = make([]Point, 2*armPoints)
1559
1560 // Set the center point of the spiral.
1561 vertices[armPoints] = PointFromCoords(0, 0, 1)
1562
1563 for i := range armPoints {
1564 angle := (2 * math.Pi / 3) * float64(i)
1565 x := math.Cos(angle)
1566 y := math.Sin(angle)
1567 r1 := float64(i) * armRadius / armPoints
1568 r2 := (float64(i) + 1.5) * armRadius / armPoints
1569 vertices[armPoints-i-1] = PointFromCoords(r1*x, r1*y, 1)
1570 vertices[armPoints+i] = PointFromCoords(r2*x, r2*y, 1)
1571 }

Callers

nothing calls this directly

Calls 13

EmptyLoopFunction · 0.85
FullLoopFunction · 0.85
cloneLoopFunction · 0.85
rotateFunction · 0.85
PointFromCoordsFunction · 0.85
LoopFromPointsFunction · 0.85
TurningAngleMethod · 0.80
CosMethod · 0.80
SinMethod · 0.80
turningAngleMaxErrorMethod · 0.80
float64NearFunction · 0.70
InvertMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…