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