gui_geometry 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -59,12 +59,24 @@ class Rectangle < Struct.new(:loc, :size)
59
59
  end
60
60
 
61
61
  def overlaps?(b)
62
- b.loc + b.size > loc &&
63
- loc + size > b.loc
62
+ case b
63
+ when Point then
64
+ contains?(b)
65
+ when Rectangle then
66
+ b.loc + b.size > loc &&
67
+ loc + size > b.loc
68
+ else raise ArgumentError.new("wrong type: (#{val.class}) - Rectangle or Point expected")
69
+ end
64
70
  end
65
71
 
66
72
  def contains?(b)
67
- (self & b) == self
73
+ case b
74
+ when Point then
75
+ b >= loc && b < (loc+size)
76
+ when Rectangle then
77
+ (self & b) == self
78
+ else raise ArgumentError.new("wrong type: (#{val.class}) - Rectangle or Point expected")
79
+ end
68
80
  end
69
81
 
70
82
  def tl; loc; end
@@ -1,3 +1,3 @@
1
1
  module GuiGeo
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -112,5 +112,23 @@ describe "Rectangle" do
112
112
  r1.bound(rect(30,0,5,5)).should == rect(15,10,5,5)
113
113
  r1.bound(rect(0,0,20,5)).should == rect(5,10,15,5)
114
114
  end
115
+
116
+ it ".overlaps? point" do
117
+ r1 = rect(5, 10, 15, 20)
118
+ r1.overlaps?(point(10,10)).should == true
119
+ r1.overlaps?(point(20,10)).should == false
120
+ r1.overlaps?(point(10,30)).should == false
121
+ r1.overlaps?(point(5,9)).should == false
122
+ r1.overlaps?(point(4,10)).should == false
123
+ end
124
+
125
+ it ".contains? point" do
126
+ r1 = rect(5, 10, 15, 20)
127
+ r1.contains?(point(10,10)).should == true
128
+ r1.contains?(point(20,10)).should == false
129
+ r1.contains?(point(10,30)).should == false
130
+ r1.contains?(point(5,9)).should == false
131
+ r1.contains?(point(4,10)).should == false
132
+ end
115
133
  end
116
134
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gui_geometry
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-03 00:00:00.000000000 Z
12
+ date: 2013-02-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake