commit a418b982eaf78540ac39069f97d408f059cd1d0a
parent 22f44ce6325821138d246d603e1f90a51c668e6e
Author: Georges Dupéron <jahvascriptmaniac+github@free.fr>
Date: Thu, 1 Dec 2011 14:45:53 +0100
Premiers calculs pour QuadRoutes.
Diffstat:
4 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/rules/quadroutes.cpp b/rules/quadroutes.cpp
@@ -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);
diff --git a/segment.cpp b/segment.cpp
@@ -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() {
diff --git a/vertex.cpp b/vertex.cpp
@@ -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 << ")";
}
diff --git a/vertex.hh b/vertex.hh
@@ -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: