Module: AMS
- Defined in:
- ../ams_Lib.rb,
main.rb
Defined Under Namespace
Modules: Cursor, Keyboard, Lib, MIDI, Menu, RayUtil, Registry, Screen, Sketchup, System, Timer, Window Classes: MultiLineText, SketchupObserver, Translate
Class Method Summary (collapse)
-
+ (Numeric) clamp(value, min, max)
Clamp value between min and max.
-
+ (Sketchup::Entity?) get_entity_by_id(id)
Get entity by entity ID.
-
+ (Boolean) is_boolean?(object)
(also: is_bool?)
Determine whether object is
trueorfalse. -
+ (Numeric) max(a, b)
Get greatest value of the two values.
-
+ (Numeric) min(a, b)
Get least value of the two values.
-
+ (Geom::Vector3d) scale_vector(vector, scale)
Scale vector.
-
+ (Fixnum) sign(value)
Get numeric value sign.
-
+ (void) validate_type(object, *types)
Validate object type.
Class Method Details
+ (Numeric) clamp(value, min, max)
Clamp value between min and max.
35 36 37 38 39 |
# File 'main.rb', line 35 def clamp(value, min, max) value = min if min and value < min value = max if max and value > max value end |
+ (Sketchup::Entity?) get_entity_by_id(id)
Get entity by entity ID.
80 81 82 83 84 85 86 87 88 89 90 |
# File 'main.rb', line 80 def get_entity_by_id(id) model = Sketchup.active_model model.entities.each { |e| return e if e.entityID == id } model.definitions.each { |d| d.instances.each { |e| return e if e.entityID == id } d.entities.each { |e| return e if e.entityID == id } } nil end |
+ (Boolean) is_boolean?(object) Also known as: is_bool?
Determine whether object is true or false.
95 96 97 |
# File 'main.rb', line 95 def is_boolean?(object) object.is_a?(TrueClass) || object.is_a?(FalseClass) end |
+ (Numeric) max(a, b)
Get greatest value of the two values.
63 64 65 |
# File 'main.rb', line 63 def max(a, b) a > b ? a : b end |
+ (Numeric) min(a, b)
Get least value of the two values.
54 55 56 |
# File 'main.rb', line 54 def min(a, b) a < b ? a : b end |
+ (Geom::Vector3d) scale_vector(vector, scale)
Scale vector.
72 73 74 |
# File 'main.rb', line 72 def scale_vector(vector, scale) Geom::Vector3d.new(vector[0]*scale, vector[1]*scale, vector[2]*scale) end |
+ (Fixnum) sign(value)
Get numeric value sign.
45 46 47 |
# File 'main.rb', line 45 def sign(value) value.zero? ? 0 : (value > 0 ? 1 : -1) end |
+ (void) validate_type(object, *types)
This method returns an undefined value.
Validate object type.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'main.rb', line 14 def validate_type(object, *types) types.flatten! return if types.empty? types.each { |type| return if object.is_a?(type) } string = case types.size when 1 types[0] when 2 "#{types[0]} or #{types[1]}" else "#{types[0...-1].join(', ')}, or #{types[-1]}" end raise TypeError, "Expected #{string}, but got #{object.class}.", caller end |