Length¶
-
class
Length(value=0.0, units=None)[source]¶ Bases:
objectThe Length class implements a concept of a length in meters.
This version adapted from the c++ and java implementation originally authored by Allen Farris
Attributes Summary
AllowedUnitsCENTIMETERKILOMETERMETERMILLIMETERMethods Summary
almostEquals(otherLength, toleranceLength)Returns True if and only if otherLength and toleranceLength are both Lengths and if the distance (absolute value of the difference) between this Length and otherLength is less than the absolute value of toleranceLength.
compareTo(otherLength)Compare this Length to the specified otherLength, which must be a Length.
divide(l, factor)Return a new Length that is a specified length divided by a specified factor, l / factor.
equals(otherLength)Return True if and only if the specified other length is a Length that has a value that is equal to this length.
from1DBin(eis)Read a list of binary Length values, in meters, from an EndianInput instance and return the resulting list.
from2DBin(eis)Read a 2D list of binary Length values, in meters, from an EndianInput instance and return the resulting list.
from3Dbin(eis)Read a 3D list of binary Length values, in meters, from an EndianInput instance and return the resulting list.
fromBin(eis)Read the binary representation of an Length, in meters, from an EndianInput instance and use the read value to set a Length.
get([units])Return the value of this length in the specified units.
getInstance(stringList)Retrieve a value from a list of strings and convert that to a Length
isZero()Return True if and only if this length is zero (0.0).
listTo1DBin(lengthList, eos)Write a 1D list of Length to the EndianOutput
listTo2DBin(lengthList, eos)Write a 2D list of Length to the EndianOutput
listTo3DBin(lengthList, eos)Write a 3D list of Length to the EndianOutput
listToBin(lengthList, eos)Write a list of Length to the EndianOutput.
multiply(l, factor)Return a new Length that is the product of a specified length and some specified factor, l * factor.
set(value[, units])Set the value of this length to the given value in the specified units.
subtract(l1, l2)Return a new Length that is the difference of the specified lengths, l1 - l2.
sum(l1, l2)Return a new Length that is the sum of the specified lengths, l1 + l2.
toBin(eos)Write this Length out, in meters, to a EndianOutput.
unit()Return the canonical unit associated with this Length, meter.
values(items)return a list of floats containing the value of the list of Length objects passed in the items argument.
Attributes Documentation
-
AllowedUnits= ['km', 'm', 'cm', 'mm']¶
-
CENTIMETER= 'cm'¶
-
KILOMETER= 'km'¶
-
METER= 'm'¶
-
MILLIMETER= 'mm'¶
Methods Documentation
-
almostEquals(otherLength, toleranceLength)[source]¶ Returns True if and only if otherLength and toleranceLength are both Lengths and if the distance (absolute value of the difference) between this Length and otherLength is less than the absolute value of toleranceLength.
-
compareTo(otherLength)[source]¶ Compare this Length to the specified otherLength, which must be a Length. Returning -1, 0, or +1 if this Length is less than, equal to, or greater than the other Length.
-
static
divide(l, factor)[source]¶ Return a new Length that is a specified length divided by a specified factor, l / factor. l The base length factor The factor that is used to divide the value. return A new Length that is the quotient of a specified length and some specified factor, l / factor.
-
equals(otherLength)[source]¶ Return True if and only if the specified other length is a Length that has a value that is equal to this length.
-
static
from1DBin(eis)[source]¶ Read a list of binary Length values, in meters, from an EndianInput instance and return the resulting list.
-
static
from2DBin(eis)[source]¶ Read a 2D list of binary Length values, in meters, from an EndianInput instance and return the resulting list.
-
static
from3Dbin(eis)[source]¶ Read a 3D list of binary Length values, in meters, from an EndianInput instance and return the resulting list.
-
static
fromBin(eis)[source]¶ Read the binary representation of an Length, in meters, from an EndianInput instance and use the read value to set a Length.
return a Length
-
get(units=None)[source]¶ Return the value of this length in the specified units. When units is None (the default) the returned units are METER. Recognized units are None (METER), METER, KILOMETER, CENTIMETER, and MILLIMETER
-
static
getInstance(stringList)[source]¶ Retrieve a value from a list of strings and convert that to a Length
This is used when parsing Length lists from an XML representation to eventually construct a list of Length instances. The string values are float representation of a length in meters
Returns a tuple of (Length, stringList) where Length is the new Length created by this call and stringList is the remaining, unused, part of stringList after removing the first element.
-
static
listToBin(lengthList, eos)[source]¶ Write a list of Length to the EndianOutput. The list may have 1, 2 or 3 dimensions.
-
static
multiply(l, factor)[source]¶ Return a new Length that is the product of a specified length and some specified factor, l * factor. l The base length factor The factor that is used to multiply the value. return A new Length that is the product of a specified length and some specified factor, l * factor.
-
set(value, units=None)[source]¶ Set the value of this length to the given value in the specified units. Any value is valid so long as it can be converted into a float using float(value) (including a parseable string). The units is a string argument that detaults to METER as defined here. Recognized units are METER, KILOMETER, CENTIMETER, and MILLIMETER (also definied here).
-
static
subtract(l1, l2)[source]¶ Return a new Length that is the difference of the specified lengths, l1 - l2. l1 The first Length of the pair. l2 The second Length of the pair. return A new Length that is the difference of the specified lengths, l1 - l2.
-
static
sum(l1, l2)[source]¶ Return a new Length that is the sum of the specified lengths, l1 + l2. l1 The first Length of the pair. l2 The second Length of the pair. return A new Length that is the sum of the specified lengths, l1 + l2.
-
static
unit()[source]¶ Return the canonical unit associated with this Length, meter. return The unit associated with this Length.
-
static
values(items)[source]¶ return a list of floats containing the value of the list of Length objects passed in the items argument. items may also be a list of lists (2D array) of Length objects. If the first item is a list then this method assumes that items is a list of lists and the return value is a list of lists of floats. The list of lists case is done by calling this method recursively and so it should work for higher orders of lists of lists. That use case is not tested.
-