geometer 0.1.1 → 0.1.2
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/geometer/point.rb +12 -1
- data/lib/geometer/version.rb +1 -1
- data/spec/geometer_spec.rb +34 -8
- 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: 81894d8f09f311bee538aef764e868e35eda2aa5
|
4
|
+
data.tar.gz: e86d15c62527abb38d94a0219749909c68879bbb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 95acd51102759f105a95d83019eb1b54176d0b0dc017731b949f20107c40c3e5eacbb6fd8f17226155c8fa47571000fd34b8a57abc887a7e68051bfa625fe842
|
7
|
+
data.tar.gz: 5d6cd926ce6ce751ebc8d5cb6bbcf23e7813577a15c4720f43db7c3d4be44456bf8f95a6f9da58a9dac95b2064aa19696ca8b3faeab8c5a2f4db77b4283fe7dc
|
data/lib/geometer/point.rb
CHANGED
@@ -4,9 +4,20 @@ module Geometer
|
|
4
4
|
"(#{x},#{y})"
|
5
5
|
end
|
6
6
|
|
7
|
-
def
|
7
|
+
def invert
|
8
8
|
Point.new(-x,-y)
|
9
9
|
end
|
10
|
+
alias_method :-@, :invert
|
11
|
+
|
12
|
+
def scale(sz)
|
13
|
+
Point.new(x*sz,y*sz)
|
14
|
+
end
|
15
|
+
alias_method :*, :scale
|
16
|
+
|
17
|
+
def divide(sz)
|
18
|
+
scale(1.0/sz)
|
19
|
+
end
|
20
|
+
alias_method :/, :divide
|
10
21
|
|
11
22
|
def translate(other_point)
|
12
23
|
dx,dy = *other_point
|
data/lib/geometer/version.rb
CHANGED
data/spec/geometer_spec.rb
CHANGED
@@ -8,14 +8,32 @@ describe Geometer do
|
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
+
describe Point do
|
12
|
+
include PointHelpers
|
13
|
+
let(:a) { coord(0,5) }
|
14
|
+
it 'should invert' do
|
15
|
+
expect(-a).to eq(coord(0,-5))
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should scale' do
|
19
|
+
expect(a*5).to eq(coord(0,25))
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should divide' do
|
23
|
+
expect(a/2).to eq(coord(0,2.5))
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
11
27
|
describe Line do
|
12
28
|
include PointHelpers
|
13
|
-
let(:point_a) { coord(0,3) }
|
14
|
-
let(:point_b) { coord(4,0) }
|
15
29
|
|
16
30
|
describe "measuring the hypotenuse" do
|
17
|
-
|
18
|
-
|
31
|
+
context "of a 3-4-5 triangle" do
|
32
|
+
let(:point_a) { coord(0,3) }
|
33
|
+
let(:point_b) { coord(4,0) }
|
34
|
+
it 'should find the hypotenuse to be 5' do
|
35
|
+
expect(Line.new(point_a,point_b).length).to eq(5)
|
36
|
+
end
|
19
37
|
end
|
20
38
|
|
21
39
|
it 'should find a 1-1-root(2) triangle' do
|
@@ -32,9 +50,17 @@ describe Rectangle do
|
|
32
50
|
let(:origin) { coord(1,1) }
|
33
51
|
let(:dimensions) { dim(2,2) }
|
34
52
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
53
|
+
describe "#area" do
|
54
|
+
it 'should have an area' do
|
55
|
+
expect(rectangle.area).to eq(4)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "#contains?" do
|
60
|
+
it 'should identify points within itself' do
|
61
|
+
expect(rectangle.contains?(coord(1,1))).to eq(true)
|
62
|
+
expect(rectangle.contains?(coord(1,0))).to eq(false)
|
63
|
+
expect(rectangle.contains?(coord(1,-1))).to eq(false)
|
64
|
+
end
|
39
65
|
end
|
40
66
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: geometer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joseph Weissman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03-
|
11
|
+
date: 2016-03-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|