tesseract  4.0.0-1-g2a2b
outlines.cpp
Go to the documentation of this file.
1 /* -*-C-*-
2  ********************************************************************************
3  *
4  * File: outlines.cpp (Formerly outlines.c)
5  * Description: Combinatorial Splitter
6  * Author: Mark Seaman, OCR Technology
7  * Created: Thu Jul 27 08:59:01 1989
8  * Modified: Wed Jul 10 14:56:49 1991 (Mark Seaman) marks@hpgrlt
9  * Language: C
10  * Package: N/A
11  * Status: Experimental (Do Not Distribute)
12  *
13  * (c) Copyright 1989, Hewlett-Packard Company.
14  ** Licensed under the Apache License, Version 2.0 (the "License");
15  ** you may not use this file except in compliance with the License.
16  ** You may obtain a copy of the License at
17  ** http://www.apache.org/licenses/LICENSE-2.0
18  ** Unless required by applicable law or agreed to in writing, software
19  ** distributed under the License is distributed on an "AS IS" BASIS,
20  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21  ** See the License for the specific language governing permissions and
22  ** limitations under the License.
23  *
24  ********************************************************************************
25  * Revision 1.2 89/09/15 09:24:41 09:24:41 marks (Mark Seaman)
26  * First released version of Combinatorial splitter code
27  **/
28 /*----------------------------------------------------------------------
29  I n c l u d e s
30 ----------------------------------------------------------------------*/
31 #include "outlines.h"
32 #include "wordrec.h"
33 
34 namespace tesseract {
35 /*----------------------------------------------------------------------
36  F u n c t i o n s
37 ----------------------------------------------------------------------*/
38 /**********************************************************************
39  * near_point
40  *
41  * Find the point on a line segment that is closest to a point not on
42  * the line segment. Return that point in near_pt. Returns whether
43  * near_pt was newly created.
44  **********************************************************************/
46  EDGEPT *line_pt_0, EDGEPT *line_pt_1,
47  EDGEPT **near_pt) {
48  TPOINT p;
49 
50  float slope;
51  float intercept;
52 
53  float x0 = line_pt_0->pos.x;
54  float x1 = line_pt_1->pos.x;
55  float y0 = line_pt_0->pos.y;
56  float y1 = line_pt_1->pos.y;
57 
58  if (x0 == x1) {
59  /* Handle vertical line */
60  p.x = (int16_t) x0;
61  p.y = point->pos.y;
62  }
63  else {
64  /* Slope and intercept */
65  slope = (y0 - y1) / (x0 - x1);
66  intercept = y1 - x1 * slope;
67 
68  /* Find perpendicular */
69  p.x = (int16_t) ((point->pos.x + (point->pos.y - intercept) * slope) /
70  (slope * slope + 1));
71  p.y = (int16_t) (slope * p.x + intercept);
72  }
73 
74  if (is_on_line (p, line_pt_0->pos, line_pt_1->pos) &&
75  (!same_point (p, line_pt_0->pos)) && (!same_point (p, line_pt_1->pos))) {
76  /* Intersection on line */
77  *near_pt = make_edgept(p.x, p.y, line_pt_1, line_pt_0);
78  return true;
79  } else { /* Intersection not on line */
80  *near_pt = closest(point, line_pt_0, line_pt_1);
81  return false;
82  }
83 }
84 
85 } // namespace tesseract
EDGEPT * make_edgept(int x, int y, EDGEPT *next, EDGEPT *prev)
Definition: split.cpp:145
TPOINT pos
Definition: blobs.h:170
#define is_on_line(p, p0, p1)
Definition: outlines.h:121
bool near_point(EDGEPT *point, EDGEPT *line_pt_0, EDGEPT *line_pt_1, EDGEPT **near_pt)
Definition: outlines.cpp:45
Definition: blobs.h:83
#define closest(test_p, p1, p2)
Definition: outlines.h:72
int16_t x
Definition: blobs.h:78
Definition: blobs.h:57
#define same_point(p1, p2)
Definition: outlines.h:50
int16_t y
Definition: blobs.h:79