Skip to content
Snippets Groups Projects
Commit d3c7a82e authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

More const-correctness in the unit system.

parent 6eec891e
Branches
Tags
1 merge request!143Gravity particles
......@@ -59,7 +59,7 @@ void initUnitSystem(struct UnitSystem* us) {
* @param us The UnitSystem used
* @param baseUnit The base unit
*/
double getBaseUnit(struct UnitSystem* us, enum BaseUnits baseUnit) {
double getBaseUnit(const struct UnitSystem* us, enum BaseUnits baseUnit) {
switch (baseUnit) {
case UNIT_MASS:
return us->UnitMass_in_cgs;
......@@ -263,7 +263,8 @@ void getBaseUnitExponantsArray(float baseUnitsExp[5],
* @param us The system of units in use
* @param unit The unit to convert
*/
double conversionFactor(struct UnitSystem* us, enum UnitConversionFactor unit) {
double conversionFactor(const struct UnitSystem* us,
enum UnitConversionFactor unit) {
float baseUnitsExp[5] = {0.f};
getBaseUnitExponantsArray(baseUnitsExp, unit);
......@@ -276,7 +277,7 @@ double conversionFactor(struct UnitSystem* us, enum UnitConversionFactor unit) {
* @param us The system of units in use
* @param unit The unit to convert
*/
float hFactor(struct UnitSystem* us, enum UnitConversionFactor unit) {
float hFactor(const struct UnitSystem* us, enum UnitConversionFactor unit) {
float baseUnitsExp[5] = {0.f};
getBaseUnitExponantsArray(baseUnitsExp, unit);
......@@ -289,7 +290,7 @@ float hFactor(struct UnitSystem* us, enum UnitConversionFactor unit) {
* @param us The system of units in use
* @param unit The unit to convert
*/
float aFactor(struct UnitSystem* us, enum UnitConversionFactor unit) {
float aFactor(const struct UnitSystem* us, enum UnitConversionFactor unit) {
float baseUnitsExp[5] = {0.f};
getBaseUnitExponantsArray(baseUnitsExp, unit);
......@@ -301,7 +302,7 @@ float aFactor(struct UnitSystem* us, enum UnitConversionFactor unit) {
* @brief Returns a string containing the exponents of the base units making up
* the conversion factors
*/
void conversionString(char* buffer, struct UnitSystem* us,
void conversionString(char* buffer, const struct UnitSystem* us,
enum UnitConversionFactor unit) {
float baseUnitsExp[5] = {0.f};
......@@ -317,8 +318,8 @@ void conversionString(char* buffer, struct UnitSystem* us,
* @param baseUnitsExponants The exponent of each base units required to form
* the desired quantity. See conversionFactor() for a working example
*/
double generalConversionFactor(struct UnitSystem* us,
float baseUnitsExponants[5]) {
double generalConversionFactor(const struct UnitSystem* us,
const float baseUnitsExponants[5]) {
double factor = 1.;
int i;
......@@ -335,7 +336,8 @@ double generalConversionFactor(struct UnitSystem* us,
* @param baseUnitsExponants The exponent of each base units required to form
* the desired quantity. See conversionFactor() for a working example
*/
float generalhFactor(struct UnitSystem* us, float baseUnitsExponants[5]) {
float generalhFactor(const struct UnitSystem* us,
const float baseUnitsExponants[5]) {
float factor_exp = 0.f;
factor_exp += -baseUnitsExponants[UNIT_MASS];
......@@ -352,7 +354,8 @@ float generalhFactor(struct UnitSystem* us, float baseUnitsExponants[5]) {
* @param baseUnitsExponants The exponent of each base units required to form
* the desired quantity. See conversionFactor() for a working example
*/
float generalaFactor(struct UnitSystem* us, float baseUnitsExponants[5]) {
float generalaFactor(const struct UnitSystem* us,
const float baseUnitsExponants[5]) {
float factor_exp = 0.f;
factor_exp += baseUnitsExponants[UNIT_LENGTH];
......@@ -369,8 +372,8 @@ float generalaFactor(struct UnitSystem* us, float baseUnitsExponants[5]) {
* @param baseUnitsExponants The exponent of each base units required to form
* the desired quantity. See conversionFactor() for a working example
*/
void generalConversionString(char* buffer, struct UnitSystem* us,
float baseUnitsExponants[5]) {
void generalConversionString(char* buffer, const struct UnitSystem* us,
const float baseUnitsExponants[5]) {
char temp[14];
double a_exp = generalaFactor(us, baseUnitsExponants);
double h_exp = generalhFactor(us, baseUnitsExponants);
......
......@@ -94,7 +94,7 @@ void initUnitSystem(struct UnitSystem*);
/**
* @brief Returns the base unit conversion factor for a given unit system
*/
double getBaseUnit(struct UnitSystem*, enum BaseUnits);
double getBaseUnit(const struct UnitSystem*, enum BaseUnits);
/**
* @brief Returns the base unit symbol in the cgs system
......@@ -110,49 +110,52 @@ const char* getBaseUnitCGSSymbol(enum BaseUnits);
* @brief Returns the conversion factor for a given unit (expressed in terms of
* the 5 fundamental units) in the chosen unit system
*/
double generalConversionFactor(struct UnitSystem* us,
float baseUnitsExponants[5]);
double generalConversionFactor(const struct UnitSystem* us,
const float baseUnitsExponants[5]);
/**
* @brief Returns the conversion factor for a given unit in the chosen unit
* system
*/
double conversionFactor(struct UnitSystem* us, enum UnitConversionFactor unit);
double conversionFactor(const struct UnitSystem* us,
enum UnitConversionFactor unit);
/**
* @brief Returns the h factor for a given unit (expressed in terms of the 5
* fundamental units) in the chosen unit system
*/
float generalhFactor(struct UnitSystem* us, float baseUnitsExponants[5]);
float generalhFactor(const struct UnitSystem* us,
const float baseUnitsExponants[5]);
/**
* @brief Returns the h factor for a given unit in the chosen unit system
*/
float hFactor(struct UnitSystem* us, enum UnitConversionFactor unit);
float hFactor(const struct UnitSystem* us, enum UnitConversionFactor unit);
/**
* @brief Returns the scaling factor for a given unit (expressed in terms of the
* 5 fundamental units) in the chosen unit system
*/
float generalaFactor(struct UnitSystem* us, float baseUnitsExponants[5]);
float generalaFactor(const struct UnitSystem* us,
const float baseUnitsExponants[5]);
/**
* @brief Returns the scaling factor for a given unit in the chosen unit system
*/
float aFactor(struct UnitSystem* us, enum UnitConversionFactor unit);
float aFactor(const struct UnitSystem* us, enum UnitConversionFactor unit);
/**
* @brief Returns a string containing the exponents of the base units making up
* the conversion factors (expressed in terms of the 5 fundamental units)
*/
void generalConversionString(char* buffer, struct UnitSystem* us,
float baseUnitsExponants[5]);
void generalConversionString(char* buffer, const struct UnitSystem* us,
const float baseUnitsExponants[5]);
/**
* @brief Returns a string containing the exponents of the base units making up
* the conversion factors
*/
void conversionString(char* buffer, struct UnitSystem* us,
void conversionString(char* buffer, const struct UnitSystem* us,
enum UnitConversionFactor unit);
#endif /* SWIFT_UNITS_H */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment