MFMv2.0.10
Movable Feast Machine Simulator 2.0.10
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Dirs.h
Go to the documentation of this file.
1 /* -*- mode:C++ -*-
2  Dirs.h Euclidean direction system
3  Copyright (C) 2014 The Regents of the University of New Mexico. All rights reserved.
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this library; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
18  USA
19 */
20 
28 #ifndef DIRS_H
29 #define DIRS_H
30 
31 #include "Point.h"
32 
33 namespace MFM
34 {
35 
36  typedef u32 Dir;
37 
38  class Dirs
39  {
40  public:
41  static const Dir NORTH = 0;
42  static const Dir NORTHEAST = 1;
43  static const Dir EAST = 2;
44  static const Dir SOUTHEAST = 3;
45  static const Dir SOUTH = 4;
46  static const Dir SOUTHWEST = 5;
47  static const Dir WEST = 6;
48  static const Dir NORTHWEST = 7;
49  static const Dir DIR_COUNT = 8;
50 
54  static const char * GetName(Dir dir)
55  {
56  switch (dir)
57  {
58  case NORTH: return "North";
59  case EAST: return "East";
60  case SOUTH: return "South";
61  case WEST: return "West";
62  case NORTHEAST: return "Northeast";
63  case SOUTHEAST: return "Southeast";
64  case SOUTHWEST: return "Southwest";
65  case NORTHWEST: return "Northwest";
66  default: return "INVALID DIRECTION";
67  }
68  }
69 
73  static bool IsCorner(Dir dir) { return dir&1; }
74 
78  static bool IsFace(Dir dir) { return !IsCorner(dir); }
79 
84  static Dir CWDir(Dir dir) { return (dir+1)%DIR_COUNT; }
85 
91  static Dir OppositeDir(Dir dir)
92  { return (dir + (DIR_COUNT / 2)) % DIR_COUNT; }
93 
98  static Dir CCWDir(Dir dir) { return (dir+DIR_COUNT-1)%DIR_COUNT; }
99 
109  static inline u32 AddDirToMask(u32 mask, Dir dir)
110  { return mask | (1 << dir); }
111 
121  static inline u32 RemoveDirInMask(u32 mask, Dir dir)
122  { return mask & (~(1 << dir)); }
123 
133  static inline bool TestDirInMask(u32 mask, Dir dir)
134  { return mask & (1 << dir); }
135 
151  static void FillDir(SPoint& pt, Dir dir);
152 
164  static Dir FromOffset(SPoint& pt);
165 
173  static inline SPoint & FlipXAxis(SPoint & pt) {
174  pt.SetX(-pt.GetX());
175  return pt;
176  }
177 
178 
186  static inline SPoint & FlipYAxis(SPoint & pt) {
187  pt.SetY(-pt.GetY());
188  return pt;
189  }
190 
214  static SPoint FlipSEPointToCorner(const SPoint& pt, const Dir corner);
215  };
216 } /* namespace MFM */
217 
218 #endif /*DIRS_H*/
static bool IsCorner(Dir dir)
Definition: Dirs.h:73
Definition: Dirs.h:38
static SPoint & FlipXAxis(SPoint &pt)
Definition: Dirs.h:173
static Dir FromOffset(SPoint &pt)
Definition: Dirs.cpp:39
static Dir OppositeDir(Dir dir)
Definition: Dirs.h:91
T GetY() const
Definition: Point.tcc:40
static Dir CWDir(Dir dir)
Definition: Dirs.h:84
static Dir CCWDir(Dir dir)
Definition: Dirs.h:98
void SetX(T x)
Definition: Point.tcc:164
static bool IsFace(Dir dir)
Definition: Dirs.h:78
static bool TestDirInMask(u32 mask, Dir dir)
Definition: Dirs.h:133
static const char * GetName(Dir dir)
Definition: Dirs.h:54
static u32 RemoveDirInMask(u32 mask, Dir dir)
Definition: Dirs.h:121
void SetY(T y)
Definition: Point.tcc:170
static void FillDir(SPoint &pt, Dir dir)
Definition: Dirs.cpp:22
static SPoint FlipSEPointToCorner(const SPoint &pt, const Dir corner)
Definition: Dirs.cpp:7
static SPoint & FlipYAxis(SPoint &pt)
Definition: Dirs.h:186
static u32 AddDirToMask(u32 mask, Dir dir)
Definition: Dirs.h:109
Definition: Point.h:45
T GetX() const
Definition: Point.tcc:34