gosu_enhanced 0.2.0 → 0.3.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.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/Gemfile.lock +1 -1
- data/lib/gosu_enhanced.rb +1 -1
- data/lib/gosu_enhanced/enhanced.rb +6 -7
- data/lib/gosu_enhanced/point.rb +6 -1
- data/lib/gosu_enhanced/region.rb +14 -13
- data/lib/gosu_enhanced/size.rb +12 -11
- data/lib/gosu_enhanced/version.rb +1 -1
- data/spec/point_spec.rb +40 -22
- data/spec/region_delegation_spec.rb +85 -78
- data/spec/region_spec.rb +9 -9
- data/spec/size_spec.rb +24 -20
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c84be3918a088b23a001df84ce7eed6b012a9373
|
4
|
+
data.tar.gz: df2ce42f9f3dd63917891aa15003421adf601a50
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 520b635d9e2c6aaa5416c9549beb980a5f988bf126f292323a3ab1a28e64e736cb9161d78350b01a282ea174264f3f0d295010ab2e47b5de7208276c5473f1f5
|
7
|
+
data.tar.gz: 801a931e4341016bc16cbc57b110a41c5c7ce0ced10c097832b1492dbe8905271dc0f05d50899da33ca104ab90cca79543a5cd6de508c34faeb32106f326751f
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
data/lib/gosu_enhanced.rb
CHANGED
@@ -18,23 +18,22 @@ module Gosu
|
|
18
18
|
|
19
19
|
# Add a measure to return both width and height for a text and a way
|
20
20
|
# to centre a text in a rectangle
|
21
|
-
|
22
21
|
class Font
|
23
22
|
include GosuEnhanced
|
24
23
|
|
25
24
|
def measure( text )
|
26
25
|
Size.new( text_width( text, 1 ), height )
|
27
26
|
end
|
28
|
-
|
27
|
+
|
29
28
|
def centred_in( text, rect )
|
30
29
|
size = measure( text )
|
31
|
-
|
32
|
-
Point.new(
|
33
|
-
(rect.width - size.width) / 2,
|
34
|
-
(rect.height - size.height) / 2
|
30
|
+
|
31
|
+
Point.new(
|
32
|
+
(rect.width - size.width) / 2,
|
33
|
+
(rect.height - size.height) / 2
|
35
34
|
)
|
36
35
|
end
|
37
36
|
|
38
37
|
alias_method :centered_in, :centred_in
|
39
|
-
end
|
38
|
+
end
|
40
39
|
end
|
data/lib/gosu_enhanced/point.rb
CHANGED
@@ -4,17 +4,22 @@ module GosuEnhanced
|
|
4
4
|
def offset( by_x, by_y = nil )
|
5
5
|
if by_x.respond_to? :x
|
6
6
|
Point.new( x + by_x.x, y + by_x.y )
|
7
|
+
elsif by_x.respond_to? :width
|
8
|
+
Point.new( x + by_x.width, y + by_x.height )
|
7
9
|
else
|
8
10
|
Point.new( x + by_x, y + by_y )
|
9
11
|
end
|
10
12
|
end
|
11
13
|
|
12
14
|
# Negative co-ordinates are allowed.
|
13
|
-
|
15
|
+
|
14
16
|
def move_by!( by_x, by_y = nil )
|
15
17
|
if by_x.respond_to? :x
|
16
18
|
self.x += by_x.x
|
17
19
|
self.y += by_x.y
|
20
|
+
elsif by_x.respond_to? :width
|
21
|
+
self.x += by_x.width
|
22
|
+
self.y += by_x.height
|
18
23
|
else
|
19
24
|
self.x += by_x
|
20
25
|
self.y += by_y
|
data/lib/gosu_enhanced/region.rb
CHANGED
@@ -5,40 +5,41 @@ module GosuEnhanced
|
|
5
5
|
# Most functions are delegated to the constituent Point and Size
|
6
6
|
class Region
|
7
7
|
extend Forwardable
|
8
|
-
|
8
|
+
|
9
9
|
def_delegators :@position, :move_by!, :move_to!, :x, :y
|
10
10
|
def_delegators :@size, :inflate!, :deflate!, :width, :height
|
11
|
-
|
11
|
+
|
12
12
|
attr_reader :position, :size
|
13
|
-
|
13
|
+
|
14
14
|
def initialize( pos, size )
|
15
15
|
@position, @size = pos.dup, size.dup
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
def contains?( col, row = nil )
|
19
19
|
if col.respond_to? :x
|
20
|
-
col.x.between?( left, left + width - 1 ) &&
|
20
|
+
col.x.between?( left, left + width - 1 ) &&
|
21
21
|
col.y.between?( top, top + height - 1 )
|
22
22
|
else
|
23
|
-
col.between?( left, left + width - 1 ) &&
|
23
|
+
col.between?( left, left + width - 1 ) &&
|
24
24
|
row.between?( top, top + height - 1 )
|
25
|
-
end
|
25
|
+
end
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
def top
|
29
29
|
position.y
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
def left
|
33
33
|
position.x
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
|
+
# It is necessary to override dup to produce an actual duplicate.
|
36
37
|
def dup
|
37
38
|
Region.new( position.dup, size.dup )
|
38
39
|
end
|
39
|
-
|
40
|
-
def draw( surface,
|
41
|
-
surface.draw_rectangle( position, size,
|
40
|
+
|
41
|
+
def draw( surface, z_order, colour )
|
42
|
+
surface.draw_rectangle( position, size, z_order, colour )
|
42
43
|
end
|
43
44
|
end
|
44
45
|
end
|
data/lib/gosu_enhanced/size.rb
CHANGED
@@ -2,23 +2,23 @@ module GosuEnhanced
|
|
2
2
|
# Hold a 2-dimensional size and allow for inflation / deflation
|
3
3
|
class Size
|
4
4
|
attr_reader :width, :height
|
5
|
-
|
5
|
+
|
6
6
|
# Neither dimension can be negative, since that doesn't make sense.
|
7
7
|
# The values are checked on inflation / deflation.
|
8
|
-
|
8
|
+
|
9
9
|
def initialize( w, h )
|
10
10
|
@width, @height = w, h
|
11
11
|
validate( 0, 0 )
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
def inflate( by_w, by_h = nil )
|
15
15
|
if by_w.respond_to? :width
|
16
16
|
validate( by_w.width, by_w.height )
|
17
|
-
|
17
|
+
|
18
18
|
Size.new( width + by_w.width, height + by_w.height )
|
19
19
|
else
|
20
20
|
validate( by_w, by_h )
|
21
|
-
|
21
|
+
|
22
22
|
Size.new( width + by_w, height + by_h )
|
23
23
|
end
|
24
24
|
end
|
@@ -34,12 +34,12 @@ module GosuEnhanced
|
|
34
34
|
def inflate!( by_w, by_h = nil )
|
35
35
|
if by_w.respond_to? :width
|
36
36
|
validate( by_w.width, by_w.height )
|
37
|
-
|
37
|
+
|
38
38
|
@width += by_w.width
|
39
39
|
@height += by_w.height
|
40
40
|
else
|
41
41
|
validate( by_w, by_h )
|
42
|
-
|
42
|
+
|
43
43
|
@width += by_w
|
44
44
|
@height += by_h
|
45
45
|
end
|
@@ -52,14 +52,15 @@ module GosuEnhanced
|
|
52
52
|
inflate!( -by_w, -by_h )
|
53
53
|
end
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
56
|
def ==( other )
|
57
57
|
width == other.width && height == other.height
|
58
58
|
end
|
59
|
+
|
59
60
|
private
|
60
|
-
|
61
|
+
|
61
62
|
def validate( by_w, by_h )
|
62
|
-
fail
|
63
|
+
fail 'Cannot make size negative' if width + by_w < 0 || height + by_h < 0
|
63
64
|
end
|
64
|
-
end
|
65
|
+
end
|
65
66
|
end
|
data/spec/point_spec.rb
CHANGED
@@ -10,19 +10,19 @@ describe GosuEnhanced::Point do
|
|
10
10
|
|
11
11
|
it 'should work with negative values' do
|
12
12
|
point = GosuEnhanced::Point.new( -10, 20 )
|
13
|
-
expect( point.x ).to eq -10
|
13
|
+
expect( point.x ).to eq( -10 )
|
14
14
|
expect( point.y ).to eq 20
|
15
15
|
|
16
16
|
point = GosuEnhanced::Point.new( 10, -20 )
|
17
17
|
expect( point.x ).to eq 10
|
18
|
-
expect( point.y ).to eq -20
|
18
|
+
expect( point.y ).to eq( -20 )
|
19
19
|
|
20
20
|
point = GosuEnhanced::Point.new( -10, -20 )
|
21
|
-
expect( point.x ).to eq -10
|
22
|
-
expect( point.y ).to eq -20
|
21
|
+
expect( point.x ).to eq( -10 )
|
22
|
+
expect( point.y ).to eq( -20 )
|
23
23
|
end
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
describe '#offset' do
|
27
27
|
it 'should work with another Point' do
|
28
28
|
point = GosuEnhanced::Point.new( 10, 20 )
|
@@ -31,6 +31,13 @@ describe GosuEnhanced::Point do
|
|
31
31
|
expect( opoint.y ).to eq 60
|
32
32
|
end
|
33
33
|
|
34
|
+
it 'should work with a Size' do
|
35
|
+
point = GosuEnhanced::Point.new( 10, 20 )
|
36
|
+
opoint = point.offset( GosuEnhanced::Size.new( 50, 60 ) )
|
37
|
+
expect( opoint.x ).to eq 60
|
38
|
+
expect( opoint.y ).to eq 80
|
39
|
+
end
|
40
|
+
|
34
41
|
it 'should work with two positive values' do
|
35
42
|
point = GosuEnhanced::Point.new( 10, 20 )
|
36
43
|
opoint = point.offset( 40, 50 )
|
@@ -48,11 +55,11 @@ describe GosuEnhanced::Point do
|
|
48
55
|
it 'should work with values that result in negative co-ordinates' do
|
49
56
|
point = GosuEnhanced::Point.new( 60, 80 )
|
50
57
|
opoint = point.offset( -80, -150 )
|
51
|
-
expect( opoint.x ).to eq -20
|
52
|
-
expect( opoint.y ).to eq -70
|
58
|
+
expect( opoint.x ).to eq( -20 )
|
59
|
+
expect( opoint.y ).to eq( -70 )
|
53
60
|
end
|
54
61
|
end
|
55
|
-
|
62
|
+
|
56
63
|
describe '#move_by!' do
|
57
64
|
it 'should work with another Point' do
|
58
65
|
point = GosuEnhanced::Point.new( 10, 20 )
|
@@ -60,7 +67,14 @@ describe GosuEnhanced::Point do
|
|
60
67
|
expect( point.x ).to eq 40
|
61
68
|
expect( point.y ).to eq 60
|
62
69
|
end
|
63
|
-
|
70
|
+
|
71
|
+
it 'should work with a Size' do
|
72
|
+
point = GosuEnhanced::Point.new( 10, 20 )
|
73
|
+
point.move_by!( GosuEnhanced::Size.new( 40, 50 ) )
|
74
|
+
expect( point.x ).to eq 50
|
75
|
+
expect( point.y ).to eq 70
|
76
|
+
end
|
77
|
+
|
64
78
|
it 'should work with two positive values' do
|
65
79
|
point = GosuEnhanced::Point.new( 10, 20 )
|
66
80
|
point.move_by!( 40, 50 )
|
@@ -78,11 +92,11 @@ describe GosuEnhanced::Point do
|
|
78
92
|
it 'should work with values that result in negative co-ordinates' do
|
79
93
|
point = GosuEnhanced::Point.new( 60, 80 )
|
80
94
|
point.move_by!( -80, -150 )
|
81
|
-
expect( point.x ).to eq -20
|
82
|
-
expect( point.y ).to eq -70
|
95
|
+
expect( point.x ).to eq( -20 )
|
96
|
+
expect( point.y ).to eq( -70 )
|
83
97
|
end
|
84
98
|
end
|
85
|
-
|
99
|
+
|
86
100
|
describe '#move_to!' do
|
87
101
|
it 'should work with another Point' do
|
88
102
|
point = GosuEnhanced::Point.new( 10, 20 )
|
@@ -90,7 +104,7 @@ describe GosuEnhanced::Point do
|
|
90
104
|
expect( point.x ).to eq 30
|
91
105
|
expect( point.y ).to eq 40
|
92
106
|
end
|
93
|
-
|
107
|
+
|
94
108
|
it 'should work with two positive values' do
|
95
109
|
point = GosuEnhanced::Point.new( 10, 20 )
|
96
110
|
point.move_to!( 40, 50 )
|
@@ -101,26 +115,30 @@ describe GosuEnhanced::Point do
|
|
101
115
|
it 'should work with two negative values' do
|
102
116
|
point = GosuEnhanced::Point.new( 60, 80 )
|
103
117
|
point.move_to!( -40, -50 )
|
104
|
-
expect( point.x ).to eq -40
|
105
|
-
expect( point.y ).to eq -50
|
118
|
+
expect( point.x ).to eq( -40 )
|
119
|
+
expect( point.y ).to eq( -50 )
|
106
120
|
end
|
107
121
|
end
|
108
|
-
|
122
|
+
|
109
123
|
# This might seem laboured, but I have run foul of dup before
|
110
|
-
|
124
|
+
|
111
125
|
describe '#dup' do
|
112
126
|
it 'should make a copy of the Point' do
|
113
127
|
point = GosuEnhanced::Point.new( 10, 20 )
|
114
128
|
npoint = point.dup
|
129
|
+
|
115
130
|
expect( point.x ).to eq 10
|
116
131
|
expect( point.y ).to eq 20
|
132
|
+
|
117
133
|
expect( npoint.x ).to eq 10
|
118
134
|
expect( npoint.y ).to eq 20
|
119
|
-
|
120
|
-
|
121
|
-
expect(
|
122
|
-
expect( npoint.
|
123
|
-
|
135
|
+
|
136
|
+
npoint.move_to!( 40, 50 )
|
137
|
+
expect( npoint.x ).to eq 40
|
138
|
+
expect( npoint.y ).to eq 50
|
139
|
+
|
140
|
+
expect( point.x ).to eq 10
|
141
|
+
expect( point.y ).to eq 20
|
124
142
|
end
|
125
143
|
end
|
126
144
|
end
|
@@ -3,46 +3,53 @@ require 'spec_helper'
|
|
3
3
|
describe GosuEnhanced::Region do
|
4
4
|
let( :point ) { GosuEnhanced::Point.new( 10, 20 ) }
|
5
5
|
let( :size ) { GosuEnhanced::Size.new( 30, 40 ) }
|
6
|
-
|
7
|
-
describe '#
|
8
|
-
it 'should return the
|
6
|
+
|
7
|
+
describe '#x' do
|
8
|
+
it 'should return the left (x) co-ordinate' do
|
9
9
|
reg = GosuEnhanced::Region.new( point, size )
|
10
|
-
expect( reg.
|
10
|
+
expect( reg.x ).to eq 10
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
describe '#
|
15
|
-
it 'should return the
|
14
|
+
describe '#y' do
|
15
|
+
it 'should return the top (y) co-ordinate' do
|
16
16
|
reg = GosuEnhanced::Region.new( point, size )
|
17
|
-
expect( reg.
|
17
|
+
expect( reg.y ).to eq 20
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
21
|
describe '#width' do
|
22
|
-
it 'should return the width' do
|
22
|
+
it 'should return the width' do
|
23
23
|
reg = GosuEnhanced::Region.new( point, size )
|
24
24
|
expect( reg.width ).to eq 30
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
28
|
describe '#height' do
|
29
|
-
it 'should return the height' do
|
29
|
+
it 'should return the height' do
|
30
30
|
reg = GosuEnhanced::Region.new( point, size )
|
31
31
|
expect( reg.height ).to eq 40
|
32
32
|
end
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
describe '#move_by!' do
|
36
36
|
it 'should work with a Point' do
|
37
37
|
reg = GosuEnhanced::Region.new( point, size )
|
38
38
|
reg.move_by!( GosuEnhanced::Point.new( 30, 40 ) )
|
39
39
|
expect( reg.left ).to eq 40
|
40
40
|
expect( reg.top ).to eq 60
|
41
|
-
|
41
|
+
|
42
42
|
expect( point.x ).to eq 10
|
43
43
|
expect( point.y ).to eq 20
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
|
+
it 'should work with a Size' do
|
47
|
+
reg = GosuEnhanced::Region.new( point, size )
|
48
|
+
reg.move_by!( GosuEnhanced::Size.new( 40, 50 ) )
|
49
|
+
expect( reg.left ).to eq 50
|
50
|
+
expect( reg.top ).to eq 70
|
51
|
+
end
|
52
|
+
|
46
53
|
it 'should work with two positive values' do
|
47
54
|
reg = GosuEnhanced::Region.new( point, size )
|
48
55
|
reg.move_by!( 40, 50 )
|
@@ -60,22 +67,22 @@ describe GosuEnhanced::Region do
|
|
60
67
|
it 'should work with values that result in negative co-ordinates' do
|
61
68
|
reg = GosuEnhanced::Region.new( point, size )
|
62
69
|
reg.move_by!( -80, -150 )
|
63
|
-
expect( reg.left ).to eq -70
|
64
|
-
expect( reg.top ).to eq -130
|
70
|
+
expect( reg.left ).to eq( -70 )
|
71
|
+
expect( reg.top ).to eq( -130 )
|
65
72
|
end
|
66
73
|
end
|
67
|
-
|
74
|
+
|
68
75
|
describe '#move_to!' do
|
69
76
|
it 'should work with a Point' do
|
70
77
|
reg = GosuEnhanced::Region.new( point, size )
|
71
78
|
reg.move_to!( GosuEnhanced::Point.new( 30, 40 ) )
|
72
79
|
expect( reg.left ).to eq 30
|
73
80
|
expect( reg.top ).to eq 40
|
74
|
-
|
81
|
+
|
75
82
|
expect( point.x ).to eq 10
|
76
83
|
expect( point.y ).to eq 20
|
77
84
|
end
|
78
|
-
|
85
|
+
|
79
86
|
it 'should work with two positive values' do
|
80
87
|
reg = GosuEnhanced::Region.new( point, size )
|
81
88
|
reg.move_to!( 40, 50 )
|
@@ -86,67 +93,67 @@ describe GosuEnhanced::Region do
|
|
86
93
|
it 'should work with two negative values' do
|
87
94
|
reg = GosuEnhanced::Region.new( point, size )
|
88
95
|
reg.move_to!( -5, -10 )
|
89
|
-
expect( reg.left ).to eq -5
|
90
|
-
expect( reg.top ).to eq -10
|
91
|
-
end
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
end
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
96
|
+
expect( reg.left ).to eq( -5 )
|
97
|
+
expect( reg.top ).to eq( -10 )
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe '#inflate!' do
|
102
|
+
it 'should work with a Size' do
|
103
|
+
reg = GosuEnhanced::Region.new( point, size )
|
104
|
+
reg.inflate!( GosuEnhanced::Size.new( 30, 40 ) )
|
105
|
+
expect( reg.width ).to eq 60
|
106
|
+
expect( reg.height ).to eq 80
|
107
|
+
|
108
|
+
expect( size.width ).to eq 30
|
109
|
+
expect( size.height ).to eq 40
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'should work with two values' do
|
113
|
+
reg = GosuEnhanced::Region.new( point, size )
|
114
|
+
reg.inflate!( 40, 50 )
|
115
|
+
expect( reg.width ).to eq 70
|
116
|
+
expect( reg.height ).to eq 90
|
117
|
+
end
|
118
|
+
|
119
|
+
it 'should work with negative values' do
|
120
|
+
reg = GosuEnhanced::Region.new( point, size )
|
121
|
+
reg.inflate!( -20, -35 )
|
122
|
+
expect( reg.width ).to eq 10
|
123
|
+
expect( reg.height ).to eq 5
|
124
|
+
end
|
125
|
+
|
126
|
+
it 'should raise an error with out-of-range values' do
|
127
|
+
reg = GosuEnhanced::Region.new( point, size )
|
128
|
+
expect { reg.inflate!( -50, -20 ) }.to raise_error Exception
|
129
|
+
expect { reg.inflate!( -25, -60 ) }.to raise_error Exception
|
130
|
+
expect { reg.inflate!( -50, -70 ) }.to raise_error Exception
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
describe '#deflate!' do
|
135
|
+
it 'should work with a Size' do
|
136
|
+
reg = GosuEnhanced::Region.new( point, size )
|
137
|
+
reg.deflate!( GosuEnhanced::Size.new( 20, 35 ) )
|
138
|
+
expect( reg.width ).to eq 10
|
139
|
+
expect( reg.height ).to eq 5
|
140
|
+
|
141
|
+
expect( size.width ).to eq 30
|
142
|
+
expect( size.height ).to eq 40
|
143
|
+
end
|
144
|
+
|
145
|
+
it 'should work with two values' do
|
146
|
+
reg = GosuEnhanced::Region.new( point, size )
|
147
|
+
reg.deflate!( 10, 25 )
|
148
|
+
expect( reg.width ).to eq 20
|
149
|
+
expect( reg.height ).to eq 15
|
150
|
+
end
|
151
|
+
|
152
|
+
it 'should raise an error for out-of-range values' do
|
153
|
+
reg = GosuEnhanced::Region.new( point, size )
|
154
|
+
expect { reg.deflate!( 25, 50 ) }.to raise_error Exception
|
155
|
+
expect { reg.deflate!( 60, 35 ) }.to raise_error Exception
|
156
|
+
expect { reg.deflate!( 80, 70 ) }.to raise_error Exception
|
150
157
|
end
|
151
158
|
end
|
152
159
|
end
|
data/spec/region_spec.rb
CHANGED
@@ -3,29 +3,29 @@ require 'spec_helper'
|
|
3
3
|
describe GosuEnhanced::Region do
|
4
4
|
let( :point ) { GosuEnhanced::Point.new( 10, 20 ) }
|
5
5
|
let( :size ) { GosuEnhanced::Size.new( 30, 40 ) }
|
6
|
-
|
6
|
+
|
7
7
|
describe '#initialize' do
|
8
8
|
it 'should work with a Point and a Size' do
|
9
9
|
reg = GosuEnhanced::Region.new( point, size )
|
10
10
|
end
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
describe '#position' do
|
14
14
|
it 'should return the position as a Point' do
|
15
15
|
reg = GosuEnhanced::Region.new( point, size )
|
16
16
|
expect( reg.position ).to eq GosuEnhanced::Point.new( 10, 20 )
|
17
17
|
end
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
describe '#top' do
|
21
|
-
it 'should return the top co-ordinate' do
|
21
|
+
it 'should return the top co-ordinate' do
|
22
22
|
reg = GosuEnhanced::Region.new( point, size )
|
23
23
|
expect( reg.top ).to eq 20
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
27
|
describe '#left' do
|
28
|
-
it 'should return the left co-ordinate' do
|
28
|
+
it 'should return the left co-ordinate' do
|
29
29
|
reg = GosuEnhanced::Region.new( point, size )
|
30
30
|
expect( reg.left ).to eq 10
|
31
31
|
end
|
@@ -37,7 +37,7 @@ describe GosuEnhanced::Region do
|
|
37
37
|
expect( reg.size ).to eq GosuEnhanced::Size.new( 30, 40 )
|
38
38
|
end
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
describe '#contains?' do
|
42
42
|
it 'should work with two co-ordinates' do
|
43
43
|
reg = GosuEnhanced::Region.new( point, size )
|
@@ -55,10 +55,10 @@ describe GosuEnhanced::Region do
|
|
55
55
|
expect( reg.contains?( GosuEnhanced::Point.new( 30, 60 ) ) ).to be false
|
56
56
|
end
|
57
57
|
end
|
58
|
-
|
58
|
+
|
59
59
|
# Unlike the Point and Size, a Region needs a dup override to actually return
|
60
60
|
# a duplicate correctly.
|
61
|
-
|
61
|
+
|
62
62
|
describe '#dup' do
|
63
63
|
it 'should duplicate a region' do
|
64
64
|
reg = GosuEnhanced::Region.new( point, size )
|
@@ -76,7 +76,7 @@ describe GosuEnhanced::Region do
|
|
76
76
|
expect( new_reg.size ).to eq GosuEnhanced::Size.new( 40, 50 )
|
77
77
|
|
78
78
|
expect( reg.position ).to eq GosuEnhanced::Point.new( 10, 20 )
|
79
|
-
expect( reg.size ).to eq GosuEnhanced::Size.new( 30, 40 )
|
79
|
+
expect( reg.size ).to eq GosuEnhanced::Size.new( 30, 40 )
|
80
80
|
end
|
81
81
|
end
|
82
82
|
end
|
data/spec/size_spec.rb
CHANGED
@@ -9,12 +9,12 @@ describe GosuEnhanced::Size do
|
|
9
9
|
end
|
10
10
|
|
11
11
|
it 'should reject negative values' do
|
12
|
-
expect {
|
13
|
-
expect {
|
14
|
-
expect {
|
12
|
+
expect { GosuEnhanced::Size.new( -10, 20 ) }.to raise_error Exception
|
13
|
+
expect { GosuEnhanced::Size.new( 10, -20 ) }.to raise_error Exception
|
14
|
+
expect { GosuEnhanced::Size.new( -10, -20 ) }.to raise_error Exception
|
15
15
|
end
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
describe '#inflate' do
|
19
19
|
it 'should work with another Size' do
|
20
20
|
size = GosuEnhanced::Size.new( 10, 20 )
|
@@ -29,7 +29,7 @@ describe GosuEnhanced::Size do
|
|
29
29
|
expect( esize.width ).to eq 50
|
30
30
|
expect( esize.height ).to eq 70
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
it 'should work with negative values' do
|
34
34
|
size = GosuEnhanced::Size.new( 40, 50 )
|
35
35
|
esize = size.inflate( -30, -20 )
|
@@ -39,9 +39,9 @@ describe GosuEnhanced::Size do
|
|
39
39
|
|
40
40
|
it 'should raise an error with out-of-range values' do
|
41
41
|
size = GosuEnhanced::Size.new( 40, 50 )
|
42
|
-
expect {
|
43
|
-
expect {
|
44
|
-
expect {
|
42
|
+
expect { size.inflate( -50, -20 ) }.to raise_error Exception
|
43
|
+
expect { size.inflate( -30, -60 ) }.to raise_error Exception
|
44
|
+
expect { size.inflate( -50, -70 ) }.to raise_error Exception
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
@@ -59,12 +59,12 @@ describe GosuEnhanced::Size do
|
|
59
59
|
expect( esize.width ).to eq 30
|
60
60
|
expect( esize.height ).to eq 10
|
61
61
|
end
|
62
|
-
|
62
|
+
|
63
63
|
it 'should raise an error for out-of-range values' do
|
64
64
|
size = GosuEnhanced::Size.new( 70, 60 )
|
65
|
-
expect {
|
66
|
-
expect {
|
67
|
-
expect {
|
65
|
+
expect { size.deflate( 80, 50 ) }.to raise_error Exception
|
66
|
+
expect { size.deflate( 60, 70 ) }.to raise_error Exception
|
67
|
+
expect { size.deflate( 80, 70 ) }.to raise_error Exception
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
@@ -82,7 +82,7 @@ describe GosuEnhanced::Size do
|
|
82
82
|
expect( size.width ).to eq 50
|
83
83
|
expect( size.height ).to eq 70
|
84
84
|
end
|
85
|
-
|
85
|
+
|
86
86
|
it 'should work with negative values' do
|
87
87
|
size = GosuEnhanced::Size.new( 40, 50 )
|
88
88
|
size.inflate!( -30, -20 )
|
@@ -112,7 +112,7 @@ describe GosuEnhanced::Size do
|
|
112
112
|
expect( size.width ).to eq 30
|
113
113
|
expect( size.height ).to eq 10
|
114
114
|
end
|
115
|
-
|
115
|
+
|
116
116
|
it 'should raise an error for out-of-range values' do
|
117
117
|
size = GosuEnhanced::Size.new( 70, 60 )
|
118
118
|
expect { size.deflate!( 80, 50 ) }.to raise_error Exception
|
@@ -120,20 +120,24 @@ describe GosuEnhanced::Size do
|
|
120
120
|
expect { size.deflate!( 80, 70 ) }.to raise_error Exception
|
121
121
|
end
|
122
122
|
end
|
123
|
-
|
123
|
+
|
124
124
|
describe '#dup' do
|
125
125
|
it 'should make a copy of the Size' do
|
126
126
|
size = GosuEnhanced::Size.new( 10, 20 )
|
127
127
|
nsize = size.dup
|
128
|
+
|
128
129
|
expect( size.width ).to eq 10
|
129
130
|
expect( size.height ).to eq 20
|
131
|
+
|
130
132
|
expect( nsize.width ).to eq 10
|
131
133
|
expect( nsize.height ).to eq 20
|
132
|
-
|
133
|
-
|
134
|
-
expect(
|
135
|
-
expect( nsize.
|
136
|
-
|
134
|
+
|
135
|
+
nsize.inflate!( 40, 50 )
|
136
|
+
expect( nsize.width ).to eq 50
|
137
|
+
expect( nsize.height ).to eq 70
|
138
|
+
|
139
|
+
expect( size.width ).to eq 10
|
140
|
+
expect( size.height ).to eq 20
|
137
141
|
end
|
138
142
|
end
|
139
143
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gosu_enhanced
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Julian Nicholls
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gosu
|