summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/ray.cc
diff options
context:
space:
mode:
authorRobert Vollmert <rvollmert@gmx.net>2009-11-03 10:11:51 +0100
committerRobert Vollmert <rvollmert@gmx.net>2009-11-03 10:15:44 +0100
commitd49f04f32345c12a726e02f8d338d8bd6efb7f66 (patch)
tree288d33a28a07b4eb98cc9eaf0fd72fc44847c8b4 /crawl-ref/source/ray.cc
parent24cffd138886ef99a186281e0bf6cc4f8c21d670 (diff)
downloadcrawl-ref-d49f04f32345c12a726e02f8d338d8bd6efb7f66.tar.gz
crawl-ref-d49f04f32345c12a726e02f8d338d8bd6efb7f66.zip
Refine ray_def assertions.
ray_def::advance() and ray_def::bounce() now check pre- and post- conditions on validity.
Diffstat (limited to 'crawl-ref/source/ray.cc')
-rw-r--r--crawl-ref/source/ray.cc25
1 files changed, 22 insertions, 3 deletions
diff --git a/crawl-ref/source/ray.cc b/crawl-ref/source/ray.cc
index b5d2dbd7df..c2f02408f2 100644
--- a/crawl-ref/source/ray.cc
+++ b/crawl-ref/source/ray.cc
@@ -77,6 +77,14 @@ static bool in_diamond(const geom::vector &v)
return (in_diamond_int(v) || is_corner(v));
}
+// Is v in the interiour of a non-diamond?
+static bool in_non_diamond_int(const geom::vector &v)
+{
+ // This could instead be done like in_diamond_int.
+ return (!in_diamond(v) && !on_line(v));
+}
+
+
coord_def ray_def::pos() const
{
// XXX: pretty arbitrary if we're just on a corner.
@@ -100,11 +108,18 @@ static bool _advance_from_non_diamond(geom::ray *r)
}
}
+// The ray is in a legal state to be passed around externally.
+bool ray_def::_valid() const
+{
+ return (on_corner && is_corner(r.start) ||
+ !on_corner && in_diamond_int(r.start));
+}
+
// Return true if we didn't hit a corner, hence if this
// is a good ray so far.
bool ray_def::advance()
{
- ASSERT(on_corner || in_diamond_int(r.start));
+ ASSERT(_valid());
if (on_corner)
{
ASSERT (is_corner(r.start));
@@ -120,14 +135,16 @@ bool ray_def::advance()
{
// r is now on a corner, going from diamond to diamond.
r.to_grid(diamonds, true);
+ ASSERT(_valid());
return (true);
}
}
// Now inside a non-diamond.
- ASSERT(!in_diamond(r.start));
+ ASSERT(in_non_diamond_int(r.start));
on_corner = _advance_from_non_diamond(&r);
+ ASSERT(_valid());
return (!on_corner);
}
@@ -153,12 +170,13 @@ void ray_def::bounce(const reflect_grid &rg)
mprf(MSGCH_DIAGNOSTICS, "mirroring ray: (%f,%f) + t*(%f,%f)",
r.start.x, r.start.y, r.dir.x, r.dir.y);
#endif
- ASSERT(in_diamond(r.start));
+ ASSERT(_valid());
if (on_corner)
{
// XXX
r.dir = -r.dir;
+ ASSERT(_valid());
return;
}
@@ -279,6 +297,7 @@ void ray_def::bounce(const reflect_grid &rg)
mprf(MSGCH_DIAGNOSTICS, "mirrored ray: (%f,%f) + t*(%f,%f)",
r.start.x, r.start.y, r.dir.x, r.dir.y);
#endif
+ ASSERT(_valid());
}
void ray_def::regress()