// should always be immutable, make a factory object
const Vector2 = {
  create(x, y) {
    // return an immutable object
    return Object.freeze({ x, y })
  },

  toString(vector) {
    return `(${vector.x}, ${vector.y})`
  },

  print(vector) {
    console.log(`(${vector.x}, ${vector.y})`)
  }

}


// returns a new vector representing the difference
Vector2.sum = Vector2.add = function(left, right) {
  return Vector2.create(left.x + right.x, left.y + right.y)
}

// returns a new vector representing the difference
Vector2.difference = Vector2.minus = Vector2.subtract = function(left, right) {
  return Vector2.create(left.x - right.x, left.y - right.y)
}

// returns a new vector representing the difference
Vector2.dot = function(left, right) {
  return left.x * right.x + left.y * right.y;
}

Vector2.right = Vector2.create(1, 0)
Vector2.left =  Vector2.create(-1, 0)
Vector2.up =    Vector2.create(0, 1)
Vector2.down =  Vector2.create(0, -1)

export default Vector2

@@ -1,165 +1,426 @@
-// should always be immutable, make a factory object%0Aconst Vector2 = %7B%0A  create(x, y) %7B%0A    // return an immutable object%0A    return Object.freeze(%7B x, y %7D
+class Vector2 %7B%0A  constructor(x, y) %7B%0A    // return an immutable object%0A    // return Object.freeze(%7B x, y %7D)%0A    // TODO: rethink if we need immutable objects. positions represented by vector2 = tons of vector2 objects being created%0A    // if we don't need immutable objects, this should just be an ES6 class%0A    this.x = x%0A    this.y = y%0A  %7D%0A%0A  mag() %7B%0A    return Math.sqrt(vector.x * vector.x + vector.y * vector.y
 )%0A  %7D
-,
 %0A%0A  
@@ -428,22 +428,16 @@
 oString(
-vector
 ) %7B%0A    
@@ -447,35 +447,31 @@
 urn %60($%7B
-vector
+this
 .x%7D, $%7B
-vector
+this
 .y%7D)%60%0A  
@@ -471,17 +471,16 @@
 y%7D)%60%0A  %7D
-,
 %0A%0A  prin
@@ -481,22 +481,16 @@
   print(
-vector
 ) %7B%0A    
@@ -509,32 +509,260 @@
 %60($%7B
-vector.x%7D, $%7Bvector.y%7D)%60
+this.x%7D, $%7Bthis.y%7D)%60)%0A  %7D%0A%0A  // returns a new vector orthogonal to the passed vector%0A  orthor() %7B%0A    return new Vector2(-this.y, this.x)%0A  %7D%0A%0A  // returns a new vector orthogonal to the passed vector%0A  orthol() %7B%0A    return new Vector2(this.y, -this.x
 )%0A  
@@ -877,38 +877,35 @@
  %7B%0A  return 
+new 
 Vector2
-.create
 (left.x + ri
@@ -1073,30 +1073,27 @@
  return 
+new 
 Vector2
-.create
 (left.x 
@@ -1267,38 +1267,194 @@
 %0A%7D%0A%0A
-Vector2.right = Vector2.create
+// returns normalized vector%0AVector2.normalize = function(vector) %7B%0A  const mag = Vector2.mag(vector)%0A  return new Vector2(vector.x / mag, vector.y / mag)%0A%7D%0A%0A%0AVector2.right = new Vector2
 (1, 
@@ -1472,30 +1472,27 @@
 left =  
+new 
 Vector2
-.create
 (-1, 0)%0A
@@ -1507,30 +1507,27 @@
 up =    
+new 
 Vector2
-.create
 (0, 1)%0AV
@@ -1545,22 +1545,19 @@
  =  
+new 
 Vector2
-.create
 (0, 
@@ -1584,8 +1584,9 @@
 Vector2%0A
+%0A

revert vector2 to class