All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
mod128.h
Go to the documentation of this file.
1 /**********************************************************************
2  * File: mod128.h (Formerly dir128.h)
3  * Description: Header for class which implements modulo arithmetic.
4  * Author: Ray Smith
5  * Created: Tue Mar 26 17:48:13 GMT 1991
6  *
7  * (C) Copyright 1991, Hewlett-Packard Ltd.
8  ** Licensed under the Apache License, Version 2.0 (the "License");
9  ** you may not use this file except in compliance with the License.
10  ** You may obtain a copy of the License at
11  ** http://www.apache.org/licenses/LICENSE-2.0
12  ** Unless required by applicable law or agreed to in writing, software
13  ** distributed under the License is distributed on an "AS IS" BASIS,
14  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  ** See the License for the specific language governing permissions and
16  ** limitations under the License.
17  *
18  **********************************************************************/
19 
20 #ifndef MOD128_H
21 #define MOD128_H
22 
23 #include "points.h"
24 
25 #define MODULUS 128 /*range of directions */
26 #define DIRBITS 7 //no of bits used
27 #define DIRSCALE 1000 //length of vector
28 
30 {
31  public:
32  DIR128() {
33  } //empty constructor
34 
35  DIR128( //constructor
36  inT16 value) { //value to assign
37  value %= MODULUS; //modulo arithmetic
38  if (value < 0)
39  value += MODULUS; //done properly
40  dir = (inT8) value;
41  }
42  DIR128(const FCOORD fc); //quantize vector
43 
44  DIR128 & operator= ( //assign of inT16
45  inT16 value) { //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  }
52  inT8 operator- ( //subtraction
53  const DIR128 & minus) const//for signed result
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  }
64  DIR128 operator+ ( //addition
65  const DIR128 & add) const //of itself
66  {
67  DIR128 result; //sum
68 
69  result = dir + add.dir; //let = do the work
70  return result;
71  }
72  DIR128 & operator+= ( //same as +
73  const DIR128 & add) {
74  *this = dir + add.dir; //let = do the work
75  return *this;
76  }
77  inT8 get_dir() const { //access function
78  return dir;
79  }
80  ICOORD vector() const; //turn to vector
81 
82  private:
83  inT8 dir; //a direction
84 };
85 #endif
#define MODULUS
Definition: mod128.h:25
Definition: mod128.h:29
ICOORD operator-(const ICOORD &src)
Definition: ipoints.h:50
integer coordinate
Definition: points.h:30
ICOORD operator+(const ICOORD &op1, const ICOORD &op2)
Definition: ipoints.h:68
SIGNED char inT8
Definition: host.h:98
DIR128(inT16 value)
Definition: mod128.h:35
DIR128()
Definition: mod128.h:32
inT8 get_dir() const
Definition: mod128.h:77
ICOORD & operator+=(ICOORD &op1, const ICOORD &op2)
Definition: ipoints.h:86
#define DLLSYM
Definition: platform.h:25
Definition: points.h:189
short inT16
Definition: host.h:100