/***************************************************************************
 *                          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 point float (x,y) or (u,v)
 *--------------------------------------------------------------------------
 * @histroy: 22.04.2003. Created
 */
#ifndef zpoint2d_h_included
#define zpoint2d_h_included

#ifndef zsequence_h_included
# include "zsequence.h"
#endif
#include <core/coreTypes.h>

//------------------------------------------------------
//  ZPoint2D - ZModeler's native 2D Point
//------------------------------------------------------
class DLL_LINKAGE ZPoint2D
{
public:
  //
  // constructors/destructors
  //
  ZPoint2D();
  ZPoint2D(const float _x, const float _y);
  ZPoint2D(const ZPoint2D& point);
  ZPoint2D(const float* initdata); //uses only two floats
  ~ZPoint2D();

public:
  //
  // access grants
  //
  float& operator [] ( core::eAxis component);
  float  operator [] ( core::eAxis component) const;

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

public:
  //
  // assignment operators
  //
  ZPoint2D& operator =  ( const ZPoint2D& p);
  ZPoint2D& operator += ( const ZPoint2D& p);
  ZPoint2D& operator -= ( const ZPoint2D& p);
  ZPoint2D& operator *= ( float v);
  ZPoint2D& operator /= ( float v);

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

public:
  //
  // binary operators
  //
  ZPoint2D operator + ( const ZPoint2D& p) const;
  ZPoint2D operator - ( const ZPoint2D& p) const;
  float    operator * ( const ZPoint2D& p) const; //cross product
  ZPoint2D operator * ( float v) const;
  ZPoint2D operator / ( float v) const;
  float    operator ^ ( const ZPoint2D& p) const; //dot product

public:
  //
  // friend operators
  //
  friend DLL_LINKAGE ZPoint2D operator * ( const float v, const ZPoint2D& p);

public:
  //
  // compare operators
  //
  bool operator == ( const ZPoint2D& p) const;
  bool operator != ( const ZPoint2D& p) const;
  bool operator < ( const ZPoint2D& p) const;
  bool operator <= ( const ZPoint2D& p) const;

public:
  //
  // operations
  //
  float   length() const;
  float   length2() const;
  float   distance( const ZPoint2D& p) const;
  inline float   distance2( const ZPoint2D& p) const
    { return (p.x-x)*(p.x-x) + (p.y-y)*(p.y-y); }

  ZAngle  angle( const ZPoint2D& p) const;
  bool    normalize();


public:
  //
  // data members
  //
  union
  {
    struct
    {
      float x, y;
    };
    struct
    {
      float u, v;
    };
  };
};

//
// adjacent typedefs:
typedef ZSequence<ZPoint2D>   ZPoint2DSeq;


#endif //zpoint2d_h_included

