tesseract  4.0.0-1-g2a2b
mod128.cpp
Go to the documentation of this file.
1 /**********************************************************************
2  * File: mod128.cpp (Formerly dir128.c)
3  * Description: Code to convert a DIR128 to an ICOORD.
4  * Author: Ray Smith
5  * Created: Tue Oct 22 11:56:09 BST 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 #include "mod128.h"
21 
22 static const int16_t idirtab[] = {
23  1000, 0, 998, 49, 995, 98, 989, 146,
24  980, 195, 970, 242, 956, 290, 941, 336,
25  923, 382, 903, 427, 881, 471, 857, 514,
26  831, 555, 803, 595, 773, 634, 740, 671,
27  707, 707, 671, 740, 634, 773, 595, 803,
28  555, 831, 514, 857, 471, 881, 427, 903,
29  382, 923, 336, 941, 290, 956, 242, 970,
30  195, 980, 146, 989, 98, 995, 49, 998,
31  0, 1000, -49, 998, -98, 995, -146, 989,
32  -195, 980, -242, 970, -290, 956, -336, 941,
33  -382, 923, -427, 903, -471, 881, -514, 857,
34  -555, 831, -595, 803, -634, 773, -671, 740,
35  -707, 707, -740, 671, -773, 634, -803, 595,
36  -831, 555, -857, 514, -881, 471, -903, 427,
37  -923, 382, -941, 336, -956, 290, -970, 242,
38  -980, 195, -989, 146, -995, 98, -998, 49,
39  -1000, 0, -998, -49, -995, -98, -989, -146,
40  -980, -195, -970, -242, -956, -290, -941, -336,
41  -923, -382, -903, -427, -881, -471, -857, -514,
42  -831, -555, -803, -595, -773, -634, -740, -671,
43  -707, -707, -671, -740, -634, -773, -595, -803,
44  -555, -831, -514, -857, -471, -881, -427, -903,
45  -382, -923, -336, -941, -290, -956, -242, -970,
46  -195, -980, -146, -989, -98, -995, -49, -998,
47  0, -1000, 49, -998, 98, -995, 146, -989,
48  195, -980, 242, -970, 290, -956, 336, -941,
49  382, -923, 427, -903, 471, -881, 514, -857,
50  555, -831, 595, -803, 634, -773, 671, -740,
51  707, -707, 740, -671, 773, -634, 803, -595,
52  831, -555, 857, -514, 881, -471, 903, -427,
53  923, -382, 941, -336, 956, -290, 970, -242,
54  980, -195, 989, -146, 995, -98, 998, -49
55 };
56 
57 const ICOORD* dirtab = reinterpret_cast<const ICOORD*>(idirtab);
58 
59 /**********************************************************************
60  * DIR128::DIR128
61  *
62  * Quantize the direction of an FCOORD to make a DIR128.
63  **********************************************************************/
64 
65 DIR128::DIR128( //from fcoord
66  const FCOORD fc //vector to quantize
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 }
const ICOORD * dirtab
Definition: mod128.cpp:57
integer coordinate
Definition: points.h:32
#define MODULUS
Definition: mod128.h:25
Definition: points.h:189
float x() const
Definition: points.h:208
DIR128()=default
float y() const
Definition: points.h:211