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.
@@ -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
- # @attribute [r] origin
105
- # @return [Point] The lower left corner
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[p1.x, p0.y], p1, Point[p0.x, p1.y]]
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 (counterclockwise)
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[maxx, miny], Point[maxx, maxy], Point[minx,maxy]]
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 (counterclockwise)
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[maxx, miny], Point[maxx, maxy], Point[minx,maxy]]
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) {|point, transformation| transformation.transform(point) }
35
+ transformations.reverse.reduce(point) {|_point, transformation| transformation.transform(_point) }
36
36
  end
37
37
  end
38
38
  end
@@ -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 *args
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
@@ -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
 
@@ -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 -1
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 -1
105
+ (edge <=> Point[0,1]).must_equal(-1)
92
106
  (edge <=> Point[2,2]).must_equal nil
93
107
  end
94
108
  end
@@ -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 -1
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 -2/3
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 -1
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
@@ -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
@@ -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
 
@@ -2,7 +2,7 @@ require 'minitest/autorun'
2
2
  require 'geometry/point_iso'
3
3
 
4
4
  describe Geometry::PointIso do
5
- let(:value) { 5 }
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?, value
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?, -value
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 value
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 value
102
- subject.y.must_equal value
103
- subject.z.must_equal value
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 (value + 3)
109
- (3 + subject).must_equal (3 + value)
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 [value+5, value+6]
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[value+5, value+6]
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 (value - 3)
130
- (3 - subject).must_equal -2
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[value - right.x, value - right.y]
135
- (left - subject).must_equal Point[left.x - value, left.y - value]
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[value, value]
235
- subject.must_be :eql?, Point[value, value]
236
- subject.must_be :===, Point[value, value]
237
- Point[value, value].must_equal subject
238
- subject.must_equal Point[value, value]
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[value, value]
242
+ subject.must_be :eql?, Vector[iso_value, iso_value]
243
243
  Vector[5, 5].must_equal subject
244
244
  end
245
245
 
@@ -126,7 +126,7 @@ describe Geometry::PointOne do
126
126
 
127
127
  describe 'when subtracting' do
128
128
  it 'must subtract a number' do
129
- (one - 3).must_equal -2
129
+ (one - 3).must_equal(-2)
130
130
  (3 - one).must_equal 2
131
131
  end
132
132
 
@@ -127,7 +127,7 @@ describe Geometry::PointZero do
127
127
 
128
128
  describe "when subtracting" do
129
129
  it "must return a number" do
130
- (zero - 3).must_equal -3
130
+ (zero - 3).must_equal(-3)
131
131
  (3 - zero).must_equal 3
132
132
  end
133
133
 
@@ -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 -1
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
@@ -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
@@ -13,7 +13,7 @@ describe Geometry::Rotation do
13
13
  rotation.angle.must_equal Math::PI/2
14
14
  rotation.x.x.must_be_close_to 0
15
15
  rotation.x.y.must_be_close_to 1
16
- rotation.y.x.must_be_close_to -1
16
+ rotation.y.x.must_be_close_to(-1)
17
17
  rotation.y.y.must_be_close_to 0
18
18
  end
19
19
 
@@ -37,7 +37,7 @@ describe Geometry::SizeOne do
37
37
 
38
38
  describe 'when subtracting' do
39
39
  it 'must subtract a number' do
40
- (one - 3).must_equal -2
40
+ (one - 3).must_equal(-2)
41
41
  (3 - one).must_equal 2
42
42
  end
43
43
 
@@ -39,7 +39,7 @@ describe Geometry::SizeZero do
39
39
 
40
40
  describe "when subtracting" do
41
41
  it "must return a number" do
42
- (zero - 3).must_equal -3
42
+ (zero - 3).must_equal(-3)
43
43
  (3 - zero).must_equal 3
44
44
  end
45
45
 
@@ -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], [3,3]), Edge.new([3,3], [3,4]), Edge.new([3,4], [2,4]), Edge.new([2,4], [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 'must have points' do
89
- subject.points.must_equal [Point[2,3], Point[3,3], Point[3,4], Point[2,4]]
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 "must have a points property" do
111
- square.points.must_equal [Point[0,1], Point[4,1], Point[4,5], Point[0,5]]
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 "must have a points property" do
153
- square.points.must_equal [Point[2,3], Point[6,3], Point[6,7], Point[2,7]]
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 -1
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
@@ -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 -2
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