-
-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(geom-isec): fix #269 update rayBox()
- fix Y/Z-axis handling - add tests
- Loading branch information
1 parent
1c0e284
commit 441cddb
Showing
2 changed files
with
74 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { eqDelta, maddN3, mulN3, normalize, Vec } from "@thi.ng/vectors"; | ||
import * as assert from "assert"; | ||
import { intersectRayAABB } from "../src"; | ||
|
||
describe("ray intersection", () => { | ||
it("rayBox inside", () => { | ||
const dirs: Vec[] = [ | ||
[-1, -1, -1], | ||
[-1, -1, 0], | ||
[-1, -1, 1], | ||
[-1, 0, -1], | ||
[-1, 0, 0], | ||
[-1, 0, 1], | ||
[-1, 1, -1], | ||
[-1, 1, 0], | ||
[-1, 1, 1], | ||
[0, -1, -1], | ||
[0, -1, 0], | ||
[0, -1, 1], | ||
[0, 0, -1], | ||
[0, 0, 1], | ||
[0, 1, -1], | ||
[0, 1, 0], | ||
[0, 1, 1], | ||
[1, -1, -1], | ||
[1, -1, 0], | ||
[1, -1, 1], | ||
[1, 0, -1], | ||
[1, 0, 0], | ||
[1, 0, 1], | ||
[1, 1, -1], | ||
[1, 1, 0], | ||
[1, 1, 1], | ||
]; | ||
for (let d of dirs) { | ||
const n = normalize([], d); | ||
const i = intersectRayAABB([5, 5, 5], n, [0, 0, 0], [10, 10, 10]); | ||
const expected = maddN3([], n, i.alpha!, [5, 5, 5]); | ||
assert(i.inside, `inside d=${d}`); | ||
assert( | ||
eqDelta(expected, <Vec>i.isec![0]), | ||
`d=${d} isec=${i.isec}, exp=${expected}` | ||
); | ||
} | ||
}); | ||
|
||
it("rayBox outside", () => { | ||
const dirs: Vec[] = [ | ||
[1, 0, 0], | ||
[0, 1, 0], | ||
[0, 0, 1], | ||
]; | ||
for (let d of dirs) { | ||
let o = mulN3([], d, -10); | ||
let i = intersectRayAABB(o, d, [-5, -5, -5], [5, 5, 5]); | ||
let expected = maddN3([], d, i.alpha!, o); | ||
assert( | ||
eqDelta(expected, <Vec>i.isec![0]), | ||
`d=${d} isec=${i.isec}, exp=${expected}` | ||
); | ||
d = mulN3(d, d, -1); | ||
o = mulN3([], d, -10); | ||
i = intersectRayAABB(o, d, [-5, -5, -5], [5, 5, 5]); | ||
expected = maddN3([], d, i.alpha!, o); | ||
assert( | ||
eqDelta(expected, <Vec>i.isec![0]), | ||
`d=${d} isec=${i.isec}, exp=${expected}` | ||
); | ||
} | ||
}); | ||
}); |