Advertisement
Guest User

Untitled

a guest
Apr 19th, 2014
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. class Intersection
  2.  
  3. def initialize(xa1, ya1, xa2, ya2, xb1, yb1, xb2, yb2 )
  4. @xa1 = xa1.to_i
  5. @ya1 = ya1.to_i
  6. @xa2 = xa2.to_i
  7. @ya2 = ya2.to_i
  8. @xb1 = xb1.to_i
  9. @yb1 = yb1.to_i
  10. @xb2 = xb2.to_i
  11. @yb2 = yb2.to_i
  12.  
  13. end
  14. # compare sizes
  15. # both can't have the same size
  16. def self.check_size?
  17. rec1 = [(@xa2-@xa1).abs, (@ya2-@ya1).abs]
  18. rec2 = [(@xb2-@xb1).abs, (@yb2-@yb1).abs]
  19. rec1 == rec2 or rec1 == rec2.reverse
  20. # rec1<<rec2.reverse
  21. end
  22.  
  23. def self.create_arr(a, b, c, d)
  24. (a..c).to_a.product((b..d).to_a)
  25. end
  26.  
  27.  
  28. ...
  29. end
  30.  
  31. require './spec_helper'
  32. require './intersection.rb'
  33.  
  34. describe Intersection do
  35. before do
  36. # YES
  37. @xa1 = 0.0
  38. @ya1 = 0.0
  39. @xa2 = 5.0
  40. @ya2 = 5.0
  41. @xb1 = 1.0
  42. @yb1 = 1.0
  43. @xb2 = 4.0
  44. @yb2 = 4.0
  45. @intersection = Intersection.new(@xa1, @ya1, @xa2, @ya2, @xb1, @yb1, @xb2, @yb2)
  46. end
  47.  
  48. specify{ expect(@intersection.create_arr(@xa1, @ya1, @xa2, @ya2)).to eq [[0,0], [0,1], [0,2], [0,3], [0,4], [0,5], [1,0], [1,1], [1,2], [1,3], [1,4], [1,5], [2,0], [2,1], [2,2], [2,3], [2,4], [2,5], [3,0], [3,1], [3,2], [3,3], [3,4], [3,5], [4,0], [4,1], [4,2], [4,3], [4,4], [4,5], [5,0], [5,1], [5,2], [5,3], [5,4], [5,5]] }
  49.  
  50. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement