Create Position Class - Node.js Data Structure

Node.js examples for Data Structure:Rectangle

Description

Create Position Class

Demo Code

function Pos(x, y)
{
  this.x = x;//w ww  . j ava  2s  .c om
  this.y = y;
  
  this.add = function(pos)
  {
    return new Pos(this.x + pos.x, this.y + pos.y);
  }
  
  this.sub = function(pos)
  {
    return new Pos(this.x - pos.x, this.y - pos.y);
  }
  
  this.equals = function(pos)
  {
    return this.x == pos.x && this.y == pos.y;
  }
  
  this.toString = function()
  {
    return "(" + this.x + "," + this.y + ")";
  }
}

Related Tutorials