Loxahatchee  v0.0.1-1346
Lox Convenience C++ Library
LoxMeasurement.hpp File Reference

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

#include <string>
#include <cstdint>
#include "LoxNumbers.hpp"
#include "LoxMetricTypes.hpp"
Include dependency graph for LoxMeasurement.hpp:
This graph shows which files directly or indirectly include this file:

Namespaces

 Lox
 Common methods and functionality easily shared between projects.
 
 Lox::Measurement
 Common functions to work with and convert metric and imperial measurements.
 

Enumerations

enum  Lox::Measurement::ERoundType {
  Lox::Measurement::kInvalid = 0,
  Lox::Measurement::kImperial_1_32 = 1,
  Lox::Measurement::kImperialDecimal = 2,
  Lox::Measurement::kMetric_1_100 = 3,
  Lox::Measurement::kMetric_1_10 = 4,
  Lox::Measurement::kMetric_5_10 = 5,
  Lox::Measurement::kMetric_mm = 6,
  Lox::Measurement::kImperial_up_1_4 = 7,
  Lox::Measurement::kImperial_up_1_2 = 8
}
 

Functions

static MM Lox::Measurement::IN_TO_MM (const IN &value)
 Convert inches to metric. More...
 
void Lox::Measurement::internalSanityCheck (void)
 Run 1-time startup tests with the metric/imperial measurement functions. More...
 
std::string Lox::Measurement::inToStr (const IN in)
 Convert fractional inches to a string. More...
 
bool Lox::Measurement::isImperial (const MM mm)
 Checks to see if the measurement is likely to be imperial. More...
 
bool Lox::Measurement::isImperial (const std::string &str)
 Checks to see if the string is likely to be imperial. More...
 
bool Lox::Measurement::isMetric (const MM mm)
 Checks to see if the measurement is likely to be metric. More...
 
bool Lox::Measurement::isMetric (const std::string &str)
 Checks to see if the string is likely to be metric. More...
 
MM Lox::Measurement::metricRound (const MM mm, const ERoundType type)
 Round the given measurement using the specified method. More...
 
MM Lox::Measurement::metricRoundTo32Imperial (const MM mm)
 Metric wrapper for roundTo32Imperial(). More...
 
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, ... More...
 
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, ... More...
 
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". More...
 
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, ... More...
 
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, ... More...
 
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". More...
 
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". More...
 
static IN Lox::Measurement::MM_TO_IN (const MM &value)
 Convert metric to inches. More...
 
std::string Lox::Measurement::mmToStr (const MM mm)
 Convert a fractional mm value to a metric or imperial string. More...
 
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. More...
 
bool Lox::Measurement::nearlyTheSame (const double a, const double b)
 Determine if the two values are nearly the same (within 1/64"). More...
 
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. More...
 
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. More...
 
IN Lox::Measurement::roundTo32Imperial (const IN in)
 Round the given inches to the nearest 1/32" value. More...
 
IN Lox::Measurement::roundUpTo2Imperial (const IN in)
 Round UP the given inches to the nearest 1/2" value. More...
 
IN Lox::Measurement::roundUpTo4Imperial (const IN in)
 Round UP the given inches to the nearest 1/4" value. More...
 
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). More...
 
bool Lox::Measurement::strToMM (const std::string &str, MM &value)
 Convert a text string to a MM value. More...
 
bool Lox::Measurement::validate (const std::string &str)
 Determine if the text is a valid measurement string. More...
 
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. More...
 
static double Lox::Measurement::MM_TO_FT (const MM &value)
 Convert metric to feet. More...
 
static double Lox::Measurement::MM_TO_FT_ROUNDED (const MM &value)
 Convert metric to feet. More...
 
static IN Lox::Measurement::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 Lox::Measurement::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 Lox::Measurement::inches_1_32 = 1.0/32.0
 1/32" is equal to 0.03125" More...
 
const IN Lox::Measurement::inches_1_64 = 1.0/64.0
 1/64" is equal to 0.015625" More...
 
const IN Lox::Measurement::inches_2_3_16 = 2.0 + 3.0/16.0
 Default size (in inches) of rails and stiles. More...
 
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. More...
 
const IN Lox::Measurement::mm_to_inches = 1.0/25.4
 Conversion factor to convert metric to inches. 1 mm == 0.039370079". More...
 
const long double Lox::Measurement::square_inches_to_square_mm = 25.4 * 25.4
 Conversion factor for area calculations. More...
 
const long double Lox::Measurement::square_feet_to_square_mm = 25.4 * 25.4 * 12.0 * 12.0
 12" * 12" == 92903.04 mm^2 More...
 
const long double Lox::Measurement::square_mm_to_square_inches = 1.0 / square_inches_to_square_mm
 0.001550003 More...
 
const long double Lox::Measurement::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.