tesseract  4.00.00dev
outlines.cpp
Go to the documentation of this file.
1 /* -*-C-*-
2  ********************************************************************************
3  *
4  * File: outlines.c (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 #ifdef __UNIX__
35 #include <assert.h>
36 #endif
37 
38 namespace tesseract {
39 /*----------------------------------------------------------------------
40  F u n c t i o n s
41 ----------------------------------------------------------------------*/
42 /**********************************************************************
43  * near_point
44  *
45  * Find the point on a line segment that is closest to a point not on
46  * the line segment. Return that point in near_pt. Returns whether
47  * near_pt was newly created.
48  **********************************************************************/
50  EDGEPT *line_pt_0, EDGEPT *line_pt_1,
51  EDGEPT **near_pt) {
52  TPOINT p;
53 
54  float slope;
55  float intercept;
56 
57  float x0 = line_pt_0->pos.x;
58  float x1 = line_pt_1->pos.x;
59  float y0 = line_pt_0->pos.y;
60  float y1 = line_pt_1->pos.y;
61 
62  if (x0 == x1) {
63  /* Handle vertical line */
64  p.x = (inT16) x0;
65  p.y = point->pos.y;
66  }
67  else {
68  /* Slope and intercept */
69  slope = (y0 - y1) / (x0 - x1);
70  intercept = y1 - x1 * slope;
71 
72  /* Find perpendicular */
73  p.x = (inT16) ((point->pos.x + (point->pos.y - intercept) * slope) /
74  (slope * slope + 1));
75  p.y = (inT16) (slope * p.x + intercept);
76  }
77 
78  if (is_on_line (p, line_pt_0->pos, line_pt_1->pos) &&
79  (!same_point (p, line_pt_0->pos)) && (!same_point (p, line_pt_1->pos))) {
80  /* Intersection on line */
81  *near_pt = make_edgept(p.x, p.y, line_pt_1, line_pt_0);
82  return true;
83  } else { /* Intersection not on line */
84  *near_pt = closest(point, line_pt_0, line_pt_1);
85  return false;
86  }
87 }
88 
89 } // namespace tesseract
EDGEPT * make_edgept(int x, int y, EDGEPT *next, EDGEPT *prev)
Definition: split.cpp:147
TPOINT pos
Definition: blobs.h:163
bool near_point(EDGEPT *point, EDGEPT *line_pt_0, EDGEPT *line_pt_1, EDGEPT **near_pt)
Definition: outlines.cpp:49
int16_t inT16
Definition: host.h:36
inT16 x
Definition: blobs.h:71
#define closest(test_p, p1, p2)
Definition: outlines.h:71
#define same_point(p1, p2)
Definition: outlines.h:49
Definition: blobs.h:76
inT16 y
Definition: blobs.h:72
Definition: blobs.h:50
#define is_on_line(p, p0, p1)
Definition: outlines.h:120