]> git.tdb.fi Git - libs/math.git/commitdiff
Convert the geometry part to use the new vector slicing API
authorMikko Rasa <tdb@tdb.fi>
Fri, 21 Nov 2014 12:38:55 +0000 (14:38 +0200)
committerMikko Rasa <tdb@tdb.fi>
Fri, 21 Nov 2014 12:38:55 +0000 (14:38 +0200)
Everything being templates makes catching subtle compilation errors a bit
hard.

source/geometry/affinetransformation.h
source/geometry/extrudedshape.h

index 15bd92675405a36a4b4205326400256ee3187934..f01ac3addbf0b6d5fb2b503f448f5ff47f493371 100644 (file)
@@ -175,13 +175,13 @@ inline AffineTransformation<T, D> invert(const AffineTransformation<T, D> &at)
 template<typename T, unsigned D>
 inline LinAl::Vector<T, D> AffineTransformation<T, D>::transform(const LinAl::Vector<T, D> &v) const
 {
-       return LinAl::Vector<T, D>(matrix*LinAl::Vector<T, D+1>(v, T(1)));
+       return (matrix*compose(v, T(1))).template slice<D>(0);
 }
 
 template<typename T, unsigned D>
 inline LinAl::Vector<T, D> AffineTransformation<T, D>::transform_linear(const LinAl::Vector<T, D> &v) const
 {
-       return LinAl::Vector<T, D>(matrix*LinAl::Vector<T, D+1>(v, T(0)));
+       return (matrix*compose(v, T(0))).template slice<D>(0);
 }
 
 template<typename T, unsigned D>
index c00111a549a67fa0bbdd4682f859030acbad4a74..400c52b8122cdee3d45627b87822aa0bd4cea19f 100644 (file)
@@ -78,8 +78,8 @@ inline BoundingBox<T, D> ExtrudedShape<T, D>::get_axis_aligned_bounding_box() co
 {
        BoundingBox<T, D-1> base_bbox = base->get_axis_aligned_bounding_box();
        T half_length = length/T(2);
-       return BoundingBox<T, D>(LinAl::Vector<T, D>(base_bbox.get_minimum_point(), -half_length),
-               LinAl::Vector<T, D>(base_bbox.get_maximum_point(), half_length));
+       return BoundingBox<T, D>(compose(base_bbox.get_minimum_point(), -half_length),
+               compose(base_bbox.get_maximum_point(), half_length));
 }
 
 template<typename T, unsigned D>
@@ -90,7 +90,7 @@ inline bool ExtrudedShape<T, D>::contains(const LinAl::Vector<T, D> &point) cons
        if(abs(point[D-1])>length/T(2))
                return false;
 
-       return base->contains(LinAl::Vector<T, D-1>(point));
+       return base->contains(point.template slice<D-1>(0));
 }
 
 template<typename T, unsigned D>
@@ -108,7 +108,7 @@ inline unsigned ExtrudedShape<T, D>::get_intersections(const Ray<T, D> &ray, Sur
        T half_length = length/T(2);
        const LinAl::Vector<T, D> &ray_start = ray.get_start();
        const LinAl::Vector<T, D> &ray_direction = ray.get_direction();
-       LinAl::Vector<T, D-1> base_dir(ray_direction);
+       LinAl::Vector<T, D-1> base_dir = ray_direction.template slice<D-1>(0);
 
        /* If the ray does not degenerate to a point in the base space, it could
        intersect the base shape. */
@@ -129,7 +129,7 @@ inline unsigned ExtrudedShape<T, D>::get_intersections(const Ray<T, D> &ray, Sur
                if(limit>=offset)
                {
                        T distortion = base_dir.norm();
-                       Ray<T, D-1> base_ray(LinAl::Vector<T, D-1>(ray_start+ray_direction*offset),
+                       Ray<T, D-1> base_ray((ray_start+ray_direction*offset).template slice<D-1>(0),
                                base_dir, (limit-offset)*distortion);
 
                        SurfacePoint<T, D-1> *base_points = 0;
@@ -145,7 +145,7 @@ inline unsigned ExtrudedShape<T, D>::get_intersections(const Ray<T, D> &ray, Sur
                                {
                                        T x = offset+base_points[i].distance/distortion;
                                        points[n].position = ray_start+ray_direction*x;
-                                       points[n].normal = LinAl::Vector<T, D>(base_points[i].normal, T(0));
+                                       points[n].normal = compose(base_points[i].normal, T(0));
                                        points[n].distance = x;
                                }
 
@@ -165,7 +165,7 @@ inline unsigned ExtrudedShape<T, D>::get_intersections(const Ray<T, D> &ray, Sur
                                continue;
 
                        LinAl::Vector<T, D> p = ray_start+ray_direction*x;
-                       if(base->contains(LinAl::Vector<T, D-1>(p)))
+                       if(base->contains(p.template slice<D-1>(0)))
                        {
                                if(points)
                                {