From 216618b74d0234e48323b8ae4dc2f5220e9d01ee Mon Sep 17 00:00:00 2001 From: Robert Vollmert Date: Mon, 2 Nov 2009 18:55:13 +0100 Subject: Make ray.cc ASSERTs a little safer. Not sure if this helps with the chain lightning problems, but the assertions should be less likely to trigger wrongly now. Also deal with "on_corner" in bounce(). --- crawl-ref/source/ray.cc | 42 ++++++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 10 deletions(-) (limited to 'crawl-ref/source/ray.cc') diff --git a/crawl-ref/source/ray.cc b/crawl-ref/source/ray.cc index b773b4b526..b5d2dbd7df 100644 --- a/crawl-ref/source/ray.cc +++ b/crawl-ref/source/ray.cc @@ -22,7 +22,7 @@ static geom::grid diamonds(geom::lineseq(1, 1, 0.5, 1), geom::lineseq(1, -1, -0.5, 1)); -static int ifloor(double d) +static int _ifloor(double d) { return static_cast(floor(d)); } @@ -32,17 +32,18 @@ static int iround(double d) return static_cast(round(d)); } -static bool double_is_integral(double d) +static int ifloor(double d) { - return (double_is_zero(d - round(d))); + int r = iround(d); + if (double_is_zero(d - r)) + return (r); + else + return (_ifloor(d)); } -// Is v in a diamond? -static bool in_diamond(const geom::vector &v) +static bool double_is_integral(double d) { - int i1 = ifloor(diamonds.ls1.index(v)); - int i2 = ifloor(diamonds.ls2.index(v)); - return ((i1 + i2) % 2 == 0); + return (double_is_zero(d - round(d))); } // Is v in the interiour of a diamond? @@ -50,7 +51,16 @@ static bool in_diamond_int(const geom::vector &v) { double d1 = diamonds.ls1.index(v); double d2 = diamonds.ls2.index(v); - return (!double_is_integral(d1) && !double_is_integral(d2)); + return (!double_is_integral(d1) && !double_is_integral(d2) + && (ifloor(d1) + ifloor(d2)) % 2 == 0); +} + +// Is v on a grid line? +static bool on_line(const geom::vector &v) +{ + double d1 = diamonds.ls1.index(v); + double d2 = diamonds.ls2.index(v); + return (double_is_integral(d1) || double_is_integral(d2)); } // Is v an intersection of grid lines? @@ -61,6 +71,12 @@ static bool is_corner(const geom::vector &v) return (double_is_integral(d1) && double_is_integral(d2)); } +// Is v in a diamond? +static bool in_diamond(const geom::vector &v) +{ + return (in_diamond_int(v) || is_corner(v)); +} + coord_def ray_def::pos() const { // XXX: pretty arbitrary if we're just on a corner. @@ -139,6 +155,13 @@ void ray_def::bounce(const reflect_grid &rg) #endif ASSERT(in_diamond(r.start)); + if (on_corner) + { + // XXX + r.dir = -r.dir; + return; + } + // Translate to cell (0,0). geom::vector p(pos().x, pos().y); geom::ray rtrans; @@ -264,4 +287,3 @@ void ray_def::regress() advance(); r.dir = -r.dir; } - -- cgit v1.2.3-54-g00ecf