| 23 | namespace devilution { |
| 24 | |
| 25 | Direction GetDirection(Point start, Point destination) |
| 26 | { |
| 27 | Direction md; |
| 28 | |
| 29 | int mx = destination.x - start.x; |
| 30 | int my = destination.y - start.y; |
| 31 | if (mx >= 0) { |
| 32 | if (my >= 0) { |
| 33 | if (5 * mx <= (my * 2)) // mx/my <= 0.4, approximation of tan(22.5) |
| 34 | return Direction::SouthWest; |
| 35 | md = Direction::South; |
| 36 | } else { |
| 37 | my = -my; |
| 38 | if (5 * mx <= (my * 2)) |
| 39 | return Direction::NorthEast; |
| 40 | md = Direction::East; |
| 41 | } |
| 42 | if (5 * my <= (mx * 2)) // my/mx <= 0.4 |
| 43 | md = Direction::SouthEast; |
| 44 | } else { |
| 45 | mx = -mx; |
| 46 | if (my >= 0) { |
| 47 | if (5 * mx <= (my * 2)) |
| 48 | return Direction::SouthWest; |
| 49 | md = Direction::West; |
| 50 | } else { |
| 51 | my = -my; |
| 52 | if (5 * mx <= (my * 2)) |
| 53 | return Direction::NorthEast; |
| 54 | md = Direction::North; |
| 55 | } |
| 56 | if (5 * my <= (mx * 2)) |
| 57 | md = Direction::NorthWest; |
| 58 | } |
| 59 | return md; |
| 60 | } |
| 61 | |
| 62 | int CalculateWidth2(int width) |
| 63 | { |
no outgoing calls