uzi-rect 0.0.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.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
4
+ *.swp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in uzi-rect.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,26 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ uzi-rect (0.0.1)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.1.2)
10
+ rspec (2.0.0)
11
+ rspec-core (= 2.0.0)
12
+ rspec-expectations (= 2.0.0)
13
+ rspec-mocks (= 2.0.0)
14
+ rspec-core (2.0.0)
15
+ rspec-expectations (2.0.0)
16
+ diff-lcs (>= 1.1.2)
17
+ rspec-mocks (2.0.0)
18
+ rspec-core (= 2.0.0)
19
+ rspec-expectations (= 2.0.0)
20
+
21
+ PLATFORMS
22
+ ruby
23
+
24
+ DEPENDENCIES
25
+ rspec (~> 2.0.0)
26
+ uzi-rect!
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,5 @@
1
+ module Uzi
2
+ class Rect
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
data/lib/uzi-rect.rb ADDED
@@ -0,0 +1,105 @@
1
+ module Uzi
2
+ class Rect
3
+ attr_accessor :x, :y, :width, :height
4
+
5
+ def initialize(*args)
6
+ if args.empty?
7
+ @x, @y, @width, @height = 0, 0, 0, 0
8
+ else
9
+ @x, @y, @width, @height = *args
10
+ end
11
+ end
12
+
13
+ def to_a
14
+ [ @x, @y, @width, @height ]
15
+ end
16
+
17
+
18
+ # Left, right, top and bottom edges
19
+ def left; @x; end
20
+ def left=(x); @x = x; end
21
+
22
+ def right; @x + @width; end
23
+ def right=(x); @x = x - @width; end
24
+
25
+ def top; @y; end
26
+ def top=(y); @y = y; end
27
+
28
+ def bottom; @y + @height; end
29
+ def bottom=(y); @y = y - @height; end
30
+
31
+
32
+ # Corner points
33
+ def topleft; [ @x, @y ]; end
34
+ def topleft=(loc); @x, @y = loc[0], loc[1]; end
35
+
36
+ def topright
37
+ [
38
+ right,
39
+ top
40
+ ]
41
+ end
42
+
43
+ def topright=(loc)
44
+ self.right = loc[0]
45
+ self.top = loc[1]
46
+ end
47
+
48
+
49
+ def bottomleft
50
+ [
51
+ left,
52
+ bottom
53
+ ]
54
+ end
55
+
56
+ def bottomleft=(loc)
57
+ self.left = loc[0]
58
+ self.bottom = loc[1]
59
+ end
60
+
61
+
62
+ def bottomright
63
+ [
64
+ right,
65
+ bottom
66
+ ]
67
+ end
68
+
69
+ def bottomright=(loc)
70
+ self.right = loc[0]
71
+ self.bottom = loc[1]
72
+ end
73
+
74
+ # Center point
75
+ def center
76
+ [
77
+ @x + (@width / 2.0),
78
+ @y + (@height / 2.0)
79
+ ]
80
+ end
81
+
82
+ def center=(loc)
83
+ @x = loc[0] - (@width / 2.0)
84
+ @y = loc[1] - (@height / 2.0)
85
+ end
86
+
87
+
88
+ def center_x; center[0]; end
89
+ def center_y; center[1]; end
90
+
91
+ def center_x=(x)
92
+ c = center
93
+ c[0] = x
94
+
95
+ self.center = c
96
+ end
97
+
98
+ def center_y=(y)
99
+ c = center
100
+ c[1] = y
101
+
102
+ self.center = c
103
+ end
104
+ end
105
+ end
data/spec/rect_spec.rb ADDED
@@ -0,0 +1,150 @@
1
+ require 'uzi-rect'
2
+ include Uzi
3
+
4
+ describe Rect do
5
+ before :each do
6
+ @r = Rect.new(0, 0, 10, 10)
7
+ end
8
+
9
+ it "should be constructed with no parameters" do
10
+ r = Rect.new
11
+ r.to_a.should == [ 0, 0, 0, 0 ]
12
+ end
13
+
14
+ it "should be constructed with x, y, width, height" do
15
+ @r.to_a.should == [ 0, 0, 10, 10 ]
16
+ end
17
+
18
+
19
+ it "should return its left side" do
20
+ @r.left.should == 0
21
+ end
22
+
23
+ it "should be able to assign the left side" do
24
+ @r.left = 10
25
+ @r.left.should == 10
26
+ @r.x.should == 10
27
+ end
28
+
29
+
30
+ it "should return its right side" do
31
+ @r.right.should == 10
32
+ end
33
+
34
+ it "should be able to assign the right side" do
35
+ @r.right = 20
36
+ @r.right.should == 20
37
+ @r.left.should == 10
38
+ end
39
+
40
+
41
+ it "should return its top side" do
42
+ @r.top.should == 0
43
+ end
44
+
45
+ it "should be able to assign the top side" do
46
+ @r.top = 10
47
+ @r.top.should == 10
48
+ @r.bottom.should == 20
49
+ end
50
+
51
+
52
+ it "should return its bottom side" do
53
+ @r.bottom.should == 10
54
+ end
55
+
56
+ it "should be able to assign the bottom side" do
57
+ @r.bottom = 20
58
+ @r.bottom.should == 20
59
+ @r.top.should == 10
60
+ end
61
+
62
+
63
+ it "should return its top-left corner" do
64
+ @r.topleft.should == [0, 0]
65
+ end
66
+
67
+ it "should be able to assign the top left corner" do
68
+ @r.topleft = [10, 10]
69
+ @r.left.should == 10
70
+ @r.top.should == 10
71
+ end
72
+
73
+
74
+ it "should return its top right corner" do
75
+ @r.topright.should == [10, 0]
76
+ end
77
+
78
+ it "should be able to assign the top right corner" do
79
+ @r.topright = [10, 10]
80
+ @r.left.should == 0
81
+ @r.right.should == 10
82
+ @r.top.should == 10
83
+ @r.bottom.should == 20
84
+ end
85
+
86
+
87
+ it "should return its bottom left corner" do
88
+ @r.bottomleft.should == [0, 10]
89
+ end
90
+
91
+ it "should be able to assign the bottom left corner" do
92
+ @r.bottomleft = [10, 10]
93
+ @r.bottom.should == 10
94
+ @r.left.should == 10
95
+ end
96
+
97
+
98
+ it "should return its bottom right corner" do
99
+ @r.bottomright.should == [10, 10]
100
+ end
101
+
102
+ it "should be able to assign the bottom right corner" do
103
+ @r.bottomright = [20, 20]
104
+ @r.bottom.should == 20
105
+ @r.right.should == 20
106
+ end
107
+
108
+
109
+ it "should return its center point" do
110
+ @r.center.should == [5, 5]
111
+ end
112
+
113
+ it "should set its center" do
114
+ @r.center = [10, 10]
115
+ @r.left.should == 5
116
+ @r.right.should == 15
117
+ @r.top.should == 5
118
+ @r.bottom.should == 15
119
+ end
120
+
121
+
122
+ it "should return its center's X" do
123
+ @r.center_x.should == 5
124
+ end
125
+
126
+ it "should return its center's Y" do
127
+ @r.center_y.should == 5
128
+ end
129
+
130
+ it "should be able to assign the center's X" do
131
+ @r.center_x = 10
132
+ @r.left.should == 5
133
+ @r.right.should == 15
134
+ @r.top.should == 0
135
+ end
136
+
137
+ it "should be able to assign the center's Y" do
138
+ @r.center_y = 10
139
+ @r.top.should == 5
140
+ @r.bottom.should == 15
141
+ @r.left.should == 0
142
+ end
143
+
144
+
145
+ it "should return the correct center if it's not an integer" do
146
+ @r.width = 11
147
+ @r.height = 11
148
+ @r.center.should == [5.5, 5.5]
149
+ end
150
+ end
data/uzi-rect.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "uzi-rect/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "uzi-rect"
7
+ s.version = Uzi::Rect::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Michael Morin"]
10
+ s.email = ["michael.c.morin@gmail.com"]
11
+ s.homepage = "http://rubygems.org/gems/uzi-rect"
12
+ s.summary = %q{A simple class to define and manipulate 2D rectangles}
13
+ s.description = %q{A simple class to define and manipulate 2D rectangles}
14
+
15
+ s.rubyforge_project = "uzi-rect"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_development_dependency 'rspec', '~> 2.0.0'
23
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: uzi-rect
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Michael Morin
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-10-19 00:00:00 -04:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rspec
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 15
30
+ segments:
31
+ - 2
32
+ - 0
33
+ - 0
34
+ version: 2.0.0
35
+ type: :development
36
+ version_requirements: *id001
37
+ description: A simple class to define and manipulate 2D rectangles
38
+ email:
39
+ - michael.c.morin@gmail.com
40
+ executables: []
41
+
42
+ extensions: []
43
+
44
+ extra_rdoc_files: []
45
+
46
+ files:
47
+ - .gitignore
48
+ - Gemfile
49
+ - Gemfile.lock
50
+ - Rakefile
51
+ - lib/uzi-rect.rb
52
+ - lib/uzi-rect/version.rb
53
+ - spec/rect_spec.rb
54
+ - uzi-rect.gemspec
55
+ has_rdoc: true
56
+ homepage: http://rubygems.org/gems/uzi-rect
57
+ licenses: []
58
+
59
+ post_install_message:
60
+ rdoc_options: []
61
+
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ hash: 3
70
+ segments:
71
+ - 0
72
+ version: "0"
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ hash: 3
79
+ segments:
80
+ - 0
81
+ version: "0"
82
+ requirements: []
83
+
84
+ rubyforge_project: uzi-rect
85
+ rubygems_version: 1.3.7
86
+ signing_key:
87
+ specification_version: 3
88
+ summary: A simple class to define and manipulate 2D rectangles
89
+ test_files:
90
+ - spec/rect_spec.rb