diff --git a/src/math/p5.Vector.js b/src/math/p5.Vector.js index f1443798d4..0ec5311495 100644 --- a/src/math/p5.Vector.js +++ b/src/math/p5.Vector.js @@ -235,7 +235,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 f951d6544a..a7a33a9e8f 100644 --- a/test/unit/math/p5.Vector.js +++ b/test/unit/math/p5.Vector.js @@ -2157,6 +2157,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', () => {