Class: GMath3D::Polyline

Inherits:
Geom
  • Object
show all
Includes:
BoxAvailable
Defined in:
lib/polyline.rb

Overview

Polyline represents a closed or open polyline on 3D space.

Instance Attribute Summary collapse

Attributes inherited from Geom

#tolerance

Instance Method Summary collapse

Methods included from BoxAvailable

#box

Methods inherited from Geom

default_tolerance

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_openObject

Returns the value of attribute is_open.



10
11
12
# File 'lib/polyline.rb', line 10

def is_open
  @is_open
end

#verticesObject

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

#centerObject

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_sObject



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