I'm stumped as to how the heck I can accomplish this feat.
What I'm trying to do is find a way to text one table against another.
(this is so I can see if one image contains another one, wholly or in part; all data is made into table[y][x] as per the Pixel Perfect Collision Library)
The fastest way of how to test for intersections is to create a new table with the values as key and the keys as values and then test the second table against it.
Something like this (untested):
function intersection(table1, table2)
local values = {}
for y, xtable in pairs(table1) do -- use ipairs when tables are arrays
for x,v in pairs(xtable) do
values[v] = {x,y}
end
end
local matches = {}
for y, xtable in pairs(table2) do
for x,v in pairs(xtable) do
if values[v] then
matches[#matches+1] = {t1 = values[v], t2 = {x,y}, value = v}
end
end
end
return matches
end
This will give you the intersection points and values of table1 and table2 using very few comparisons.
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.