1
0
forked from josh/j3ml

Implement Geometric Class Definitions (round 2)

This commit is contained in:
2024-01-26 00:14:28 -05:00
parent 4152b0d2aa
commit 256fe730cd
11 changed files with 139 additions and 11 deletions

View File

@@ -1,9 +1,48 @@
#pragma once
#include <vector>
#include <cstdint>
#include <J3ML/LinearAlgebra/Vector2.h>
namespace Geometry
{
template <typename T>
class QuadTree
{
public:
struct Node
{
Node *parent;
uint32_t childIndex;
std::vector<T> objects;
Vector2 center;
Vector2 radius;
bool IsLeaf() const { return childIndex == 0xFFFFFFFF;}
uint32_t TopLeftChildIndex() const { return childIndex;}
uint32_t TopRightChildIndex() const { return childIndex+1;}
uint32_t BottomLeftChildIndex() const { return childIndex+2;}
uint32_t BottomRightChildIndex() const { return childIndex+3;}
/// This assumes that the QuadTree contains unique objects and never duplicates
void Remove(const T &object)
{
for (size_t i = 0; i < objects.size(); ++i){
if (objects[i] == object) {
AssociateQuadTreeNode(object, 0); // Mark in the object that it has been removed from the QuadTree.
std::swap(objects[i], objects.back());
objects.pop_back();
return;
}
}
}
AABB2D ComputeAABB()
{}
};
};
}