Hi there. Recently I tried optimising a project I have and I noticed something strange. The p5.Vector() object contains an instance of p5()… the whole p5() object
Inside the src code I found this
p5.Vector = function Vector() {
let x, y, z;
// This is how it comes in with createVector()
if (arguments[0] instanceof p5) {
// save reference to p5 if passed in
this.p5 = arguments[0];
x = arguments[1][0] || 0;
y = arguments[1][1] || 0;
z = arguments[1][2] || 0;
// This is what we'll get with new p5.Vector()
} else {
x = arguments[0] || 0;
y = arguments[1] || 0;
z = arguments[2] || 0;
}
Fair enough, maybe for some functionality you would need an instance of p5 inside the Vector(). But my Vectors were created without the first argument being a p5(), but the instance is still there! Demo here
The size of a p5() object is 202 bytes, which seems like a lot of extra memory for each Vector(). Is there a real need for this? I find it odd that I can