summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/ray.cc
diff options
context:
space:
mode:
authorRobert Vollmert <rvollmert@gmx.net>2009-11-02 18:55:13 +0100
committerRobert Vollmert <rvollmert@gmx.net>2009-11-02 18:55:13 +0100
commit216618b74d0234e48323b8ae4dc2f5220e9d01ee (patch)
treeebac8f5ba31e7bb9a2fd58530412255cb04fcc18 /crawl-ref/source/ray.cc
parent8c993f339f6264342c4ea7a1032cd1e5c94e601d (diff)
downloadcrawl-ref-216618b74d0234e48323b8ae4dc2f5220e9d01ee.tar.gz
crawl-ref-216618b74d0234e48323b8ae4dc2f5220e9d01ee.zip
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().
Diffstat (limited to 'crawl-ref/source/ray.cc')
-rw-r--r--crawl-ref/source/ray.cc42
1 files changed, 32 insertions, 10 deletions
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<int>(floor(d));
}
@@ -32,17 +32,18 @@ static int iround(double d)
return static_cast<int>(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;
}
-