//-----------------------------------------------------------------------------
// NastBox2d.cpp
//-----------------------------------------------------------------------------

#include "NastBox2d.h"
#include "NastDebug.h"

#include <signal.h>		// Workaround fuer einen Bug in HP-Includefiles
#include <limits.h>

#ifdef _MSC_VER
#  include <float.h>
#endif


//-----------------------------------------------------------------------------
//                             Hilfsfunktionen
//-----------------------------------------------------------------------------

//  naja der min,max Dauerbrenner
static inline double NastMin( double a, double b)
{
    if( a < b ) 
        return a;
    else
        return b;
}

static inline double NastMax( double a, double b)
{
    if( a > b ) 
        return a;
    else
        return b;
}


//-----------------------------------------------------------------------------
//                    Konstruktor + Destruktor
//-----------------------------------------------------------------------------

//  Konstruktor
CNastBox2d::CNastBox2d( double x0, double y0, double x1, double y1)
    :m_pntMin( NastMin( x0, x1 ),
               NastMin( y0, y1 )),
     m_pntMax( NastMax( x0, x1 ),
               NastMax( y0, y1 ))
{}

CNastBox2d::CNastBox2d( const CNastPoint2d &pnt1, const CNastPoint2d &pnt2)
    :m_pntMin( NastMin( pnt1.x(), pnt2.x()),
               NastMin( pnt1.y(), pnt2.y())),
     m_pntMax( NastMax( pnt1.x(), pnt2.x()),
               NastMax( pnt1.y(), pnt2.y()))
{}

CNastBox2d::CNastBox2d( const CNastPoint2d &pntOrigin, const double sizeX, const double sizeY )
    :m_pntMin( pntOrigin ),
     m_pntMax( pntOrigin + CNastVector2d( sizeX, sizeY))
{}


//  Destruktor
CNastBox2d::~CNastBox2d()
{
//  Muell in die Datenmember schreiben damit falsche Zugriff schnell erkannt werden
#ifdef NAST_DEBUG
    m_pntMin = CNastPoint2d( DBL_MAX,DBL_MAX);
    m_pntMax = CNastPoint2d( DBL_MAX,DBL_MAX);
#endif
}

//  Copyconstr.
CNastBox2d::CNastBox2d( const CNastBox2d &other )
    :CNastObject( other),
     m_pntMin( other.m_pntMin ),
     m_pntMax( other.m_pntMax )    
{}

//  Zuweisungsoperator
const CNastBox2d&
CNastBox2d::operator=( const CNastBox2d &other )
{
    if( this != &other )		//  keine Zuweisung auf sich selbst ?
    {
        CNastObject::operator=( other );
        m_pntMin = other.m_pntMin;
        m_pntMax = other.m_pntMax;
    }
    
    return *this;
}


// ----------------------------------------------------------------------------
//                                    Debug
// ----------------------------------------------------------------------------

void 
CNastBox2d::debugDump( CNastDumpContext &dumpContext ) const
{
    CNastObject::debugDump( dumpContext );
    dumpContext << "\tCNastBox2d" << "\n";
    dumpContext << "\t\tGroesse : X:" << sizeX();
    dumpContext << " Y:" << sizeY();
    dumpContext << "\n";
    dumpContext << "\t\tpntMin  : X:";
    dumpContext << m_pntMin.x();
    dumpContext << " Y:" << m_pntMin.y() << "\n";
    dumpContext << "\t\tpntMax  : X:";
    dumpContext << m_pntMax.x();
    dumpContext << " Y:" << m_pntMax.y() << "\n";
}

void 
CNastBox2d::assertValid() const
{
    // zuerst einmal AssertValid der Basisklasse aufrufen
    CNastObject::assertValid(); 
}


