/***************************************************************************
 *                          Zanoza Modeler v2.x                            *
 *      This is unpublished propietary source code of Zanoza Software.     *
 *      The copyright notice does not evidence any actual or intended      *
 *                    publication of such source code.                     *
 *                                                                         *
 *                   Copyright (c) 2003 Zanoza Software.                   *
 *                                                                         *
 *                        All rights reserved.                             *
 ***************************************************************************
 *--------------------------------------------------------------------------
 * @author:   Oleg M.
 *--------------------------------------------------------------------------
 * @purpose:  ZModeler's native 3D plane
 *--------------------------------------------------------------------------
 * @histroy: 08.03.2003. Created
 */
#ifndef zplane_h_included
#define zplane_h_included

#ifndef zsequence_h_included
# include "zsequence.h"
#endif

//------------------------------------------------------
//  ZPlane - ZModeler's native Plane in 3D
//------------------------------------------------------
class DLL_LINKAGE ZPlane
{
public:
  //
  // determines position of the plane relative to something
  enum ePlanePos
  {
    UNDER     =-1,
    INTERSECT = 0,
    LIES_ON   = INTERSECT,
    ABOVE     = 1
  };
  //
  // Constructor/Destructor
  //
  ZPlane();
  ZPlane(const ZPlane& plane);
  ZPlane(const ZPoint3D& center, const ZVector& normal);
  ZPlane(const ZPoint3D& v0, const ZPoint3D& v1, const ZPoint3D& v2);
  ~ZPlane();

public:
  //
  // assignment operators
  //
  ZPlane& operator = ( const ZPlane& plane);


public:
  //
  // operations:
  //
  inline ZVector& normal()    { return m_vecNormal; }
  inline ZVector& position()  { return m_ptCenter;  }
  float       distance(ZPoint3D point);
  ePlanePos   pointPosition(ZPoint3D point, float precision = MINFLOAT);
  // perpendicular projection
  ZPoint3D    projectPoint(ZPoint3D point);
  // perpendicular projection
  bool        projectLine(const ZLine3D& line, ZPoint3D& ptResult);
  //for equation of plane: ax+by+cz+d = 0
  void        getPlaneCoefficients(float& a, float& b, float& c, float& d);
  void        getPlaneData(ZPoint3D& ptOrigin, ZVector& normal) const;
  void        setPlaneData(const ZPoint3D ptOrigin, const ZVector normal);
  // projects lines to the plane and determines whether (and where) they are crossed  
  bool        linesIntersection(
                            const ZLine3D& line1,
                            const ZLine3D& line2,
                            ZPoint3D& ptIntersect);

private:
  //
  // data members:
  //
  ZPoint3D    m_ptCenter;
  ZVector     m_vecNormal; //always normalized;
};

typedef ZSequence<ZPlane>  ZPlaneSeq;


#endif //zplane_h_included

