Add AABB-AABB intersection test
asalga opened this issue · 4 comments
Add an AABB-AABB intersection test. Does anyone have a preference of how to return values, since there are 4 cases?
A is inside B
B is inside A
A and B intersect
A and B are disjoint
Might be best to break this up into separate functions, I can imagine cases where you'd only care to check intersect or engulf plus testing both A inside B vs. B inside A might be irrelevant in cases such as BSP/Octree.
If you want to make an additional function that can test all possibilities of A vs. B it would be ideal to extend base.enums and add a list of entries under something like base.enums.aabb.DISJOINT=0, base.enums.aabb.INTERSECT=1, base.enums.aabb.INSIDE=2, base.enums.ENGULF=3 (just quick suggestions, there's probably better names for those)
example of enumerator usage can be found in several classes such as: https://github.com/cjcliffe/CubicVR.js/blob/master/source/CubicVR.Light.js#L11 just add an import for 'enums' to the math lib.
I just read this. Hold off review until I change the code.
no problem, just add the commits to the existing pull request when ready
Now available as CubicVR.aabb.intersects(boxA, boxB), added enums and optimized the intersect testing order a bit moving the broader axis ones to be first.
comments updated to reflect the new enums:
/**
Returns positive integer if intersect between A and B, 0 otherwise.
For more detailed intersect result check value:
CubicVR.enums.aabb.INTERSECT if AABBs intersect
CubicVR.enums.aabb.A_INSIDE_B if boxA is inside boxB
CubicVR.enums.aabb.B_INSIDE_A if boxB is inside boxA
CubicVR.enums.aabb.DISJOINT if AABBs are disjoint (do not intersect)
*/