Fix failing tests; this involves changing 2 bad tests and 1 bad behavior:

- vec2 to_polar/from_cartesian tests were testing for equality rather than using an epsilon.
- bound2.contains had two tests that were plain wrong.
- While I'm fixing the bounds test, bound2.contains and bound3.contains probably ought to test their own min and max values for inclusion.
- The implementation of mat4.look_at appears to be wrong. The final column was being set to 0,0,0,1 which comparing against other implementations does not seem to be correct. My replacement code is modeled on the method used in mat4x4_look_at() in linmath.h in GLFW, which says it's a reimplementation on the method from gluLookAt(). With this change the test passes as originally written.
This commit is contained in:
mcc 2019-11-29 17:16:20 -05:00
parent 6c49915112
commit 7fa1785469
4 changed files with 10 additions and 8 deletions

View File

@ -542,10 +542,10 @@ function mat4.look_at(out, a, eye, look_at, up)
out[10] = y_axis.z
out[11] = z_axis.z
out[12] = 0
out[13] = 0
out[14] = 0
out[15] = 0
out[16] = 1
out[13] = -out[ 1]*eye.x - out[4+1]*eye.y - out[8+1]*eye.z
out[14] = -out[ 2]*eye.x - out[4+2]*eye.y - out[8+2]*eye.z
out[15] = -out[ 3]*eye.x - out[4+3]*eye.y - out[8+3]*eye.z
out[16] = -out[ 4]*eye.x - out[4+4]*eye.y - out[8+4]*eye.z + 1
return out
end

View File

@ -162,13 +162,13 @@ describe("bound2:", function()
it("tests for points inside bound2", function()
local a = bound2(vec2(1,2), vec2(4,5))
assert.is_true(a:contains(vec2(1,2)))
assert.is_true(a:contains(vec2(4,5)))
assert.is_true(a:contains(vec2(2,3)))
assert.is_not_true(a:contains(vec2(0,3)))
assert.is_not_true(a:contains(vec2(5,3)))
assert.is_not_true(a:contains(vec2(2,1)))
assert.is_not_true(a:contains(vec2(2,6)))
assert.is_not_true(a:contains(vec2(2,3)))
assert.is_not_true(a:contains(vec2(2,3)))
end)
it("checks for bound2.zero", function()

View File

@ -199,6 +199,8 @@ describe("bound3:", function()
it("tests for points inside bound3", function()
local a = bound3(vec3(1,2,3), vec3(4,5,6))
assert.is_true(a:contains(vec3(1,2,3)))
assert.is_true(a:contains(vec3(4,5,6)))
assert.is_true(a:contains(vec3(2,3,4)))
assert.is_not_true(a:contains(vec3(0,3,4)))
assert.is_not_true(a:contains(vec3(5,3,4)))

View File

@ -166,8 +166,8 @@ describe("vec2:", function()
local a = vec2(3, 5)
local r, t = a:to_polar()
local b = vec2.from_cartesian(r, t)
assert.is.equal(a.x, b.x)
assert.is.equal(a.y, b.y)
assert.is_true(abs(a.x - b.x) <= DBL_EPSILON*2) -- Allow 2X epsilon error because there were 2 operations.
assert.is_true(abs(a.y - b.y) <= DBL_EPSILON*2)
end)
it("gets a perpendicular vector", function()