Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Intersection
- def initialize(xa1, ya1, xa2, ya2, xb1, yb1, xb2, yb2 )
- @xa1 = xa1.to_i
- @ya1 = ya1.to_i
- @xa2 = xa2.to_i
- @ya2 = ya2.to_i
- @xb1 = xb1.to_i
- @yb1 = yb1.to_i
- @xb2 = xb2.to_i
- @yb2 = yb2.to_i
- end
- # compare sizes
- # both can't have the same size
- def self.check_size?
- rec1 = [(@xa2-@xa1).abs, (@ya2-@ya1).abs]
- rec2 = [(@xb2-@xb1).abs, (@yb2-@yb1).abs]
- rec1 == rec2 or rec1 == rec2.reverse
- # rec1<<rec2.reverse
- end
- def self.create_arr(a, b, c, d)
- (a..c).to_a.product((b..d).to_a)
- end
- ...
- end
- require './spec_helper'
- require './intersection.rb'
- describe Intersection do
- before do
- # YES
- @xa1 = 0.0
- @ya1 = 0.0
- @xa2 = 5.0
- @ya2 = 5.0
- @xb1 = 1.0
- @yb1 = 1.0
- @xb2 = 4.0
- @yb2 = 4.0
- @intersection = Intersection.new(@xa1, @ya1, @xa2, @ya2, @xb1, @yb1, @xb2, @yb2)
- end
- 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]] }
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement