Advertisement
Guest User

Class js

a guest
Feb 8th, 2016
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Coord2D(X, Y) {
  2.     var _this = this;
  3.  
  4.     (function() {
  5.         _this.X = X || 0;
  6.         _this.Y = Y || 0;
  7.     })();
  8.  
  9.     // Retourne la distance entre 2 points
  10.     this.getDistance = function(coordTo) {
  11.         return Math.pow(_this.X - coordTo.X, 2) + Math.pow(_this.Y - coordTo.Y, 2);
  12.     };
  13. }
  14.  
  15. var pointA = new Coord2D();
  16. var pointB = new Coord2D(2, 2);
  17. var dist = pointA.getDistance(pointB);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement