diff options
Diffstat (limited to 'crawl-ref')
-rw-r--r-- | crawl-ref/source/geom2d.cc | 41 | ||||
-rw-r--r-- | crawl-ref/source/geom2d.h | 5 | ||||
-rw-r--r-- | crawl-ref/source/ray.cc | 8 |
3 files changed, 29 insertions, 25 deletions
diff --git a/crawl-ref/source/geom2d.cc b/crawl-ref/source/geom2d.cc index eef902f14d..f1d4e3b1c9 100644 --- a/crawl-ref/source/geom2d.cc +++ b/crawl-ref/source/geom2d.cc @@ -68,54 +68,57 @@ static double tdist(const ray &r, const lineseq &ls) } // Shoot the ray inside the next cell. -// Returns true if succesfully advanced into a new cell, +// Returns true if successfully advanced into a new cell, // false if it hit a corner. -bool nextcell(ray &r, const grid &g) +bool ray::to_next_cell(const grid &g) { // ASSERT(!parallel(g.vert, g.horiz)); lineseq ls; - if (parallel(r.dir, g.ls1.f)) + if (parallel(dir, g.ls1.f)) ls = g.ls2; - else if (parallel(r.dir, g.ls2.f)) + else if (parallel(dir, g.ls2.f)) ls = g.ls1; else { - double s = nextintersect(r, g.ls1); - double t = nextintersect(r, g.ls2); - double sd = tdist(r, g.ls1); - double td = tdist(r, g.ls2); + double s = nextintersect(*this, g.ls1); + double t = nextintersect(*this, g.ls2); + double sd = tdist(*this, g.ls1); + double td = tdist(*this, g.ls2); if (double_is_zero(s - t)) { // Move onto the corner. The fact that we're on a corner // should be tracked externally. - r.advance(s); + advance(s); return (false); } double dmin = std::min(s,t); double dnext = std::min(std::max(s,t), dmin + std::min(sd, td)); - r.advance((dmin + dnext) / 2.0); + advance((dmin + dnext) / 2.0); return (true); } // parallel: just advance an extra half - double s = nextintersect(r, ls); - r.advance(s + 0.5 * tdist(r, ls)); + double s = nextintersect(*this, ls); + advance(s + 0.5 * tdist(*this, ls)); return (true); } -void movehalfcell(ray &r, const grid &g) +// Move a ray by half a cell: starting at a corner of the grid, +// it ends up within the next cell. +void ray::move_half_cell(const grid &g) { // ASSERT(!parallel(g.vert, g.horiz)); lineseq ls; double t; - if (parallel(r.dir, g.ls1.f)) - t = tdist(r, g.ls2); - else if (parallel(r.dir, g.ls2.f)) - t = tdist(r, g.ls1); + if (parallel(dir, g.ls1.f)) + t = tdist(*this, g.ls2); + else if (parallel(dir, g.ls2.f)) + t = tdist(*this, g.ls1); else - t = std::min(tdist(r, g.ls1), tdist(r, g.ls2)); - r.advance(0.5 * t); + t = std::min(tdist(*this, g.ls1), tdist(*this, g.ls2)); + advance(0.5 * t); } + // vector space implementation const vector& vector::operator+=(const vector &v) diff --git a/crawl-ref/source/geom2d.h b/crawl-ref/source/geom2d.h index 37b62745df..f1e2310bf4 100644 --- a/crawl-ref/source/geom2d.h +++ b/crawl-ref/source/geom2d.h @@ -31,6 +31,7 @@ struct form // A ray in two-dimensional space given by starting point // and direction vector. // The points of R are start + t*dir. +struct grid; struct ray { vector start; @@ -42,6 +43,8 @@ struct ray vector shoot(double t) const; void advance(double t); + void move_half_cell(const grid &g); + bool to_next_cell(const grid& g); }; // A line in two-dimensional space as the preimage of a number @@ -76,8 +79,6 @@ struct grid double intersect(const ray &r, const line &l); double nextintersect(const ray &r, const lineseq &ls); -bool nextcell(ray &r, const grid &g); -void movehalfcell(ray &r, const grid &g); } diff --git a/crawl-ref/source/ray.cc b/crawl-ref/source/ray.cc index 32b9531fd5..e0fa416f91 100644 --- a/crawl-ref/source/ray.cc +++ b/crawl-ref/source/ray.cc @@ -40,23 +40,23 @@ bool ray_def::advance() if (on_corner) { on_corner = false; - geom::movehalfcell(r, diamonds); + r.move_half_cell(diamonds); } else { // Starting inside a diamond. - bool c = !geom::nextcell(r, diamonds); + bool c = !r.to_next_cell(diamonds); if (c) { // r is now on a corner, going from diamond to diamond. - geom::movehalfcell(r, diamonds); + r.move_half_cell(diamonds); return (false); } } // Now inside a non-diamond. - if (geom::nextcell(r, diamonds)) + if (r.to_next_cell(diamonds)) return (true); else { |