separating-axis-test
Version:
test for the intersection of convex polytopes in 2d or 3d, computing the minimum translation vector
92 lines (90 loc) • 2.09 kB
JavaScript
var sat3d = require('../3d.js')
var test = require('tape')
test('mix axis-aligned boxes 3d', function (t) {
t.deepEqual(sat3d(
[],
{
separatingAxes: [0,0,1,0,1,0,1,0,0],
positions: [
[0,0,0],[0,1,0],[1,1,0],[1,0,0],
[0,0,1],[0,1,1],[1,1,1],[1,0,1]
]
},
{
separatingAxes: [[0,0,1],[0,1,0],[1,0,0]],
positions: [
-0.5,0.4,0,0.5,0.4,0,0.5,-0.6,0,-0.5,-0.6,0,
-0.5,0.4,1,0.5,0.4,1,0.5,-0.6,1,-0.5,-0.6,1
]
}
), [0,0.4,0])
t.deepEqual(sat3d(
[],
{
separatingAxes: [0,0,1,0,1,0,1,0,0],
positions: [
[0,0,0],[0,1,0],[1,1,0],[1,0,0],
[0,0,1],[0,1,1],[1,1,1],[1,0,1]
]
},
{
separatingAxes: [0,0,1,0,1,0,1,0,0],
positions: [
[-0.6,0.5,0],[0.4,0.5,0],[0.4,-0.5,0],[-0.6,-0.5,0],
[-0.6,0.5,1],[0.4,0.5,1],[0.4,-0.5,1],[-0.6,-0.5,1]
]
}
), [0.4,0,0])
t.deepEqual(sat3d(
[],
{
separatingAxes: [[0,0,1],[0,1,0],[1,0,0]],
positions: [
0,0,0,0,1,0,1,1,0,1,0,0,
0,0,1,0,1,1,1,1,1,1,0,1
]
},
{
separatingAxes: [[0,0,1],[0,1,0],[1,0,0]],
positions: [
-0.4,1.5,0,0.6,1.5,0,0.6,0.5,0,-0.4,0.5,0,
-0.4,1.5,1,0.6,1.5,1,0.6,0.5,1,-0.4,0.5,1
]
}
), [0,-0.5,0])
t.deepEqual(sat3d(
[],
{
separatingAxes: [0,0,1,0,1,0,1,0,0],
positions: [
0,0,0,0,1,0,1,1,0,1,0,0,
0,0,1,0,1,1,1,1,1,1,0,1
]
},
{
separatingAxes: [0,0,1,0,1,0,1,0,0],
positions: [
[-0.5,1.6,0],[0.5,1.6,0],[0.5,0.6,0],[-0.5,0.6,0],
[-0.5,1.6,1],[0.5,1.6,1],[0.5,0.6,1],[-0.5,0.6,1]
]
}
), [0,-0.4,0])
t.notOk(sat3d(
[],
{
separatingAxes: [0,0,1,0,1,0,1,0,0],
positions: [
0,1,0,1,1,0,1,0,0,0,0,0,
0,1,1,1,1,1,1,0,1,0,0,1
]
},
{
separatingAxes: [[0,0,1],[0,1,0],[1,0,0]],
positions: [
-0.5,-0.5,0,0.5,-0.5,0,0.5,-1.5,0,-0.5,-1.5,0,
-0.5,-0.5,1,0.5,-0.5,1,0.5,-1.5,1,-0.5,-1.5,1
]
}
))
t.end()
})