Loxahatchee  v0.0.1-1346
Lox Convenience C++ Library
Lox::Measurement Namespace Reference

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...
 

Detailed Description

Common functions to work with and convert metric and imperial measurements.

Enumeration Type Documentation

Enumerator
kInvalid 
kImperial_1_32 

round to 1/32" (approximately 0.8 mm)

kImperialDecimal 

round to 0.01" (approximately 0.3 mm or 3/256")

kMetric_1_100 

round to 0.01 mm (exactly 1/2540")

kMetric_1_10 

round to 0.1 mm (approximately 1/256")

kMetric_5_10 

round to 0.5 mm (approximately 5/256")

kMetric_mm 

round to 1.0 mm (approximately 5/128")

kImperial_up_1_4 

round UP to next 1/4" value

kImperial_up_1_2 

round UP to next 1/2" value

Function Documentation

static MM Lox::Measurement::IN_TO_MM ( const IN value)
inlinestatic

Convert inches to metric.

References inches_to_mm.

Referenced by internalSanityCheck(), inToStr(), metricRoundTo32Imperial(), metricRoundToImperialDecimal(), metricRoundUpTo2Imperial(), metricRoundUpTo4Imperial(), and split32Imperial().

Here is the caller graph for this function:

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().

Here is the call graph for this function:

std::string Lox::Measurement::inToStr ( const IN  in)

Convert fractional inches to a string.

References IN_TO_MM(), and mmToStr().

Referenced by internalSanityCheck().

Here is the call graph for this function:

Here is the caller graph for this function:

bool Lox::Measurement::isImperial ( const MM  mm)

Checks to see if the measurement is likely to be imperial.

Note
The value passed in is MM, meaning you may have to convert from inches to mm.
isImperial( IN_TO_MM(1.0) ) // checks to see if 1.0" is imperial, returns "true"
isImperial( 25.4 ) // checks to see if 1.0" is imperial, returns "true"
isImperial( 1 ) // checks to see if 1 mm is imperial, returns "false"

References mmToStr().

Here is the call graph for this function:

bool Lox::Measurement::isImperial ( const std::string &  str)

Checks to see if the string is likely to be imperial.

References Lox::trim().

Here is the call graph for this function:

bool Lox::Measurement::isMetric ( const MM  mm)

Checks to see if the measurement is likely to be metric.

References mmToStr().

Here is the call graph for this function:

bool Lox::Measurement::isMetric ( const std::string &  str)

Checks to see if the string is likely to be metric.

References Lox::trim().

Here is the call graph for this function:

Lox::MM Lox::Measurement::metricRound ( const MM  mm,
const ERoundType  type 
)
Lox::MM Lox::Measurement::metricRoundTo32Imperial ( const MM  mm)

Metric wrapper for roundTo32Imperial().

Note
Both the input and output are metric units.

References IN_TO_MM(), MM_TO_IN(), and roundTo32Imperial().

Referenced by metricRound().

Here is the call graph for this function:

Here is the caller graph for this function:

Lox::MM Lox::Measurement::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, ...

Referenced by metricRound().

Here is the caller graph for this function:

Lox::MM Lox::Measurement::metricRoundToHundrethMM ( const MM  mm)

Round the given measurement to the nearest 0.01 mm value. For example, 0.01, 0.02, 0.03, ...

Referenced by metricRound().

Here is the caller graph for this function:

Lox::MM Lox::Measurement::metricRoundToImperialDecimal ( const MM  mm)

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().

Here is the call graph for this function:

Here is the caller graph for this function:

Lox::MM Lox::Measurement::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, ...

Referenced by metricRound().

Here is the caller graph for this function:

Lox::MM Lox::Measurement::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, ...

Referenced by metricRound().

Here is the caller graph for this function:

Lox::MM Lox::Measurement::metricRoundUpTo2Imperial ( const MM  mm)

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().

Here is the call graph for this function:

Here is the caller graph for this function:

Lox::MM Lox::Measurement::metricRoundUpTo4Imperial ( const MM  mm)

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().

Here is the call graph for this function:

Here is the caller graph for this function:

static IN Lox::Measurement::MM_SQUARE_TO_FEET_SQUARE ( const MM value)
inlinestatic

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().

Here is the caller graph for this function:

static IN Lox::Measurement::MM_SQUARE_TO_FEET_SQUARE_ROUNDED ( const MM value)
inlinestatic

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().

Here is the call graph for this function:

static double Lox::Measurement::MM_TO_FT ( const MM value)
inlinestatic

Convert metric to feet.

References MM_TO_IN().

Referenced by MM_TO_FT_ROUNDED().

Here is the call graph for this function:

Here is the caller graph for this function:

static double Lox::Measurement::MM_TO_FT_ROUNDED ( const MM value)
inlinestatic

Convert metric to feet.

References MM_TO_FT(), and Lox::Numbers::round_to_2_decimals().

Here is the call graph for this function:

static IN Lox::Measurement::MM_TO_IN ( const MM value)
inlinestatic

Convert metric to inches.

References mm_to_inches.

Referenced by metricRoundTo32Imperial(), metricRoundToImperialDecimal(), metricRoundUpTo2Imperial(), metricRoundUpTo4Imperial(), MM_TO_FT(), and mmToStr().

Here is the caller graph for this function:

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().

Here is the call graph for this function:

Here is the caller graph for this function:

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().

Here is the call graph for this function:

bool Lox::Measurement::nearlyTheSame ( const double  a,
const double  b 
)

Determine if the two values are nearly the same (within 1/64").

Returns
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.

See also
Lox::Measurement::split32Imperial()

References Lox::kImperial, Lox::kMetric, Lox::Colours::kUnknown, limit_where_ambiguous_values_are_considered_metric, and Lox::Numbers::nearlyTheSame().

Here is the call graph for this function:

std::string Lox::Measurement::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.

References mmToStr(), and strToMM().

Here is the call graph for this function:

Lox::IN Lox::Measurement::roundTo32Imperial ( const IN  in)

Round the given inches to the nearest 1/32" value.

Referenced by metricRoundTo32Imperial().

Here is the caller graph for this function:

Lox::IN Lox::Measurement::roundUpTo2Imperial ( const IN  in)

Round UP the given inches to the nearest 1/2" value.

Referenced by metricRoundUpTo2Imperial().

Here is the caller graph for this function:

Lox::IN Lox::Measurement::roundUpTo4Imperial ( const IN  in)

Round UP the given inches to the nearest 1/4" value.

Referenced by metricRoundUpTo4Imperial().

Here is the caller graph for this function:

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).

See also
Lox::Measurement::parse()

References IN_TO_MM(), kImperial_1_32, and mmToStr().

Here is the call graph for this function:

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().

Here is the call graph for this function:

Here is the caller graph for this function:

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().

Here is the call graph for this function:

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.

See also
Lox::Measurement::parse()

References limit_where_ambiguous_values_are_considered_metric.

Variable Documentation

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