geomotion 0.5 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/Gemfile.lock +16 -0
- data/README.md +103 -5
- data/lib/geomotion/cg_point.rb +42 -4
- data/lib/geomotion/cg_rect.rb +81 -17
- data/lib/geomotion/cg_size.rb +20 -0
- data/lib/geomotion/version.rb +1 -1
- data/spec/cg_point_spec.rb +53 -0
- data/spec/cg_rect_spec.rb +211 -8
- data/spec/cg_size_spec.rb +18 -0
- metadata +5 -3
data/.gitignore
CHANGED
data/Gemfile.lock
ADDED
data/README.md
CHANGED
@@ -20,25 +20,47 @@ rect_zero = CGRect.empty
|
|
20
20
|
rect_zero.empty?
|
21
21
|
=> true
|
22
22
|
|
23
|
+
# to get the center of the frame, relative to the origin or in absolute coordinates
|
23
24
|
rect.center
|
24
|
-
=> CGPoint(25, 10) # center
|
25
|
+
=> CGPoint(25, 10) # center relative to bounds
|
25
26
|
rect.center(true)
|
26
|
-
=> CGPoint(35, 110) # center
|
27
|
+
=> CGPoint(35, 110) # center relative to frame
|
28
|
+
|
29
|
+
# Other points in the rect can be returned as well, and the same
|
30
|
+
# relative/absolute return values are supported (defaults to relative)
|
31
|
+
|
32
|
+
top_left top_center
|
33
|
+
| |
|
34
|
+
o--o--o top_right
|
35
|
+
| |
|
36
|
+
center_left o x o center_right
|
37
|
+
| |
|
38
|
+
o--o--o bottom_right
|
39
|
+
| |
|
40
|
+
bottom_left bottom_center
|
27
41
|
|
28
42
|
# Operator Overloading
|
29
43
|
-rect
|
30
44
|
=> CGRect(-10, -100, -50, -20)
|
31
45
|
|
46
|
+
# union of rects
|
32
47
|
rect + CGRect.make(x: 9, y: 99, width: 10, height: 10)
|
33
|
-
=> CGRect(9, 99,
|
48
|
+
=> rect.union_with(CGRect.make(x: 9, y: 99, width: 10, height: 10))
|
49
|
+
=> CGRect(9, 99, 50, 20)
|
34
50
|
|
51
|
+
# increases the size, but keeps the origin
|
35
52
|
rect + CGSize.make(width: 11, height: 1)
|
36
|
-
=> CGRect(10, 100, 61, 21)
|
53
|
+
=> CGRect(10, 100, 61, 21)
|
54
|
+
# not the same as `grow`, which grows the rect in all directions
|
37
55
|
|
56
|
+
# moves the rect
|
38
57
|
rect + CGPoint.make(x: 10, y: 10)
|
58
|
+
=> rect.offset(CGPoint.make(x: 10, y: 10))
|
39
59
|
=> CGRect(20, 110, 50, 20)
|
40
60
|
|
61
|
+
# moves the rect
|
41
62
|
rect + UIOffsetMake(10, 10)
|
63
|
+
=> rect.offset(UIOffsetMake(10, 10))
|
42
64
|
=> CGRect(20, 110, 50, 20)
|
43
65
|
|
44
66
|
a_point + a_size
|
@@ -98,6 +120,75 @@ CGRect.layout(rect, above: rect2, right_of: rect3, margins: [0, 0, 10, 15])
|
|
98
120
|
|
99
121
|
```
|
100
122
|
|
123
|
+
## *Relative* vs *Absolute*
|
124
|
+
|
125
|
+
When you are positioning frames, you'll be doing so in one of two ways:
|
126
|
+
|
127
|
+
1. Two frames relative *to each other*, within a common parent frame
|
128
|
+
2. A frame being added *as a child* of another frame
|
129
|
+
|
130
|
+
*(generally speaking)*
|
131
|
+
|
132
|
+
geomotion is optimized for both cases, but the arsenal of methods is different.
|
133
|
+
|
134
|
+
###### frames relative to each other
|
135
|
+
|
136
|
+
Any of the location methods (`up, down, left, right, beside, before, above, below`)
|
137
|
+
will return a frame that is in the same coordinate system of the receiver, and
|
138
|
+
this behavior cannot be changed.
|
139
|
+
|
140
|
+
```ruby
|
141
|
+
frame = CGRect.new(x: 10, y: 10, width:10, height: 10)
|
142
|
+
frame.beside
|
143
|
+
# => [[20, 10], [10, 10]]
|
144
|
+
|
145
|
+
frame.right(30).down(5).taller(100)
|
146
|
+
# => [[10+30, 10+5], [10, 10+100]]
|
147
|
+
# aka
|
148
|
+
# => [[40, 15], [10, 110]]
|
149
|
+
```
|
150
|
+
|
151
|
+
Any methods that include the *x* or *y* variable in their name will be absolute.
|
152
|
+
|
153
|
+
```ruby
|
154
|
+
frame.x
|
155
|
+
frame.min_x
|
156
|
+
frame.max_x
|
157
|
+
frame.mid_x
|
158
|
+
frame.y
|
159
|
+
frame.min_y
|
160
|
+
frame.max_y
|
161
|
+
frame.mid_y
|
162
|
+
```
|
163
|
+
|
164
|
+
###### positions relative to the frame's origin
|
165
|
+
|
166
|
+
Any of the position methods that do *NOT* include the *x* or *y* variable will
|
167
|
+
*ignore* the *x* and *y* values unless explicitly told to use absolute
|
168
|
+
coordinates.
|
169
|
+
|
170
|
+
*Note:* These methods will "normalize" the width and height, so even if
|
171
|
+
the width or height is negative, these methods will always return positive
|
172
|
+
numbers. If you specify absolute coordinates, the values might be negative, but
|
173
|
+
they will also be sorted (x == min, min < mid, mid < max, x + width == max).
|
174
|
+
|
175
|
+
```ruby
|
176
|
+
frame = CGRect.new(x: 10, y: 10, width:10, height: 10)
|
177
|
+
frame.top_left # => [0, 0]
|
178
|
+
frame.top_center # => [5, 0]
|
179
|
+
frame.bottom_right # => [10, 10]
|
180
|
+
|
181
|
+
# use absolute coordinates
|
182
|
+
frame.top_left(true) # => [10, 10]
|
183
|
+
frame.top_center(true) # => [15, 10]
|
184
|
+
frame.bottom_right(true) # => [20, 20]
|
185
|
+
|
186
|
+
# negative widths and heights are "corrected" when using absolute coordinates
|
187
|
+
frame = CGRect.new(x: 20, y: 20, width:-10, height: -10)
|
188
|
+
frame.top_center(true) # => [15, 10]
|
189
|
+
frame.bottom_right(true) # => [20, 20]
|
190
|
+
```
|
191
|
+
|
101
192
|
### CGSize
|
102
193
|
|
103
194
|
```ruby
|
@@ -131,6 +222,13 @@ size.rect_at_point CGPoint.make(x: 10, y: 30)
|
|
131
222
|
# Initializers
|
132
223
|
point = CGPoint.make(x: 10, y: 100)
|
133
224
|
|
225
|
+
# Return a modified copy
|
226
|
+
point.up(50).left(5)
|
227
|
+
=> CGPoint(5, 50)
|
228
|
+
# original is not modified, a new point is returned
|
229
|
+
point.down(50).right(5)
|
230
|
+
=> CGPoint(15, 150)
|
231
|
+
|
134
232
|
# Operator Overloading
|
135
233
|
-point
|
136
234
|
=> CGPoint(-10, -100)
|
@@ -159,4 +257,4 @@ point.inside? CGRect.make(x: 0, y: 0, width: 20, height: 110)
|
|
159
257
|
|
160
258
|
## Forking
|
161
259
|
|
162
|
-
If you have cool/better ideas, pull-request away!
|
260
|
+
If you have cool/better ideas, pull-request away!
|
data/lib/geomotion/cg_point.rb
CHANGED
@@ -12,6 +12,32 @@ class CGPoint
|
|
12
12
|
CGRect.new([self.x, self.y], size)
|
13
13
|
end
|
14
14
|
|
15
|
+
# modified points
|
16
|
+
def left(dist = 0)
|
17
|
+
CGPoint.new(self.x - dist, self.y)
|
18
|
+
end
|
19
|
+
|
20
|
+
def right(dist = 0)
|
21
|
+
CGPoint.new(self.x + dist, self.y)
|
22
|
+
end
|
23
|
+
|
24
|
+
def up(dist = 0)
|
25
|
+
CGPoint.new(self.x, self.y - dist)
|
26
|
+
end
|
27
|
+
|
28
|
+
def down(dist = 0)
|
29
|
+
CGPoint.new(self.x, self.y + dist)
|
30
|
+
end
|
31
|
+
|
32
|
+
def round
|
33
|
+
CGPoint.new(self.x.round, self.y.round)
|
34
|
+
end
|
35
|
+
|
36
|
+
def inside?(rect)
|
37
|
+
CGRectContainsPoint(rect, self)
|
38
|
+
end
|
39
|
+
|
40
|
+
# operator
|
15
41
|
def +(other)
|
16
42
|
case other
|
17
43
|
when CGSize
|
@@ -21,12 +47,24 @@ class CGPoint
|
|
21
47
|
end
|
22
48
|
end
|
23
49
|
|
24
|
-
def
|
25
|
-
|
50
|
+
def *(scale)
|
51
|
+
case scale
|
52
|
+
when Numeric
|
53
|
+
return CGPoint.new(self.x * scale, self.y * scale)
|
54
|
+
else
|
55
|
+
super
|
56
|
+
end
|
26
57
|
end
|
27
58
|
|
28
|
-
|
29
|
-
|
59
|
+
# it is tempting to define this as self * (1.0/scale) but floating point
|
60
|
+
# errors result in too many errors
|
61
|
+
def /(scale)
|
62
|
+
case scale
|
63
|
+
when Numeric
|
64
|
+
return CGPoint.new(self.x / scale, self.y / scale)
|
65
|
+
else
|
66
|
+
super
|
67
|
+
end
|
30
68
|
end
|
31
69
|
|
32
70
|
def ==(point)
|
data/lib/geomotion/cg_rect.rb
CHANGED
@@ -77,6 +77,10 @@ class CGRect
|
|
77
77
|
CGRectGetMinX(self)
|
78
78
|
end
|
79
79
|
|
80
|
+
def mid_x
|
81
|
+
CGRectGetMidX(self)
|
82
|
+
end
|
83
|
+
|
80
84
|
def max_x
|
81
85
|
CGRectGetMaxX(self)
|
82
86
|
end
|
@@ -85,6 +89,10 @@ class CGRect
|
|
85
89
|
CGRectGetMinY(self)
|
86
90
|
end
|
87
91
|
|
92
|
+
def mid_y
|
93
|
+
CGRectGetMidY(self)
|
94
|
+
end
|
95
|
+
|
88
96
|
def max_y
|
89
97
|
CGRectGetMaxY(self)
|
90
98
|
end
|
@@ -196,27 +204,51 @@ class CGRect
|
|
196
204
|
CGRect.new([self.x + self.width + margin, self.y], [width, self.height])
|
197
205
|
end
|
198
206
|
|
199
|
-
#
|
207
|
+
# positions
|
208
|
+
private
|
209
|
+
def cgrect_offset(absolute)
|
210
|
+
if absolute
|
211
|
+
CGPoint.new(self.min_x, self.min_y)
|
212
|
+
else
|
213
|
+
CGPoint.new(0, 0)
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
public
|
200
218
|
def center(absolute = false)
|
201
|
-
|
202
|
-
|
203
|
-
|
219
|
+
cgrect_offset(absolute) + CGPoint.new(self.width / 2, self.height / 2)
|
220
|
+
end
|
221
|
+
|
222
|
+
def top_left(absolute = false)
|
223
|
+
cgrect_offset(absolute) + CGPoint.new(0, 0)
|
224
|
+
end
|
225
|
+
|
226
|
+
def top_center(absolute = false)
|
227
|
+
cgrect_offset(absolute) + CGPoint.new(self.width / 2, 0)
|
228
|
+
end
|
229
|
+
|
230
|
+
def top_right(absolute = false)
|
231
|
+
cgrect_offset(absolute) + CGPoint.new(self.width, 0)
|
232
|
+
end
|
233
|
+
|
234
|
+
def center_right(absolute = false)
|
235
|
+
cgrect_offset(absolute) + CGPoint.new(self.width, self.height / 2)
|
204
236
|
end
|
205
237
|
|
206
|
-
def
|
207
|
-
CGPoint.new(
|
238
|
+
def bottom_right(absolute = false)
|
239
|
+
cgrect_offset(absolute) + CGPoint.new(self.width, self.height)
|
208
240
|
end
|
209
241
|
|
210
|
-
def
|
211
|
-
CGPoint.new(
|
242
|
+
def bottom_center(absolute = false)
|
243
|
+
cgrect_offset(absolute) + CGPoint.new(self.width / 2, self.height)
|
212
244
|
end
|
213
245
|
|
214
|
-
def bottom_left
|
215
|
-
CGPoint.new(
|
246
|
+
def bottom_left(absolute = false)
|
247
|
+
cgrect_offset(absolute) + CGPoint.new(0, self.height)
|
216
248
|
end
|
217
249
|
|
218
|
-
def
|
219
|
-
CGPoint.new(
|
250
|
+
def center_left(absolute = false)
|
251
|
+
cgrect_offset(absolute) + CGPoint.new(0, self.height / 2)
|
220
252
|
end
|
221
253
|
|
222
254
|
# others
|
@@ -235,11 +267,31 @@ class CGRect
|
|
235
267
|
when CGSize
|
236
268
|
return CGRect.new([self.x, self.y], [self.width + other.width, self.height + other.height])
|
237
269
|
when CGPoint
|
238
|
-
return
|
270
|
+
return self.offset(other.x, other.y)
|
239
271
|
when UIOffset
|
240
|
-
|
272
|
+
return self.offset(other.horizontal, other.vertical)
|
241
273
|
when UIEdgeInsets
|
242
|
-
|
274
|
+
return self.inset(other)
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
278
|
+
def *(scale)
|
279
|
+
case scale
|
280
|
+
when Numeric
|
281
|
+
return CGRect.new(self.origin, self.size * scale)
|
282
|
+
else
|
283
|
+
super
|
284
|
+
end
|
285
|
+
end
|
286
|
+
|
287
|
+
# it is tempting to define this as self * (1.0/scale) but floating point
|
288
|
+
# errors result in too many errors
|
289
|
+
def /(scale)
|
290
|
+
case scale
|
291
|
+
when Numeric
|
292
|
+
return CGRect.new(self.origin, self.size / scale)
|
293
|
+
else
|
294
|
+
super
|
243
295
|
end
|
244
296
|
end
|
245
297
|
|
@@ -251,18 +303,30 @@ class CGRect
|
|
251
303
|
CGRectUnion(self, rect)
|
252
304
|
end
|
253
305
|
|
306
|
+
def inset(insets)
|
307
|
+
UIEdgeInsetsInsetRect(self, insets)
|
308
|
+
end
|
309
|
+
|
310
|
+
def offset(point_or_x, y=nil)
|
311
|
+
if y
|
312
|
+
CGRectOffset(self, point_or_x, y)
|
313
|
+
else
|
314
|
+
CGRectOffset(self, point_or_x[0], point_or_x[1])
|
315
|
+
end
|
316
|
+
end
|
317
|
+
|
254
318
|
def grow(size)
|
255
319
|
if size.is_a? Numeric
|
256
320
|
size = CGSize.new(size, size)
|
257
321
|
end
|
258
|
-
CGRectInset(self, -size
|
322
|
+
CGRectInset(self, -size[0], -size[1])
|
259
323
|
end
|
260
324
|
|
261
325
|
def shrink(size)
|
262
326
|
if size.is_a? Numeric
|
263
327
|
size = CGSize.new(size, size)
|
264
328
|
end
|
265
|
-
CGRectInset(self, size
|
329
|
+
CGRectInset(self, size[0], size[1])
|
266
330
|
end
|
267
331
|
|
268
332
|
def empty?
|
data/lib/geomotion/cg_size.rb
CHANGED
@@ -37,6 +37,26 @@ class CGSize
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
+
def *(scale)
|
41
|
+
case scale
|
42
|
+
when Numeric
|
43
|
+
return CGSize.new(self.width * scale, self.height * scale)
|
44
|
+
else
|
45
|
+
super
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# it is tempting to define this as self * (1.0/scale) but floating point
|
50
|
+
# errors result in too many miscalculations
|
51
|
+
def /(scale)
|
52
|
+
case scale
|
53
|
+
when Numeric
|
54
|
+
return CGSize.new(self.width / scale, self.height / scale)
|
55
|
+
else
|
56
|
+
super
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
40
60
|
def infinite?
|
41
61
|
infinity = CGRect.null[0][0] # null rects are rects with infinite width & height
|
42
62
|
self.width == infinity or self.height == infinity
|
data/lib/geomotion/version.rb
CHANGED
data/spec/cg_point_spec.rb
CHANGED
@@ -20,6 +20,41 @@ describe "CGPoint" do
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
+
describe "#up" do
|
24
|
+
it "should work" do
|
25
|
+
point = CGPointMake(1, 1).up(1)
|
26
|
+
CGPointEqualToPoint(point, CGPointMake(1, 0)).should == true
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "#down" do
|
31
|
+
it "should work" do
|
32
|
+
point = CGPointMake(1, 1).down(1)
|
33
|
+
CGPointEqualToPoint(point, CGPointMake(1, 2)).should == true
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "#left" do
|
38
|
+
it "should work" do
|
39
|
+
point = CGPointMake(1, 1).left(1)
|
40
|
+
CGPointEqualToPoint(point, CGPointMake(0, 1)).should == true
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "#right" do
|
45
|
+
it "should work" do
|
46
|
+
point = CGPointMake(1, 1).right(1)
|
47
|
+
CGPointEqualToPoint(point, CGPointMake(2, 1)).should == true
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "#chaining up().down().left().right()" do
|
52
|
+
it "should work" do
|
53
|
+
point = CGPointMake(1, 1).up(2).down(1).left(2).right(1)
|
54
|
+
CGPointEqualToPoint(point, CGPointMake(0, 0)).should == true
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
23
58
|
describe "#+" do
|
24
59
|
it "should work with CGSize" do
|
25
60
|
size = CGSizeMake(20, 30)
|
@@ -32,6 +67,24 @@ describe "CGPoint" do
|
|
32
67
|
end
|
33
68
|
end
|
34
69
|
|
70
|
+
describe "#*" do
|
71
|
+
it "should work with Numeric" do
|
72
|
+
point = CGPointMake(12, 24)
|
73
|
+
bigger = point * 3
|
74
|
+
bigger.x.should == 36
|
75
|
+
bigger.y.should == 72
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe "#/" do
|
80
|
+
it "should work with Numeric" do
|
81
|
+
point = CGPointMake(12, 24)
|
82
|
+
smaller = point / 3
|
83
|
+
smaller.x.should == 4
|
84
|
+
smaller.y.should == 8
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
35
88
|
describe "#- (unary)" do
|
36
89
|
it "should work" do
|
37
90
|
point = CGPoint.make(x: 100, y: 200)
|
data/spec/cg_rect_spec.rb
CHANGED
@@ -142,6 +142,11 @@ describe "CGRect" do
|
|
142
142
|
it "returns value when no args" do
|
143
143
|
@rect.x.should == 10
|
144
144
|
end
|
145
|
+
it "returns min_x when width is negative" do
|
146
|
+
rect = CGRect.make(x: 110, y: 10, width: -100, height: 100)
|
147
|
+
rect.x.should == 10
|
148
|
+
rect.origin.x.should == 110
|
149
|
+
end
|
145
150
|
|
146
151
|
it "returns copy when has args" do
|
147
152
|
rect = @rect.x(20)
|
@@ -162,6 +167,11 @@ describe "CGRect" do
|
|
162
167
|
it "returns value when no args" do
|
163
168
|
@rect.y.should == 100
|
164
169
|
end
|
170
|
+
it "returns min_y when height is negative" do
|
171
|
+
rect = CGRect.make(x: 10, y: 110, width: 100, height: -100)
|
172
|
+
rect.y.should == 10
|
173
|
+
rect.origin.y.should == 110
|
174
|
+
end
|
165
175
|
|
166
176
|
it "returns copy when has args" do
|
167
177
|
rect = @rect.y(20)
|
@@ -182,7 +192,10 @@ describe "CGRect" do
|
|
182
192
|
it "returns value when no args" do
|
183
193
|
@rect.width.should == 50
|
184
194
|
end
|
185
|
-
|
195
|
+
it "always returns positive width" do
|
196
|
+
rect = CGRect.make(x: 10, y: 110, width: -100, height: -100)
|
197
|
+
rect.width.should == 100
|
198
|
+
end
|
186
199
|
it "returns copy when has args" do
|
187
200
|
rect = @rect.width(20)
|
188
201
|
rect.is_a?(CGRect).should == true
|
@@ -202,7 +215,10 @@ describe "CGRect" do
|
|
202
215
|
it "returns value when no args" do
|
203
216
|
@rect.height.should == 20
|
204
217
|
end
|
205
|
-
|
218
|
+
it "always returns positive height" do
|
219
|
+
rect = CGRect.make(x: 10, y: 110, width: -100, height: -100)
|
220
|
+
rect.height.should == 100
|
221
|
+
end
|
206
222
|
it "returns copy when has args" do
|
207
223
|
rect = @rect.height(50)
|
208
224
|
rect.is_a?(CGRect).should == true
|
@@ -218,6 +234,51 @@ describe "CGRect" do
|
|
218
234
|
end
|
219
235
|
end
|
220
236
|
|
237
|
+
describe "#min_x, #mid_x, #max_x, #min_y, #mid_y, #max_y" do
|
238
|
+
before do
|
239
|
+
@min_rect = CGRect.make(x: 10, y: 10, width: 100, height: 100)
|
240
|
+
@min_rect_negative = CGRect.make(x: 110, y: 110, width: -100, height: -100)
|
241
|
+
end
|
242
|
+
|
243
|
+
it "#min_x works" do
|
244
|
+
@min_rect.min_x.should == 10
|
245
|
+
end
|
246
|
+
it "#mid_x works" do
|
247
|
+
@min_rect.mid_x.should == 60
|
248
|
+
end
|
249
|
+
it "#max_x works" do
|
250
|
+
@min_rect.max_x.should == 110
|
251
|
+
end
|
252
|
+
it "#min_x works with negative width" do
|
253
|
+
@min_rect_negative.min_x.should == 10
|
254
|
+
end
|
255
|
+
it "#mid_x works with negative width" do
|
256
|
+
@min_rect_negative.mid_x.should == 60
|
257
|
+
end
|
258
|
+
it "#max_x works with negative width" do
|
259
|
+
@min_rect_negative.max_x.should == 110
|
260
|
+
end
|
261
|
+
|
262
|
+
it "#min_y works" do
|
263
|
+
@min_rect.min_y.should == 10
|
264
|
+
end
|
265
|
+
it "#mid_y works" do
|
266
|
+
@min_rect.mid_y.should == 60
|
267
|
+
end
|
268
|
+
it "#max_y works" do
|
269
|
+
@min_rect.max_y.should == 110
|
270
|
+
end
|
271
|
+
it "#min_y works with negative height" do
|
272
|
+
@min_rect_negative.min_y.should == 10
|
273
|
+
end
|
274
|
+
it "#mid_y works with negative height" do
|
275
|
+
@min_rect_negative.mid_y.should == 60
|
276
|
+
end
|
277
|
+
it "#max_y works with negative height" do
|
278
|
+
@min_rect_negative.max_y.should == 110
|
279
|
+
end
|
280
|
+
end
|
281
|
+
|
221
282
|
describe "#left" do
|
222
283
|
it "works" do
|
223
284
|
rect = CGRect.empty
|
@@ -333,16 +394,30 @@ describe "CGRect" do
|
|
333
394
|
rect = CGRect.make(x: 10, y: 20, width: 100, height: 200)
|
334
395
|
point = rect.top_left
|
335
396
|
point.is_a?(CGPoint).should == true
|
397
|
+
CGPointEqualToPoint(point, CGPointMake(0, 0)).should == true
|
398
|
+
end
|
399
|
+
|
400
|
+
it "works as relative" do
|
401
|
+
rect = CGRect.make(x: 10, y: 20, width: 100, height: 200)
|
402
|
+
point = rect.top_left(true)
|
403
|
+
point.is_a?(CGPoint).should == true
|
336
404
|
CGPointEqualToPoint(point, CGPointMake(10, 20)).should == true
|
337
405
|
end
|
338
406
|
end
|
339
407
|
|
340
|
-
describe "#
|
408
|
+
describe "#top_center" do
|
341
409
|
it "works" do
|
342
410
|
rect = CGRect.make(x: 10, y: 20, width: 100, height: 200)
|
343
|
-
point = rect.
|
411
|
+
point = rect.top_center
|
344
412
|
point.is_a?(CGPoint).should == true
|
345
|
-
CGPointEqualToPoint(point, CGPointMake(
|
413
|
+
CGPointEqualToPoint(point, CGPointMake(50, 0)).should == true
|
414
|
+
end
|
415
|
+
|
416
|
+
it "works as relative" do
|
417
|
+
rect = CGRect.make(x: 10, y: 20, width: 100, height: 200)
|
418
|
+
point = rect.top_center(true)
|
419
|
+
point.is_a?(CGPoint).should == true
|
420
|
+
CGPointEqualToPoint(point, CGPointMake(60, 20)).should == true
|
346
421
|
end
|
347
422
|
end
|
348
423
|
|
@@ -351,19 +426,97 @@ describe "CGRect" do
|
|
351
426
|
rect = CGRect.make(x: 10, y: 20, width: 100, height: 200)
|
352
427
|
point = rect.top_right
|
353
428
|
point.is_a?(CGPoint).should == true
|
429
|
+
CGPointEqualToPoint(point, CGPointMake(100, 0)).should == true
|
430
|
+
end
|
431
|
+
|
432
|
+
it "works as relative" do
|
433
|
+
rect = CGRect.make(x: 10, y: 20, width: 100, height: 200)
|
434
|
+
point = rect.top_right(true)
|
435
|
+
point.is_a?(CGPoint).should == true
|
354
436
|
CGPointEqualToPoint(point, CGPointMake(110, 20)).should == true
|
355
437
|
end
|
356
438
|
end
|
357
439
|
|
440
|
+
describe "#center_right" do
|
441
|
+
it "works" do
|
442
|
+
rect = CGRect.make(x: 10, y: 20, width: 100, height: 200)
|
443
|
+
point = rect.center_right
|
444
|
+
point.is_a?(CGPoint).should == true
|
445
|
+
CGPointEqualToPoint(point, CGPointMake(100, 100)).should == true
|
446
|
+
end
|
447
|
+
|
448
|
+
it "works as relative" do
|
449
|
+
rect = CGRect.make(x: 10, y: 20, width: 100, height: 200)
|
450
|
+
point = rect.center_right(true)
|
451
|
+
point.is_a?(CGPoint).should == true
|
452
|
+
CGPointEqualToPoint(point, CGPointMake(110, 120)).should == true
|
453
|
+
end
|
454
|
+
end
|
455
|
+
|
358
456
|
describe "#bottom_right" do
|
359
457
|
it "works" do
|
360
458
|
rect = CGRect.make(x: 10, y: 20, width: 100, height: 200)
|
361
459
|
point = rect.bottom_right
|
362
460
|
point.is_a?(CGPoint).should == true
|
461
|
+
CGPointEqualToPoint(point, CGPointMake(100, 200)).should == true
|
462
|
+
end
|
463
|
+
|
464
|
+
it "works as relative" do
|
465
|
+
rect = CGRect.make(x: 10, y: 20, width: 100, height: 200)
|
466
|
+
point = rect.bottom_right(true)
|
467
|
+
point.is_a?(CGPoint).should == true
|
363
468
|
CGPointEqualToPoint(point, CGPointMake(110, 220)).should == true
|
364
469
|
end
|
365
470
|
end
|
366
471
|
|
472
|
+
describe "#bottom_center" do
|
473
|
+
it "works" do
|
474
|
+
rect = CGRect.make(x: 10, y: 20, width: 100, height: 200)
|
475
|
+
point = rect.bottom_center
|
476
|
+
point.is_a?(CGPoint).should == true
|
477
|
+
CGPointEqualToPoint(point, CGPointMake(50, 200)).should == true
|
478
|
+
end
|
479
|
+
|
480
|
+
it "works as relative" do
|
481
|
+
rect = CGRect.make(x: 10, y: 20, width: 100, height: 200)
|
482
|
+
point = rect.bottom_center(true)
|
483
|
+
point.is_a?(CGPoint).should == true
|
484
|
+
CGPointEqualToPoint(point, CGPointMake(60, 220)).should == true
|
485
|
+
end
|
486
|
+
end
|
487
|
+
|
488
|
+
describe "#bottom_left" do
|
489
|
+
it "works" do
|
490
|
+
rect = CGRect.make(x: 10, y: 20, width: 100, height: 200)
|
491
|
+
point = rect.bottom_left
|
492
|
+
point.is_a?(CGPoint).should == true
|
493
|
+
CGPointEqualToPoint(point, CGPointMake(0, 200)).should == true
|
494
|
+
end
|
495
|
+
|
496
|
+
it "works as relative" do
|
497
|
+
rect = CGRect.make(x: 10, y: 20, width: 100, height: 200)
|
498
|
+
point = rect.bottom_left(true)
|
499
|
+
point.is_a?(CGPoint).should == true
|
500
|
+
CGPointEqualToPoint(point, CGPointMake(10, 220)).should == true
|
501
|
+
end
|
502
|
+
end
|
503
|
+
|
504
|
+
describe "#center_left" do
|
505
|
+
it "works" do
|
506
|
+
rect = CGRect.make(x: 10, y: 20, width: 100, height: 200)
|
507
|
+
point = rect.center_left
|
508
|
+
point.is_a?(CGPoint).should == true
|
509
|
+
CGPointEqualToPoint(point, CGPointMake(0, 100)).should == true
|
510
|
+
end
|
511
|
+
|
512
|
+
it "works as relative" do
|
513
|
+
rect = CGRect.make(x: 10, y: 20, width: 100, height: 200)
|
514
|
+
point = rect.center_left(true)
|
515
|
+
point.is_a?(CGPoint).should == true
|
516
|
+
CGPointEqualToPoint(point, CGPointMake(10, 120)).should == true
|
517
|
+
end
|
518
|
+
end
|
519
|
+
|
367
520
|
describe "#center" do
|
368
521
|
it "works" do
|
369
522
|
point = CGRect.make(width: 100, height: 100).center
|
@@ -443,12 +596,57 @@ describe "CGRect" do
|
|
443
596
|
end
|
444
597
|
|
445
598
|
it "works with UIEdgeInsets" do
|
446
|
-
|
447
|
-
rect = (@rect +
|
599
|
+
insets = UIEdgeInsetsMake(10, 10, 10, 5)
|
600
|
+
rect = (@rect + insets)
|
448
601
|
CGRectEqualToRect(rect, CGRectMake(20, 110, 35, 0)).should == true
|
449
602
|
end
|
450
603
|
end
|
451
604
|
|
605
|
+
describe "offset" do
|
606
|
+
it "works with x, y" do
|
607
|
+
rect = @rect.offset(50, 20)
|
608
|
+
CGRectEqualToRect(rect, CGRectMake(60, 120, 50, 20)).should == true
|
609
|
+
end
|
610
|
+
|
611
|
+
it "works with CGPoint" do
|
612
|
+
point = CGPointMake(50, 20)
|
613
|
+
rect = @rect.offset(point)
|
614
|
+
CGRectEqualToRect(rect, CGRectMake(60, 120, 50, 20)).should == true
|
615
|
+
end
|
616
|
+
|
617
|
+
it "works with UIOffset" do
|
618
|
+
offset = UIOffsetMake(50, 20)
|
619
|
+
rect = @rect.offset(offset)
|
620
|
+
CGRectEqualToRect(rect, CGRectMake(60, 120, 50, 20)).should == true
|
621
|
+
end
|
622
|
+
end
|
623
|
+
|
624
|
+
describe "inset" do
|
625
|
+
it "works with UIEdgeInsets" do
|
626
|
+
insets = UIEdgeInsetsMake(10, 10, 10, 5)
|
627
|
+
rect = @rect.inset(insets)
|
628
|
+
CGRectEqualToRect(rect, CGRectMake(20, 110, 35, 0)).should == true
|
629
|
+
end
|
630
|
+
end
|
631
|
+
|
632
|
+
describe "#*" do
|
633
|
+
it "should work with Numeric" do
|
634
|
+
rect = CGRectMake(0, 0, 12, 24)
|
635
|
+
bigger = rect * 3
|
636
|
+
bigger.size.width.should == 36
|
637
|
+
bigger.size.height.should == 72
|
638
|
+
end
|
639
|
+
end
|
640
|
+
|
641
|
+
describe "#/" do
|
642
|
+
it "should work with Numeric" do
|
643
|
+
rect = CGRectMake(0, 0, 12, 24)
|
644
|
+
smaller = rect / 3
|
645
|
+
smaller.size.width.should == 4
|
646
|
+
smaller.size.height.should == 8
|
647
|
+
end
|
648
|
+
end
|
649
|
+
|
452
650
|
describe "#intersection_with" do
|
453
651
|
it "should work" do
|
454
652
|
lower_rect = CGRectMake(0, 0, 100, 100)
|
@@ -489,5 +687,10 @@ describe "CGRect" do
|
|
489
687
|
rect = @rect.shrink(CGSizeMake(20, 10))
|
490
688
|
CGRectEqualToRect(rect, CGRectMake(30, 110, 10, 0)).should == true
|
491
689
|
end
|
690
|
+
|
691
|
+
it "should work with Array" do
|
692
|
+
rect = @rect.shrink([20, 10])
|
693
|
+
CGRectEqualToRect(rect, CGRectMake(30, 110, 10, 0)).should == true
|
694
|
+
end
|
492
695
|
end
|
493
|
-
end
|
696
|
+
end
|
data/spec/cg_size_spec.rb
CHANGED
@@ -46,6 +46,24 @@ describe "CGSize" do
|
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
+
describe "#*" do
|
50
|
+
it "should work with Numeric" do
|
51
|
+
size = CGSizeMake(12, 24)
|
52
|
+
bigger = size * 3
|
53
|
+
bigger.width.should == 36
|
54
|
+
bigger.height.should == 72
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "#/" do
|
59
|
+
it "should work with Numeric" do
|
60
|
+
size = CGSizeMake(12, 24)
|
61
|
+
smaller = size / 3
|
62
|
+
smaller.width.should == 4
|
63
|
+
smaller.height.should == 8
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
49
67
|
describe "#infinite?" do
|
50
68
|
it "should return true" do
|
51
69
|
infinite = CGSize.infinite
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: geomotion
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 0.7.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:
|
12
|
+
date: 2013-02-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -36,6 +36,7 @@ extra_rdoc_files: []
|
|
36
36
|
files:
|
37
37
|
- .gitignore
|
38
38
|
- Gemfile
|
39
|
+
- Gemfile.lock
|
39
40
|
- Geomotion.gemspec
|
40
41
|
- README.md
|
41
42
|
- Rakefile
|
@@ -68,7 +69,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
68
69
|
version: '0'
|
69
70
|
requirements: []
|
70
71
|
rubyforge_project:
|
71
|
-
rubygems_version: 1.8.
|
72
|
+
rubygems_version: 1.8.24
|
72
73
|
signing_key:
|
73
74
|
specification_version: 3
|
74
75
|
summary: A RubyMotion Geometry Wrapper
|
@@ -76,3 +77,4 @@ test_files:
|
|
76
77
|
- spec/cg_point_spec.rb
|
77
78
|
- spec/cg_rect_spec.rb
|
78
79
|
- spec/cg_size_spec.rb
|
80
|
+
has_rdoc:
|