diff --git a/src/math/p5.Vector.js b/src/math/p5.Vector.js index e5275ad7cc..d255df9686 100644 --- a/src/math/p5.Vector.js +++ b/src/math/p5.Vector.js @@ -238,7 +238,7 @@ class Vector { * @param {Number} xVal - The new value for the x component. */ set x(xVal) { - if (this.values.length > 1) { + if (this.values.length > 0) { this.values[0] = xVal; } } diff --git a/test/unit/math/p5.Vector.js b/test/unit/math/p5.Vector.js index bbe7c38a5b..80823e654a 100644 --- a/test/unit/math/p5.Vector.js +++ b/test/unit/math/p5.Vector.js @@ -2184,6 +2184,12 @@ suite('p5.Vector', function () { v = new Vector(1, 2, 3, 4); expect(v.toString()).toBe('vector[1, 2, 3, 4]'); }); + + test('should show a value change for x with toString() for 1d Vector', function(){ + v = new Vector(1); + v.x = 2; + expect(v.toString()).toBe('vector[2]'); + }) }); describe('set heading', () => {