From bd5b9722eab134f2106ab89007e4d006702a6e5e Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Tue, 6 Aug 2013 21:23:56 +1000 Subject: [PATCH] Make vector constructor explicit It had been seen to construct out of single doubles, which is problematic... --- vector.cpp | 18 +++++++++++------- vector.hpp | 2 +- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/vector.cpp b/vector.cpp index af916fe5..1e793de3 100644 --- a/vector.cpp +++ b/vector.cpp @@ -269,8 +269,10 @@ util::vector::normalised (void) const { //----------------------------------------------------------------------------- util::vector<2> util::polar_to_cartesian (const util::vector<2> &v) { - return { v.r * std::cos (v.t), - v.r * std::sin (v.t) }; + return util::vector<2> { + v.r * std::cos (v.t), + v.r * std::sin (v.t) + }; } //----------------------------------------------------------------------------- @@ -286,16 +288,18 @@ util::vector::dot (const util::vector &rhs) const { util::vector<3> util::cross (const util::vector<3> &a, const util::vector<3> &b) { - return { a.y * b.z - a.z * b.y, - a.z * b.x - a.x * b.z, - a.x * b.y - a.y * b.x }; + return util::vector<3> { + a.y * b.z - a.z * b.y, + a.z * b.x - a.x * b.z, + a.x * b.y - a.y * b.x + }; } //----------------------------------------------------------------------------- util::vector<3> util::spherical_to_cartesian (const util::vector<3> &s) { - return { + return util::vector<3> { s.x * sin (s.y) * cos (s.z), s.x * sin (s.y) * sin (s.z), s.x * cos (s.y), @@ -307,7 +311,7 @@ util::vector<3> util::cartesian_to_spherical (const util::vector<3> &c) { double mag = c.magnitude (); - return { + return util::vector<3> { mag, acos (c.z / mag), atan2 (c.y, c.x) diff --git a/vector.hpp b/vector.hpp index d9b4edc1..396ddb1b 100644 --- a/vector.hpp +++ b/vector.hpp @@ -36,7 +36,7 @@ namespace util { vector (); template - vector (T ...t): detail::coord_data {std::forward (t)...} { ; } + explicit vector (T ...t): detail::coord_data {std::forward (t)...} { ; } util::vector operator* (double) const; util::vector& operator*=(double);