Skip to content

Commit

Permalink
Function create_simple_dimensions() and get_simple_dimensions() renam…
Browse files Browse the repository at this point in the history
…ed to create_base_dimensions() and get_base_dimensions(), respectively, in order to improve readability. Documentation and test updated with this change
  • Loading branch information
iarfen committed Jul 29, 2024
1 parent e389d56 commit fdd2534
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 95 deletions.
8 changes: 4 additions & 4 deletions docs/dox/units/dimension.dox
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@
* \fn bool dimension::is_dimensionless() const
* \brief If the dimension_type is DEGREE, RADIAN or STERADIAN, it's considered dimensionless, following the SI system of units. If the dimension_type is NONE, it's considered dimensionless too.

* \fn vector<dimension> dimension::get_simple_dimensions() const
* \fn vector<dimension> dimension::get_base_dimensions() const
* \brief Returns the simple dimensions of the dimension, which are different than the dimension, and more than one, if the dimension is not a simple dimension but a derived dimension.

* \fn void dimension::invert()
Expand Down Expand Up @@ -271,7 +271,7 @@
* \fn vector<dimension> scifir::create_dimensions(string init_dimensions)
* \brief Creates the dimensions from an initialization string of dimensions

* \fn vector<dimension> scifir::create_simple_dimensions(const string& init_dimensions)
* \fn vector<dimension> scifir::create_base_dimensions(const string& init_dimensions)
* \brief Creates the derived dimensions from an initialization string of dimensions

* \fn string scifir::to_string(const dimension& x)
Expand All @@ -280,10 +280,10 @@
* \fn string scifir::to_string(const vector<dimension>& x_dimensions, bool with_brackets)
* \brief Creates the string representation of a vector of dimensions. Used to display the dimensions of scalar_unit and all vector_unit classes. The dimensions can be displayed optionally between brackets like '[]' too.

* \fn vector<dimension> scifir::create_simple_dimensions(const vector<dimension>& x)
* \fn vector<dimension> scifir::create_base_dimensions(const vector<dimension>& x)
* \brief Creates all the derived dimensions from a vector of dimensions.

* \fn vector<dimension> scifir::create_simple_dimensions(const vector<dimension>& x, long double& value)
* \fn vector<dimension> scifir::create_base_dimensions(const vector<dimension>& x, long double& value)
* \brief Creates all the derived dimensions from a vector of dimensions, updating also the associated value related to those dimensions based on the prefix math and the conversion factor of the dimension, if that conversion factor is different than one.

* \fn vector<dimension> scifir::multiply_dimensions(const vector<dimension>& x, const vector<dimension>& y)
Expand Down
120 changes: 60 additions & 60 deletions tests/units/test_dimension.cpp

Large diffs are not rendered by default.

28 changes: 14 additions & 14 deletions units/dimension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1302,7 +1302,7 @@ namespace scifir
}
}

vector<dimension> dimension::get_simple_dimensions() const
vector<dimension> dimension::get_base_dimensions() const
{
vector<dimension> basic_dimensions = vector<dimension>();
switch (dimension_type)
Expand Down Expand Up @@ -1724,18 +1724,18 @@ namespace scifir
return dimensions;
}

vector<dimension> create_simple_dimensions(const string& init_dimensions)
vector<dimension> create_base_dimensions(const string& init_dimensions)
{
vector<dimension> new_dimensions = create_dimensions(init_dimensions);
return create_simple_dimensions(new_dimensions);
return create_base_dimensions(new_dimensions);
}

vector<dimension> create_simple_dimensions(const vector<dimension>& x)
vector<dimension> create_base_dimensions(const vector<dimension>& x)
{
vector<dimension> new_x = vector<dimension>();
for(unsigned int i = 0; i < x.size(); i++)
{
vector<dimension> x_subdimensions = x[i].get_simple_dimensions();
vector<dimension> x_subdimensions = x[i].get_base_dimensions();
for (dimension& x_subdimension : x_subdimensions)
{
if (x[i].dimension_position == dimension::DENOMINATOR)
Expand All @@ -1748,7 +1748,7 @@ namespace scifir
return new_x;
}

vector<dimension> create_simple_dimensions(const vector<dimension>& x,long double& value)
vector<dimension> create_base_dimensions(const vector<dimension>& x,long double& value)
{
vector<dimension> new_x = vector<dimension>();
for(unsigned int i = 0; i < x.size(); i++)
Expand All @@ -1763,7 +1763,7 @@ namespace scifir
value /= x[i].get_conversion_factor();
value /= x[i].prefix_math();
}
vector<dimension> x_subdimensions = x[i].get_simple_dimensions();
vector<dimension> x_subdimensions = x[i].get_base_dimensions();
for (dimension& x_subdimension : x_subdimensions)
{
if (x[i].dimension_position == dimension::DENOMINATOR)
Expand Down Expand Up @@ -1892,7 +1892,7 @@ namespace scifir

vector<dimension> normalize_dimensions(const vector<dimension>& x)
{
vector<dimension> new_x = create_simple_dimensions(x);
vector<dimension> new_x = create_base_dimensions(x);
vector<unsigned int> skip_dimensions = vector<unsigned int>();
for(unsigned int i = 0; i < new_x.size(); i++)
{
Expand Down Expand Up @@ -1942,7 +1942,7 @@ namespace scifir

vector<dimension> normalize_dimensions(const vector<dimension>& x,long double& value)
{
vector<dimension> new_x = create_simple_dimensions(x,value);
vector<dimension> new_x = create_base_dimensions(x,value);
vector<unsigned int> skip_dimensions = vector<unsigned int>();
for(unsigned int i = 0; i < new_x.size(); i++)
{
Expand Down Expand Up @@ -2013,9 +2013,9 @@ namespace scifir

bool common_dimension(const dimension& x,const dimension& y)
{
for (const dimension& x_dimension : x.get_simple_dimensions())
for (const dimension& x_dimension : x.get_base_dimensions())
{
for (const dimension& y_dimension : y.get_simple_dimensions())
for (const dimension& y_dimension : y.get_base_dimensions())
{
if (x_dimension.dimension_type == y_dimension.dimension_type and x_dimension.dimension_position == y_dimension.dimension_position)
{
Expand All @@ -2035,8 +2035,8 @@ namespace scifir

bool equal_dimensions(const vector<dimension>& x,const vector<dimension>& y)
{
vector<dimension> x_derived_dimensions = create_simple_dimensions(x);
vector<dimension> y_derived_dimensions = create_simple_dimensions(y);
vector<dimension> x_derived_dimensions = create_base_dimensions(x);
vector<dimension> y_derived_dimensions = create_base_dimensions(y);
if (x_derived_dimensions.size() == y_derived_dimensions.size())
{
vector<unsigned int> skip = vector<unsigned int>();
Expand Down Expand Up @@ -2138,7 +2138,7 @@ bool operator ==(const scifir::dimension& x,const scifir::dimension& y)
}
}

bool operator!=(const scifir::dimension& x,const scifir::dimension& y)
bool operator !=(const scifir::dimension& x,const scifir::dimension& y)
{
return !(x == y);
}
Expand Down
12 changes: 6 additions & 6 deletions units/dimension.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace scifir
class dimension;

vector<dimension> create_dimensions(string init_dimensions);
vector<dimension> create_simple_dimensions(const string& init_dimensions);
vector<dimension> create_base_dimensions(const string& init_dimensions);

class dimension
{
Expand Down Expand Up @@ -65,7 +65,7 @@ namespace scifir

bool is_dimensionless() const;

vector<dimension> get_simple_dimensions() const;
vector<dimension> get_base_dimensions() const;

void invert();

Expand All @@ -78,7 +78,7 @@ namespace scifir
{
if (dimension::base_dimensions.count(new_symbol) == 0)
{
dimension::base_dimensions[new_symbol] = create_simple_dimensions(init_dimensions);
dimension::base_dimensions[new_symbol] = create_base_dimensions(init_dimensions);
}
}

Expand Down Expand Up @@ -171,8 +171,8 @@ namespace scifir
string to_string(const dimension& x);
string to_string(const vector<dimension>& x_dimensions,bool with_brackets = false);

vector<dimension> create_simple_dimensions(const vector<dimension>& x);
vector<dimension> create_simple_dimensions(const vector<dimension>& x,long double& value);
vector<dimension> create_base_dimensions(const vector<dimension>& x);
vector<dimension> create_base_dimensions(const vector<dimension>& x,long double& value);

vector<dimension> multiply_dimensions(const vector<dimension>& x,const vector<dimension>& y);
vector<dimension> multiply_dimensions(vector<dimension> x,const vector<dimension>& y,long double& value);
Expand All @@ -195,7 +195,7 @@ namespace scifir
}

bool operator ==(const scifir::dimension& x,const scifir::dimension& y);
bool operator!=(const scifir::dimension& x,const scifir::dimension& y);
bool operator !=(const scifir::dimension& x,const scifir::dimension& y);

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

Expand Down
14 changes: 7 additions & 7 deletions units/scalar_unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ namespace scifir
remove_dimension(actual_dimension);
if(actual_dimension.is_composite_dimension())
{
vector<dimension> derived_dimensions = actual_dimension.get_simple_dimensions();
vector<dimension> derived_dimensions = actual_dimension.get_base_dimensions();
for(const dimension& derived_dimension : derived_dimensions)
{
remove_dimension(derived_dimension);
Expand All @@ -247,7 +247,7 @@ namespace scifir
add_dimension(new_dimension);
if(new_dimension.is_composite_dimension())
{
vector<dimension> new_derived_dimensions = new_dimension.get_simple_dimensions();
vector<dimension> new_derived_dimensions = new_dimension.get_base_dimensions();
for(const dimension& new_derived_dimension : new_derived_dimensions)
{
add_dimension(new_derived_dimension);
Expand Down Expand Up @@ -275,7 +275,7 @@ namespace scifir
remove_dimension(actual_dimension);
if(actual_dimension.is_composite_dimension())
{
vector<dimension> derived_dimensions = actual_dimension.get_simple_dimensions();
vector<dimension> derived_dimensions = actual_dimension.get_base_dimensions();
for(const dimension& derived_dimension : derived_dimensions)
{
remove_dimension(derived_dimension);
Expand All @@ -288,7 +288,7 @@ namespace scifir
add_dimension(new_dimension);
if(new_dimension.is_composite_dimension())
{
vector<dimension> new_derived_dimensions = new_dimension.get_simple_dimensions();
vector<dimension> new_derived_dimensions = new_dimension.get_base_dimensions();
for(const dimension& new_derived_dimension : new_derived_dimensions)
{
add_dimension(new_derived_dimension);
Expand Down Expand Up @@ -407,7 +407,7 @@ namespace scifir

vector<dimension> scalar_unit::get_derived_dimensions() const
{
return create_simple_dimensions(dimensions);
return create_base_dimensions(dimensions);
}

string scalar_unit::display(int number_of_decimals,bool with_brackets,bool use_close_prefix) const
Expand Down Expand Up @@ -443,7 +443,7 @@ namespace scifir
{
ostringstream output;
long double x_value = get_value();
vector<dimension> derived_dimensions = create_simple_dimensions(dimensions,x_value);
vector<dimension> derived_dimensions = create_base_dimensions(dimensions,x_value);
if (derived_dimensions.size() == 1 and use_close_prefix == true)
{
int value_scale = int(log10(get_value()));
Expand Down Expand Up @@ -481,7 +481,7 @@ namespace scifir
new_value /= x_dimension.prefix_math();
}
}
vector<dimension> derived_dimensions = create_simple_dimensions(dimensions);
vector<dimension> derived_dimensions = create_base_dimensions(dimensions);
for(const dimension& x_dimension : derived_dimensions)
{
if (x_dimension.dimension_position == dimension::NUMERATOR)
Expand Down
2 changes: 1 addition & 1 deletion units/scalar_unit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
} \
\
const string name::dimensions_match = init_dimensions; \
const vector<dimension> name::real_dimensions = create_simple_dimensions(init_dimensions)
const vector<dimension> name::real_dimensions = create_base_dimensions(init_dimensions)

using namespace std;

Expand Down
2 changes: 1 addition & 1 deletion units/vector_unit_2d.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
name##_2d::name##_2d(const name##_2d& x) : vector_unit_2d(x) {} \
name##_2d::name##_2d(name##_2d&& x) : vector_unit_2d(std::move(x)) {} \
const string name##_2d::dimensions_match = init_dimensions; \
const vector<dimension> name##_2d::real_dimensions = create_simple_dimensions(init_dimensions)
const vector<dimension> name##_2d::real_dimensions = create_base_dimensions(init_dimensions)

using namespace std;

Expand Down
2 changes: 1 addition & 1 deletion units/vector_unit_3d.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
name##_3d::name##_3d(const name##_3d& x) : vector_unit_3d(x) {} \
name##_3d::name##_3d(name##_3d&& x) : vector_unit_3d(std::move(x)) {} \
const string name##_3d::dimensions_match = init_dimensions; \
const vector<dimension> name##_3d::real_dimensions = create_simple_dimensions(init_dimensions)
const vector<dimension> name##_3d::real_dimensions = create_base_dimensions(init_dimensions)

#define VECTOR_UNIT_HPP(name) SCALAR_UNIT_HPP(name); \
VECTOR_UNIT_2D_HPP(name); \
Expand Down
2 changes: 1 addition & 1 deletion units/vector_unit_nd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
name##_nd::name##_nd(const name##_nd& x) : vector_unit_nd(x) {} \
name##_nd::name##_nd(name##_nd&& x) : vector_unit_nd(std::move(x)) {} \
const string name##_nd::dimensions_match = init_dimensions; \
const vector<dimension> name##_nd::real_dimensions = create_simple_dimensions(init_dimensions)
const vector<dimension> name##_nd::real_dimensions = create_base_dimensions(init_dimensions)

using namespace std;

Expand Down

0 comments on commit fdd2534

Please sign in to comment.