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.
- data/lib/gui_geometry/point.rb +0 -7
- data/lib/gui_geometry/rectangle.rb +11 -9
- data/lib/gui_geometry/tools.rb +7 -0
- data/lib/gui_geometry/version.rb +1 -1
- data/spec/rectangle_spec.rb +6 -0
- metadata +2 -2
data/lib/gui_geometry/point.rb
CHANGED
@@ -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?(
|
62
|
-
case
|
61
|
+
def overlaps?(val)
|
62
|
+
case val
|
63
|
+
when nil then false
|
63
64
|
when Point then
|
64
|
-
contains?(
|
65
|
+
contains?(val)
|
65
66
|
when Rectangle then
|
66
|
-
|
67
|
-
loc + size >
|
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?(
|
73
|
-
case
|
73
|
+
def contains?(val)
|
74
|
+
case val
|
75
|
+
when nil then false
|
74
76
|
when Point then
|
75
|
-
|
77
|
+
val >= loc && val < (loc+size)
|
76
78
|
when Rectangle then
|
77
|
-
(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
|
data/lib/gui_geometry/tools.rb
CHANGED
data/lib/gui_geometry/version.rb
CHANGED
data/spec/rectangle_spec.rb
CHANGED
@@ -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.
|
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-
|
12
|
+
date: 2013-02-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|