gui_geometry 0.1.1 → 0.2.0
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/Rakefile +8 -2
- data/gui_geometry.gemspec +1 -1
- data/lib/gui_geometry/point.rb +12 -2
- data/lib/gui_geometry/rectangle.rb +19 -0
- data/lib/gui_geometry/tools.rb +4 -0
- data/lib/gui_geometry/version.rb +1 -1
- data/spec/point_spec.rb +24 -0
- data/spec/rectangle_spec.rb +30 -0
- data/spec/spec_helper.rb +1 -3
- metadata +3 -3
data/Rakefile
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
require "bundler/gem_tasks"
|
2
2
|
require "rspec/core/rake_task"
|
3
3
|
|
4
|
-
RSpec::Core::RakeTask.new(:spec)
|
5
|
-
|
6
4
|
task :default => :spec
|
5
|
+
|
6
|
+
desc "Run specs"
|
7
|
+
RSpec::Core::RakeTask.new do |task|
|
8
|
+
task.pattern = "**/spec/*_spec.rb"
|
9
|
+
task.rspec_opts = Dir.glob("[0-9][0-9][0-9]_*").collect { |x| "-I#{x}" }.sort
|
10
|
+
task.rspec_opts << '--color'
|
11
|
+
task.rspec_opts << '-f documentation'
|
12
|
+
end
|
data/gui_geometry.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |gem|
|
|
10
10
|
gem.email = ["shanebdavis@gmail.com"]
|
11
11
|
gem.description = %q{2D geometry specificly designed to support graphical user interfaces and bitmaps currently focsued on Point and Rectangle classes}
|
12
12
|
gem.summary = %q{2D geometry specificly designed to support graphical user interfaces and bitmaps}
|
13
|
-
gem.homepage = ""
|
13
|
+
gem.homepage = "https://github.com/shanebdavis/gui_geometry"
|
14
14
|
|
15
15
|
gem.files = `git ls-files`.split($/)
|
16
16
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
data/lib/gui_geometry/point.rb
CHANGED
@@ -7,8 +7,18 @@ class Point < Struct.new(:x, :y)
|
|
7
7
|
super if args.length!=0
|
8
8
|
end
|
9
9
|
|
10
|
-
def min(b); point(
|
11
|
-
def max(b); point(
|
10
|
+
def min(b); point(Tools::min(x, b.x), Tools::min(y, b.y)); end
|
11
|
+
def max(b); point(Tools::max(x, b.x), Tools::max(y, b.y)); end
|
12
|
+
def bound(a, b); point(Tools::bound(a.x, x, b.x), Tools::bound(a.y, y, b.y)); end
|
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
|
+
def clone; point(clone_value(x), clone_value(y)); end
|
12
22
|
|
13
23
|
def inspect; "point(#{x},#{y})" end
|
14
24
|
def to_s; "(#{x},#{y})" end
|
@@ -23,6 +23,25 @@ class Rectangle < Struct.new(:loc, :size)
|
|
23
23
|
!present?
|
24
24
|
end
|
25
25
|
|
26
|
+
def clone
|
27
|
+
rect loc.clone, size.clone
|
28
|
+
end
|
29
|
+
|
30
|
+
# val can be a Rectangle or Point
|
31
|
+
# returns a Rectangle or Point that is within this Rectangle
|
32
|
+
# For Rectangles, the size is only changed if it has to be
|
33
|
+
def bound(val)
|
34
|
+
case val
|
35
|
+
when Rectangle then
|
36
|
+
r = val.clone
|
37
|
+
r.size = r.size.min(size)
|
38
|
+
r.loc = r.loc.bound(loc, loc + size - val.size)
|
39
|
+
r
|
40
|
+
when Point then (val-loc).bound(point, size) + loc
|
41
|
+
else raise ArgumentError.new("wrong type: (#{val.class}) - Rectangle or Point expected")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
26
45
|
def x; loc.x; end
|
27
46
|
def y; loc.y; end
|
28
47
|
def w; size.x; end
|
data/lib/gui_geometry/tools.rb
CHANGED
data/lib/gui_geometry/version.rb
CHANGED
data/spec/point_spec.rb
CHANGED
@@ -13,6 +13,22 @@ describe "Point" do
|
|
13
13
|
(point(1,2) + 3).should == point(4,5)
|
14
14
|
end
|
15
15
|
|
16
|
+
it "clone basic point" do
|
17
|
+
p1 = point(1,2)
|
18
|
+
p2 = p1.clone
|
19
|
+
p1.should == p2
|
20
|
+
p2.x = 3
|
21
|
+
p1.should_not == p2
|
22
|
+
end
|
23
|
+
|
24
|
+
it "clone complex point" do
|
25
|
+
p1 = point("hi","bye")
|
26
|
+
p2 = p1.clone
|
27
|
+
p1.should == p2
|
28
|
+
p2.x.upcase!
|
29
|
+
p1.should_not == p2
|
30
|
+
end
|
31
|
+
|
16
32
|
it "-" do
|
17
33
|
(point(9,8) - point(3,4)).should == point(6,4)
|
18
34
|
(point(9,8) - 3).should == point(6,5)
|
@@ -79,5 +95,13 @@ describe "Point" do
|
|
79
95
|
point(9,5).max(point(5,9)).should == point(9,9)
|
80
96
|
point(5,9).max(point(9,5)).should == point(9,9)
|
81
97
|
end
|
98
|
+
|
99
|
+
it "bound" do
|
100
|
+
point(3,4).bound(point(1,2), point(5,6)).should == point(3,4)
|
101
|
+
point(3,0).bound(point(1,2), point(5,6)).should == point(3,2)
|
102
|
+
point(3,6).bound(point(1,2), point(5,6)).should == point(3,6)
|
103
|
+
point(0,4).bound(point(1,2), point(5,6)).should == point(1,4)
|
104
|
+
point(6,4).bound(point(1,2), point(5,6)).should == point(5,4)
|
105
|
+
end
|
82
106
|
end
|
83
107
|
end
|
data/spec/rectangle_spec.rb
CHANGED
@@ -13,6 +13,15 @@ describe "Rectangle" do
|
|
13
13
|
expect { rect(1,2,3,4,5) }.to raise_error
|
14
14
|
end
|
15
15
|
|
16
|
+
it "clone" do
|
17
|
+
r1 = rect(1,2,3,4)
|
18
|
+
r2 = r1.clone
|
19
|
+
r1.should == r2
|
20
|
+
r1.object_id.should_not == r2.object_id
|
21
|
+
r1.loc.object_id.should_not == r2.loc.object_id
|
22
|
+
r1.size.object_id.should_not == r2.size.object_id
|
23
|
+
end
|
24
|
+
|
16
25
|
it "init with one point" do
|
17
26
|
rect(point(1,2)).should == rect(0,0,1,2)
|
18
27
|
end
|
@@ -76,11 +85,32 @@ describe "Rectangle" do
|
|
76
85
|
rect(0,0,0,1).present?.should == false
|
77
86
|
rect(0,0,0,0).present?.should == false
|
78
87
|
end
|
88
|
+
|
79
89
|
it ".blank?" do
|
80
90
|
rect(0,0,1,1).blank?.should == false
|
81
91
|
rect(0,0,1,0).blank?.should == true
|
82
92
|
rect(0,0,0,1).blank?.should == true
|
83
93
|
rect(0,0,0,0).blank?.should == true
|
84
94
|
end
|
95
|
+
|
96
|
+
it ".bound(point)" do
|
97
|
+
r = rect(5, 10, 15, 20)
|
98
|
+
r.bound(point(5,10)).should == point(5,10)
|
99
|
+
r.bound(point(20,30)).should == point(20,30)
|
100
|
+
r.bound(point(5,31)).should == point(5,30)
|
101
|
+
r.bound(point(21,10)).should == point(20,10)
|
102
|
+
r.bound(point(5,10)).should == point(5,10)
|
103
|
+
r.bound(point(5, 9)).should == point(5,10)
|
104
|
+
r.bound(point(4,10)).should == point(5,10)
|
105
|
+
end
|
106
|
+
|
107
|
+
it ".bound(smaller_rect)" do
|
108
|
+
r1 = rect(5, 10, 15, 20)
|
109
|
+
r1.bound(rect(5,0,5,5)).should == rect(5,10,5,5)
|
110
|
+
r1.bound(rect(0,10,5,5)).should == rect(5,10,5,5)
|
111
|
+
r1.bound(rect(0,30,5,5)).should == rect(5,25,5,5)
|
112
|
+
r1.bound(rect(30,0,5,5)).should == rect(15,10,5,5)
|
113
|
+
r1.bound(rect(0,0,20,5)).should == rect(5,10,15,5)
|
114
|
+
end
|
85
115
|
end
|
86
116
|
end
|
data/spec/spec_helper.rb
CHANGED
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.
|
4
|
+
version: 0.2.0
|
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-
|
12
|
+
date: 2013-02-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -131,7 +131,7 @@ files:
|
|
131
131
|
- spec/rectangle_spec.rb
|
132
132
|
- spec/spec_helper.rb
|
133
133
|
- spec/tools_spec.rb
|
134
|
-
homepage:
|
134
|
+
homepage: https://github.com/shanebdavis/gui_geometry
|
135
135
|
licenses: []
|
136
136
|
post_install_message:
|
137
137
|
rdoc_options: []
|