Removed unnecessary statements

This commit is contained in:
Pablo Ariel Mayobre (Positive07) 2017-11-05 19:46:31 -03:00
parent 1bee6093e6
commit 93fa069474

25
gjk.lua
View File

@ -28,7 +28,7 @@ local _PACKAGE = (...):match("^(.+)%.[^%.]+")
local vector = require(_PACKAGE .. '.vector-light') local vector = require(_PACKAGE .. '.vector-light')
local huge, abs = math.huge, math.abs local huge, abs = math.huge, math.abs
local simplex = {} local simplex, edge = {}, {}
local function support(shape_a, shape_b, dx, dy) local function support(shape_a, shape_b, dx, dy)
local x,y = shape_a:support(dx,dy) local x,y = shape_a:support(dx,dy)
@ -36,7 +36,6 @@ local function support(shape_a, shape_b, dx, dy)
end end
-- returns closest edge to the origin -- returns closest edge to the origin
local edge = {}
local function closest_edge(n) local function closest_edge(n)
edge.dist = huge edge.dist = huge
@ -56,8 +55,6 @@ local function closest_edge(n)
edge.i = k edge.i = k
end end
end end
return edge
end end
local function EPA(shape_a, shape_b) local function EPA(shape_a, shape_b)
@ -72,22 +69,22 @@ local function EPA(shape_a, shape_b)
local is_either_circle = shape_a._center or shape_b._center local is_either_circle = shape_a._center or shape_b._center
local last_diff_dist, n = huge, 6 local last_diff_dist, n = huge, 6
while true do while true do
local e = closest_edge(n) closest_edge(n)
local px,py = support(shape_a, shape_b, e.nx, e.ny) local px,py = support(shape_a, shape_b, edge.nx, edge.ny)
local d = vector.dot(px,py, e.nx, e.ny) local d = vector.dot(px,py, edge.nx, edge.ny)
local diff_dist = d - e.dist local diff_dist = d - edge.dist
if diff_dist < 1e-6 or (is_either_circle and abs(last_diff_dist - diff_dist) < 1e-10) then if diff_dist < 1e-6 or (is_either_circle and abs(last_diff_dist - diff_dist) < 1e-10) then
return -d*e.nx, -d*e.ny return -d*edge.nx, -d*edge.ny
end end
last_diff_dist = diff_dist last_diff_dist = diff_dist
-- simplex = {..., simplex[e.i-1], px, py, simplex[e.i] -- simplex = {..., simplex[edge.i-1], px, py, simplex[edge.i]
for i = n, e.i, -1 do for i = n, edge.i, -1 do
simplex[i+2] = simplex[i] simplex[i+2] = simplex[i]
end end
simplex[e.i+0] = px simplex[edge.i+0] = px
simplex[e.i+1] = py simplex[edge.i+1] = py
n = n + 2 n = n + 2
end end
end end
@ -130,7 +127,6 @@ local function do_triangle()
-- simplex = {bx,by, ax,ay} -- simplex = {bx,by, ax,ay}
simplex[1], simplex[2] = bx,by simplex[1], simplex[2] = bx,by
simplex[3], simplex[4] = ax,ay simplex[3], simplex[4] = ax,ay
simplex[5], simplex[6] = nil, nil
return 4, dx,dy return 4, dx,dy
end end
@ -142,7 +138,6 @@ local function do_triangle()
if vector.dot(dx,dy, aox, aoy) > 0 then if vector.dot(dx,dy, aox, aoy) > 0 then
-- simplex = {cx,cy, ax,ay} -- simplex = {cx,cy, ax,ay}
simplex[3], simplex[4] = ax,ay simplex[3], simplex[4] = ax,ay
simplex[5], simplex[6] = nil, nil
return 4, dx,dy return 4, dx,dy
end end