#include "polyaprx.h"
#include <cstdint>
#include "blobs.h"
#include "coutln.h"
#include "errcode.h"
#include "host.h"
#include "mod128.h"
#include "params.h"
#include "points.h"
#include "rect.h"
#include "tprintf.h"
#include "vecfuncs.h"
Go to the source code of this file.
◆ approx_dist
◆ DIR
◆ EXTERN
◆ 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 65 of file polyaprx.cpp.
69 EDGEPT* edgepts = stack_edgepts;
78 area = loop_box.
width();
85 EDGEPT* prev_result =
nullptr;
89 new_pt->
prev = prev_result;
90 if (prev_result ==
nullptr) {
93 prev_result->
next = new_pt;
94 new_pt->
prev = prev_result;
96 if (allow_detailed_fx) {
101 prev_result = new_pt;
102 edgept = edgept->
next;
104 while (edgept != startpt);
105 prev_result->
next = result;
106 result->
prev = prev_result;
107 if (edgepts != stack_edgepts)
EDGEPT * edgesteps_to_edgepts(C_OUTLINE *c_outline, EDGEPT edgepts[])
void fix2(EDGEPT *start, int area)
int32_t pathlength() const
const TBOX & bounding_box() const
EDGEPT * poly2(EDGEPT *startpt, int area)
EXTERN bool poly_wide_objects_better
static TESSLINE * BuildFromOutlineList(EDGEPT *outline)
◆ cutline()
Definition at line 502 of file polyaprx.cpp.
524 if (vecsum.
x == 0 && vecsum.
y == 0) {
530 vlen = vecsum.
x > 0 ? vecsum.
x : -vecsum.
x;
533 else if (-vecsum.
y > vlen)
539 squaresum = ptcount = 0;
543 perp =
CROSS (vec, vecsum);
550 tprintf (
"Cutline:Final perp=%d\n", perp);
551 if (perp > maxperp) {
555 vec.
x += edge->
vec.
x;
556 vec.
y += edge->
vec.
y;
559 while (edge !=
last);
564 if (maxperp < 256 * INT16_MAX) {
572 if (squaresum < 256 * INT16_MAX)
574 perp = (squaresum << 8) / (perp * ptcount);
577 perp = (squaresum / perp << 8) / ptcount;
580 tprintf (
"Cutline:A=%d, max=%.2f(%.2f%%), msd=%.2f(%.2f%%)\n",
581 area, maxperp / 256.0, maxperp * 200.0 / area,
582 perp / 256.0, perp * 300.0 / area);
583 if (maxperp *
par1 >= 10 * area || perp *
par2 >= 10 * area || vlen >= 126) {
586 cutline(first, maxpoint, area);
DLLSYM void tprintf(const char *format,...)
void cutline(EDGEPT *first, EDGEPT *last, int area)
◆ edgesteps_to_edgepts()
Definition at line 120 of file polyaprx.cpp.
142 int prev_stepindex = 0;
144 dir = c_outline->
step_dir (stepindex);
145 vec = c_outline->
step (stepindex);
146 if (stepindex < length - 1
147 && c_outline->
step_dir (stepindex + 1) - dir == -32) {
149 vec += c_outline->
step (stepindex + 1);
159 edgepts[epindex].
pos.
x = pos.
x ();
160 edgepts[epindex].
pos.
y = pos.
y ();
162 edgepts[epindex].
vec.
x = prev_vec.
x ();
163 edgepts[epindex].
vec.
y = prev_vec.
y ();
166 edgepts[epindex].
prev = &edgepts[epindex - 1];
168 edgepts[epindex].
next = &edgepts[epindex + 1];
170 epdir = (
DIR128) 0 - prevdir;
173 edgepts[epindex].
flags[
DIR] = epdir;
176 edgepts[epindex].
step_count = stepindex - prev_stepindex;
181 prev_stepindex = stepindex;
185 stepindex += stepinc;
187 while (stepindex < length);
188 edgepts[epindex].
pos.
x = pos.
x ();
189 edgepts[epindex].
pos.
y = pos.
y ();
191 edgepts[epindex].
vec.
x = prev_vec.
x ();
192 edgepts[epindex].
vec.
y = prev_vec.
y ();
198 edgepts[epindex].
step_count = stepindex - prev_stepindex;
199 edgepts[epindex].
prev = &edgepts[epindex - 1];
200 edgepts[epindex].
next = &edgepts[0];
202 epdir = (
DIR128) 0 - prevdir;
205 edgepts[epindex].
flags[
DIR] = epdir;
206 edgepts[0].
prev = &edgepts[epindex];
int16_t y() const
access_function
const ICOORD & start_pos() const
int16_t x() const
access function
int32_t pathlength() const
DIR128 step_dir(int index) const
ICOORD step(int index) const
◆ fix2()
void fix2 |
( |
EDGEPT * |
start, |
|
|
int |
area |
|
) |
| |
Definition at line 219 of file polyaprx.cpp.
230 int d01, d12, d23, gapmin;
231 TPOINT d01vec, d12vec, d23vec;
232 EDGEPT *edgefix, *startfix;
233 EDGEPT *edgefix0, *edgefix1, *edgefix2, *edgefix3;
240 edgept = edgept->
next;
250 edgept = edgept->
next;
254 if (((dir1 - dir2 + 1) & 7) < 3) {
256 edgept = edgept->
next;
264 if (edgept == loopstart)
271 linestart = linestart->
prev;
276 || (edgept->
flags[
DIR] == dir1 && sum1 >= sum2)
278 || (edgept->
flags[
DIR] == dir2 && sum2 >= sum1))
279 && linestart->
next != edgept))
280 edgept = edgept->
next;
286 while (edgept != loopstart && !stopped);
295 edgept1 = edgept->
next;
298 edgept = edgept->
next;
300 while (edgept != start);
315 edgept = edgept->
next;
317 while (edgept != start);
330 edgept = edgept->
next;
332 while (edgept != start);
334 edgept = edgept->
next;
337 edgept = edgept->
next;
339 edgept = edgept->
next;
342 edgept = edgept->
next;
344 edgept = edgept->
next;
347 edgept = edgept->
next;
349 edgept = edgept->
next;
355 if (fixed_count <= 3)
384 edgept = edgept->
next;
386 if (edgept == startfix)
388 edgept = edgept->
next;
393 while ((edgefix != startfix) && (!stopped));
#define point_diff(p, p1, p2)
◆ poly2()
Definition at line 404 of file polyaprx.cpp.
427 edgept = edgept->
next;
429 while (edgept != startpt);
445 edgept = edgept->
next;
448 && edgept != loopstart && edgesum < 126);
451 (
"Poly2:starting at (%d,%d)+%d=(%d,%d),%d to (%d,%d)\n",
453 linestart->
vec.
x, linestart->
vec.
y, edgesum, edgept->
pos.
x,
456 cutline(linestart, edgept, area);
459 && edgept != loopstart)
460 edgept = edgept->
next;
463 while (edgept != loopstart);
468 edgept = edgept->
next;
471 while (edgept != loopstart);
479 edgept = edgept->
next;
482 linestart->
next = edgept;
483 edgept->
prev = linestart;
487 while (edgept != loopstart);
DLLSYM void tprintf(const char *format,...)
void cutline(EDGEPT *first, EDGEPT *last, int area)
◆ par1
◆ par2
◆ poly_debug
◆ poly_wide_objects_better
"More accurate approx on wide things"
Definition at line 38 of file polyaprx.cpp.