(t *testing.T)
| 513 | } |
| 514 | |
| 515 | func TestCapIntersectsCell(t *testing.T) { |
| 516 | faceRadius := math.Atan(math.Sqrt2) |
| 517 | for face := range 6 { |
| 518 | // The cell consisting of the entire face. |
| 519 | rootCell := CellFromCellID(CellIDFromFace(face)) |
| 520 | |
| 521 | // A leaf cell at the midpoint of the v=1 edge. |
| 522 | edgeCell := CellFromPoint(Point{faceUVToXYZ(face, 0, 1-epsilon)}) |
| 523 | |
| 524 | // A leaf cell at the u=1, v=1 corner |
| 525 | cornerCell := CellFromPoint(Point{faceUVToXYZ(face, 1-epsilon, 1-epsilon)}) |
| 526 | |
| 527 | // Quick check for full and empty caps. |
| 528 | if emptyCap.IntersectsCell(rootCell) { |
| 529 | t.Errorf("Cap(%v).IntersectsCell(%v) = %t; want = %t", emptyCap, rootCell, true, false) |
| 530 | } |
| 531 | |
| 532 | // Check intersections with the bounding caps of the leaf cells that are adjacent to |
| 533 | // cornerCell along the Hilbert curve. Because this corner is at (u=1,v=1), the curve |
| 534 | // stays locally within the same cube face. |
| 535 | first := cornerCell.id.Advance(-3) |
| 536 | last := cornerCell.id.Advance(4) |
| 537 | for id := first; id < last; id = id.Next() { |
| 538 | c := CellFromCellID(id).CapBound() |
| 539 | if got, want := c.IntersectsCell(cornerCell), id.immediateParent().Contains(cornerCell.id); got != want { |
| 540 | t.Errorf("Cap(%v).IntersectsCell(%v) = %t; want = %t", c, cornerCell, got, want) |
| 541 | } |
| 542 | } |
| 543 | |
| 544 | antiFace := (face + 3) % 6 |
| 545 | for capFace := range 6 { |
| 546 | // A cap that barely contains all of capFace. |
| 547 | center := unitNorm(capFace) |
| 548 | covering := CapFromCenterAngle(center, s1.Angle(faceRadius+epsilon)) |
| 549 | if got, want := covering.IntersectsCell(rootCell), capFace != antiFace; got != want { |
| 550 | t.Errorf("Cap(%v).IntersectsCell(%v) = %t; want = %t", covering, rootCell, got, want) |
| 551 | } |
| 552 | if got, want := covering.IntersectsCell(edgeCell), covering.ContainsCell(edgeCell); got != want { |
| 553 | t.Errorf("Cap(%v).IntersectsCell(%v) = %t; want = %t", covering, edgeCell, got, want) |
| 554 | } |
| 555 | if got, want := covering.IntersectsCell(cornerCell), center.Dot(cornerCell.id.Point().Vector) > 0; got != want { |
| 556 | t.Errorf("Cap(%v).IntersectsCell(%v) = %t; want = %t", covering, cornerCell, got, want) |
| 557 | } |
| 558 | |
| 559 | // A cap that barely intersects the edges of capFace. |
| 560 | bulging := CapFromCenterAngle(center, s1.Angle(math.Pi/4+epsilon)) |
| 561 | if got, want := bulging.IntersectsCell(rootCell), capFace != antiFace; got != want { |
| 562 | t.Errorf("Cap(%v).IntersectsCell(%v) = %t; want = %t", bulging, rootCell, got, want) |
| 563 | } |
| 564 | if got, want := bulging.IntersectsCell(edgeCell), center.Dot(edgeCell.id.Point().Vector) > 0.1; got != want { |
| 565 | t.Errorf("Cap(%v).IntersectsCell(%v) = %t; want = %t", bulging, edgeCell, got, want) |
| 566 | } |
| 567 | if bulging.IntersectsCell(cornerCell) { |
| 568 | t.Errorf("Cap(%v).IntersectsCell(%v) = %t; want = %t", bulging, cornerCell, true, false) |
| 569 | } |
| 570 | |
| 571 | // A singleton cap. |
| 572 | singleton := CapFromCenterAngle(center, 0) |
nothing calls this directly
no test coverage detected
searching dependent graphs…