SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00008 // A class to realise a uniform n:m - relationship using the 00009 /****************************************************************************/ 00010 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00011 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors 00012 /****************************************************************************/ 00013 // 00014 // This file is part of SUMO. 00015 // SUMO is free software: you can redistribute it and/or modify 00016 // it under the terms of the GNU General Public License as published by 00017 // the Free Software Foundation, either version 3 of the License, or 00018 // (at your option) any later version. 00019 // 00020 /****************************************************************************/ 00021 00022 00023 // =========================================================================== 00024 // included modules 00025 // =========================================================================== 00026 #ifdef _MSC_VER 00027 #include <windows_config.h> 00028 #else 00029 #include <config.h> 00030 #endif 00031 00032 #include <iostream> 00033 #include <utils/common/StdDefs.h> 00034 #include "Bresenham.h" 00035 00036 #ifdef CHECK_MEMORY_LEAKS 00037 #include <foreign/nvwa/debug_new.h> 00038 #endif // CHECK_MEMORY_LEAKS 00039 00040 00041 // =========================================================================== 00042 // method definitions 00043 // =========================================================================== 00044 void 00045 Bresenham::compute(BresenhamCallBack* callBack, const unsigned int val1, const unsigned int val2) { 00046 const unsigned int smaller = MIN2(val1, val2); 00047 const unsigned int greater = MAX2(val1, val2); 00048 unsigned int pos = 0; 00049 unsigned int c = smaller; 00050 for (unsigned int i = 0; i < greater; i++) { 00051 if (smaller == val1) { 00052 callBack->execute(pos, i); 00053 } else { 00054 callBack->execute(i, pos); 00055 } 00056 c += 2 * smaller; 00057 if (c >= 2 * greater) { 00058 pos++; 00059 c -= 2 * greater; 00060 } 00061 } 00062 } 00063 00064 00065 00066 /****************************************************************************/ 00067