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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2849b8793d903cd5b5435ef01744b5bd792603ad
4
- data.tar.gz: a32e790ce5e5fbba6b683ab3c7127ff8d3ed6b88
3
+ metadata.gz: d76d64722dcae03f213988afda85f2c22af60d8a
4
+ data.tar.gz: a37ea6056ecae70890ecedb93dd3567570086880
5
5
  SHA512:
6
- metadata.gz: c51450ad8eed5bd725cb33f0c487ee4570d06b8febf616c45bd64f01bb8c0f535f7d195094db5961b1e9f467776e967e80f0bb48e0691793f2264b17d24bce5e
7
- data.tar.gz: e5018d57fba2c6ed8127998022b6729d2d5011823c1d65f4fd8431315b42513cb9b9528acffd3516f5229d752c4ab2d9ae1fa9752a5871cbb0e1360577fe2d87
6
+ metadata.gz: 196c2c9d6b1c294e8f5d47cf2d22e4922508a779c0b209926e72a8197a7f0c72bb0841984ac87295588bd14c6a89193a814837c3c7942c2e11fec72372f92581
7
+ data.tar.gz: acd1157d49e7d7d9bfe0c0f9f9f9df0acea22be968ac2de03e126bdb371786b4f3593581a7c06721b55e2272e24f216ad208580ff7f4424db21b006c49cb0fbf
@@ -24,5 +24,9 @@ module Coords
24
24
 
25
25
  Spherical.new(radius, theta, phi)
26
26
  end
27
+
28
+ def ==(point)
29
+ x == point.x && y == point.y && z == point.z
30
+ end
27
31
  end
28
32
  end
data/lib/coords/polar.rb CHANGED
@@ -36,5 +36,9 @@ module Coords
36
36
 
37
37
  Cartesian2d.new(x, y)
38
38
  end
39
+
40
+ def ==(point)
41
+ radius == point.radius && theta == point.theta
42
+ end
39
43
  end
40
44
  end
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Coords
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -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.3
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: