www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 73da98b6a31b0d964e9c5fc68d6a0e9069aaa859
parent f84116dbf4a3c954fe516196055b1b91ce4d9ca5
Author: Georges Dupéron <jahvascriptmaniac+github@free.fr>
Date:   Fri, 25 Nov 2011 14:31:18 +0100

Carrefour et Route sont maintenant sous-classes de Chose. Correction de quelques bugs.

Diffstat:
Mall_includes.hh | 3++-
Mhash.cpp | 5+----
Mhash.hh | 3++-
Mrules/carrefour.cpp | 10++++++++++
Mrules/carrefour.hh | 14+++++++-------
Mrules/chose.cpp | 4++--
Mrules/rectangleroutes.cpp | 8++++----
Mrules/route.cpp | 10++++++++++
Mrules/route.hh | 14+++++++-------
Msegment.cpp | 2+-
10 files changed, 46 insertions(+), 27 deletions(-)

diff --git a/all_includes.hh b/all_includes.hh @@ -2,7 +2,8 @@ #define _ALL_INCLUDES_HH_ #include <iostream> -#include <math.h> +#include <cstdlib> +#include <cmath> #include <vector> #include "vertex.hh" diff --git a/hash.cpp b/hash.cpp @@ -1,7 +1,4 @@ -#include <time.h> -unsigned int random() { - return (unsigned int)time((time_t*)0); -} +#include "all_includes.hh" // Ce hash donne des bons résultats sur tous les bits de l'entier // généré (pas d'artefacts, répartition homogène des 0 et des 1). diff --git a/hash.hh b/hash.hh @@ -1,7 +1,8 @@ #ifndef _HASH_HH_ #define _HASH_HH_ -unsigned int random(); +#include "all_includes.hh" + unsigned int hash2(unsigned int a, unsigned int b); unsigned int hash3(unsigned int seed, int x, int y); int hashInRange(int seed, int n, int a, int b); diff --git a/rules/carrefour.cpp b/rules/carrefour.cpp @@ -8,6 +8,10 @@ Carrefour::Carrefour(Vertex ne, Vertex se, Vertex sw, Vertex nw) { std::cout << this << std::endl; } +void Carrefour::subdivide() { + // TODO +} + std::ostream& operator<<(std::ostream& os, const Carrefour* c) { return os << *c; } @@ -15,3 +19,9 @@ std::ostream& operator<<(std::ostream& os, const Carrefour* c) { std::ostream& operator<<(std::ostream& os, const Carrefour& c) { return os << "Carrefour " << c.corners[NE] << "-" << c.corners[SE] << "-" << c.corners[NW] << "-" << c.corners[SW]; } + +void Carrefour::triangulation() { + initTriangles(2); + addTriangle(new Triangle(corners[SW], corners[NW], corners[NE])); + addTriangle(new Triangle(corners[SW], corners[SE], corners[NE])); +} diff --git a/rules/carrefour.hh b/rules/carrefour.hh @@ -1,18 +1,18 @@ #ifndef _CARREFOUR_ROUTE_HH_ #define _CARREFOUR_ROUTE_HH_ -#include <iostream> -#include "../vertex.hh" -#include "../directions.hh" +#include "all_includes.hh" -class Carrefour { +class Carrefour : Chose { public: Vertex corners[4]; public: Carrefour(Vertex ne, Vertex se, Vertex sw, Vertex nw); + virtual void subdivide(); + virtual void triangulation(); +public: + friend std::ostream& operator<<(std::ostream& os, const Carrefour& c); + friend std::ostream& operator<<(std::ostream& os, const Carrefour* c); }; -std::ostream& operator<<(std::ostream& os, const Carrefour& c); -std::ostream& operator<<(std::ostream& os, const Carrefour* c); - #endif diff --git a/rules/chose.cpp b/rules/chose.cpp @@ -20,11 +20,11 @@ void Chose::initTriangles(int n) { } void Chose::addChild(Chose* c) { - children.insert(children.end(), c); + children.push_back(c); // TODO : Ajouter c dans une file d'attente des éléments pouvant être split. } void Chose::addTriangle(Triangle* t) { - triangles.insert(triangles.end(), t); + triangles.push_back(t); // TODO : Ajouter t dans la liste des triangles à envoyer au GPU. } diff --git a/rules/rectangleroutes.cpp b/rules/rectangleroutes.cpp @@ -6,9 +6,9 @@ RectangleRoutes::RectangleRoutes(Vertex ne, Vertex sw) : ne(ne), sw(sw) { std::cout << this << std::endl; } -int RectangleRoutes::width() { return this->ne.x - this->sw.x; } +int RectangleRoutes::width() { return std::abs(this->ne.x - this->sw.x); } -int RectangleRoutes::height() { return this->ne.y - this->sw.y; } +int RectangleRoutes::height() { return std::abs(this->ne.y - this->sw.y); } void RectangleRoutes::subdivide() { initChildren(9); @@ -22,9 +22,9 @@ void RectangleRoutes::subdivide() { new Carrefour(split + Vertex(1,1,0), split + Vertex(1,-1,0), split + Vertex(-1,-1,0), split + Vertex(-1,1,0)); // routes au NESW du carrefour // TODO : la plupart des zéros en z sont faux… - Vertex roadEndN(this->ne.y, split.x, 0); + Vertex roadEndN(split.x, this->ne.y, 0); Vertex roadEndE(this->ne.x, split.y, 0); - Vertex roadEndS(this->sw.y, split.x, 0); + Vertex roadEndS(split.x, this->sw.y, 0); Vertex roadEndW(this->sw.x, split.y, 0); // TODO : addChild(…); Route* rn = new Route(roadEndN + Vertex(-1,0,0), roadEndN + Vertex(+1,0,0), split + Vertex(+1,+1,0), split + Vertex(-1,+1,0)); // N diff --git a/rules/route.cpp b/rules/route.cpp @@ -10,6 +10,10 @@ Route::Route(Vertex ne, Vertex se, Vertex sw, Vertex nw) { std::cout << this << std::endl; } +void Route::subdivide() { + // TODO +} + std::ostream& operator<<(std::ostream& os, const Route* r) { return os << *r; } @@ -17,3 +21,9 @@ std::ostream& operator<<(std::ostream& os, const Route* r) { std::ostream& operator<<(std::ostream& os, const Route& r) { return os << "Route " << r.corners[NE] << "-" << r.corners[SE] << "-" << r.corners[NW] << "-" << r.corners[SW]; } + +void Route::triangulation() { + initTriangles(2); + addTriangle(new Triangle(corners[SW], corners[NW], corners[NE])); + addTriangle(new Triangle(corners[SW], corners[SE], corners[NE])); +} diff --git a/rules/route.hh b/rules/route.hh @@ -1,18 +1,18 @@ #ifndef _RULES_ROUTE_HH_ #define _RULES_ROUTE_HH_ -#include <iostream> -#include "../vertex.hh" -#include "../directions.hh" +#include "all_includes.hh" -class Route { +class Route : Chose { public: Vertex corners[4]; public: Route(Vertex ne, Vertex se, Vertex sw, Vertex nw); + virtual void subdivide(); + virtual void triangulation(); +public: + friend std::ostream& operator<<(std::ostream& os, const Route& r); + friend std::ostream& operator<<(std::ostream& os, const Route* r); }; -std::ostream& operator<<(std::ostream& os, const Route& r); -std::ostream& operator<<(std::ostream& os, const Route* r); - #endif diff --git a/segment.cpp b/segment.cpp @@ -5,7 +5,7 @@ Segment::Segment(Vertex u, Vertex v): u(u), v(v) {} int Segment::length() { int x = u.x - v.x; int y = u.y - v.y; - return sqrt(x*x + y*y); + return std::sqrt(x*x + y*y); } int Segment::width() {