geomotion 0.7.0 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- geomotion (0.6.0)
4
+ geomotion (0.9.0)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
@@ -4,8 +4,8 @@ require File.expand_path('../lib/geomotion/version', __FILE__)
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "geomotion"
6
6
  s.version = Geomotion::VERSION
7
- s.authors = ["Clay Allsopp"]
8
- s.email = ["clay.allsopp@gmail.com"]
7
+ s.authors = ["Clay Allsopp", "Colin T.A. Gray"]
8
+ s.email = ["clay.allsopp@gmail.com", "colinta@gmail.com"]
9
9
  s.homepage = "https://github.com/clayallsopp/geomotion"
10
10
  s.summary = "A RubyMotion Geometry Wrapper"
11
11
  s.description = "A RubyMotion Geometry Wrapper"
data/README.md CHANGED
@@ -138,7 +138,7 @@ will return a frame that is in the same coordinate system of the receiver, and
138
138
  this behavior cannot be changed.
139
139
 
140
140
  ```ruby
141
- frame = CGRect.new(x: 10, y: 10, width:10, height: 10)
141
+ frame = CGRect.make(x: 10, y: 10, width:10, height: 10)
142
142
  frame.beside
143
143
  # => [[20, 10], [10, 10]]
144
144
 
@@ -173,7 +173,7 @@ numbers. If you specify absolute coordinates, the values might be negative, but
173
173
  they will also be sorted (x == min, min < mid, mid < max, x + width == max).
174
174
 
175
175
  ```ruby
176
- frame = CGRect.new(x: 10, y: 10, width:10, height: 10)
176
+ frame = CGRect.make(x: 10, y: 10, width:10, height: 10)
177
177
  frame.top_left # => [0, 0]
178
178
  frame.top_center # => [5, 0]
179
179
  frame.bottom_right # => [10, 10]
@@ -184,7 +184,7 @@ frame.top_center(true) # => [15, 10]
184
184
  frame.bottom_right(true) # => [20, 20]
185
185
 
186
186
  # negative widths and heights are "corrected" when using absolute coordinates
187
- frame = CGRect.new(x: 20, y: 20, width:-10, height: -10)
187
+ frame = CGRect.make(x: 20, y: 20, width:-10, height: -10)
188
188
  frame.top_center(true) # => [15, 10]
189
189
  frame.bottom_right(true) # => [20, 20]
190
190
  ```
@@ -243,9 +243,18 @@ point + CGSize.make(width: 50, height: 20)
243
243
  point.rect_of_size CGSize.make(width: 50, height: 20)
244
244
  => CGRect(10, 100, 50, 20)
245
245
 
246
- # Combine with CGRect
246
+ # Compare with CGRect
247
247
  point.inside? CGRect.make(x: 0, y: 0, width: 20, height: 110)
248
248
  => true
249
+
250
+ # Distance to point
251
+ point.distance_to(CGPoint.make(x: 13, y:104))
252
+ => 5
253
+
254
+ # Angle between target and receiver
255
+ # (up 10, over 10)
256
+ point.angle_to(CGPoint.make(x: 20, y:110))
257
+ => 0.785398163397 (pi/4)
249
258
  ```
250
259
 
251
260
  ## Install
@@ -37,6 +37,18 @@ class CGPoint
37
37
  CGRectContainsPoint(rect, self)
38
38
  end
39
39
 
40
+ def distance_to(point)
41
+ dx = self.x - point.x
42
+ dy = self.y - point.y
43
+ return Math.sqrt(dx**2 + dy**2)
44
+ end
45
+
46
+ def angle_to(point)
47
+ dx = point.x - self.x
48
+ dy = point.y - self.y
49
+ return Math.atan2(dy, dx)
50
+ end
51
+
40
52
  # operator
41
53
  def +(other)
42
54
  case other
@@ -13,6 +13,22 @@ class CGSize
13
13
  CGSizeZero.dup
14
14
  end
15
15
 
16
+ def wider(dist)
17
+ CGSize.new(self.width + dist, self.height)
18
+ end
19
+
20
+ def thinner(dist)
21
+ CGSize.new(self.width - dist, self.height)
22
+ end
23
+
24
+ def taller(dist)
25
+ CGSize.new(self.width, self.height + dist)
26
+ end
27
+
28
+ def shorter(dist)
29
+ CGSize.new(self.width, self.height - dist)
30
+ end
31
+
16
32
  # size = CGSize.make width: 100, height: 100
17
33
  # point = CPPoint.make x:0, y:10
18
34
  # size.rect_at_point(point) # => CGRect([0, 10], [100, 100])
@@ -1,3 +1,3 @@
1
1
  module Geomotion
2
- VERSION = "0.7.0"
2
+ VERSION = "0.10.0"
3
3
  end
@@ -48,13 +48,32 @@ describe "CGPoint" do
48
48
  end
49
49
  end
50
50
 
51
- describe "#chaining up().down().left().right()" do
51
+ describe "chaining up().down().left().right()" do
52
52
  it "should work" do
53
53
  point = CGPointMake(1, 1).up(2).down(1).left(2).right(1)
54
54
  CGPointEqualToPoint(point, CGPointMake(0, 0)).should == true
55
55
  end
56
56
  end
57
57
 
58
+ describe "#distance_to" do
59
+ it "should work" do
60
+ point = CGPoint.make(x: 10, y: 100)
61
+ point.distance_to(CGPoint.make(x: 13, y:104)).should == 5
62
+ point.distance_to(CGPoint.make(x: 14, y:103)).should == 5
63
+ end
64
+ end
65
+
66
+ describe "#angle_to" do
67
+ it "should work" do
68
+ point = CGPoint.make(x: 0, y: 0)
69
+ point.angle_to(CGPoint.make(x: 10, y:0)).should == 0
70
+ (0.785 - point.angle_to(CGPoint.make(x: 10, y:10))).abs.should < 0.01 # ~= Math::PI/4
71
+ (1.57 - point.angle_to(CGPoint.make(x: 0, y:10))).abs.should < 0.01 # ~= Math::PI/2
72
+ (3.14 - point.angle_to(CGPoint.make(x: -10, y:0))).abs.should < 0.01 # ~= Math::PI
73
+ (-1.57 - point.angle_to(CGPoint.make(x: 0, y:-10))).abs.should < 0.01 # ~= -Math::PI/2
74
+ end
75
+ end
76
+
58
77
  describe "#+" do
59
78
  it "should work with CGSize" do
60
79
  size = CGSizeMake(20, 30)
@@ -13,6 +13,34 @@ describe "CGSize" do
13
13
  end
14
14
  end
15
15
 
16
+ describe "#wider" do
17
+ it "works" do
18
+ size = CGSize.new(0, 0).wider(20)
19
+ size.width.should == 20
20
+ end
21
+ end
22
+
23
+ describe "#thinner" do
24
+ it "works" do
25
+ size = CGSize.new(0, 0).thinner(20)
26
+ size.width.should == -20
27
+ end
28
+ end
29
+
30
+ describe "#taller" do
31
+ it "works" do
32
+ size = CGSize.new(0, 0).taller(20)
33
+ size.height.should == 20
34
+ end
35
+ end
36
+
37
+ describe "#shorter" do
38
+ it "works" do
39
+ size = CGSize.new(0, 0).shorter(20)
40
+ size.height.should == -20
41
+ end
42
+ end
43
+
16
44
  describe "#rect_at_point" do
17
45
  it "should work" do
18
46
  point = CGPointMake(20, 30)
metadata CHANGED
@@ -1,15 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geomotion
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.10.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Clay Allsopp
9
+ - Colin T.A. Gray
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2013-02-14 00:00:00.000000000 Z
13
+ date: 2013-03-21 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: rake
@@ -30,6 +31,7 @@ dependencies:
30
31
  description: A RubyMotion Geometry Wrapper
31
32
  email:
32
33
  - clay.allsopp@gmail.com
34
+ - colinta@gmail.com
33
35
  executables: []
34
36
  extensions: []
35
37
  extra_rdoc_files: []
@@ -69,7 +71,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
69
71
  version: '0'
70
72
  requirements: []
71
73
  rubyforge_project:
72
- rubygems_version: 1.8.24
74
+ rubygems_version: 1.8.25
73
75
  signing_key:
74
76
  specification_version: 3
75
77
  summary: A RubyMotion Geometry Wrapper