Advertisement
Tyler_Elric

corsinversion.js

Dec 19th, 2013
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function(a,b,step){
  2.   var increasing = null, decreasing=null,directions={X:-1,Y:-1};
  3.   if(a.X<b.X){
  4.     increasing = 'X';
  5.     decreasing = 'Y';
  6.     directions.X=1;
  7.   }
  8.   if(a.Y<b.Y){
  9.     increasing = 'Y';
  10.     decreasing = 'X';
  11.     directions.Y=1;
  12.   }
  13.   step *= ( b[increasing] - a[increasing] );
  14.   is_good = (function(p){
  15.     return a[increasing]<b[increasing]?p[increasing]<b[increasing]:p[increasing]<b[increasing];
  16.   });
  17.   var p = {X:a.X,Y:a.Y}, inverted_point = {X:0,Y:0};
  18.   inverted_point[increasing] = b[increasing];
  19.   inverted_point[decreasing] = b[decreasing];
  20.   while(is_good(p)){
  21.     console.log("(",p.X,",",p.Y,")::(",inverted_point.X,",",inverted_point.Y,");");
  22.     inverted_point[decreasing]+=step*directions[decreasing];
  23.     p[increasing]+=step*directions[increasing];
  24.   }
  25. })({X:0,Y:30},{X:20,Y:10},2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement