11 #ifndef MI_MATH_VECTOR_H
12 #define MI_MATH_VECTOR_H
134 template <
typename T, Size DIM>
174 template <
typename T, Size DIM>
181 template <
typename T, Size DIM>
188 template <
typename T>
195 template <
typename T>
202 template <
typename T>
209 template <
typename T>
216 template <
typename T>
223 template <
typename T>
230 template <
typename T>
237 template <
typename T>
249 template <
class T, Size DIM>
253 template <
typename T, Size DIM>
298 template <
class T, Size DIM>
299 class Vector :
public Vector_struct<T, DIM>
336 inline const T*
end()
const {
return begin() + DIM; }
341 #if defined(DEBUG) || (defined(_MSC_VER) && _MSC_VER <= 1310)
349 T v = (Traits::has_signaling_NaN) ? Traits::signaling_NaN()
351 for(
Size i(0u); i < DIM; ++i)
359 for(
Size i(0u); i < DIM; ++i)
366 for(
Size i(0u); i < DIM; ++i)
383 template <
typename Iterator>
386 for(
Size i(0u); i < DIM; ++i, ++p)
401 template <
typename T2>
402 inline explicit Vector( T2
const (& array)[DIM])
404 for(
Size i(0u); i < DIM; ++i)
405 (*
this)[i] = array[i];
410 template <
typename T2>
413 for(
Size i(0u); i < DIM; ++i)
414 (*
this)[i] = T(other[i]);
572 for(
Size i(0u); i < DIM; ++i)
573 (*
this)[i] = other[i];
580 for(
Size i(0u); i < DIM; ++i)
619 inline const T&
get(
Size i)
const
644 const T rec_length = T(1) /
length( *
this);
645 const bool result =
isfinite( rec_length);
647 (*this) *= rec_length;
671 inline bool operator<( Vector_proxy_<T,DIM> rhs)
const
679 inline bool operator<=( Vector_proxy_<T,DIM> rhs)
const
700 #ifdef MI_NEURAYLIB_DEPRECATED_5_0
702 inline Vector multiply( T factor)
const
705 for(
Size i(0u); i < DIM; ++i)
710 inline Vector divide( T factor)
const
712 Vector<T,DIM> tmp( *
this);
714 for(
Size i(0u); i < DIM; ++i)
721 Vector<T,DIM> tmp( *
this);
722 for(
Size i(0u); i < DIM; ++i)
729 Vector<T,DIM> tmp( *
this);
730 for(
Size i(0u); i < DIM; ++i)
738 return Vector<T,3>( (*this)[1] * vector[2] - (*this)[2] * vector[1],
739 (*this)[2] * vector[0] - (*this)[0] * vector[2],
740 (*this)[0] * vector[1] - (*this)[1] * vector[0]);
745 inline T norm()
const {
return length( *
this); }
759 #endif // MI_NEURAYLIB_DEPRECATED_5_0
766 template <
typename T, Size DIM>
771 for(
Size i(0u); i < DIM; ++i)
777 template <
typename T, Size DIM>
782 for(
Size i(0u); i < DIM; ++i)
788 template <
typename T, Size DIM>
793 for(
Size i(0u); i < DIM; ++i)
800 template <
typename T, Size DIM>
805 for(
Size i(0u); i < DIM; ++i)
811 template <
typename T,
typename U, Size DIM>
816 for(
Size i(0u); i < DIM; ++i)
817 lhs[i] = T(lhs[i] / rhs[i]);
822 template <
typename T, Size DIM>
832 template <
typename T, Size DIM>
842 template <
typename T, Size DIM>
853 template <
typename T, Size DIM>
863 template <
typename T,
typename U, Size DIM>
873 template <
typename T, Size DIM>
877 for(
Size i(0u); i < DIM; ++i)
887 template <
typename T,
typename TT, Size DIM>
892 for(
Size i(0u); i < DIM; ++i)
900 template <
typename T,
typename TT, Size DIM>
905 for(
Size i(0u); i < DIM; ++i)
911 template <
typename T,
typename TT, Size DIM>
916 for(
Size i(0u); i < DIM; ++i)
922 template <
typename T,
typename TT, Size DIM>
932 template <
typename T,
typename TT, Size DIM>
944 template <
typename T,
typename TT, Size DIM>
954 template <
typename T,
typename TT, Size DIM>
967 template <
typename T, Size DIM>
975 template <
typename T, Size DIM>
1098 template <
typename T, Size DIM>
1109 template <
typename T, Size DIM>
1120 template <
typename T, Size DIM>
1131 template <
typename T, Size DIM>
1142 template <
typename T, Size DIM>
1153 template <
typename T, Size DIM>
1167 template <
typename T, Size DIM>
1171 for(
Size i = 0; i != DIM; ++i)
1172 result[i] =
abs( v[i]);
1177 template <
typename T, Size DIM>
1181 for(
Size i = 0; i != DIM; ++i)
1182 result[i] =
acos( v[i]);
1187 template <
typename T, Size DIM>
1190 for(
Size i = 0; i != DIM; ++i)
1197 template <
typename T, Size DIM>
1200 for(
Size i = 0; i != DIM; ++i)
1207 template <
typename T, Size DIM>
1211 for(
Size i = 0; i != DIM; ++i)
1212 result[i] =
asin( v[i]);
1217 template <
typename T, Size DIM>
1221 for(
Size i = 0; i != DIM; ++i)
1222 result[i] =
atan( v[i]);
1229 template <
typename T, Size DIM>
1233 for(
Size i = 0; i != DIM; ++i)
1234 result[i] =
atan2( v[i], w[i]);
1240 template <
typename T, Size DIM>
1244 for(
Size i = 0; i != DIM; ++i)
1245 result[i] =
ceil( v[i]);
1250 template <
typename T, Size DIM>
1257 for(
Size i = 0u; i < DIM; ++i)
1258 result[i] =
clamp( v[i], low[i], high[i]);
1263 template <
typename T, Size DIM>
1270 for(
Size i = 0u; i < DIM; ++i)
1271 result[i] =
clamp( v[i], low[i], high);
1276 template <
typename T, Size DIM>
1283 for(
Size i = 0u; i < DIM; ++i)
1284 result[i] =
clamp( v[i], low, high[i]);
1289 template <
typename T, Size DIM>
1296 for(
Size i = 0u; i < DIM; ++i)
1297 result[i] =
clamp( v[i], low, high);
1302 template <
typename T, Size DIM>
1306 for(
Size i = 0; i != DIM; ++i)
1307 result[i] =
cos( v[i]);
1312 template <
typename T, Size DIM>
1316 for(
Size i = 0; i != DIM; ++i)
1322 template <
typename T, Size DIM>
1328 for(
Size i(0u); i < Vector<T,DIM>::DIMENSION; ++i)
1334 template <
typename T, Size DIM>
1340 for(
Size i(0u); i < Vector<T,DIM>::DIMENSION; ++i)
1346 template <
typename T, Size DIM>
1350 for(
Size i = 0; i != DIM; ++i)
1351 result[i] =
exp( v[i]);
1356 template <
typename T, Size DIM>
1360 for(
Size i = 0; i != DIM; ++i)
1361 result[i] =
exp2( v[i]);
1367 template <
typename T, Size DIM>
1371 for(
Size i = 0; i != DIM; ++i)
1372 result[i] =
floor( v[i]);
1379 template <
typename T, Size DIM>
1383 for(
Size i = 0; i != DIM; ++i)
1384 result[i] =
fmod( a[i], b[i]);
1391 template <
typename T, Size DIM>
1395 for(
Size i = 0; i != DIM; ++i)
1396 result[i] =
fmod( a[i], b);
1401 template <
typename T, Size DIM>
1405 for(
Size i = 0; i != DIM; ++i)
1406 result[i] =
frac( v[i]);
1411 template <
typename T, Size DIM>
1417 for(
Size i = 0u; i < DIM; ++i)
1425 template <
typename T, Size DIM>
1432 for(
Size i = 0; i != DIM; ++i)
1433 result[i] = v1[i] * (T(1)-t[i]) + v2[i] * t[i];
1439 template <
typename T, Size DIM>
1448 for(
Size i = 0; i != DIM; ++i)
1449 result[i] = v1[i] * t2 + v2[i] * t;
1454 template <
typename T, Size DIM>
1458 for(
Size i = 0; i != DIM; ++i)
1459 result[i] =
log( v[i]);
1464 template <
typename T, Size DIM>
1468 for(
Size i = 0; i != DIM; ++i)
1474 template <
typename T, Size DIM>
1478 for(
Size i = 0; i != DIM; ++i)
1479 result[i] =
log10( v[i]);
1487 template <
typename T, Size DIM>
1491 for(
Size j = 0; j != DIM; ++j)
1492 result[j] =
modf( v[j], i[j]);
1497 template <
typename T, Size DIM>
1501 for(
Size i = 0; i != DIM; ++i)
1502 result[i] =
pow( a[i], b[i]);
1507 template <
typename T, Size DIM>
1511 for(
Size i = 0; i != DIM; ++i)
1512 result[i] =
pow( a[i], b);
1517 template <
typename T, Size DIM>
1521 for(
Size i = 0; i != DIM; ++i)
1527 template <
typename T, Size DIM>
1531 for(
Size i = 0; i != DIM; ++i)
1532 result[i] =
round( v[i]);
1537 template <
typename T, Size DIM>
1541 for(
Size i = 0; i != DIM; ++i)
1542 result[i] =
rsqrt( v[i]);
1547 template <
typename T, Size DIM>
1551 for(
Size i = 0; i != DIM; ++i)
1557 template <
typename T, Size DIM>
1561 for(
Size i = 0; i != DIM; ++i)
1562 result[i] =
sign( v[i]);
1567 template <
typename T, Size DIM>
1571 for(
Size i = 0; i != DIM; ++i)
1572 result[i] =
sin( v[i]);
1579 template <
typename T, Size DIM>
1582 for(
Size i = 0; i != DIM; ++i)
1583 sincos( a[i], s[i], c[i]);
1591 template <
typename T, Size DIM>
1598 for(
Size i = 0; i != DIM; ++i)
1608 template <
typename T, Size DIM>
1615 for(
Size i = 0; i != DIM; ++i)
1621 template <
typename T, Size DIM>
1625 for(
Size i = 0; i != DIM; ++i)
1626 result[i] =
sqrt( v[i]);
1631 template <
typename T, Size DIM>
1635 for(
Size i = 0; i != DIM; ++i)
1636 result[i] =
step( a[i], v[i]);
1641 template <
typename T, Size DIM>
1645 for(
Size i = 0; i != DIM; ++i)
1646 result[i] =
tan( v[i]);
1654 template <
typename T>
1659 return lhs.x * rhs.y - lhs.y * rhs.x;
1663 template <
typename T>
1668 return Vector<T,3>( lhs.y * rhs.z - lhs.z * rhs.y,
1669 lhs.z * rhs.x - lhs.x * rhs.z,
1670 lhs.x * rhs.y - lhs.y * rhs.x);
1678 template <
typename T>
1684 #ifdef mi_base_assert_enabled
1685 const T eps = 1e-6f;
1694 if(
abs(n.x) <
abs(n.y)) {
1726 template <
typename T>
1734 const T eps = 1e-6f;
1756 if(
dot( *b,v) < T(0))
1776 template <
typename T2, Size DIM2,
typename T1, Size DIM1>
1779 const T2& fill = T2(0))
1783 for(
Size i = 0; i < dim_min; ++i)
1784 result[i] = T2(v[i]);
1785 for(
Size i = dim_min; i < DIM2; ++i)
1790 #ifdef MI_NEURAYLIB_DEPRECATED_5_0
1792 template <
typename T, Size DIM>
1798 template <
typename T, Size DIM>
1804 template <
typename T, Size DIM>
1810 #endif // MI_NEURAYLIB_DEPRECATED_5_0
1818 #endif // MI_MATH_VECTOR_H