Skip to content

Commit 7625fa0

Browse files
committed
common: Use Z=0 for Inferno.ConvexHull2D()
+ Test
1 parent 7aad279 commit 7625fa0

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

common/inferno.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func (inf Inferno) ConvexHull2D() *s2.Loop {
6060
Vector: r3.Vector{
6161
X: f.Vector.X,
6262
Y: f.Vector.Y,
63-
Z: 1,
63+
Z: 0,
6464
},
6565
})
6666
}

common/inferno_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"testing"
55

66
r3 "github.com/golang/geo/r3"
7+
s2 "github.com/golang/geo/s2"
78
assert "github.com/stretchr/testify/assert"
89
)
910

@@ -37,3 +38,43 @@ func TestInfernoActive(t *testing.T) {
3738

3839
assert.Equal(t, activeFires, inf.Active().Fires, "Active inferno should contain active fires")
3940
}
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

Comments
 (0)