diff options
author | Robert Vollmert <rvollmert@gmx.net> | 2009-10-31 18:17:08 +0100 |
---|---|---|
committer | Robert Vollmert <rvollmert@gmx.net> | 2009-11-01 21:45:25 +0100 |
commit | c8f4dd7a1f5e3c666bc84e81248df7fba78eefeb (patch) | |
tree | d52b15c1ed055bfebf86124b2a6d7792fa9812a3 /crawl-ref/source/geom2d.cc | |
parent | d106005da5f41332ac26febe398adb0d5bb61de0 (diff) | |
download | crawl-ref-c8f4dd7a1f5e3c666bc84e81248df7fba78eefeb.tar.gz crawl-ref-c8f4dd7a1f5e3c666bc84e81248df7fba78eefeb.zip |
Some geom2d changes.
1. Add function to reflect vector at a line.
2. Implement scalar multiplication as external operator.
Diffstat (limited to 'crawl-ref/source/geom2d.cc')
-rw-r--r-- | crawl-ref/source/geom2d.cc | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/crawl-ref/source/geom2d.cc b/crawl-ref/source/geom2d.cc index f1d4e3b1c9..de8d86724b 100644 --- a/crawl-ref/source/geom2d.cc +++ b/crawl-ref/source/geom2d.cc @@ -24,7 +24,7 @@ static bool parallel(vector v, form f) vector ray::shoot(double t) const { - return (start + dir * t); + return (start + t*dir); } void ray::advance(double t) @@ -118,6 +118,16 @@ void ray::move_half_cell(const grid &g) advance(0.5 * t); } +vector normal(const form &f) +{ + return (vector(f.a, f.b)); +} + +vector reflect(const vector &v, const form &f) +{ + vector n = normal(f); + return (v - 2 * f(v)/f(n) * n); +} // vector space implementation @@ -135,18 +145,24 @@ vector vector::operator+(const vector &v) const return (copy); } -const vector& vector::operator*=(double t) +vector vector::operator-() const { - x *= t; - y *= t; - return (*this); + return ((-1) * (*this)); } -vector vector::operator*(double t) const +const vector& vector::operator-=(const vector &v) { - vector copy = *this; - copy *= t; - return (copy); + return (*this += -v); +} + +vector vector::operator-(const vector &v) const +{ + return (*this + (-v)); +} + +vector operator*(double t, const vector &v) +{ + return (vector(t*v.x, t*v.y)); } double form::operator()(const vector& v) const |