13#ifndef ML_FLOATING_POINT_VECTOR_H
14#define ML_FLOATING_POINT_VECTOR_H
60template <
class T,
size_t size,
class DataContainer = FloatingPo
intVectorDataContainerBase<T, size>>
153 return (*
this -
buffer).length();
159 return (*
this -
buffer).lengthSquared();
223 r[0] = this->_buffer[1] * b.
_buffer[2] - this->_buffer[2] * b.
_buffer[1];
224 r[1] = this->_buffer[2] * b.
_buffer[0] - this->_buffer[0] * b.
_buffer[2];
225 r[2] = this->_buffer[0] * b.
_buffer[1] - this->_buffer[1] * b.
_buffer[0];
254 for (
size_t i = 0;
i < size; ++
i) {
267 for (
size_t i = 0;
i < size; ++
i) {
277template <
class T,
size_t size,
class DataContainer>
281 for (
size_t i = 0;
i < size; ++
i) {
282 op1[
i] *=
static_cast<T>(value);
291template <
class T,
size_t size,
class DataContainer>
295 for (
size_t i = 0;
i < size; ++
i) {
306template <
class T,
size_t size,
class DataContainer>
313 for (
size_t i = 0;
i < size; ++
i) {
314 op1[
i] /=
static_cast<T>(value);
324template <
class T,
size_t size,
class DataContainer>
331 for (
size_t i = 0;
i < size; ++
i) {
341template <
class T,
size_t size,
class DataContainer>
345 for (
size_t c = 1; c < size; c++) {
355template <
class T,
size_t size,
class DataContainer>
366template <
class T,
size_t size,
class DataContainer>
377template <
class T,
size_t size,
class DataContainer>
388template <
class T,
size_t size,
class DataContainer>
392 for (
size_t i = 0;
i < size; ++
i) {
402template <
class T,
size_t size,
class DataContainer>
413template <
class T,
size_t size,
class DataContainer>
417 return lhs *=
static_cast<T>(
rhs);
424template <
class T,
size_t size,
class DataContainer>
428 return rhs *=
static_cast<T>(
lhs);
435template <
class T,
size_t size,
class DataContainer>
439 return lhs /=
static_cast<T>(
rhs);
446template <
class T,
size_t size,
class DataContainer>
458template <
class T,
size_t size,
class DataContainer>
470template <
class T,
size_t size,
class DataContainer>
481template <
class T,
size_t size,
class DataContainer>
493template <
class T,
size_t size,
class DataContainer>
505template <
class T,
size_t size,
class DataContainer>
518template <
class T,
size_t size,
class DataContainer>
531template <
class T,
size_t size,
class DataContainer>
546template <
class T,
size_t size,
class DataContainer>
560template <
class T,
size_t size,
class DataContainer>
578 template <
class T,
size_t size,
class DataContainer>
579 inline ostream&
operator<<(ostream&
os,
const ML_LA_NAMESPACE::FloatingPointVector<T, size, DataContainer>& v)
581 return v.writeOut(
os);
587 template <
class T,
size_t size,
class DataContainer>
588 inline istream&
operator>>(istream& is, ML_LA_NAMESPACE::FloatingPointVector<T, size, DataContainer>& v)
610template <
class T,
size_t size,
class DataContainer>
613 for (
size_t i = 0;
i < size; ++
i) {
614 this->_buffer[
i] = value;
621template <
class T,
size_t size,
class DataContainer>
624 for (
size_t i = 0;
i < size; ++
i) {
625 this->_buffer[
i] = value;
637template <
class T,
size_t size,
class DataContainer>
inline bool
640 for (
size_t i = 0;
i < size; ++
i) {
654template <
class T,
size_t size,
class DataContainer>
inline bool
657 for (
size_t i = 0;
i < size; ++
i) {
677template <
class T,
size_t size,
class DataContainer>
inline bool
680 for (
size_t i = 0;
i < size; ++
i) {
682 return (this->_buffer[
i] <
buffer._buffer[
i]);
697template <
class T,
size_t size,
class DataContainer>
700 return this->_buffer[
i];
708template <
class T,
size_t size,
class DataContainer>
711 return this->_buffer[
i];
721template <
class T,
size_t size,
class DataContainer>
734 for (
size_t i = 0;
i < size; ++
i) {
735 norm += this->_buffer[
i] * this->_buffer[
i];
738 return static_cast<T>(
sqrt(norm));
740 return static_cast<T>(
::sqrt(norm));
748template <
class T,
size_t size,
class DataContainer>
inline T
752 for (
size_t i = 0;
i < size; ++
i) {
767template <
class T,
size_t size,
class DataContainer>
inline T
771 for (
size_t i = 0;
i < size; ++
i) {
787 for (
size_t i = 0;
i < size; ++
i) {
798template <
class T,
size_t size,
class DataContainer>
807template <
class T,
size_t size,
class DataContainer>
816template <
class T,
size_t size,
class DataContainer>
820 for (
size_t i = 1;
i < size; ++
i) {
829template <
class T,
size_t size,
class DataContainer>
833 for (
size_t i = 1;
i < size; ++
i) {
842template <
class T,
size_t size,
class DataContainer>
846 T m =
static_cast<T>(
MLAbs(this->_buffer[
i++]));
848 for (;
i < size; ++
i) {
849 m = (
n =
static_cast<T>(
MLAbs(this->_buffer[
i]))) >
m ?
n :
m;
857template <
class T,
size_t size,
class DataContainer>
860 for (
size_t i = 0;
i < size; ++
i) {
868template <
class T,
size_t size,
class DataContainer>
871 for (
size_t i = 0;
i < size; ++
i) {
881 for (
size_t i = 0;
i < size; ++
i) {
882 this->_buffer[
i] =
static_cast<T>(
MLAbs(this->_buffer[
i]));
890template <
class T,
size_t size,
class DataContainer>
893 for (
size_t i = 0;
i < size; ++
i) {
903 for (
size_t i = 0;
i < size; ++
i) {
904 this->_buffer[
i] *= this->_buffer[
i];
914 for (
size_t i = 0;
i < size; ++
i) {
916 this->_buffer[
i] =
static_cast<T>(
sqrt(this->_buffer[
i]));
918 this->_buffer[
i] =
static_cast<T>(
::sqrt(this->_buffer[
i]));
927template <
class T,
size_t size,
class DataContainer>
inline void
937template <
class T,
size_t size,
class DataContainer>
inline void
950template <
class T,
size_t size,
class DataContainer>
964template <
class T,
size_t size,
class DataContainer>
967 for (
size_t i = 0;
i < size; ++
i) {
968 this->_buffer[
i] = std::floor(this->_buffer[
i] +
static_cast<T>(0.5));
975template <
class T,
size_t size,
class DataContainer>
978 for (
size_t i = 0;
i < size; ++
i) {
979 this->_buffer[
i] = std::floor(this->_buffer[
i]);
988 for (
size_t i = 0;
i < size; ++
i) {
989 this->_buffer[
i] = std::ceil(this->_buffer[
i]);
996template <
class T,
size_t size,
class DataContainer>
999 for (
size_t i = 0;
i < size; ++
i) {
1000 this->_buffer[
i] = f(this->_buffer[
i]);
1008template <
class T,
size_t size,
class DataContainer>
1011 for (
size_t i = 0;
i < size; ++
i) {
1012 os << this->_buffer[
i] <<
" ";
1020template <
class T,
size_t size,
class DataContainer>
1023 for (
size_t i = 0;
i < size; ++
i) {
1024 is >> this->_buffer[
i];
Base class of the FloatingPointVector class that holds the data buffer.
Template class for vector arithmetic with floating point datatypes.
FloatingPointVector(T value=T(0))
Default and value constructor.
FloatingPointVector< T, size, DataContainer > operator/(FloatingPointVector< T, size, DataContainer > lhs, MLdouble rhs)
Component-wise division of lhs by specialized rhs of type MLdouble.
FloatingPointVector< T, size, DataContainer > & operator/=(FloatingPointVector< T, size, DataContainer > &op1, const FloatingPointVector< T, size, DataContainer > &op2)
Arithmetic assignment: Component-wise division of *this by the values of a vector of the same size.
FloatingPointVector< T, size, DataContainer > operator*(FloatingPointVector< T, size, DataContainer > lhs, MLdouble rhs)
Component-wise multiplication of lhs with rhs.
std::ostream & writeOut(std::ostream &os) const
Writes all components to ostream os starting from index 0 to size-1.
FloatingPointVector< T, size, DataContainer > compMax(FloatingPointVector< T, size, DataContainer > buffer1, const FloatingPointVector< T, size, DataContainer > &buffer2)
Component-wise maximum of buffer1 and buffer2.
void clampMax(const FloatingPointVector< T, size, DataContainer > &upper)
Calculates and sets all components clamped to upper, i.e., if any component is greater than the corre...
void compMin(FloatingPointVector< T, size, DataContainer > buffer)
Sets the component-wise minimum of *this and buffer in *this.
T & operator[](const size_t i)
Indexing operators.
FloatingPointVector< T, size, DataContainer > & operator*=(FloatingPointVector< T, size, DataContainer > &op1, const FloatingPointVector< T, size, DataContainer > &op2)
Arithmetic assignment: Component-wise multiplication *this with a vector of the same size.
T length() const
Returns the length of the vector, i.e., norm2().
void clamp(const FloatingPointVector< T, size, DataContainer > &lower, const FloatingPointVector< T, size, DataContainer > &upper)
Calculates and sets all components of *this so that they are between minimum lower and maximum upper.
FloatingPointVector< T, size, DataContainer > & operator/=(FloatingPointVector< T, size, DataContainer > &op1, MLdouble value)
Arithmetic assignment: Component-wise division of *this by scalar value.
FloatingPointVector< T, size, DataContainer > operator+(const FloatingPointVector< T, size, DataContainer > &buffer)
Unary plus, for completeness and for those who really want to use that.
bool operator==(const FloatingPointVector< T, size, DataContainer > &buffer) const
Returns whether *this and buffer are component-wise equal.
FloatingPointVector< T, size, DataContainer > & operator-=(FloatingPointVector< T, size, DataContainer > &op1, const FloatingPointVector< T, size, DataContainer > &buffer)
Arithmetic assignment: Component-wise subtraction of buffer from *this.
void compMax(FloatingPointVector< T, size, DataContainer > buffer)
Sets the component-wise maximum of *this and buffer in *this.
FloatingPointVector< T, size, DataContainer > clamp(FloatingPointVector< T, size, DataContainer > vec, const FloatingPointVector< T, size, DataContainer > &lower, const FloatingPointVector< T, size, DataContainer > &upper)
Returns a new vector with all components from vec clamped to range [lower, upper].
FloatingPointVector< T, 3, DataContainer > cross(const FloatingPointVector< T, 3, DataContainer > &b) const
Returns the cross product for elements, i.e., the returned vector is orthogonal to *this and b.
T normalize()
Normalizes the buffer and returns the Euclidean length of vector before normalization,...
void compAbs()
Kills negative signs from all components.
const T & operator[](const size_t i) const
Constant indexing operators.
T distance(const FloatingPointVector< T, size, DataContainer > &buffer) const
Returns the distance of this vector to a given one.
T compMaxAbs() const
Returns the maximum of absolute component values.
void compFloor()
Rounds all components of this vector using floor(component).
bool operator<(const FloatingPointVector< T, size, DataContainer > &buffer) const
Defines an artificial order for use in sort algorithms (lexicographical order).
void compDiv(const FloatingPointVector< T, size, DataContainer > &d)
Divides each vector component by the corresponding one of d.
T compMul() const
Returns the product of all vector components.
bool operator!(const FloatingPointVector< T, size, DataContainer > &a)
Returns whether all components are 0.
FloatingPointVector< T, size, DataContainer > & operator=(T value)
Assignment of scalar value to all components.
T compMul(const FloatingPointVector< T, size, DataContainer > &vec)
Returns the product of all components.
FloatingPointVector< T, size, DataContainer > clampMax(FloatingPointVector< T, size, DataContainer > vec, const FloatingPointVector< T, size, DataContainer > &m)
Returns a new vector with all components from vec clamped to maximum m.
FloatingPointVector< T, size, DataContainer > compSqrt(FloatingPointVector< T, size, DataContainer > vec)
Returns a vector with all components from vec square-rooted.
FloatingPointVector< T, size, DataContainer > compSqr(FloatingPointVector< T, size, DataContainer > vec)
Returns a vector with all components from vec squared.
T operator*(const FloatingPointVector< T, size, DataContainer > &a, const FloatingPointVector< T, size, DataContainer > &b)
Dot product, returns a.dot(b).
void compRound()
Rounds all components of this vector using floor(component + 0.5).
T norm2(const FloatingPointVector< T, size, DataContainer > &weight) const
Returns the weighted Euclidean norm, i.e., square root of sum of squares of all components multiplied...
T dot(const FloatingPointVector< T, size, DataContainer > &buffer) const
Returns the dot product, i.e., sum of all components multiplied with corresponding components of buff...
void compSqr()
Calculates and sets the square of all components.
bool operator!=(const FloatingPointVector< T, size, DataContainer > &buffer) const
Returns whether any components of *this and buffer are not equal.
T norm2() const
Returns the Euclidean norm (the vector length), i.e., square root of sum of squares of all components...
T compSum() const
Returns the sum of all components.
FloatingPointVector< T, size, DataContainer > operator+(FloatingPointVector< T, size, DataContainer > lhs, const FloatingPointVector< T, size, DataContainer > &rhs)
Return value is the component-wise addition of lhs and rhs.
std::istream & readIn(std::istream &is)
Reads all components from istream is starting starting from index 0 to size-1.
FloatingPointVector< T, size, DataContainer > compMin(FloatingPointVector< T, size, DataContainer > buffer1, const FloatingPointVector< T, size, DataContainer > &buffer2)
Component-wise minimum of buffer1 and buffer2.
void compCeil()
Rounds all components of this vector to integer using ceil(component).
size_t getSize() const
Returns the number of elements of value buffer.
void clampMin(const FloatingPointVector< T, size, DataContainer > &lower)
Calculates and sets all components clamped to lower, i.e., if any component is smaller than the corre...
void compSqrt()
Calculates and sets square root of all components.
FloatingPointVector< T, size, DataContainer > & operator+=(FloatingPointVector< T, size, DataContainer > &op1, const FloatingPointVector< T, size, DataContainer > &buffer)
Arithmetic assignment: Component-wise addition.
FloatingPointVector< T, size, DataContainer > operator-(FloatingPointVector< T, size, DataContainer > lhs, const FloatingPointVector< T, size, DataContainer > &rhs)
Return value is the component-wise subtraction of rhs from lhs.
FloatingPointVector< T, size, DataContainer > operator*(MLdouble lhs, FloatingPointVector< T, size, DataContainer > rhs)
Component-wise multiplication of rhs with lhs.
FloatingPointVector< T, size, DataContainer > compAbs(FloatingPointVector< T, size, DataContainer > vec)
Returns a vector with all components from vec without negative sign.
T distanceSquared(const FloatingPointVector< T, size, DataContainer > &buffer) const
Returns the squared distance of this vector to a given one.
void apply(ML_LA_FROM_DOUBLE_TO_DOUBLE f)
Applies the function f to each component starting from index 0 to index size-1.
FloatingPointVector< T, size, DataContainer > & operator*=(FloatingPointVector< T, size, DataContainer > &op1, MLdouble value)
Arithmetic assignment: Component-wise multiplication *this with specialized MLdouble scalar value.
FloatingPointVector< T, size, DataContainer > operator-(const FloatingPointVector< T, size, DataContainer > &buffer)
Unary minus, all components of the vector are multiplied with -1.
T ComponentType
A typedef to 'export' the type of components.
FloatingPointVector< T, size, DataContainer > clampMin(FloatingPointVector< T, size, DataContainer > vec, const FloatingPointVector< T, size, DataContainer > &m)
Returns a new vector with all components from vec clamped to minimum m.
T lengthSquared() const
Returns the squared length of the vector.
FloatingPointVector< T, size, DataContainer > compDiv(FloatingPointVector< T, size, DataContainer > vec, const FloatingPointVector< T, size, DataContainer > &d)
Component-wise division of vec / d.
bool MLValueIs0WOM(MLint8 a)
Returns true if value is 0; otherwise, it returns false.
DT MLAbs(const DT val)
Defines a templated MLAbs version to circumvent fabs ambiguities on different platforms.
bool MLValuesDifferWOM(MLint8 a, MLint8 b)
Returns true if values differ; otherwise, it returns false.
double(* ML_LA_FROM_DOUBLE_TO_DOUBLE)(double)
Template base class for floating point vectors.
Target mlrange_cast(Source arg)
Generic version of checked ML casts.
FloatingPointVector< T, size, DataContainer > compMax(FloatingPointVector< T, size, DataContainer > buffer1, const FloatingPointVector< T, size, DataContainer > &buffer2)
Component-wise maximum of buffer1 and buffer2.
constexpr Is< T > is(T d)
FloatingPointVector< T, size, DataContainer > compMin(FloatingPointVector< T, size, DataContainer > buffer1, const FloatingPointVector< T, size, DataContainer > &buffer2)
Component-wise minimum of buffer1 and buffer2.
MLEXPORT std::ostream & operator<<(std::ostream &s, const ml::Field &v)
Overloads the operator '<<' for stream output of Field objects.
istream & operator>>(istream &is, ml::FloatingPointVector< T, size, DataContainer > &v)
Reads a vector from std::istream.