perlin 0.2.1 → 0.2.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.
@@ -1,5 +1,5 @@
1
1
  # Perlin noise generation.
2
2
  module Perlin
3
3
  # Current version of the gem.
4
- VERSION = "0.2.1"
4
+ VERSION = "0.2.2"
5
5
  end
@@ -1,4 +1,23 @@
1
1
  require "rspec"
2
2
 
3
3
  $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
4
- require "perlin"
4
+ require "perlin"
5
+
6
+ RSpec.configure do |config|
7
+ config.raise_errors_for_deprecations!
8
+ end
9
+
10
+ # Check a N-d array of floats for consistency with another one.
11
+ def same_array_within_accuracy(result, expected, accuracy)
12
+ expect(result.size).to eq expected.size
13
+
14
+ result.zip(expected) do |a, b|
15
+ if b[0].is_a? Array
16
+ same_array_within_accuracy a, b, accuracy
17
+ else
18
+ a.zip(b.flatten) do |x, y|
19
+ expect(x).to be_within(@accuracy).of y
20
+ end
21
+ end
22
+ end
23
+ end
@@ -1,6 +1,7 @@
1
1
 
2
2
  require File.expand_path("../../helper.rb", __FILE__)
3
3
 
4
+
4
5
  describe Perlin::Generator do
5
6
  before :each do
6
7
  @classic = Perlin::Generator.new 123, 1.5, 2, :classic => true
@@ -9,135 +10,133 @@ describe Perlin::Generator do
9
10
  end
10
11
 
11
12
  it "should have seed set correctly" do
12
- @classic.seed.should eq 123
13
- @classic.seed.should be_kind_of Integer
13
+ expect(@classic.seed).to eq 123
14
+ expect(@classic.seed).to be_kind_of Integer
14
15
  end
15
16
 
16
17
  it "should have seed set uniquely on all generators" do
17
18
  # This was a bug in the original code!
18
19
  g = Perlin::Generator.new 99, 1, 1
19
- g.seed.should eq 99
20
- g.seed.should be_kind_of Integer
20
+ expect(g.seed).to eq 99
21
+ expect(g.seed).to be_kind_of Integer
21
22
 
22
- @classic.seed.should eq 123
23
- g[0, 0].should_not eq @classic[0, 0]
23
+ expect(@classic.seed).to eq 123
24
+ expect(g[0, 0]).not_to eq @classic[0, 0]
24
25
  end
25
26
 
26
27
  it "should have persistence set correctly" do
27
- @classic.persistence.should be_within(@accuracy).of 1.5
28
+ expect(@classic.persistence).to be_within(@accuracy).of 1.5
28
29
  end
29
30
 
30
31
  it "should have octave set correctly" do
31
- @classic.octave.should eq 2
32
- @classic.octave.should be_kind_of Integer
32
+ expect(@classic.octave).to eq 2
33
+ expect(@classic.octave).to be_kind_of Integer
33
34
  end
34
35
 
35
36
  describe "SIMPLEX" do
36
37
  it "should have classic? set correctly" do
37
- @simplex.classic?.should be_false
38
+ expect(@simplex.classic?).to be false
38
39
  end
39
40
  end
40
41
 
41
42
  describe "CLASSIC" do
42
43
  it "should have classic? set correctly" do
43
- @classic.classic?.should be_true
44
+ expect(@classic.classic?).to be true
44
45
  end
45
46
  end
46
47
 
47
48
  describe "seed=" do
48
49
  it "should set seed correctly" do
49
50
  @classic.seed = 12
50
- @classic.seed.should eq 12
51
- @classic.seed.should be_kind_of Integer
51
+ expect(@classic.seed).to eq 12
52
+ expect(@classic.seed).to be_kind_of Integer
52
53
  end
53
54
 
54
55
  it "should fail unless >= 1" do
55
- lambda { @classic.seed = 0 }.should raise_error ArgumentError, "seed must be >= 1"
56
+ expect { @classic.seed = 0 }.to raise_error ArgumentError, "seed must be >= 1"
56
57
  end
57
58
  end
58
59
 
59
60
  describe "persistence=" do
60
61
  it "should set persistence correctly" do
61
62
  @classic.persistence = 12.1513
62
- @classic.persistence.should eq 12.1513
63
- @classic.persistence.should be_kind_of Float
63
+ expect(@classic.persistence).to eq 12.1513
64
+ expect(@classic.persistence).to be_kind_of Float
64
65
  end
65
66
  end
66
67
 
67
68
  describe "octave=" do
68
69
  it "should set octave correctly" do
69
70
  @classic.octave = 12
70
- @classic.octave.should eq 12
71
- @classic.octave.should be_kind_of Integer
71
+ expect(@classic.octave).to eq 12
72
+ expect(@classic.octave).to be_kind_of Integer
72
73
  end
73
74
 
74
75
  it "should fail unless >= 1" do
75
- lambda { @classic.octave = 0 }.should raise_error ArgumentError, "octave must be >= 1"
76
+ expect { @classic.octave = 0 }.to raise_error ArgumentError, "octave must be >= 1"
76
77
  end
77
78
  end
78
79
 
79
80
  describe "classic=" do
80
81
  it "should set classic? correctly" do
81
82
  @simplex.classic = true
82
- @simplex.classic?.should be_true
83
+ expect(@simplex.classic?).to be true
83
84
  end
84
85
  end
85
86
 
86
87
  describe "[]" do
87
88
  it "[x, y] should support float values" do
88
- @simplex[0, 0].should_not be_within(@accuracy).of @simplex[0.2, 0.2]
89
+ expect(@simplex[0, 0]).not_to be_within(@accuracy).of @simplex[0.2, 0.2]
89
90
  end
90
91
 
91
-
92
-
93
92
  it "[x, y, z] should support float values" do
94
- @simplex[0, 0, 0].should_not be_within(@accuracy).of @simplex[0.2, 0.2, 0.2]
93
+ expect(@simplex[0, 0, 0]).not_to be_within(@accuracy).of @simplex[0.2, 0.2, 0.2]
95
94
  end
96
95
 
97
96
  it "should fail if given too few arguments" do
98
- lambda { @classic[0] }.should raise_error ArgumentError
97
+ expect { @classic[0] }.to raise_error ArgumentError
99
98
  end
100
99
 
101
100
  it "should fail if given too many arguments" do
102
- lambda { @classic[0, 0, 0, 0] }.should raise_error ArgumentError
101
+ expect { @classic[0, 0, 0, 0] }.to raise_error ArgumentError
103
102
  end
104
103
 
105
- describe "SIMPLEX" do
104
+ context "SIMPLEX" do
106
105
  describe "[](x, y)" do
107
106
  it "should return the appropriate value" do
108
- @simplex[0, 1].should be_within(@accuracy).of -0.7169484162988542
107
+ expect(@simplex[0, 1]).to be_within(@accuracy).of -0.7169484162988542
109
108
  end
110
109
 
111
110
  it "should return different values based on seed" do
112
111
  initial = @simplex[9, 5]
113
112
  @simplex.seed = 95
114
- initial.should_not be_within(@accuracy).of @simplex[9, 5]
113
+ expect(initial).to_not be_within(@accuracy).of @simplex[9, 5]
115
114
  end
116
115
  end
117
116
 
118
117
  describe "[](x, y, z)" do
119
118
  it "should return the appropriate value" do
120
- @simplex[0, 1, 2].should be_within(@accuracy).of 0.3528568374548613
119
+ expect(@simplex[0, 1, 2]).to be_within(@accuracy).of 0.3528568374548613
121
120
  end
122
121
  end
123
122
  end
124
123
 
125
- describe "CLASSIC" do
124
+ context "CLASSIC" do
126
125
  describe "[](x, y)" do
127
126
  it "should return the appropriate value" do
128
- @classic[0, 0].should be_within(@accuracy).of -1.0405873507261276
127
+ expect(@classic[0, 0]).to be_within(@accuracy).of -1.0405873507261276
129
128
  end
130
129
 
131
130
  it "should return different values based on seed" do
132
131
  initial = @classic[9, 5]
133
132
  @classic.seed = 95
134
- initial.should_not be_within(@accuracy).of @classic[9, 5]
133
+ expect(initial).to_not be_within(@accuracy).of @classic[9, 5]
135
134
  end
136
135
  end
137
136
 
138
137
  describe "[](x, y, z)" do
139
138
  it "should return the appropriate value" do
140
- @classic[0, 0, 0].should be_within(@accuracy).of -1.5681833028793335
139
+ expect(@classic[0, 0, 0]).to be_within(@accuracy).of -1.5681833028793335
141
140
  end
142
141
  end
143
142
  end
@@ -146,20 +145,25 @@ describe Perlin::Generator do
146
145
  describe "chunk" do
147
146
  describe "chunk 2D" do
148
147
 
149
- describe "SIMPLEX" do
148
+ context "SIMPLEX" do
150
149
  it "should return the appropriate values" do
151
150
  chunk = @simplex.chunk 1, 2, 3, 4, 1
152
- chunk.should eq [[0.3256153247344187, -0.044141564834959, -1.9775393411691766e-07, -0.30403976440429686], [0.0, 1.9775393411691766e-07, 0.0, -0.21674697868461495], [1.9775393411691766e-07, -0.23931307266021215, -0.7600996287015893, -5.93261818394248e-07]]
151
+ expected = [
152
+ [0.3256153247344187, -0.044141564834959, -1.9775393411691766e-07, -0.30403976440429686],
153
+ [0.0, 1.9775393411691766e-07, 0.0, -0.21674697868461495],
154
+ [1.9775393411691766e-07, -0.23931307266021215, -0.7600996287015893, -5.93261818394248e-07],
155
+ ]
156
+ same_array_within_accuracy chunk, expected, @accuracy
153
157
  end
154
158
 
155
159
  it "should give the same results, regardless of x/y offset" do
156
160
  chunk1 = @simplex.chunk 0, 0, 3, 3, 0.1
157
161
  chunk2 = @simplex.chunk 0.1, 0.1, 3, 3, 0.1
158
162
 
159
- chunk2[0][0].should eq chunk1[1][1]
160
- chunk2[0][1].should eq chunk1[1][2]
161
- chunk2[1][0].should eq chunk1[2][1]
162
- chunk2[1][1].should eq chunk1[2][2]
163
+ expect(chunk2[0][0]).to eq chunk1[1][1]
164
+ expect(chunk2[0][1]).to eq chunk1[1][2]
165
+ expect(chunk2[1][0]).to eq chunk1[2][1]
166
+ expect(chunk2[1][1]).to eq chunk1[2][2]
163
167
  end
164
168
 
165
169
  it "should work with a block" do
@@ -167,23 +171,43 @@ describe Perlin::Generator do
167
171
  @simplex.chunk 1, 2, 3, 4, 1 do |h, x, y|
168
172
  arr << [h, x, y]
169
173
  end
170
- arr.should eq [[0.3256153247344187, 1.0, 2.0], [-0.044141564834959, 1.0, 3.0], [-1.9775393411691766e-07, 1.0, 4.0], [-0.30403976440429686, 1.0, 5.0], [0.0, 2.0, 2.0], [1.9775393411691766e-07, 2.0, 3.0], [0.0, 2.0, 4.0], [-0.21674697868461495, 2.0, 5.0], [1.9775393411691766e-07, 3.0, 2.0], [-0.23931307266021215, 3.0, 3.0], [-0.7600996287015893, 3.0, 4.0], [-5.93261818394248e-07, 3.0, 5.0]]
174
+
175
+ expected = [
176
+ [0.3256153247344187, 1.0, 2.0],
177
+ [-0.044141564834959, 1.0, 3.0],
178
+ [-1.9775393411691766e-07, 1.0, 4.0],
179
+ [-0.30403976440429686, 1.0, 5.0],
180
+ [0.0, 2.0, 2.0],
181
+ [1.9775393411691766e-07, 2.0, 3.0],
182
+ [0.0, 2.0, 4.0],
183
+ [-0.21674697868461495, 2.0, 5.0],
184
+ [1.9775393411691766e-07, 3.0, 2.0],
185
+ [-0.23931307266021215, 3.0, 3.0],
186
+ [-0.7600996287015893, 3.0, 4.0],
187
+ [-5.93261818394248e-07, 3.0, 5.0],
188
+ ]
189
+ same_array_within_accuracy arr, expected, @accuracy
171
190
  end
172
191
  end
173
192
 
174
- describe "CLASSIC" do
193
+ context "CLASSIC" do
175
194
  it "should return the appropriate values" do
176
195
  chunk = @classic.chunk 1, 2, 3, 4, 1
177
- chunk.should eq [[-2.014809340238571, -0.7094215080142021, -0.5946878045797348, 0.4915006756782532], [-1.4068767204880714, -0.732808068394661, 0.07362580299377441, -0.325466126203537], [-0.857817449606955, -1.940980076789856, -0.5687579363584518, 1.4209578335285187]]
196
+ expected = [
197
+ [-2.014809340238571, -0.7094215080142021, -0.5946878045797348, 0.4915006756782532],
198
+ [-1.4068767204880714, -0.732808068394661, 0.07362580299377441, -0.325466126203537],
199
+ [-0.857817449606955, -1.940980076789856, -0.5687579363584518, 1.4209578335285187],
200
+ ]
201
+ same_array_within_accuracy chunk, expected, @accuracy
178
202
  end
179
203
 
180
204
  it "should give the same results, regardless of x/y offset" do
181
205
  chunk1 = @classic.chunk 0, 0, 3, 3, 0.1
182
206
  chunk2 = @classic.chunk 0.1, 0.1, 3, 3, 0.1
183
- chunk2[0][0].should eq chunk1[1][1]
184
- chunk2[0][1].should eq chunk1[1][2]
185
- chunk2[1][0].should eq chunk1[2][1]
186
- chunk2[1][1].should eq chunk1[2][2]
207
+ expect(chunk2[0][0]).to eq chunk1[1][1]
208
+ expect(chunk2[0][1]).to eq chunk1[1][2]
209
+ expect(chunk2[1][0]).to eq chunk1[2][1]
210
+ expect(chunk2[1][1]).to eq chunk1[2][2]
187
211
  end
188
212
 
189
213
  it "should work with a block" do
@@ -191,25 +215,43 @@ describe Perlin::Generator do
191
215
  @classic.chunk 1, 2, 3, 4, 1 do |h, x, y|
192
216
  arr << [h, x, y]
193
217
  end
194
- arr.should eq [[-2.014809340238571, 1.0, 2.0], [-0.7094215080142021, 1.0, 3.0], [-0.5946878045797348, 1.0, 4.0], [0.4915006756782532, 1.0, 5.0], [-1.4068767204880714, 2.0, 2.0], [-0.732808068394661, 2.0, 3.0], [0.07362580299377441, 2.0, 4.0], [-0.325466126203537, 2.0, 5.0], [-0.857817449606955, 3.0, 2.0], [-1.940980076789856, 3.0, 3.0], [-0.5687579363584518, 3.0, 4.0], [1.4209578335285187, 3.0, 5.0]]
218
+ expected = [
219
+ [-2.014809340238571, 1.0, 2.0],
220
+ [-0.7094215080142021, 1.0, 3.0],
221
+ [-0.5946878045797348, 1.0, 4.0],
222
+ [0.4915006756782532, 1.0, 5.0],
223
+ [-1.4068767204880714, 2.0, 2.0],
224
+ [-0.732808068394661, 2.0, 3.0],
225
+ [0.07362580299377441, 2.0, 4.0],
226
+ [-0.325466126203537, 2.0, 5.0],
227
+ [-0.857817449606955, 3.0, 2.0],
228
+ [-1.940980076789856, 3.0, 3.0],
229
+ [-0.5687579363584518, 3.0, 4.0],
230
+ [1.4209578335285187, 3.0, 5.0],
231
+ ]
232
+ same_array_within_accuracy arr, expected, @accuracy
195
233
  end
196
234
  end
197
235
 
198
236
  it "should fail if given negative size_x" do
199
- lambda { @classic.chunk 0, 0, -1, 0 }.should raise_error ArgumentError
237
+ expect { @classic.chunk 0, 0, -1, 0 }.to raise_error ArgumentError
200
238
  end
201
239
 
202
240
  it "should fail if given negative size_y" do
203
- lambda { @classic.chunk 0, 0, 0, -1 }.should raise_error ArgumentError
241
+ expect { @classic.chunk 0, 0, 0, -1 }.to raise_error ArgumentError
204
242
  end
205
-
206
243
  end
207
244
 
208
245
  describe "chunk 3D" do
209
- describe "SIMPLEX" do
246
+ context "SIMPLEX" do
210
247
  it "should return the appropriate values" do
211
248
  chunk = @simplex.chunk 6, 5, 4, 3, 2, 1, 1
212
- chunk.should eq [[[-0.13219586780905937], [-0.10557871005195935]], [[0.057937057229464836], [0.14160177316516637]], [[0.4784122159704566], [0.23034484239760417]]]
249
+ expected = [
250
+ [ [-0.13219586780905937], [-0.10557871005195935], ],
251
+ [ [0.057937057229464836], [0.14160177316516637] ],
252
+ [ [0.4784122159704566], [0.23034484239760417] ],
253
+ ]
254
+ same_array_within_accuracy chunk, expected, @accuracy
213
255
  end
214
256
 
215
257
  it "should work with a block" do
@@ -217,14 +259,27 @@ describe Perlin::Generator do
217
259
  @simplex.chunk 6, 5, 4, 3, 2, 1, 1 do |h, x, y, z|
218
260
  arr << [h, x, y, z]
219
261
  end
220
- arr.should eq [[-0.13219586780905937, 6.0, 5.0, 4.0], [-0.10557871005195935, 6.0, 6.0, 4.0], [0.057937057229464836, 7.0, 5.0, 4.0], [0.14160177316516637, 7.0, 6.0, 4.0], [0.4784122159704566, 8.0, 5.0, 4.0], [0.23034484239760417, 8.0, 6.0, 4.0]]
262
+ expected = [
263
+ [-0.13219586780905937, 6.0, 5.0, 4.0],
264
+ [-0.10557871005195935, 6.0, 6.0, 4.0],
265
+ [0.057937057229464836, 7.0, 5.0, 4.0],
266
+ [0.14160177316516637, 7.0, 6.0, 4.0],
267
+ [0.4784122159704566, 8.0, 5.0, 4.0],
268
+ [0.23034484239760417, 8.0, 6.0, 4.0],
269
+ ]
270
+ same_array_within_accuracy arr, expected, @accuracy
221
271
  end
222
272
  end
223
273
 
224
- describe "CLASSIC" do
274
+ context "CLASSIC" do
225
275
  it "should return the appropriate values" do
226
276
  chunk = @classic.chunk 6, 5, 4, 3, 2, 1, 1
227
- chunk.should eq [[[0.7522532045841217], [0.3314518630504608]], [[0.3198353797197342], [0.967293307185173]], [[1.1024393141269684], [0.5659154206514359]]]
277
+ expected = [
278
+ [[0.7522532045841217], [0.3314518630504608]],
279
+ [[0.3198353797197342], [0.967293307185173]],
280
+ [[1.1024393141269684], [0.5659154206514359]],
281
+ ]
282
+ same_array_within_accuracy chunk, expected, @accuracy
228
283
  end
229
284
 
230
285
  it "should work with a block" do
@@ -232,22 +287,28 @@ describe Perlin::Generator do
232
287
  @classic.chunk 6, 5, 4, 3, 2, 1, 1 do |h, x, y, z|
233
288
  arr << [h, x, y, z]
234
289
  end
235
- arr.should eq [[0.7522532045841217, 6.0, 5.0, 4.0], [0.3314518630504608, 6.0, 6.0, 4.0], [0.3198353797197342, 7.0, 5.0, 4.0], [0.967293307185173, 7.0, 6.0, 4.0], [1.1024393141269684, 8.0, 5.0, 4.0], [0.5659154206514359, 8.0, 6.0, 4.0]]
290
+ expected = [
291
+ [0.7522532045841217, 6.0, 5.0, 4.0],
292
+ [0.3314518630504608, 6.0, 6.0, 4.0],
293
+ [0.3198353797197342, 7.0, 5.0, 4.0],
294
+ [0.967293307185173, 7.0, 6.0, 4.0],
295
+ [1.1024393141269684, 8.0, 5.0, 4.0],
296
+ [0.5659154206514359, 8.0, 6.0, 4.0]]
297
+ same_array_within_accuracy arr, expected, @accuracy
236
298
  end
237
299
  end
238
300
 
239
301
  it "should fail if given negative size_x" do
240
- lambda { @classic.chunk 0, 0, 0, -1, 0, 0 }.should raise_error ArgumentError
302
+ expect { @classic.chunk 0, 0, 0, -1, 0, 0 }.to raise_error ArgumentError
241
303
  end
242
304
 
243
305
  it "should fail if given negative size_y" do
244
- lambda { @classic.chunk 0, 0, 0, 0, -1, 0 }.should raise_error ArgumentError
306
+ expect { @classic.chunk 0, 0, 0, 0, -1, 0 }.to raise_error ArgumentError
245
307
  end
246
308
 
247
309
  it "should fail if given negative size_z" do
248
- lambda { @classic.chunk 0, 0, 0, 0, 0, -1 }.should raise_error ArgumentError
310
+ expect { @classic.chunk 0, 0, 0, 0, 0, -1 }.to raise_error ArgumentError
249
311
  end
250
312
  end
251
-
252
313
  end
253
314
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: perlin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2015-02-25 00:00:00.000000000 Z
14
+ date: 2015-10-12 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: RedCloth
@@ -52,7 +52,7 @@ dependencies:
52
52
  requirements:
53
53
  - - ~>
54
54
  - !ruby/object:Gem::Version
55
- version: 2.10.0
55
+ version: '3.3'
56
56
  type: :development
57
57
  prerelease: false
58
58
  version_requirements: !ruby/object:Gem::Requirement
@@ -60,7 +60,7 @@ dependencies:
60
60
  requirements:
61
61
  - - ~>
62
62
  - !ruby/object:Gem::Version
63
- version: 2.10.0
63
+ version: '3.3'
64
64
  - !ruby/object:Gem::Dependency
65
65
  name: rake-compiler
66
66
  requirement: !ruby/object:Gem::Requirement
@@ -132,7 +132,7 @@ dependencies:
132
132
  requirements:
133
133
  - - ~>
134
134
  - !ruby/object:Gem::Version
135
- version: 0.7.45
135
+ version: '0.7'
136
136
  type: :development
137
137
  prerelease: false
138
138
  version_requirements: !ruby/object:Gem::Requirement
@@ -140,7 +140,7 @@ dependencies:
140
140
  requirements:
141
141
  - - ~>
142
142
  - !ruby/object:Gem::Version
143
- version: 0.7.45
143
+ version: '0.7'
144
144
  - !ruby/object:Gem::Dependency
145
145
  name: fidgit
146
146
  requirement: !ruby/object:Gem::Requirement