gui_geometry 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -51,8 +51,8 @@ class Rectangle < Struct.new(:loc, :size)
51
51
 
52
52
  def area; size.area; end
53
53
 
54
- def x_range; x .. (x + w - 1) end
55
- def y_range; y .. (y + h - 1) end
54
+ def x_range; x ... (x + w) end
55
+ def y_range; y ... (y + h) end
56
56
 
57
57
  def inspect
58
58
  "rect"+to_s
@@ -90,6 +90,11 @@ class Rectangle < Struct.new(:loc, :size)
90
90
  def bl; point(x, y + h); end
91
91
  def tr; point(x + w, y); end
92
92
 
93
+ def top; loc.x; end
94
+ def left; loc.y; end
95
+ def right; loc.x + size.x; end
96
+ def bottom; loc.x + size.y; end
97
+
93
98
 
94
99
  def union(b)
95
100
  return clone unless b
@@ -107,5 +112,41 @@ class Rectangle < Struct.new(:loc, :size)
107
112
  rect l, s
108
113
  end
109
114
  alias :| :intersection
115
+
116
+ # return 1-3 rectangles which, together, cover exactly the same area as self and b, but do not overlapp
117
+ def disjoint(b)
118
+ return self if !b || contains(b)
119
+ return b if b.contains(self)
120
+ return self,b unless overlaps?(b)
121
+ tl_contained = contains?(b.tl) ? 1 : 0
122
+ tr_contained = contains?(b.tr) ? 1 : 0
123
+ bl_contained = contains?(b.bl) ? 1 : 0
124
+ br_contained = contains?(b.br) ? 1 : 0
125
+ sum = tl_contained + tr_contained + bl_contained + br_contained
126
+ case sum
127
+ when 0 # rectangles form a plus "+"
128
+ if b.y < self.y
129
+ r1,r2 = b,self
130
+ else
131
+ r1,r2 = self,b
132
+ end
133
+ tl1 = r1.tl
134
+ br1 = point(r1.right, r2.top)
135
+ tl2 = point(r1.left, r2.bottom)
136
+ br2 = r1.br
137
+ [
138
+ r2,
139
+ rect(tl1,br1-tl1),
140
+ rect(tl2,br2-tl2),
141
+ ]
142
+ when 1
143
+ when 2
144
+ else raise "internal error in disjoint - cases 3 and 4 should be taken care of by the return-tests at the top of the method"
145
+ end
146
+
147
+
148
+
149
+
150
+ end
110
151
  end
111
152
  end
@@ -1,3 +1,3 @@
1
1
  module GuiGeo
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
@@ -140,5 +140,12 @@ describe "Rectangle" do
140
140
  it ".area" do
141
141
  rect(5, 10, 15, 20).area.should == 300
142
142
  end
143
+
144
+ it ".y_range and .x_range" do
145
+ rect(5, 10, 15, 20).x_range.should == (5...20)
146
+ rect(5, 10, 15, 20).y_range.should == (10...30)
147
+ rect(0,0,0,0).x_range.should == (0...0)
148
+ rect(0,0,0,0).y_range.should == (0...0)
149
+ end
143
150
  end
144
151
  end
metadata CHANGED
@@ -1,104 +1,120 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: gui_geometry
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 3
8
- - 0
9
- version: 0.3.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.1
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Shane Brinkman-Davis
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
-
17
- date: 2013-02-24 00:00:00 -08:00
18
- default_executable:
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2013-03-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: rake
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- requirements:
25
- - - ">="
26
- - !ruby/object:Gem::Version
27
- segments:
28
- - 0
29
- version: "0"
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
30
22
  type: :development
31
- version_requirements: *id001
32
- - !ruby/object:Gem::Dependency
33
- name: rspec
34
23
  prerelease: false
35
- requirement: &id002 !ruby/object:Gem::Requirement
36
- requirements:
37
- - - ">="
38
- - !ruby/object:Gem::Version
39
- segments:
40
- - 0
41
- version: "0"
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
42
38
  type: :development
43
- version_requirements: *id002
44
- - !ruby/object:Gem::Dependency
45
- name: guard-rspec
46
39
  prerelease: false
47
- requirement: &id003 !ruby/object:Gem::Requirement
48
- requirements:
49
- - - ">="
50
- - !ruby/object:Gem::Version
51
- segments:
52
- - 0
53
- version: "0"
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: guard-rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
54
  type: :development
55
- version_requirements: *id003
56
- - !ruby/object:Gem::Dependency
57
- name: guard-test
58
55
  prerelease: false
59
- requirement: &id004 !ruby/object:Gem::Requirement
60
- requirements:
61
- - - ">="
62
- - !ruby/object:Gem::Version
63
- segments:
64
- - 0
65
- version: "0"
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: guard-test
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
66
70
  type: :development
67
- version_requirements: *id004
68
- - !ruby/object:Gem::Dependency
69
- name: rb-fsevent
70
71
  prerelease: false
71
- requirement: &id005 !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- segments:
76
- - 0
77
- version: "0"
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rb-fsevent
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
78
86
  type: :development
79
- version_requirements: *id005
80
- - !ruby/object:Gem::Dependency
81
- name: simplecov
82
87
  prerelease: false
83
- requirement: &id006 !ruby/object:Gem::Requirement
84
- requirements:
85
- - - ">="
86
- - !ruby/object:Gem::Version
87
- segments:
88
- - 0
89
- version: "0"
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: simplecov
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
90
102
  type: :development
91
- version_requirements: *id006
92
- description: 2D geometry specificly designed to support graphical user interfaces and bitmaps currently focsued on Point and Rectangle classes
93
- email:
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ description: 2D geometry specificly designed to support graphical user interfaces
111
+ and bitmaps currently focsued on Point and Rectangle classes
112
+ email:
94
113
  - shanebdavis@gmail.com
95
114
  executables: []
96
-
97
115
  extensions: []
98
-
99
116
  extra_rdoc_files: []
100
-
101
- files:
117
+ files:
102
118
  - .gitignore
103
119
  - Gemfile
104
120
  - Guardfile
@@ -115,37 +131,32 @@ files:
115
131
  - spec/rectangle_spec.rb
116
132
  - spec/spec_helper.rb
117
133
  - spec/tools_spec.rb
118
- has_rdoc: true
119
134
  homepage: https://github.com/shanebdavis/gui_geometry
120
135
  licenses: []
121
-
122
136
  post_install_message:
123
137
  rdoc_options: []
124
-
125
- require_paths:
138
+ require_paths:
126
139
  - lib
127
- required_ruby_version: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - ">="
130
- - !ruby/object:Gem::Version
131
- segments:
132
- - 0
133
- version: "0"
134
- required_rubygems_version: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - ">="
137
- - !ruby/object:Gem::Version
138
- segments:
139
- - 0
140
- version: "0"
140
+ required_ruby_version: !ruby/object:Gem::Requirement
141
+ none: false
142
+ requirements:
143
+ - - ! '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ required_rubygems_version: !ruby/object:Gem::Requirement
147
+ none: false
148
+ requirements:
149
+ - - ! '>='
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
141
152
  requirements: []
142
-
143
153
  rubyforge_project:
144
- rubygems_version: 1.3.6
154
+ rubygems_version: 1.8.25
145
155
  signing_key:
146
156
  specification_version: 3
147
- summary: 2D geometry specificly designed to support graphical user interfaces and bitmaps
148
- test_files:
157
+ summary: 2D geometry specificly designed to support graphical user interfaces and
158
+ bitmaps
159
+ test_files:
149
160
  - spec/point_spec.rb
150
161
  - spec/rectangle_spec.rb
151
162
  - spec/spec_helper.rb