diff options
Diffstat (limited to 'src/math')
-rw-r--r-- | src/math/point.h | 10 | ||||
-rw-r--r-- | src/math/vector.h | 11 |
2 files changed, 21 insertions, 0 deletions
diff --git a/src/math/point.h b/src/math/point.h index d6768c8..80f80f4 100644 --- a/src/math/point.h +++ b/src/math/point.h @@ -24,6 +24,7 @@ #include "func.h" #include <cmath> +#include <sstream> // Math module namespace @@ -147,6 +148,15 @@ struct Point return Point(left.x / right, left.y / right); } + + //! Returns a string "[x, y]" + inline std::string ToString() const + { + std::stringstream s; + s.precision(3); + s << "[" << x << ", " << y << "]"; + return s.str(); + } }; // struct Point diff --git a/src/math/vector.h b/src/math/vector.h index 41f11a8..65fc2f9 100644 --- a/src/math/vector.h +++ b/src/math/vector.h @@ -24,6 +24,7 @@ #include "func.h" #include <cmath> +#include <sstream> // Math module namespace @@ -202,6 +203,16 @@ struct Vector return Vector(left.x / right, left.y / right, left.z / right); } + + //! Returns a string "[x, y, z]" + inline std::string ToString() const + { + std::stringstream s; + s.precision(3); + s << "[" << x << ", " << y << ", " << z << "]"; + return s.str(); + } + }; // struct Point //! Checks if two vectors are equal within given \a tolerance |