geomotion 0.1 → 0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +24 -15
- data/lib/geomotion/cg_point.rb +13 -1
- data/lib/geomotion/cg_rect.rb +115 -28
- data/lib/geomotion/cg_size.rb +24 -0
- data/lib/geomotion/version.rb +1 -1
- data/spec/cg_point_spec.rb +14 -0
- data/spec/cg_rect_spec.rb +116 -4
- data/spec/cg_size_spec.rb +46 -0
- metadata +2 -2
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Geomotion
|
1
|
+
# Geomotion for [RubyMotion](http://rubymotion.com)
|
2
2
|
|
3
3
|
iOS Geometry in idiomatic Ruby. Exhaustively tested. What's not to love?
|
4
4
|
|
@@ -26,35 +26,38 @@ rect.center(true)
|
|
26
26
|
=> CGPoint(35, 110) # center as frame
|
27
27
|
|
28
28
|
# Operator Overloading
|
29
|
+
-rect
|
30
|
+
=> CGRect(-10, -100, -50, -20)
|
31
|
+
|
29
32
|
rect + CGRect.make(x: 9, y: 99, width: 10, height: 10)
|
30
33
|
=> CGRect(9, 99, 50, 20) # == union of rects
|
31
34
|
|
32
|
-
rect + CGSize.
|
35
|
+
rect + CGSize.make(width: 11, height: 1)
|
33
36
|
=> CGRect(10, 100, 61, 21) # == increases the size, but keeps the origin
|
34
37
|
|
35
|
-
rect + CGPoint.
|
36
|
-
=> CGRect
|
38
|
+
rect + CGPoint.make(x: 10, y: 10)
|
39
|
+
=> CGRect(20, 110, 50, 20)
|
37
40
|
|
38
41
|
rect + UIOffsetMake(10, 10)
|
39
|
-
=> CGRect
|
42
|
+
=> CGRect(20, 110, 50, 20)
|
40
43
|
|
41
44
|
a_point + a_size
|
42
45
|
=> CGRect # a point and a size make a rectangle. makes sense, right?
|
43
46
|
|
44
47
|
# Union and Intersection
|
45
|
-
rect.union_with CGRect.
|
48
|
+
rect.union_with CGRect.make(x: 9, y: 99, width: 10, height: 10)
|
46
49
|
=> CGRect(9, 99, 50, 20)
|
47
50
|
|
48
|
-
rect.intersection_with CGRect.
|
49
|
-
=> CGRect
|
51
|
+
rect.intersection_with CGRect.make(x: 9, y: 99, width: 10, height: 10)
|
52
|
+
=> CGRect(10, 100, 10, 10)
|
50
53
|
|
51
54
|
# Growing and shrinking
|
52
55
|
# The center stays the same. Think margins!
|
53
|
-
rect.grow(CGSize.
|
54
|
-
=> CGRect
|
56
|
+
rect.grow(CGSize.make(width: 10, height: 20))
|
57
|
+
=> CGRect(5, 90, 60, 40)
|
55
58
|
|
56
59
|
rect.shrink(10)
|
57
|
-
=> CGRect
|
60
|
+
=> CGRect(15, 105, 40, 10)
|
58
61
|
|
59
62
|
# Powerful layout adjustments with chainable methods
|
60
63
|
view = UIView.alloc.initWithFrame rect.below.width(100).height(10)
|
@@ -73,14 +76,14 @@ rect = CGRect.make(x: 10, y: 100, width: 50, height: 20)
|
|
73
76
|
# Layout "above" and "before" rectangles
|
74
77
|
# (default offset is the rectangle's width or height)
|
75
78
|
rect.before(5)
|
76
|
-
=> CGRect
|
79
|
+
=> CGRect(-45, 100, 50, 20)
|
77
80
|
rect.before(5, width:20)
|
78
|
-
=> CGRect
|
81
|
+
=> CGRect(-15, 100, 20, 20)
|
79
82
|
|
80
83
|
rect.above(5)
|
81
|
-
=> CGRect
|
84
|
+
=> CGRect(10, 75, 50, 20)
|
82
85
|
rect.above(5, height:10)
|
83
|
-
=> CGRect
|
86
|
+
=> CGRect(10, 85, 50, 10)
|
84
87
|
|
85
88
|
# Layout a rect relative to others
|
86
89
|
rect2 = CGRect.make(x: 50, y: 50, width: 100, height: 100)
|
@@ -108,6 +111,9 @@ size_zero.empty?
|
|
108
111
|
=> true
|
109
112
|
|
110
113
|
# Operator Overloading
|
114
|
+
-size
|
115
|
+
=> CGSize(-50, -20)
|
116
|
+
|
111
117
|
size + CGSize.make(width: 100, height: 50)
|
112
118
|
=> CGSize(150, 70)
|
113
119
|
|
@@ -126,6 +132,9 @@ size.rect_at_point CGPoint.make(x: 10, y: 30)
|
|
126
132
|
point = CGPoint.make(x: 10, y: 100)
|
127
133
|
|
128
134
|
# Operator Overloading
|
135
|
+
-point
|
136
|
+
=> CGPoint(-10, -100)
|
137
|
+
|
129
138
|
point + CGPoint.make(x: 20, y: 40)
|
130
139
|
=> CGPoint(30, 140)
|
131
140
|
|
data/lib/geomotion/cg_point.rb
CHANGED
@@ -6,7 +6,7 @@ class CGPoint
|
|
6
6
|
|
7
7
|
# size = CGSize.make width: 100, height: 100
|
8
8
|
# point = CPPoint.make x:0, y:10
|
9
|
-
# point.rect_of_size(
|
9
|
+
# point.rect_of_size(size) # => CGRect([0, 10], [100, 100])
|
10
10
|
# point.rect_of_size([10, 20]) # => CGRect([10, 20], [100, 100])
|
11
11
|
def rect_of_size(size)
|
12
12
|
CGRect.new([self.x, self.y], size)
|
@@ -33,4 +33,16 @@ class CGPoint
|
|
33
33
|
point.is_a?(CGPoint) && CGPointEqualToPoint(self, point)
|
34
34
|
end
|
35
35
|
|
36
|
+
def -@
|
37
|
+
CGPoint.new(-self.x, -self.y)
|
38
|
+
end
|
39
|
+
|
40
|
+
def -(other)
|
41
|
+
self.+(-other)
|
42
|
+
end
|
43
|
+
|
44
|
+
def inspect
|
45
|
+
"#{self.class.name}(#{self.x}, #{self.y})"
|
46
|
+
end
|
47
|
+
|
36
48
|
end
|
data/lib/geomotion/cg_rect.rb
CHANGED
@@ -1,29 +1,48 @@
|
|
1
1
|
class CGRect
|
2
|
-
# CGRect.make
|
2
|
+
# CGRect.make # default rect: {origin: {x: 0, y: 0}, size: {width:0, height:0}}
|
3
|
+
# # aka CGRectZero
|
4
|
+
# CGRect.make(x: 10, y: 30) # default size: [0, 0]
|
3
5
|
# CGRect.make(x: 10, y: 30, width:100, height: 20)
|
6
|
+
#
|
7
|
+
# point = CGPoint.make(x: 10, y: 30)
|
8
|
+
# size = CGSize.make(width: 100, height: 20)
|
9
|
+
# CGRect.make(origin: point, size: size)
|
4
10
|
def self.make(options = {})
|
5
11
|
if options[:origin]
|
6
|
-
|
7
|
-
|
12
|
+
x = options[:origin].x
|
13
|
+
y = options[:origin].y
|
14
|
+
else
|
15
|
+
x = options[:x] || 0
|
16
|
+
y = options[:y] || 0
|
8
17
|
end
|
9
18
|
if options[:size]
|
10
|
-
|
11
|
-
|
19
|
+
w = options[:size].width
|
20
|
+
h = options[:size].height
|
21
|
+
else
|
22
|
+
w = options[:width] || 0
|
23
|
+
h = options[:height] || 0
|
12
24
|
end
|
13
|
-
|
25
|
+
self.new([x, y], [w, h])
|
14
26
|
end
|
15
27
|
|
16
28
|
def self.empty
|
17
|
-
# Don't return CGRectZero; can be mutated
|
18
|
-
|
29
|
+
# Don't just return CGRectZero; can be mutated
|
30
|
+
CGRectZero.dup
|
19
31
|
end
|
20
32
|
|
21
33
|
def self.null
|
22
|
-
CGRectNull
|
34
|
+
# Don't just return CGRectNull; can be mutated
|
35
|
+
CGRectNull.dup
|
23
36
|
end
|
24
37
|
|
25
38
|
def self.infinite
|
26
|
-
|
39
|
+
# This actually returns the not-very-infinite value of:
|
40
|
+
# [[-1.7014114289565e+38, -1.7014114289565e+38], [3.402822857913e+38, 3.402822857913e+38]]
|
41
|
+
# originally this method returned [[-Infinity, -Infinity], [Infinity, Infinity]],
|
42
|
+
# but that rect ended up returning `false` for any point in the method
|
43
|
+
# CGRect.infinite.contains?(point). CGRectInfinite returns `true` for any
|
44
|
+
# (sensible) point, so we'll go with that instead
|
45
|
+
CGRectInfinite.dup
|
27
46
|
end
|
28
47
|
|
29
48
|
# OPTIONS: [:above, :below, :left_of, :right_of, :margins]
|
@@ -31,11 +50,11 @@ class CGRect
|
|
31
50
|
# EX CGRect.layout(rect1, above: rect2, left_of: rect3, margins: [0, 10, 20, 0])
|
32
51
|
def self.layout(rect1, options)
|
33
52
|
if options.empty?
|
34
|
-
p "No options provided in
|
53
|
+
p "No options provided in #{self.class}.layout"
|
35
54
|
return rect1
|
36
55
|
end
|
37
56
|
|
38
|
-
rect =
|
57
|
+
rect = self.new
|
39
58
|
rect.size = rect1.size
|
40
59
|
|
41
60
|
options[:margins] ||= []
|
@@ -53,11 +72,29 @@ class CGRect
|
|
53
72
|
rect
|
54
73
|
end
|
55
74
|
|
75
|
+
# bounds
|
76
|
+
def min_x
|
77
|
+
CGRectGetMinX(self)
|
78
|
+
end
|
79
|
+
|
80
|
+
def max_x
|
81
|
+
CGRectGetMaxX(self)
|
82
|
+
end
|
83
|
+
|
84
|
+
def min_y
|
85
|
+
CGRectGetMinY(self)
|
86
|
+
end
|
87
|
+
|
88
|
+
def max_y
|
89
|
+
CGRectGetMaxY(self)
|
90
|
+
end
|
91
|
+
|
92
|
+
# getters/setters
|
56
93
|
def x(setter = nil)
|
57
94
|
if setter
|
58
95
|
return CGRect.new([setter, self.y], self.size)
|
59
96
|
end
|
60
|
-
|
97
|
+
min_x
|
61
98
|
end
|
62
99
|
|
63
100
|
def x=(_x)
|
@@ -68,7 +105,7 @@ class CGRect
|
|
68
105
|
if setter
|
69
106
|
return CGRect.new([self.x, setter], self.size)
|
70
107
|
end
|
71
|
-
|
108
|
+
min_y
|
72
109
|
end
|
73
110
|
|
74
111
|
def y=(_y)
|
@@ -79,7 +116,7 @@ class CGRect
|
|
79
116
|
if setter
|
80
117
|
return CGRect.new(self.origin, [setter, self.height])
|
81
118
|
end
|
82
|
-
self
|
119
|
+
CGRectGetWidth(self)
|
83
120
|
end
|
84
121
|
|
85
122
|
def width=(_width)
|
@@ -90,13 +127,14 @@ class CGRect
|
|
90
127
|
if setter
|
91
128
|
return CGRect.new(self.origin, [self.width, setter])
|
92
129
|
end
|
93
|
-
self
|
130
|
+
CGRectGetHeight(self)
|
94
131
|
end
|
95
132
|
|
96
133
|
def height=(_height)
|
97
134
|
self.size.height = _height
|
98
135
|
end
|
99
136
|
|
137
|
+
# modified rects
|
100
138
|
def left(dist = 0)
|
101
139
|
CGRect.new([self.x - dist, self.y], self.size)
|
102
140
|
end
|
@@ -113,6 +151,23 @@ class CGRect
|
|
113
151
|
CGRect.new([self.x, self.y + dist], self.size)
|
114
152
|
end
|
115
153
|
|
154
|
+
def wider(dist)
|
155
|
+
CGRect.new(self.origin, [self.width + dist, self.height])
|
156
|
+
end
|
157
|
+
|
158
|
+
def thinner(dist)
|
159
|
+
CGRect.new(self.origin, [self.width - dist, self.height])
|
160
|
+
end
|
161
|
+
|
162
|
+
def taller(dist)
|
163
|
+
CGRect.new(self.origin, [self.width, self.height + dist])
|
164
|
+
end
|
165
|
+
|
166
|
+
def shorter(dist)
|
167
|
+
CGRect.new(self.origin, [self.width, self.height - dist])
|
168
|
+
end
|
169
|
+
|
170
|
+
# adjacent rects
|
116
171
|
def above(margin = 0)
|
117
172
|
self.above(margin, height:self.height)
|
118
173
|
end
|
@@ -134,24 +189,43 @@ class CGRect
|
|
134
189
|
end
|
135
190
|
|
136
191
|
def beside(margin = 0)
|
137
|
-
|
192
|
+
self.beside(margin, width: self.width)
|
138
193
|
end
|
139
194
|
|
140
|
-
def
|
141
|
-
|
142
|
-
|
195
|
+
def beside(margin, width:width)
|
196
|
+
CGRect.new([self.x + self.width + margin, self.y], [width, self.height])
|
197
|
+
end
|
198
|
+
|
199
|
+
# locations
|
200
|
+
def center(absolute = false)
|
201
|
+
offset_x = absolute ? self.x : 0
|
202
|
+
offset_y = absolute ? self.y : 0
|
143
203
|
CGPoint.new(offset_x + self.width / 2, offset_y + self.height / 2)
|
144
204
|
end
|
145
205
|
|
206
|
+
def top_left
|
207
|
+
CGPoint.new(CGRectGetMinX(self), CGRectGetMinY(self))
|
208
|
+
end
|
209
|
+
|
210
|
+
def top_right
|
211
|
+
CGPoint.new(CGRectGetMaxX(self), CGRectGetMinY(self))
|
212
|
+
end
|
213
|
+
|
214
|
+
def bottom_left
|
215
|
+
CGPoint.new(CGRectGetMinX(self), CGRectGetMaxY(self))
|
216
|
+
end
|
217
|
+
|
218
|
+
def bottom_right
|
219
|
+
CGPoint.new(CGRectGetMaxX(self), CGRectGetMaxY(self))
|
220
|
+
end
|
221
|
+
|
222
|
+
# others
|
146
223
|
def round
|
147
224
|
CGRect.new([self.x.round, self.y.round], [self.width.round, self.height.round])
|
148
225
|
end
|
149
226
|
|
150
|
-
def centered_in(rect,
|
151
|
-
|
152
|
-
offset_y = relative ? rect.y : 0
|
153
|
-
CGRect.new([offset_x + ((rect.width - self.width) / 2),
|
154
|
-
offset_y + ((rect.height - self.height) / 2)], self.size)
|
227
|
+
def centered_in(rect, absolute = false)
|
228
|
+
self.size.centered_in(rect, absolute)
|
155
229
|
end
|
156
230
|
|
157
231
|
def +(other)
|
@@ -196,7 +270,7 @@ class CGRect
|
|
196
270
|
end
|
197
271
|
|
198
272
|
def infinite?
|
199
|
-
self.size.infinite?
|
273
|
+
self.size.infinite? || CGRectEqualToRect(self, CGRectInfinite)
|
200
274
|
end
|
201
275
|
|
202
276
|
def null?
|
@@ -208,7 +282,7 @@ class CGRect
|
|
208
282
|
when CGRect
|
209
283
|
CGRectIntersectsRect(self, rect)
|
210
284
|
else
|
211
|
-
super
|
285
|
+
super # raises an error
|
212
286
|
end
|
213
287
|
end
|
214
288
|
|
@@ -219,11 +293,24 @@ class CGRect
|
|
219
293
|
when CGRect
|
220
294
|
CGRectContainsRect(self, rect_or_point)
|
221
295
|
else
|
222
|
-
super
|
296
|
+
super # raises an error
|
223
297
|
end
|
224
298
|
end
|
225
299
|
|
226
300
|
def ==(rect)
|
227
301
|
rect.is_a?(CGRect) && CGRectEqualToRect(self, rect)
|
228
302
|
end
|
303
|
+
|
304
|
+
def -@
|
305
|
+
CGRect.new(-self.origin, -self.size)
|
306
|
+
end
|
307
|
+
|
308
|
+
def -(other)
|
309
|
+
self.+(-other)
|
310
|
+
end
|
311
|
+
|
312
|
+
def inspect
|
313
|
+
"#{self.class.name}([#{self.origin.x}, #{self.origin.y}], [#{self.size.width}, #{self.size.height}])"
|
314
|
+
end
|
315
|
+
|
229
316
|
end
|
data/lib/geomotion/cg_size.rb
CHANGED
@@ -9,6 +9,10 @@ class CGSize
|
|
9
9
|
CGSizeMake(infinity, infinity)
|
10
10
|
end
|
11
11
|
|
12
|
+
def self.empty
|
13
|
+
CGSizeZero.dup
|
14
|
+
end
|
15
|
+
|
12
16
|
# size = CGSize.make width: 100, height: 100
|
13
17
|
# point = CPPoint.make x:0, y:10
|
14
18
|
# size.rect_at_point(point) # => CGRect([0, 10], [100, 100])
|
@@ -17,6 +21,13 @@ class CGSize
|
|
17
21
|
CGRect.new(point, [self.width, self.height])
|
18
22
|
end
|
19
23
|
|
24
|
+
def centered_in(rect, absolute = false)
|
25
|
+
offset_x = absolute ? rect.x : 0
|
26
|
+
offset_y = absolute ? rect.y : 0
|
27
|
+
CGRect.new([offset_x + ((rect.width - self.width) / 2),
|
28
|
+
offset_y + ((rect.height - self.height) / 2)], self)
|
29
|
+
end
|
30
|
+
|
20
31
|
def +(other)
|
21
32
|
case other
|
22
33
|
when CGSize
|
@@ -38,4 +49,17 @@ class CGSize
|
|
38
49
|
def ==(size)
|
39
50
|
size.is_a?(CGSize) && CGSizeEqualToSize(self, size)
|
40
51
|
end
|
52
|
+
|
53
|
+
def -@
|
54
|
+
CGSize.new(-self.width, -self.height)
|
55
|
+
end
|
56
|
+
|
57
|
+
def -(other)
|
58
|
+
self.+(-other)
|
59
|
+
end
|
60
|
+
|
61
|
+
def inspect
|
62
|
+
"#{self.class.name}(#{self.width}, #{self.height})"
|
63
|
+
end
|
64
|
+
|
41
65
|
end
|
data/lib/geomotion/version.rb
CHANGED
data/spec/cg_point_spec.rb
CHANGED
@@ -32,6 +32,20 @@ describe "CGPoint" do
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
+
describe "#- (unary)" do
|
36
|
+
it "should work" do
|
37
|
+
point = CGPoint.make(x: 100, y: 200)
|
38
|
+
(-point).should == CGPoint.new(-100, -200)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "#- (binary)" do
|
43
|
+
it "should work" do
|
44
|
+
point = CGPoint.make(x: 100, y: 200)
|
45
|
+
(point - point).should == CGPoint.new(0, 0)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
35
49
|
describe "#inside?" do
|
36
50
|
it "should return true" do
|
37
51
|
rect = CGRectMake(0, 0, 100, 100)
|
data/spec/cg_rect_spec.rb
CHANGED
@@ -24,11 +24,19 @@ describe "CGRect" do
|
|
24
24
|
it "should work" do
|
25
25
|
CGRectIsEmpty(CGRect.empty).should == true
|
26
26
|
end
|
27
|
+
|
28
|
+
it "should not be mutable" do
|
29
|
+
f = CGRect.empty
|
30
|
+
f.width = 10
|
31
|
+
f.height = 10
|
32
|
+
f.x = 10
|
33
|
+
f.y = 10
|
34
|
+
CGRectIsEmpty(CGRect.empty).should == true
|
35
|
+
end
|
27
36
|
end
|
28
37
|
|
29
38
|
describe "#empty?" do
|
30
39
|
it "should work" do
|
31
|
-
p "ZERO1 #{CGRectZero.inspect}"
|
32
40
|
CGRectZero.empty?.should == true
|
33
41
|
end
|
34
42
|
end
|
@@ -37,26 +45,44 @@ describe "CGRect" do
|
|
37
45
|
it "should work" do
|
38
46
|
CGRectIsNull(CGRect.null).should == true
|
39
47
|
end
|
48
|
+
|
49
|
+
it "should not be mutable" do
|
50
|
+
f = CGRect.null
|
51
|
+
f.width = 10
|
52
|
+
f.height = 10
|
53
|
+
f.x = 10
|
54
|
+
f.y = 10
|
55
|
+
CGRectIsNull(CGRect.null).should == true
|
56
|
+
end
|
40
57
|
end
|
41
58
|
|
42
59
|
describe "#null?" do
|
43
60
|
it "should work" do
|
44
61
|
CGRectNull.null?.should == true
|
62
|
+
CGRect.null.null?.should == true
|
45
63
|
end
|
46
64
|
end
|
47
65
|
|
48
66
|
# Currently does NOT work due to some strange RM bug?
|
49
|
-
=begin
|
50
67
|
describe ".infinite" do
|
51
68
|
it "should work" do
|
52
|
-
|
69
|
+
CGRect.infinite.infinite?.should == true
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should not be mutable" do
|
73
|
+
f = CGRect.infinite
|
74
|
+
f.width = 10
|
75
|
+
f.height = 10
|
76
|
+
f.x = 10
|
77
|
+
f.y = 10
|
78
|
+
CGRect.infinite.infinite?.should == true
|
53
79
|
end
|
54
80
|
end
|
55
|
-
=end
|
56
81
|
|
57
82
|
describe "#infinite?" do
|
58
83
|
it "should work" do
|
59
84
|
CGRect.infinite.infinite?.should == true
|
85
|
+
CGRectInfinite.infinite?.should == true
|
60
86
|
end
|
61
87
|
end
|
62
88
|
|
@@ -221,6 +247,34 @@ describe "CGRect" do
|
|
221
247
|
end
|
222
248
|
end
|
223
249
|
|
250
|
+
describe "#wider" do
|
251
|
+
it "works" do
|
252
|
+
rect = CGRect.empty.wider(20)
|
253
|
+
rect.size.width.should == 20
|
254
|
+
end
|
255
|
+
end
|
256
|
+
|
257
|
+
describe "#thinner" do
|
258
|
+
it "works" do
|
259
|
+
rect = CGRect.empty.thinner(20)
|
260
|
+
rect.size.width.should == -20
|
261
|
+
end
|
262
|
+
end
|
263
|
+
|
264
|
+
describe "#taller" do
|
265
|
+
it "works" do
|
266
|
+
rect = CGRect.empty.taller(20)
|
267
|
+
rect.size.height.should == 20
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
271
|
+
describe "#shorter" do
|
272
|
+
it "works" do
|
273
|
+
rect = CGRect.empty.shorter(20)
|
274
|
+
rect.size.height.should == -20
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
224
278
|
describe "#above" do
|
225
279
|
it "works with margins" do
|
226
280
|
rect = CGRect.make(height: 50).above(20)
|
@@ -266,6 +320,50 @@ describe "CGRect" do
|
|
266
320
|
end
|
267
321
|
end
|
268
322
|
|
323
|
+
describe "#beside:width:" do
|
324
|
+
it "works" do
|
325
|
+
rect = CGRect.make(x: 50, width: 20).beside(10, width: 30)
|
326
|
+
rect.origin.x.should == 80
|
327
|
+
rect.size.width.should == 30
|
328
|
+
end
|
329
|
+
end
|
330
|
+
|
331
|
+
describe "#top_left" do
|
332
|
+
it "works" do
|
333
|
+
rect = CGRect.make(x: 10, y: 20, width: 100, height: 200)
|
334
|
+
point = rect.top_left
|
335
|
+
point.is_a?(CGPoint).should == true
|
336
|
+
CGPointEqualToPoint(point, CGPointMake(10, 20)).should == true
|
337
|
+
end
|
338
|
+
end
|
339
|
+
|
340
|
+
describe "#bottom_left" do
|
341
|
+
it "works" do
|
342
|
+
rect = CGRect.make(x: 10, y: 20, width: 100, height: 200)
|
343
|
+
point = rect.bottom_left
|
344
|
+
point.is_a?(CGPoint).should == true
|
345
|
+
CGPointEqualToPoint(point, CGPointMake(10, 220)).should == true
|
346
|
+
end
|
347
|
+
end
|
348
|
+
|
349
|
+
describe "#top_right" do
|
350
|
+
it "works" do
|
351
|
+
rect = CGRect.make(x: 10, y: 20, width: 100, height: 200)
|
352
|
+
point = rect.top_right
|
353
|
+
point.is_a?(CGPoint).should == true
|
354
|
+
CGPointEqualToPoint(point, CGPointMake(110, 20)).should == true
|
355
|
+
end
|
356
|
+
end
|
357
|
+
|
358
|
+
describe "#bottom_right" do
|
359
|
+
it "works" do
|
360
|
+
rect = CGRect.make(x: 10, y: 20, width: 100, height: 200)
|
361
|
+
point = rect.bottom_right
|
362
|
+
point.is_a?(CGPoint).should == true
|
363
|
+
CGPointEqualToPoint(point, CGPointMake(110, 220)).should == true
|
364
|
+
end
|
365
|
+
end
|
366
|
+
|
269
367
|
describe "#center" do
|
270
368
|
it "works" do
|
271
369
|
point = CGRect.make(width: 100, height: 100).center
|
@@ -305,6 +403,20 @@ describe "CGRect" do
|
|
305
403
|
end
|
306
404
|
end
|
307
405
|
|
406
|
+
describe "#- (unary)" do
|
407
|
+
it "should work" do
|
408
|
+
rect = CGRect.make(x: 10, y:10, width: 100, height: 200)
|
409
|
+
(-rect).should == CGRect.new([-10, -10], [-100, -200])
|
410
|
+
end
|
411
|
+
end
|
412
|
+
|
413
|
+
describe "#- (binary)" do
|
414
|
+
it "should work" do
|
415
|
+
rect = CGRect.make(x: 10, y:10, width: 100, height: 200)
|
416
|
+
(rect - rect).should == CGRect.new([-110, -210], [220, 420])
|
417
|
+
end
|
418
|
+
end
|
419
|
+
|
308
420
|
describe "#+" do
|
309
421
|
it "works with CGRect" do
|
310
422
|
_rect = CGRectMake(10, 100, 50, 20)
|
data/spec/cg_size_spec.rb
CHANGED
@@ -20,6 +20,20 @@ describe "CGSize" do
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
+
describe "#- (unary)" do
|
24
|
+
it "should work" do
|
25
|
+
size = CGSize.make(width: 100, height: 200)
|
26
|
+
(-size).should == CGSize.new(-100, -200)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "#- (binary)" do
|
31
|
+
it "should work" do
|
32
|
+
size = CGSize.make(width: 100, height: 200)
|
33
|
+
(size - size).should == CGSize.new(0, 0)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
23
37
|
describe "#+" do
|
24
38
|
it "should work with CGSize" do
|
25
39
|
size = CGSizeMake(20, 30)
|
@@ -39,6 +53,19 @@ describe "CGSize" do
|
|
39
53
|
end
|
40
54
|
end
|
41
55
|
|
56
|
+
describe ".empty" do
|
57
|
+
it "should work" do
|
58
|
+
CGRectIsEmpty(CGSize.empty.rect_at_point([0, 0])).should == true
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should not be mutable" do
|
62
|
+
f = CGSize.empty
|
63
|
+
f.width = 10
|
64
|
+
f.height = 10
|
65
|
+
CGRectIsEmpty(CGSize.empty.rect_at_point([0, 0])).should == true
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
42
69
|
describe "#empty?" do
|
43
70
|
it "should return true" do
|
44
71
|
empty = CGSizeMake(0, 0)
|
@@ -57,4 +84,23 @@ describe "CGSize" do
|
|
57
84
|
@size.should != size
|
58
85
|
end
|
59
86
|
end
|
87
|
+
|
88
|
+
describe "#centered_in" do
|
89
|
+
it "works" do
|
90
|
+
outer_rect = CGRect.make(width: 100, height: 100)
|
91
|
+
inner_size = CGSize.make(width: 50, height: 50)
|
92
|
+
|
93
|
+
centered_rect = inner_size.centered_in(outer_rect)
|
94
|
+
CGRectEqualToRect(centered_rect, CGRectMake(25, 25, 50, 50)).should == true
|
95
|
+
end
|
96
|
+
|
97
|
+
it "works as relative" do
|
98
|
+
outer_rect = CGRect.make(x: 20, y: 30, width: 100, height: 100)
|
99
|
+
inner_size = CGSize.make(width: 50, height: 50)
|
100
|
+
|
101
|
+
centered_rect = inner_size.centered_in(outer_rect, true)
|
102
|
+
CGRectEqualToRect(centered_rect, CGRectMake(45, 55, 50, 50)).should == true
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
60
106
|
end
|
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: '0.
|
4
|
+
version: '0.5'
|
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: 2012-
|
12
|
+
date: 2012-12-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|