A Utility Unit class for Length.
The Length class aims to provide a better way to convert and store different units for length. This way, when a function asks for a distance or a length to drive, any unit can be used to specify the distance. This makes it easier to write and tune autons as well as perform calculations, as you can use whatever unit is most comfortable.
The Pixel unit is leftover from a Vex simulation project I started. I built the Length class around the pixels in the sim, making the pixel the default/internal unit. There isn't any purpose to using them, but it does make it so that if a unit is not specified, the results can be quite unexpected.
- Todo
- remove the Pixel unit and choose a different unit as the default/internal unit
Definition at line 36 of file Units.h.
| art::Length::Length |
( |
double | f | ) |
|
Construct a new Length object.
- Parameters
-
| f | - a number(or Length) to initialize m_value to |
This constructor is used similarly to the assignment operator. It can be used to construct a Length to copy the value of another length without needing to convert to and from a specified unit. In order words, instead of a number, another Length can be used and/or modified by treating it as a number.
As of right now, this number(f) is in Pixels, which is also the default output when a Length is used as a number.
Definition at line 69 of file Units.cpp.
| art::Length::operator double |
( |
| ) |
|
Returns the Length as a default value(Pixels)
- Returns
- double - the Length as a default value(Pixels)
This operator overload allows Length to be treated as a plain old number. I can be typecasted to a double explicitly or just used in an expression. The value returned is technically in Pixels, but when adding different lengths together or multiplying by a scale, this doesn't matter as long as the result is stored using Length(double f) or Length operator=(double const &f), as oppsosed to a Unit-specifying constructing function (Inches, Tiles, Meters etc.).
A Utility Unit class for Length.
Length Inches(double inches)
Constructs a Length from Inches.
Length Feet(double feet)
Constructs a Length from Feet.
Normal C++ order of operations applies, as each Length is simply replaced by it's underlying value.
Definition at line 62 of file Units.cpp.
| Length art::Length::operator= |
( |
double const & | f | ) |
|
Assign a value to the Length object.
- Parameters
-
| f | - a number(or Length) to initialize m_value to |
- Returns
- Length - The new modified length
This overloaded assignment operator allows the result of an operation using a Length to be stored by another Length.
Keep in mind this works best when the value on the right side is a Length. Modifying the Length with operators is okay, but keep in mind how those operations distribute.
As of right now, this number(f) is in Pixels, which is also the default output when a Length is used as a number.
Definition at line 55 of file Units.cpp.