#include "Area.hpp"

#include "../geometry/math.hpp"
#include "../geometry/Box.hpp"
#include "Elements.hpp"

using namespace world;

bool ChunkContainer::inRange(const chunk_pos& pos) const {
    return glm::all(glm::lessThan(glm::abs(pos), chunk_pos(radius)));
}
std::shared_ptr<EdittableChunk> ChunkContainer::findInRange(const chunk_pos &pos) const {
    const auto it = find(pos);
    return it != end() ? it->second : nullptr;
}

void Area::free(const node_id& i, Elements& l) {
    l.areas.erase(i);
}
aabb Area::getBoundingBox(const Elements&) const {
    return aabb(glm::lfvec3(-CHUNK_LENGTH * (chunks.getRadius() - 1)),
        glm::lfvec3(CHUNK_LENGTH * chunks.getRadius()));
}