Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions src/path_converters.h
Original file line number Diff line number Diff line change
Expand Up @@ -557,32 +557,46 @@ class PathSnapper
double m_snap_value;

static bool should_snap(VertexSource &path, e_snap_mode snap_mode, unsigned total_vertices)
{
// If this contains only straight horizontal or vertical lines, it should be
// snapped to the nearest pixels
double x0 = 0, y0 = 0, x1 = 0, y1 = 0;
unsigned code;
{
const unsigned path_cmd_end_poly_masked = agg::path_flags_close | agg::path_cmd_end_poly;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

paths can have multiple closed polygons, what happens in that case?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't understand. Do you mean multiple polygons within the same commands set? (like self-intersecting polygons)
If yes, then is that practically possible (multiple polygons in one command set)?

In that case, maybe modify:

case path_cmd_end_poly_masked:
    if (fabs(xs - x0) >= 1e-4 && fabs(ys - y0) >= 1e-4) {
        return false;
    }

to:

case path_cmd_end_poly_masked:
    if (fabs(xs - x0) >= 1e-4 && fabs(ys - y0) >= 1e-4) {
        return false;
    }
    xs = x0 = x1;
    ys = y0 = y1;

and continue on . . .

I'm just guessing. It would be helpful to have a list of possible command sequences to verify against.

// If this contains only straight horizontal or vertical lines, it should be
// snapped to the nearest pixels
double x0 = 0, y0 = 0, x1 = 0, y1 = 0, xs = 0, ys = 0;
unsigned code;

switch (snap_mode) {
switch (snap_mode) {
case SNAP_AUTO:
if (total_vertices > 1024) {
return false;
}

code = path.vertex(&x0, &y0);
if (code == agg::path_cmd_stop) {
switch (code) {
case agg::path_cmd_stop:
return false;
case agg::path_cmd_move_to:
xs = x0;
ys = y0;
}

while ((code = path.vertex(&x1, &y1)) != agg::path_cmd_stop) {
switch (code) {
case agg::path_cmd_move_to:
xs = x1;
ys = x1;
break;
case agg::path_cmd_curve3:
case agg::path_cmd_curve4:
return false;
case agg::path_cmd_line_to:
if (fabs(x0 - x1) >= 1e-4 && fabs(y0 - y1) >= 1e-4) {
return false;
}
break;
case path_cmd_end_poly_masked:
if (fabs(xs - x0) >= 1e-4 && fabs(ys - y0) >= 1e-4) {
return false;
}
}
x0 = x1;
y0 = y1;
Expand Down
Loading