geomotion 0.10.0 → 0.12.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,247 @@
1
+ describe "CGAffineTransform" do
2
+
3
+ describe "operations" do
4
+
5
+ it "should support ==" do
6
+ CGAffineTransformMake(2, 0, 0, 2, 0, 0).should == CGAffineTransformMake(2, 0, 0, 2, 0, 0)
7
+ end
8
+
9
+ it "should support +" do
10
+ t1 = CGAffineTransformMake(2, 0, 0, 2, 0, 0)
11
+ t2 = CGAffineTransformMake(1, 0, 0, 1, 10, 10)
12
+ (t1 + t2).should == CGAffineTransformMake(2, 0, 0, 2, 10, 10)
13
+ end
14
+
15
+ it "should support <<" do
16
+ t1 = CGAffineTransformMake(2, 0, 0, 2, 0, 0)
17
+ t2 = CGAffineTransformMake(1, 0, 0, 1, 10, 10)
18
+ (t1 << t2).should == CGAffineTransformMake(2, 0, 0, 2, 10, 10)
19
+ end
20
+
21
+ it "should support -" do
22
+ t1 = CGAffineTransformMake(2, 0, 0, 2, 0, 0)
23
+ t2 = CGAffineTransformMake(1, 0, 0, 1, 10, 10)
24
+ (t1 - t2).should == CGAffineTransformMake(2, 0, 0, 2, -10, -10)
25
+ end
26
+
27
+ it "subtracting itself should return identity (scale)" do
28
+ t1 = CGAffineTransformMake(2, 0, 0, 2, 0, 0)
29
+ (t1 - t1).should == CGAffineTransformMake(1, 0, 0, 1, 0, 0)
30
+ end
31
+
32
+ it "subtracting itself should return identity (translate)" do
33
+ t1 = CGAffineTransformMake(1, 0, 0, 1, 10, 10)
34
+ (t1 - t1).should == CGAffineTransformMake(1, 0, 0, 1, 0, 0)
35
+ end
36
+
37
+ it "subtracting itself should return identity (rotate)" do
38
+ t1 = CGAffineTransformMake(-1, 0, 0, -1, 0, 0)
39
+ (t1 - t1).should == CGAffineTransformMake(1, 0, 0, 1, 0, 0)
40
+ end
41
+
42
+ it "should support unary -" do
43
+ (- CGAffineTransformMake(2, 0, 0, 2, 0, 0)).should == CGAffineTransformMake(0.5, 0, 0, 0.5, 0, 0)
44
+ end
45
+
46
+ it "should support unary +" do
47
+ (+ CGAffineTransformMake(1, 0, 0, 1, 0, 0)).should == CGAffineTransformMake(1, 0, 0, 1, 0, 0)
48
+ end
49
+
50
+ end
51
+
52
+ describe ".make" do
53
+
54
+ it "should work with no arguments" do
55
+ transform = CGAffineTransform.make
56
+ transform.should == CGAffineTransformMake(1, 0, 0, 1, 0, 0)
57
+ end
58
+
59
+ it "should work with options" do
60
+ transform = CGAffineTransform.make(a: 2, b: 0, c: 0, d: 2, tx: 0, ty: 0)
61
+ transform.should == CGAffineTransformMake(2, 0, 0, 2, 0, 0)
62
+ end
63
+
64
+ it "should work with transform options (scale)" do
65
+ CGAffineTransform.make(scale: [2, 3]).should == CGAffineTransformMake(2, 0, 0, 3, 0, 0)
66
+ end
67
+
68
+ it "should work with transform options (translate)" do
69
+ CGAffineTransform.make(translate: [10, 20]).should == CGAffineTransformMake(1, 0, 0, 1, 10, 20)
70
+ end
71
+
72
+ it "should work with transform options (rotate)" do
73
+ transform = CGAffineTransform.make(rotate: Math::PI).to_a.map { |v| v.round(3) }
74
+ CGAffineTransform.new(*transform).should == CGAffineTransformMake(-1, 0, 0, -1, 0, 0)
75
+ end
76
+
77
+ it "should work with transform options (scale + translate)" do
78
+ CGAffineTransform.make(scale: [2, 3], translate: [10, 20]).should == CGAffineTransformMake(2, 0, 0, 3, 10, 20)
79
+ end
80
+
81
+ it "should work with transform options (scale + translate + rotation)" do
82
+ transform = CGAffineTransform.make(scale: [2, 3], rotate: Math::PI, translate: [10, 10]).to_a.map { |v| v.round(3) }
83
+ CGAffineTransform.new(*transform).should == CGAffineTransformMake(-2, 0, 0, -3, 10, 10)
84
+ end
85
+
86
+ end
87
+
88
+ describe "identity" do
89
+
90
+ it "should return the identity matrix" do
91
+ CGAffineTransformIsIdentity(CGAffineTransform.identity).should == true
92
+ end
93
+
94
+ it "identity? should return true for identity matrix" do
95
+ CGAffineTransform.identity.identity?.should == true
96
+ end
97
+
98
+ it "identity? should return false other matrices" do
99
+ CGAffineTransform.new(2, 0, 0, 2, 0, 0).identity?.should == false
100
+ end
101
+
102
+ end
103
+
104
+ describe ".rotate" do
105
+
106
+ it "should work as a factory" do
107
+ transform = CGAffineTransform.rotate(Math::PI).to_a.map { |v| v.round(3) }
108
+ CGAffineTransform.new(*transform).should == CGAffineTransformMake(-1, 0, 0, -1, 0, 0)
109
+ end
110
+
111
+ it "should work as an instance method" do
112
+ transform = CGAffineTransform.identity.rotate(Math::PI).to_a.map { |v| v.round(3) }
113
+ CGAffineTransform.new(*transform).should == CGAffineTransformMake(-1, 0, 0, -1, 0, 0)
114
+ end
115
+
116
+ end
117
+
118
+ describe ".scale" do
119
+
120
+ it "should work as a factory with one argument" do
121
+ CGAffineTransform.scale(2).should == CGAffineTransformMake(2, 0, 0, 2, 0, 0)
122
+ end
123
+
124
+ it "should work as a factory with two arguments" do
125
+ CGAffineTransform.scale(2, 3).should == CGAffineTransformMake(2, 0, 0, 3, 0, 0)
126
+ end
127
+
128
+ it "should work as a factory with one array" do
129
+ CGAffineTransform.scale([2, 3]).should == CGAffineTransformMake(2, 0, 0, 3, 0, 0)
130
+ end
131
+
132
+ it "should work as an instance method with one argument" do
133
+ CGAffineTransform.identity.scale(2).should == CGAffineTransformMake(2, 0, 0, 2, 0, 0)
134
+ end
135
+
136
+ it "should work as an instance method with two arguments" do
137
+ CGAffineTransform.identity.scale(2, 3).should == CGAffineTransformMake(2, 0, 0, 3, 0, 0)
138
+ end
139
+
140
+ it "should work as an instance method with one array" do
141
+ CGAffineTransform.identity.scale([2, 3]).should == CGAffineTransformMake(2, 0, 0, 3, 0, 0)
142
+ end
143
+
144
+ end
145
+
146
+ describe ".translate" do
147
+
148
+ it "should work as a factory with two arguments" do
149
+ CGAffineTransform.translate(10, 20).should == CGAffineTransformMake(1, 0, 0, 1, 10, 20)
150
+ end
151
+
152
+ it "should work as a factory with one array" do
153
+ CGAffineTransform.translate([10, 20]).should == CGAffineTransformMake(1, 0, 0, 1, 10, 20)
154
+ end
155
+
156
+ it "should work as an instance method with two arguments" do
157
+ CGAffineTransform.identity.translate(10, 20).should == CGAffineTransformMake(1, 0, 0, 1, 10, 20)
158
+ end
159
+
160
+ it "should work as an instance method with one array" do
161
+ CGAffineTransform.identity.translate([10, 20]).should == CGAffineTransformMake(1, 0, 0, 1, 10, 20)
162
+ end
163
+
164
+ end
165
+
166
+ describe ".shear" do
167
+
168
+ it "should work as a factory with proportion in x direction" do
169
+ CGAffineTransform.shear(1.5, 0).should == CGAffineTransformMake(1, 0, 1.5, 1, 0, 0)
170
+ end
171
+
172
+ it "should work as a factory with proportion and y direction" do
173
+ CGAffineTransform.shear(0, 1.5).should == CGAffineTransformMake(1, 1.5, 0, 1, 0, 0)
174
+ end
175
+
176
+ it "should work as a factory with proportion and both directions" do
177
+ CGAffineTransform.shear(1.5, 1.5).should == CGAffineTransformMake(1, 1.5, 1.5, 1, 0, 0)
178
+ end
179
+
180
+ it "should work as an instance method with proportion and x direction" do
181
+ CGAffineTransform.identity.shear(1.5, 0).should == CGAffineTransformMake(1, 0, 1.5, 1, 0, 0)
182
+ end
183
+
184
+ it "should work as an instance method with proportion and y direction" do
185
+ CGAffineTransform.identity.shear(0, 1.5).should == CGAffineTransformMake(1, 1.5, 0, 1, 0, 0)
186
+ end
187
+
188
+ end
189
+
190
+ describe "apply_to" do
191
+
192
+ before do
193
+ @transform = CGAffineTransformMake(2, 0, 0, 3, 10, 20)
194
+ end
195
+
196
+ it "should work on a point" do
197
+ thing = CGPoint.new(0, 0)
198
+ @transform.apply_to(thing).should == CGPoint.new(10, 20)
199
+ end
200
+
201
+ it "should work on a size" do
202
+ thing = CGSize.new(10, 10)
203
+ @transform.apply_to(thing).should == CGSize.new(20, 30)
204
+ end
205
+
206
+ it "should work on a rect" do
207
+ thing = CGRect.new([0, 0], [10, 10])
208
+ @transform.apply_to(thing).should == CGRect.new([10, 20], [20, 30])
209
+ end
210
+
211
+ it "should not work on anything else" do
212
+ ->{ @transform.apply_to(1) }.should.raise
213
+ ->{ @transform.apply_to([0, 0]) }.should.raise
214
+ end
215
+
216
+ end
217
+
218
+ describe "other methods" do
219
+
220
+ it "should support concat" do
221
+ t1 = CGAffineTransformMake(2, 0, 0, 2, 0, 0)
222
+ t2 = CGAffineTransformMake(1, 0, 0, 1, 10, 10)
223
+ t1.concat(t2).should == CGAffineTransformMake(2, 0, 0, 2, 10, 10)
224
+
225
+ t1 = CGAffineTransformMake(1, 0, 0, 1, 10, 10)
226
+ t2 = CGAffineTransformMake(2, 0, 0, 2, 0, 0)
227
+ t1.concat(t2).should == CGAffineTransformMake(2, 0, 0, 2, 20, 20)
228
+ end
229
+
230
+ it "should support invert" do
231
+ t1 = CGAffineTransformMake(2, 0, 0, 2, 0, 0)
232
+ t1.invert.should == CGAffineTransformMake(0.5, 0, 0, 0.5, 0, 0)
233
+ end
234
+
235
+ it "should support to_transform3d" do
236
+ t1 = CGAffineTransformMake(2, 0, 0, 2, 0, 0)
237
+ t1.to_transform3d.should == CATransform3D.new(2,0,0,0 ,0,2,0,0 ,0,0,1,0 ,0,0,0,1)
238
+ end
239
+
240
+ it 'should support to_a' do
241
+ t1 = CGAffineTransformMake(2, 0, 0, 2, 0, 0)
242
+ t1.to_a.should == [2, 0, 0, 2, 0, 0]
243
+ end
244
+
245
+ end
246
+
247
+ end
data/spec/cg_rect_spec.rb CHANGED
@@ -8,13 +8,20 @@ describe "CGRect" do
8
8
  CGRectEqualToRect(@rect, CGRectMake(10, 100, 50, 20)).should == true
9
9
  end
10
10
 
11
- it "should work with nested options" do
11
+ it "should work with nested options (CGPoint, CGSize)" do
12
12
  CGRectEqualToRect(
13
13
  CGRect.make(origin: CGPointMake(10, 100), size: CGSizeMake(50,20)),
14
14
  CGRectMake(10, 100, 50, 20)
15
15
  ).should == true
16
16
  end
17
17
 
18
+ it "should work with nested options (Arrays)" do
19
+ CGRectEqualToRect(
20
+ CGRect.make(origin: [10, 100], size: [50,20]),
21
+ CGRectMake(10, 100, 50, 20)
22
+ ).should == true
23
+ end
24
+
18
25
  it "should work with no options" do
19
26
  CGRectEqualToRect(CGRect.make, CGRectMake(0, 0, 0, 0)).should == true
20
27
  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.10.0
4
+ version: 0.12.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-03-21 00:00:00.000000000 Z
13
+ date: 2013-04-25 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake
@@ -37,17 +37,27 @@ extensions: []
37
37
  extra_rdoc_files: []
38
38
  files:
39
39
  - .gitignore
40
+ - .travis.yml
40
41
  - Gemfile
41
42
  - Gemfile.lock
42
43
  - Geomotion.gemspec
43
44
  - README.md
44
45
  - Rakefile
45
46
  - app/app_delegate.rb
47
+ - app/next_controller.rb
48
+ - app/perspective_controller.rb
49
+ - app/shearing_controller.rb
46
50
  - lib/geomotion.rb
51
+ - lib/geomotion/ca_transform_3d.rb
52
+ - lib/geomotion/cg_affine_transform.rb
47
53
  - lib/geomotion/cg_point.rb
48
54
  - lib/geomotion/cg_rect.rb
49
55
  - lib/geomotion/cg_size.rb
50
56
  - lib/geomotion/version.rb
57
+ - resources/perspective.png
58
+ - resources/shearing.png
59
+ - spec/ca_transform_3d_spec.rb
60
+ - spec/cg_affine_transform_spec.rb
51
61
  - spec/cg_point_spec.rb
52
62
  - spec/cg_rect_spec.rb
53
63
  - spec/cg_size_spec.rb
@@ -76,7 +86,8 @@ signing_key:
76
86
  specification_version: 3
77
87
  summary: A RubyMotion Geometry Wrapper
78
88
  test_files:
89
+ - spec/ca_transform_3d_spec.rb
90
+ - spec/cg_affine_transform_spec.rb
79
91
  - spec/cg_point_spec.rb
80
92
  - spec/cg_rect_spec.rb
81
93
  - spec/cg_size_spec.rb
82
- has_rdoc: