#ifndef __BSPHERE3_H__
#define __BSPHERE3_H__

#include <iostream>
#include <cassert>
#include <cmath>

#include "vector3.h"

#include "public.h"


namespace xrt {


// The BSphere3 class is for 3D bounding spheres.
//
// We GUARANTEE that the memory layout and size of a BSphere3 is
// identical to a float[4], and thus it's presumed relatively
// safe to cast between a (float *) and a (BSphere3 *).
//
// Semantics are as described below: construction from four floats
// or one Vector3 and a float.

class PUBLIC BSphere3 {

public:

    // Default constructor leaves contents undefined
    BSphere3 (void) { }

    // Constructor from four floats fill in the BSphere values
    BSphere3 (float xcenter, float ycenter, float zcenter, float radius = 0.f) : center (xcenter, ycenter, zcenter),  radius (radius) { }

    // Constructor from a Vector3 and a float
    BSphere3 (const Vector3 &center, float radius = 0.f) : center (center),  radius (radius) { }

    // Direct access to the data -- use with caution
    const float *data(void) const { return b; }

    // Component access
    float operator[] (int i) const {
	assert(i>=0 && i < 4);  // range check -- only in DEBUG mode
	return b[i];
    }
    float& operator[] (int i) {
	assert(i>=0 && i < 4);  // range check -- only in DEBUG mode
	return b[i];
    }


public:
    union {
		float b[4];     // xcenter, ycenter, zcenter, radius
		struct { Vector3 center; float radius; };
	};
};


};  /* end namespace xrt */


#endif  /* !defined(__BSPHERE3_H__) */