scifir-units 2.0.0
scifir-units is a library of units of measurement, angles, coordinates, fields, and related data, all lightweight, that help in the development of scientific software and scientific machines
Loading...
Searching...
No Matches
Namespaces | Functions
vector_unit_nd.cpp File Reference
#include "./vector_unit_nd.hpp"
#include "../coordinates/coordinates_2d.hpp"
#include "../coordinates/coordinates_3d.hpp"
Include dependency graph for vector_unit_nd.cpp:

Go to the source code of this file.

Namespaces

namespace  scifir
 The namespace scifir contains all scifir-units, excepting the string literals, which are outside.
 

Functions

string scifir::to_string (const vector_unit_nd &x)
 It generates a string representation of vector_unit_nd.
 
scalar_unit scifir::norm (const vector_unit_nd &x)
 It returns the value of the vector, which is the value in 1D, p in 2D (polar coordinates), or r in 3D (spherical coordinates).
 
vector_unit_nd scifir::sqrt (const vector_unit_nd &x)
 It squares the vector, creating a vector_unit_nd with the value squared and always the same angles. The dimensions are squared with the same rules for the square of dimensions than scalar_unit classes.
 
vector_unit_nd scifir::sqrt_nth (const vector_unit_nd &x, int index)
 It takes the root of the vector with the index given, creating a vector_unit_nd with the value rooted to that index and always maintains the same angles. The dimensions are squared with the same rules for the square of dimensions than scalar_unit classes.
 
scalar_unit scifir::dot_product (const vector_unit_nd &x, const vector_unit_nd &y)
 Creates a scalar_unit as the dot product of the two vectors x and y.
 
vector_unit_nd scifir::cross_product (const vector_unit_nd &x, const vector_unit_nd &y)
 Creates a vector_unit_nd as the cross product of the two vectors x and y. If both vectors aren't in 3D, it returns an empty vector_unit_nd, because the cross product doesn't exists outside 3D.
 
angle scifir::angle_between (const vector_unit_nd &x, const vector_unit_nd &y)
 Returns the angle between two vectors x and y inside the ND space, which can be 2D or 3D, depending on the ND of the vectors. If the vectors have different ND, it returns an empty vector_unit_nd instead.
 
bool scifir::same_nd (const vector_unit_nd &x, const vector_unit_nd &y)
 Checks if two vectors have the same number of dimensions.
 
bool scifir::same_direction (const vector_unit_nd &x, const vector_unit_nd &y)
 Checks if two vectors x and y have the same direction. Both vectors must have the same ND, otherwise it returns an empty vector_unit_nd instead.
 
bool scifir::parallel (const vector_unit_nd &x, const vector_unit_nd &y)
 Checks if two vectors x and y are parallel, which means that their direction is the same or the exact opposite. Both vectors must have the same ND, otherwise it returns an empty vector_unit_nd instead.
 
bool scifir::orthogonal (const vector_unit_nd &x, const vector_unit_nd &y)
 Checks if two vectors x and y are orthogonal, that's, if they have 90 degrees between them. Both vectors must have the same ND, otherwise it returns an empty vector_unit_nd instead.
 
scifir::vector_unit_nd operator* (const scifir::scalar_unit &x, const scifir::vector_unit_nd &y)
 It creates a new vector_unitn3d scaling a vector_unit_nd by the scalar_unit x.
 
bool operator!= (const scifir::vector_unit_nd &x, const scifir::vector_unit_nd &y)
 Comparison operator. Two vector_unit_nd are not equal if their value, dimensions or angles are different.
 
bool operator== (const scifir::vector_unit_nd &x, const string &init_vector_nd)
 Returns true if x is equal to the vector_unit_nd initialized with the string being compared. The vectorial_display() function is not used, and so the values are compared with all its decimal numbers.
 
bool operator!= (const scifir::vector_unit_nd &x, const string &init_vector_nd)
 Returns true if x is not equal to the vector_unit_nd initialized with the string being compared. The vectorial_display() function is not used, and so the values are compared with all its decimal numbers.
 
bool operator== (const string &init_vector_nd, const scifir::vector_unit_nd &x)
 Returns true if x is equal to the vector_unit_nd initialized with the string being compared. The vectorial_display() function is not used, and so the values are compared with all its decimal numbers.
 
bool operator!= (const string &init_vector_nd, const scifir::vector_unit_nd &x)
 Returns true if x is not equal to the vector_unit_nd initialized with the string being compared. The vectorial_display() function is not used, and so the values are compared with all its decimal numbers.
 
void operator+= (string &x, const scifir::vector_unit_nd &y)
 Concatenates the string representation of the vector_unit_nd y to the string x.
 
string operator+ (const string &x, const scifir::vector_unit_nd &y)
 Creates a new string as the concatenation of the string x with the representation string of the vector_unit_nd y.
 
string operator+ (const scifir::vector_unit_nd &y, const string &x)
 Creates a new string as the concatenation of the string x with the representation string of the vector_unit_nd y.
 
ostream & operator<< (ostream &os, const scifir::vector_unit_nd &x)
 Adds the string representation of the vector_unit_nd x to an output stream os.
 
istream & operator>> (istream &is, scifir::vector_unit_nd &x)
 Allows that an istream initializes by string a vector_unit_nd x.
 

Function Documentation

◆ operator!=() [1/3]

bool operator!= ( const scifir::vector_unit_nd x,
const scifir::vector_unit_nd y 
)

Comparison operator. Two vector_unit_nd are not equal if their value, dimensions or angles are different.

Definition at line 947 of file vector_unit_nd.cpp.

948{
949 return !(x == y);
950}

◆ operator!=() [2/3]

bool operator!= ( const scifir::vector_unit_nd x,
const string &  init_vector_nd 
)

Returns true if x is not equal to the vector_unit_nd initialized with the string being compared. The vectorial_display() function is not used, and so the values are compared with all its decimal numbers.

Definition at line 958 of file vector_unit_nd.cpp.

959{
960 return !(x == init_vector_nd);
961}

◆ operator!=() [3/3]

bool operator!= ( const string &  init_vector_nd,
const scifir::vector_unit_nd x 
)

Returns true if x is not equal to the vector_unit_nd initialized with the string being compared. The vectorial_display() function is not used, and so the values are compared with all its decimal numbers.

Definition at line 969 of file vector_unit_nd.cpp.

970{
971 return !(init_vector_nd == x);
972}

◆ operator*()

scifir::vector_unit_nd operator* ( const scifir::scalar_unit x,
const scifir::vector_unit_nd y 
)

It creates a new vector_unitn3d scaling a vector_unit_nd by the scalar_unit x.

Definition at line 925 of file vector_unit_nd.cpp.

926{
927 long double new_value = y.get_value() * x.get_value();
928 vector<scifir::dimension> new_dimensions = multiply_dimensions(y.get_dimensions(), x.get_dimensions(),new_value);
929 if(y.is_nd(1))
930 {
931 return scifir::vector_unit_nd(float(new_value), new_dimensions);
932 }
933 else if(y.is_nd(2))
934 {
935 return scifir::vector_unit_nd(float(new_value), new_dimensions, {y.angles[0]});
936 }
937 else if(y.is_nd(3))
938 {
939 return scifir::vector_unit_nd(float(new_value), new_dimensions, {y.angles[0], y.angles[1]});
940 }
941 else
942 {
943 return scifir::vector_unit_nd(float(new_value), new_dimensions, y.angles);
944 }
945}
const vector< dimension > & get_dimensions() const
Read-only getter of the dimensions.
const float & get_value() const
Read-only getter of the value.
Class that creates a vector in ND, which means a variable number of dimensions. A vector_unit_nd can ...
bool is_nd(unsigned int i) const
Returns true if the vector is at the same number of dimensions as i.
vector< angle > angles
The angles. A total of one angle means the vector is in 2D in polar coordinates, two angles means it'...
vector< dimension > multiply_dimensions(const vector< dimension > &x, const vector< dimension > &y)
Multiplies two vectors of dimensions. The result is normalized after, which means that equal dimensio...

◆ operator+() [1/2]

string operator+ ( const scifir::vector_unit_nd y,
const string &  x 
)

Creates a new string as the concatenation of the string x with the representation string of the vector_unit_nd y.

Definition at line 989 of file vector_unit_nd.cpp.

990{
991 ostringstream output;
992 output << y;
993 output << x;
994 return output.str();
995}

◆ operator+() [2/2]

string operator+ ( const string &  x,
const scifir::vector_unit_nd y 
)

Creates a new string as the concatenation of the string x with the representation string of the vector_unit_nd y.

Definition at line 981 of file vector_unit_nd.cpp.

982{
983 ostringstream output;
984 output << x;
985 output << y;
986 return output.str();
987}

◆ operator+=()

void operator+= ( string &  x,
const scifir::vector_unit_nd y 
)

Concatenates the string representation of the vector_unit_nd y to the string x.

Definition at line 974 of file vector_unit_nd.cpp.

975{
976 ostringstream output;
977 output << y;
978 x += output.str();
979}

◆ operator<<()

ostream & operator<< ( ostream &  os,
const scifir::vector_unit_nd x 
)

Adds the string representation of the vector_unit_nd x to an output stream os.

Definition at line 997 of file vector_unit_nd.cpp.

998{
999 ostringstream angles_text;
1000 if (!x.is_nd(1))
1001 {
1002 for(const auto& x_angle : x.angles)
1003 {
1004 angles_text << " ";
1005 angles_text << x_angle;
1006 }
1007 }
1008 return os << x.get_value() << " " << x.display_dimensions() << angles_text.str();
1009}
string display_dimensions() const
Generates an string of the dimensions of the scalar_unit, with the same format as the initialization ...

◆ operator==() [1/2]

bool operator== ( const scifir::vector_unit_nd x,
const string &  init_vector_nd 
)

Returns true if x is equal to the vector_unit_nd initialized with the string being compared. The vectorial_display() function is not used, and so the values are compared with all its decimal numbers.

Definition at line 952 of file vector_unit_nd.cpp.

953{
954 scifir::vector_unit_nd y(init_vector_nd);
955 return (x == y);
956}

◆ operator==() [2/2]

bool operator== ( const string &  init_vector_nd,
const scifir::vector_unit_nd x 
)

Returns true if x is equal to the vector_unit_nd initialized with the string being compared. The vectorial_display() function is not used, and so the values are compared with all its decimal numbers.

Definition at line 963 of file vector_unit_nd.cpp.

964{
965 scifir::vector_unit_nd y(init_vector_nd);
966 return (y == x);
967}

◆ operator>>()

istream & operator>> ( istream &  is,
scifir::vector_unit_nd x 
)

Allows that an istream initializes by string a vector_unit_nd x.

Definition at line 1011 of file vector_unit_nd.cpp.

1012{
1013 char a[256];
1014 is.getline(a, 256);
1015 string b(a);
1016 boost::trim(b);
1018 return is;
1019}