X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=synfig-core%2Ftrunk%2Fsrc%2Fsynfig%2Fvector.h;h=46baff80b1feec4489bc08eb41e7707c24cf1753;hb=9459638ad6797b8139f1e9f0715c96076dbf0890;hp=80ff9761cd91adb6380d5bfa5326d26cbb811ccb;hpb=7e6a1eb31322a853ebc47393a1f3dd6f124b6d33;p=synfig.git diff --git a/synfig-core/trunk/src/synfig/vector.h b/synfig-core/trunk/src/synfig/vector.h index 80ff976..46baff8 100644 --- a/synfig-core/trunk/src/synfig/vector.h +++ b/synfig-core/trunk/src/synfig/vector.h @@ -2,10 +2,11 @@ /*! \file vector.h ** \brief Various discreet type definitions ** -** $Id: vector.h,v 1.2 2005/01/23 04:03:21 darco Exp $ +** $Id$ ** ** \legal ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley +** Copyright (c) 2007 Chris Moore ** ** This package is free software; you can redistribute it and/or ** modify it under the terms of the GNU General Public License as @@ -27,6 +28,7 @@ /* === H E A D E R S ======================================================= */ +#include "angle.h" #include "real.h" #include @@ -71,19 +73,19 @@ private: value_type _x, _y; public: - Vector() { }; + Vector(): _x(0.0), _y(0.0) { }; Vector(const value_type &x, const value_type &y):_x(x),_y(y) { }; bool is_valid()const { return !(isnan(_x) || isnan(_y)); } - + value_type & operator[](const int& i) - { return (&_x)[i] ; } + { return i?_y:_x; } const value_type & operator[](const int& i) const - { return (&_x)[i] ; } - + { return i?_y:_x; } + const Vector & operator+=(const Vector &rhs) { @@ -91,7 +93,7 @@ public: _y+=rhs._y; return *this; } - + const Vector & operator-=(const Vector &rhs) { @@ -99,7 +101,7 @@ public: _y-=rhs._y; return *this; } - + const Vector & operator*=(const value_type &rhs) { @@ -107,7 +109,7 @@ public: _y*=rhs; return *this; } - + const Vector & operator/=(const value_type &rhs) { @@ -116,7 +118,7 @@ public: _y*=tmp; return *this; } - + Vector operator+(const Vector &rhs)const { return Vector(*this)+=rhs; } @@ -144,15 +146,15 @@ public: bool operator==(const Vector &rhs)const { return _x==rhs._x && _y==rhs._y; } - + bool operator!=(const Vector &rhs)const { return _y!=rhs._y || _x!=rhs._x; } - + //! Returns the squared magnitude of the vector value_type mag_squared()const { return _x*_x+_y*_y; } - + //! Returns the magnitude of the vector value_type mag()const { return sqrt(mag_squared()); } @@ -168,14 +170,17 @@ public: //! Returns a perpendicular version of the vector Vector perp()const { return Vector(_y,-_x); } - + + Angle angle()const + { return Angle::rad(atan2(_y, _x)); } + bool is_equal_to(const Vector& rhs)const { static const value_type epsilon(0.0000000000001); // return (_x>rhs._x)?_x-rhs._x<=epsilon:rhs._x-_x<=epsilon && (_y>rhs._y)?_y-rhs._y<=epsilon:rhs._y-_y<=epsilon; return (*this-rhs).mag_squared()<=epsilon; } - + static const Vector zero() { return Vector(0,0); } }; @@ -213,7 +218,7 @@ private: value_type a,b,c,d; protected: - affine_combo affine_func; + affine_combo affine_func; public: bezier_base() { } @@ -221,7 +226,7 @@ public: const value_type &a, const value_type &b, const value_type &c, const value_type &d, const time_type &r=0.0, const time_type &s=1.0): a(a),b(b),c(c),d(d) { set_rs(r,s); sync(); } - + void sync() { bezier_x[0]=a[0],bezier_y[0]=a[1]; @@ -237,11 +242,11 @@ public: { return synfig::Vector(bezier_x(t),bezier_y(t)); } - + void evaluate(time_type t, value_type &f, value_type &df) const { t=(t-get_r())/get_dt(); - + const value_type p1 = affine_func( affine_func(a,b,t), affine_func(b,c,t) @@ -250,7 +255,7 @@ public: affine_func(b,c,t), affine_func(c,d,t) ,t); - + f = affine_func(p1,p2,t); df = (p2-p1)*3; } @@ -271,7 +276,7 @@ public: { return (&a)[i]; } //! Bezier curve intersection function - time_type intersect(const bezier_base &x, time_type near=0.0)const + time_type intersect(const bezier_base &/*x*/, time_type /*near*/=0.0)const { return 0; }