Skip to content

Commit 0b4bfe9

Browse files
authored
Merge pull request #437 from marcusround/master
random should only return unit vector when scale is undefined
2 parents d30bf3b + 8726b20 commit 0b4bfe9

File tree

6 files changed

+27
-6
lines changed

6 files changed

+27
-6
lines changed

spec/gl-matrix/vec2-spec.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,14 @@ describe("vec2", function() {
433433
describe("with a scale", function() {
434434
beforeEach(function() { result = vec2.random(out, 5.0); });
435435

436-
it("should result in a unit length vector", function() { expect(vec2.len(out)).toBeEqualish(5.0); });
436+
it("should result in a vector of correct length", function() { expect(vec2.len(out)).toBeEqualish(5.0); });
437+
it("should return out", function() { expect(result).toBe(out); });
438+
});
439+
440+
describe("with a scale of zero", function() {
441+
beforeEach(function() { result = vec2.random(out, 0); });
442+
443+
it("should result in a zero vector", function() { expect(vec2.len(out)).toBeEqualish(0); });
437444
it("should return out", function() { expect(result).toBe(out); });
438445
});
439446
});

spec/gl-matrix/vec3-spec.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,14 @@ describe("vec3", function() {
602602
describe("with a scale", function() {
603603
beforeEach(function() { result = vec3.random(out, 5.0); });
604604

605-
it("should result in a unit length vector", function() { expect(vec3.len(out)).toBeEqualish(5.0); });
605+
it("should result in a vector of correct length", function() { expect(vec3.len(out)).toBeEqualish(5.0); });
606+
it("should return out", function() { expect(result).toBe(out); });
607+
});
608+
609+
describe("with a scale of zero", function() {
610+
beforeEach(function() { result = vec3.random(out, 0); });
611+
612+
it("should result in a zero vector", function() { expect(vec3.len(out)).toBeEqualish(0); });
606613
it("should return out", function() { expect(result).toBe(out); });
607614
});
608615
});

spec/gl-matrix/vec4-spec.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,14 @@ describe("vec4", function() {
420420
describe("with a scale", function() {
421421
beforeEach(function() { result = vec4.random(out, 5.0); });
422422

423-
it("should result in a unit length vector", function() { expect(vec4.len(out)).toBeEqualish(5.0); });
423+
it("should result in a vector of correct length", function() { expect(vec4.len(out)).toBeEqualish(5.0); });
424+
it("should return out", function() { expect(result).toBe(out); });
425+
});
426+
427+
describe("with a scale of zero", function() {
428+
beforeEach(function() { result = vec4.random(out, 0); });
429+
430+
it("should result in a zero vector", function() { expect(vec4.len(out)).toBeEqualish(0); });
424431
it("should return out", function() { expect(result).toBe(out); });
425432
});
426433
});

src/vec2.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ export function lerp(out, a, b, t) {
373373
* @returns {vec2} out
374374
*/
375375
export function random(out, scale) {
376-
scale = scale || 1.0;
376+
scale = scale === undefined ? 1.0 : scale;
377377
var r = glMatrix.RANDOM() * 2.0 * Math.PI;
378378
out[0] = Math.cos(r) * scale;
379379
out[1] = Math.sin(r) * scale;

src/vec3.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ export function bezier(out, a, b, c, d, t) {
481481
* @returns {vec3} out
482482
*/
483483
export function random(out, scale) {
484-
scale = scale || 1.0;
484+
scale = scale === undefined ? 1.0 : scale;
485485

486486
let r = glMatrix.RANDOM() * 2.0 * Math.PI;
487487
let z = glMatrix.RANDOM() * 2.0 - 1.0;

src/vec4.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ export function lerp(out, a, b, t) {
441441
* @returns {vec4} out
442442
*/
443443
export function random(out, scale) {
444-
scale = scale || 1.0;
444+
scale = scale === undefined ? 1.0 : scale;
445445

446446
// Marsaglia, George. Choosing a Point from the Surface of a
447447
// Sphere. Ann. Math. Statist. 43 (1972), no. 2, 645--646.

0 commit comments

Comments
 (0)