geometry 6.2 → 6.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +4 -0
- data/README.markdown +58 -44
- data/geometry.gemspec +1 -1
- data/lib/geometry.rb +1 -0
- data/lib/geometry/annulus.rb +74 -0
- data/lib/geometry/circle.rb +6 -0
- data/lib/geometry/edge.rb +6 -3
- data/lib/geometry/obround.rb +6 -0
- data/lib/geometry/point.rb +40 -3
- data/lib/geometry/point_iso.rb +133 -0
- data/lib/geometry/point_one.rb +131 -0
- data/lib/geometry/point_zero.rb +19 -1
- data/lib/geometry/polygon.rb +6 -6
- data/lib/geometry/polyline.rb +4 -0
- data/lib/geometry/rectangle.rb +6 -0
- data/lib/geometry/regular_polygon.rb +59 -52
- data/lib/geometry/rotation.rb +1 -0
- data/lib/geometry/size.rb +41 -11
- data/lib/geometry/size_one.rb +85 -0
- data/lib/geometry/size_zero.rb +8 -0
- data/lib/geometry/square.rb +6 -0
- data/lib/geometry/triangle.rb +21 -0
- data/test/geometry/annulus.rb +69 -0
- data/test/geometry/circle.rb +36 -0
- data/test/geometry/obround.rb +5 -0
- data/test/geometry/point.rb +40 -5
- data/test/geometry/point_iso.rb +189 -0
- data/test/geometry/point_one.rb +199 -0
- data/test/geometry/point_zero.rb +23 -2
- data/test/geometry/polyline.rb +4 -0
- data/test/geometry/rectangle.rb +4 -0
- data/test/geometry/regular_polygon.rb +57 -11
- data/test/geometry/rotation.rb +6 -0
- data/test/geometry/size.rb +31 -10
- data/test/geometry/size_one.rb +155 -0
- data/test/geometry/size_zero.rb +8 -0
- data/test/geometry/square.rb +4 -0
- data/test/geometry/triangle.rb +16 -0
- metadata +15 -2
@@ -0,0 +1,155 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'geometry/size_one'
|
3
|
+
|
4
|
+
describe Geometry::SizeOne do
|
5
|
+
Size = Geometry::Size
|
6
|
+
|
7
|
+
let(:one) { Geometry::SizeOne.new }
|
8
|
+
|
9
|
+
describe 'arithmetic' do
|
10
|
+
let(:left) { Size[1,2] }
|
11
|
+
let(:right) { Size[3,4] }
|
12
|
+
|
13
|
+
it 'must have +@' do
|
14
|
+
(+one).must_be :eql?, 1
|
15
|
+
(+one).must_be_instance_of(Geometry::SizeOne)
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'must have unary negation' do
|
19
|
+
(-one).must_be :eql?, -1
|
20
|
+
# (-one).must_be_instance_of(Geometry::SizeOne)
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'must add a number' do
|
24
|
+
(one + 3).must_equal 4
|
25
|
+
(3 + one).must_equal 4
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'return a Size when adding two Sizes' do
|
29
|
+
(one + right).must_be_kind_of Size
|
30
|
+
(left + one).must_be_kind_of Size
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'must return a Size when adding an array' do
|
34
|
+
(one + [5,6]).must_equal [6,7]
|
35
|
+
# ([5,6] + one).must_equal [6,7]
|
36
|
+
end
|
37
|
+
|
38
|
+
describe 'when subtracting' do
|
39
|
+
it 'must subtract a number' do
|
40
|
+
(one - 3).must_equal -2
|
41
|
+
(3 - one).must_equal 2
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'return a Size when subtracting two Size' do
|
45
|
+
(one - right).must_equal Size[-2,-3]
|
46
|
+
(left - one).must_equal Size[0,1]
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'must return a Size when subtracting an array' do
|
50
|
+
(one - [5,6]).must_equal [-4, -5]
|
51
|
+
# ([5,6] - one).must_equal [6,7]
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'must multiply by a scalar' do
|
56
|
+
(one * 3).must_equal 3
|
57
|
+
(one * 3.0).must_equal 3.0
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'must refuse to multiply by a Size' do
|
61
|
+
-> { one * Size[1,2] }.must_raise Geometry::OperationNotDefined
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'must refuse to multiply by a Vector' do
|
65
|
+
-> { one * Vector[1, 2] }.must_raise Geometry::OperationNotDefined
|
66
|
+
end
|
67
|
+
|
68
|
+
describe 'division' do
|
69
|
+
it 'must divide by a scalar' do
|
70
|
+
(one / 3).must_equal 1/3
|
71
|
+
(one / 4.0).must_equal 1/4.0
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'must raise an exception when divided by 0' do
|
75
|
+
-> { one / 0 }.must_raise ZeroDivisionError
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'must raise an exception for Sizes' do
|
79
|
+
-> { one / Size[1,2] }.must_raise Geometry::OperationNotDefined
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'must raise an exception for Vectors' do
|
83
|
+
-> { one / Vector[1,2] }.must_raise Geometry::OperationNotDefined
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe 'coercion' do
|
89
|
+
it 'must coerce Arrays into Sizes' do
|
90
|
+
one.coerce([3,4]).must_equal [Size[3,4], Size[1,1]]
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'must coerce Vectors into Vectors' do
|
94
|
+
one.coerce(Vector[3,4]).must_equal [Vector[3,4], Vector[1,1]]
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'must coerce Size into Size' do
|
98
|
+
one.coerce(Size[5,6]).must_equal [Size[5,6], Size[1,1]]
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
describe 'comparison' do
|
103
|
+
let(:one) { Geometry::SizeOne.new }
|
104
|
+
|
105
|
+
it 'must be equal to 1 and 1.0' do
|
106
|
+
one.must_be :eql?, 1
|
107
|
+
one.must_be :eql?, 1.0
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'must not be equal to a non-one number' do
|
111
|
+
0.wont_equal one
|
112
|
+
3.14.wont_equal one
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'must be equal to an Array of ones' do
|
116
|
+
one.must_be :==, [1,1]
|
117
|
+
one.must_be :eql?, [1,1]
|
118
|
+
[1,1].must_equal one
|
119
|
+
end
|
120
|
+
|
121
|
+
it 'must not be equal to a non-one Array' do
|
122
|
+
one.wont_equal [3,2]
|
123
|
+
[3,2].wont_equal one
|
124
|
+
end
|
125
|
+
|
126
|
+
it 'must be equal to a Size of ones' do
|
127
|
+
one.must_be :==, Size[1,1]
|
128
|
+
one.must_be :eql?, Size[1,1]
|
129
|
+
Size[1,1].must_equal one
|
130
|
+
end
|
131
|
+
|
132
|
+
it 'must not be equal to a non-one Size' do
|
133
|
+
one.wont_equal Size[3,2]
|
134
|
+
Size[3,2].wont_equal one
|
135
|
+
end
|
136
|
+
|
137
|
+
it 'must be equal to an Vector of onees' do
|
138
|
+
one.must_be :eql?, Vector[1,1]
|
139
|
+
Vector[1,1].must_equal one
|
140
|
+
end
|
141
|
+
|
142
|
+
it 'must not be equal to a non-one Vector' do
|
143
|
+
one.wont_equal Vector[3,2]
|
144
|
+
Vector[3,2].wont_equal one
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
describe 'when enumerating' do
|
149
|
+
it 'must have a first method' do
|
150
|
+
one.first.must_equal 1
|
151
|
+
one.first(1).must_equal [1]
|
152
|
+
one.first(5).must_equal [1,1,1,1,1]
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
data/test/geometry/size_zero.rb
CHANGED
@@ -150,4 +150,12 @@ describe Geometry::SizeZero do
|
|
150
150
|
Vector[3,2].wont_equal zero
|
151
151
|
end
|
152
152
|
end
|
153
|
+
|
154
|
+
describe 'when enumerating' do
|
155
|
+
it 'must have a first method' do
|
156
|
+
zero.first.must_equal 0
|
157
|
+
zero.first(1).must_equal [0]
|
158
|
+
zero.first(5).must_equal [0,0,0,0,0]
|
159
|
+
end
|
160
|
+
end
|
153
161
|
end
|
data/test/geometry/square.rb
CHANGED
@@ -61,6 +61,10 @@ describe Geometry::Square do
|
|
61
61
|
describe "properties" do
|
62
62
|
subject { Square.new from:[2,3], to:[3,4] }
|
63
63
|
|
64
|
+
it 'must always be closed' do
|
65
|
+
subject.closed?.must_equal true
|
66
|
+
end
|
67
|
+
|
64
68
|
it "must have an origin accessor" do
|
65
69
|
subject.origin.must_equal Point[2,3]
|
66
70
|
end
|
data/test/geometry/triangle.rb
CHANGED
@@ -4,6 +4,10 @@ require 'geometry/triangle'
|
|
4
4
|
describe Geometry::Triangle do
|
5
5
|
Triangle = Geometry::Triangle
|
6
6
|
|
7
|
+
it 'must always be closed' do
|
8
|
+
Triangle.new([0,0], [0,1], [1,0]).closed?.must_equal true
|
9
|
+
end
|
10
|
+
|
7
11
|
describe "when constructed with 3 points" do
|
8
12
|
let(:triangle) { Triangle.new [0,0], [0,1], [1,0] }
|
9
13
|
|
@@ -15,6 +19,18 @@ describe Geometry::Triangle do
|
|
15
19
|
it "must have a points accessor" do
|
16
20
|
triangle.points.must_equal [Point[0,0], Point[0,1], Point[1,0]]
|
17
21
|
end
|
22
|
+
|
23
|
+
it 'must know the max' do
|
24
|
+
triangle.max.must_equal Point[1,1]
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'must know the min' do
|
28
|
+
triangle.min.must_equal Point[0,0]
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'must know the min and the max' do
|
32
|
+
triangle.minmax.must_equal [Point[0,0], Point[1,1]]
|
33
|
+
end
|
18
34
|
end
|
19
35
|
|
20
36
|
describe "when constructed with a point and a leg length" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: geometry
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '6.
|
4
|
+
version: '6.3'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandon Fosdick
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-08-17 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Geometric primitives and algorithms for Ruby
|
14
14
|
email:
|
@@ -18,12 +18,14 @@ extensions: []
|
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
20
|
- .gitignore
|
21
|
+
- .travis.yml
|
21
22
|
- Gemfile
|
22
23
|
- LICENSE
|
23
24
|
- README.markdown
|
24
25
|
- Rakefile
|
25
26
|
- geometry.gemspec
|
26
27
|
- lib/geometry.rb
|
28
|
+
- lib/geometry/annulus.rb
|
27
29
|
- lib/geometry/arc.rb
|
28
30
|
- lib/geometry/circle.rb
|
29
31
|
- lib/geometry/cluster_factory.rb
|
@@ -32,6 +34,8 @@ files:
|
|
32
34
|
- lib/geometry/obround.rb
|
33
35
|
- lib/geometry/path.rb
|
34
36
|
- lib/geometry/point.rb
|
37
|
+
- lib/geometry/point_iso.rb
|
38
|
+
- lib/geometry/point_one.rb
|
35
39
|
- lib/geometry/point_zero.rb
|
36
40
|
- lib/geometry/polygon.rb
|
37
41
|
- lib/geometry/polyline.rb
|
@@ -39,6 +43,7 @@ files:
|
|
39
43
|
- lib/geometry/regular_polygon.rb
|
40
44
|
- lib/geometry/rotation.rb
|
41
45
|
- lib/geometry/size.rb
|
46
|
+
- lib/geometry/size_one.rb
|
42
47
|
- lib/geometry/size_zero.rb
|
43
48
|
- lib/geometry/square.rb
|
44
49
|
- lib/geometry/transformation.rb
|
@@ -46,6 +51,7 @@ files:
|
|
46
51
|
- lib/geometry/triangle.rb
|
47
52
|
- lib/geometry/vector.rb
|
48
53
|
- test/geometry.rb
|
54
|
+
- test/geometry/annulus.rb
|
49
55
|
- test/geometry/arc.rb
|
50
56
|
- test/geometry/circle.rb
|
51
57
|
- test/geometry/edge.rb
|
@@ -53,6 +59,8 @@ files:
|
|
53
59
|
- test/geometry/obround.rb
|
54
60
|
- test/geometry/path.rb
|
55
61
|
- test/geometry/point.rb
|
62
|
+
- test/geometry/point_iso.rb
|
63
|
+
- test/geometry/point_one.rb
|
56
64
|
- test/geometry/point_zero.rb
|
57
65
|
- test/geometry/polygon.rb
|
58
66
|
- test/geometry/polyline.rb
|
@@ -60,6 +68,7 @@ files:
|
|
60
68
|
- test/geometry/regular_polygon.rb
|
61
69
|
- test/geometry/rotation.rb
|
62
70
|
- test/geometry/size.rb
|
71
|
+
- test/geometry/size_one.rb
|
63
72
|
- test/geometry/size_zero.rb
|
64
73
|
- test/geometry/square.rb
|
65
74
|
- test/geometry/transformation.rb
|
@@ -91,6 +100,7 @@ specification_version: 4
|
|
91
100
|
summary: Geometric primitives and algoritms
|
92
101
|
test_files:
|
93
102
|
- test/geometry.rb
|
103
|
+
- test/geometry/annulus.rb
|
94
104
|
- test/geometry/arc.rb
|
95
105
|
- test/geometry/circle.rb
|
96
106
|
- test/geometry/edge.rb
|
@@ -98,6 +108,8 @@ test_files:
|
|
98
108
|
- test/geometry/obround.rb
|
99
109
|
- test/geometry/path.rb
|
100
110
|
- test/geometry/point.rb
|
111
|
+
- test/geometry/point_iso.rb
|
112
|
+
- test/geometry/point_one.rb
|
101
113
|
- test/geometry/point_zero.rb
|
102
114
|
- test/geometry/polygon.rb
|
103
115
|
- test/geometry/polyline.rb
|
@@ -105,6 +117,7 @@ test_files:
|
|
105
117
|
- test/geometry/regular_polygon.rb
|
106
118
|
- test/geometry/rotation.rb
|
107
119
|
- test/geometry/size.rb
|
120
|
+
- test/geometry/size_one.rb
|
108
121
|
- test/geometry/size_zero.rb
|
109
122
|
- test/geometry/square.rb
|
110
123
|
- test/geometry/transformation.rb
|