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.
108 109 110 |
# File 'lib/contrek/reducers/visvalingam_reducer.rb', line 108 def is_live @is_live end |
#next ⇒ Object (readonly)
Returns the value of attribute next.
60 61 62 |
# File 'lib/contrek/reducers/visvalingam_reducer.rb', line 60 def next @next end |
#prev ⇒ Object (readonly)
Returns the value of attribute prev.
60 61 62 |
# File 'lib/contrek/reducers/visvalingam_reducer.rb', line 60 def prev @prev end |
#pt ⇒ Object (readonly)
Returns the value of attribute pt.
60 61 62 |
# File 'lib/contrek/reducers/visvalingam_reducer.rb', line 60 def pt @pt end |
Class Method Details
.build_line(pts) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/contrek/reducers/visvalingam_reducer.rb', line 70 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
104 105 106 |
# File 'lib/contrek/reducers/visvalingam_reducer.rb', line 104 def get_area @area end |
#get_coordinates ⇒ Object
129 130 131 132 133 134 135 136 137 138 |
# File 'lib/contrek/reducers/visvalingam_reducer.rb', line 129 def get_coordinates coords = [] curr = self loop do coords << curr.pt curr = curr.next break if curr.nil? end coords end |
#remove ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/contrek/reducers/visvalingam_reducer.rb', line 110 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
91 92 93 |
# File 'lib/contrek/reducers/visvalingam_reducer.rb', line 91 def setNext(nextp) @next = nextp end |
#setPrev(prev) ⇒ Object
87 88 89 |
# File 'lib/contrek/reducers/visvalingam_reducer.rb', line 87 def setPrev(prev) @prev = prev end |