2018-08-17 03:37:19 +00:00
|
|
|
package render_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strconv"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"git.kirsle.net/apps/doodle/render"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestPointInside(t *testing.T) {
|
|
|
|
type testCase struct {
|
|
|
|
rect render.Rect
|
2018-10-19 20:31:58 +00:00
|
|
|
p render.Point
|
2018-08-17 03:37:19 +00:00
|
|
|
shouldPass bool
|
|
|
|
}
|
|
|
|
tests := []testCase{
|
|
|
|
testCase{
|
|
|
|
rect: render.Rect{
|
|
|
|
X: 0,
|
|
|
|
Y: 0,
|
|
|
|
W: 500,
|
|
|
|
H: 500,
|
|
|
|
},
|
2018-10-19 20:31:58 +00:00
|
|
|
p: render.NewPoint(128, 256),
|
2018-08-17 03:37:19 +00:00
|
|
|
shouldPass: true,
|
|
|
|
},
|
|
|
|
testCase{
|
|
|
|
rect: render.Rect{
|
|
|
|
X: 100,
|
|
|
|
Y: 80,
|
|
|
|
W: 40,
|
|
|
|
H: 60,
|
|
|
|
},
|
2018-10-19 20:31:58 +00:00
|
|
|
p: render.NewPoint(128, 256),
|
2018-08-17 03:37:19 +00:00
|
|
|
shouldPass: false,
|
|
|
|
},
|
2018-10-19 20:31:58 +00:00
|
|
|
testCase{
|
|
|
|
// true values when debugging why Doodads weren't
|
|
|
|
// considered inside the viewport.
|
|
|
|
rect: render.Rect{
|
|
|
|
X: 0,
|
|
|
|
Y: -232,
|
|
|
|
H: 874,
|
|
|
|
W: 490,
|
|
|
|
},
|
|
|
|
p: render.NewPoint(509, 260),
|
2019-04-05 20:16:33 +00:00
|
|
|
shouldPass: false,
|
2018-10-19 20:31:58 +00:00
|
|
|
},
|
2018-08-17 03:37:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range tests {
|
2018-10-19 20:31:58 +00:00
|
|
|
if test.p.Inside(test.rect) != test.shouldPass {
|
|
|
|
t.Errorf("Failed: %s inside %s should be %s",
|
|
|
|
test.p,
|
2018-08-17 03:37:19 +00:00
|
|
|
test.rect,
|
|
|
|
strconv.FormatBool(test.shouldPass),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|