]> git.tdb.fi Git - libs/math.git/commitdiff
Use range-based for loops where appropriate
authorMikko Rasa <tdb@tdb.fi>
Sat, 25 Jan 2025 23:21:37 +0000 (01:21 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sat, 25 Jan 2025 23:21:37 +0000 (01:21 +0200)
source/geometry/compositeshape.h
source/geometry/loader.h

index 0baa57919889ccabd28e87a66bd4986daf1cf7f8..012c390f55b8b1afe2aa5bb22d97d64b5b8dbe01 100644 (file)
@@ -66,8 +66,8 @@ template<typename T, unsigned D, typename O>
 inline void CompositeShape<T, D, O>::init()
 {
        max_isect = 0;
-       for(typename ShapeArray::const_iterator i=shapes.begin(); i!=shapes.end(); ++i)
-               max_isect += (*i)->get_max_ray_intersections();
+       for(Shape<T, D> *s: shapes)
+               max_isect += s->get_max_ray_intersections();
 }
 
 template<typename T, unsigned D, typename O>
@@ -75,19 +75,19 @@ inline CompositeShape<T, D, O>::CompositeShape(const CompositeShape<T, D, O> &ot
        shapes(other.shapes),
        max_isect(other.max_isect)
 {
-       for(typename ShapeArray::iterator i=shapes.begin(); i!=shapes.end(); ++i)
-               *i = (*i)->clone();
+       for(Shape<T, D> *&s: shapes)
+               s = s->clone();
 }
 
 template<typename T, unsigned D, typename O>
 inline CompositeShape<T, D, O> &CompositeShape<T, D, O>::operator=(const CompositeShape<T, D, O> &other)
 {
-       for(typename ShapeArray::iterator i=shapes.begin(); i!=shapes.end(); ++i)
-               delete *i;
+       for(Shape<T, D> *s: shapes)
+               delete s;
 
        shapes = other.shapes;
-       for(typename ShapeArray::iterator i=shapes.begin(); i!=shapes.end(); ++i)
-               *i = (*i)->clone();
+       for(Shape<T, D> *&s: shapes)
+               s = s->clone();
 
        max_isect = other.max_isect;
 }
@@ -95,8 +95,8 @@ inline CompositeShape<T, D, O> &CompositeShape<T, D, O>::operator=(const Composi
 template<typename T, unsigned D, typename O>
 inline CompositeShape<T, D, O>::~CompositeShape()
 {
-       for(typename ShapeArray::iterator i=shapes.begin(); i!=shapes.end(); ++i)
-               delete *i;
+       for(Shape<T, D> *s: shapes)
+               delete s;
 }
 
 template<typename T, unsigned D, typename O>
@@ -106,7 +106,7 @@ inline BoundingBox<T, D> CompositeShape<T, D, O>::get_axis_aligned_bounding_box(
                return this->bisect_axis_aligned_bounding_box(detail);
 
        BoundingBox<T, D> aabb;
-       for(typename ShapeArray::const_iterator i=shapes.begin(); i!=shapes.end(); ++i)
+       for(auto i=shapes.begin(); i!=shapes.end(); ++i)
        {
                if(i==shapes.begin())
                        aabb = (*i)->get_axis_aligned_bounding_box();
@@ -120,9 +120,9 @@ template<typename T, unsigned D, typename O>
 inline bool CompositeShape<T, D, O>::contains(const LinAl::Vector<T, D> &point) const
 {
        bool inside = false;
-       for(typename ShapeArray::const_iterator i=shapes.begin(); i!=shapes.end(); ++i)
+       for(Shape<T, D> *s: shapes)
        {
-               inside = (*i)->contains(point);
+               inside = s->contains(point);
                if(Ops::shortcircuit(inside))
                        return inside;
        }
@@ -142,7 +142,7 @@ inline unsigned CompositeShape<T, D, O>::get_intersections(const Ray<T, D> &ray,
 
        int start_nesting = 0;
        unsigned n = 0;
-       for(typename ShapeArray::const_iterator i=shapes.begin(); (n<buf_size && i!=shapes.end()); ++i)
+       for(auto i=shapes.begin(); (n<buf_size && i!=shapes.end()); ++i)
        {
                unsigned base = n;
                unsigned count = (*i)->get_intersections(ray, buffer+base, buf_size-base);
@@ -198,7 +198,7 @@ template<typename T, unsigned D, typename O>
 inline Coverage CompositeShape<T, D, O>::get_coverage(const BoundingBox<T, D> &bbox) const
 {
        Coverage coverage = NO_COVERAGE;
-       for(typename ShapeArray::const_iterator i=shapes.begin(); i!=shapes.end(); ++i)
+       for(auto i=shapes.begin(); i!=shapes.end(); ++i)
        {
                Coverage c = (*i)->get_coverage(bbox);
                if(i==shapes.begin())
index c5d7e563324527d65e97c29716a6b5206216d652..6b03bbb4826dc8de9a5ffc3bfa2086a9c493a50f 100644 (file)
@@ -195,8 +195,8 @@ inline DimensionIndependentLoader<T, D>::DimensionIndependentLoader(bool s):
 template<typename T, unsigned D>
 inline DimensionIndependentLoader<T, D>::~DimensionIndependentLoader()
 {
-       for(typename std::list<Shape<T, D> *>::iterator i=shapes.begin(); i!=shapes.end(); ++i)
-               delete *i;
+       for(Shape<T, D> *s: shapes)
+               delete s;
 }
 
 template<typename T, unsigned D>