70 inline vec2() { v[0] = v[1] = 0; }
73 inline vec2(
const ivec2& a) { v[0] = a[0]; v[1] = a[1]; }
74 inline vec2(
const vec2& a) { v[0] = a[0]; v[1] = a[1]; }
78 inline Real& operator[] (
int i) {
return v[i]; }
79 inline const Real& operator[] (
int i)
const {
return v[i]; }
80 inline Real& operator() (
int i) {
return v[i % 2]; }
81 inline const Real& operator() (
int i)
const {
return v[i % 2]; }
86 inline bool is_zero()
const {
return (v[0] == 0.0 && v[1] == 0.0); }
88 return (fabs(v[0]) <= tiny_tol && fabs(v[1]) <= tiny_tol);
104 bool is_perpendicular(
131 inline vec2
operator + (
const vec2& a,
const vec2& b)
134 for (
int i = 0; i < 2; ++i) { c[i] = a[i] + b[i]; }
141 for (
int i = 0; i < 2; ++i) { c[i] = a + b[i]; }
148 for (
int i = 0; i < 2; ++i) { c[i] = a[i] + b; }
154 inline vec2
operator - (
const vec2& a,
const vec2& b)
157 for (
int i = 0; i < 2; ++i) { c[i] = a[i] - b[i]; }
164 for (
int i = 0; i < 2; ++i) { c[i] = a - b[i]; }
171 for (
int i = 0; i < 2; ++i) { c[i] = a[i] - b; }
177 inline vec2
operator * (
const vec2& a,
const vec2& b)
180 for (
int i = 0; i < 2; ++i) { c[i] = a[i] * b[i]; }
187 for (
int i = 0; i < 2; ++i) { c[i] = a * b[i]; }
194 for (
int i = 0; i < 2; ++i) { c[i] = a[i] * b; }
200 inline vec2
operator / (
const vec2& a,
const vec2& b)
203 for (
int i = 0; i < 2; ++i) { c[i] = a[i] / b[i]; }
210 for (
int i = 0; i < 2; ++i) { c[i] = a / b[i]; }
217 for (
int i = 0; i < 2; ++i) { c[i] = a[i] / b; }
277 inline int operator == (
const vec2& a,
const vec2& b)
280 for (
int i = 0; i < 2; ++i) { c = c & (a[i] == b[i]); }
287 for (
int i = 0; i < 2; ++i) { c = c & (a == b[i]); }
294 for (
int i = 0; i < 2; ++i) { c = c & (a[i] == b); }
300 inline int operator < (
const vec2& a,
const vec2& b)
303 for (
int i = 0; i < 2; ++i) { c = c & (a[i] < b[i]); }
310 for (
int i = 0; i < 2; ++i) { c = c & (a < b[i]); }
317 for (
int i = 0; i < 2; ++i) { c = c & (a[i] < b); }
323 inline int operator <= (
const vec2& a,
const vec2& b)
326 for (
int i = 0; i < 2; ++i) { c = c & (a[i] <= b[i]); }
333 for (
int i = 0; i < 2; ++i) { c = c & (a <= b[i]); }
340 for (
int i = 0; i < 2; ++i) { c = c & (a[i] <= b); }
346 inline int operator > (
const vec2& a,
const vec2& b)
349 for (
int i = 0; i < 2; ++i) { c = c & (a[i] > b[i]); }
356 for (
int i = 0; i < 2; ++i) { c = c & (a > b[i]); }
363 for (
int i = 0; i < 2; ++i) { c = c & (a[i] > b); }
369 inline int operator >= (
const vec2& a,
const vec2& b)
372 for (
int i = 0; i < 2; ++i) { c = c & (a[i] >= b[i]); }
379 for (
int i = 0; i < 2; ++i) { c = c & (a >= b[i]); }
386 for (
int i = 0; i < 2; ++i) { c = c & (a[i] >= b); }
396 for (
int i = 0; i < 2; ++i) { c[i] = -a[i]; }
411 inline Real inner(
const vec2& a,
const vec2& b)
419 return sqrt(
inner(a, a));
426 inline vec2
unit(
const vec2& a)
435 inline Real angle(
const vec2& a,
const vec2& b)
446 inline vec2
proj(
const vec2& axis,
const vec2& a)
449 return inner(a, u) * u;
452 inline vec2
absolute(
const vec2& val)
454 return vec2(fabs(val[0]), fabs(val[1]));
457 void store(FILE* fp,
const vec2& v);
460 int apx_equal(
const vec2& a,
const vec2& b);
470 inline vec3() { v[0] = v[1] = v[2] = 0; }
473 inline vec3(
const ivec3& a) { v[0] = a[0]; v[1] = a[1]; v[2] = a[2]; }
474 inline vec3(
const vec3& a) { v[0] = a[0]; v[1] = a[1]; v[2] = a[2]; }
477 inline Real& operator[] (
int i) {
return v[i]; }
478 inline const Real& operator[] (
int i)
const {
return v[i]; }
479 inline Real& operator() (
int i) {
return v[i % 3]; }
480 inline const Real& operator() (
int i)
const {
return v[i % 3]; }
482 inline bool is_zero()
const {
return (v[0] == 0.0 && v[1] == 0.0 && v[2] == 0.0); }
483 inline bool is_tiny(
Real tiny_tol =
epsilon)
const {
return (fabs(v[0]) <= tiny_tol && fabs(v[1]) <= tiny_tol && fabs(v[2]) <= tiny_tol); }
503 bool is_perpendicular(
526 inline vec3
operator + (
const vec3& a,
const vec3& b)
529 for (
int i = 0; i < 3; ++i) { c[i] = a[i] + b[i]; }
536 for (
int i = 0; i < 3; ++i) { c[i] = a + b[i]; }
543 for (
int i = 0; i < 3; ++i) { c[i] = a[i] + b; }
549 inline vec3
operator - (
const vec3& a,
const vec3& b)
552 for (
int i = 0; i < 3; ++i) { c[i] = a[i] - b[i]; }
559 for (
int i = 0; i < 3; ++i) { c[i] = a - b[i]; }
566 for (
int i = 0; i < 3; ++i) { c[i] = a[i] - b; }
572 inline vec3
operator * (
const vec3& a,
const vec3& b)
575 for (
int i = 0; i < 3; ++i) { c[i] = a[i] * b[i]; }
582 for (
int i = 0; i < 3; ++i) { c[i] = a * b[i]; }
589 for (
int i = 0; i < 3; ++i) { c[i] = a[i] * b; }
595 inline vec3
operator / (
const vec3& a,
const vec3& b)
598 for (
int i = 0; i < 3; ++i) { c[i] = a[i] / b[i]; }
605 for (
int i = 0; i < 3; ++i) { c[i] = a / b[i]; }
612 for (
int i = 0; i < 3; ++i) { c[i] = a[i] / b; }
670 inline int operator == (
const vec3& a,
const vec3& b)
673 for (
int i = 0; i < 3; ++i) { c = c & (a[i] == b[i]); }
680 for (
int i = 0; i < 3; ++i) { c = c & (a == b[i]); }
687 for (
int i = 0; i < 3; ++i) { c = c & (a[i] == b); }
693 inline int operator < (
const vec3& a,
const vec3& b)
696 for (
int i = 0; i < 3; ++i) { c = c & (a[i] < b[i]); }
703 for (
int i = 0; i < 3; ++i) { c = c & (a < b[i]); }
710 for (
int i = 0; i < 3; ++i) { c = c & (a[i] < b); }
716 inline int operator <= (
const vec3& a,
const vec3& b)
719 for (
int i = 0; i < 3; ++i) { c = c & (a[i] <= b[i]); }
726 for (
int i = 0; i < 3; ++i) { c = c & (a <= b[i]); }
733 for (
int i = 0; i < 3; ++i) { c = c & (a[i] <= b); }
739 inline int operator > (
const vec3& a,
const vec3& b)
742 for (
int i = 0; i < 3; ++i) { c = c & (a[i] > b[i]); }
749 for (
int i = 0; i < 3; ++i) { c = c & (a > b[i]); }
756 for (
int i = 0; i < 3; ++i) { c = c & (a[i] > b); }
762 inline int operator >= (
const vec3& a,
const vec3& b)
765 for (
int i = 0; i < 3; ++i) { c = c & (a[i] >= b[i]); }
772 for (
int i = 0; i < 3; ++i) { c = c & (a >= b[i]); }
779 for (
int i = 0; i < 3; ++i) { c = c & (a[i] >= b); }
789 for (
int i = 0; i < 3; ++i) { c[i] = -a[i]; }
793 inline vec3
absolute(
const vec3& val)
795 return vec3(fabs(val[0]), fabs(val[1]), fabs(val[2]));
814 inline Real inner(
const vec3& a,
const vec3& b)
826 return sqrt(
inner(a, a));
829 inline vec3
unit(
const vec3& a)
838 inline Real angle(
const vec3& a,
const vec3& b)
849 inline vec3
proj(
const vec3& axis,
const vec3& a)
852 return inner(a, u) * u;
855 void store(FILE* fp,
const vec3& v);
858 int apx_equal(
const vec3& a,
const vec3& b);
868 inline vec4() { v[0] = v[1] = v[2] = v[3] = 0; }
869 inline vec4(
Real a) { v[0] = v[1] = v[2] = v[3] = a; }
871 inline vec4(
const ivec4& a) { v[0] = a[0]; v[1] = a[1]; v[2] = a[2]; v[3] = a[3]; }
872 inline vec4(
const vec4& a) { v[0] = a[0]; v[1] = a[1]; v[2] = a[2]; v[3] = a[3]; }
874 inline vec4&
operator=(
const vec4& a) { v[0] = a[0]; v[1] = a[1]; v[2] = a[2]; v[3] = a[3];
return *
this; }
875 inline Real& operator[] (
int i) {
return v[i]; }
876 inline const Real& operator[] (
int i)
const {
return v[i]; }
877 inline Real& operator() (
int i) {
return v[i % 4]; }
878 inline const Real& operator() (
int i)
const {
return v[i % 4]; }
880 inline bool is_zero()
const {
return (v[0] == 0.0 && v[1] == 0.0 && v[2] == 0.0 && v[3] == 0.0); }
882 return (fabs(v[0]) <= tiny_tol && fabs(v[1]) <= tiny_tol && fabs(v[2]) <= tiny_tol && fabs(v[3]) <= tiny_tol);
896 inline vec4
operator + (
const vec4& a,
const vec4& b)
899 for (
int i = 0; i < 4; ++i) { c[i] = a[i] + b[i]; }
906 for (
int i = 0; i < 4; ++i) { c[i] = a + b[i]; }
913 for (
int i = 0; i < 4; ++i) { c[i] = a[i] + b; }
919 inline vec4
operator - (
const vec4& a,
const vec4& b)
922 for (
int i = 0; i < 4; ++i) { c[i] = a[i] - b[i]; }
929 for (
int i = 0; i < 4; ++i) { c[i] = a - b[i]; }
936 for (
int i = 0; i < 4; ++i) { c[i] = a[i] - b; }
942 inline vec4
operator * (
const vec4& a,
const vec4& b)
945 for (
int i = 0; i < 4; ++i) { c[i] = a[i] * b[i]; }
952 for (
int i = 0; i < 4; ++i) { c[i] = a * b[i]; }
959 for (
int i = 0; i < 4; ++i) { c[i] = a[i] * b; }
965 inline vec4
operator / (
const vec4& a,
const vec4& b)
968 for (
int i = 0; i < 4; ++i) { c[i] = a[i] / b[i]; }
975 for (
int i = 0; i < 4; ++i) { c[i] = a / b[i]; }
982 for (
int i = 0; i < 4; ++i) { c[i] = a[i] / b; }
1042 inline int operator == (
const vec4& a,
const vec4& b)
1045 for (
int i = 0; i < 4; ++i) { c = c & (a[i] == b[i]); }
1052 for (
int i = 0; i < 4; ++i) { c = c & (a == b[i]); }
1059 for (
int i = 0; i < 4; ++i) { c = c & (a[i] == b); }
1065 inline int operator < (
const vec4& a,
const vec4& b)
1068 for (
int i = 0; i < 4; ++i) { c = c & (a[i] < b[i]); }
1075 for (
int i = 0; i < 4; ++i) { c = c & (a < b[i]); }
1082 for (
int i = 0; i < 4; ++i) { c = c & (a[i] < b); }
1088 inline int operator <= (
const vec4& a,
const vec4& b)
1091 for (
int i = 0; i < 4; ++i) { c = c & (a[i] <= b[i]); }
1098 for (
int i = 0; i < 4; ++i) { c = c & (a <= b[i]); }
1105 for (
int i = 0; i < 4; ++i) { c = c & (a[i] <= b); }
1111 inline int operator > (
const vec4& a,
const vec4& b)
1114 for (
int i = 0; i < 4; ++i) { c = c & (a[i] > b[i]); }
1121 for (
int i = 0; i < 4; ++i) { c = c & (a > b[i]); }
1128 for (
int i = 0; i < 4; ++i) { c = c & (a[i] > b); }
1134 inline int operator >= (
const vec4& a,
const vec4& b)
1137 for (
int i = 0; i < 4; ++i) { c = c & (a[i] >= b[i]); }
1144 for (
int i = 0; i < 4; ++i) { c = c & (a >= b[i]); }
1151 for (
int i = 0; i < 4; ++i) { c = c & (a[i] >= b); }
1161 for (
int i = 0; i < 4; ++i) { c[i] = -a[i]; }
1165 inline vec4
absolute(
const vec4& val)
1167 return vec4(fabs(val[0]), fabs(val[1]), fabs(val[2]), fabs(val[3]));
1172 inline Real sum(
const vec4& a)
1187 inline Real inner(
const vec4& a,
const vec4& b)
1197 return sqrt(
inner(a, a));
1200 inline vec4
unit(
const vec4& a)
1209 inline Real angle(
const vec4& a,
const vec4& b)
1220 inline vec4
proj(
const vec4& axis,
const vec4& a)
1222 vec4 u =
unit(axis);
1223 return inner(a, u) * u;
1226 void store(FILE* fp,
const vec4& v);
1230 int apx_equal(
const vec4& a,
const vec4& b);
1233 vec3
cross(
const vec3& a,
const vec3& b);
bool is_tiny(Real tiny_tol=epsilon) const
Real inner(const vec2 &a, const vec2 &b)
ivec2 operator+=(ivec2 &a, const ivec2 &b)
vec2 proj(const vec2 &axis, const vec2 &a)
vec3(Real v_1, Real v_2, Real v_3)
vec2 & operator=(const vec2 &a)
ivec2 operator-(const ivec2 &a, const ivec2 &b)
vec2 absolute(const vec2 &val)
structure for 2-dimensional integer vector and its arithmetic.
int operator>=(const ivec2 &a, const ivec2 &b)
Real squaredNorm(const vec2 &a)
ivec2 operator+(const ivec2 &a, const ivec2 &b)
void store(FILE *fp, const vec2 &v)
ivec2 operator*(const ivec2 &a, const ivec2 &b)
int apx_equal(Real x, Real y)
vec2 operator/=(vec2 &a, const vec2 &b)
int operator<=(const ivec2 &a, const ivec2 &b)
vec3 cross(const vec3 &a, const vec3 &b)
vec3 & operator=(const vec3 &a)
structure for 4-dimensional integer vector and its arithmetic.
structure for 2-dimensional Real type vector and its arithmetic.
vec2 operator/(const vec2 &a, const vec2 &b)
vec4 & operator=(const vec4 &a)
ivec2 operator-=(ivec2 &a, const ivec2 &b)
structure for 3-dimensional Real type vector and its arithmetic.
bool is_tiny(Real tiny_tol=epsilon) const
vec4(Real v_1, Real v_2, Real v_3, Real v_4)
int operator>(const ivec2 &a, const ivec2 &b)
int operator==(const ivec2 &a, const ivec2 &b)
bool is_tiny(Real tiny_tol=epsilon) const
void angle(const std::vector< Complex< T >> &src, std::vector< T > &dst)
structure for 3-dimensional integer vector and its arithmetic.
int operator<(const ivec2 &a, const ivec2 &b)
structure for 4-dimensional Real type vector and its arithmetic.
ivec2 operator*=(ivec2 &a, const ivec2 &b)