/***************************************************************************
 *                          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) 2002 Zanoza Software.                   *
 *                                                                         *
 *                        All rights reserved.                             *
 ***************************************************************************
 *--------------------------------------------------------------------------
 * @author:   Oleg M.
 *--------------------------------------------------------------------------
 * @purpose:  ZModeler's native 2d screen-coord line
 *--------------------------------------------------------------------------
 * @histroy: 09.03.2003. Created
 */
#ifndef zline_h_included
#define zline_h_included

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


//------------------------------------------------------
//  ZLine - ZModeler's native line (2d screen-coord line)
//------------------------------------------------------
class DLL_LINKAGE ZLine
{
public:
  //
  // constructors/destructors
  //
  ZLine();
  ZLine(const ZPoint pos, const ZPoint dir);
  ZLine(const ZLine& line);
  ZLine(const long px, const long py, const long dx, const long dy);
  ~ZLine();

public:
  //
  // access grants
  //
  ZPoint& operator [] ( int npoint ); // 0 : position else : direction
  ZPoint  operator [] ( int npoint ) const;

public:
  //
  // casting operators
  //
  operator ZPoint* ();
  operator const ZPoint* () const;

public:
  //
  // assignment operators
  //
  ZLine& operator =  ( const ZLine& l);

public:
  //
  // unary operators
  //
  ZLine operator + () const;
  ZLine operator - () const;

public:
  //
  // binary operators
  //
  float operator * ( const ZLine& l) const; //dot product


public:
  //
  // compare operators
  //
  bool operator == ( const ZLine& l) const;
  bool operator != ( const ZLine& l) const;

public:
  //
  // operations
  //
  float   length() const;
  float   length2() const;
  float   distance( const ZLine& l) const;
  //distance to infinite line
  float   distance( const ZPoint& p) const;
  //distance to finit line segment
  ZPoint  nearest( const ZPoint& p) const;
  bool    cross( const ZLine& line, ZPoint* pThisCross, ZPoint* pOtherCross = NULL) const;
  ZAngle  angle( const ZLine& line) const;//direction only 
  float   sin( const ZLine& line) const;
  float   cos( const ZLine& line) const;
  ZLine&  rotate( const ZAngle angle);
  ZLine&  scale( const float scale);
  ZLine&  pointTo( const ZPoint& p);
  ZLine&  moveTo( const ZPoint& position);
  ZLine&  move( const ZPoint& offset);
  ZLine&  toOrigin();
  bool    isVertical() const;
  bool    isHorizontal() const;
  ZLine&  makeVertical(bool changePosition = false);
  ZLine&  makeHorizontal(bool changePosition = false);


private:
  //
  // data members
  //
  ZPoint  m_pos, m_dir;
};

//
// adjacent typedefs:
typedef ZSequence<ZLine>   ZLineSeq;


#endif //zline_h_included

