All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
split.h File Reference
#include "blobs.h"
#include "scrollview.h"

Go to the source code of this file.

Classes

struct  SPLIT
 

Functions

EDGEPTmake_edgept (int x, int y, EDGEPT *next, EDGEPT *prev)
 
void remove_edgept (EDGEPT *point)
 

Variables

bool wordrec_display_splits = 0
 

Function Documentation

EDGEPT* make_edgept ( int  x,
int  y,
EDGEPT next,
EDGEPT prev 
)

Definition at line 142 of file split.cpp.

142  {
143  EDGEPT *this_edgept;
144  /* Create point */
145  this_edgept = new EDGEPT;
146  this_edgept->pos.x = x;
147  this_edgept->pos.y = y;
148  // Now deal with the src_outline steps.
149  C_OUTLINE* prev_ol = prev->src_outline;
150  if (prev_ol != NULL && prev->next == next) {
151  // Compute the fraction of the segment that is being cut.
152  FCOORD segment_vec(next->pos.x - prev->pos.x, next->pos.y - prev->pos.y);
153  FCOORD target_vec(x - prev->pos.x, y - prev->pos.y);
154  double cut_fraction = target_vec.length() / segment_vec.length();
155  // Get the start and end at the step level.
156  ICOORD step_start = prev_ol->position_at_index(prev->start_step);
157  int end_step = prev->start_step + prev->step_count;
158  int step_length = prev_ol->pathlength();
159  ICOORD step_end = prev_ol->position_at_index(end_step % step_length);
160  ICOORD step_vec = step_end - step_start;
161  double target_length = step_vec.length() * cut_fraction;
162  // Find the point on the segment that gives the length nearest to target.
163  int best_step = prev->start_step;
164  ICOORD total_step(0, 0);
165  double best_dist = target_length;
166  for (int s = prev->start_step; s < end_step; ++s) {
167  total_step += prev_ol->step(s % step_length);
168  double dist = fabs(target_length - total_step.length());
169  if (dist < best_dist) {
170  best_dist = dist;
171  best_step = s + 1;
172  }
173  }
174  // The new point is an intermediate point.
175  this_edgept->src_outline = prev_ol;
176  this_edgept->step_count = end_step - best_step;
177  this_edgept->start_step = best_step % step_length;
178  prev->step_count = best_step - prev->start_step;
179  } else {
180  // The new point is poly only.
181  this_edgept->src_outline = NULL;
182  this_edgept->step_count = 0;
183  this_edgept->start_step = 0;
184  }
185  /* Hook it up */
186  this_edgept->next = next;
187  this_edgept->prev = prev;
188  prev->next = this_edgept;
189  next->prev = this_edgept;
190  /* Set up vec entries */
191  this_edgept->vec.x = this_edgept->next->pos.x - x;
192  this_edgept->vec.y = this_edgept->next->pos.y - y;
193  this_edgept->prev->vec.x = x - this_edgept->prev->pos.x;
194  this_edgept->prev->vec.y = y - this_edgept->prev->pos.y;
195  return this_edgept;
196 }
int start_step
Definition: blobs.h:173
EDGEPT * prev
Definition: blobs.h:170
inT16 y
Definition: blobs.h:72
inT32 pathlength() const
Definition: coutln.h:133
float length() const
find length
Definition: points.h:78
VECTOR vec
Definition: blobs.h:164
EDGEPT * next
Definition: blobs.h:169
inT16 x
Definition: blobs.h:71
int step_count
Definition: blobs.h:174
integer coordinate
Definition: points.h:30
C_OUTLINE * src_outline
Definition: blobs.h:171
TPOINT pos
Definition: blobs.h:163
Definition: blobs.h:76
ICOORD step(int index) const
Definition: coutln.h:142
#define NULL
Definition: host.h:144
ICOORD position_at_index(int index) const
Definition: coutln.h:151
Definition: points.h:189
void remove_edgept ( EDGEPT point)

Definition at line 203 of file split.cpp.

203  {
204  EDGEPT *prev = point->prev;
205  EDGEPT *next = point->next;
206  // Add point's steps onto prev's steps if they are from the same outline.
207  if (prev->src_outline == point->src_outline && prev->src_outline != NULL) {
208  prev->step_count += point->step_count;
209  }
210  prev->next = next;
211  next->prev = prev;
212  prev->vec.x = next->pos.x - prev->pos.x;
213  prev->vec.y = next->pos.y - prev->pos.y;
214  delete point;
215 }
EDGEPT * prev
Definition: blobs.h:170
inT16 y
Definition: blobs.h:72
VECTOR vec
Definition: blobs.h:164
EDGEPT * next
Definition: blobs.h:169
inT16 x
Definition: blobs.h:71
int step_count
Definition: blobs.h:174
C_OUTLINE * src_outline
Definition: blobs.h:171
TPOINT pos
Definition: blobs.h:163
Definition: blobs.h:76
#define NULL
Definition: host.h:144

Variable Documentation

bool wordrec_display_splits = 0

"Display splits"

Definition at line 44 of file split.cpp.