Guest User

Untitled

a guest
Jan 21st, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. void CMisc::GetPoint(int x0, int y0, int x1, int y1, int * pX, int * pY, int * pError)
  2. { int dx, dy, x_inc, y_inc, error, index;
  3. int iResultX, iResultY;
  4. if ((x0 == x1) && (y0 == y1))
  5. { *pX = x0;
  6. *pY = y0;
  7. *pError = 0;
  8. return;
  9. }
  10. error = *pError;
  11. iResultX = x0;
  12. iResultY = y0;
  13. dx = x1 - x0;
  14. dy = y1 - y0;
  15. x_inc = -1;
  16. if (dx >= 0) { x_inc = 1; }
  17. else { dx = -dx; }
  18. y_inc = -1;
  19. if (dy >= 0) { y_inc = 1; }
  20. else { dy = -dy; }
  21. if (dx > dy)
  22. { for (index = 0; index <= dx; index++)
  23. { error += dy;
  24. if (error>dx)
  25. { error -= dx;
  26. iResultY += y_inc;
  27. }
  28. iResultX += x_inc;
  29. goto CALC_OK;
  30. }
  31. }
  32. else
  33. { for (index = 0; index <= dy; index++)
  34. { error += dx;
  35. if (error>0)
  36. { error -= dy;
  37. iResultX += x_inc;
  38. }
  39. iResultY += y_inc;
  40. goto CALC_OK;
  41. } }
  42. CALC_OK:;
  43. *pX = iResultX;
  44. *pY = iResultY;
  45. *pError = error;
  46. }
  47.  
  48.  
  49. void CMisc::GetPoint2(int x0, int y0, int x1, int y1, int * pX, int * pY, int * pError, int iCount)
  50. { int dx, dy, x_inc, y_inc, error, index;
  51. int iResultX, iResultY, iCnt = 0;
  52. if ((x0 == x1) && (y0 == y1))
  53. { *pX = x0;
  54. *pY = y0;
  55. *pError = 0;
  56. return;
  57. }
  58. error = *pError;
  59. iResultX = x0;
  60. iResultY = y0;
  61. dx = x1 - x0;
  62. dy = y1 - y0;
  63. x_inc = -1;
  64. if (dx >= 0) { x_inc = 1; }
  65. else { dx = -dx; }
  66. y_inc = -1;
  67. if (dy >= 0) { y_inc = 1; }
  68. else { dy = -dy; }
  69. if (dx>dy)
  70. { for (index = 0; index <= dx; index++)
  71. { error += dy;
  72. if (error > dx)
  73. { error -= dx;
  74. iResultY += y_inc;
  75. }
  76. iResultX += x_inc;
  77. iCnt++;
  78. if (iCnt >= iCount) goto CALC_OK;
  79. }
  80. }else
  81. { for (index = 0; index <= dy; index++)
  82. { error += dx;
  83. if (error > dy)
  84. { error -= dy;
  85. iResultX += x_inc;
  86. }
  87. iResultY += y_inc;
  88. iCnt++;
  89. if (iCnt >= iCount) goto CALC_OK;
  90. } }
  91. CALC_OK:;
  92. *pX = iResultX;
  93. *pY = iResultY;
  94. *pError = error;
  95. }
Add Comment
Please, Sign In to add comment