fix: prune duplicate entity results from quad tree

This commit is contained in:
cha0s 2019-03-21 20:13:53 -05:00
parent bb02bed6a5
commit 25809f5b31

View File

@ -101,9 +101,18 @@ export class Listed extends Trait {
const quadTree = this.entity.list.quadTree();
position = Vector.add(position, Vector.scale(size, -0.5));
const query = Rectangle.compose(position, size);
return quadTree.search(query).map((node) => {
const entities = quadTree.search(query).map((node) => {
return node.data[2];
});
// Hitting multiple points for each entity can return duplicates.
const uniqueEntities = new Map();
entities.forEach((entity) => {
if (uniqueEntities.has(entity)) {
return;
}
uniqueEntities.set(entity, true);
})
return Array.from(uniqueEntities.keys());
},
resetQuadTreeNodes: () => {