Premiers calculs pour QuadRoutes.

This commit is contained in:
Georges Dupéron 2011-12-01 14:45:53 +01:00
parent 22f44ce632
commit a418b982ea
4 changed files with 15 additions and 3 deletions

View File

@ -11,6 +11,14 @@ int QuadRoutes::height() { return std::abs(this->ne.y - this->sw.y); }
bool QuadRoutes::subdivide() {
children.reserve(9);
int minchildsize = 4;
int lx = std::floor(std::min((nw-ne).norm(), (sw-se).norm()));
// constraint: lx - maxdelta*2 ≥ minchildsize
// constraint: maxdelta ≤ lx/4
int maxdelta = std::min(lx/4, (lx-minchildsize)/2);
float xpos = (lx/2.f + hashInRange(seed, 0, -maxdelta, maxdelta)) / (float)lx; // xpos \in 0..1
Vertex n = nw * xpos + ne * (1-xpos);
int splitXMin = this->sw.x + std::max(4, this->width()*1/4);
int splitXMax = this->ne.x - std::max(4, this->width()*1/4);
int splitYMin = this->sw.y + std::max(4, this->height()*1/4);

View File

@ -3,9 +3,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 std::sqrt(x*x + y*y);
return (u-v).norm();
}
int Segment::width() {

View File

@ -4,6 +4,8 @@ Vertex::Vertex() {}
Vertex::Vertex(int x, int y, int z): x(x), y(y), z(z) {}
float Vertex::norm() { return std::sqrt(x*x + y*y + z*z); }
std::ostream& operator<<(std::ostream& os, const Vertex& v) {
return os << "(" << v.x << "," << v.y << "," << v.z << ")";
}
@ -52,6 +54,8 @@ Vertexf::Vertexf() {}
Vertexf::Vertexf(float x, float y, float z): x(x), y(y), z(z) {}
float Vertexf::norm() { return std::sqrt(x*x + y*y + z*z); }
std::ostream& operator<<(std::ostream& os, const Vertexf& v) {
return os << "(" << v.x << "," << v.y << "," << v.z << ")";
}

View File

@ -13,6 +13,7 @@ class Vertex {
public:
Vertex();
Vertex(int x, int y, int z);
float norm();
static Vertex fromSpherical(float r, float xAngle, float yAngle);
public:
@ -35,6 +36,7 @@ class Vertexf {
public:
Vertexf();
Vertexf(float x, float y, float z);
float norm();
static Vertexf fromSpherical(float r, float xAngle, float yAngle);
public: