From 643aa7b2317f88463f66da11e595ebe0f6c9621d Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Tue, 21 May 2013 16:32:49 +0300 Subject: [PATCH] Math function usage fixes Add using declarations and #includes where needed, and clean up some unnecessary ones. abs() is particularly annoying, as the int version easily gets into the global namespace and doesn't give a warning if used with floats or doubles. --- source/geometry/extrudedshape.h | 2 -- source/geometry/hyperbox.h | 2 ++ source/geometry/hypersphere.h | 3 +++ source/linal/squarematrix.h | 3 +++ source/linal/vector.h | 1 + 5 files changed, 9 insertions(+), 2 deletions(-) diff --git a/source/geometry/extrudedshape.h b/source/geometry/extrudedshape.h index 8fac4bc..0d895ac 100644 --- a/source/geometry/extrudedshape.h +++ b/source/geometry/extrudedshape.h @@ -107,8 +107,6 @@ inline unsigned ExtrudedShape::get_max_ray_intersections() const template inline unsigned ExtrudedShape::get_intersections(const Ray &ray, SurfacePoint *points, unsigned size) const { - using std::abs; - using std::sqrt; using std::swap; unsigned n = 0; diff --git a/source/geometry/hyperbox.h b/source/geometry/hyperbox.h index 845ca34..865b968 100644 --- a/source/geometry/hyperbox.h +++ b/source/geometry/hyperbox.h @@ -64,6 +64,8 @@ inline T HyperBox::get_dimension(unsigned i) const template inline bool HyperBox::contains(const LinAl::Vector &point) const { + using std::abs; + for(unsigned i=0; idimensions[i]/2) return false; diff --git a/source/geometry/hypersphere.h b/source/geometry/hypersphere.h index ce424e1..01aee0e 100644 --- a/source/geometry/hypersphere.h +++ b/source/geometry/hypersphere.h @@ -1,6 +1,7 @@ #ifndef MSP_GEOMETRY_HYPERSPHERE_H_ #define MSP_GEOMETRY_HYPERSPHERE_H_ +#include #include #include "hyperbox.h" #include "ray.h" @@ -79,6 +80,8 @@ inline bool HyperSphere::check_intersection(const Ray &ray) const template inline unsigned HyperSphere::get_intersections(const Ray &ray, SurfacePoint *points, unsigned size) const { + using std::sqrt; + T mid = -inner_product(ray.get_direction(), ray.get_start()); LinAl::Vector nearest = ray.get_start()+ray.get_direction()*mid; T offset_sq = radius*radius-inner_product(nearest, nearest); diff --git a/source/linal/squarematrix.h b/source/linal/squarematrix.h index 0af9a74..1cdc567 100644 --- a/source/linal/squarematrix.h +++ b/source/linal/squarematrix.h @@ -1,6 +1,7 @@ #ifndef MSP_LINAL_SQUAREMATRIX_H_ #define MSP_LINAL_SQUAREMATRIX_H_ +#include #include #include "matrix.h" @@ -52,6 +53,8 @@ SquareMatrix &SquareMatrix::operator*=(const SquareMatrix &m) template SquareMatrix &SquareMatrix::invert() { + using std::abs; + SquareMatrix r = identity(); for(unsigned i=0; i &v1, const Vector &v2) template inline T Vector::norm() const { + using std::sqrt; return sqrt(inner_product(*this, *this)); } -- 2.43.0