]> git.tdb.fi Git - libs/math.git/commitdiff
Use default members initializers and defaulted special members
authorMikko Rasa <tdb@tdb.fi>
Mon, 23 Jan 2023 14:56:56 +0000 (16:56 +0200)
committerMikko Rasa <tdb@tdb.fi>
Mon, 23 Jan 2023 14:56:56 +0000 (16:56 +0200)
24 files changed:
source/geometry/affinetransform.h
source/geometry/angle.h
source/geometry/boundingbox.h
source/geometry/boundingsphere.h
source/geometry/box.h
source/geometry/circle.h
source/geometry/compositeshape.h
source/geometry/extrudedshape.h
source/geometry/hypersphere.h
source/geometry/intersection.h
source/geometry/loader.h
source/geometry/negation.h
source/geometry/quaternion.h
source/geometry/ray.h
source/geometry/rectangle.h
source/geometry/shape.h
source/geometry/surfacepoint.h
source/geometry/transformedshape.h
source/geometry/union.h
source/interpolate/polynomial.h
source/interpolate/spline.h
source/linal/dynamicmatrix.h
source/linal/dynamicvector.h
source/linal/vector.h

index f9660c60d1c7042a6e96f88cf3fdd8bc67820959..a3806153513a19cc962727dc9d11942b52b6e251 100644 (file)
@@ -21,14 +21,14 @@ template<typename T, unsigned D>
 class AffineTransformOps
 {
 protected:
-       AffineTransformOps() { }
+       AffineTransformOps() = default;
 };
 
 template<typename T>
 class AffineTransformOps<T, 2>
 {
 protected:
-       AffineTransformOps() { }
+       AffineTransformOps() = default;
 
 public:
        static AffineTransform<T, 2> rotation(Angle<T>);
@@ -38,7 +38,7 @@ template<typename T>
 class AffineTransformOps<T, 3>
 {
 protected:
-       AffineTransformOps() { }
+       AffineTransformOps() = default;
 
 public:
        static AffineTransform<T, 3> rotation(Angle<T>, const LinAl::Vector<T, 3> &);
@@ -78,12 +78,11 @@ public:
        BoundingBox<T, D> transform(const BoundingBox<T, D> &) const;
 };
 
-template<typename T, unsigned D>
-inline AffineTransform<T, D>::AffineTransform()
-{
-       this->matrix = LinAl::Matrix<T, D+1, D+1>::identity();
-}
 
+template<typename T, unsigned D>
+inline AffineTransform<T, D>::AffineTransform():
+       matrix(LinAl::Matrix<T, D+1, D+1>::identity())
+{ }
 
 template<typename T, unsigned D>
 AffineTransform<T, D> AffineTransform<T, D>::translation(const LinAl::Vector<T, D> &v)
index bcd7ccad72985ec1dc65208094299e65c9fc44e5..c9d898c007d97d206f6ad878561917242cd1c4b7 100644 (file)
@@ -14,11 +14,11 @@ template<typename T>
 class Angle
 {
 private:
-       T value;
+       T value = T(0);
 
        explicit Angle(T v): value(v) { }
 public:
-       Angle(): value(0) { }
+       Angle() = default;
        template<typename U>
        Angle(Angle<U> other): value(other.radians()) { }
 
index ae9da2baac7b8f562eafc5632f5ae5bc86032f8c..d24aab96233894eb43582d30ef83e0468f5c7e56 100644 (file)
@@ -14,11 +14,11 @@ class BoundingBox
 private:
        LinAl::Vector<T, D> min_pt;
        LinAl::Vector<T, D> max_pt;
-       bool empty;
-       bool negated;
+       bool empty = true;
+       bool negated = false;
 
 public:
-       BoundingBox();
+       BoundingBox() = default;
        BoundingBox(const LinAl::Vector<T, D> &, const LinAl::Vector<T, D> &);
 
        static BoundingBox negate(const BoundingBox &);
@@ -35,18 +35,12 @@ public:
        bool is_negated() const { return negated; }
 };
 
-template<typename T, unsigned D>
-inline BoundingBox<T, D>::BoundingBox():
-       empty(true),
-       negated(false)
-{ }
 
 template<typename T, unsigned D>
 inline BoundingBox<T, D>::BoundingBox(const LinAl::Vector<T, D> &n, const LinAl::Vector<T, D> &x):
        min_pt(n),
        max_pt(x),
-       empty(false),
-       negated(false)
+       empty(false)
 {
        for(unsigned i=0; i<D; ++i)
                if(min_pt[i]>max_pt[i])
index 66c14d5c904776f68c7344e76e534e1638e4f933..311b70e931ad4b38e314107d5461c2499af749dd 100644 (file)
@@ -12,11 +12,11 @@ class BoundingSphere
 {
 private:
        LinAl::Vector<T, N> center;
-       T radius;
-       bool empty;
+       T radius = T(0);
+       bool empty = true;
 
 public:
-       BoundingSphere();
+       BoundingSphere() = default;
        BoundingSphere(const LinAl::Vector<T, N> &, T);
 
        template<typename Iter>
@@ -27,11 +27,6 @@ public:
        bool is_empty() const { return empty; }
 };
 
-template<typename T, unsigned N>
-BoundingSphere<T, N>::BoundingSphere():
-       radius(0),
-       empty(true)
-{ }
 
 template<typename T, unsigned N>
 BoundingSphere<T, N>::BoundingSphere(const LinAl::Vector<T, N> &c, T r):
index b46eb677c37b7f0c0180505facdfe219f8d22e81..14fb8ac492f98e2a978b9f470e68bb6d563c4c56 100644 (file)
@@ -15,7 +15,7 @@ template<typename T>
 class Box: public HyperBox<T, 3>
 {
 public:
-       Box() { }
+       Box() = default;
        explicit Box(const LinAl::Vector<T, 3> &d): HyperBox<T, 3>(d) { }
        Box(T w, T h, T d): HyperBox<T, 3>(LinAl::Vector<T, 3>(w, h, d)) { }
 
index 3a2cfc286dc82049117ab324dddd2fe52f5097e7..317c0889ea484b8c082ee929fd04e0d556ecdcc4 100644 (file)
@@ -15,7 +15,7 @@ template<typename T>
 class Circle: public HyperSphere<T, 2>
 {
 public:
-       Circle() { }
+       Circle() = default;
        explicit Circle(T r): HyperSphere<T, 2>(r) { }
 };
 
index c472b437e3052f4948cde3a68ac40a9f1107b35a..b6206369ceece8afc549d1aea37f80d81e1e6f09 100644 (file)
@@ -22,7 +22,7 @@ protected:
        ShapeArray shapes;
        unsigned max_isect;
 
-       CompositeShape() { }
+       CompositeShape() = default;
        CompositeShape(const Shape<T, D> &, const Shape<T, D> &);
        template<typename Iter>
        void init_from_iter_range(const Iter &, const Iter &);
index fd4597b9b1a5c935f50a3eb3a6e02296cd3f3a9f..e57ee94587597320a5d00301ab4c89167a8cdeed 100644 (file)
@@ -17,8 +17,8 @@ template<typename T, unsigned D>
 class ExtrudedShape: public Shape<T, D>
 {
 private:
-       Shape<T, D-1> *base;
-       T length;
+       Shape<T, D-1> *base = 0;
+       T length = T(1);
 
 public:
        ExtrudedShape(const Shape<T, D-1> &, T);
index 13e4278430b8b5e2a811974a1959d54dac8bd305..0b327cf7be4f513835405ba60806a635925c6551 100644 (file)
@@ -17,10 +17,10 @@ template<typename T, unsigned D>
 class HyperSphere: public Shape<T, D>
 {
 private:
-       T radius;
+       T radius = T(1);
 
 public:
-       HyperSphere(): radius(1) { }
+       HyperSphere() = default;
        explicit HyperSphere(T);
 
        virtual HyperSphere *clone() const;
index 24e668dc35a1924a70e1c3815fecbeac8147595e..9bf34165717cbd808c72995e4dba46baabfea261 100644 (file)
@@ -21,7 +21,7 @@ template<typename T, unsigned D>
 class Intersection: public CompositeShape<T, D, IntersectionOps<T, D> >
 {
 private:
-       Intersection() { }
+       Intersection() = default;
 public:
        Intersection(const Shape<T, D> &, const Shape<T, D> &);
 
index 0a9c4b537c9ffbc90b11bb51cb48a28a70c10c87..58ca8a0026c85f3d6b654e4f9b01b93ef1710a17 100644 (file)
@@ -20,7 +20,7 @@ template<typename T, unsigned D>
 class DimensionIndependentLoader: public DataFile::Loader
 {
 protected:
-       bool single;
+       bool single = true;
        std::list<Shape<T, D> *> shapes;
 
        DimensionIndependentLoader(bool = true);
index 60b92e33d1d30def4d60f631c8311acbbcd0c115..c2f96e90a33fb6bc00c0da3d0771ad37a1ed23bc 100644 (file)
@@ -14,7 +14,7 @@ template<typename T, unsigned D>
 class Negation: public Shape<T, D>
 {
 private:
-       Shape<T, D> *shape;
+       Shape<T, D> *shape = 0;
 
 public:
        Negation(const Shape<T, D> &);
index 7c036123058d279fa810c95265fde6ba320f4adc..809259710884b2f2931ad6674913f65d1909a81d 100644 (file)
@@ -12,9 +12,12 @@ namespace Geometry {
 template<typename T>
 struct Quaternion
 {
-       T a, b, c, d;
+       T a = T(0);
+       T b = T(0);
+       T c = T(0);
+       T d = T(0);
 
-       Quaternion(): a(0), b(0), c(0), d(0) { }
+       Quaternion() = default;
        Quaternion(T a_, T b_, T c_, T d_): a(a_), b(b_), c(c_), d(d_) { }
 
        static Quaternion one() { return Quaternion(1, 0, 0, 0); }
index d8eb7d8405ec75f799226572c5135d08260b978b..efe47fe08ebec337ffe9fd13adf84f1a1628a772 100644 (file)
@@ -16,7 +16,7 @@ class Ray
 private:
        LinAl::Vector<T, D> start;
        LinAl::Vector<T, D> direction;
-       T limit;
+       T limit = T(0);
 
 public:
        Ray();
@@ -30,8 +30,7 @@ public:
 };
 
 template<typename T, unsigned D>
-inline Ray<T, D>::Ray():
-       limit(0)
+inline Ray<T, D>::Ray()
 {
        direction[0] = T(1);
 }
@@ -39,8 +38,7 @@ inline Ray<T, D>::Ray():
 template<typename T, unsigned D>
 inline Ray<T, D>::Ray(const LinAl::Vector<T, D> &s, const LinAl::Vector<T, D> &d):
        start(s),
-       direction(normalize(d)),
-       limit(0)
+       direction(normalize(d))
 { }
 
 template<typename T, unsigned D>
index cbf625c913a04be0cc894d3f7d9732dbfa0bdcb5..273becbf963cd8d76aa8eb8445a042f94946b080 100644 (file)
@@ -15,7 +15,7 @@ template<typename T>
 class Rectangle: public HyperBox<T, 2>
 {
 public:
-       Rectangle() { }
+       Rectangle() = default;
        explicit Rectangle(const LinAl::Vector<T, 2> &d): HyperBox<T, 2>(d) { }
        Rectangle(T w, T h): HyperBox<T, 2>(LinAl::Vector<T, 2>(w, h)) { }
 
index 920e4560454799d7828a50a9601e3ad4ba2295b7..543550dbc0616db13a20f35a49f5cf817cf7cbf4 100644 (file)
@@ -35,9 +35,9 @@ protected:
                Coverage coverage;
        };
 
-       Shape() { }
+       Shape() = default;
 public:
-       virtual ~Shape() { }
+       virtual ~Shape() = default;
 
        virtual Shape *clone() const = 0;
 
index 3b38e1d2d03f6fdf5e2ee5c99ff6fbfaca633813..e5faed1edf0f0ba1c67e5b689b950eda7cd64723 100644 (file)
@@ -15,8 +15,8 @@ struct SurfacePoint
 {
        LinAl::Vector<T, N> position;
        LinAl::Vector<T, N> normal;
-       T distance;
-       bool entry;
+       T distance = T(0);
+       bool entry = true;
 };
 
 template<typename T, unsigned N>
index 168fbd9732e960dfbc79dc254cb281e8553859f1..b53f5b8c040630232ba87520b43c76f377af8744 100644 (file)
@@ -14,7 +14,7 @@ template<typename T, unsigned D>
 class TransformedShape: public Shape<T, D>
 {
 private:
-       Shape<T, D> *shape;
+       Shape<T, D> *shape = 0;
        AffineTransform<T, D> transformation;
        AffineTransform<T, D> inverse_trans;
 
index 8c02f2b808dc8a18301653c77e8175e83b2ea555..0a2de4fe6f17a0ba0c86a10e8e9b593b91068371 100644 (file)
@@ -21,7 +21,7 @@ template<typename T, unsigned D>
 class Union: public CompositeShape<T, D, UnionOps<T, D> >
 {
 private:
-       Union() { }
+       Union() = default;
 public:
        Union(const Shape<T, D> &, const Shape<T, D> &);
 
index 859eea85583eca2ec09c8abb7667cfd4a813a0be..e076204b5117470c42ef011a5bf0d4ad77ad4a8d 100644 (file)
@@ -18,7 +18,7 @@ private:
        LinAl::Vector<T, D+1> coeff;
 
 public:
-       Polynomial() { }
+       Polynomial() = default;
        Polynomial(const LinAl::Vector<T, D+1> &c): coeff(c) { }
        template<typename U, unsigned G>
        Polynomial(const Polynomial<U, G> &);
index bd606d9d2aa14cbd4f6a1374d819985dd93a4135..7c5e03209e44480fcf3c2dec6f758845637b818b 100644 (file)
@@ -63,12 +63,12 @@ public:
 private:
        enum { STRIDE = sizeof(Segment)-sizeof(Knot) };
 
-       unsigned short n_segments;
-       unsigned short capacity;
-       char *segments;
+       unsigned short n_segments = 0;
+       unsigned short capacity = 0;
+       char *segments = 0;
 
 public:
-       Spline();
+       Spline() = default;
 protected:
        Spline(const Knot &);
 public:
@@ -92,27 +92,15 @@ public:
        Value operator()(T) const;
 };
 
-template<typename T, unsigned D, unsigned N>
-inline Spline<T, D, N>::Spline():
-       n_segments(0),
-       capacity(0),
-       segments(0)
-{ }
-
 template<typename T, unsigned D, unsigned N>
 inline Spline<T, D, N>::Spline(const Knot &k):
-       n_segments(0),
-       capacity(0),
        segments(new char[sizeof(Knot)])
 {
        new(segments) Knot(k);
 }
 
 template<typename T, unsigned D, unsigned N>
-inline Spline<T, D, N>::Spline(const Spline &s):
-       n_segments(0),
-       capacity(0),
-       segments(0)
+inline Spline<T, D, N>::Spline(const Spline &s)
 {
        *this = s;
 }
index de4511c647e870eaf97376127c3195b8ccabe979..74c93611d0b922c4b64098121118d78cd18fa70d 100644 (file)
@@ -21,9 +21,9 @@ public:
        typedef T ElementType;
 
 private:
-       unsigned rows_;
-       unsigned columns_;
-       T *data;
+       unsigned rows_ = 0;
+       unsigned columns_ = 0;
+       T *data = 0;
 
 public:
        DynamicMatrix(unsigned, unsigned);
index a5379d87002cdea25b4059629c1eb5a4c96b358f..7016a7400f381aff0faabe28c18aa2cee81d8cd3 100644 (file)
@@ -29,8 +29,8 @@ public:
        typedef T ElementType;
 
 private:
-       unsigned size_;
-       T *data;
+       unsigned size_ = 0;
+       T *data = 0;
 
 public:
        DynamicVector(unsigned);
index 610ac2103a21ab83e0b58f88905e6d07c6962d2d..1587411c63a767192d907f23a7f470f454a676db 100644 (file)
@@ -19,7 +19,7 @@ private:
        T data[N];
 
 protected:
-       VectorComponents() { }
+       VectorComponents() = default;
 
 public:
        T &operator[](unsigned i) { return data[i]; }
@@ -33,7 +33,7 @@ public:
        T x, y;
 
 protected:
-       VectorComponents() { }
+       VectorComponents() = default;
 
 public:
        T &operator[](unsigned i) { return *(&x+i); }
@@ -47,7 +47,7 @@ public:
        T x, y, z;
 
 protected:
-       VectorComponents() { }
+       VectorComponents() = default;
 
 public:
        T &operator[](unsigned i) { return *(&x+i); }
@@ -61,7 +61,7 @@ public:
        T x, y, z, w;
 
 protected:
-       VectorComponents() { }
+       VectorComponents() = default;
 
 public:
        T &operator[](unsigned i) { return *(&x+i); }