/////////////////////////////////////////////////////////////////////////
//                                                                     //
// This file contains the declaration of the CIntersection class.      //
//                                                                     //
/////////////////////////////////////////////////////////////////////////
#ifndef __CINTERSECTION_HPP__
#define __CINTERSECTION_HPP__


#include "CBooleanSurface.hpp"


/////////////////////////////////////////////////////////////////////////
//                                                                     //
// This class is a constructive geometry implementation for boolean    //
// intersection of two surfaces.                                       //
//                                                                     //
/////////////////////////////////////////////////////////////////////////
class CIntersection : public CBooleanSurface
{
public:
  inline CIntersection(const std::string& strName,
                       CSurface* pOrigSurface1,
                       CSurface* pOrigSurface2);
  virtual ~CIntersection();


  // Interface implementation
  inline virtual CIntersection* Copy() const;


protected:
  // This function describes the boolean operation representing this
  // surface
  virtual bool IsIn(bool surface1, bool surface2) const;

  // This function does the concrete OpenGL drawing of the surface
  virtual void ConcreteDrawGL() const;
};




inline CIntersection::CIntersection(const std::string& strName,
                                    CSurface* pOrigSurface1,
                                    CSurface* pOrigSurface2)
  : CBooleanSurface(strName,
                    pOrigSurface1,
                    pOrigSurface2)
{
}
inline CIntersection::~CIntersection()
{
}
inline CIntersection* CIntersection::Copy() const
{
  return new CIntersection(*this);
}

inline bool CIntersection::IsIn(bool surface1, bool surface2) const
{
  return (surface1 && surface2);
}
inline void CIntersection::ConcreteDrawGL() const
{
  drawInside(pSurface2.get(),
             pSurface1.get(),
             GL_BACK,
             GL_NOTEQUAL);

  drawFixup(pSurface1.get());

  drawInside(pSurface1.get(),
             pSurface2.get(),
             GL_BACK,
             GL_NOTEQUAL);
}




#endif // __CINTERSECTION_HPP__
