SUMO - Simulation of Urban MObility
Bresenham.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
18 // A class to realise a uniform n:m - relationship using the
19 /****************************************************************************/
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #ifdef _MSC_VER
26 #include <windows_config.h>
27 #else
28 #include <config.h>
29 #endif
30 
31 #include <iostream>
32 #include <utils/common/StdDefs.h>
33 #include "Bresenham.h"
34 
35 
36 // ===========================================================================
37 // method definitions
38 // ===========================================================================
39 void
40 Bresenham::compute(BresenhamCallBack* callBack, const int val1, const int val2) {
41  const int smaller = MIN2(val1, val2);
42  const int greater = MAX2(val1, val2);
43  int pos = 0;
44  int c = smaller;
45  for (int i = 0; i < greater; i++) {
46  if (smaller == val1) {
47  callBack->execute(pos, i);
48  } else {
49  callBack->execute(i, pos);
50  }
51  c += 2 * smaller;
52  if (c >= 2 * greater) {
53  pos++;
54  c -= 2 * greater;
55  }
56  }
57 }
58 
59 
60 
61 /****************************************************************************/
62 
T MAX2(T a, T b)
Definition: StdDefs.h:73
T MIN2(T a, T b)
Definition: StdDefs.h:67
static void compute(BresenhamCallBack *callBack, const int val1, const int val2)
Definition: Bresenham.cpp:40
virtual void execute(const int val1, const int val2)=0