/usr/include/synfig-1.0/synfig/vector.h is in libsynfig-dev 1.2.1-0ubuntu4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 | /* === S Y N F I G ========================================================= */
/*! \file vector.h
** \brief Various discreet type definitions
**
** $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
** published by the Free Software Foundation; either version 2 of
** the License, or (at your option) any later version.
**
** This package 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
** General Public License for more details.
** \endlegal
*/
/* ========================================================================= */
/* === S T A R T =========================================================== */
#ifndef __SYNFIG_VECTOR_H
#define __SYNFIG_VECTOR_H
/* === H E A D E R S ======================================================= */
#include "angle.h"
#include "real.h"
#include <cmath>
/* === M A C R O S ========================================================= */
/* === T Y P E D E F S ===================================================== */
/* === C L A S S E S & S T R U C T S ======================================= */
namespace synfig {
/*! \class VectorInt
** \todo writeme
*/
class VectorInt
{
public:
typedef int value_type;
protected:
value_type _x, _y;
public:
VectorInt(): _x(0), _y(0) { };
VectorInt(const value_type &x, const value_type &y):_x(x),_y(y) { };
static VectorInt zero() { return VectorInt(0, 0); }
value_type &
operator[](const int& i)
{ return i ? _y: _x; }
const value_type &
operator[] (const int& i) const
{ return i ? _y: _x; }
const VectorInt &
operator+=(const VectorInt &rhs)
{
_x += rhs._x;
_y += rhs._y;
return *this;
}
const VectorInt &
operator-=(const VectorInt &rhs)
{
_x -= rhs._x;
_y -= rhs._y;
return *this;
}
const VectorInt &
operator*=(const value_type &rhs)
{
_x *= rhs;
_y *= rhs;
return *this;
}
const VectorInt &
operator/=(const value_type &rhs)
{
_x /= rhs;
_y /= rhs;
return *this;
}
VectorInt
operator+(const VectorInt &rhs)const
{ return VectorInt(*this) += rhs; }
VectorInt
operator-(const VectorInt &rhs)const
{ return VectorInt(*this) -= rhs; }
VectorInt
operator*(const value_type &rhs)const
{ return VectorInt(*this) *= rhs; }
VectorInt
operator/(const value_type &rhs)const
{ return VectorInt(*this) /= rhs; }
VectorInt
operator-()const
{ return VectorInt(-_x,-_y); }
value_type
operator*(const VectorInt &rhs)const
{ return _x*rhs._x+_y*rhs._y; }
bool
operator==(const VectorInt &rhs)const
{ return _x==rhs._x && _y==rhs._y; }
bool
operator!=(const VectorInt &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
Real mag()const
{ return sqrt(mag_squared()); }
//! Returns the reciprocal of the magnitude of the vector
Real inv_mag()const
{ return 1.0/sqrt(mag_squared()); }
//! Returns a perpendicular version of the vector
VectorInt perp()const
{ return VectorInt(_y,-_x); }
Angle angle()const
{ return Angle::rad(atan2(_y, _x)); }
VectorInt multiply_coords(const VectorInt &rhs) const
{ return VectorInt(_x*rhs._x, _y*rhs._y); }
VectorInt divide_coords(const VectorInt &rhs) const
{ return VectorInt(_x/rhs._x, _y/rhs._y); }
};
/*! \typedef PointInt
** \todo writeme
*/
typedef VectorInt PointInt;
/*! \class Vector
** \todo writeme
*/
class Vector
{
public:
typedef Real value_type;
private:
value_type _x, _y;
public:
Vector(): _x(0.0), _y(0.0) { };
Vector(const value_type &x, const value_type &y):_x(x),_y(y) { };
Vector(const value_type &radius, const Angle &angle):
_x(radius*Angle::cos(angle).get()),
_y(radius*Angle::sin(angle).get())
{ };
bool is_valid()const { return !(std::isnan(_x) || std::isnan(_y)); }
bool is_nan_or_inf()const { return std::isnan(_x) || std::isnan(_y) || std::isinf(_x) || std::isinf(_y); }
bool
operator<(const Vector &rhs)const
{
return _x<rhs._x ? true
: rhs._x<_x ? false
: _y<rhs._y;
}
value_type &
operator[](const int& i)
{ return i?_y:_x; }
const value_type &
operator[](const int& i) const
{ return i?_y:_x; }
const Vector &
operator+=(const Vector &rhs)
{
_x+=rhs._x;
_y+=rhs._y;
return *this;
}
const Vector &
operator-=(const Vector &rhs)
{
_x-=rhs._x;
_y-=rhs._y;
return *this;
}
const Vector &
operator*=(const value_type &rhs)
{
_x*=rhs;
_y*=rhs;
return *this;
}
const Vector &
operator/=(const value_type &rhs)
{
value_type tmp=1.0/rhs;
_x*=tmp;
_y*=tmp;
return *this;
}
Vector
operator+(const Vector &rhs)const
{ return Vector(*this)+=rhs; }
Vector
operator-(const Vector &rhs)const
{ return Vector(*this)-=rhs; }
Vector
operator*(const value_type &rhs)const
{ return Vector(*this)*=rhs; }
Vector
operator/(const value_type &rhs)const
{ return Vector(*this)/=rhs; }
Vector
operator-()const
{ return Vector(-_x,-_y); }
value_type
operator*(const Vector &rhs)const
{ return _x*rhs._x+_y*rhs._y; }
bool
operator==(const Vector &rhs)const
{ return is_equal_to(rhs); }
bool
operator!=(const Vector &rhs)const
{ return !(*this == rhs); }
//! 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()); }
//! Returns the reciprocal of the magnitude of the vector
value_type inv_mag()const
{ return 1.0/sqrt(mag_squared()); }
//! Returns a normalized version of the vector
Vector norm()const
{ return (*this)*inv_mag(); }
//! 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
{ return approximate_equal((*this-rhs).mag_squared(), value_type(0.0)); }
static Vector zero() { return Vector(0,0); }
Vector multiply_coords(const Vector &rhs) const
{ return Vector(_x*rhs._x, _y*rhs._y); }
Vector divide_coords(const Vector &rhs) const
{ return Vector(_x/rhs._x, _y/rhs._y); }
Vector one_divide_coords() const
{ return Vector(1.0/_x, 1.0/_y); }
Vector rotate(const Angle &rhs) const
{
value_type s = Angle::sin(rhs).get();
value_type c = Angle::cos(rhs).get();
return Vector(c*_x - s*_y, s*_x + c*_y);
}
};
/*! \typedef Point
** \todo writeme
*/
typedef Vector Point;
}; // END of namespace synfig
namespace std {
inline synfig::Vector::value_type
abs(const synfig::Vector &rhs)
{ return rhs.mag(); }
}; // END of namespace std
#include <ETL/bezier>
_ETL_BEGIN_NAMESPACE
template <>
class bezier_base<synfig::Vector,float> : public std::unary_function<float,synfig::Vector>
{
public:
typedef synfig::Vector value_type;
typedef float time_type;
private:
bezier_base<synfig::Vector::value_type,time_type> bezier_x,bezier_y;
value_type a,b,c,d;
protected:
affine_combo<value_type,time_type> affine_func;
public:
bezier_base() { }
bezier_base(
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];
bezier_x[1]=b[0],bezier_y[1]=b[1];
bezier_x[2]=c[0],bezier_y[2]=c[1];
bezier_x[3]=d[0],bezier_y[3]=d[1];
bezier_x.sync();
bezier_y.sync();
}
value_type
operator()(time_type t)const
{
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)
,t);
const value_type p2 = affine_func(
affine_func(b,c,t),
affine_func(c,d,t)
,t);
f = affine_func(p1,p2,t);
df = (p2-p1)*3;
}
void set_rs(time_type new_r, time_type new_s) { bezier_x.set_rs(new_r,new_s); bezier_y.set_rs(new_r,new_s); }
void set_r(time_type new_r) { bezier_x.set_r(new_r); bezier_y.set_r(new_r); }
void set_s(time_type new_s) { bezier_x.set_s(new_s); bezier_y.set_s(new_s); }
const time_type &get_r()const { return bezier_x.get_r(); }
const time_type &get_s()const { return bezier_x.get_s(); }
time_type get_dt()const { return bezier_x.get_dt(); }
value_type &
operator[](int i)
{ return (&a)[i]; }
const value_type &
operator[](int i) const
{ return (&a)[i]; }
//! Bezier curve intersection function
time_type intersect(const bezier_base<value_type,time_type> &/*x*/, time_type /*near*/=0.0)const
{
return 0;
}
};
_ETL_END_NAMESPACE
/* === E N D =============================================================== */
#endif
|