Skip to content

Commit 11aa39e

Browse files
committed
Removed the Vector random methods and moved to their own function as they're swappable between each other
1 parent 44ab157 commit 11aa39e

7 files changed

Lines changed: 47 additions & 41 deletions

File tree

v3/src/math/RandomXY.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
var RandomXY = function (vector, scale)
2+
{
3+
if (scale === undefined) { scale = 1; }
4+
5+
var r = Math.random() * 2 * Math.PI;
6+
7+
vector.x = Math.cos(r) * scale;
8+
vector.y = Math.sin(r) * scale;
9+
10+
return vector;
11+
};
12+
13+
module.exports = RandomXY;

v3/src/math/RandomXYZ.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Position Vector randomly in a spherical area defined by the given radius
2+
var RandomXYZ = function (vector, radius)
3+
{
4+
if (radius === undefined) { radius = 1; }
5+
6+
var r = Math.random() * 2 * Math.PI;
7+
var z = (Math.random() * 2) - 1;
8+
var zScale = Math.sqrt(1 - z * z) * radius;
9+
10+
vector.x = Math.cos(r) * zScale;
11+
vector.y = Math.sin(r) * zScale;
12+
vector.z = z * radius;
13+
14+
return vector;
15+
};
16+
17+
module.exports = RandomXYZ;

v3/src/math/RandomXYZW.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
var RandomXYZW = function (vector, scale)
2+
{
3+
if (scale === undefined) { scale = 1; }
4+
5+
// Not spherical; should fix this for more uniform distribution
6+
vector.x = (Math.random() * 2 - 1) * scale;
7+
vector.y = (Math.random() * 2 - 1) * scale;
8+
vector.z = (Math.random() * 2 - 1) * scale;
9+
vector.w = (Math.random() * 2 - 1) * scale;
10+
11+
return vector;
12+
};
13+
14+
module.exports = RandomXYZW;

v3/src/math/Vector2.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -198,18 +198,6 @@ var Vector2 = new Class({
198198
this.x = 0;
199199
this.y = 0;
200200

201-
return this;
202-
},
203-
204-
random: function (scale)
205-
{
206-
if (scale === undefined) { scale = 1; }
207-
208-
var r = Math.random() * 2 * Math.PI;
209-
210-
this.x = Math.cos(r) * scale;
211-
this.y = Math.sin(r) * scale;
212-
213201
return this;
214202
}
215203

v3/src/math/Vector3.js

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -327,22 +327,6 @@ var Vector3 = new Class({
327327
return this.project(invProjectionView);
328328
},
329329

330-
// Position Vector randomly in a spherical area defined by the given radius
331-
random: function (radius)
332-
{
333-
if (radius === undefined) { radius = 1; }
334-
335-
var r = Math.random() * 2 * Math.PI;
336-
var z = (Math.random() * 2) - 1;
337-
var zScale = Math.sqrt(1 - z * z) * radius;
338-
339-
this.x = Math.cos(r) * zScale;
340-
this.y = Math.sin(r) * zScale;
341-
this.z = z * radius;
342-
343-
return this;
344-
},
345-
346330
reset: function ()
347331
{
348332
this.x = 0;

v3/src/math/Vector4.js

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -246,19 +246,6 @@ var Vector4 = new Class({
246246
return this;
247247
},
248248

249-
random: function (scale)
250-
{
251-
if (scale === undefined) { scale = 1; }
252-
253-
// Not spherical; should fix this for more uniform distribution
254-
this.x = (Math.random() * 2 - 1) * scale;
255-
this.y = (Math.random() * 2 - 1) * scale;
256-
this.z = (Math.random() * 2 - 1) * scale;
257-
this.w = (Math.random() * 2 - 1) * scale;
258-
259-
return this;
260-
},
261-
262249
reset: function ()
263250
{
264251
this.x = 0;

v3/src/math/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ module.exports = {
2929
MinSub: require('./MinSub'),
3030
Percent: require('./Percent'),
3131
RadToDeg: require('./RadToDeg'),
32+
RandomXY: require('./RandomXY'),
33+
RandomXYZ: require('./RandomXYZ'),
34+
RandomXYZW: require('./RandomXYZW'),
3235
Rotate: require('./Rotate'),
3336
RotateAround: require('./RotateAround'),
3437
RotateAroundDistance: require('./RotateAroundDistance'),

0 commit comments

Comments
 (0)