AABB and Sphere Bounds with new BVH tree implement with go 1.18 generic

This commit is contained in:
Tnze
2022-03-18 11:10:55 +08:00
parent ed742efb97
commit 00de623cc2
7 changed files with 513 additions and 263 deletions

View File

@ -0,0 +1,38 @@
package bvh
import "testing"
func TestAABB_WithIn(t *testing.T) {
aabb := AABB[float64, Vec2[float64]]{
Upper: Vec2[float64]{2, 2},
Lower: Vec2[float64]{-1, -1},
}
if !aabb.WithIn(Vec2[float64]{0, 0}) {
panic("(0, 0) should included")
}
if aabb.WithIn(Vec2[float64]{-2, -2}) {
panic("(-2, -2) shouldn't included")
}
aabb2 := AABB[int, Vec3[int]]{
Upper: Vec3[int]{1, 1, 1},
Lower: Vec3[int]{-1, -1, -1},
}
if !aabb2.WithIn(Vec3[int]{0, 0, 0}) {
panic("(0, 0, 0) should included")
}
if aabb2.WithIn(Vec3[int]{-2, -2, 0}) {
panic("(-2, -2, 0) shouldn't included")
}
sphere := Sphere[float64, Vec2[float64]]{
Center: Vec2[float64]{0, 0},
R: 1.0,
}
if !sphere.WithIn(Vec2[float64]{0, 0}) {
t.Errorf("(0,0) is in")
}
if sphere.WithIn(Vec2[float64]{1, 1}) {
t.Errorf("(1,1) isn't in")
}
}