|
4 | 4 | "testing" |
5 | 5 |
|
6 | 6 | r3 "github.com/golang/geo/r3" |
| 7 | + s2 "github.com/golang/geo/s2" |
7 | 8 | assert "github.com/stretchr/testify/assert" |
8 | 9 | ) |
9 | 10 |
|
@@ -37,3 +38,43 @@ func TestInfernoActive(t *testing.T) { |
37 | 38 |
|
38 | 39 | assert.Equal(t, activeFires, inf.Active().Fires, "Active inferno should contain active fires") |
39 | 40 | } |
| 41 | + |
| 42 | +func TestInfernoConvexHull2D(t *testing.T) { |
| 43 | + // Construct a Inferno that looks roughly like this. |
| 44 | + // D should be inside the 2D Convex Hull but a corner of the 3D Convex Hull |
| 45 | + // |
| 46 | + // C |
| 47 | + // / \ |
| 48 | + // / D \ |
| 49 | + // / \ |
| 50 | + // A - - - - - - - B |
| 51 | + // |
| 52 | + inf := Inferno{ |
| 53 | + Fires: []*Fire{ |
| 54 | + &Fire{ |
| 55 | + Vector: r3.Vector{X: 1, Y: 2, Z: 3}, |
| 56 | + }, |
| 57 | + &Fire{ |
| 58 | + Vector: r3.Vector{X: 4, Y: 7, Z: 6}, |
| 59 | + }, |
| 60 | + &Fire{ |
| 61 | + Vector: r3.Vector{X: 7, Y: 2, Z: 9}, |
| 62 | + }, |
| 63 | + &Fire{ |
| 64 | + Vector: r3.Vector{X: 4, Y: 4, Z: 12}, // This fire is inside the 2D hull |
| 65 | + }, |
| 66 | + }, |
| 67 | + } |
| 68 | + |
| 69 | + expectedHull := s2.LoopFromPoints([]s2.Point{ |
| 70 | + s2.Point{Vector: r3.Vector{X: 4, Y: 7, Z: 0}}, |
| 71 | + s2.Point{Vector: r3.Vector{X: 1, Y: 2, Z: 0}}, |
| 72 | + s2.Point{Vector: r3.Vector{X: 7, Y: 2, Z: 0}}, |
| 73 | + }) |
| 74 | + |
| 75 | + assert.ElementsMatch(t, expectedHull.Vertices(), inf.ConvexHull2D().Vertices(), "ConvexHull2D should be as expected") |
| 76 | + assert.True(t, inf.ConvexHull2D().BoundaryEqual(expectedHull), "Boundary of expected and actual should be equal") |
| 77 | + |
| 78 | + // 3D-hull should be different |
| 79 | + assert.NotEqual(t, expectedHull.NumVertices(), inf.ConvexHull3D().NumVertices(), "3D hull should contain the vertex 'D'") |
| 80 | +} |
0 commit comments