Guest User

Untitled

a guest
May 25th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. class Node
  2. @@nodes = []
  3. attr_accessor :x, :y
  4. attr_accessor :id, :label
  5. def initialize(id, x, y)
  6. @id = id
  7. @x = x
  8. @y = y
  9. @@nodes.push self
  10. end
  11. def self.find_nodes(x, y, r)
  12. @@nodes.clone.reject { |n| (x-n.x)**2 + (y-n.y)**2 > r**2 } # Do i really need the clone() here?
  13. end
  14. def get_neighbors(r)
  15. self.class.find_nodes(@x, @y, r) - [self]
  16. end
  17. end
Add Comment
Please, Sign In to add comment