Find entities in two adjacent areas without overcounting
Posted: Tue Jun 09, 2020 6:15 pm
If I have areas A and B which are rectangles directly next to each other (but of different sizes), and I want to find the entities that exist in the union of the two regions, I could try calling .find_entities(A) and .find_entities(B) and adding the resulting tables together.
Large objects can straddle the divide, however, and appear in both lists, so they would be double-counted. I don't know how to compare if two entity objects are equal, though, in order to remove duplicates. The following code doesn't work:
because we just get back joint_list again.
Any suggestions?
Large objects can straddle the divide, however, and appear in both lists, so they would be double-counted. I don't know how to compare if two entity objects are equal, though, in order to remove duplicates. The following code doesn't work:
Code: Select all
local hash, joint_list_2 = {}
for _, e in pairs(joint_list) do
if (not hash[e]) then
hash[e] = true
joint_list_2[#joint_list_2 + 1] = e
end
end
Any suggestions?