Common functions to work with and convert metric and imperial measurements. More...
Enumerations | |
enum | ERoundType { kInvalid = 0, kImperial_1_32 = 1, kImperialDecimal = 2, kMetric_1_100 = 3, kMetric_1_10 = 4, kMetric_5_10 = 5, kMetric_mm = 6, kImperial_up_1_4 = 7, kImperial_up_1_2 = 8 } |
Functions | |
static MM | IN_TO_MM (const IN &value) |
Convert inches to metric. More... | |
void | internalSanityCheck (void) |
Run 1-time startup tests with the metric/imperial measurement functions. More... | |
std::string | inToStr (const IN in) |
Convert fractional inches to a string. More... | |
bool | isImperial (const MM mm) |
Checks to see if the measurement is likely to be imperial. More... | |
bool | isImperial (const std::string &str) |
Checks to see if the string is likely to be imperial. More... | |
bool | isMetric (const MM mm) |
Checks to see if the measurement is likely to be metric. More... | |
bool | isMetric (const std::string &str) |
Checks to see if the string is likely to be metric. More... | |
MM | metricRound (const MM mm, const ERoundType type) |
Round the given measurement using the specified method. More... | |
MM | metricRoundTo32Imperial (const MM mm) |
Metric wrapper for roundTo32Imperial(). More... | |
MM | metricRoundToHalfTenthMM (const MM mm) |
Round the given measurement to the nearest 0.5 mm value. For example, 0.0, 0.5, 1.0, 1.5, ... More... | |
MM | metricRoundToHundrethMM (const MM mm) |
Round the given measurement to the nearest 0.01 mm value. For example, 0.01, 0.02, 0.03, ... More... | |
MM | metricRoundToImperialDecimal (const MM mm) |
Round so there remains 2 decimal digits once converted to inches. For example, 1/8" becomes 0.13". More... | |
MM | metricRoundToMM (const MM mm) |
Round the given measurement to the nearest 1.0 mm value. For example, 0.0, 1.0, 2.0, 3.0, ... More... | |
MM | metricRoundToTenthMM (const MM mm) |
Round the given measurement to the nearest 0.1 mm value. For example, 0.0, 0.1, 0.2, 0.3, ... More... | |
MM | metricRoundUpTo2Imperial (const MM mm) |
Round UP the given inches to the nearest 1/2" value. For example, 3 1/32" becomes 3 1/2". More... | |
MM | metricRoundUpTo4Imperial (const MM mm) |
Round UP the given inches to the nearest 1/4" value. For example, 3 1/32" becomes 3 1/4". More... | |
static IN | MM_TO_IN (const MM &value) |
Convert metric to inches. More... | |
std::string | mmToStr (const MM mm) |
Convert a fractional mm value to a metric or imperial string. More... | |
std::string | mmToStr (const MM mm, const ERoundType type) |
Similar to the other mmToStr() function, but this one describes the rounding and the units to use when generating the string. More... | |
bool | nearlyTheSame (const double a, const double b) |
Determine if the two values are nearly the same (within 1/64"). More... | |
bool | parse (const std::string &str, double &value, int &numerator, int &denominator, EUnits &units) |
Parse a text string and get back a measurement value. More... | |
std::string | reformatStr (const std::string &str) |
If the input string is a valid measurement, reformat the string. Make no change if the string is not a valid measurement. More... | |
IN | roundTo32Imperial (const IN in) |
Round the given inches to the nearest 1/32" value. More... | |
IN | roundUpTo2Imperial (const IN in) |
Round UP the given inches to the nearest 1/2" value. More... | |
IN | roundUpTo4Imperial (const IN in) |
Round UP the given inches to the nearest 1/4" value. More... | |
void | split32Imperial (const IN in, int32_t &inches, int32_t &numerator, int32_t &denominator) |
Split values such as 17 1/32" into 3 components (17, 1, and 32). More... | |
bool | strToMM (const std::string &str, MM &value) |
Convert a text string to a MM value. More... | |
bool | validate (const std::string &str) |
Determine if the text is a valid measurement string. More... | |
void | valuesGreaterThanAreConsideredMetric (const double value) |
When parsing text, if the resulting values are ambiguous, numbers greater than "X" will be considered as metric, while values <= "X" will be considered imperial. More... | |
static double | MM_TO_FT (const MM &value) |
Convert metric to feet. More... | |
static double | MM_TO_FT_ROUNDED (const MM &value) |
Convert metric to feet. More... | |
static IN | MM_SQUARE_TO_FEET_SQUARE (const MM &value) |
Convert mm^2 to feet^2. The types "MM" and "IN" are misleading. This takes mm^2 and returns feet^2. More... | |
static IN | MM_SQUARE_TO_FEET_SQUARE_ROUNDED (const MM &value) |
Convert mm^2 to feet^2. The types "MM" and "IN" are misleading. This takes mm^2 and returns feet^2. More... | |
Variables | |
const IN | inches_1_32 = 1.0/32.0 |
1/32" is equal to 0.03125" More... | |
const IN | inches_1_64 = 1.0/64.0 |
1/64" is equal to 0.015625" More... | |
const IN | inches_2_3_16 = 2.0 + 3.0/16.0 |
Default size (in inches) of rails and stiles. More... | |
const MM | inches_to_mm = 25.4 |
Conversion factor to convert inches to metric. This is an exact measurement. 1" == 25.4 mm. More... | |
const IN | mm_to_inches = 1.0/25.4 |
Conversion factor to convert metric to inches. 1 mm == 0.039370079". More... | |
const long double | square_inches_to_square_mm = 25.4 * 25.4 |
Conversion factor for area calculations. More... | |
const long double | square_feet_to_square_mm = 25.4 * 25.4 * 12.0 * 12.0 |
12" * 12" == 92903.04 mm^2 More... | |
const long double | square_mm_to_square_inches = 1.0 / square_inches_to_square_mm |
0.001550003 More... | |
const long double | square_mm_to_square_feet = 1.0 / square_feet_to_square_mm |
0.000010764 More... | |
Common functions to work with and convert metric and imperial measurements.
Convert inches to metric.
References inches_to_mm.
Referenced by internalSanityCheck(), inToStr(), metricRoundTo32Imperial(), metricRoundToImperialDecimal(), metricRoundUpTo2Imperial(), metricRoundUpTo4Imperial(), and split32Imperial().
void Lox::Measurement::internalSanityCheck | ( | void | ) |
Run 1-time startup tests with the metric/imperial measurement functions.
References IN_TO_MM(), inches_1_32, inches_1_64, inches_2_3_16, inches_to_mm, inToStr(), LOX_WHERE, mm_to_inches, mmToStr(), Lox::Numbers::nearlyTheSame(), Lox::Numbers::reformatStr(), and strToMM().
std::string Lox::Measurement::inToStr | ( | const IN | in | ) |
Convert fractional inches to a string.
References IN_TO_MM(), and mmToStr().
Referenced by internalSanityCheck().
bool Lox::Measurement::isImperial | ( | const MM | mm | ) |
Checks to see if the measurement is likely to be imperial.
MM
, meaning you may have to convert from inches to mm. References mmToStr().
bool Lox::Measurement::isImperial | ( | const std::string & | str | ) |
Checks to see if the string is likely to be imperial.
References Lox::trim().
bool Lox::Measurement::isMetric | ( | const MM | mm | ) |
Checks to see if the measurement is likely to be metric.
References mmToStr().
bool Lox::Measurement::isMetric | ( | const std::string & | str | ) |
Checks to see if the string is likely to be metric.
References Lox::trim().
Lox::MM Lox::Measurement::metricRound | ( | const MM | mm, |
const ERoundType | type | ||
) |
Round the given measurement using the specified method.
References kImperial_1_32, kImperial_up_1_2, kImperial_up_1_4, kImperialDecimal, Lox::Colours::kInvalid, kMetric_1_10, kMetric_1_100, kMetric_5_10, kMetric_mm, metricRoundTo32Imperial(), metricRoundToHalfTenthMM(), metricRoundToHundrethMM(), metricRoundToImperialDecimal(), metricRoundToMM(), metricRoundToTenthMM(), metricRoundUpTo2Imperial(), and metricRoundUpTo4Imperial().
Referenced by mmToStr().
Metric wrapper for roundTo32Imperial().
References IN_TO_MM(), MM_TO_IN(), and roundTo32Imperial().
Referenced by metricRound().
Round the given measurement to the nearest 0.5 mm value. For example, 0.0, 0.5, 1.0, 1.5, ...
Referenced by metricRound().
Round the given measurement to the nearest 0.01 mm value. For example, 0.01, 0.02, 0.03, ...
Referenced by metricRound().
Round so there remains 2 decimal digits once converted to inches. For example, 1/8" becomes 0.13".
References IN_TO_MM(), and MM_TO_IN().
Referenced by metricRound().
Round the given measurement to the nearest 1.0 mm value. For example, 0.0, 1.0, 2.0, 3.0, ...
Referenced by metricRound().
Round the given measurement to the nearest 0.1 mm value. For example, 0.0, 0.1, 0.2, 0.3, ...
Referenced by metricRound().
Round UP the given inches to the nearest 1/2" value. For example, 3 1/32" becomes 3 1/2".
References IN_TO_MM(), MM_TO_IN(), and roundUpTo2Imperial().
Referenced by metricRound().
Round UP the given inches to the nearest 1/4" value. For example, 3 1/32" becomes 3 1/4".
References IN_TO_MM(), MM_TO_IN(), and roundUpTo4Imperial().
Referenced by metricRound().
Convert mm^2 to feet^2. The types "MM" and "IN" are misleading. This takes mm^2 and returns feet^2.
Referenced by MM_SQUARE_TO_FEET_SQUARE_ROUNDED().
Convert mm^2 to feet^2. The types "MM" and "IN" are misleading. This takes mm^2 and returns feet^2.
References MM_SQUARE_TO_FEET_SQUARE(), and Lox::Numbers::round_to_2_decimals().
|
inlinestatic |
Convert metric to feet.
References MM_TO_IN().
Referenced by MM_TO_FT_ROUNDED().
|
inlinestatic |
Convert metric to feet.
References MM_TO_FT(), and Lox::Numbers::round_to_2_decimals().
Convert metric to inches.
References mm_to_inches.
Referenced by metricRoundTo32Imperial(), metricRoundToImperialDecimal(), metricRoundUpTo2Imperial(), metricRoundUpTo4Imperial(), MM_TO_FT(), and mmToStr().
std::string Lox::Measurement::mmToStr | ( | const MM | mm | ) |
Convert a fractional mm value to a metric or imperial string.
The decision to use metric or imperial depends on whichever system best represents the fractional mm value.
References inches_1_32, mm_to_inches, and Lox::Numbers::nearlyTheSame().
Referenced by internalSanityCheck(), inToStr(), isImperial(), isMetric(), mmToStr(), reformatStr(), and split32Imperial().
std::string Lox::Measurement::mmToStr | ( | const MM | mm, |
const ERoundType | type | ||
) |
Similar to the other mmToStr() function, but this one describes the rounding and the units to use when generating the string.
References kImperial_1_32, kImperial_up_1_2, kImperial_up_1_4, kImperialDecimal, Lox::Colours::kInvalid, kMetric_1_10, kMetric_1_100, kMetric_5_10, kMetric_mm, metricRound(), MM_TO_IN(), and mmToStr().
bool Lox::Measurement::nearlyTheSame | ( | const double | a, |
const double | b | ||
) |
Determine if the two values are nearly the same (within 1/64").
TRUE
if the absolute difference between a
and b
is smaller than 1/64" References inches_1_64.
bool Lox::Measurement::parse | ( | const std::string & | str, |
double & | value, | ||
int & | numerator, | ||
int & | denominator, | ||
EUnits & | units | ||
) |
Parse a text string and get back a measurement value.
References Lox::kImperial, Lox::kMetric, Lox::Colours::kUnknown, limit_where_ambiguous_values_are_considered_metric, and Lox::Numbers::nearlyTheSame().
std::string Lox::Measurement::reformatStr | ( | const std::string & | str | ) |
Round the given inches to the nearest 1/32" value.
Referenced by metricRoundTo32Imperial().
Round UP the given inches to the nearest 1/2" value.
Referenced by metricRoundUpTo2Imperial().
Round UP the given inches to the nearest 1/4" value.
Referenced by metricRoundUpTo4Imperial().
void Lox::Measurement::split32Imperial | ( | const IN | in, |
int32_t & | inches, | ||
int32_t & | numerator, | ||
int32_t & | denominator | ||
) |
Split values such as 17 1/32"
into 3 components (17, 1, and 32).
References IN_TO_MM(), kImperial_1_32, and mmToStr().
bool Lox::Measurement::strToMM | ( | const std::string & | str, |
MM & | value | ||
) |
Convert a text string to a MM value.
References inches_to_mm, Lox::kImperial, Lox::Colours::kUnknown, and Lox::Numbers::parse().
Referenced by internalSanityCheck(), and reformatStr().
bool Lox::Measurement::validate | ( | const std::string & | str | ) |
Determine if the text is a valid measurement string.
References Lox::Colours::kUnknown, and Lox::Numbers::parse().
void Lox::Measurement::valuesGreaterThanAreConsideredMetric | ( | const double | value | ) |
When parsing text, if the resulting values are ambiguous, numbers greater than "X" will be considered as metric, while values <= "X" will be considered imperial.
References limit_where_ambiguous_values_are_considered_metric.
const IN Lox::Measurement::inches_1_32 = 1.0/32.0 |
1/32" is equal to 0.03125"
Referenced by internalSanityCheck(), and mmToStr().
const IN Lox::Measurement::inches_1_64 = 1.0/64.0 |
1/64" is equal to 0.015625"
Referenced by internalSanityCheck(), and nearlyTheSame().
const IN Lox::Measurement::inches_2_3_16 = 2.0 + 3.0/16.0 |
Default size (in inches) of rails and stiles.
Referenced by internalSanityCheck().
const MM Lox::Measurement::inches_to_mm = 25.4 |
Conversion factor to convert inches to metric. This is an exact measurement. 1" == 25.4 mm.
Referenced by IN_TO_MM(), internalSanityCheck(), and strToMM().
const IN Lox::Measurement::mm_to_inches = 1.0/25.4 |
Conversion factor to convert metric to inches. 1 mm == 0.039370079".
Referenced by internalSanityCheck(), MM_TO_IN(), and mmToStr().
const long double Lox::Measurement::square_feet_to_square_mm = 25.4 * 25.4 * 12.0 * 12.0 |
12" * 12" == 92903.04 mm^2
const long double Lox::Measurement::square_inches_to_square_mm = 25.4 * 25.4 |
Conversion factor for area calculations.
1" * 1" == 645.16 mm^2
const long double Lox::Measurement::square_mm_to_square_feet = 1.0 / square_feet_to_square_mm |
0.000010764
const long double Lox::Measurement::square_mm_to_square_inches = 1.0 / square_inches_to_square_mm |
0.001550003