You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

58 lines
1.1 KiB

  1. int x1, y1, x2, y2;
  2. int dx, dy;
  3. int xinc, yinc;
  4. x1 = s->x1; y1 = s->y1; x2 = s->x2; y2 = s->y2;
  5. dx = abs(x2 - x1);
  6. dy = abs(y2 - y1);
  7. xinc = (x1 > x2) ? -1 : 1;
  8. yinc = (y1 > y2) ? -1 : 1;
  9. if(dx >= dy)
  10. {
  11. int dpr = dy << 1;
  12. int dpru = dpr - (dx << 1);
  13. int delta = dpr - dx;
  14. for(; dx>=0; dx--)
  15. {
  16. ASSIGN(x1, y1, img->w);
  17. if(delta > 0)
  18. {
  19. x1 += xinc;
  20. y1 += yinc;
  21. delta += dpru;
  22. }
  23. else
  24. {
  25. x1 += xinc;
  26. delta += dpr;
  27. }
  28. }
  29. }
  30. else
  31. {
  32. int dpr = dx << 1;
  33. int dpru = dpr - (dy << 1);
  34. int delta = dpr - dy;
  35. for(; dy >= 0; dy--)
  36. {
  37. ASSIGN(x1, y1, img->w);
  38. if(delta > 0)
  39. {
  40. x1 += xinc;
  41. y1 += yinc;
  42. delta += dpru;
  43. }
  44. else
  45. {
  46. y1 += yinc;
  47. delta += dpr;
  48. }
  49. }
  50. }