From d106005da5f41332ac26febe398adb0d5bb61de0 Mon Sep 17 00:00:00 2001 From: Robert Vollmert Date: Sat, 31 Oct 2009 17:25:39 +0100 Subject: Make nextcell and movehalfcell methods of geom::ray. Seems sensible given they modify the ray, even if it's not really something intrinsic to a ray. --- crawl-ref/source/geom2d.cc | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) (limited to 'crawl-ref/source/geom2d.cc') 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) -- cgit v1.2.3-54-g00ecf