geometry 6.5 → 6.6
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 +5 -13
- data/.github/workflows/ruby.yml +21 -0
- data/Gemfile +3 -0
- data/README.markdown +1 -2
- data/geometry.gemspec +5 -1
- data/lib/geometry/annulus.rb +2 -2
- data/lib/geometry/arc.rb +72 -1
- data/lib/geometry/edge.rb +21 -4
- data/lib/geometry/line.rb +2 -2
- data/lib/geometry/obround.rb +1 -2
- data/lib/geometry/path.rb +27 -0
- data/lib/geometry/point.rb +21 -6
- data/lib/geometry/point_iso.rb +0 -2
- data/lib/geometry/point_one.rb +0 -2
- data/lib/geometry/point_zero.rb +0 -1
- data/lib/geometry/polygon.rb +13 -12
- data/lib/geometry/polyline.rb +6 -6
- data/lib/geometry/rectangle.rb +12 -12
- data/lib/geometry/rotation.rb +5 -3
- data/lib/geometry/size.rb +1 -3
- data/lib/geometry/square.rb +13 -11
- data/lib/geometry/transformation/composition.rb +1 -1
- data/lib/geometry/triangle.rb +1 -1
- data/test/geometry/arc.rb +98 -0
- data/test/geometry/circle.rb +3 -3
- data/test/geometry/edge.rb +16 -2
- data/test/geometry/line.rb +3 -3
- data/test/geometry/path.rb +16 -0
- data/test/geometry/point.rb +18 -0
- data/test/geometry/point_iso.rb +21 -21
- data/test/geometry/point_one.rb +1 -1
- data/test/geometry/point_zero.rb +1 -1
- data/test/geometry/polygon.rb +1 -1
- data/test/geometry/rectangle.rb +6 -1
- data/test/geometry/rotation.rb +1 -1
- data/test/geometry/size_one.rb +1 -1
- data/test/geometry/size_zero.rb +1 -1
- data/test/geometry/square.rb +15 -10
- data/test/geometry/transformation.rb +1 -1
- data/test/geometry/vector.rb +1 -1
- metadata +63 -10
- data/.travis.yml +0 -12
data/lib/geometry/square.rb
CHANGED
@@ -16,10 +16,6 @@ The {Square} class cluster is like the {Rectangle} class cluster, but not longer
|
|
16
16
|
class Square
|
17
17
|
include ClusterFactory
|
18
18
|
|
19
|
-
# @!attribute origin
|
20
|
-
# @return [Point] The {Square}'s origin
|
21
|
-
attr_reader :origin
|
22
|
-
|
23
19
|
# @!attribute points
|
24
20
|
# @return [Array<Point>] the corner {Point}s of the {Square} in counter-clockwise order
|
25
21
|
attr_reader :points
|
@@ -101,15 +97,16 @@ The {Square} class cluster is like the {Rectangle} class cluster, but not longer
|
|
101
97
|
[self.min, self.max]
|
102
98
|
end
|
103
99
|
|
104
|
-
#
|
105
|
-
#
|
100
|
+
# @!attribute origin
|
101
|
+
# @return [Point] The {Square}'s origin (lower-left corner)
|
106
102
|
def origin
|
107
103
|
@points.first
|
108
104
|
end
|
109
105
|
|
106
|
+
# @return [Array<Point>] The {Square}'s four points (clockwise)
|
110
107
|
def points
|
111
108
|
p0, p1 = *@points
|
112
|
-
[p0, Point[
|
109
|
+
[p0, Point[p0.x, p1.y], p1, Point[p1.x, p0.y]]
|
113
110
|
end
|
114
111
|
|
115
112
|
def height
|
@@ -122,6 +119,11 @@ The {Square} class cluster is like the {Rectangle} class cluster, but not longer
|
|
122
119
|
max.x - min.x
|
123
120
|
end
|
124
121
|
# @endgroup
|
122
|
+
|
123
|
+
# @return [Path] A closed {Path} that traces the boundary of the {Square} clockwise, starting from the lower-left
|
124
|
+
def path
|
125
|
+
Path.new(*self.points, self.points.first)
|
126
|
+
end
|
125
127
|
end
|
126
128
|
|
127
129
|
# A {Square} created with a center point and a size
|
@@ -166,7 +168,7 @@ The {Square} class cluster is like the {Rectangle} class cluster, but not longer
|
|
166
168
|
end
|
167
169
|
|
168
170
|
# @attribute [r] points
|
169
|
-
# @return [Array<Point>] The {Square}'s four points (
|
171
|
+
# @return [Array<Point>] The {Square}'s four points (clockwise)
|
170
172
|
def points
|
171
173
|
half_size = @size/2
|
172
174
|
minx = @center.x - half_size
|
@@ -174,7 +176,7 @@ The {Square} class cluster is like the {Rectangle} class cluster, but not longer
|
|
174
176
|
miny = @center.y - half_size
|
175
177
|
maxy = @center.y + half_size
|
176
178
|
|
177
|
-
[Point[minx,miny], Point[
|
179
|
+
[Point[minx,miny], Point[minx, maxy], Point[maxx, maxy], Point[maxx,miny]]
|
178
180
|
end
|
179
181
|
|
180
182
|
def height
|
@@ -224,14 +226,14 @@ The {Square} class cluster is like the {Rectangle} class cluster, but not longer
|
|
224
226
|
end
|
225
227
|
|
226
228
|
# @attribute [r] points
|
227
|
-
# @return [Array<Point>] The {Square}'s four points (
|
229
|
+
# @return [Array<Point>] The {Square}'s four points (clockwise)
|
228
230
|
def points
|
229
231
|
minx = origin.x
|
230
232
|
maxx = origin.x + size
|
231
233
|
miny = origin.y
|
232
234
|
maxy = origin.y + size
|
233
235
|
|
234
|
-
[origin, Point[
|
236
|
+
[origin, Point[minx, maxy], Point[maxx, maxy], Point[maxx,miny]]
|
235
237
|
end
|
236
238
|
|
237
239
|
# @return [Number] The size of the {Square} along the y-axis
|
@@ -32,7 +32,7 @@ module Geometry
|
|
32
32
|
# @endgroup
|
33
33
|
|
34
34
|
def transform(point)
|
35
|
-
transformations.reverse.reduce(point) {|
|
35
|
+
transformations.reverse.reduce(point) {|_point, transformation| transformation.transform(_point) }
|
36
36
|
end
|
37
37
|
end
|
38
38
|
end
|
data/lib/geometry/triangle.rb
CHANGED
@@ -30,7 +30,7 @@ An isoscoles right {Triangle} created with an origin and leg length
|
|
30
30
|
# @param [Number] height The length of the {Triangle}'s vertical leg
|
31
31
|
def self.new(*args)
|
32
32
|
if args.size == 3
|
33
|
-
ScaleneTriangle.new
|
33
|
+
ScaleneTriangle.new(*args)
|
34
34
|
elsif args.size == 2
|
35
35
|
RightTriangle.new args[0], args[1], args[1]
|
36
36
|
end
|
data/test/geometry/arc.rb
CHANGED
@@ -23,3 +23,101 @@ describe Geometry::Arc do
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
26
|
+
|
27
|
+
describe Geometry::ThreePointArc do
|
28
|
+
it 'must have an ending angle' do
|
29
|
+
arc = Geometry::ThreePointArc.new([0,0], [1,0], [0,1])
|
30
|
+
arc.end_angle.must_equal Math::PI/2
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'must have a radius' do
|
34
|
+
arc = Geometry::ThreePointArc.new([0,0], [1,0], [0,1])
|
35
|
+
arc.radius.must_equal 1
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'must have an starting angle' do
|
39
|
+
arc = Geometry::ThreePointArc.new([0,0], [1,0], [0,1])
|
40
|
+
arc.start_angle.must_equal 0
|
41
|
+
end
|
42
|
+
|
43
|
+
describe 'max' do
|
44
|
+
# Cosine and sine of a 22.5 degree angle
|
45
|
+
let(:cos) { 0.9239556995 }
|
46
|
+
let(:sin) { 0.3824994973 }
|
47
|
+
let(:radius) { 1.0000000000366434 }
|
48
|
+
|
49
|
+
it 'must handle an Arc entirely in quadrant 1' do
|
50
|
+
arc = Geometry::ThreePointArc.new([0,0], [cos,sin], [sin,cos])
|
51
|
+
arc.max.must_equal Point[cos,cos]
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'must handle a counterclockwise Arc from quadrant 1 to quadrant 2' do
|
55
|
+
arc = Geometry::ThreePointArc.new([0,0], [cos,sin], [-cos,sin])
|
56
|
+
arc.max.must_equal Point[cos,radius]
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'must handle a counterclockwise Arc from quadrant 4 to quadrant 1' do
|
60
|
+
arc = Geometry::ThreePointArc.new([0,0], [sin,-cos], [sin,cos])
|
61
|
+
arc.max.must_equal Point[radius,cos]
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'must handle a counterclockwise Arc from quadrant 3 to quadrant 2' do
|
65
|
+
arc = Geometry::ThreePointArc.new([0,0], [-cos,-sin], [-cos,sin])
|
66
|
+
arc.max.must_equal Point[radius,radius]
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe 'min' do
|
71
|
+
# Cosine and sine of a 22.5 degree angle
|
72
|
+
let(:cos) { 0.9239556995 }
|
73
|
+
let(:sin) { 0.3824994973 }
|
74
|
+
let(:radius) { 1.0000000000366434 }
|
75
|
+
|
76
|
+
it 'must handle an Arc entirely in quadrant 1' do
|
77
|
+
arc = Geometry::ThreePointArc.new([0,0], [cos,sin], [sin,cos])
|
78
|
+
arc.min.must_equal Point[sin,sin]
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'must handle a counterclockwise Arc from quadrant 1 to quadrant 2' do
|
82
|
+
arc = Geometry::ThreePointArc.new([0,0], [cos,sin], [-cos,sin])
|
83
|
+
arc.min.must_equal Point[-cos,sin]
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'must handle a counterclockwise Arc from quadrant 4 to quadrant 1' do
|
87
|
+
arc = Geometry::ThreePointArc.new([0,0], [sin,-cos], [sin,cos])
|
88
|
+
arc.min.must_equal Point[sin,-cos]
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'must handle a counterclockwise Arc from quadrant 3 to quadrant 2' do
|
92
|
+
arc = Geometry::ThreePointArc.new([0,0], [-cos,-sin], [-cos,sin])
|
93
|
+
arc.min.must_equal Point[-cos,-radius]
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
describe 'minmax' do
|
98
|
+
# Cosine and sine of a 22.5 degree angle
|
99
|
+
let(:cos) { 0.9239556995 }
|
100
|
+
let(:sin) { 0.3824994973 }
|
101
|
+
let(:radius) { 1.0000000000366434 }
|
102
|
+
|
103
|
+
it 'must handle an Arc entirely in quadrant 1' do
|
104
|
+
arc = Geometry::ThreePointArc.new([0,0], [cos,sin], [sin,cos])
|
105
|
+
arc.minmax.must_equal [Point[sin,sin], Point[cos,cos]]
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'must handle a counterclockwise Arc from quadrant 1 to quadrant 2' do
|
109
|
+
arc = Geometry::ThreePointArc.new([0,0], [cos,sin], [-cos,sin])
|
110
|
+
arc.minmax.must_equal [Point[-cos,sin], Point[cos,radius]]
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'must handle a counterclockwise Arc from quadrant 4 to quadrant 1' do
|
114
|
+
arc = Geometry::ThreePointArc.new([0,0], [sin,-cos], [sin,cos])
|
115
|
+
arc.minmax.must_equal [Point[sin,-cos], Point[radius,cos]]
|
116
|
+
end
|
117
|
+
|
118
|
+
it 'must handle a counterclockwise Arc from quadrant 3 to quadrant 2' do
|
119
|
+
arc = Geometry::ThreePointArc.new([0,0], [-cos,-sin], [-cos,sin])
|
120
|
+
arc.minmax.must_equal [Point[-cos,-radius], Point[radius,radius]]
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
data/test/geometry/circle.rb
CHANGED
@@ -108,17 +108,17 @@ describe Geometry::Circle do
|
|
108
108
|
let(:circle) { Circle.new :diameter => Rational(5,3) }
|
109
109
|
|
110
110
|
it 'must have the correct min values' do
|
111
|
-
circle.min.must_equal Point[-5/6, -5/6]
|
111
|
+
circle.min.must_equal Point[-5.to_r/6, -5.to_r/6]
|
112
112
|
circle.min.must_be_instance_of Geometry::PointIso
|
113
113
|
end
|
114
114
|
|
115
115
|
it 'must have the correct max values' do
|
116
|
-
circle.max.must_equal Point[5/6, 5/6]
|
116
|
+
circle.max.must_equal Point[5.to_r/6, 5.to_r/6]
|
117
117
|
circle.max.must_be_instance_of Geometry::PointIso
|
118
118
|
end
|
119
119
|
|
120
120
|
it 'must have the correct minmax values' do
|
121
|
-
circle.minmax.must_equal [Point[-5/6, -5/6], Point[5/6,5/6]]
|
121
|
+
circle.minmax.must_equal [Point[-5.to_r/6, -5.to_r/6], Point[5.to_r/6,5.to_r/6]]
|
122
122
|
end
|
123
123
|
end
|
124
124
|
|
data/test/geometry/edge.rb
CHANGED
@@ -75,11 +75,25 @@ describe Geometry::Edge do
|
|
75
75
|
subject.to_a.must_equal original.reverse
|
76
76
|
end
|
77
77
|
|
78
|
+
describe 'attributes' do
|
79
|
+
it 'must have a maximum' do
|
80
|
+
Edge([0,0], [1,1]).max.must_equal Point[1,1]
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'must have a minimum' do
|
84
|
+
Edge([0,0], [1,1]).min.must_equal Point[0,0]
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'must have a minmax' do
|
88
|
+
Edge([0,0], [1,1]).minmax.must_equal [Point[0,0], Point[1,1]]
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
78
92
|
describe "spaceship" do
|
79
93
|
it "ascending with a Point" do
|
80
94
|
edge = Edge.new [0,0], [1,1]
|
81
95
|
(edge <=> Point[0,0]).must_equal 0
|
82
|
-
(edge <=> Point[1,0]).must_equal
|
96
|
+
(edge <=> Point[1,0]).must_equal(-1)
|
83
97
|
(edge <=> Point[0,1]).must_equal 1
|
84
98
|
(edge <=> Point[2,2]).must_equal nil
|
85
99
|
end
|
@@ -88,7 +102,7 @@ describe Geometry::Edge do
|
|
88
102
|
edge = Edge.new [1,1], [0,0]
|
89
103
|
(edge <=> Point[0,0]).must_equal 0
|
90
104
|
(edge <=> Point[1,0]).must_equal 1
|
91
|
-
(edge <=> Point[0,1]).must_equal
|
105
|
+
(edge <=> Point[0,1]).must_equal(-1)
|
92
106
|
(edge <=> Point[2,2]).must_equal nil
|
93
107
|
end
|
94
108
|
end
|
data/test/geometry/line.rb
CHANGED
@@ -155,7 +155,7 @@ describe Geometry::PointSlopeLine do
|
|
155
155
|
end
|
156
156
|
|
157
157
|
it 'must have a y-intercept' do
|
158
|
-
subject.intercept.must_equal
|
158
|
+
subject.intercept.must_equal(-1)
|
159
159
|
end
|
160
160
|
end
|
161
161
|
|
@@ -199,7 +199,7 @@ describe Geometry::SlopeInterceptLine do
|
|
199
199
|
end
|
200
200
|
|
201
201
|
it 'must have an x-intercept' do
|
202
|
-
subject.intercept(:x).must_equal
|
202
|
+
subject.intercept(:x).must_equal(-2/3)
|
203
203
|
end
|
204
204
|
|
205
205
|
it 'must not have an x-intercept for horizontal lines' do
|
@@ -251,7 +251,7 @@ describe Geometry::TwoPointLine do
|
|
251
251
|
end
|
252
252
|
|
253
253
|
it 'must have an x-intercept' do
|
254
|
-
subject.intercept(:x).must_equal
|
254
|
+
subject.intercept(:x).must_equal(-1)
|
255
255
|
end
|
256
256
|
|
257
257
|
it 'must not have an x-intercept for horizontal lines' do
|
data/test/geometry/path.rb
CHANGED
@@ -63,4 +63,20 @@ describe Geometry::Path do
|
|
63
63
|
path.elements[0].last.must_equal path.elements[1].first
|
64
64
|
end
|
65
65
|
end
|
66
|
+
|
67
|
+
describe 'attributes' do
|
68
|
+
let(:unit_square) { Geometry::Path.new [0,0], [1,0], [1,1], [0,1] }
|
69
|
+
|
70
|
+
it 'must know the max' do
|
71
|
+
unit_square.max.must_equal Point[1,1]
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'must know the min' do
|
75
|
+
unit_square.min.must_equal Point[0,0]
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'must know the min and the max' do
|
79
|
+
unit_square.minmax.must_equal [Point[0,0], Point[1,1]]
|
80
|
+
end
|
81
|
+
end
|
66
82
|
end
|
data/test/geometry/point.rb
CHANGED
@@ -15,6 +15,15 @@ describe Geometry::Point do
|
|
15
15
|
Point.one(3).must_equal Point[1,1,1]
|
16
16
|
end
|
17
17
|
|
18
|
+
it 'must generate a PointIso' do
|
19
|
+
Point.iso(3).must_be_kind_of(PointIso)
|
20
|
+
Point.iso(3).value.must_equal 3
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'must generate a Point filled with a given value' do
|
24
|
+
Point.iso(3, 2).must_equal Point[3,3]
|
25
|
+
end
|
26
|
+
|
18
27
|
it "must generate a PointZero" do
|
19
28
|
Point.zero.must_be_instance_of(PointZero)
|
20
29
|
end
|
@@ -312,6 +321,15 @@ describe Geometry::Point do
|
|
312
321
|
end
|
313
322
|
end
|
314
323
|
|
324
|
+
describe 'attributes' do
|
325
|
+
it 'must have a quadrant' do
|
326
|
+
Point[1,1].quadrant.must_equal 1
|
327
|
+
Point[-1,1].quadrant.must_equal 2
|
328
|
+
Point[-1,-1].quadrant.must_equal 3
|
329
|
+
Point[1,-1].quadrant.must_equal 4
|
330
|
+
end
|
331
|
+
end
|
332
|
+
|
315
333
|
describe "coercion" do
|
316
334
|
subject { Point[1,2] }
|
317
335
|
|
data/test/geometry/point_iso.rb
CHANGED
@@ -2,7 +2,7 @@ require 'minitest/autorun'
|
|
2
2
|
require 'geometry/point_iso'
|
3
3
|
|
4
4
|
describe Geometry::PointIso do
|
5
|
-
let(:
|
5
|
+
let(:iso_value) { 5 }
|
6
6
|
subject { Geometry::PointIso.new(5) }
|
7
7
|
|
8
8
|
it 'must pop' do
|
@@ -83,30 +83,30 @@ describe Geometry::PointIso do
|
|
83
83
|
end
|
84
84
|
|
85
85
|
it 'must have +@' do
|
86
|
-
(+subject).must_be :eql?,
|
86
|
+
(+subject).must_be :eql?, iso_value
|
87
87
|
(+subject).must_be_instance_of(Geometry::PointIso)
|
88
88
|
end
|
89
89
|
|
90
90
|
it 'must have unary negation' do
|
91
|
-
(-subject).must_be :eql?, -
|
91
|
+
(-subject).must_be :eql?, -iso_value
|
92
92
|
(-subject).must_be_instance_of(Geometry::PointIso)
|
93
93
|
end
|
94
94
|
|
95
95
|
describe 'Accessors' do
|
96
96
|
it 'must return 1 for array access' do
|
97
|
-
subject[3].must_equal
|
97
|
+
subject[3].must_equal iso_value
|
98
98
|
end
|
99
99
|
|
100
100
|
it 'must return 1 for named element access' do
|
101
|
-
subject.x.must_equal
|
102
|
-
subject.y.must_equal
|
103
|
-
subject.z.must_equal
|
101
|
+
subject.x.must_equal iso_value
|
102
|
+
subject.y.must_equal iso_value
|
103
|
+
subject.z.must_equal iso_value
|
104
104
|
end
|
105
105
|
end
|
106
106
|
|
107
107
|
it 'must add a number' do
|
108
|
-
(subject + 3).must_equal (
|
109
|
-
(3 + subject).must_equal (3 +
|
108
|
+
(subject + 3).must_equal (iso_value + 3)
|
109
|
+
(3 + subject).must_equal (3 + iso_value)
|
110
110
|
end
|
111
111
|
|
112
112
|
it 'return a Point when adding two Points' do
|
@@ -115,24 +115,24 @@ describe Geometry::PointIso do
|
|
115
115
|
end
|
116
116
|
|
117
117
|
it 'must return an Array when adding an array' do
|
118
|
-
(subject + [5,6]).must_equal [
|
118
|
+
(subject + [5,6]).must_equal [iso_value+5, iso_value+6]
|
119
119
|
# ([5,6] + subject).must_equal [10, 11]
|
120
120
|
end
|
121
121
|
|
122
122
|
it 'must return a Point when adding a Size' do
|
123
123
|
(subject + Size[5,6]).must_be_instance_of(Point)
|
124
|
-
(subject + Size[5,6]).must_equal Point[
|
124
|
+
(subject + Size[5,6]).must_equal Point[iso_value+5, iso_value+6]
|
125
125
|
end
|
126
126
|
|
127
127
|
describe 'when subtracting' do
|
128
128
|
it 'must subtract a number' do
|
129
|
-
(subject - 3).must_equal (
|
130
|
-
(3 - subject).must_equal
|
129
|
+
(subject - 3).must_equal (iso_value - 3)
|
130
|
+
(3 - subject).must_equal(-2)
|
131
131
|
end
|
132
132
|
|
133
133
|
it 'return a Point when subtracting two Points' do
|
134
|
-
(subject - right).must_equal Point[
|
135
|
-
(left - subject).must_equal Point[left.x -
|
134
|
+
(subject - right).must_equal Point[iso_value - right.x, iso_value - right.y]
|
135
|
+
(left - subject).must_equal Point[left.x - iso_value, left.y - iso_value]
|
136
136
|
end
|
137
137
|
|
138
138
|
it 'must return a Point when subtracting an array' do
|
@@ -231,15 +231,15 @@ describe Geometry::PointIso do
|
|
231
231
|
end
|
232
232
|
|
233
233
|
it 'must be equal to a Point of subjects' do
|
234
|
-
subject.must_be :==, Point[
|
235
|
-
subject.must_be :eql?, Point[
|
236
|
-
subject.must_be :===, Point[
|
237
|
-
Point[
|
238
|
-
subject.must_equal Point[
|
234
|
+
subject.must_be :==, Point[iso_value, iso_value]
|
235
|
+
subject.must_be :eql?, Point[iso_value, iso_value]
|
236
|
+
subject.must_be :===, Point[iso_value, iso_value]
|
237
|
+
Point[iso_value, iso_value].must_equal subject
|
238
|
+
subject.must_equal Point[iso_value, iso_value]
|
239
239
|
end
|
240
240
|
|
241
241
|
it 'must be equal to an Vector of the same value' do
|
242
|
-
subject.must_be :eql?, Vector[
|
242
|
+
subject.must_be :eql?, Vector[iso_value, iso_value]
|
243
243
|
Vector[5, 5].must_equal subject
|
244
244
|
end
|
245
245
|
|
data/test/geometry/point_one.rb
CHANGED
data/test/geometry/point_zero.rb
CHANGED
data/test/geometry/polygon.rb
CHANGED
@@ -118,7 +118,7 @@ describe Geometry::Polygon do
|
|
118
118
|
|
119
119
|
describe "spaceship" do
|
120
120
|
it "with a Point" do
|
121
|
-
(unit_square <=> Point[2,0]).must_equal
|
121
|
+
(unit_square <=> Point[2,0]).must_equal(-1)
|
122
122
|
(unit_square <=> Point[1,0]).must_equal 0
|
123
123
|
(unit_square <=> Point[0.5,0.5]).must_equal 1
|
124
124
|
end
|
data/test/geometry/rectangle.rb
CHANGED
@@ -133,10 +133,11 @@ describe Geometry::Rectangle do
|
|
133
133
|
edges.each {|edge| assert_kind_of(Geometry::Edge, edge)}
|
134
134
|
end
|
135
135
|
|
136
|
-
it "have a points property that returns 4 points" do
|
136
|
+
it "have a points property that returns 4 points in clockwise order starting from the lower-left" do
|
137
137
|
points = rectangle.points
|
138
138
|
assert_equal(4, points.size)
|
139
139
|
points.each {|point| assert_kind_of(Geometry::Point, point)}
|
140
|
+
points.must_equal [Point[1,2], Point[1,4], Point[3,4], Point[3,2]]
|
140
141
|
end
|
141
142
|
|
142
143
|
it "must have a bounds property that returns a Rectangle" do
|
@@ -154,5 +155,9 @@ describe Geometry::Rectangle do
|
|
154
155
|
it "must have a min property that returns the lower left corner of the bounding rectangle" do
|
155
156
|
subject.min.must_equal Point[1,2]
|
156
157
|
end
|
158
|
+
|
159
|
+
it 'must have a path property that returns a closed Path' do
|
160
|
+
rectangle.path.must_equal Geometry::Path.new([1,2], [1,4], [3,4], [3,2], [1,2])
|
161
|
+
end
|
157
162
|
end
|
158
163
|
end
|
data/test/geometry/rotation.rb
CHANGED
data/test/geometry/size_one.rb
CHANGED
data/test/geometry/size_zero.rb
CHANGED
data/test/geometry/square.rb
CHANGED
@@ -9,7 +9,7 @@ describe Geometry::Square do
|
|
9
9
|
square = Square.new from:[1,2], to:[3,4]
|
10
10
|
square.must_be_kind_of Geometry::Square
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
it "must reorder swapped points when constructed from two Points" do
|
14
14
|
square = Geometry::Square.new from:[3,4], to:[1,2]
|
15
15
|
square.must_be_kind_of Geometry::Square
|
@@ -57,7 +57,7 @@ describe Geometry::Square do
|
|
57
57
|
-> { Square.new size:[1,2] }.must_raise Geometry::NotSquareError
|
58
58
|
end
|
59
59
|
end
|
60
|
-
|
60
|
+
|
61
61
|
describe "properties" do
|
62
62
|
subject { Square.new from:[2,3], to:[3,4] }
|
63
63
|
|
@@ -66,7 +66,7 @@ describe Geometry::Square do
|
|
66
66
|
end
|
67
67
|
|
68
68
|
it 'must have edges' do
|
69
|
-
subject.edges.must_equal [Edge([2,3], [
|
69
|
+
subject.edges.must_equal [Edge([2,3], [2,4]), Edge.new([2,4], [3,4]), Edge.new([3,4], [3,3]), Edge.new([3,3], [2,3])]
|
70
70
|
end
|
71
71
|
|
72
72
|
it "must have an origin accessor" do
|
@@ -85,8 +85,13 @@ describe Geometry::Square do
|
|
85
85
|
subject.min.must_equal Point[2, 3]
|
86
86
|
end
|
87
87
|
|
88
|
-
it '
|
89
|
-
subject.points.must_equal [Point[2,3], Point[
|
88
|
+
it 'have a points property that returns 4 points in clockwise order starting from the lower-left' do
|
89
|
+
subject.points.must_equal [Point[2,3], Point[2,4], Point[3,4], Point[3,3]]
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'must have a path property that returns a closed Path' do
|
93
|
+
square = Geometry::Square.new origin:[0,0], size:5
|
94
|
+
square.path.must_equal Geometry::Path.new([0,0], [0,5], [5,5], [5,0], [0,0])
|
90
95
|
end
|
91
96
|
end
|
92
97
|
end
|
@@ -102,13 +107,13 @@ describe Geometry::CenteredSquare do
|
|
102
107
|
|
103
108
|
describe "properties" do
|
104
109
|
let(:square) { Geometry::CenteredSquare.new [2,3], 4 }
|
105
|
-
|
110
|
+
|
106
111
|
it "must have a center property" do
|
107
112
|
square.center.must_equal Point[2,3]
|
108
113
|
end
|
109
114
|
|
110
|
-
it
|
111
|
-
square.points.must_equal [Point[0,1], Point[
|
115
|
+
it 'have a points property that returns 4 points in clockwise order starting from the lower-left' do
|
116
|
+
square.points.must_equal [Point[0,1], Point[0,5], Point[4,5], Point[4,1]]
|
112
117
|
end
|
113
118
|
|
114
119
|
it "must have a height property" do
|
@@ -149,8 +154,8 @@ describe Geometry::SizedSquare do
|
|
149
154
|
square.center.must_equal Point[4,5]
|
150
155
|
end
|
151
156
|
|
152
|
-
it
|
153
|
-
square.points.must_equal [Point[2,3], Point[
|
157
|
+
it 'have a points property that returns 4 points in clockwise order starting from the lower-left' do
|
158
|
+
square.points.must_equal [Point[2,3], Point[2,7], Point[6,7], Point[6,3]]
|
154
159
|
end
|
155
160
|
|
156
161
|
it "must have a height property" do
|
@@ -78,7 +78,7 @@ describe Geometry::Transformation do
|
|
78
78
|
rotation.angle.must_equal Math::PI/2
|
79
79
|
rotation.x.x.must_be_close_to 0
|
80
80
|
rotation.x.y.must_be_close_to 1
|
81
|
-
rotation.y.x.must_be_close_to
|
81
|
+
rotation.y.x.must_be_close_to(-1)
|
82
82
|
rotation.y.y.must_be_close_to 0
|
83
83
|
end
|
84
84
|
end
|
data/test/geometry/vector.rb
CHANGED
@@ -15,7 +15,7 @@ describe Vector do
|
|
15
15
|
end
|
16
16
|
|
17
17
|
it "must cross product" do
|
18
|
-
left.cross(right).must_equal
|
18
|
+
left.cross(right).must_equal(-2)
|
19
19
|
Vector[1,2,3].cross(Vector[3,4,5]).must_equal Vector[-2, 4, -2]
|
20
20
|
(Vector[1,2,3] ** Vector[3,4,5]).must_equal Vector[-2, 4, -2]
|
21
21
|
end
|