/// This file is part of the X3DToolKit library
/// Copyright (C) 2002-2004  Yannick Le Goc (legoc@imag.fr)

/// http://artis.imag.fr/Members/Yannick.Legoc/X3D/

/// This library is free software; you can redistribute it and/or
/// modify it under the terms of the GNU Lesser General Public
/// License as published by the Free Software Foundation; either
/// version 2.1 of the License, or (at your option) any later version.

/// This library is distributed in the hope that it will be useful,
/// but WITHOUT ANY WARRANTY; without even the implied warranty of
/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
/// Lesser General Public License for more details.

/// You should have received a copy of the GNU Lesser General Public
/// License along with this library; if not, write to the Free Software
/// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#ifndef X3DTK_SFPOINT2F_H
#define X3DTK_SFPOINT2F_H

#include "SFVec2f.h"

#include <math.h>
#include <iostream>

namespace X3DTK {

class SFString;

/*! \brief Class declared in <b><X3DTK/kernel.h></b> providing a 2D point.
 * 
 *  SFPoint2f is a point in an affin space, which is different from a vector represented
 *  by the SFVec2f class. 
 *
 *  \ingroup base
 */
 
class SFPoint2f
{
public:
   /// x coordinates.
  float x;
  /// y coordinates.
  float y;

  /// Constructor.
  SFPoint2f();
  /// Constructor with x, y and z coordinates in parameters.
  SFPoint2f(float x, float y);
  /// Copy constructor.
  SFPoint2f(const SFPoint2f &p);
  /// Overloaded assignment operator.
  SFPoint2f &operator= (const SFPoint2f &v);
  /// Overloaded operator.
  SFPoint2f &operator+= (const SFVec2f &v);
  /// Overloaded operator.
  SFPoint2f &operator+= (const SFPoint2f &v);
  /// Overloaded operator.
  SFPoint2f &operator-= (const SFVec2f &v);
  /// Explicit constructor from a string of which format is "x y".
  explicit SFPoint2f(const SFString &s);
  // Conversion from vector to point.
  explicit SFPoint2f(const SFVec2f &V);
  /// Bracket operator.
  inline float &operator[](int i) {return (&x)[i];};
  /// Bracket operator.
  inline const float &operator[](int i) const {return (&x)[i];};
  
   /// Overloaded operator+.
  friend SFPoint2f operator+ (const SFPoint2f &v1, const SFVec2f &v2);
   /// Overloaded operator+.
  friend SFPoint2f operator+ (const SFPoint2f &v1, const SFPoint2f &v2);
  /// Overloaded operator-.
  friend SFPoint2f operator- (const SFPoint2f &v1, const SFVec2f &v2);
  /// Overloaded operator-.
  friend SFVec2f operator- (const SFPoint2f &v1, const SFPoint2f &v2);
  /// Overloaded operator*. 
  friend SFPoint2f operator* (const float a, const SFPoint2f &v);
  /// Returns the distance between the points A and B.
  friend float distance(const SFPoint2f &A, const SFPoint2f &B);
  /// Returns the pointed array.
  inline float *f_data() {return &x;};
  /// Returns the pointed array.
  inline const float *f_data() const {return &x;};
  /// Returns the pointed array.
  inline operator float *() {return &x;};
  /// Returns the pointed array.
  inline operator const float *() const {return &x;};
  /// Origin point.
  static const SFPoint2f null;
};

}

#endif
