Class: GMath3D::Polyline
- Includes:
- BoxAvailable
- Defined in:
- lib/polyline.rb
Overview
Polyline represents a closed or open polyline on 3D space.
Instance Attribute Summary collapse
-
#is_open ⇒ Object
Returns the value of attribute is_open.
-
#vertices ⇒ Object
Returns the value of attribute vertices.
Attributes inherited from Geom
Instance Method Summary collapse
-
#==(rhs) ⇒ Object
- Input
-
rhs is Polyline.
-
#center ⇒ Object
- Output
-
return center point as Vector3.
-
#initialize(vertices = [], is_open = true) ⇒ Polyline
constructor
- Input
-
vertices should be Array of Vector3.
- #initialize_copy(original_obj) ⇒ Object
- #to_s ⇒ Object
Methods included from BoxAvailable
Methods inherited from Geom
Constructor Details
#initialize(vertices = [], is_open = true) ⇒ Polyline
- Input
-
vertices should be Array of Vector3.
- Output
-
return new instance of Polyline.
18 19 20 21 22 23 |
# File 'lib/polyline.rb', line 18 def initialize(vertices = [], is_open = true) Util3D.check_arg_type(Array, vertices) super() @vertices = vertices @is_open = is_open end |
Instance Attribute Details
#is_open ⇒ Object
Returns the value of attribute is_open.
10 11 12 |
# File 'lib/polyline.rb', line 10 def is_open @is_open end |
#vertices ⇒ Object
Returns the value of attribute vertices.
9 10 11 |
# File 'lib/polyline.rb', line 9 def vertices @vertices end |
Instance Method Details
#==(rhs) ⇒ Object
- Input
-
rhs is Polyline.
- Output
-
return true if rhs equals myself.
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/polyline.rb', line 37 def ==(rhs) return false if rhs == nil return false if( !rhs.kind_of?(Polyline) ) return false if( self.is_open != rhs.is_open ) return false if(@vertices.size != rhs.vertices.size) for i in 0..(@vertices.size-1) return false if( self.vertices[i] != rhs.vertices[i]) end return true end |
#center ⇒ Object
- Output
-
return center point as Vector3.
62 63 64 65 66 67 68 69 |
# File 'lib/polyline.rb', line 62 def center center = Vector3.new() @vertices.each do |vertex| center += vertex end center /= @vertices.size return center end |
#initialize_copy(original_obj) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/polyline.rb', line 25 def initialize_copy( original_obj ) @vertices = Array.new(original_obj.vertices.size) for i in 0..@vertices.size-1 @vertices[i] = original_obj.vertices[i].dup end @is_open = original_obj.is_open end |
#to_s ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/polyline.rb', line 48 def to_s str = "Polyline[" vertices.each do |vertex| str += vertex.to_element_s + ", " end str.slice!(str.length - 2, 2) if(vertices.size > 0) str += "] " str += "open" if(@is_open) str += "closed" if(!@is_open) return str end |