www

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

commit a28b61c41fd3fff0757f3514b95535f726620d89
parent b1fd8eb29999e175f96fcd34c1aa4e363b553817
Author: Georges Dupéron <jahvascriptmaniac+github@free.fr>
Date:   Tue, 10 Jan 2012 21:06:11 +0100

Ajout de QuartierQuadConcave, pour corriger les quadrilatères concaves.

Diffstat:
Mall_includes.hh | 1+
Mgeometry/vertex.cpp | 6+++++-
Mrules/quartier/quartierquad.cpp | 5++++-
Arules/quartier/quartierquadconcave.cpp | 16++++++++++++++++
Arules/quartier/quartierquadconcave.hh | 13+++++++++++++
Mrules/quartier/quartiertri.cpp | 11++++++-----
6 files changed, 45 insertions(+), 7 deletions(-)

diff --git a/all_includes.hh b/all_includes.hh @@ -47,6 +47,7 @@ class Chose; #include "rules/quartier/quartierquad.hh" #include "rules/quartier/quartierquadangle.hh" +#include "rules/quartier/quartierquadconcave.hh" #include "rules/quartier/quartierquadcarre.hh" #include "rules/quartier/quartierquadrect.hh" #include "rules/quartier/quartiertri.hh" diff --git a/geometry/vertex.cpp b/geometry/vertex.cpp @@ -2,7 +2,11 @@ Vertex::Vertex() {} -Vertex::Vertex(float _x, float _y, float _z): x(_x), y(_y), z(_z) {} +Vertex::Vertex(float _x, float _y, float _z): x(_x), y(_y), z(_z) { + // TODO : DEBUG + //if (!(std::isfinite(x) && std::isfinite(y) && std::isfinite(z))) + // throw "Attempted to create vertex with bad data !"; +} float Vertex::norm() const { return std::sqrt(x*x + y*y + z*z); } diff --git a/rules/quartier/quartierquad.cpp b/rules/quartier/quartierquad.cpp @@ -13,10 +13,13 @@ Chose* QuartierQuad::factory(int seed, int n, Quad c) { bool small = c.minLength() < 3500; bool big = c.maxLength() >= 6000; bool anglesAcceptable = c.minAngle() > Angle::d2r(90-60) && c.maxAngle() < Angle::d2r(90+60); + bool concave = c.maxAngle() > Angle::d2r(160); bool anglesOk = c.minAngle() > Angle::d2r(90-40) && c.maxAngle() < Angle::d2r(90+40); bool tooWideX = c.minLengthEW() * 2 < c.maxLengthNS(); // trop allongé (côté E ou W deux fois plus petit que le côté N ou S). bool tooWideY = c.minLengthNS() * 2 < c.maxLengthEW(); // trop allongé (côté N ou S deux fois plus petit que le côté E ou W). - if (!big && proba(seed, n, 1, 20)) { + if (concave) { + return new QuartierQuadConcave(c); + } else if (!big && proba(seed, n, 1, 20)) { return new RouteTrottoirQuad(c); } else if (small && anglesAcceptable) { return new RouteTrottoirQuad(c); diff --git a/rules/quartier/quartierquadconcave.cpp b/rules/quartier/quartierquadconcave.cpp @@ -0,0 +1,16 @@ +#include "all_includes.hh" + +QuartierQuadConcave::QuartierQuadConcave(Quad _c) : QuartierQuad(_c) { +} + +bool QuartierQuadConcave::split() { + for (int i = 0; i < 4; i++) { + if (Triangle(c[NW+i], c[NE+i], c[SE+i]).angle() >= Angle::d2r(160)) { + addChild(QuartierTri::factory(seed, 0, Triangle(c[NE+i], c[SE+i], c[SW+i]))); + addChild(QuartierTri::factory(seed, 1, Triangle(c[SW+i], c[NW+i], c[NE+i]))); + return true; + } + } + throw "ERREUR : Ne devait jamais arriver ici !"; + return true; +} diff --git a/rules/quartier/quartierquadconcave.hh b/rules/quartier/quartierquadconcave.hh @@ -0,0 +1,13 @@ +#ifndef _RULES_QUARTIER_QUARTIERQUADCONCAVE_HH_ +#define _RULES_QUARTIER_QUARTIERQUADCONCAVE_HH_ + +#include "all_includes.hh" + +// QuadAngle est un quadrilatère avec un angle > 160. +class QuartierQuadConcave : public QuartierQuad { + public : + QuartierQuadConcave(Quad c); + virtual bool split(); +}; + +#endif diff --git a/rules/quartier/quartiertri.cpp b/rules/quartier/quartiertri.cpp @@ -10,12 +10,13 @@ void QuartierTri::getBoundingBoxPoints() { } Chose* QuartierTri::factory(int seed, int n, Triangle c) { - bool small = c.minLength() < 2500; + bool small = c.minLength() < 3500; bool big = c.maxLength() >= 6000; - bool verybig = c.maxLength() >= 20000; - if (small && !big) { + bool verybig = c.minLength() >= 10000; + bool anglesAcceptable = c.minAngle() > 30 && c.maxAngle() < 120; + if (small) { return new RouteTrottoirTri(c); - } else if (verybig) { + } else if (verybig && anglesAcceptable) { int choice = hash2(seed, n) % 3; if (choice == 0) { return new QuartierTriCentre(c); @@ -24,7 +25,7 @@ Chose* QuartierTri::factory(int seed, int n, Triangle c) { } else { return new QuartierTriTrapeze(c); } - } else if (big && c.maxAngle() < 75 && c.minAngle() > 45) { + } else if (big && !small && c.maxAngle() < 60+15 && c.minAngle() > 60-15) { return new QuartierTriCentre(c); } else if (big && !small) { return new QuartierTriHauteur(c);