motion-ui-geometry 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- 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/float_spec.rb
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
describe "Float" do
|
2
|
+
|
3
|
+
describe "#clamp" do
|
4
|
+
it "works with a [-1,1] range" do
|
5
|
+
-1.0.clamp(-1, 1).should == -1
|
6
|
+
0.0.clamp(-1, 1).should == 0
|
7
|
+
1.0.clamp(-1, 1).should == 1
|
8
|
+
-2.0.clamp(-1, 1).should == -1
|
9
|
+
2.0.clamp(-1, 1).should == 1
|
10
|
+
-1.0.clamp(1, -1).should == -1
|
11
|
+
0.0.clamp(1, -1).should == 0
|
12
|
+
1.0.clamp(1, -1).should == 1
|
13
|
+
-2.0.clamp(1, -1).should == -1
|
14
|
+
2.0.clamp(1, -1).should == 1
|
15
|
+
end
|
16
|
+
|
17
|
+
it "works with a [0, 100] range" do
|
18
|
+
42.0.clamp(0, 100).should == 42
|
19
|
+
1337.0.clamp(0, 100).should == 100
|
20
|
+
-123.0.clamp(0, 100).should == 0
|
21
|
+
42.0.clamp(100, 0).should == 42
|
22
|
+
1337.0.clamp(100, 0).should == 100
|
23
|
+
-123.0.clamp(100, 0).should == 0
|
24
|
+
end
|
25
|
+
|
26
|
+
it "works with a [0, 0] range" do
|
27
|
+
42.0.clamp(0, 0).should == 0
|
28
|
+
1337.0.clamp(0, 0).should == 0
|
29
|
+
-123.0.clamp(0, 0).should == 0
|
30
|
+
end
|
31
|
+
|
32
|
+
it "works with floats" do
|
33
|
+
-1.0001.clamp(-1, 1).should == -1
|
34
|
+
1.0001.clamp(-1, 1).should == 1
|
35
|
+
-1.0001.clamp(1, -1).should == -1
|
36
|
+
1.0001.clamp(1, -1).should == 1
|
37
|
+
end
|
38
|
+
|
39
|
+
it "raises an error if given a string" do
|
40
|
+
lambda {0.0.clamp("123", 0)}.should.raise(TypeError)
|
41
|
+
lambda {0.0.clamp(0, "123")}.should.raise(TypeError)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "#roughly_equal" do
|
46
|
+
it "returns true for the same value" do
|
47
|
+
1.0.should.roughly_equal(1.0, 0.0)
|
48
|
+
-1.0.should.roughly_equal(-1.0, 0.0)
|
49
|
+
end
|
50
|
+
|
51
|
+
it "returns true for values within the given epsilon limit" do
|
52
|
+
1.0.should.roughly_equal(1.00001, 0.00002)
|
53
|
+
1.0.should.roughly_equal(0.99999, 0.00002)
|
54
|
+
1.0.should.roughly_equal(0.9999999)
|
55
|
+
end
|
56
|
+
|
57
|
+
it "returns false for values outside the given epsilon limit" do
|
58
|
+
1.0.should.not.roughly_equal(1.1, 0.001)
|
59
|
+
-1.0.should.not.roughly_equal(-1.1, 0.001)
|
60
|
+
-1.0.should.not.roughly_equal(-1.1)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "=~" do
|
65
|
+
it "behaves like roughly_equal with epsilon == 0.0001" do
|
66
|
+
1.0.should =~ 1.0000001
|
67
|
+
1.0.should.not =~ 1.001
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe "#to_radians, #to_degrees" do
|
72
|
+
it "is mathematically correct for example values" do
|
73
|
+
-180.0.to_radians.should == -Math::PI
|
74
|
+
0.0.to_radians.should == 0
|
75
|
+
180.0.to_radians.should == Math::PI
|
76
|
+
360.0.to_radians.should == 2.0 * Math::PI
|
77
|
+
|
78
|
+
-180.0.to_radians.should == -Math::PI
|
79
|
+
0.0.to_radians.should == 0
|
80
|
+
180.0.to_radians.should == Math::PI
|
81
|
+
360.0.to_radians.should == 2 * Math::PI
|
82
|
+
|
83
|
+
-Math::PI.to_degrees.should == -180
|
84
|
+
0.0.to_degrees.should == 0.0
|
85
|
+
Math::PI.to_degrees.should == 180
|
86
|
+
(2 * Math::PI).to_degrees.should == 360.0
|
87
|
+
end
|
88
|
+
|
89
|
+
it "returns the initial value if reverse-applied" do
|
90
|
+
1.0.to_radians.to_degrees.should =~ 1.0
|
91
|
+
1.0.to_degrees.to_radians.should =~ 1.0
|
92
|
+
|
93
|
+
Math::PI.to_degrees.to_radians.should =~ Math::PI
|
94
|
+
180.0.to_radians.to_degrees.should =~ 180.0
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
describe "#to_value" do
|
99
|
+
it "should return an NSNumber" do
|
100
|
+
value = 12.34.to_value
|
101
|
+
value.should.is_a NSNumber
|
102
|
+
value.floatValue.should == 12.34
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
|
107
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
Exception.log_exceptions = false
|
@@ -0,0 +1,15 @@
|
|
1
|
+
describe NSDictionary do
|
2
|
+
|
3
|
+
describe "#to_point" do
|
4
|
+
{"X" => 10, "Y" => 10}.to_point.should == CGPointMake(10, 10)
|
5
|
+
end
|
6
|
+
|
7
|
+
describe "#to_size" do
|
8
|
+
{"Width" => 10, "Height" => 10}.to_size.should == CGSizeMake(10, 10)
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#to_rect" do
|
12
|
+
{"X" => 1, "Y" => 2, "Width" => 3, "Height" => 4}.to_rect.should == CGRectMake(1, 2, 3, 4)
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
describe NSString do
|
2
|
+
describe "#to_point" do
|
3
|
+
it "should return a point" do
|
4
|
+
"{1, 2}".to_point.should == CGPointMake(1, 2)
|
5
|
+
"{1, 2, 3}".to_point.should == CGPointMake(1, 2)
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should return CGPointZero if in wrong format" do
|
9
|
+
"{1, 2, 3".to_point.should == CGPointZero
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "#to_size" do
|
14
|
+
it "should return a size" do
|
15
|
+
"{1, 2}".to_size.should == CGSizeMake(1, 2)
|
16
|
+
"{1, 2, 3}".to_size.should == CGSizeMake(1, 2)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should return CGSizeZero if in wrong format" do
|
20
|
+
"{1, 2, 3".to_size.should == CGSizeZero
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "#to_rect" do
|
25
|
+
it "should return a rect" do
|
26
|
+
"{{1, 2}, {3, 4}}".to_rect.should == CGRectMake(1, 2, 3, 4)
|
27
|
+
"{{1,2},{3,4}}".to_rect.should == CGRectMake(1, 2, 3, 4)
|
28
|
+
"{{1,2},{3,4},{5,6}}".to_rect.should == CGRectMake(1, 2, 3, 4)
|
29
|
+
end
|
30
|
+
it "should return CGRectZero if in wrong format" do
|
31
|
+
"{1, 2, 3".to_rect.should == CGRectZero
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "#to_affine_transform" do
|
36
|
+
it "should return a transform" do
|
37
|
+
"[1,2,3,4,5,6]".to_transform.should == CGAffineTransformMake(1, 2, 3, 4, 5, 6)
|
38
|
+
"[1,2, 3,4, 5,6]".to_transform.should == CGAffineTransformMake(1, 2, 3, 4, 5, 6)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: motion-ui-geometry
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Sebastian Burkhart
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-07-07 00:00:00.000000000Z
|
13
|
+
dependencies: []
|
14
|
+
description: Access CoreGraphics UI geometry the Ruby way.
|
15
|
+
email:
|
16
|
+
- sebastianburkhart@me.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- Gemfile
|
23
|
+
- LICENSE
|
24
|
+
- README.md
|
25
|
+
- Rakefile
|
26
|
+
- lib/motion-ui-geometry.rb
|
27
|
+
- lib/motion-ui-geometry/cgaffinetransform.rb
|
28
|
+
- lib/motion-ui-geometry/cgpoint.rb
|
29
|
+
- lib/motion-ui-geometry/cgrect.rb
|
30
|
+
- lib/motion-ui-geometry/cgsize.rb
|
31
|
+
- lib/motion-ui-geometry/float.rb
|
32
|
+
- lib/motion-ui-geometry/nsdictionary.rb
|
33
|
+
- lib/motion-ui-geometry/nsstring.rb
|
34
|
+
- lib/motion-ui-geometry/spec_app_delegate.rb
|
35
|
+
- lib/motion-ui-geometry/version.rb
|
36
|
+
- motion-ui-geometry.gemspec
|
37
|
+
- spec/cgaffinetransform_spec.rb
|
38
|
+
- spec/cgpoint_spec.rb
|
39
|
+
- spec/cgrect_spec.rb
|
40
|
+
- spec/cgsize_spec.rb
|
41
|
+
- spec/float_spec.rb
|
42
|
+
- spec/helpers/no_exception_logging.rb
|
43
|
+
- spec/nsdictionary_spec.rb
|
44
|
+
- spec/nsstring_spec.rb
|
45
|
+
homepage: ''
|
46
|
+
licenses: []
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options: []
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ! '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
segments:
|
58
|
+
- 0
|
59
|
+
hash: -2171170578995522578
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
segments:
|
67
|
+
- 0
|
68
|
+
hash: -2171170578995522578
|
69
|
+
requirements: []
|
70
|
+
rubyforge_project:
|
71
|
+
rubygems_version: 1.8.10
|
72
|
+
signing_key:
|
73
|
+
specification_version: 3
|
74
|
+
summary: Contains Ruby-ish interfaces mixed into Float, CGPoint, CGRect, CGSize and
|
75
|
+
CGPoint.
|
76
|
+
test_files:
|
77
|
+
- spec/cgaffinetransform_spec.rb
|
78
|
+
- spec/cgpoint_spec.rb
|
79
|
+
- spec/cgrect_spec.rb
|
80
|
+
- spec/cgsize_spec.rb
|
81
|
+
- spec/float_spec.rb
|
82
|
+
- spec/helpers/no_exception_logging.rb
|
83
|
+
- spec/nsdictionary_spec.rb
|
84
|
+
- spec/nsstring_spec.rb
|