All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
DIR128 Class Reference

#include <mod128.h>

Public Member Functions

 DIR128 ()
 
 DIR128 (inT16 value)
 
 DIR128 (const FCOORD fc)
 
DIR128operator= (inT16 value)
 
inT8 operator- (const DIR128 &minus) const
 
DIR128 operator+ (const DIR128 &add) const
 
DIR128operator+= (const DIR128 &add)
 
inT8 get_dir () const
 
ICOORD vector () const
 

Detailed Description

Definition at line 29 of file mod128.h.

Constructor & Destructor Documentation

DIR128::DIR128 ( )
inline

Definition at line 32 of file mod128.h.

32  {
33  } //empty constructor
DIR128::DIR128 ( inT16  value)
inline

Definition at line 35 of file mod128.h.

36  { //value to assign
37  value %= MODULUS; //modulo arithmetic
38  if (value < 0)
39  value += MODULUS; //done properly
40  dir = (inT8) value;
41  }
#define MODULUS
Definition: mod128.h:25
SIGNED char inT8
Definition: host.h:98
DIR128::DIR128 ( const FCOORD  fc)

Definition at line 65 of file mod128.cpp.

67  {
68  int high, low, current; //binary search
69 
70  low = 0;
71  if (fc.y () == 0) {
72  if (fc.x () >= 0)
73  dir = 0;
74  else
75  dir = MODULUS / 2;
76  return;
77  }
78  high = MODULUS;
79  do {
80  current = (high + low) / 2;
81  if (dirtab[current] * fc >= 0)
82  low = current;
83  else
84  high = current;
85  }
86  while (high - low > 1);
87  dir = low;
88 }
float x() const
Definition: points.h:209
const ICOORD * dirtab
Definition: mod128.cpp:57
#define MODULUS
Definition: mod128.h:25
float y() const
Definition: points.h:212

Member Function Documentation

inT8 DIR128::get_dir ( ) const
inline

Definition at line 77 of file mod128.h.

77  { //access function
78  return dir;
79  }
DIR128 DIR128::operator+ ( const DIR128 add) const
inline

Definition at line 64 of file mod128.h.

66  {
67  DIR128 result; //sum
68 
69  result = dir + add.dir; //let = do the work
70  return result;
71  }
Definition: mod128.h:29
DIR128& DIR128::operator+= ( const DIR128 add)
inline

Definition at line 72 of file mod128.h.

73  {
74  *this = dir + add.dir; //let = do the work
75  return *this;
76  }
inT8 DIR128::operator- ( const DIR128 minus) const
inline

Definition at line 52 of file mod128.h.

54  {
55  //result
56  inT16 result = dir - minus.dir;
57 
58  if (result > MODULUS / 2)
59  result -= MODULUS; //get in range
60  else if (result < -MODULUS / 2)
61  result += MODULUS;
62  return (inT8) result;
63  }
#define MODULUS
Definition: mod128.h:25
SIGNED char inT8
Definition: host.h:98
short inT16
Definition: host.h:100
DIR128& DIR128::operator= ( inT16  value)
inline

Definition at line 44 of file mod128.h.

45  { //value to assign
46  value %= MODULUS; //modulo arithmetic
47  if (value < 0)
48  value += MODULUS; //done properly
49  dir = (inT8) value;
50  return *this;
51  }
#define MODULUS
Definition: mod128.h:25
SIGNED char inT8
Definition: host.h:98
ICOORD DIR128::vector ( ) const

Definition at line 97 of file mod128.cpp.

97  { //convert to vector
98  return dirtab[dir]; //easy really
99 }
const ICOORD * dirtab
Definition: mod128.cpp:57

The documentation for this class was generated from the following files: