Class: GreinerHormann::Vertex
- Inherits:
-
Object
- Object
- GreinerHormann::Vertex
- Defined in:
- lib/greiner_hormann/vertex.rb
Instance Attribute Summary collapse
-
#corresponding ⇒ Object
Returns the value of attribute corresponding.
-
#distance ⇒ Object
Returns the value of attribute distance.
-
#is_entry ⇒ Object
Returns the value of attribute is_entry.
-
#is_intersection ⇒ Object
Returns the value of attribute is_intersection.
-
#next_node ⇒ Object
Returns the value of attribute next_node.
-
#prev_node ⇒ Object
Returns the value of attribute prev_node.
-
#visited ⇒ Object
Returns the value of attribute visited.
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
Class Method Summary collapse
Instance Method Summary collapse
- #==(v) ⇒ Object
- #equals(v) ⇒ Object
-
#initialize(x, y) ⇒ Vertex
constructor
A new instance of Vertex.
- #is_inside(poly) ⇒ Object
- #visit ⇒ Object
Constructor Details
#initialize(x, y) ⇒ Vertex
Returns a new instance of Vertex.
5 6 7 8 9 10 11 12 13 |
# File 'lib/greiner_hormann/vertex.rb', line 5 def initialize(x, y) self.x = x self.y = y self.next_node = self.prev_node = self.corresponding = nil self.distance = 0.0 self.is_entry = true self.is_intersection = self.visited = false end |
Instance Attribute Details
#corresponding ⇒ Object
Returns the value of attribute corresponding.
3 4 5 |
# File 'lib/greiner_hormann/vertex.rb', line 3 def corresponding @corresponding end |
#distance ⇒ Object
Returns the value of attribute distance.
3 4 5 |
# File 'lib/greiner_hormann/vertex.rb', line 3 def distance @distance end |
#is_entry ⇒ Object
Returns the value of attribute is_entry.
3 4 5 |
# File 'lib/greiner_hormann/vertex.rb', line 3 def is_entry @is_entry end |
#is_intersection ⇒ Object
Returns the value of attribute is_intersection.
3 4 5 |
# File 'lib/greiner_hormann/vertex.rb', line 3 def is_intersection @is_intersection end |
#next_node ⇒ Object
Returns the value of attribute next_node.
3 4 5 |
# File 'lib/greiner_hormann/vertex.rb', line 3 def next_node @next_node end |
#prev_node ⇒ Object
Returns the value of attribute prev_node.
3 4 5 |
# File 'lib/greiner_hormann/vertex.rb', line 3 def prev_node @prev_node end |
#visited ⇒ Object
Returns the value of attribute visited.
3 4 5 |
# File 'lib/greiner_hormann/vertex.rb', line 3 def visited @visited end |
#x ⇒ Object
Returns the value of attribute x.
3 4 5 |
# File 'lib/greiner_hormann/vertex.rb', line 3 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
3 4 5 |
# File 'lib/greiner_hormann/vertex.rb', line 3 def y @y end |
Class Method Details
Instance Method Details
#==(v) ⇒ Object
30 31 32 |
# File 'lib/greiner_hormann/vertex.rb', line 30 def ==(v) x == v.x && y == v.y end |
#equals(v) ⇒ Object
34 35 36 |
# File 'lib/greiner_hormann/vertex.rb', line 34 def equals(v) self == v end |
#is_inside(poly) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/greiner_hormann/vertex.rb', line 38 def is_inside(poly) odd_nodes = false vert = poly.first next_n = vert.next_node loop do if (vert.y < y && next_n.y >= y || next_n.y < y && vert.y >= y) && (vert.x <= x || next_n.x <= x) odd_nodes ^= vert.x + (y - vert.y) / (next_n.y - vert.y) * (next_n.x - vert.x) < x end vert = vert.next_node next_n = vert.next_node || poly.first break if vert == poly.first end odd_nodes end |
#visit ⇒ Object
23 24 25 26 27 28 |
# File 'lib/greiner_hormann/vertex.rb', line 23 def visit self.visited = true if !corresponding.nil? && !corresponding.visited corresponding.visit end end |