coords 0.1.0 → 0.1.1

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,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ODgxMDZhMWE3NzdhODZkOTljMWVlMWM4NTAwNWY5YjExZGJlNWNhYg==
4
+ ZWJjM2YwYmIzZjQzYmE2NTU5ZWZhOTMyMmExNTIyNTkyNTM3ZjFkYQ==
5
5
  data.tar.gz: !binary |-
6
- OTlmMTNhOWRlN2I3MjlkZjNjZWVkYTAzZGU0M2I3NTJhYWZmNDUyYw==
6
+ NTRkNDNmNDUyY2IzNWE3NjZmMDVkMTJmMzExYzQ5ODVhOTY2MzUzZQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MmQ0Y2FkNWE4MDk4ODgwN2RhYjg1NDM5MTgzMzRmNjA0OGUwYTczM2FhZmY1
10
- MDgxYzUwNmMxNDQ2ZmM1YThlN2U0MzQ5N2MxNmIzZDdlMmY0ZDY2NjlkNDli
11
- Nzk5YTU1MGU2ZWMxMTQwZTY4YTRiMzk5YmQ4NDA2OTBhNWM1YWU=
9
+ MTg4ZGVmYjUyYzUxNWFlNGMwMGUyNzZlNGE2NzdlNzgwN2U0MTFkNThkZTc3
10
+ ZmQxOGRlYmNiYzJlY2IwNmNhYmE5OGJlNDQ1NGFmY2M4ZTFkNWY5OThkNmU3
11
+ ZjI4NGFmZDhjMjhkODkxZDgwYzFmYTNlNTY1MDg4NTY0NDdhNGI=
12
12
  data.tar.gz: !binary |-
13
- YmE4ZDNlZDAzNmZhZDA5OGJmYTQ5ZDMxMzA2Y2M5ZGQwMzI5OTk0MTFlOWNm
14
- ZjVlOGY0YzhlNjU0ZjczOTc4MWI1M2U1N2IzNjM3NzIxNjI0MjVmYTZlYTE1
15
- MTUxODJjM2ZlYmY0MjlhMDYyZTE4MzE1ZDZhZjBlMmZjYmQyNmU=
13
+ ZDljOTM1ODhkMTE3OWIwOGU0ZjlkOGVmMGY1ODBmNzRkYWI1YmNlZjAxZWI0
14
+ ZGFmNGVmZWU1MTJkMmMxMWUyMDAyNThjMDIxNzhmZDU4MmY5Mjk2M2Y1NGM1
15
+ ODI3ZmI0YjM1ZTU2ZDAyMTM5ZGZmZDllNWUxMWNiMzIyNGUwNzg=
data/lib/coords.rb CHANGED
@@ -5,6 +5,7 @@ require "coords/polar"
5
5
  require "coords/spherical"
6
6
 
7
7
  require "coords/shapes/line2d"
8
+ require "coords/shapes/line3d"
8
9
 
9
10
  module Coords
10
11
 
@@ -0,0 +1,27 @@
1
+ module Coords
2
+ module Shapes
3
+ class Line3d < Line2d
4
+
5
+ def initialize(x1, y1, z1, x2, y2, z2)
6
+ @point1 = Coords::Cartesian3d.new(x1, y1, z1)
7
+ @point2 = Coords::Cartesian3d.new(x2, y2, z2)
8
+ end
9
+
10
+ def to_s
11
+ "(#{point1.x.to_s},#{point1.y.to_s},#{point1.z.to_s}),(#{point2.x.to_s},#{point2.y.to_s},#{point2.z.to_s})"
12
+ end
13
+
14
+ def translate(x2, y2, z2)
15
+ translated_line = Line3d.new(point1.x, point1.y, point1.z, point2.x, point2.y, point2.z)
16
+ translated_line.translate!(x2, y2, z2)
17
+ translated_line
18
+ end
19
+
20
+ def translate!(x2, y2, z2)
21
+ point1.translate!(x2, y2, z2)
22
+ point2.translate!(x2, y2, z2)
23
+ end
24
+
25
+ end
26
+ end
27
+ end
@@ -1,3 +1,3 @@
1
1
  module Coords
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -0,0 +1,73 @@
1
+ require 'spec_helper'
2
+
3
+ describe Coords::Shapes::Line3d do
4
+ let(:point1) { Coords::Cartesian3d.new(1, 1, 1) }
5
+ let(:point2) { Coords::Cartesian3d.new(1, 1, 2) }
6
+
7
+ subject { Coords::Shapes::Line3d.new(1, 1, 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),(1,1,2)')
42
+ end
43
+ end
44
+
45
+ describe '#==' do
46
+ it 'compares equality of two lines' do
47
+ equal_line = Coords::Shapes::Line3d.new(1,1,1,1,1,2)
48
+ unequal_line = Coords::Shapes::Line3d.new(1,1,1,2,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, 5)
57
+ expect(subject.point1.x).to eq(1)
58
+ expect(subject.point1.y).to eq(1)
59
+ expect(subject.point1.z).to eq(1)
60
+ expect(subject.point2.x).to eq(1)
61
+ expect(subject.point2.y).to eq(1)
62
+ expect(subject.point2.z).to eq(2)
63
+
64
+ expect(line2.point1.x).to eq(4)
65
+ expect(line2.point1.y).to eq(5)
66
+ expect(line2.point1.z).to eq(6)
67
+ expect(line2.point2.x).to eq(4)
68
+ expect(line2.point2.y).to eq(5)
69
+ expect(line2.point2.z).to eq(7)
70
+ end
71
+ end
72
+
73
+ 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.1.0
4
+ version: 0.1.1
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-19 00:00:00.000000000 Z
11
+ date: 2015-03-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -112,12 +112,14 @@ files:
112
112
  - lib/coords/cartesian3d.rb
113
113
  - lib/coords/polar.rb
114
114
  - lib/coords/shapes/line2d.rb
115
+ - lib/coords/shapes/line3d.rb
115
116
  - lib/coords/spherical.rb
116
117
  - lib/coords/version.rb
117
118
  - spec/lib/coords/cartesian2d_spec.rb
118
119
  - spec/lib/coords/cartesian3d_spec.rb
119
120
  - spec/lib/coords/polar_spec.rb
120
121
  - spec/lib/coords/shapes/line2d_spec.rb
122
+ - spec/lib/coords/shapes/line3d_spec.rb
121
123
  - spec/lib/coords/spherical_spec.rb
122
124
  - spec/lib/coords_spec.rb
123
125
  - spec/spec_helper.rb
@@ -150,6 +152,7 @@ test_files:
150
152
  - spec/lib/coords/cartesian3d_spec.rb
151
153
  - spec/lib/coords/polar_spec.rb
152
154
  - spec/lib/coords/shapes/line2d_spec.rb
155
+ - spec/lib/coords/shapes/line3d_spec.rb
153
156
  - spec/lib/coords/spherical_spec.rb
154
157
  - spec/lib/coords_spec.rb
155
158
  - spec/spec_helper.rb