motion-ui-geometry 0.5.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 +20 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +224 -0
- data/Rakefile +20 -0
- data/lib/motion-ui-geometry.rb +9 -0
- data/lib/motion-ui-geometry/cgaffinetransform.rb +141 -0
- data/lib/motion-ui-geometry/cgpoint.rb +142 -0
- data/lib/motion-ui-geometry/cgrect.rb +246 -0
- data/lib/motion-ui-geometry/cgsize.rb +111 -0
- data/lib/motion-ui-geometry/float.rb +42 -0
- data/lib/motion-ui-geometry/nsdictionary.rb +21 -0
- data/lib/motion-ui-geometry/nsstring.rb +17 -0
- data/lib/motion-ui-geometry/spec_app_delegate.rb +7 -0
- data/lib/motion-ui-geometry/version.rb +7 -0
- data/motion-ui-geometry.gemspec +17 -0
- data/spec/cgaffinetransform_spec.rb +272 -0
- data/spec/cgpoint_spec.rb +210 -0
- data/spec/cgrect_spec.rb +352 -0
- data/spec/cgsize_spec.rb +174 -0
- data/spec/float_spec.rb +107 -0
- data/spec/helpers/no_exception_logging.rb +1 -0
- data/spec/nsdictionary_spec.rb +15 -0
- data/spec/nsstring_spec.rb +42 -0
- metadata +84 -0
data/spec/cgrect_spec.rb
ADDED
@@ -0,0 +1,352 @@
|
|
1
|
+
describe "CGRect" do
|
2
|
+
before do
|
3
|
+
@unit_rect = CGRectMake(0, 0, 1, 1)
|
4
|
+
end
|
5
|
+
|
6
|
+
describe "Operators" do
|
7
|
+
describe '==' do
|
8
|
+
it "returns true for the same rect" do
|
9
|
+
CGRectMake(-1, -2, -3, -4).should == CGRectMake(-1, -2, -3, -4)
|
10
|
+
CGRectMake(1, 2, 3, 4).should == CGRectMake(1, 2, 3, 4)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "returns false for other rects" do
|
14
|
+
rect = CGRectMake(1, 1, 1, 1)
|
15
|
+
rect.should != CGRectMake(0.999, 0.999, 0.999, 0.999)
|
16
|
+
rect.should != CGRectMake(1, 1, 1, 2)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "returns false for other classes" do
|
20
|
+
CGRectZero.should != "abc"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "=~" do
|
25
|
+
it "returns true for a roughly equal rect" do
|
26
|
+
rect = CGRectMake(1, 1, 1, 1)
|
27
|
+
rect.should =~ CGRectMake(0.999999, 0.999999, 0.999999, 0.999999)
|
28
|
+
rect.should =~ CGRectMake(1.000001, 1.000001, 1.000001, 1.000001)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "returns false for a non-equal rect" do
|
32
|
+
CGRectMake(1, 1, 1, 1).should.not =~ CGRectMake(1, 2, 3, 4)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "raises if given no rect to compare" do
|
36
|
+
lambda { CGRectZero =~ "abc" }.should.raise TypeError
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "roughly_equal?(other, epsilon)" do
|
41
|
+
it "returns true for a roughly equal rect" do
|
42
|
+
rect = CGRectMake 1, 1, 1, 1
|
43
|
+
rect.should.roughly_equal CGRectMake(0.99, 0.99, 0.99, 0.99), 0.1
|
44
|
+
rect.should.roughly_equal CGRectMake(1.01, 1.01, 1.01, 1.01), 0.1
|
45
|
+
end
|
46
|
+
|
47
|
+
it "returns false for a non-equal rect" do
|
48
|
+
CGRectMake(1, 1, 1, 1).should.not.roughly_equal CGRectMake(1, 2, 3, 4), 0.1
|
49
|
+
end
|
50
|
+
|
51
|
+
it "raises if given no rect to compare" do
|
52
|
+
lambda { CGRectZero.roughly_equal? "abc" }.should.raise TypeError
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "+" do
|
57
|
+
it "translates if given a point" do
|
58
|
+
(@unit_rect + CGPointMake(3, 4)).should == CGRectMake(3, 4, 1, 1)
|
59
|
+
end
|
60
|
+
|
61
|
+
it "resizes if given a size" do
|
62
|
+
(@unit_rect + CGSizeMake(3, 4)).should == CGRectMake(0, 0, 4, 5)
|
63
|
+
end
|
64
|
+
|
65
|
+
it "raises if given another type" do
|
66
|
+
lambda { @unit_rect + "abc" }.should.raise TypeError
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe "*" do
|
71
|
+
before do
|
72
|
+
@rect = CGRectMake(-1, -1, 1, 1)
|
73
|
+
end
|
74
|
+
it "scales the rect if given a Float" do
|
75
|
+
(@rect * 5.0).should == CGRectMake(-5, -5, 5, 5)
|
76
|
+
(@rect * 0.0).should == CGRectZero
|
77
|
+
(@rect * 1.0).should == @rect
|
78
|
+
end
|
79
|
+
|
80
|
+
it "scales the rect if given a Fixnum" do
|
81
|
+
(@rect * 5).should == CGRectMake(-5, -5, 5, 5)
|
82
|
+
(@rect * 0).should == CGRectZero
|
83
|
+
(@rect * 1).should == @rect
|
84
|
+
end
|
85
|
+
|
86
|
+
it "applies a transform if given" do
|
87
|
+
t = CGAffineTransform.scale(5.0)
|
88
|
+
CGRectMake(-1, -1, 1, 1)
|
89
|
+
(@rect * t).should == (@rect * 5)
|
90
|
+
end
|
91
|
+
|
92
|
+
it "raises if given another type" do
|
93
|
+
lambda { @rect * "asd" }.should.raise TypeError
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
describe "&" do
|
98
|
+
it "intersects rects" do
|
99
|
+
(@unit_rect & CGRectMake(0.5, 0.5, 1, 1)).
|
100
|
+
should == CGRectMake(0.5, 0.5, 0.5, 0.5)
|
101
|
+
end
|
102
|
+
|
103
|
+
it "raises if given no rect to intersect" do
|
104
|
+
lambda { CGRectZero & "abc" }.should.raise TypeError
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
describe "|" do
|
109
|
+
it "unionizes rects" do
|
110
|
+
(@unit_rect | CGRectMake(1, 1, 2, 2)).should == CGRectMake(0, 0, 3, 3)
|
111
|
+
end
|
112
|
+
|
113
|
+
it "raises if given something else" do
|
114
|
+
lambda { @unit_rect | "abc" }.should.raise TypeError
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
describe "initialize(origin, size)" do
|
120
|
+
it "should work if given an origin an a size" do
|
121
|
+
origin = CGPointMake(1, 2)
|
122
|
+
size = CGSizeMake(3, 4)
|
123
|
+
rect = CGRect.new origin, size
|
124
|
+
rect.should == CGRectMake(1, 2, 3, 4)
|
125
|
+
end
|
126
|
+
|
127
|
+
it "raises if given no correct origin" do
|
128
|
+
lambda { CGRect.new "abc", CGSizeZero }.should.raise TypeError
|
129
|
+
end
|
130
|
+
|
131
|
+
it "raises if not given a correct size" do
|
132
|
+
lambda { CGRect.new CGPointZero, "abc"}.should.raise TypeError
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
describe '#round' do
|
137
|
+
it "returns the rect with points rounded to next integer coordinates" do
|
138
|
+
CGRectMake(0.1, 0.1, 0.1, 0.1).round.should == CGRectZero
|
139
|
+
CGRectMake(-0.1, -0.1, -0.1, -0.1).round.should == CGRectZero
|
140
|
+
CGRectMake(12.34, 12.34, 12.34, 12.34).round.should == CGRectMake(12, 12, 12, 12)
|
141
|
+
CGRectMake(34.56, 34.56, 34.56, 34.56).round.should == CGRectMake(35, 35, 35, 35)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
describe '#floor' do
|
146
|
+
it "returns the rect with points rounded down to integer coordinates" do
|
147
|
+
CGRectMake(0.1, 0.1, 0.1, 0.1).floor.should == CGRectZero
|
148
|
+
CGRectMake(-0.1, -0.1, -0.1, -0.1).floor.should == CGRectMake(-1, -1, -1, -1)
|
149
|
+
CGRectMake(12.34, 12.34, 12.34, 12.34).floor.should == CGRectMake(12, 12, 12, 12)
|
150
|
+
CGRectMake(34.56, 34.56, 34.56, 34.56).floor.should == CGRectMake(34, 34, 34, 34)
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
describe "#center" do
|
155
|
+
it "should return the center point" do
|
156
|
+
CGRectMake(0, 1, 2, 3).center.should == CGPointMake(1, 2.5)
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
describe "#top_left" do
|
161
|
+
it "should return the top left corner point" do
|
162
|
+
CGRectMake(0, 1, 2, 3).top_left.should == CGPointMake(0, 1)
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
describe "#bottom_left" do
|
167
|
+
it "should return the bottom left corner point" do
|
168
|
+
CGRectMake(0, 1, 2, 3).bottom_left.should == CGPointMake(0, 4)
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
describe "#bottom_right" do
|
173
|
+
it "should return the top right corner point" do
|
174
|
+
CGRectMake(0, 1, 2, 3).bottom_right.should == CGPointMake(2, 4)
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
describe "#top_right" do
|
179
|
+
it "should return the top right corner point" do
|
180
|
+
CGRectMake(0, 1, 2, 3).top_right.should == CGPointMake(2, 1)
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
# describe "#angle" do
|
185
|
+
# it "should return the top-left bottom-right diagonal's angle" do
|
186
|
+
# end
|
187
|
+
# end
|
188
|
+
|
189
|
+
describe "#divide(amount, edge)" do
|
190
|
+
it "returns two rects divided from left if no edge given" do
|
191
|
+
rect1, rect2 = @unit_rect.divide(0.2)
|
192
|
+
rect1.should == CGRectMake(0, 0, 0.2, 1)
|
193
|
+
rect2.should == CGRectMake(0.2, 0, 0.8, 1)
|
194
|
+
end
|
195
|
+
|
196
|
+
describe "edges" do
|
197
|
+
it "returns correct rects when edge == :right" do
|
198
|
+
rect1, rect2 = @unit_rect.divide(0.2, :right)
|
199
|
+
rect1.should == CGRectMake(0.8, 0, 0.2, 1)
|
200
|
+
rect2.should == CGRectMake(0, 0, 0.8, 1)
|
201
|
+
end
|
202
|
+
|
203
|
+
it "returns correct rects when edge == :left" do
|
204
|
+
rect1, rect2 = @unit_rect.divide(0.2, :left)
|
205
|
+
rect1.should == CGRectMake(0, 0, 0.2, 1)
|
206
|
+
rect2.should == CGRectMake(0.2, 0, 0.8, 1)
|
207
|
+
end
|
208
|
+
|
209
|
+
it "returns correct rects when edge == :top" do
|
210
|
+
rect1, rect2 = @unit_rect.divide(0.2, :top)
|
211
|
+
rect1.should == CGRectMake(0, 0, 1, 0.2)
|
212
|
+
rect2.should == CGRectMake(0, 0.2, 1, 0.8)
|
213
|
+
end
|
214
|
+
|
215
|
+
it "returns correct rects when edge == :bottom" do
|
216
|
+
rect1, rect2 = @unit_rect.divide(0.2, :bottom)
|
217
|
+
rect1.should == CGRectMake(0, 0.8, 1, 0.2)
|
218
|
+
rect2.should == CGRectMake(0, 0, 1, 0.8)
|
219
|
+
end
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
describe "#inset(dx, dy)" do
|
224
|
+
it "returns an inset rect with correct coordinates" do
|
225
|
+
@unit_rect.inset(0.1, 0.2).should == CGRectMake(0.1, 0.2, 0.8, 0.6)
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
describe "#union(rect)" do
|
230
|
+
it "returns the union of both rects" do
|
231
|
+
@unit_rect.union(CGRectMake(1, 1, 2, 2)).
|
232
|
+
should == CGRectMake(0, 0, 3, 3)
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
describe "#intersection(rect)" do
|
237
|
+
it "raises if not given a rect" do
|
238
|
+
lambda { @unit_rect.intersection("abc") }.
|
239
|
+
should.raise(TypeError)
|
240
|
+
end
|
241
|
+
|
242
|
+
it "returns the intersection of both rects" do
|
243
|
+
@unit_rect.intersection(CGRectMake(0.5, 0.5, 1, 1)).
|
244
|
+
should == CGRectMake(0.5, 0.5, 0.5, 0.5)
|
245
|
+
end
|
246
|
+
end
|
247
|
+
|
248
|
+
describe "#contain?([point|rect])" do
|
249
|
+
it "raises if given parameter is no point or rect" do
|
250
|
+
lambda { @unit_rect.contain?("abc") }.should.raise(TypeError)
|
251
|
+
end
|
252
|
+
|
253
|
+
it "returns true if point is inside" do
|
254
|
+
@unit_rect.should.contain(CGPointMake(0.2, 0.6))
|
255
|
+
end
|
256
|
+
|
257
|
+
it "returns false if point is outside" do
|
258
|
+
@unit_rect.should.not.contain(CGPointMake(-1.5, 2))
|
259
|
+
end
|
260
|
+
|
261
|
+
it "returns true if rect is inside" do
|
262
|
+
@unit_rect.should.contain(CGRectMake(0.2, 0, 0.5, 0.8))
|
263
|
+
end
|
264
|
+
|
265
|
+
it "returns false if rect is outside" do
|
266
|
+
@unit_rect.should.not.contain(CGRectMake(1.2, 0, 0.5, 0.8))
|
267
|
+
end
|
268
|
+
|
269
|
+
it "returns false if rect only intersects" do
|
270
|
+
@unit_rect.should.not.contain(CGRectMake(0.2, 0, 0.5, 1.8))
|
271
|
+
end
|
272
|
+
end
|
273
|
+
|
274
|
+
describe "#intersects?(rect)" do
|
275
|
+
it "returns true for intersecting rects" do
|
276
|
+
@unit_rect.should.intersect(CGRectMake(-0.5, -0.5, 1, 1))
|
277
|
+
CGRectMake(-0.9, -0.9, 1, 1).should.intersect(CGRectMake(0.0, 0.0, 1, 1))
|
278
|
+
CGRectMake(0.999, 0.999, 1, 1).should.intersect(CGRectMake(0.0, 0.0, 1, 1))
|
279
|
+
end
|
280
|
+
|
281
|
+
it "returns false for non-intersecting rects" do
|
282
|
+
@unit_rect.should.not.intersect(CGRectMake(-1.5, -1.5, 1, 1))
|
283
|
+
CGRectMake(1, 1, 1, 1).should.not.intersect(CGRectMake(-0.1, -0.1, 1, 1))
|
284
|
+
CGRectMake(-1, -1, 1, 1).should.not.intersect(CGRectMake(0.1, 0.1, 1, 1))
|
285
|
+
CGRectMake(-1, -1, 1, 1).should.not.intersect(CGRectMake(0.1, 0.1, 1, 1))
|
286
|
+
end
|
287
|
+
end
|
288
|
+
|
289
|
+
describe "#empty?" do
|
290
|
+
it "returns true for an empty rect" do
|
291
|
+
CGRectMake(0, 0, 0, 0).should.be.empty
|
292
|
+
CGRectMake(-1, 42, 0, 0).should.be.empty
|
293
|
+
CGRectMake(0, 0, 0.1, 0).should.be.empty
|
294
|
+
CGRectMake(0, 0, 0, 0.1).should.be.empty
|
295
|
+
end
|
296
|
+
|
297
|
+
it "returns false for a non-empty rect" do
|
298
|
+
CGRectMake(-1, 42, 0.0001, 0.1).should.not.be.empty
|
299
|
+
CGRectMake(-1, 42, 3, 0.1).should.not.be.empty
|
300
|
+
end
|
301
|
+
end
|
302
|
+
|
303
|
+
describe "#null?" do
|
304
|
+
it "returns true for the null rect" do
|
305
|
+
CGRectNull.should.be.null
|
306
|
+
end
|
307
|
+
|
308
|
+
it "returns false for other rects" do
|
309
|
+
CGRectZero.should.not.be.null
|
310
|
+
@unit_rect.should.not.be.null
|
311
|
+
end
|
312
|
+
end
|
313
|
+
|
314
|
+
describe "#apply(transform)" do
|
315
|
+
it "returns a new rect with the given transform applied" do
|
316
|
+
r = CGRectMake(1, 1, 1, 1).apply(CGAffineTransform.scale(2.0, 2.0))
|
317
|
+
r.should =~ CGRectMake(2, 2, 2, 2)
|
318
|
+
end
|
319
|
+
end
|
320
|
+
|
321
|
+
# TODO: Fix this
|
322
|
+
#
|
323
|
+
# describe "#infinite?" do
|
324
|
+
# it "returns true for an infinite rect" do
|
325
|
+
# CGRectInfinite.should.be.infinite
|
326
|
+
# end
|
327
|
+
#
|
328
|
+
# it "returns false for a non-infinite rect" do
|
329
|
+
# @unit_rect.should.not.be.infinite
|
330
|
+
# end
|
331
|
+
# end
|
332
|
+
|
333
|
+
describe "#to_dictionary" do
|
334
|
+
it "returns a dictionary" do
|
335
|
+
@unit_rect.to_dictionary.should.is_a(NSDictionary)
|
336
|
+
end
|
337
|
+
end
|
338
|
+
|
339
|
+
describe "#to_value" do
|
340
|
+
it "returns correct NSValue" do
|
341
|
+
value = @unit_rect.to_value
|
342
|
+
value.CGRectValue.should == @unit_rect
|
343
|
+
end
|
344
|
+
end
|
345
|
+
|
346
|
+
describe "#to_s" do
|
347
|
+
it "should return a sensible string" do
|
348
|
+
CGRectMake(1, 2, 3, 4).to_s.should == "{{1, 2}, {3, 4}}"
|
349
|
+
end
|
350
|
+
end
|
351
|
+
|
352
|
+
end
|
data/spec/cgsize_spec.rb
ADDED
@@ -0,0 +1,174 @@
|
|
1
|
+
describe "CGSize" do
|
2
|
+
|
3
|
+
before do
|
4
|
+
@unit_size = CGSizeMake 1, 1
|
5
|
+
end
|
6
|
+
|
7
|
+
describe "operators" do
|
8
|
+
describe '==' do
|
9
|
+
it "returns true for the same size" do
|
10
|
+
CGSizeMake(-12345, -12345).should == CGSizeMake(-12345, -12345)
|
11
|
+
@unit_size.should == @unit_size
|
12
|
+
end
|
13
|
+
|
14
|
+
it "returns false for other sizes" do
|
15
|
+
@unit_size.should != CGSizeMake(0.999, 0.999)
|
16
|
+
@unit_size.should != CGSizeZero
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "=~" do
|
21
|
+
it "should return true for a roughly equal size" do
|
22
|
+
CGSizeMake(0.00001, 0.00001).should =~ CGSizeZero
|
23
|
+
CGSizeMake(-0.00001, -0.00001).should =~ CGSizeZero
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should return false for a non-equal size" do
|
27
|
+
CGSizeMake(0, 1).should.not =~ CGSizeZero
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should return true for a roughly equal point" do
|
31
|
+
CGSizeMake(0.00001).should =~ CGSizeZero
|
32
|
+
CGSizeMake(-0.00001).should =~ CGSizeZero
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should return false for a non-equal point" do
|
36
|
+
CGSizeMake(0, 1).should.not =~ CGSizeZero
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should raise if given another type" do
|
40
|
+
lambda {CGSizeZero =~ "abc"}.should.raise TypeError
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "+" do
|
45
|
+
it "returns the added size vectors as size if given a size" do
|
46
|
+
(@unit_size + @unit_size).should == CGSizeMake(2, 2)
|
47
|
+
(CGSizeMake(-1, -1) + @unit_size).should == CGSizeZero
|
48
|
+
end
|
49
|
+
|
50
|
+
it "returns the added size vectors as size if given a point" do
|
51
|
+
(@unit_size + @unit_size).should == CGSizeMake(2, 2)
|
52
|
+
(CGSizeMake(-1, -1) + @unit_size).should == CGSizeZero
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should raise if given another type" do
|
56
|
+
lambda {CGSizeZero + "abc"}.should.raise TypeError
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
describe "binary -" do
|
62
|
+
it "returns the subtracted size vectors as size if given a size" do
|
63
|
+
(@unit_size - @unit_size).should == CGSizeZero
|
64
|
+
(CGSizeZero - @unit_size).should == CGSizeMake(-1, -1)
|
65
|
+
end
|
66
|
+
|
67
|
+
it "returns the subtracted size vectors as size if given a point" do
|
68
|
+
(@unit_size - CGPointMake(1, 1)).should == CGSizeZero
|
69
|
+
(CGSizeZero - CGPointMake(1, 1)).should == -@unit_size
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should raise if given another type" do
|
73
|
+
lambda {CGSizeZero - "abc"}.should.raise TypeError
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe "unary -" do
|
78
|
+
it "should return the negative size" do
|
79
|
+
(-CGSizeMake(1, 2)).should == CGSizeMake(-1, -2)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe "*" do
|
84
|
+
it "scales the size if given a Float" do
|
85
|
+
(@unit_size * 2.0).should == CGSizeMake(2, 2)
|
86
|
+
end
|
87
|
+
|
88
|
+
it "scales the size if given a Fixnum" do
|
89
|
+
(@unit_size * 2).should == CGSizeMake(2, 2)
|
90
|
+
end
|
91
|
+
|
92
|
+
it "scales the size if given a CGSize" do
|
93
|
+
(@unit_size * @unit_size).should == @unit_size
|
94
|
+
(@unit_size * CGSizeZero).should == CGSizeZero
|
95
|
+
(CGSizeMake(1, 2) * CGSizeMake(-0.5, -0.5)).should == CGSizeMake(-0.5, -1)
|
96
|
+
end
|
97
|
+
|
98
|
+
it "scales the size if given a CGPoint" do
|
99
|
+
(@unit_size * CGPointMake(1, 1)).should == @unit_size
|
100
|
+
(@unit_size * CGPointZero).should == CGSizeZero
|
101
|
+
(CGSizeMake(1, 2) * CGPointMake(-0.5, -0.5)).should == CGSizeMake(-0.5, -1)
|
102
|
+
end
|
103
|
+
|
104
|
+
it "applies a transform if given" do
|
105
|
+
size = CGSizeMake(1, 2) * CGAffineTransform.scale(3, 4)
|
106
|
+
size.should == CGSizeMake(3, 8)
|
107
|
+
end
|
108
|
+
|
109
|
+
it "raises if given another type" do
|
110
|
+
lambda { CGSizeZero * "abc" }.should.raise TypeError
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
describe '#round' do
|
116
|
+
it "returns the size rounded to next integer coordinates" do
|
117
|
+
CGSizeMake(0.1, 0.1).round.should == CGSizeZero
|
118
|
+
CGSizeMake(-0.1, -0.1).round.should == CGSizeZero
|
119
|
+
CGSizeMake(12.34, 12.34).round.should == CGSizeMake(12, 12)
|
120
|
+
CGSizeMake(34.56, 34.56).round.should == CGSizeMake(35, 35)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
describe '#floor' do
|
125
|
+
it "returns the size rounded down to integer coordinates" do
|
126
|
+
CGSizeMake(0.1, 0.1).floor.should == CGSizeZero
|
127
|
+
CGSizeMake(-0.1, -0.1).floor.should == CGSizeMake(-1, -1)
|
128
|
+
CGSizeMake(12.34, 12.34).floor.should == CGSizeMake(12, 12)
|
129
|
+
CGSizeMake(34.56, 34.56).floor.should == CGSizeMake(34, 34)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
describe "#apply(transform)" do
|
134
|
+
it "returns a new size with the given transform applied" do
|
135
|
+
s = CGSizeMake(1, 2).apply(CGAffineTransform.scale(2.0, 2.0))
|
136
|
+
s.should =~ CGSizeMake(2, 4)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
# describe "#angle" do
|
141
|
+
# it "should work"
|
142
|
+
# end
|
143
|
+
|
144
|
+
|
145
|
+
describe "conversion methods" do
|
146
|
+
describe "#to_dictionary" do
|
147
|
+
it "returns a dictionary" do
|
148
|
+
@unit_size.to_dictionary.should.is_a(NSDictionary)
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
describe "#to_value" do
|
153
|
+
it "returns correct NSValue" do
|
154
|
+
value = @unit_size.to_value
|
155
|
+
value.CGSizeValue.should == @unit_size
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
describe "#to_rect" do
|
160
|
+
it "returns a CGRect" do
|
161
|
+
rect = CGSizeMake(1, 2).to_rect
|
162
|
+
rect.should.is_a(CGRect)
|
163
|
+
rect.should == CGRectMake(0, 0, 1, 2)
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
describe "#to_s" do
|
168
|
+
it "should return a sensible string" do
|
169
|
+
CGSizeMake(23, 42).to_s.should == "{23, 42}"
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
end
|