coords 0.0.3 → 0.0.4
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/lib/coords/cartesian3d.rb +4 -0
- data/lib/coords/polar.rb +4 -0
- data/lib/coords/spherical.rb +5 -1
- data/lib/coords/version.rb +1 -1
- data/spec/lib/coords/cartesian3d_spec.rb +41 -0
- data/spec/lib/coords/polar_spec.rb +53 -0
- data/spec/lib/coords/spherical_spec.rb +41 -0
- metadata +7 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d76d64722dcae03f213988afda85f2c22af60d8a
|
4
|
+
data.tar.gz: a37ea6056ecae70890ecedb93dd3567570086880
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 196c2c9d6b1c294e8f5d47cf2d22e4922508a779c0b209926e72a8197a7f0c72bb0841984ac87295588bd14c6a89193a814837c3c7942c2e11fec72372f92581
|
7
|
+
data.tar.gz: acd1157d49e7d7d9bfe0c0f9f9f9df0acea22be968ac2de03e126bdb371786b4f3593581a7c06721b55e2272e24f216ad208580ff7f4424db21b006c49cb0fbf
|
data/lib/coords/cartesian3d.rb
CHANGED
data/lib/coords/polar.rb
CHANGED
data/lib/coords/spherical.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module Coords
|
2
|
-
class Spherical
|
2
|
+
class Spherical < Polar
|
3
3
|
def initialize(radius, theta, phi)
|
4
4
|
super(radius, theta)
|
5
5
|
@phi = phi
|
@@ -31,5 +31,9 @@ module Coords
|
|
31
31
|
|
32
32
|
Cartesian3d.new(x, y, z)
|
33
33
|
end
|
34
|
+
|
35
|
+
def ==(point)
|
36
|
+
radius == point.radius && theta == point.theta && phi == point.phi
|
37
|
+
end
|
34
38
|
end
|
35
39
|
end
|
data/lib/coords/version.rb
CHANGED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Coords::Cartesian3d do
|
4
|
+
subject { Coords::Cartesian3d.new(1, 2, 3) }
|
5
|
+
|
6
|
+
describe '#z' do
|
7
|
+
it 'returns value of z coordinate' do
|
8
|
+
expect(subject.z).to eq(3)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '#distance_squared' do
|
13
|
+
it 'returns squared distance between two points' do
|
14
|
+
point2 = Coords::Cartesian3d.new(4, 6, 8)
|
15
|
+
expect(subject.distance_squared(point2)).to eq(50)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#to_s' do
|
20
|
+
it 'returns comma delimited coordinate values' do
|
21
|
+
expect(subject.to_s).to eq('1,2,3')
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '#to_spherical' do
|
26
|
+
it 'returns point in spherical coordinate system' do
|
27
|
+
spherical = subject.to_spherical
|
28
|
+
expect(spherical.radius).to eq(3.7416573867739413)
|
29
|
+
expect(spherical.theta).to eq(0.6405223126794245)
|
30
|
+
expect(spherical.phi).to eq(1.1071487177940904)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '#==' do
|
35
|
+
it 'compares coordinate values equality' do
|
36
|
+
point2 = Coords::Cartesian3d.new(1, 2, 3)
|
37
|
+
expect(subject == point2).to be true
|
38
|
+
expect(subject != point2).to be false
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Coords::Polar do
|
4
|
+
subject { Coords::Polar.new(1, 2) }
|
5
|
+
|
6
|
+
describe '#radius' do
|
7
|
+
it 'returns value of radius' do
|
8
|
+
expect(subject.radius).to eq(1)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '#theta' do
|
13
|
+
it 'returns value of theta' do
|
14
|
+
expect(subject.theta).to eq(2)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#distance_squared' do
|
19
|
+
it 'returns squared distance between two points' do
|
20
|
+
point2 = Coords::Polar.new(4, 6)
|
21
|
+
expect(subject.distance_squared(point2)).to eq(22.229148966908895)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '#distance' do
|
26
|
+
it 'returns distance between two points' do
|
27
|
+
point2 = Coords::Polar.new(4, 6)
|
28
|
+
expect(subject.distance(point2)).to eq(4.714779842888626)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '#to_s' do
|
33
|
+
it 'returns comma delimited radius/theta values' do
|
34
|
+
expect(subject.to_s).to eq('1,2')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '#to_cartesian' do
|
39
|
+
it 'returns point in cartesian coordinate system' do
|
40
|
+
cart = subject.to_cartesian
|
41
|
+
expect(cart.x).to eq(-0.4161468365471424)
|
42
|
+
expect(cart.y).to eq(0.9092974268256817)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe '#==' do
|
47
|
+
it 'compares coordinate values equality' do
|
48
|
+
point2 = Coords::Polar.new(1, 2)
|
49
|
+
expect(subject == point2).to be true
|
50
|
+
expect(subject != point2).to be false
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Coords::Spherical do
|
4
|
+
subject { Coords::Spherical.new(1, 2, 3) }
|
5
|
+
|
6
|
+
describe '#phi' do
|
7
|
+
it 'returns value of phi' do
|
8
|
+
expect(subject.phi).to eq(3)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '#distance_squared' do
|
13
|
+
it 'returns squared distance between two points' do
|
14
|
+
point2 = Coords::Spherical.new(4, 6, 8)
|
15
|
+
expect(subject.distance_squared(point2)).to eq(20.773139100421478)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#to_s' do
|
20
|
+
it 'returns comma delimited radius/theta/phi values' do
|
21
|
+
expect(subject.to_s).to eq('1,2,3')
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '#to_cartesian' do
|
26
|
+
it 'returns point in cartesian coordinate system' do
|
27
|
+
cart = subject.to_cartesian
|
28
|
+
expect(cart.x).to eq(-0.9001976297355174)
|
29
|
+
expect(cart.y).to eq(0.12832006020245673)
|
30
|
+
expect(cart.z).to eq(-0.4161468365471424)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '#==' do
|
35
|
+
it 'compares coordinate values equality' do
|
36
|
+
point2 = Coords::Spherical.new(1, 2, 3)
|
37
|
+
expect(subject == point2).to be true
|
38
|
+
expect(subject != point2).to be false
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Craig Allan
|
@@ -114,6 +114,9 @@ files:
|
|
114
114
|
- lib/coords/spherical.rb
|
115
115
|
- lib/coords/version.rb
|
116
116
|
- spec/lib/coords/cartesian2d_spec.rb
|
117
|
+
- spec/lib/coords/cartesian3d_spec.rb
|
118
|
+
- spec/lib/coords/polar_spec.rb
|
119
|
+
- spec/lib/coords/spherical_spec.rb
|
117
120
|
- spec/spec_helper.rb
|
118
121
|
homepage: https://github.com/ceud/coords
|
119
122
|
licenses:
|
@@ -141,5 +144,8 @@ specification_version: 4
|
|
141
144
|
summary: A small suite of coordinate system classes.
|
142
145
|
test_files:
|
143
146
|
- spec/lib/coords/cartesian2d_spec.rb
|
147
|
+
- spec/lib/coords/cartesian3d_spec.rb
|
148
|
+
- spec/lib/coords/polar_spec.rb
|
149
|
+
- spec/lib/coords/spherical_spec.rb
|
144
150
|
- spec/spec_helper.rb
|
145
151
|
has_rdoc:
|