coords 0.0.7 → 0.0.8

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: 0ef9b5e2c1c4abd073f48762963efacecefaf883
4
- data.tar.gz: 93f89db2a8d99ffedfaf63490a3a496f5f35501d
3
+ metadata.gz: 71f88964e9d3049a37804c1c9db1401aefb8f163
4
+ data.tar.gz: 2bcbd911f75fa84b05482d8994ee1956bf53dca7
5
5
  SHA512:
6
- metadata.gz: 0584d5390b17ca055081f9b1ef8dbe340971aa2e067be870b6f55b01ffa17e20ef6d2714bfe91d780683c3381bb65723503d90d189d48aec2d446a0b01e45d8b
7
- data.tar.gz: b0791aab99ca15f1ba2c88935ef4844cce8ab5e9d4b1050f400e7a085fb0888072284a2df4587085e9ec028f5675a34ea43b8be8ef84ada67f0a873096e19ad2
6
+ metadata.gz: 28d4fe183b98a0b10c3ffb8e44035beb0042235722e98fa1f3a9c922bc66a38553332c584fed6db370fe18da846777fa3e824207b2851f882bf9ad24e3272471
7
+ data.tar.gz: a8077a0ea3ae2a4af4e8a1cfd09e18356c9cd1f920b063450cd649b52421bea3e31fa5b8c3798668fe6e29edc7dd8e1dc737d3ecc486d6982f2c30ba3a2d1805
@@ -30,11 +30,11 @@ module Coords
30
30
  radius = Math.sqrt((x ** 2) + (y ** 2));
31
31
  theta = Math.atan2(y, x);
32
32
 
33
- Polar.new(radius.round(15), theta.round(15))
33
+ Polar.new(radius.round(12), theta.round(12))
34
34
  end
35
35
 
36
36
  def ==(point)
37
- x.round(15) == point.x.round(15) && y.round(15) == point.y.round(15)
37
+ x.round(12) == point.x.round(12) && y.round(12) == point.y.round(12)
38
38
  end
39
39
 
40
40
  def translate(x2, y2)
@@ -56,8 +56,8 @@ module Coords
56
56
 
57
57
  def rotate!(theta)
58
58
  tmp_x = x
59
- @x = ((x * Math.cos(theta)) - (y * Math.sin(theta))).round(15)
60
- @y = ((tmp_x * Math.sin(theta)) + (y * Math.cos(theta))).round(15)
59
+ @x = ((x * Math.cos(theta)) - (y * Math.sin(theta))).round(12)
60
+ @y = ((tmp_x * Math.sin(theta)) + (y * Math.cos(theta))).round(12)
61
61
  end
62
62
 
63
63
  def reflect(type = 'origin')
@@ -23,15 +23,17 @@ module Coords
23
23
  theta = Math.acos(z / radius)
24
24
  phi = Math.atan2(y, x)
25
25
 
26
- Spherical.new(radius, theta, phi)
26
+ Spherical.new(radius.round(12), theta.round(12), phi.round(12))
27
27
  end
28
28
 
29
29
  def ==(point)
30
- x.round(15) == point.x.round(15) && y.round(15) == point.y.round(15) && z.round(15) == point.z.round(15)
30
+ x.round(12) == point.x.round(12) && y.round(12) == point.y.round(12) && z.round(12) == point.z.round(12)
31
31
  end
32
32
 
33
33
  def translate(x2, y2, z2)
34
- Cartesian3d.new(x + x2, y + y2, z + z2)
34
+ translated_point = Cartesian3d.new(x, y, z)
35
+ translated_point.translate!(x2, y2, z2)
36
+ translated_point
35
37
  end
36
38
 
37
39
  def translate!(x2, y2, z2)
@@ -39,5 +41,32 @@ module Coords
39
41
  @z += z2
40
42
  end
41
43
 
44
+ def rotate(rZ = 0, rX = 0, rY = 0)
45
+ rotated_point = Cartesian3d.new(x, y, z)
46
+ rotated_point.rotate!(rZ, rX, rY)
47
+ rotated_point
48
+ end
49
+
50
+ def rotate!(rZ = 0, rX = 0, rY = 0)
51
+ d = Math.hypot(y, x)
52
+ theta = Math.atan2(y, x) + rZ
53
+ @x = d * Math.cos(theta)
54
+ @y = d * Math.sin(theta)
55
+
56
+ d = Math.hypot(y, z)
57
+ theta = Math.atan2(z, y) + rX
58
+ @y = d * Math.cos(theta)
59
+ @z = d * Math.sin(theta)
60
+
61
+ d = Math.hypot(x, z)
62
+ theta = Math.atan2(x, z) + rY
63
+ @z = d * Math.cos(theta)
64
+ @x = d * Math.sin(theta)
65
+
66
+ @x = x.round(12)
67
+ @y = y.round(12)
68
+ @z = z.round(12)
69
+ end
70
+
42
71
  end
43
72
  end
data/lib/coords/polar.rb CHANGED
@@ -35,11 +35,11 @@ module Coords
35
35
  x = radius * Math.cos(theta)
36
36
  y = radius * Math.sin(theta)
37
37
 
38
- Cartesian2d.new(x.round(15), y.round(15))
38
+ Cartesian2d.new(x.round(12), y.round(12))
39
39
  end
40
40
 
41
41
  def ==(point)
42
- radius.round(15) == point.radius.round(15) && theta.round(15) == point.theta.round(15)
42
+ radius.round(12) == point.radius.round(12) && theta.round(12) == point.theta.round(12)
43
43
  end
44
44
 
45
45
  end
@@ -34,7 +34,7 @@ module Coords
34
34
  end
35
35
 
36
36
  def ==(point)
37
- radius.round(15) == point.radius.round(15) && theta.round(15) == point.theta.round(15) && phi.round(15) == point.phi.round(15)
37
+ radius.round(12) == point.radius.round(12) && theta.round(12) == point.theta.round(12) && phi.round(12) == point.phi.round(12)
38
38
  end
39
39
 
40
40
  end
@@ -1,3 +1,3 @@
1
1
  module Coords
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
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
@@ -38,8 +38,8 @@ describe Coords::Cartesian2d do
38
38
  describe '#to_polar' do
39
39
  it 'returns point in polar coordinate system' do
40
40
  polar = subject.to_polar
41
- expect(polar.radius).to eq(2.23606797749979)
42
- expect(polar.theta).to eq(1.10714871779409)
41
+ expect(polar.radius).to eq(2.2360679775)
42
+ expect(polar.theta).to eq(1.107148717794)
43
43
  end
44
44
  end
45
45
 
@@ -61,15 +61,6 @@ describe Coords::Cartesian2d do
61
61
  end
62
62
  end
63
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
64
  describe '#rotate' do
74
65
  it 'rotates values to new point' do
75
66
  point2 = subject.rotate(Coords.radians(90))
@@ -80,15 +71,6 @@ describe Coords::Cartesian2d do
80
71
  end
81
72
  end
82
73
 
83
- # describe '#rotate!' do
84
- # it 'rotates values of original point' do
85
- # point2 = Coords::Cartesian2d.new(1, 2)
86
- # point2.rotate!(Coords.radians(90))
87
- # expect(point2.x).to eq(-2)
88
- # expect(point2.y).to eq(1)
89
- # end
90
- # end
91
-
92
74
  describe '#reflect' do
93
75
  it 'reflects values to new point by origin' do
94
76
  point2 = subject.reflect('origin')
@@ -25,9 +25,9 @@ describe Coords::Cartesian3d do
25
25
  describe '#to_spherical' do
26
26
  it 'returns point in spherical coordinate system' do
27
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)
28
+ expect(spherical.radius).to eq(3.741657386774)
29
+ expect(spherical.theta).to eq(0.640522312679)
30
+ expect(spherical.phi).to eq(1.107148717794)
31
31
  end
32
32
  end
33
33
 
@@ -51,13 +51,15 @@ describe Coords::Cartesian3d do
51
51
  end
52
52
  end
53
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)
54
+ describe '#rotate' do
55
+ it 'rotates values to new point' do
56
+ point2 = subject.rotate(Coords.radians(90), Coords.radians(90), Coords.radians(90))
57
+ expect(subject.x).to eq(1)
58
+ expect(subject.y).to eq(2)
59
+ expect(subject.z).to eq(3)
60
+ expect(point2.x).to eq(1)
61
+ expect(point2.y).to eq(-3)
62
+ expect(point2.z).to eq(2)
61
63
  end
62
64
  end
63
65
  end
@@ -38,8 +38,8 @@ describe Coords::Polar do
38
38
  describe '#to_cartesian' do
39
39
  it 'returns point in cartesian coordinate system' do
40
40
  cart = subject.to_cartesian
41
- expect(cart.x).to eq(-0.416146836547142)
42
- expect(cart.y).to eq(0.909297426825682)
41
+ expect(cart.x).to eq(-0.416146836547)
42
+ expect(cart.y).to eq(0.909297426826)
43
43
  end
44
44
  end
45
45
 
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.7
4
+ version: 0.0.8
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-14 00:00:00.000000000 Z
11
+ date: 2015-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler