wordrec/split.cpp

Go to the documentation of this file.
00001 
00020 /*----------------------------------------------------------------------
00021               I n c l u d e s
00022 ----------------------------------------------------------------------*/
00023 #include "split.h"
00024 #include "structures.h"
00025 #include "debug.h"
00026 #include "hideedge.h"
00027 #include "callcpp.h"
00028 
00029 #ifdef __UNIX__
00030 #include <assert.h>
00031 #endif
00032 
00033 /*----------------------------------------------------------------------
00034               V a r i a b l e s
00035 ----------------------------------------------------------------------*/
00036 
00039 make_toggle_var (display_splits, 0, make_display_splits,
00040 3, 3, set_display_splits, "Display splits");
00041 
00042 #define SPLITBLOCK 100           /* Cells per block */
00043 makestructure (newsplit, free_split, printsplit, SPLIT,
00044 freesplit, SPLITBLOCK, "SPLIT", splitcount);
00047 /*----------------------------------------------------------------------
00048               F u n c t i o n s
00049 ----------------------------------------------------------------------*/
00050 /* ================== */
00055 void init_splitter_vars() { 
00056   make_display_splits(); 
00057 }
00058 
00059 
00060 /* ================== */
00066 void delete_split(SPLIT *split) { 
00067   if (split) {
00068     free_split(split); 
00069   }
00070 }
00071 
00072 
00073 /* ================== */
00077 EDGEPT *make_edgept(int x, int y, EDGEPT *next, EDGEPT *prev) { 
00078   EDGEPT *this_edgept;
00079   /* Create point */
00080   this_edgept = newedgept ();
00081   this_edgept->pos.x = x;
00082   this_edgept->pos.y = y;
00083   /* Hook it up */
00084   this_edgept->next = next;
00085   this_edgept->prev = prev;
00086   prev->next = this_edgept;
00087   next->prev = this_edgept;
00088   /* Set up vec entries */
00089   this_edgept->vec.x = this_edgept->next->pos.x - x;
00090   this_edgept->vec.y = this_edgept->next->pos.y - y;
00091   this_edgept->prev->vec.x = x - this_edgept->prev->pos.x;
00092   this_edgept->prev->vec.y = y - this_edgept->prev->pos.y;
00093 
00094   reveal_edge(this_edgept); 
00095   this_edgept->flags[1] = 0;
00096 
00097   return (this_edgept);
00098 }
00099 
00100 
00101 /* ================== */
00105 SPLIT *new_split(EDGEPT *point1, EDGEPT *point2) { 
00106   SPLIT *s;
00107   s = (SPLIT *) newsplit ();
00108   s->point1 = point1;
00109   s->point2 = point2;
00110   return (s);
00111 }
00112 
00113 
00114 /* ================== */
00120 void print_split(SPLIT *split) { 
00121   if (split) {
00122     cprintf ("(%d,%d)--(%d,%d)",
00123       split->point1->pos.x, split->point1->pos.y,
00124       split->point2->pos.x, split->point2->pos.y);
00125   }
00126 }
00127 
00128 
00129 /* ================== */
00135 void split_outline(EDGEPT *join_point1, EDGEPT *join_point2) { 
00136   EDGEPT *join_point1a;
00137   EDGEPT *temp2;
00138   EDGEPT *temp1;
00139 
00140   assert (join_point1 != join_point2);
00141 
00142   temp2 = join_point2->next;
00143   temp1 = join_point1->next;
00144   /* Create two new points */
00145   join_point1a = make_edgept (join_point1->pos.x,
00146     join_point1->pos.y, temp1, join_point2);
00147 
00148   make_edgept (join_point2->pos.x, join_point2->pos.y, temp2, join_point1);
00149 }
00150 
00151 
00152 /* ================== */
00156 void unsplit_outlines(EDGEPT *p1, EDGEPT *p2) { 
00157   EDGEPT *tmp1 = p1->next;
00158   EDGEPT *tmp2 = p2->next;
00159 
00160   assert (p1 != p2);
00161 
00162   tmp1->next->prev = p2;
00163   tmp2->next->prev = p1;
00164 
00165   p1->next = tmp2->next;
00166   p2->next = tmp1->next;
00167 
00168   oldedgept(tmp1); 
00169   oldedgept(tmp2); 
00170 
00171   p1->vec.x = p1->next->pos.x - p1->pos.x;
00172   p1->vec.y = p1->next->pos.y - p1->pos.y;
00173 
00174   p2->vec.x = p2->next->pos.x - p2->pos.x;
00175   p2->vec.y = p2->next->pos.y - p2->pos.y;
00176 }

Generated on Wed Feb 28 19:49:13 2007 for Tesseract by  doxygen 1.5.1