Class: Length
| Relationships | |
| Super Chains via Extension / Inclusion / Inheritance | |
|
Class Chain:
self,
Float
|
|
|
Instance Chain:
self,
Float
|
|
| Inherits: |
Float
|
Overview
Prior to SketchUp 2015, Length used to be derived from Float. This is no longer the case.
When serializing a Length object to a string to save for later use, e.g. in a config file, first convert them to Float objects. The string representation of a Length is rounded and uses the local decimal separator which can lead to data loss and portability issues. The string representation is intended for humans, not computers.
Because length units are used so often in SketchUp, a special class has been added to make it easier to work with length values. You can use a Length object any place that you would use a Float.
Internally, all lengths in SketchUp are stored in inches. The Length class stores values in inches as well. A number of methods have been added to the Ruby Numeric class to do units conversions. Find more info about units and lengths in this article.
The setting for the Length Format and Length Unit can be retrieved from the Sketchup::Model#options by querying the “UnitsOptions” ::Sketchup::OptionsProvider for “LengthFormat” and “LengthUnit” respectively.
Constants:
- Length Format
- Length Unit
-
(Added in SketchUp 2020.0)
- Area Unit
-
(Added in SketchUp 2019.2)
(Added in SketchUp 2020.0)
- Volume Unit
-
(Added in SketchUp 2019.2)
(Added in SketchUp 2020.0)
Constant Summary
-
Architectural =
# File 'lib/sketchup-api-stubs/stubs/Length.rb', line 72
Constants
nil -
Centimeter =
# File 'lib/sketchup-api-stubs/stubs/Length.rb', line 74
Stub value.
nil -
CubicCentimeter =
# File 'lib/sketchup-api-stubs/stubs/Length.rb', line 76
Stub value.
nil -
CubicFeet =
# File 'lib/sketchup-api-stubs/stubs/Length.rb', line 77
Stub value.
nil -
CubicInches =
# File 'lib/sketchup-api-stubs/stubs/Length.rb', line 78
Stub value.
nil -
CubicMeter =
# File 'lib/sketchup-api-stubs/stubs/Length.rb', line 79
Stub value.
nil -
CubicMillimeter =
# File 'lib/sketchup-api-stubs/stubs/Length.rb', line 80
Stub value.
nil -
CubicYard =
# File 'lib/sketchup-api-stubs/stubs/Length.rb', line 81
Stub value.
nil -
Decimal =
# File 'lib/sketchup-api-stubs/stubs/Length.rb', line 83
Stub value.
nil -
Engineering =
# File 'lib/sketchup-api-stubs/stubs/Length.rb', line 85
Stub value.
nil -
Feet =
# File 'lib/sketchup-api-stubs/stubs/Length.rb', line 89
Stub value.
nil -
Fractional =
# File 'lib/sketchup-api-stubs/stubs/Length.rb', line 87
Stub value.
nil -
Inches =
# File 'lib/sketchup-api-stubs/stubs/Length.rb', line 91
Stub value.
nil -
Liter =
# File 'lib/sketchup-api-stubs/stubs/Length.rb', line 93
Stub value.
nil -
Meter =
# File 'lib/sketchup-api-stubs/stubs/Length.rb', line 97
Stub value.
nil -
Millimeter =
# File 'lib/sketchup-api-stubs/stubs/Length.rb', line 95
Stub value.
nil -
SquareCentimeter =
# File 'lib/sketchup-api-stubs/stubs/Length.rb', line 99
Stub value.
nil -
SquareFeet =
# File 'lib/sketchup-api-stubs/stubs/Length.rb', line 100
Stub value.
nil -
SquareInches =
# File 'lib/sketchup-api-stubs/stubs/Length.rb', line 101
Stub value.
nil -
SquareMeter =
# File 'lib/sketchup-api-stubs/stubs/Length.rb', line 102
Stub value.
nil -
SquareMillimeter =
# File 'lib/sketchup-api-stubs/stubs/Length.rb', line 103
Stub value.
nil -
SquareYard =
# File 'lib/sketchup-api-stubs/stubs/Length.rb', line 104
Stub value.
nil -
USGallon =
# File 'lib/sketchup-api-stubs/stubs/Length.rb', line 106
Stub value.
nil -
Yard =
# File 'lib/sketchup-api-stubs/stubs/Length.rb', line 108
Stub value.
nil
Instance Method Summary
-
#<(length2) ⇒ Boolean
The < method is used to see if one length is less than another length.
-
#<=(length2) ⇒ Boolean
The <= method is used to see if one length is less than or equal to another length.
-
#<=>(length2) ⇒ Integer
The <=> method is used to see if one length is less than equal or greater than another length.
-
#==(length2) ⇒ Boolean
The == method is used to see if one length is equal to another length.
-
#>(length2) ⇒ Boolean
The > method is used to see if one length is greater than another length.
-
#>=(length2) ⇒ Boolean
The >= method is used to see if one length is greater than or equal to another length.
-
#inspect ⇒ String
The inspect method is used to retrieve an unformatted string for the length, which is the length in inches, regardless of the user’s model unit settings.
-
#to_f ⇒ Float
The to_f method is used to convert a length to a normal float.
-
#to_s ⇒ String
Format a length as a
::Stringusing the current units formatting settings for the model.
Instance Method Details
#<(length2) ⇒ Boolean
The < method is used to see if one length is less than another length.
For example, if l1 = 1.0.inch and l2 = 1.000001.inch then l1 == l2 so l1 < l2 should return false.
#<=(length2) ⇒ Boolean
The <= method is used to see if one length is less than or equal to another length.
#<=>(length2) ⇒ Integer
The <=> method is used to see if one length is less than equal or greater than another length. Because we change == for Length to do a test based on a tolerance, we also need to change <=> to also take tolerance into account.
#==(length2) ⇒ Boolean
The == method is used to see if one length is equal to another length.
The equality comparison on Length values uses the default tolerance that SketchUp uses for comparing lengths.
#>(length2) ⇒ Boolean
The > method is used to see if one length is greater than another length.
For example, if l1 = 1.0.inch and l2 = 1.000001.inch then l1 == l2 so l1 > l2 should return false.
#>=(length2) ⇒ Boolean
The >= method is used to see if one length is greater than or equal to another length.
For example, if l1 = 1.0.inch and l2 = 1.000001.inch then l1 == l2 so l1 >= l2 should return true. Also L1 <= l2 would return true.
#inspect ⇒ String
The inspect method is used to retrieve an unformatted string for the length, which is the length in inches, regardless of the user’s model unit settings. See Length.to_s for a way automatically format your Length to the user’s model units.
#to_f ⇒ Float
The to_f method is used to convert a length to a normal float.
#to_s ⇒ String
Format a length as a ::String using the current units formatting settings for the model. (So if the user’s model is set to feet, this method will return a nicely formatted length in feet.)