10 extern double operator*(
const Vec2f& v,
const Vec2f& w);
11 extern Vec2f operator*(
const double scalar,
const Vec2f& v);
12 extern Vec2f operator*(
const Vec2f& v,
const double scalar);
13 extern Vec2f operator/(
const Vec2f& v,
const double scalar);
14 extern Vec2f operator/(
const double scalar,
const Vec2f& v);
15 extern Vec2f operator-(
const double scalar,
const Vec2f& v);
22 Vec2f(
const Vec2f& v);
24 Vec2f(
double xx,
double yy){ x=xx; y=yy;}
25 Vec2f(
double xx[2]) { x = xx[0]; y = xx[1]; }
26 Vec2f(
const double xx[2]) { x = xx[0]; y = xx[1]; }
29 inline void setZero() { x=y=0.f; }
30 inline bool isZero()
const {
return x==0.f && y==0.f; }
31 Vec2f rangeCut(
const double &border)
const;
32 Vec2f rangeCut(
const double &lower_border,
const double &upper_border)
const;
33 double getmax()
const {
return x>y ? x : y; }
34 double getmin()
const {
return x<y ? x : y; }
36 Vec2f mapped(
double (*func)(
double)) {
return Vec2f(func(x), func(y)); }
37 void map(
double (*func)(
double)) { x = func(x); y = func(y); }
38 inline Vec2f operator+(
const double& t)
const {
return Vec2f(x+t, y+t);}
39 inline Vec2f operator-(
const double& t)
const {
return Vec2f(x-t, y-t);}
40 inline Vec2f operator+(
const Vec2f& v)
const {
return Vec2f(x+v.x, y+v.y);}
41 inline Vec2f operator-()
const {
return Vec2f(-x, -y);}
42 inline Vec2f operator-(
const Vec2f& v)
const {
return Vec2f(x-v.x, y-v.y);}
43 inline Vec2f& operator/=(
const Vec2f& v) { x/=v.x; y/=v.y;
return *
this;}
44 inline Vec2f operator/(
const Vec2f& v)
const {
return Vec2f(x/v.x, y/v.y);}
45 inline Vec2f operator%(
const Vec2f& v)
const {
return Vec2f(x*v.x, y*v.y);}
46 inline Vec2f operator%=(
const Vec2f& v)
const {
return Vec2f(x*v.x, y*v.y);}
47 inline bool operator==(
const Vec2f& v)
const {
return (x==v.x) && (y==v.y);}
48 inline bool operator!=(
const Vec2f& v)
const {
return (x!=v.x) || (y!=v.y);}
50 inline Vec2f& operator=(
const Vec2f& v){ x=v.x; y=v.y;
return *
this;}
51 inline Vec2f& operator*=(
const double scalar){ x*=scalar;y*=scalar;
return *
this;}
52 inline Vec2f& operator/=(
const double scalar){ x/=scalar;y/=scalar;
return *
this;}
53 inline Vec2f& operator+=(
const Vec2f& v){ x+=v.x; y+=v.y;
return *
this;}
54 inline Vec2f& operator-=(
const Vec2f& v){ x-=v.x; y-=v.y;
return *
this;}
57 inline Vec2f& projectTo(
const Vec2f& to)
59 *
this = to * ( ((*this) * to) / to.norm2());
63 inline Vec2f projectionTo(
const Vec2f& to)
const
70 double ellipseDist(
const Vec2f &p)
const
78 inline double cross(
const Vec2f& v2)
const {
return x*v2.y-y*v2.x; };
80 inline double norm1()
const {
return qAbs(x) + qAbs(y);}
82 inline double norm()
const {
return sqrt(x*x+y*y);}
84 inline double norm2()
const {
return x*x+y*y;}
86 inline double angle()
const {
return atan2(y,x); }
87 inline void normalize()
101 inline Vec2f normalize()
const
105 return Vec2f(x / n, y / n);
111 inline double dist(
const Vec2f& v)
const {
return (*
this-v).norm();}
113 inline double dist2(
const Vec2f& v)
const {
return (*
this-v).norm2();}
115 bool isLeftOf(
const Vec2f& v)
const
117 return (v.x * y - x * v.y) < 0;
120 inline void rotate(
double angle)
124 x = x_ * cos(angle) + y_ * -sin(angle);
125 y = x_ * sin(angle) + y_ * cos(angle);
128 inline Vec2f rotated(
double angle)
const
135 inline bool operator<(
const Vec2f& v )
const
137 return norm2() < v.norm2();
141 QDebug operator<<(QDebug dbg,
const Vec2f &v);