gui_geometry 0.2.1 → 0.2.2

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.
@@ -11,13 +11,6 @@ class Point < Struct.new(:x, :y)
11
11
  def max(b); point(Tools::max(x, b.x), Tools::max(y, b.y)); end
12
12
  def bound(a, b); point(Tools::bound(a.x, x, b.x), Tools::bound(a.y, y, b.y)); end
13
13
 
14
- def clone_value(v)
15
- case v
16
- when Fixnum, Bignum, Float then v
17
- else v.clone
18
- end
19
- end
20
-
21
14
  def clone; point(clone_value(x), clone_value(y)); end
22
15
 
23
16
  def inspect; "point(#{x},#{y})" end
@@ -58,23 +58,25 @@ class Rectangle < Struct.new(:loc, :size)
58
58
  "(#{[loc.x,loc.y,size.x,size.y].join ','})"
59
59
  end
60
60
 
61
- def overlaps?(b)
62
- case b
61
+ def overlaps?(val)
62
+ case val
63
+ when nil then false
63
64
  when Point then
64
- contains?(b)
65
+ contains?(val)
65
66
  when Rectangle then
66
- b.loc + b.size > loc &&
67
- loc + size > b.loc
67
+ val.loc + val.size > loc &&
68
+ loc + size > val.loc
68
69
  else raise ArgumentError.new("wrong type: (#{val.class}) - Rectangle or Point expected")
69
70
  end
70
71
  end
71
72
 
72
- def contains?(b)
73
- case b
73
+ def contains?(val)
74
+ case val
75
+ when nil then false
74
76
  when Point then
75
- b >= loc && b < (loc+size)
77
+ val >= loc && val < (loc+size)
76
78
  when Rectangle then
77
- (self & b) == self
79
+ (self & val) == self
78
80
  else raise ArgumentError.new("wrong type: (#{val.class}) - Rectangle or Point expected")
79
81
  end
80
82
  end
@@ -12,6 +12,13 @@ module Tools
12
12
  end
13
13
  def bound(a,bounded,c) max(a,min(bounded,c)); end
14
14
 
15
+ def clone_value(v)
16
+ case v
17
+ when Fixnum, Bignum, Float then v
18
+ else v.clone
19
+ end
20
+ end
21
+
15
22
  class << self
16
23
  include GuiGeo::Tools
17
24
  end
@@ -1,3 +1,3 @@
1
1
  module GuiGeo
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
@@ -130,5 +130,11 @@ describe "Rectangle" do
130
130
  r1.contains?(point(5,9)).should == false
131
131
  r1.contains?(point(4,10)).should == false
132
132
  end
133
+
134
+ it ".contains? and .overlaps? with nil" do
135
+ r1 = rect(5, 10, 15, 20)
136
+ r1.overlaps?(nil).should == false
137
+ r1.contains?(nil).should == false
138
+ end
133
139
  end
134
140
  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.1
4
+ version: 0.2.2
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-06 00:00:00.000000000 Z
12
+ date: 2013-02-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake