1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#ifndef GFXGEOM_3D_INCLUDED // -*- C++ -*-
#define GFXGEOM_3D_INCLUDED

#include "Vec3.h"
#include "Vec4.h"
#include "Array.h"

class Bounds
{
public:

    Vec3 min, max;
    Vec3 center;
    double radius;
    unsigned int points;

    Bounds() { reset(); }

    void reset();
    void addPoint(const Vec3&);
    void complete();
};

class Plane
{
    //
    // A plane is defined by the equation:  n*p + d = 0
    Vec3 n;
    double d;

public:

    Plane() : n(0,0,1) { d=0; } // -- this will define the XY plane
    Plane(const Vec3& p, const Vec3& q, const Vec3& r) { calcFrom(p,q,r); }
    Plane(const array<Vec3>& verts) { calcFrom(verts); }
    Plane(const Plane& p) { n=p.n; d=p.d; }<--- Variable 'n' is assigned in constructor body. Consider performing initialization in initialization list.

    void calcFrom(const Vec3& p, const Vec3& q, const Vec3& r);
    void calcFrom(const array<Vec3>&);

    bool isValid() const { return n[X]!=0.0 || n[Y]!=0.0 || n[Z]!= 0.0; }
    void markInvalid() { n[X] = n[Y] = n[Z] = 0.0; }

    double distTo(const Vec3& p) const { return n*p + d; }
    const Vec3& normal() const { return n; }

    void coeffs(double *a, double *b, double *c, double *dd) const {
        *a=n[X]; *b=n[Y]; *c=n[Z]; *dd=d;
    }
    Vec4 coeffs() const { return Vec4(n,d); }
};

// GFXGEOM_3D_INCLUDED
#endif