I made a small vector2d class. When I print just the vector2d itself, I get a 3 point value despite the class only having a X and Y value.
My class has no Z value or field, so its impossible to return a third value. Its default constructor insures that.
For example:
var newVec = new vector2d(0.5, 0.5); print(newVec);
Outputs:
0.5, 0.5, 0.0
Where as:
var newVec = new vector2d(0.5, 0.5); print(newVec.x + ", " + newVec.y);
Outputs:
0.5, 0.5
Here is my class:
// vector2d class by xanimalkingx // Holds 2 points which can be used for things that require 2D coordinates, // such as texture coordinates. // (must be defined at start of file) vector2d = function(xVal, yVal) { // Constructor // Check for null if (xVal == null) { this.x = 0; } else { this.x = xVal; } if (yVal == null) { this.y = 0; } else { this.y = yVal; } // Set both points to new values this.set = function(newX, newY) { this.x = newX; this.y = newY; } // Set a new value for the x point this.setX = function(newX) { this.x = newX; } // Set a new value for the y point this.setY = function(newY) { this.y = newY; } // Clone this vector2d into a new variable this.clone = function() { return new vector2d(this.x, this.y); } }
