Skip to content

Commit

Permalink
Use of word derived changed by base, renaming various functions with …
Browse files Browse the repository at this point in the history
…derived in their name, because now the word derived is used similar to the SI system of units, but for all derived units of scifir-units, which are more than the derived units of the SI system of units. Explanation inside HISTORY.md updated too. Documentation updated related to that, too
  • Loading branch information
iarfen committed Jul 30, 2024
1 parent 945ac34 commit ff68960
Show file tree
Hide file tree
Showing 19 changed files with 74 additions and 74 deletions.
2 changes: 1 addition & 1 deletion HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Units

The unit classes have been hard to create, and have been a good challenge. Their first implementation was functionally perfect, they work good to allow to work with units instead of with numbers, as was their purpose. The implementation was with an abstract scalar_unit class and their derived unit classes, like mass, length and force, that were fixed in dimensions, allowing only to change their prefix. Besides that, there was the auto_unit class to allow to have a unit with any dimension needed. Apart from the scalar_units, there was the vector_unit class, and their derived vectorial unit classes, like force and velocity. In order to allow to have a vector_unit with any dimension, the class auto_vector was available. Needed for the implementation, there were the scalar_unit_crtp<> and vector_unit_crtp<> classes.
The unit classes have been hard to create, and have been a good challenge. Their first implementation was functionally perfect, they work good to allow to work with units instead of with numbers, as was their purpose. The implementation was with an abstract scalar_unit class and their child unit classes, like mass, length and force, that were fixed in dimensions, allowing only to change their prefix. Besides that, there was the auto_unit class to allow to have a unit with any dimension needed. Apart from the scalar_units, there was the vector_unit class, and their child vectorial unit classes, like force and velocity. In order to allow to have a vector_unit with any dimension, the class auto_vector was available. Needed for the implementation, there were the scalar_unit_crtp<> and vector_unit_crtp<> classes.

The problem with that first version of the units library was his complexity. The classes auto_unit and auto_vector were adding too much complexity. Also, the implementation wasn't as simple enough in order to allow for a compilation enoughly simple and close to the use of float as possible. That was very important, because to have an implementation that was producing machine code close to the code produced when working with float was meaning that the implementation was as perfect as possible, because it's not possible to have a unit class more simple than the central primitive type it uses.

Expand Down
16 changes: 8 additions & 8 deletions docs/dox/units/dimension.dox
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@
* \brief Returns the math between some prefix and the dimension. The difference with the other prefix_math() function is that the prefix is given as parameter.

* \fn bool dimension::is_simple_dimension() const
* \brief If the dimension doesn't has more derived dimensions, it's a simple dimension.
* \brief If the dimension doesn't has more base dimensions, it's a simple dimension.

* \fn bool dimension::is_composite_dimension() const
* \brief If the dimension has more simple dimensions, it's a composite dimension.
Expand All @@ -245,13 +245,13 @@
* \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_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.
* \brief Returns the base dimensions of the dimensions, which can be the same dimension or all the base dimension this dimension has, if it's a derived dimension.

* \fn void dimension::invert()
* \brief Changes the position of the dimension to the reverse, from the NUMERATOR to the DENOMINATOR, or from the DENOMINATOR to the NUMERATOR.

* \fn static void dimension::create_custom_dimension(const string& new_symbol, const string& init_dimensions)
* \brief Creates a new custom dimension, that's stored with its symbol, which is given as an string, and the dimensions it can be derived to, if this custom dimension is not a new basic dimension.
* \brief Creates a new custom dimension, that's stored with its symbol, which is given as an string, and the base dimensions it has, if this custom dimension is not a new base dimension.

* \fn static char* dimension::create_full_symbol(const string& full_symbol)
* \brief Creates a new dimension that's stored in the private static map dimension::full_symbols.
Expand All @@ -275,7 +275,7 @@
* \brief Creates the dimensions from an initialization string of dimensions

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

* \fn string scifir::to_string(const dimension& x)
* \brief Creates the string representation of a dimension
Expand All @@ -284,10 +284,10 @@
* \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_base_dimensions(const vector<dimension>& x)
* \brief Creates all the derived dimensions from a vector of dimensions.
* \brief Creates all the base dimensions from a vector of dimensions.

* \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.
* \brief Creates all the base 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)
* \brief Multiplies two vectors of dimensions. The result is normalized after, which means that equal dimensions at the numerator and at the denominator are cancelled.
Expand Down Expand Up @@ -317,10 +317,10 @@
* \brief Checks if two initialization strings of dimensions initialize the same basic dimensions.

* \fn bool scifir::equal_dimensions(const vector<dimension>& x, const vector<dimension>& y)
* brief Checks if the derived dimensions of two vectors of dimensions are equal.
* brief Checks if the base dimensions of two vectors of dimensions are equal.

* \fn bool scifir::equal_dimensions_and_prefixes(const vector<dimension>& x, const vector<dimension>& y)
* \brief Checks if the derived dimensions of two vectors of dimensions are equal, and if they have also the same prefixes.
* \brief Checks if the base dimensions of two vectors of dimensions are equal, and if they have also the same prefixes.

* \fn bool operator ==(const scifir::dimension& x, const scifir::dimension& y)
* \brief Checks if the dimension type, the position and the prefix of two dimensions are the same.
Expand Down
10 changes: 5 additions & 5 deletions docs/dox/units/scalar_unit.dox
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/** \class scifir::scalar_unit
* \brief Class that allows to create scalar units, which are composed of a value (as a float) and dimensions. The dimensions can be of any number, and be simple dimensions, composite dimensions and/or special names of dimensions. **Initialization string** example: "1 N".

* scalar_unit is a class that allows to have a scalar unit, which is composed of a value and one or more dimensions. All dimensions of the SI system of units are supported, and also all of its special names. The special names can be converted to its equivalent dimensions, too. scalar_unit classes have operators with all numeric types, and have operators with themselves. They can be displayed by its dimensions, its derived dimensions, or any custom combination of dimensions. When they change dimensions, like, for example, from meters to kilometers, their numeric value is changed accordingly.
* scalar_unit is a class that allows to have a scalar unit, which is composed of a value and one or more dimensions. All dimensions of the SI system of units are supported, and also all of its special names. The special names can be converted to its equivalent dimensions, too. scalar_unit classes have operators with all numeric types, and have operators with themselves. They can be displayed by its dimensions, its base dimensions, or any custom combination of dimensions. When they change dimensions, like, for example, from meters to kilometers, their numeric value is changed accordingly.
* POSSIBLE FEATURES
* At the present scalar_unit classes use a vector<dimension> to allow to have any number of dimensions, which can be simple, composite or special names. In order to size less, it's possible for some scalar_unit classes to have only one dimension, instead of a vector, that saves memory. With that approach, the dimension needs only 3 bytes. The possibility to switch between a single dimension and a vector<dimension> doesn't yet exists in C++, and so this important feature has been postposed.

Expand Down Expand Up @@ -154,8 +154,8 @@
* \fn dimension::type scalar_unit::get_single_dimension_type() const
* \brief Returns the dimension::type if there's only one dimension, returns dimension::NONE if there's more than one dimension or if the dimensions are empty.

* \fn vector<dimension> scalar_unit::get_derived_dimensions() const
* \brief Generates a set of the derived dimensions of the dimensions of the scalar_unit.
* \fn vector<dimension> scalar_unit::get_base_dimensions() const
* \brief Generates a set of the base dimensions of the dimensions of the scalar_unit.

* \fn const vector<dimension>& scalar_unit::get_dimensions() const
* \brief Read-only getter of the dimensions.
Expand All @@ -166,8 +166,8 @@
* \fn string scalar_unit::display(int number_of_decimals=2, bool with_brackets=false, bool use_close_prefix=false) const
* \brief Generates a string representation of the scalar_unit, with the value and the dimensions. The dimensions can be enclosed by brackets, and the value can be set to have the closest prefix.

* \fn string scalar_unit::derived_display(int number_of_decimals=2, bool with_brackets=false, bool use_close_prefix=false) const
* \brief Generates a string representation of the scalar_unit, with all dimensions converted to their derived counterpart.
* \fn string scalar_unit::base_display(int number_of_decimals=2, bool with_brackets=false, bool use_close_prefix=false) const
* \brief Generates a string representation of the scalar_unit, with its dimensions converted to their base counterpart.

* \fn string scalar_unit::custom_display(const string& init_dimensions, int number_of_decimals=2, bool with_brackets=false) const
* \brief Generates a string representation of the scalar_unit, with the dimensions changed to any set of dimensions, specified by an initialization string of dimensions.
Expand Down
4 changes: 2 additions & 2 deletions docs/dox/units/vector_unit_2d.dox
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@
* \fn string vector_unit_2d::vectorial_display(int number_of_decimals)
* \brief Displays the vector as the string representation of the scalar unit adding also the angle theta.

* \fn string vector_unit_2d::vectorial_derived_display(int number_of_decimals)
* \brief Displays the vector as the string representation of the scalar unit adding also the angle theta. It displays the dimensions with its derived dimensions.
* \fn string vector_unit_2d::vectorial_base_display(int number_of_decimals)
* \brief Displays the vector as the string representation of the scalar unit adding also the angle theta. It displays the dimensions with its base dimensions.

* \fn string vector_unit_2d::vectorial_custom_display(const string& init_dimensions,int number_of_decimals)
* \brief Displays the vector as the string representation of the scalar unit adding also the angle theta. It displays the vector in the dimensions specified in the initialization string of dimensions init_dimensions.
Expand Down
4 changes: 2 additions & 2 deletions docs/dox/units/vector_unit_3d.dox
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@
* \fn string vector_unit_3d::vectorial_display(int number_of_decimals)
* \brief Displays the vector as the string representation of the scalar unit adding also the angle theta and the angle phi.

* \fn string vector_unit_3d::vectorial_derived_display(int number_of_decimals)
* \brief Displays the vector as the string representation of the scalar unit adding also the angle theta and the angle phi. It displays the dimensions with its derived dimensions.
* \fn string vector_unit_3d::vectorial_base_display(int number_of_decimals)
* \brief Displays the vector as the string representation of the scalar unit adding also the angle theta and the angle phi. It displays the dimensions with its base dimensions.

* \fn string vector_unit_3d::vectorial_custom_display(const string& init_dimensions,int number_of_decimals)
* \brief Displays the vector as the string representation of the scalar unit adding also the angle theta and the angle phi. It displays the vector in the dimensions specified in the initialization string of dimensions init_dimensions.
Expand Down
4 changes: 2 additions & 2 deletions docs/dox/units/vector_unit_nd.dox
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@
* \fn string vector_unit_nd::vectorial_display(int number_of_decimals) const
* \brief Displays the vector as the string representation of the scalar unit adding also all the angles.

* \fn string vector_unit_nd::vectorial_derived_display(int number_of_decimals) const
* \brief Displays the vector as the string representation of the scalar unit adding also all the angles. It displays the dimensions with its derived dimensions.
* \fn string vector_unit_nd::vectorial_base_display(int number_of_decimals) const
* \brief Displays the vector as the string representation of the scalar unit adding also all the angles. It displays the dimensions with its base dimensions.

* \fn string vector_unit_nd::vectorial_custom_display(const string& init_dimensions,int number_of_decimals) const
* \brief Displays the vector as the string representation of the scalar unit adding also all the angles. It displays the vector in the dimensions specified in the initialization string of dimensions init_dimensions.
Expand Down
10 changes: 5 additions & 5 deletions tests/units/test_scalar_unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ TEST_CASE("scalar_unit class") {
scalar_unit d = 10_N/5_N;
CHECK(d.display_dimensions() == "[empty]");
scalar_unit e = 2_N;
CHECK(to_string(e.get_derived_dimensions()) == "kg*m/s2");
CHECK(to_string(e.get_base_dimensions()) == "kg*m/s2");
scalar_unit f("2 m2");
CHECK(f.display_dimensions() == "m2");
}
Expand All @@ -303,19 +303,19 @@ TEST_CASE("scalar_unit class") {
{
scalar_unit a(1.0f,"N");
CHECK(a.display() == "1 N");
CHECK(a.derived_display() == "1 kg*m/s2");
CHECK(a.base_display() == "1 kg*m/s2");
CHECK(a.custom_display("g*m/s2") == "1000 g*m/s2");
scalar_unit b("100 m");
CHECK(b.display() == "100 m");
CHECK(b.display(2,false,true) == "1 hm");
scalar_unit c("10 N");
CHECK(c.derived_display(2,false,true) == "10 kg*m/s2");
CHECK(c.base_display(2,false,true) == "10 kg*m/s2");
scalar_unit c2("100 °C");
CHECK(c2.derived_display(2,false,false) == "373.14 K");
CHECK(c2.base_display(2,false,false) == "373.14 K");
scalar_unit d("0 m");
CHECK(d.display(2,false,true) == "0 m");
scalar_unit e("1 AU");
CHECK(e.derived_display(2,false,true) == "1.49598e+11 m");
CHECK(e.base_display(2,false,true) == "1.49598e+11 m");
scalar_unit f("1 km/hour");
CHECK(f.custom_display("m/s",2,true) == "0.27 [m/s]");
scalar_unit g = 373.15_K;
Expand Down
4 changes: 2 additions & 2 deletions tests/units/test_vector_unit_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ TEST_CASE("class vector_unit_2d")
{
vector_unit_2d a(1.0f,"N",20);
CHECK(a.vectorial_display() == "1 N 20θ");
CHECK(a.vectorial_derived_display() == "1 kg*m/s2 20θ");
CHECK(a.vectorial_base_display() == "1 kg*m/s2 20θ");
CHECK(a.vectorial_custom_display("g*m/s2") == "1000 g*m/s2 20θ");
}

Expand Down Expand Up @@ -269,7 +269,7 @@ TEST_CASE("class vector_unit_2d")
{
vector_unit_2d a(1.0f,"N",20);
CHECK(a.vectorial_display() == "1 N 20θ");
CHECK(a.vectorial_derived_display() == "1 kg*m/s2 20θ");
CHECK(a.vectorial_base_display() == "1 kg*m/s2 20θ");
CHECK(a.vectorial_custom_display("g*m/s2") == "1000 g*m/s2 20θ");
}

Expand Down
2 changes: 1 addition & 1 deletion tests/units/test_vector_unit_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ TEST_CASE("class vector_unit_3d")
{
vector_unit_3d a(1,"N",20,20);
CHECK(a.vectorial_display() == "1 N 20θ 20Φ");
CHECK(a.vectorial_derived_display() == "1 kg*m/s2 20θ 20Φ");
CHECK(a.vectorial_base_display() == "1 kg*m/s2 20θ 20Φ");
CHECK(a.vectorial_custom_display("g*m/s2") == "1000 g*m/s2 20θ 20Φ");
}

Expand Down
2 changes: 1 addition & 1 deletion tests/units/test_vector_unit_nd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ TEST_CASE("class vector_unit_nd")
{
vector_unit_nd a(1,"N",{20,20,20,20});
CHECK(a.vectorial_display() == "1 N 20° 20° 20° 20°");
CHECK(a.vectorial_derived_display() == "1 kg*m/s2 20° 20° 20° 20°");
CHECK(a.vectorial_base_display() == "1 kg*m/s2 20° 20° 20° 20°");
CHECK(a.vectorial_custom_display("g*m/s2") == "1000 g*m/s2 20° 20° 20° 20°");
}

Expand Down
12 changes: 6 additions & 6 deletions units/dimension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2062,15 +2062,15 @@ namespace scifir

bool equal_dimensions(const vector<dimension>& x,const vector<dimension>& 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<dimension> x_base_dimensions = create_base_dimensions(x);
vector<dimension> y_base_dimensions = create_base_dimensions(y);
if (x_base_dimensions.size() == y_base_dimensions.size())
{
vector<unsigned int> skip = vector<unsigned int>();
for (const dimension& x_dimension: x_derived_dimensions)
for (const dimension& x_dimension: x_base_dimensions)
{
bool is_equal = false;
for (unsigned int j = 0; j < y_derived_dimensions.size(); j++)
for (unsigned int j = 0; j < y_base_dimensions.size(); j++)
{
bool skip_j = false;
if (skip.size() > 0)
Expand All @@ -2087,7 +2087,7 @@ namespace scifir
{
continue;
}
if (x_dimension.dimension_type == y_derived_dimensions[j].dimension_type and x_dimension.dimension_position == y_derived_dimensions[j].dimension_position)
if (x_dimension.dimension_type == y_base_dimensions[j].dimension_type and x_dimension.dimension_position == y_base_dimensions[j].dimension_position)
{
skip.push_back(j);
is_equal = true;
Expand Down
Loading

0 comments on commit ff68960

Please sign in to comment.