/// 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_SFVEC2F_H #define X3DTK_SFVEC2F_H #include "Platform.h" #include #include namespace X3DTK { class SFString; class SFPoint2f; /*! \brief Class declared in providing a 2D vector. * * SFVec2f is a vector in an affin space, which is different from a point represented * by the SFPoint2f class. * * \ingroup base */ class SFVec2f { public: /// x coordinates. float x; /// y coordinates. float y; /// Constructor. SFVec2f(); /// Constructor with x, y and z coordinates in parameters. SFVec2f(float x, float y); /// Copy constructor SFVec2f(const SFVec2f &v); /// Overloaded assignment operator. SFVec2f &operator= (const SFVec2f &v); /// Overloaded operator. SFVec2f &operator+= (const SFVec2f &v); /// Overloaded operator. SFVec2f &operator-= (const SFVec2f &v); /// Explicit constructor from a string of which format is "x y". explicit SFVec2f(const SFString &s); /// Conversion from point to vector. explicit SFVec2f(const SFPoint2f &P); /// 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 bool operator== (const SFVec2f &v1, const SFVec2f &v2); /// Overloaded operator!=. friend bool operator!= (const SFVec2f &v1, const SFVec2f &v2); /// Overloaded operator+. friend SFVec2f operator+ (const SFVec2f &v1, const SFVec2f &v2); /// Overloaded operator-. friend SFVec2f operator- (const SFVec2f &v1, const SFVec2f &v2); /// Overloaded operator-. friend SFVec2f operator- (const SFVec2f &v); /// Overloaded operator*. friend float operator* (const SFVec2f &v1, const SFVec2f &v2); /// Overloaded operator*. friend SFVec2f operator* (const float a, const SFVec2f &v); /// Returns the norm of the vector. float norm() const; /// Normalizes the vector. SFVec2f normalize(); /// Returns the vector normalized but doesn't change the vector. SFVec2f normalized() const; /// 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;}; /// Converts into string. SFString toSFString() const; /// Null vector. static const SFVec2f null; }; } #endif