Bresenham.cpp
Go to the documentation of this file.00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifdef _MSC_VER
00025 #include <windows_config.h>
00026 #else
00027 #include <config.h>
00028 #endif
00029
00030 #include <iostream>
00031 #include "Bresenham.h"
00032
00033 #ifdef CHECK_MEMORY_LEAKS
00034 #include <foreign/nvwa/debug_new.h>
00035 #endif // CHECK_MEMORY_LEAKS
00036
00037
00038
00039
00040
00041 void
00042 Bresenham::compute(BresenhamCallBack *callBack, SUMOReal val1, SUMOReal val2) {
00043
00044 if (val1==val2) {
00045 for (SUMOReal step=0; step<val1; step++) {
00046 callBack->execute(step, step);
00047 }
00048 return;
00049 }
00050
00051 if (val1>val2) {
00052 SUMOReal pos = 0;
00053 SUMOReal prop = val2 / val1;
00054 SUMOReal cnt = prop / 2;
00055 for (SUMOReal i=0; i<val1; i++) {
00056 callBack->execute(i, pos);
00057 cnt += prop;
00058 if (cnt>=1.0) {
00059 pos++;
00060 cnt -= 1.0;
00061 }
00062 }
00063 return;
00064 }
00065
00066 if (val1<val2) {
00067 SUMOReal pos = 0;
00068 SUMOReal prop = val1 / val2;
00069 SUMOReal cnt = prop / 2;
00070 for (SUMOReal i=0; i<val2; i++) {
00071 callBack->execute(pos, i);
00072 cnt += prop;
00073 if (cnt>=1.0) {
00074 pos++;
00075 cnt -= 1.0;
00076 }
00077 }
00078 return;
00079 }
00080 }
00081
00082
00083
00084
00085