completed coverage for rect intersect
This commit is contained in:
parent
b221034c8d
commit
ab6673d712
@ -227,19 +227,7 @@ func TestRectIntersect(t *testing.T) {
|
||||
v Vector2d
|
||||
expected result
|
||||
}{
|
||||
{
|
||||
rect: AABB2d{
|
||||
A: Point2d{5, 5},
|
||||
B: Point2d{15, 15},
|
||||
},
|
||||
p: Point2d{10, 0},
|
||||
v: Vector2d{0, 10},
|
||||
expected: result{
|
||||
collided: true,
|
||||
inside: false,
|
||||
pos: Point2d{10, 5},
|
||||
},
|
||||
},
|
||||
// inside
|
||||
{
|
||||
rect: AABB2d{
|
||||
A: Point2d{0, 0},
|
||||
@ -253,6 +241,76 @@ func TestRectIntersect(t *testing.T) {
|
||||
pos: Point2d{1, 1},
|
||||
},
|
||||
},
|
||||
// bottom
|
||||
{
|
||||
rect: AABB2d{
|
||||
A: Point2d{5, 5},
|
||||
B: Point2d{15, 15},
|
||||
},
|
||||
p: Point2d{10, 0},
|
||||
v: Vector2d{0, 10},
|
||||
expected: result{
|
||||
collided: true,
|
||||
inside: false,
|
||||
pos: Point2d{10, 5},
|
||||
},
|
||||
},
|
||||
// wall left
|
||||
{
|
||||
rect: AABB2d{
|
||||
A: Point2d{0, 0},
|
||||
B: Point2d{10, 10},
|
||||
},
|
||||
p: Point2d{-1, 5},
|
||||
v: Vector2d{2, 0},
|
||||
expected: result{
|
||||
collided: true,
|
||||
inside: false,
|
||||
pos: Point2d{0, 5},
|
||||
},
|
||||
},
|
||||
// wall right
|
||||
{
|
||||
rect: AABB2d{
|
||||
A: Point2d{0, 0},
|
||||
B: Point2d{10, 10},
|
||||
},
|
||||
p: Point2d{11, 5},
|
||||
v: Vector2d{-2, 0},
|
||||
expected: result{
|
||||
collided: true,
|
||||
inside: false,
|
||||
pos: Point2d{10, 5},
|
||||
},
|
||||
},
|
||||
// wall top
|
||||
{
|
||||
rect: AABB2d{
|
||||
A: Point2d{0, 0},
|
||||
B: Point2d{10, 10},
|
||||
},
|
||||
p: Point2d{5, 11},
|
||||
v: Vector2d{0, -2},
|
||||
expected: result{
|
||||
collided: true,
|
||||
inside: false,
|
||||
pos: Point2d{5, 10},
|
||||
},
|
||||
},
|
||||
// outside
|
||||
{
|
||||
rect: AABB2d{
|
||||
A: Point2d{0, 0},
|
||||
B: Point2d{10, 10},
|
||||
},
|
||||
p: Point2d{5, -1},
|
||||
v: Vector2d{0, -1},
|
||||
expected: result{
|
||||
collided: false,
|
||||
inside: false,
|
||||
pos: Point2d{5, -1},
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
coll, inside, pos := RectIntersection(test.rect, test.p, test.v)
|
||||
@ -261,9 +319,10 @@ func TestRectIntersect(t *testing.T) {
|
||||
}
|
||||
if inside != test.expected.inside {
|
||||
t.Errorf("RectIntersection Error")
|
||||
t.Errorf("unexpected inside: expected: %t, actual: %t", test.expected.inside, inside)
|
||||
}
|
||||
if pos != test.expected.pos {
|
||||
t.Errorf("RectIntersection Error")
|
||||
t.Errorf("unexpected collision point: expected: %+v, actual: %+v", test.expected.pos, pos)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user