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_2d.cpp File Reference
#include "./vector_unit_2d.hpp"
#include "../coordinates/coordinates_2d.hpp"
#include "../util/types.hpp"
#include "boost/algorithm/string.hpp"
Include dependency graph for vector_unit_2d.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

scalar_unit scifir::norm (const vector_unit_2d &x)
 It returns the value of the vector in polar coordinates, p.
 
vector_unit_2d scifir::sqrt (const vector_unit_2d &x)
 It squares the vector, creating a vector_unit_2d with the value squared and always the same theta. The dimensions are squared with the same rules for the square of dimensions than scalar_unit classes.
 
vector_unit_2d scifir::sqrt_nth (const vector_unit_2d &x, int index)
 It takes the root of the vector with the index given, creating a vector_unit_2d with the value rooted to that index and always maintains the same theta. 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_2d &x, const vector_unit_2d &y)
 Creates a scalar_unit as the dot product of the two vectors x and y.
 
angle scifir::angle_between (const vector_unit_2d &x, const vector_unit_2d &y)
 Returns the angle between two vectors x and y inside a 2D space.
 
bool scifir::same_direction (const vector_unit_2d &x, const vector_unit_2d &y)
 Checks if two vectors x and y have the same direction.
 
bool scifir::parallel (const vector_unit_2d &x, const vector_unit_2d &y)
 Checks if two vectors x and y are parallel, which means that their direction is the same or the exact opposite.
 
bool scifir::orthogonal (const vector_unit_2d &x, const vector_unit_2d &y)
 Checks if two vectors x and y are orthogonal, that's, if they have 90 degrees of difference.
 
scifir::vector_unit_2d operator* (const scifir::scalar_unit &x, const scifir::vector_unit_2d &y)
 It creates a new vector_unit_3d scaling a vector_unit_3d by the scalar_unit x.
 
bool operator!= (const scifir::vector_unit_2d &x, const scifir::vector_unit_2d &y)
 Comparison operator. Two vector_unit_2d are not equal if their value, dimensions or theta are different.
 
bool operator== (const scifir::vector_unit_2d &x, const string &init_vector_2d)
 Returns true if x is equal to the vector_unit_2d 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_2d &x, const string &init_vector_2d)
 Returns true if x is not equal to the vector_unit_2d 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_2d, const scifir::vector_unit_2d &x)
 Returns true if x is equal to the vector_unit_2d 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_2d, const scifir::vector_unit_2d &x)
 Returns true if x is not equal to the vector_unit_2d 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_2d &y)
 Concatenates the string representation of the vector_unit_2d y to the string x.
 
string operator+ (const string &x, const scifir::vector_unit_2d &y)
 Creates a new string as the concatenation of the string x with the representation string of the vector_unit_2d y.
 
string operator+ (const scifir::vector_unit_2d &y, const string &x)
 Creates a new string as the concatenation of the string x with the representation string of the vector_unit_2d y.
 
ostream & operator<< (ostream &os, const scifir::vector_unit_2d &x)
 Adds the string representation of the vector_unit_2d x to an output stream os.
 
istream & operator>> (istream &is, scifir::vector_unit_2d &x)
 Allows that an istream initializes by string a vector_unit_2d x.
 

Function Documentation

◆ operator!=() [1/3]

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

Comparison operator. Two vector_unit_2d are not equal if their value, dimensions or theta are different.

Definition at line 397 of file vector_unit_2d.cpp.

398{
399 return !(x == y);
400}

◆ operator!=() [2/3]

bool operator!= ( const scifir::vector_unit_2d x,
const string &  init_vector_2d 
)

Returns true if x is not equal to the vector_unit_2d 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 408 of file vector_unit_2d.cpp.

409{
410 return !(x == init_vector_2d);
411}

◆ operator!=() [3/3]

bool operator!= ( const string &  init_vector_2d,
const scifir::vector_unit_2d x 
)

Returns true if x is not equal to the vector_unit_2d 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 419 of file vector_unit_2d.cpp.

420{
421 return !(init_vector_2d == x);
422}

◆ operator*()

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

It creates a new vector_unit_3d scaling a vector_unit_3d by the scalar_unit x.

Definition at line 390 of file vector_unit_2d.cpp.

391{
392 long double new_value = x.get_value() * y.get_value();
393 vector<scifir::dimension> new_dimensions = multiply_dimensions(x.get_dimensions(), y.get_dimensions(),new_value);
394 return scifir::vector_unit_2d(float(new_value), new_dimensions, y.theta);
395}
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 unit in 2D. The vector is in polar coordinates with a value and dimension...
angle theta
Angle of the vector in 2D space, in polar coordinates. As all angles of scifir-units,...
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_2d y,
const string &  x 
)

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

Definition at line 439 of file vector_unit_2d.cpp.

440{
441 ostringstream output;
442 output << y;
443 output << x;
444 return output.str();
445}

◆ operator+() [2/2]

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

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

Definition at line 431 of file vector_unit_2d.cpp.

432{
433 ostringstream output;
434 output << x;
435 output << y;
436 return output.str();
437}

◆ operator+=()

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

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

Definition at line 424 of file vector_unit_2d.cpp.

425{
426 ostringstream output;
427 output << y;
428 x += output.str();
429}

◆ operator<<()

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

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

Definition at line 447 of file vector_unit_2d.cpp.

448{
449 return os << to_string(x);
450}
string to_string(const aid &x)
Creates a string representation of aid, it's for aid equivalent to the display() function of aid.
Definition aid.cpp:582

◆ operator==() [1/2]

bool operator== ( const scifir::vector_unit_2d x,
const string &  init_vector_2d 
)

Returns true if x is equal to the vector_unit_2d 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 402 of file vector_unit_2d.cpp.

403{
404 scifir::vector_unit_2d y(init_vector_2d);
405 return (x == y);
406}

◆ operator==() [2/2]

bool operator== ( const string &  init_vector_2d,
const scifir::vector_unit_2d x 
)

Returns true if x is equal to the vector_unit_2d 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 413 of file vector_unit_2d.cpp.

414{
415 scifir::vector_unit_2d y(init_vector_2d);
416 return (y == x);
417}

◆ operator>>()

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

Allows that an istream initializes by string a vector_unit_2d x.

Definition at line 452 of file vector_unit_2d.cpp.

453{
454 char a[256];
455 is.getline(a, 256);
456 string b(a);
457 boost::trim(b);
459 return is;
460}