Guest User

Untitled

a guest
Feb 25th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. class Ejercicio {
  2.  
  3.  
  4. constructor(){
  5. this.w = this.width = 194, this.height= 122;
  6. this.g = Array(this.width*(this.height+2)).fill(0);
  7.  
  8. for(let i=0; i< this.width; i++){
  9. for(let j=0; j< this.height; j++){
  10. if (j <= 2 || j >= this.height - 2 )
  11. this.g[ j*this.width + i ] = 7 ;
  12. if (i <= 2 || i >= this.width - 2 )
  13. this.g[ j*this.width + i ] = 7 ;
  14. }
  15. }
  16.  
  17.  
  18. };
  19.  
  20. cmp(x, y){
  21. if (x > y) return 1;
  22. else if (x < y) return -1;
  23. else return 0;
  24. };
  25.  
  26. cell_empty(x,y){
  27. return this.g[this.w*y+x] == 0;
  28. };
  29.  
  30. pscan(p0,p1){
  31. let g = this.g; let [x,y] = p0; let [x0,y0] = p0;
  32. let [x1,y1] = p1;
  33. let ux=this.cmp(x1,x0);
  34. let uy=this.cmp(y1,y0);
  35. let adx = Math.abs(x1-x0)+1; let ady = Math.abs(y1-y0)+1;
  36.  
  37. while (x!=x1 || y!= y1) {
  38. if (Math.abs((x1-x)*ady) > Math.abs((y1-y)*adx)){
  39. if (!this.cell_empty(x+ux,y))
  40. return [[x+ux,y], [ux,0]];
  41. else
  42. x += 2*ux;
  43. }else{
  44. if (! this.cell_empty(x,y+uy))
  45. return [[x,y+uy], [0, uy]];
  46. else
  47. y += 2*uy;
  48. }
  49. }
  50. return null;
  51. };
  52.  
  53. prueba(){
  54. let p0 = [63, 57];
  55. let p1 = [55, 61];
  56. let res = this.pscan(p0, p1);
  57. };
  58.  
  59. }
  60.  
  61.  
  62. let ej = new Ejercicio();
  63. let res = ej.prueba();
Add Comment
Please, Sign In to add comment