commit f84116dbf4a3c954fe516196055b1b91ce4d9ca5
parent dfbdee7b7d381882c548366a6e51858325c14e3e
Author: Georges Dupéron <jahvascriptmaniac+github@free.fr>
Date: Fri, 25 Nov 2011 00:40:39 +0100
Initialisation des vectors d'enfants et de triangles.
Diffstat:
4 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/rules/batiment.cpp b/rules/batiment.cpp
@@ -13,6 +13,8 @@ void Batiment::subdivide() {
}
void Batiment::triangulation() {
+ initTriangles(12);
+
// abcd sont les quatre coins du bâtiment.
Vertex a = this->ne;
Vertex b = Vertex(this->ne.x, this->sw.y, 0);
diff --git a/rules/chose.cpp b/rules/chose.cpp
@@ -11,6 +11,14 @@ std::ostream& operator<<(std::ostream& os, const Chose& r) {
return os << "Chose";
}
+void Chose::initChildren(int n) {
+ children = std::vector<Chose*>(n);
+}
+
+void Chose::initTriangles(int n) {
+ triangles = std::vector<Triangle*>(n);
+}
+
void Chose::addChild(Chose* c) {
children.insert(children.end(), c);
// TODO : Ajouter c dans une file d'attente des éléments pouvant être split.
diff --git a/rules/chose.hh b/rules/chose.hh
@@ -20,6 +20,8 @@ public:
inline void addEntropy(Vertex v1, Vertex v2) { addEntropy(v1); addEntropy(v2); }
inline void addEntropy(Vertex v1, Vertex v2, Vertex v3) { addEntropy(v1, v2); addEntropy(v3); }
inline void addEntropy(Vertex v1, Vertex v2, Vertex v3, Vertex v4) { addEntropy(v1, v2); addEntropy(v3, v4); }
+ void initChildren(int n);
+ void initTriangles(int n);
void addChild(Chose* c);
void addTriangle(Triangle* t);
virtual void subdivide() = 0;
diff --git a/rules/rectangleroutes.cpp b/rules/rectangleroutes.cpp
@@ -11,6 +11,8 @@ int RectangleRoutes::width() { return this->ne.x - this->sw.x; }
int RectangleRoutes::height() { return this->ne.y - this->sw.y; }
void RectangleRoutes::subdivide() {
+ initChildren(9);
+
Vertex split(
hashInRange(this->seed, 0, this->sw.x + this->width()*1/4, this->sw.x + this->width()*3/4),
hashInRange(this->seed, 1, this->sw.y + this->height()*1/4, this->sw.y + this->height()*3/4),
@@ -37,10 +39,11 @@ void RectangleRoutes::subdivide() {
}
void RectangleRoutes::triangulation() {
+ initTriangles(2);
Vertex nw(this->sw.x, this->ne.y, 0);
Vertex se(this->ne.x, this->sw.y, 0);
- new Triangle(this->sw, nw, this->ne);
- new Triangle(this->sw, se, this->ne);
+ addTriangle(new Triangle(this->sw, nw, this->ne));
+ addTriangle(new Triangle(this->sw, se, this->ne));
}
Chose* RectangleRoutes::sub(Vertex ne, Vertex sw) {