diff options
Diffstat (limited to 'crawl-ref/source/geom2d.cc')
-rw-r--r-- | crawl-ref/source/geom2d.cc | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/crawl-ref/source/geom2d.cc b/crawl-ref/source/geom2d.cc index 720f334226..3fba76e2d3 100644 --- a/crawl-ref/source/geom2d.cc +++ b/crawl-ref/source/geom2d.cc @@ -154,5 +154,19 @@ double form::operator()(const vector& v) const return (a*v.x + b*v.y); } +double degrees(const vector &v) +{ + if (v.x == 0) + return (v.y > 0 ? 90.0 : -90.0); + double rad = v.x > 0 ? atan(v.y/v.x) : M_PI + atan(v.y/v.x); + return (180.0 / M_PI * rad); +} + +vector degree_to_vector(double d) +{ + double rad = d / 180.0 * M_PI; + return (vector(cos(rad), sin(rad))); +} + } |