ART v1.0-alpha
A Robot Template that raises the floor for VRC teams
Loading...
Searching...
No Matches
art::Length Class Reference

A Utility Unit class for Length. More...

#include <Units.h>

Public Member Functions

double pixels ()
 Returns the Length in pixels.
 
double inches ()
 Returns the Length in inches.
 
double feet ()
 Returns the Length in feet.
 
double meters ()
 Returns the Length in meters.
 
double centimeters ()
 Returns the Length in centimeters.
 
double millimeters ()
 Returns the Length in millimeters.
 
double tiles ()
 Returns the Length in tiles.
 
 Length ()
 Construct a new Length object.
 
 Length (double f)
 Construct a new Length object.
 
Length operator= (double const &f)
 Assign a value to the Length object.
 
 operator double ()
 Returns the Length as a default value(Pixels)
 

Private Attributes

double m_value {0.0}
 The underlying value of Length.
 

Friends

Length Pixels (double pixels)
 Constructs a Length from Pixels.
 
Length Inches (double inches)
 Constructs a Length from Inches.
 
Length Feet (double feet)
 Constructs a Length from Feet.
 
Length Meters (double meters)
 Constructs a Length from Meters.
 
Length Centimeters (double centimeters)
 Constructs a Length from Centimeters.
 
Length Millimeters (double millimeters)
 Constructs a Length from Millimeters.
 
Length Tiles (double tiles)
 Constructs a Length from Tiles.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ Length() [1/2]

art::Length::Length ( )

Construct a new Length object.

Initializes the value to 0.

Definition at line 67 of file Units.cpp.

◆ Length() [2/2]

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.

Member Function Documentation

◆ centimeters()

double art::Length::centimeters ( )

Returns the Length in centimeters.

Returns
double - the Length in centimeters

Definition at line 40 of file Units.cpp.

◆ feet()

double art::Length::feet ( )

Returns the Length in feet.

Returns
double - the Length in feet

Definition at line 30 of file Units.cpp.

◆ inches()

double art::Length::inches ( )

Returns the Length in inches.

Returns
double - the Length in inches

Definition at line 25 of file Units.cpp.

◆ meters()

double art::Length::meters ( )

Returns the Length in meters.

Returns
double - the Length in meters

Definition at line 35 of file Units.cpp.

◆ millimeters()

double art::Length::millimeters ( )

Returns the Length in millimeters.

Returns
double - the Length in millimeters

Definition at line 45 of file Units.cpp.

◆ operator double()

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

art::Length length = art::Inches(5) * 5 + art::Feet(2); //stores a length of 49 (25+24) inches
A Utility Unit class for Length.
Definition Units.h:37
Length Inches(double inches)
Constructs a Length from Inches.
Definition Units.cpp:78
Length Feet(double feet)
Constructs a Length from Feet.
Definition Units.cpp:85

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.

◆ operator=()

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.

art::Length length1 = art::Inches(5) + 5; //stores a length of 6 inches(don't do this)
art::Length length2 = art::Inches(5) + art::Inches(5); //stores a length of 10 inches(do this instead)
art::Length length3 = art::Inches(5 + 5); //stores a length of 10 inches(this is best)
art::Length length4 = art::Inches(5) * 5; //stores a length of 25 inches

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.

◆ pixels()

double art::Length::pixels ( )

Returns the Length in pixels.

Returns
double - the Length in pixels

Definition at line 20 of file Units.cpp.

◆ tiles()

double art::Length::tiles ( )

Returns the Length in tiles.

Returns
double - the Length in tiles

Definition at line 50 of file Units.cpp.

Friends And Related Symbol Documentation

◆ Centimeters

Length Centimeters ( double centimeters)
friend

Constructs a Length from Centimeters.

Parameters
centimetersthe length in Centimeters
Returns
Length - the constructed Length

Definition at line 99 of file Units.cpp.

◆ Feet

Length Feet ( double feet)
friend

Constructs a Length from Feet.

Parameters
feetthe length in Feet
Returns
Length - the constructed Length

Definition at line 85 of file Units.cpp.

◆ Inches

Length Inches ( double inches)
friend

Constructs a Length from Inches.

Parameters
inchesthe length in Inches
Returns
Length - the constructed Length

Definition at line 78 of file Units.cpp.

◆ Meters

Length Meters ( double meters)
friend

Constructs a Length from Meters.

Parameters
metersthe length in Meters
Returns
Length - the constructed Length

Definition at line 92 of file Units.cpp.

◆ Millimeters

Length Millimeters ( double millimeters)
friend

Constructs a Length from Millimeters.

Parameters
millimetersthe length in Millimeters
Returns
Length - the constructed Length

Definition at line 106 of file Units.cpp.

◆ Pixels

Length Pixels ( double pixels)
friend

Constructs a Length from Pixels.

Parameters
pixelsthe length in Pixels
Returns
Length - the constructed Length

Definition at line 71 of file Units.cpp.

◆ Tiles

Length Tiles ( double tiles)
friend

Constructs a Length from Tiles.

Parameters
tilesthe length in Tiles
Returns
Length - the constructed Length

Definition at line 113 of file Units.cpp.

Member Data Documentation

◆ m_value

double art::Length::m_value {0.0}
private

The underlying value of Length.

Stores the Length in pixels. This is what is returned and modified by some methods, but this is also converted to and from other units using the corresponding constructing function or get method.

Definition at line 207 of file Units.h.


The documentation for this class was generated from the following files: