coords 0.0.9 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 5650aafea9e3293dfabd0891b4b918454189af5d
4
- data.tar.gz: 86475eb12664e5cc73ddeeab6b6ee528e03256c1
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ODgxMDZhMWE3NzdhODZkOTljMWVlMWM4NTAwNWY5YjExZGJlNWNhYg==
5
+ data.tar.gz: !binary |-
6
+ OTlmMTNhOWRlN2I3MjlkZjNjZWVkYTAzZGU0M2I3NTJhYWZmNDUyYw==
5
7
  SHA512:
6
- metadata.gz: 8be3f54bd57d0287adb8188ef35dfd0ba22c766f7a77498d0ec195975255c272b8ae29ffff92d1218811092138998abe66447da2b7a1f55f8db54496855f47c1
7
- data.tar.gz: 29f0df2c3e01fcc3354ecfea6846cf517106b731aa81397a93e2e95239a9d247572872bd1a4fd326f2114e8ce73685baa4a24535c622caeba5b0bd39a38c4521
8
+ metadata.gz: !binary |-
9
+ MmQ0Y2FkNWE4MDk4ODgwN2RhYjg1NDM5MTgzMzRmNjA0OGUwYTczM2FhZmY1
10
+ MDgxYzUwNmMxNDQ2ZmM1YThlN2U0MzQ5N2MxNmIzZDdlMmY0ZDY2NjlkNDli
11
+ Nzk5YTU1MGU2ZWMxMTQwZTY4YTRiMzk5YmQ4NDA2OTBhNWM1YWU=
12
+ data.tar.gz: !binary |-
13
+ YmE4ZDNlZDAzNmZhZDA5OGJmYTQ5ZDMxMzA2Y2M5ZGQwMzI5OTk0MTFlOWNm
14
+ ZjVlOGY0YzhlNjU0ZjczOTc4MWI1M2U1N2IzNjM3NzIxNjI0MjVmYTZlYTE1
15
+ MTUxODJjM2ZlYmY0MjlhMDYyZTE4MzE1ZDZhZjBlMmZjYmQyNmU=
data/lib/coords.rb CHANGED
@@ -4,6 +4,8 @@ require "coords/cartesian3d"
4
4
  require "coords/polar"
5
5
  require "coords/spherical"
6
6
 
7
+ require "coords/shapes/line2d"
8
+
7
9
  module Coords
8
10
 
9
11
  def self.radians(degrees)
@@ -0,0 +1,51 @@
1
+ module Coords
2
+ module Shapes
3
+ class Line2d
4
+
5
+ def initialize(x1, y1, x2, y2)
6
+ @point1 = Coords::Cartesian2d.new(x1, y1)
7
+ @point2 = Coords::Cartesian2d.new(x2, y2)
8
+ end
9
+
10
+ def point1
11
+ @point1
12
+ end
13
+
14
+ def point2
15
+ @point2
16
+ end
17
+
18
+ def ends
19
+ [point1, point2]
20
+ end
21
+
22
+ def length_squared
23
+ point1.distance_squared(point2)
24
+ end
25
+
26
+ def length
27
+ Math.sqrt(length_squared)
28
+ end
29
+
30
+ def to_s
31
+ "(#{point1.x.to_s},#{point1.y.to_s}),(#{point2.x.to_s},#{point2.y.to_s})"
32
+ end
33
+
34
+ def ==(line)
35
+ ((point1 == line.point1 && point2 == line.point2) || (point1 == line.point2 && point2 == line.point1))
36
+ end
37
+
38
+ def translate(x2, y2)
39
+ translated_line = Line2d.new(point1.x, point1.y, point2.x, point2.y)
40
+ translated_line.translate!(x2, y2)
41
+ translated_line
42
+ end
43
+
44
+ def translate!(x2, y2)
45
+ point1.translate!(x2, y2)
46
+ point2.translate!(x2, y2)
47
+ end
48
+
49
+ end
50
+ end
51
+ end
@@ -1,3 +1,3 @@
1
1
  module Coords
2
- VERSION = "0.0.9"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -3,17 +3,17 @@ require 'spec_helper'
3
3
  describe Coords::Cartesian2d do
4
4
  subject { Coords::Cartesian2d.new(1, 2) }
5
5
 
6
- # describe '#x' do
7
- # it 'returns value of x coordinate' do
8
- # expect(subject.x).to eq(1)
9
- # end
10
- # end
6
+ describe '#x' do
7
+ it 'returns value of x coordinate' do
8
+ expect(subject.x).to eq(1)
9
+ end
10
+ end
11
11
 
12
- # describe '#y' do
13
- # it 'returns value of y coordinate' do
14
- # expect(subject.y).to eq(2)
15
- # end
16
- # end
12
+ describe '#y' do
13
+ it 'returns value of y coordinate' do
14
+ expect(subject.y).to eq(2)
15
+ end
16
+ end
17
17
 
18
18
  describe '#distance_squared' do
19
19
  it 'returns squared distance between two points' do
@@ -0,0 +1,69 @@
1
+ require 'spec_helper'
2
+
3
+ describe Coords::Shapes::Line2d do
4
+ let(:point1) { Coords::Cartesian2d.new(1, 1) }
5
+ let(:point2) { Coords::Cartesian2d.new(1, 2) }
6
+
7
+ subject { Coords::Shapes::Line2d.new(1, 1, 1, 2) }
8
+
9
+ describe '#point1' do
10
+ it 'returns coordinates of point 1' do
11
+ expect(subject.point1).to eq(point1)
12
+ end
13
+ end
14
+
15
+ describe '#point2' do
16
+ it 'returns coordinates of point 2' do
17
+ expect(subject.point2).to eq(point2)
18
+ end
19
+ end
20
+
21
+ describe '#ends' do
22
+ it 'returns array of coordinates of points' do
23
+ expect(subject.ends).to eq([point1, point2])
24
+ end
25
+ end
26
+
27
+ describe '#length_squared' do
28
+ it 'returns squared distance between both ends' do
29
+ expect(subject.length_squared).to eq(1)
30
+ end
31
+ end
32
+
33
+ describe '#length' do
34
+ it 'returns distance between both ends' do
35
+ expect(subject.length).to eq(1)
36
+ end
37
+ end
38
+
39
+ describe '#to_s' do
40
+ it 'returns comma delimited coordinate values' do
41
+ expect(subject.to_s).to eq('(1,1),(1,2)')
42
+ end
43
+ end
44
+
45
+ describe '#==' do
46
+ it 'compares equality of two lines' do
47
+ equal_line = Coords::Shapes::Line2d.new(1,1,1,2)
48
+ unequal_line = Coords::Shapes::Line2d.new(1,1,2,2)
49
+ expect(subject == equal_line).to be true
50
+ expect(subject == unequal_line).to be false
51
+ end
52
+ end
53
+
54
+ describe '#translate' do
55
+ it 'translates line to a new line' do
56
+ line2 = subject.translate(3, 4)
57
+ expect(subject.point1.x).to eq(1)
58
+ expect(subject.point1.y).to eq(1)
59
+ expect(subject.point2.x).to eq(1)
60
+ expect(subject.point2.y).to eq(2)
61
+
62
+ expect(line2.point1.x).to eq(4)
63
+ expect(line2.point1.y).to eq(5)
64
+ expect(line2.point2.x).to eq(4)
65
+ expect(line2.point2.y).to eq(6)
66
+ end
67
+ end
68
+
69
+ end
metadata CHANGED
@@ -1,97 +1,97 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coords
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Craig Allan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-16 00:00:00.000000000 Z
11
+ date: 2015-03-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.6'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ~>
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.6'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - ! '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - ! '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - ! '>='
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - ! '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: pry
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - ! '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - ! '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: pry-remote
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - ! '>='
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - ! '>='
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: pry-nav
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ">="
87
+ - - ! '>='
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ">="
94
+ - - ! '>='
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  description: Coordinate system library enabling cross-system conversions.
@@ -101,7 +101,7 @@ executables: []
101
101
  extensions: []
102
102
  extra_rdoc_files: []
103
103
  files:
104
- - ".gitignore"
104
+ - .gitignore
105
105
  - Gemfile
106
106
  - LICENSE.txt
107
107
  - README.md
@@ -111,11 +111,13 @@ files:
111
111
  - lib/coords/cartesian2d.rb
112
112
  - lib/coords/cartesian3d.rb
113
113
  - lib/coords/polar.rb
114
+ - lib/coords/shapes/line2d.rb
114
115
  - lib/coords/spherical.rb
115
116
  - lib/coords/version.rb
116
117
  - spec/lib/coords/cartesian2d_spec.rb
117
118
  - spec/lib/coords/cartesian3d_spec.rb
118
119
  - spec/lib/coords/polar_spec.rb
120
+ - spec/lib/coords/shapes/line2d_spec.rb
119
121
  - spec/lib/coords/spherical_spec.rb
120
122
  - spec/lib/coords_spec.rb
121
123
  - spec/spec_helper.rb
@@ -129,12 +131,12 @@ require_paths:
129
131
  - lib
130
132
  required_ruby_version: !ruby/object:Gem::Requirement
131
133
  requirements:
132
- - - ">="
134
+ - - ! '>='
133
135
  - !ruby/object:Gem::Version
134
136
  version: '0'
135
137
  required_rubygems_version: !ruby/object:Gem::Requirement
136
138
  requirements:
137
- - - ">="
139
+ - - ! '>='
138
140
  - !ruby/object:Gem::Version
139
141
  version: '0'
140
142
  requirements: []
@@ -147,7 +149,7 @@ test_files:
147
149
  - spec/lib/coords/cartesian2d_spec.rb
148
150
  - spec/lib/coords/cartesian3d_spec.rb
149
151
  - spec/lib/coords/polar_spec.rb
152
+ - spec/lib/coords/shapes/line2d_spec.rb
150
153
  - spec/lib/coords/spherical_spec.rb
151
154
  - spec/lib/coords_spec.rb
152
155
  - spec/spec_helper.rb
153
- has_rdoc: