Measurement Types
A measurement type is one of the types area, density, length, mass, position, and volume. Every measurement type is fundamental value type, which means it is as intrinsic to the GCScript language as the types bool, double, int, and string. Furthermore, as with those other types, every measurement type name is a keyword; that name cannot be used for any other purpose.
A measurement instance is an instance of a measurement type, in the same way that the number 12.34 is an instance of the double type. Generally, a measurement instance can be treated like a number: It can participate in arithmetic operations, and (in some cases) it is directly interchangeable with a double instance. However, unlike a plain number, a measurement instance is unit-aware. A measurement instance isn't just 5, it's 5 meters; it's not just 4.5, it's 4 feet 6 inches; and so on. The units are properly maintained across arithmetic operations.
The following table shows specific information about each measurement type.
Measurement type | What it represents | Units supported | Special arithmetic operations * | Notes |
---|---|---|---|---|
area | The area of a two-dimensional entity |
ac (acres) cm² (square centimeters) ft² (square feet) in² (square inches) km² (square kilometers) m² (square meters) mi² (square miles) mm² (square millimeters) |
area * length → volume length * area → volume area / length → length |
An area instance is directly interchangeable with a plain number. |
density | Mass/weight per unit volume | Any unit of mass combined with any unit of volume; for example, lb / ft³ (pounds per cubic foot). |
density * volume → mass volume * density → mass mass / density → volume |
A density instance is directly interchangeable with a plain number. |
length | A length, distance, or location along a line |
cm (centimeters) ft (feet) in (inches) km (kilometers) m (meters) mi (miles) mm (millimeters) |
length * length → area length * length * length → volume |
A length instance is directly interchangeable with a plain number. |
mass | A mass or weight |
g (grams) kg (kilograms) lb (pounds) oz (ounces) |
mass / volume → density |
A mass instance is directly interchangeable with a plain number. |
position | A location in three-dimensional space, identified by its Cartesian coordinates x, y, and z, each of which is a length | Because each of the x, y, and z members is a length instance, each supports the same units as the length type |
Because each of the x, y, and z members is a length instance, each supports the same arithmetic operations as the length type. Also: position - position → length |
Because each of the x, y, and z members is a length instance, each is directly interchangeable with a plain number. |
volume | The volume of a three-dimensional entity |
cm³ (cubic centimeters) ft³ (cubic feet) in³ (cubic inches) kl (kiloliters) km³ (cubic kilometers) l (liters) m³ (cubic meters) mi³ (cubic miles) ml (milliliters) mm³ (cubic millimeters) |
volume / area → length volume / length → area |
A volume instance is directly interchangeable with a plain number. |
* These special arithmetic operations are in addition to arithmetic operations with plain numbers. For example, any measurement value can be increased (value + number) or scaled (value * number).