SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Bresenham.cpp
Go to the documentation of this file.
1 /****************************************************************************/
8 // A class to realise a uniform n:m - relationship using the
9 /****************************************************************************/
10 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
11 // Copyright (C) 2001-2014 DLR (http://www.dlr.de/) and contributors
12 /****************************************************************************/
13 //
14 // This file is part of SUMO.
15 // SUMO is free software: you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation, either version 3 of the License, or
18 // (at your option) any later version.
19 //
20 /****************************************************************************/
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #ifdef _MSC_VER
27 #include <windows_config.h>
28 #else
29 #include <config.h>
30 #endif
31 
32 #include <iostream>
33 #include <utils/common/StdDefs.h>
34 #include "Bresenham.h"
35 
36 #ifdef CHECK_MEMORY_LEAKS
37 #include <foreign/nvwa/debug_new.h>
38 #endif // CHECK_MEMORY_LEAKS
39 
40 
41 // ===========================================================================
42 // method definitions
43 // ===========================================================================
44 void
45 Bresenham::compute(BresenhamCallBack* callBack, const unsigned int val1, const unsigned int val2) {
46  const unsigned int smaller = MIN2(val1, val2);
47  const unsigned int greater = MAX2(val1, val2);
48  unsigned int pos = 0;
49  unsigned int c = smaller;
50  for (unsigned int i = 0; i < greater; i++) {
51  if (smaller == val1) {
52  callBack->execute(pos, i);
53  } else {
54  callBack->execute(i, pos);
55  }
56  c += 2 * smaller;
57  if (c >= 2 * greater) {
58  pos++;
59  c -= 2 * greater;
60  }
61  }
62 }
63 
64 
65 
66 /****************************************************************************/
67 
T MAX2(T a, T b)
Definition: StdDefs.h:72
T MIN2(T a, T b)
Definition: StdDefs.h:66
virtual void execute(const unsigned int val1, const unsigned int val2)=0
static void compute(BresenhamCallBack *callBack, const unsigned int val1, const unsigned int val2)
Definition: Bresenham.cpp:45