• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* -*-C-*-
2  ********************************************************************************
3  *
4  * File:        split.c  (Formerly split.c)
5  * Description:
6  * Author:       Mark Seaman, OCR Technology
7  * Created:      Fri Oct 16 14:37:00 1987
8  * Modified:     Fri May 17 16:27:49 1991 (Mark Seaman) marks@hpgrlt
9  * Language:     C
10  * Package:      N/A
11  * Status:       Reusable Software Component
12  *
13  * (c) Copyright 1987, 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 /*----------------------------------------------------------------------
26               I n c l u d e s
27 ----------------------------------------------------------------------*/
28 #include "split.h"
29 #include "structures.h"
30 #include "hideedge.h"
31 #include "callcpp.h"
32 
33 #ifdef __UNIX__
34 #include <assert.h>
35 #endif
36 
37 /*----------------------------------------------------------------------
38               V a r i a b l e s
39 ----------------------------------------------------------------------*/
40 BOOL_VAR(wordrec_display_splits, 0, "Display splits");
41 
42 #define SPLITBLOCK 100           /* Cells per block */
43 makestructure (newsplit, free_split, printsplit, SPLIT,
44 freesplit, SPLITBLOCK, "SPLIT", splitcount);
45 
46 /*----------------------------------------------------------------------
47               F u n c t i o n s
48 ----------------------------------------------------------------------*/
49 
50 /**********************************************************************
51  * delete_split
52  *
53  * Remove this split from existance.  Take if off the display list and
54  * deallocate its memory.
55  **********************************************************************/
delete_split(SPLIT * split)56 void delete_split(SPLIT *split) {
57   if (split) {
58     free_split(split);
59   }
60 }
61 
62 
63 /**********************************************************************
64  * make_edgept
65  *
66  * Create an EDGEPT and hook it into an existing list of edge points.
67  **********************************************************************/
make_edgept(int x,int y,EDGEPT * next,EDGEPT * prev)68 EDGEPT *make_edgept(int x, int y, EDGEPT *next, EDGEPT *prev) {
69   EDGEPT *this_edgept;
70   /* Create point */
71   this_edgept = newedgept ();
72   this_edgept->pos.x = x;
73   this_edgept->pos.y = y;
74   /* Hook it up */
75   this_edgept->next = next;
76   this_edgept->prev = prev;
77   prev->next = this_edgept;
78   next->prev = this_edgept;
79   /* Set up vec entries */
80   this_edgept->vec.x = this_edgept->next->pos.x - x;
81   this_edgept->vec.y = this_edgept->next->pos.y - y;
82   this_edgept->prev->vec.x = x - this_edgept->prev->pos.x;
83   this_edgept->prev->vec.y = y - this_edgept->prev->pos.y;
84 
85   reveal_edge(this_edgept);
86   this_edgept->flags[1] = 0;
87 
88   return (this_edgept);
89 }
90 
91 
92 /**********************************************************************
93  * new_split
94  *
95  * Create a new split record and initialize it.  Put it on the display
96  * list.
97  **********************************************************************/
new_split(EDGEPT * point1,EDGEPT * point2)98 SPLIT *new_split(EDGEPT *point1, EDGEPT *point2) {
99   SPLIT *s;
100   s = (SPLIT *) newsplit ();
101   s->point1 = point1;
102   s->point2 = point2;
103   return (s);
104 }
105 
106 
107 /**********************************************************************
108  * print_split
109  *
110  * Print a list of splits.  Show the coordinates of both points in
111  * each split.
112  **********************************************************************/
print_split(SPLIT * split)113 void print_split(SPLIT *split) {
114   if (split) {
115     cprintf ("(%d,%d)--(%d,%d)",
116       split->point1->pos.x, split->point1->pos.y,
117       split->point2->pos.x, split->point2->pos.y);
118   }
119 }
120 
121 
122 /**********************************************************************
123  * split_outline
124  *
125  * Split between these two edge points. Apply a split and return a
126  * pointer to the other side of the split.
127  **********************************************************************/
split_outline(EDGEPT * join_point1,EDGEPT * join_point2)128 void split_outline(EDGEPT *join_point1, EDGEPT *join_point2) {
129   EDGEPT *join_point1a;
130   EDGEPT *temp2;
131   EDGEPT *temp1;
132 
133   assert (join_point1 != join_point2);
134 
135   temp2 = join_point2->next;
136   temp1 = join_point1->next;
137   /* Create two new points */
138   join_point1a = make_edgept (join_point1->pos.x,
139     join_point1->pos.y, temp1, join_point2);
140 
141   make_edgept (join_point2->pos.x, join_point2->pos.y, temp2, join_point1);
142 }
143 
144 
145 /**********************************************************************
146  * unsplit_outlines
147  *
148  * Remove the split that was put between these two points.
149  **********************************************************************/
unsplit_outlines(EDGEPT * p1,EDGEPT * p2)150 void unsplit_outlines(EDGEPT *p1, EDGEPT *p2) {
151   EDGEPT *tmp1 = p1->next;
152   EDGEPT *tmp2 = p2->next;
153 
154   assert (p1 != p2);
155 
156   tmp1->next->prev = p2;
157   tmp2->next->prev = p1;
158 
159   p1->next = tmp2->next;
160   p2->next = tmp1->next;
161 
162   oldedgept(tmp1);
163   oldedgept(tmp2);
164 
165   p1->vec.x = p1->next->pos.x - p1->pos.x;
166   p1->vec.y = p1->next->pos.y - p1->pos.y;
167 
168   p2->vec.x = p2->next->pos.x - p2->pos.x;
169   p2->vec.y = p2->next->pos.y - p2->pos.y;
170 }
171