|
tesseract 3.04.01
|
00001 /* -*-C-*- 00002 ******************************************************************************** 00003 * 00004 * File: outlines.c (Formerly outlines.c) 00005 * Description: Combinatorial Splitter 00006 * Author: Mark Seaman, OCR Technology 00007 * Created: Thu Jul 27 08:59:01 1989 00008 * Modified: Wed Jul 10 14:56:49 1991 (Mark Seaman) marks@hpgrlt 00009 * Language: C 00010 * Package: N/A 00011 * Status: Experimental (Do Not Distribute) 00012 * 00013 * (c) Copyright 1989, Hewlett-Packard Company. 00014 ** Licensed under the Apache License, Version 2.0 (the "License"); 00015 ** you may not use this file except in compliance with the License. 00016 ** You may obtain a copy of the License at 00017 ** http://www.apache.org/licenses/LICENSE-2.0 00018 ** Unless required by applicable law or agreed to in writing, software 00019 ** distributed under the License is distributed on an "AS IS" BASIS, 00020 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00021 ** See the License for the specific language governing permissions and 00022 ** limitations under the License. 00023 * 00024 ******************************************************************************** 00025 * Revision 1.2 89/09/15 09:24:41 09:24:41 marks (Mark Seaman) 00026 * First released version of Combinatorial splitter code 00027 **/ 00028 /*---------------------------------------------------------------------- 00029 I n c l u d e s 00030 ----------------------------------------------------------------------*/ 00031 #include "outlines.h" 00032 #include "wordrec.h" 00033 00034 #ifdef __UNIX__ 00035 #include <assert.h> 00036 #endif 00037 00038 namespace tesseract { 00039 /*---------------------------------------------------------------------- 00040 F u n c t i o n s 00041 ----------------------------------------------------------------------*/ 00042 /********************************************************************** 00043 * near_point 00044 * 00045 * Find the point on a line segment that is closest to a point not on 00046 * the line segment. Return that point in near_pt. Returns whether 00047 * near_pt was newly created. 00048 **********************************************************************/ 00049 bool Wordrec::near_point(EDGEPT *point, 00050 EDGEPT *line_pt_0, EDGEPT *line_pt_1, 00051 EDGEPT **near_pt) { 00052 TPOINT p; 00053 00054 float slope; 00055 float intercept; 00056 00057 float x0 = line_pt_0->pos.x; 00058 float x1 = line_pt_1->pos.x; 00059 float y0 = line_pt_0->pos.y; 00060 float y1 = line_pt_1->pos.y; 00061 00062 if (x0 == x1) { 00063 /* Handle vertical line */ 00064 p.x = (inT16) x0; 00065 p.y = point->pos.y; 00066 } 00067 else { 00068 /* Slope and intercept */ 00069 slope = (y0 - y1) / (x0 - x1); 00070 intercept = y1 - x1 * slope; 00071 00072 /* Find perpendicular */ 00073 p.x = (inT16) ((point->pos.x + (point->pos.y - intercept) * slope) / 00074 (slope * slope + 1)); 00075 p.y = (inT16) (slope * p.x + intercept); 00076 } 00077 00078 if (is_on_line (p, line_pt_0->pos, line_pt_1->pos) && 00079 (!same_point (p, line_pt_0->pos)) && (!same_point (p, line_pt_1->pos))) { 00080 /* Intersection on line */ 00081 *near_pt = make_edgept(p.x, p.y, line_pt_1, line_pt_0); 00082 return true; 00083 } else { /* Intersection not on line */ 00084 *near_pt = closest(point, line_pt_0, line_pt_1); 00085 return false; 00086 } 00087 } 00088 00089 } // namespace tesseract