#include "polyaprx.h"
#include <cstdint>
#include "blobs.h"
#include "coutln.h"
#include "errcode.h"
#include "mod128.h"
#include "params.h"
#include "points.h"
#include "rect.h"
#include "tprintf.h"
Go to the source code of this file.
◆ approx_dist
◆ DIR
#define DIR 2 /*direction of run */ |
◆ FASTEDGELENGTH
#define FASTEDGELENGTH 256 |
◆ FIXED
#define FIXED 4 /*OUTLINE point is fixed */ |
◆ fixed_dist
◆ FLAGS
◆ RUNLENGTH
#define RUNLENGTH 1 /*length of run */ |
◆ ApproximateOutline()
Definition at line 59 of file polyaprx.cpp.
65 EDGEPT* edgepts = stack_edgepts;
73 if (!poly_wide_objects_better && loop_box.
width() > area)
74 area = loop_box.
width();
81 EDGEPT* prev_result =
nullptr;
85 new_pt->prev = prev_result;
86 if (prev_result ==
nullptr) {
89 prev_result->
next = new_pt;
90 new_pt->
prev = prev_result;
92 if (allow_detailed_fx) {
98 edgept = edgept->
next;
100 while (edgept != startpt);
101 prev_result->
next = result;
102 result->
prev = prev_result;
103 if (edgepts != stack_edgepts)
◆ cutline()
Definition at line 492 of file polyaprx.cpp.
520 if (vecsum.
x == 0 && vecsum.
y == 0) {
526 vlen = vecsum.
x > 0 ? vecsum.
x : -vecsum.
x;
529 else if (-vecsum.
y > vlen)
535 squaresum = ptcount = 0;
539 perp = vec.
cross(vecsum);
546 tprintf (
"Cutline:Final perp=%d\n", perp);
547 if (perp > maxperp) {
551 vec.
x += edge->
vec.
x;
552 vec.
y += edge->
vec.
y;
555 while (edge !=
last);
560 if (maxperp < 256 * INT16_MAX) {
568 if (squaresum < 256 * INT16_MAX)
570 perp = (squaresum << 8) / (perp * ptcount);
573 perp = (squaresum / perp << 8) / ptcount;
576 tprintf (
"Cutline:A=%d, max=%.2f(%.2f%%), msd=%.2f(%.2f%%)\n",
577 area, maxperp / 256.0, maxperp * 200.0 / area,
578 perp / 256.0, perp * 300.0 / area);
579 if (maxperp *
par1 >= 10 * area || perp *
par2 >= 10 * area || vlen >= 126) {
◆ edgesteps_to_edgepts()
Definition at line 113 of file polyaprx.cpp.
138 int prev_stepindex = 0;
140 dir = c_outline->
step_dir (stepindex);
141 vec = c_outline->
step (stepindex);
142 if (stepindex < length - 1
143 && c_outline->
step_dir (stepindex + 1) - dir == -32) {
145 vec += c_outline->
step (stepindex + 1);
155 edgepts[epindex].
pos.
x = pos.
x ();
156 edgepts[epindex].
pos.
y = pos.
y ();
158 edgepts[epindex].
vec.
x = prev_vec.
x ();
159 edgepts[epindex].
vec.
y = prev_vec.
y ();
162 edgepts[epindex].
prev = &edgepts[epindex - 1];
164 edgepts[epindex].
next = &edgepts[epindex + 1];
166 epdir =
DIR128(0) - prevdir;
169 edgepts[epindex].
flags[
DIR] = epdir;
172 edgepts[epindex].
step_count = stepindex - prev_stepindex;
177 prev_stepindex = stepindex;
181 stepindex += stepinc;
183 while (stepindex < length);
184 edgepts[epindex].
pos.
x = pos.
x ();
185 edgepts[epindex].
pos.
y = pos.
y ();
187 edgepts[epindex].
vec.
x = prev_vec.
x ();
188 edgepts[epindex].
vec.
y = prev_vec.
y ();
194 edgepts[epindex].
step_count = stepindex - prev_stepindex;
195 edgepts[epindex].
prev = &edgepts[epindex - 1];
196 edgepts[epindex].
next = &edgepts[0];
198 epdir =
DIR128(0) - prevdir;
201 edgepts[epindex].
flags[
DIR] = epdir;
202 edgepts[0].
prev = &edgepts[epindex];
◆ fix2()
void fix2 |
( |
EDGEPT * |
start, |
|
|
int |
area |
|
) |
| |
Definition at line 211 of file polyaprx.cpp.
226 int d01, d12, d23, gapmin;
227 TPOINT d01vec, d12vec, d23vec;
228 EDGEPT *edgefix, *startfix;
229 EDGEPT *edgefix0, *edgefix1, *edgefix2, *edgefix3;
236 edgept = edgept->
next;
246 edgept = edgept->
next;
250 if (((dir1 - dir2 + 1) & 7) < 3) {
252 edgept = edgept->
next;
260 if (edgept == loopstart)
267 linestart = linestart->
prev;
272 || (edgept->
flags[
DIR] == dir1 && sum1 >= sum2)
274 || (edgept->
flags[
DIR] == dir2 && sum2 >= sum1))
275 && linestart->
next != edgept))
276 edgept = edgept->
next;
282 while (edgept != loopstart && !stopped);
291 edgept1 = edgept->
next;
294 edgept = edgept->
next;
296 while (edgept != start);
311 edgept = edgept->
next;
313 while (edgept != start);
326 edgept = edgept->
next;
328 while (edgept != start);
330 edgept = edgept->
next;
333 edgept = edgept->
next;
335 edgept = edgept->
next;
338 edgept = edgept->
next;
340 edgept = edgept->
next;
343 edgept = edgept->
next;
345 edgept = edgept->
next;
351 if (fixed_count <= 3)
380 edgept = edgept->
next;
382 if (edgept == startfix)
384 edgept = edgept->
next;
◆ poly2()
Definition at line 395 of file polyaprx.cpp.
423 edgept = edgept->
next;
425 while (edgept != startpt);
441 edgept = edgept->
next;
444 && edgept != loopstart && edgesum < 126);
447 (
"Poly2:starting at (%d,%d)+%d=(%d,%d),%d to (%d,%d)\n",
449 linestart->
vec.
x, linestart->
vec.
y, edgesum, edgept->
pos.
x,
452 cutline(linestart, edgept, area);
455 && edgept != loopstart)
456 edgept = edgept->
next;
459 while (edgept != loopstart);
464 edgept = edgept->
next;
467 while (edgept != loopstart);
475 edgept = edgept->
next;
478 linestart->
next = edgept;
479 edgept->
prev = linestart;
483 while (edgept != loopstart);
◆ par1
◆ par2