mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-02-05 14:10:52 +03:00
Improved connecting discontiguous corners
This commit is contained in:
parent
ef223f52f7
commit
d5b86c0c91
Binary file not shown.
Before Width: | Height: | Size: 533 B After Width: | Height: | Size: 533 B |
|
@ -1683,7 +1683,7 @@ def test_discontiguous_corners_polygon() -> None:
|
||||||
BLACK,
|
BLACK,
|
||||||
)
|
)
|
||||||
expected = os.path.join(IMAGES_PATH, "discontiguous_corners_polygon.png")
|
expected = os.path.join(IMAGES_PATH, "discontiguous_corners_polygon.png")
|
||||||
assert_image_similar_tofile(img, expected, 1)
|
assert_image_equal_tofile(img, expected)
|
||||||
|
|
||||||
|
|
||||||
def test_polygon2() -> None:
|
def test_polygon2() -> None:
|
||||||
|
|
|
@ -501,60 +501,54 @@ polygon_generic(
|
||||||
// Needed to draw consistent polygons
|
// Needed to draw consistent polygons
|
||||||
xx[j] = xx[j - 1];
|
xx[j] = xx[j - 1];
|
||||||
j++;
|
j++;
|
||||||
} else if (current->dx != 0 && j % 2 == 1 &&
|
} else if ((ymin == current->ymin || ymin == current->ymax) &&
|
||||||
roundf(xx[j - 1]) == xx[j - 1]) {
|
current->dx != 0) {
|
||||||
// Connect discontiguous corners
|
// Connect discontiguous corners
|
||||||
for (k = 0; k < i; k++) {
|
for (k = 0; k < i; k++) {
|
||||||
Edge *other_edge = edge_table[k];
|
Edge *other_edge = edge_table[k];
|
||||||
if ((current->dx > 0 && other_edge->dx <= 0) ||
|
if ((ymin != other_edge->ymin && ymin != other_edge->ymax) ||
|
||||||
(current->dx < 0 && other_edge->dx >= 0)) {
|
other_edge->dx == 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// Check if the two edges join to make a corner
|
// Check if the two edges join to make a corner
|
||||||
if (xx[j - 1] ==
|
if (roundf(xx[j - 1]) ==
|
||||||
(ymin - other_edge->y0) * other_edge->dx + other_edge->x0) {
|
roundf(
|
||||||
|
(ymin - other_edge->y0) * other_edge->dx +
|
||||||
|
other_edge->x0
|
||||||
|
)) {
|
||||||
// Determine points from the edges on the next row
|
// Determine points from the edges on the next row
|
||||||
// Or if this is the last row, check the previous row
|
// Or if this is the last row, check the previous row
|
||||||
int offset = ymin == ymax ? -1 : 1;
|
int offset = ymin == current->ymax ? -1 : 1;
|
||||||
adjacent_line_x =
|
adjacent_line_x =
|
||||||
(ymin + offset - current->y0) * current->dx +
|
(ymin + offset - current->y0) * current->dx +
|
||||||
current->x0;
|
current->x0;
|
||||||
|
if (ymin + offset >= other_edge->ymin &&
|
||||||
|
ymin + offset <= other_edge->ymax) {
|
||||||
adjacent_line_x_other_edge =
|
adjacent_line_x_other_edge =
|
||||||
(ymin + offset - other_edge->y0) * other_edge->dx +
|
(ymin + offset - other_edge->y0) * other_edge->dx +
|
||||||
other_edge->x0;
|
other_edge->x0;
|
||||||
if (ymin == current->ymax) {
|
if (xx[j - 1] > adjacent_line_x + 1 &&
|
||||||
if (current->dx > 0) {
|
xx[j - 1] > adjacent_line_x_other_edge + 1) {
|
||||||
xx[k] =
|
xx[j - 1] =
|
||||||
fmax(
|
roundf(fmax(
|
||||||
adjacent_line_x, adjacent_line_x_other_edge
|
adjacent_line_x, adjacent_line_x_other_edge
|
||||||
) +
|
)) +
|
||||||
1;
|
1;
|
||||||
} else {
|
} else if (xx[j - 1] < adjacent_line_x - 1 &&
|
||||||
xx[k] =
|
xx[j - 1] < adjacent_line_x_other_edge - 1) {
|
||||||
fmin(
|
xx[j - 1] =
|
||||||
|
roundf(fmin(
|
||||||
adjacent_line_x, adjacent_line_x_other_edge
|
adjacent_line_x, adjacent_line_x_other_edge
|
||||||
) -
|
)) -
|
||||||
1;
|
1;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
if (current->dx > 0) {
|
|
||||||
xx[k] = fmin(
|
|
||||||
adjacent_line_x, adjacent_line_x_other_edge
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
xx[k] =
|
|
||||||
fmax(
|
|
||||||
adjacent_line_x, adjacent_line_x_other_edge
|
|
||||||
) +
|
|
||||||
1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
qsort(xx, j, sizeof(float), x_cmp);
|
qsort(xx, j, sizeof(float), x_cmp);
|
||||||
if (hasAlpha == 1) {
|
if (hasAlpha == 1) {
|
||||||
int x_pos = j == 0 ? -1 : 0;
|
int x_pos = j == 0 ? -1 : 0;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user