coords 0.0.4 → 0.0.5
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 +4 -4
- data/README.md +2 -0
- data/coords.gemspec +0 -3
- data/lib/coords/cartesian2d.rb +24 -1
- data/lib/coords/cartesian3d.rb +24 -1
- data/lib/coords/polar.rb +3 -1
- data/lib/coords/spherical.rb +3 -1
- data/lib/coords/version.rb +1 -1
- data/lib/coords.rb +9 -1
- data/spec/lib/coords/cartesian2d_spec.rb +29 -0
- data/spec/lib/coords/cartesian3d_spec.rb +22 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f93b4aa9416c7cae15b4674bd007ff7bf81f0ac
|
4
|
+
data.tar.gz: cdd12a97636f9fd2ee8777a89cd33d5e22e27136
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 99a732eee293f74f8b0a6f0d8e53588f9c20112afd29e78e057cecd7b2e7b79a12799c5469fe6124464519b4ff450aeab2018d55d4f2d1eae4e762496236a898
|
7
|
+
data.tar.gz: 5bc610ea300c2dc27d55f0d40f5a6cf82f76fc652d6193cb27915e67f4ca3098e2cda158d91aa04c9418f0aecc00f4c6f50551c8471e8454c2303e97d2a8b675
|
data/README.md
CHANGED
data/coords.gemspec
CHANGED
@@ -21,9 +21,6 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.add_development_dependency "bundler", "~> 1.6"
|
22
22
|
spec.add_development_dependency "rake"
|
23
23
|
spec.add_development_dependency "rspec"
|
24
|
-
# spec.add_development_dependency "rspec-nc"
|
25
|
-
# spec.add_development_dependency "guard"
|
26
|
-
# spec.add_development_dependency "guard-rspec"
|
27
24
|
spec.add_development_dependency "pry"
|
28
25
|
spec.add_development_dependency "pry-remote"
|
29
26
|
spec.add_development_dependency "pry-nav"
|
data/lib/coords/cartesian2d.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
module Coords
|
2
2
|
class Cartesian2d
|
3
|
+
|
3
4
|
def initialize(x, y)
|
4
5
|
@x = x
|
5
6
|
@y = y
|
@@ -33,7 +34,29 @@ module Coords
|
|
33
34
|
end
|
34
35
|
|
35
36
|
def ==(point)
|
36
|
-
x == point.x && y == point.y
|
37
|
+
x.round(15) == point.x.round(15) && y.round(15) == point.y.round(15)
|
38
|
+
end
|
39
|
+
|
40
|
+
def translate(x2, y2)
|
41
|
+
Cartesian2d.new(x + x2, y + y2)
|
37
42
|
end
|
43
|
+
|
44
|
+
def translate!(x2, y2)
|
45
|
+
@x += x2
|
46
|
+
@y += y2
|
47
|
+
end
|
48
|
+
|
49
|
+
def rotate(theta)
|
50
|
+
x_rotated = ((x * Math.cos(theta)) - (y * Math.sin(theta))).round(15)
|
51
|
+
y_rotated = ((x * Math.sin(theta)) + (y * Math.cos(theta))).round(15)
|
52
|
+
|
53
|
+
Cartesian2d.new(x_rotated, y_rotated)
|
54
|
+
end
|
55
|
+
|
56
|
+
def rotate!(theta)
|
57
|
+
@x = ((x * Math.cos(theta)) - (y * Math.sin(theta))).round(15)
|
58
|
+
@y = ((x * Math.sin(theta)) + (y * Math.cos(theta))).round(15)
|
59
|
+
end
|
60
|
+
|
38
61
|
end
|
39
62
|
end
|
data/lib/coords/cartesian3d.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
module Coords
|
2
2
|
class Cartesian3d < Cartesian2d
|
3
|
+
|
3
4
|
def initialize(x, y, z)
|
4
5
|
super(x, y)
|
5
6
|
@z = z
|
@@ -26,7 +27,29 @@ module Coords
|
|
26
27
|
end
|
27
28
|
|
28
29
|
def ==(point)
|
29
|
-
x == point.x && y == point.y && z == point.z
|
30
|
+
x.round(15) == point.x.round(15) && y.round(15) == point.y.round(15) && z.round(15) == point.z.round(15)
|
31
|
+
end
|
32
|
+
|
33
|
+
def translate(x2, y2, z2)
|
34
|
+
Cartesian3d.new(x + x2, y + y2, z + z2)
|
35
|
+
end
|
36
|
+
|
37
|
+
def translate!(x2, y2, z2)
|
38
|
+
super(x2, y2)
|
39
|
+
@z += z2
|
30
40
|
end
|
41
|
+
|
42
|
+
# def rotate(theta)
|
43
|
+
# x_rotated = (x * Math.cos(theta)) - (y * Math.sin(theta))
|
44
|
+
# y_rotated = (x * Math.sin(theta)) + (y * Math.cos(theta))
|
45
|
+
|
46
|
+
# Cartesian2d.new(x_rotated, y_rotated)
|
47
|
+
# end
|
48
|
+
|
49
|
+
# def rotate!(theta)
|
50
|
+
# @x = (x * Math.cos(theta)) - (y * Math.sin(theta))
|
51
|
+
# @y = (x * Math.sin(theta)) + (y * Math.cos(theta))
|
52
|
+
# end
|
53
|
+
|
31
54
|
end
|
32
55
|
end
|
data/lib/coords/polar.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
module Coords
|
2
2
|
class Polar
|
3
|
+
|
3
4
|
def initialize(radius, theta)
|
4
5
|
@radius = radius
|
5
6
|
@theta = theta
|
@@ -38,7 +39,8 @@ module Coords
|
|
38
39
|
end
|
39
40
|
|
40
41
|
def ==(point)
|
41
|
-
radius == point.radius && theta == point.theta
|
42
|
+
radius.round(15) == point.radius.round(15) && theta.round(15) == point.theta.round(15)
|
42
43
|
end
|
44
|
+
|
43
45
|
end
|
44
46
|
end
|
data/lib/coords/spherical.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
module Coords
|
2
2
|
class Spherical < Polar
|
3
|
+
|
3
4
|
def initialize(radius, theta, phi)
|
4
5
|
super(radius, theta)
|
5
6
|
@phi = phi
|
@@ -33,7 +34,8 @@ module Coords
|
|
33
34
|
end
|
34
35
|
|
35
36
|
def ==(point)
|
36
|
-
radius == point.radius && theta == point.theta && phi == point.phi
|
37
|
+
radius.round(15) == point.radius.round(15) && theta.round(15) == point.theta.round(15) && phi.round(15) == point.phi.round(15)
|
37
38
|
end
|
39
|
+
|
38
40
|
end
|
39
41
|
end
|
data/lib/coords/version.rb
CHANGED
data/lib/coords.rb
CHANGED
@@ -50,4 +50,33 @@ describe Coords::Cartesian2d do
|
|
50
50
|
expect(subject != point2).to be false
|
51
51
|
end
|
52
52
|
end
|
53
|
+
|
54
|
+
describe '#translate' do
|
55
|
+
it 'translates values to new point' do
|
56
|
+
point2 = subject.translate(3, 4)
|
57
|
+
expect(subject.x).to eq(1)
|
58
|
+
expect(subject.y).to eq(2)
|
59
|
+
expect(point2.x).to eq(4)
|
60
|
+
expect(point2.y).to eq(6)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe '#translate!' do
|
65
|
+
it 'translates values of original point' do
|
66
|
+
point2 = Coords::Cartesian2d.new(1, 2)
|
67
|
+
point2.translate!(3, 4)
|
68
|
+
expect(point2.x).to eq(4)
|
69
|
+
expect(point2.y).to eq(6)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe '#rotate' do
|
74
|
+
it 'rotates values to new point' do
|
75
|
+
point2 = subject.rotate(Coords.radians(90))
|
76
|
+
expect(subject.x).to eq(1)
|
77
|
+
expect(subject.y).to eq(2)
|
78
|
+
expect(point2.x).to eq(-2)
|
79
|
+
expect(point2.y).to eq(1)
|
80
|
+
end
|
81
|
+
end
|
53
82
|
end
|
@@ -38,4 +38,26 @@ describe Coords::Cartesian3d do
|
|
38
38
|
expect(subject != point2).to be false
|
39
39
|
end
|
40
40
|
end
|
41
|
+
|
42
|
+
describe '#translate' do
|
43
|
+
it 'translates values to new point' do
|
44
|
+
point2 = subject.translate(3, 4, 5)
|
45
|
+
expect(subject.x).to eq(1)
|
46
|
+
expect(subject.y).to eq(2)
|
47
|
+
expect(subject.z).to eq(3)
|
48
|
+
expect(point2.x).to eq(4)
|
49
|
+
expect(point2.y).to eq(6)
|
50
|
+
expect(point2.z).to eq(8)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe '#translate!' do
|
55
|
+
it 'translates values of original point' do
|
56
|
+
point2 = Coords::Cartesian3d.new(1, 2, 3)
|
57
|
+
point2.translate!(3, 4, 5)
|
58
|
+
expect(point2.x).to eq(4)
|
59
|
+
expect(point2.y).to eq(6)
|
60
|
+
expect(point2.z).to eq(8)
|
61
|
+
end
|
62
|
+
end
|
41
63
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: coords
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
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-
|
11
|
+
date: 2015-03-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|