/*-
 * Copyright (c) 1999,2000 Qube Software, Ltd.
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 * 
 * 1. Redistributions of the source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 
 * 2. Any redistribution solely in binary form must conspicuously
 *    reproduce the following disclaimer in documentation provided with the
 *    binary redistribution.
 * 
 * THIS SOFTWARE IS PROVIDED ``AS IS'', WITHOUT ANY WARRANTIES, EXPRESS
 * OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  LICENSOR SHALL
 * NOT BE LIABLE FOR ANY LOSS OR DAMAGES RESULTING FROM THE USE OF THIS
 * SOFTWARE, EITHER ALONE OR IN COMBINATION WITH ANY OTHER SOFTWARE.
 * 
 * 	$Id: box3.h,v 1.11 2000/04/20 16:21:57 n_hibma Exp $
 */

#ifndef __box3_h__
#define __box3_h__

MATHS_BEGIN

struct Rayf;

struct EXPORT_QMATHS Box3f
{
    Vec3f	min;
    Vec3f	max;

    // Constructors
    Box3f()
    {
    }

    Box3f(float minx, float miny, float minz,
	  float maxx, float maxy, float maxz)
	: min(minx, miny, minz), max(maxx, maxy, maxz)
    {
    }

    Box3f(const Vec3f& vmin, const Vec3f& vmax)
	: min(vmin), max(vmax)
    {
    }
    
    // Accessors
    Vec3f&		operator[](int i) { return (&min)[i]; }
    const Vec3f&	operator[](int i) const { return (&min)[i]; }
    Vec3f		centre() const
    {
	return (min + max) / 2.0f;
    }
    Vec3f		dimensions() const
    {
	return max - min;
    }

    // Modifiers
    void		intersect(const Box3f&);
    void		add(const Box3f&); // union
    void                add(const Vec3f& v);

    // Testing
    bool		operator==(const Box3f& box) const
    {
	return min == box.min && max == box.max;
    }
    bool		equal(const Box3f&, float e = Epsilon) const;
    bool		contains(const Box3f&) const;
    bool		contains(const Vec3f&) const;
    bool		intersects(const Box3f&) const;
    bool		intersects(const Rayf&, float&, float&) const;
    bool		intersects(const Vec3f&,
				   const Vec3f*, int) const;

    // Features
    void                invalidate();
    bool                valid() const;
    bool		intersects(const Vec3f&, float) const;

    // Matrix operations
    Box3f		transform(const Matrix4f& m) const;
    Box3f		inverseTransform(const Matrix4f& m) const;
    Box3f		expandBy(float delta) const;
};

MATHS_END

#endif

