Class: Contrek::Reducers::Vertex
- Inherits:
-
Object
- Object
- Contrek::Reducers::Vertex
- Defined in:
- lib/contrek/reducers/visvalingam_reducer.rb
Constant Summary collapse
- MAX_AREA =
Float::MAX
Instance Attribute Summary collapse
-
#is_live ⇒ Object
readonly
Returns the value of attribute is_live.
-
#next ⇒ Object
readonly
Returns the value of attribute next.
-
#prev ⇒ Object
readonly
Returns the value of attribute prev.
-
#pt ⇒ Object
readonly
Returns the value of attribute pt.
Class Method Summary collapse
Instance Method Summary collapse
- #get_area ⇒ Object
- #get_coordinates ⇒ Object
-
#initialize(pt) ⇒ Vertex
constructor
A new instance of Vertex.
- #remove ⇒ Object
- #setNext(nextp) ⇒ Object
- #setPrev(prev) ⇒ Object
- #updateArea ⇒ Object
Constructor Details
Instance Attribute Details
#is_live ⇒ Object (readonly)
Returns the value of attribute is_live.
106 107 108 |
# File 'lib/contrek/reducers/visvalingam_reducer.rb', line 106 def is_live @is_live end |
#next ⇒ Object (readonly)
Returns the value of attribute next.
58 59 60 |
# File 'lib/contrek/reducers/visvalingam_reducer.rb', line 58 def next @next end |
#prev ⇒ Object (readonly)
Returns the value of attribute prev.
58 59 60 |
# File 'lib/contrek/reducers/visvalingam_reducer.rb', line 58 def prev @prev end |
#pt ⇒ Object (readonly)
Returns the value of attribute pt.
58 59 60 |
# File 'lib/contrek/reducers/visvalingam_reducer.rb', line 58 def pt @pt end |
Class Method Details
.build_line(pts) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/contrek/reducers/visvalingam_reducer.rb', line 68 def self.build_line(pts) first = nil prev = nil pts.each_with_index do |pt, i| v = Vertex.new(pts[i]) first = v if first.nil? v.setPrev(prev) if !prev.nil? prev.setNext(v) prev.updateArea end prev = v end first end |
Instance Method Details
#get_area ⇒ Object
102 103 104 |
# File 'lib/contrek/reducers/visvalingam_reducer.rb', line 102 def get_area @area end |
#get_coordinates ⇒ Object
127 128 129 130 131 132 133 134 135 136 |
# File 'lib/contrek/reducers/visvalingam_reducer.rb', line 127 def get_coordinates coords = [] curr = self loop do coords << curr.pt curr = curr.next break if curr.nil? end coords end |
#remove ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/contrek/reducers/visvalingam_reducer.rb', line 108 def remove tmp_prev = @prev tmp_next = @next result = nil if !prev.nil? @prev.setNext(tmp_next) @prev.updateArea result = prev end if !@next.nil? @next.setPrev(tmp_prev) @next.updateArea result = @next if result.nil? end @is_live = false result end |
#setNext(nextp) ⇒ Object
89 90 91 |
# File 'lib/contrek/reducers/visvalingam_reducer.rb', line 89 def setNext(nextp) @next = nextp end |
#setPrev(prev) ⇒ Object
85 86 87 |
# File 'lib/contrek/reducers/visvalingam_reducer.rb', line 85 def setPrev(prev) @prev = prev end |