mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-11 04:07:21 +03:00
Merge pull request #1577 from radarhere/float
Changed arcs, chords and pie slices to use floats
This commit is contained in:
commit
6e16168567
|
@ -58,13 +58,13 @@ class TestImageDraw(PillowTestCase):
|
|||
self.assertRaises(ValueError,
|
||||
lambda: ImageDraw.ImageDraw(im, mode="L"))
|
||||
|
||||
def helper_arc(self, bbox):
|
||||
def helper_arc(self, bbox, start, end):
|
||||
# Arrange
|
||||
im = Image.new("RGB", (W, H))
|
||||
draw = ImageDraw.Draw(im)
|
||||
|
||||
# Act
|
||||
draw.arc(bbox, 0, 180)
|
||||
draw.arc(bbox, start, end)
|
||||
del draw
|
||||
|
||||
# Assert
|
||||
|
@ -72,10 +72,12 @@ class TestImageDraw(PillowTestCase):
|
|||
im, Image.open("Tests/images/imagedraw_arc.png"), 1)
|
||||
|
||||
def test_arc1(self):
|
||||
self.helper_arc(BBOX1)
|
||||
self.helper_arc(BBOX1, 0, 180)
|
||||
self.helper_arc(BBOX1, 0.5, 180.4)
|
||||
|
||||
def test_arc2(self):
|
||||
self.helper_arc(BBOX2)
|
||||
self.helper_arc(BBOX2, 0, 180)
|
||||
self.helper_arc(BBOX2, 0.5, 180.4)
|
||||
|
||||
def test_bitmap(self):
|
||||
# Arrange
|
||||
|
@ -91,13 +93,13 @@ class TestImageDraw(PillowTestCase):
|
|||
self.assert_image_equal(
|
||||
im, Image.open("Tests/images/imagedraw_bitmap.png"))
|
||||
|
||||
def helper_chord(self, bbox):
|
||||
def helper_chord(self, bbox, start, end):
|
||||
# Arrange
|
||||
im = Image.new("RGB", (W, H))
|
||||
draw = ImageDraw.Draw(im)
|
||||
|
||||
# Act
|
||||
draw.chord(bbox, 0, 180, fill="red", outline="yellow")
|
||||
draw.chord(bbox, start, end, fill="red", outline="yellow")
|
||||
del draw
|
||||
|
||||
# Assert
|
||||
|
@ -105,10 +107,12 @@ class TestImageDraw(PillowTestCase):
|
|||
im, Image.open("Tests/images/imagedraw_chord.png"), 1)
|
||||
|
||||
def test_chord1(self):
|
||||
self.helper_chord(BBOX1)
|
||||
self.helper_chord(BBOX1, 0, 180)
|
||||
self.helper_chord(BBOX1, 0.5, 180.4)
|
||||
|
||||
def test_chord2(self):
|
||||
self.helper_chord(BBOX2)
|
||||
self.helper_chord(BBOX2, 0, 180)
|
||||
self.helper_chord(BBOX2, 0.5, 180.4)
|
||||
|
||||
def helper_ellipse(self, bbox):
|
||||
# Arrange
|
||||
|
@ -161,13 +165,13 @@ class TestImageDraw(PillowTestCase):
|
|||
def test_line2(self):
|
||||
self.helper_line(POINTS2)
|
||||
|
||||
def helper_pieslice(self, bbox):
|
||||
def helper_pieslice(self, bbox, start, end):
|
||||
# Arrange
|
||||
im = Image.new("RGB", (W, H))
|
||||
draw = ImageDraw.Draw(im)
|
||||
|
||||
# Act
|
||||
draw.pieslice(bbox, -90, 45, fill="white", outline="blue")
|
||||
draw.pieslice(bbox, start, end, fill="white", outline="blue")
|
||||
del draw
|
||||
|
||||
# Assert
|
||||
|
@ -175,10 +179,12 @@ class TestImageDraw(PillowTestCase):
|
|||
im, Image.open("Tests/images/imagedraw_pieslice.png"), 1)
|
||||
|
||||
def test_pieslice1(self):
|
||||
self.helper_pieslice(BBOX1)
|
||||
self.helper_pieslice(BBOX1, -90, 45)
|
||||
self.helper_pieslice(BBOX1, -90.5, 45.4)
|
||||
|
||||
def test_pieslice2(self):
|
||||
self.helper_pieslice(BBOX2)
|
||||
self.helper_pieslice(BBOX2, -90, 45)
|
||||
self.helper_pieslice(BBOX2, -90.5, 45.4)
|
||||
|
||||
def helper_point(self, points):
|
||||
# Arrange
|
||||
|
|
12
_imaging.c
12
_imaging.c
|
@ -2382,9 +2382,9 @@ _draw_arc(ImagingDrawObject* self, PyObject* args)
|
|||
|
||||
PyObject* data;
|
||||
int ink;
|
||||
int start, end;
|
||||
float start, end;
|
||||
int op = 0;
|
||||
if (!PyArg_ParseTuple(args, "Oiii|i", &data, &start, &end, &ink))
|
||||
if (!PyArg_ParseTuple(args, "Offi|i", &data, &start, &end, &ink))
|
||||
return NULL;
|
||||
|
||||
n = PyPath_Flatten(data, &xy);
|
||||
|
@ -2456,8 +2456,8 @@ _draw_chord(ImagingDrawObject* self, PyObject* args)
|
|||
|
||||
PyObject* data;
|
||||
int ink, fill;
|
||||
int start, end;
|
||||
if (!PyArg_ParseTuple(args, "Oiiii",
|
||||
float start, end;
|
||||
if (!PyArg_ParseTuple(args, "Offii",
|
||||
&data, &start, &end, &ink, &fill))
|
||||
return NULL;
|
||||
|
||||
|
@ -2677,8 +2677,8 @@ _draw_pieslice(ImagingDrawObject* self, PyObject* args)
|
|||
|
||||
PyObject* data;
|
||||
int ink, fill;
|
||||
int start, end;
|
||||
if (!PyArg_ParseTuple(args, "Oiiii", &data, &start, &end, &ink, &fill))
|
||||
float start, end;
|
||||
if (!PyArg_ParseTuple(args, "Offii", &data, &start, &end, &ink, &fill))
|
||||
return NULL;
|
||||
|
||||
n = PyPath_Flatten(data, &xy);
|
||||
|
|
|
@ -743,10 +743,11 @@ ImagingDrawBitmap(Imaging im, int x0, int y0, Imaging bitmap, const void* ink,
|
|||
|
||||
static int
|
||||
ellipse(Imaging im, int x0, int y0, int x1, int y1,
|
||||
int start, int end, const void* ink_, int fill,
|
||||
float start, float end, const void* ink_, int fill,
|
||||
int mode, int op)
|
||||
{
|
||||
int i, n;
|
||||
float i;
|
||||
int n;
|
||||
int cx, cy;
|
||||
int w, h;
|
||||
int x = 0, y = 0;
|
||||
|
@ -779,7 +780,10 @@ ellipse(Imaging im, int x0, int y0, int x1, int y1,
|
|||
|
||||
n = 0;
|
||||
|
||||
for (i = start; i <= end; i++) {
|
||||
for (i = start; i < end+1; i++) {
|
||||
if (i > end) {
|
||||
i = end;
|
||||
}
|
||||
x = FLOOR((cos(i*M_PI/180) * w/2) + cx + 0.5);
|
||||
y = FLOOR((sin(i*M_PI/180) * h/2) + cy + 0.5);
|
||||
if (i != start)
|
||||
|
@ -807,7 +811,10 @@ ellipse(Imaging im, int x0, int y0, int x1, int y1,
|
|||
|
||||
} else {
|
||||
|
||||
for (i = start; i <= end; i++) {
|
||||
for (i = start; i < end+1; i++) {
|
||||
if (i > end) {
|
||||
i = end;
|
||||
}
|
||||
x = FLOOR((cos(i*M_PI/180) * w/2) + cx + 0.5);
|
||||
y = FLOOR((sin(i*M_PI/180) * h/2) + cy + 0.5);
|
||||
if (i != start)
|
||||
|
@ -835,14 +842,14 @@ ellipse(Imaging im, int x0, int y0, int x1, int y1,
|
|||
|
||||
int
|
||||
ImagingDrawArc(Imaging im, int x0, int y0, int x1, int y1,
|
||||
int start, int end, const void* ink, int op)
|
||||
float start, float end, const void* ink, int op)
|
||||
{
|
||||
return ellipse(im, x0, y0, x1, y1, start, end, ink, 0, ARC, op);
|
||||
}
|
||||
|
||||
int
|
||||
ImagingDrawChord(Imaging im, int x0, int y0, int x1, int y1,
|
||||
int start, int end, const void* ink, int fill, int op)
|
||||
float start, float end, const void* ink, int fill, int op)
|
||||
{
|
||||
return ellipse(im, x0, y0, x1, y1, start, end, ink, fill, CHORD, op);
|
||||
}
|
||||
|
@ -856,7 +863,7 @@ ImagingDrawEllipse(Imaging im, int x0, int y0, int x1, int y1,
|
|||
|
||||
int
|
||||
ImagingDrawPieslice(Imaging im, int x0, int y0, int x1, int y1,
|
||||
int start, int end, const void* ink, int fill, int op)
|
||||
float start, float end, const void* ink, int fill, int op)
|
||||
{
|
||||
return ellipse(im, x0, y0, x1, y1, start, end, ink, fill, PIESLICE, op);
|
||||
}
|
||||
|
|
|
@ -345,11 +345,11 @@ struct ImagingAffineMatrixInstance {
|
|||
typedef struct ImagingAffineMatrixInstance *ImagingAffineMatrix;
|
||||
|
||||
extern int ImagingDrawArc(Imaging im, int x0, int y0, int x1, int y1,
|
||||
int start, int end, const void* ink, int op);
|
||||
float start, float end, const void* ink, int op);
|
||||
extern int ImagingDrawBitmap(Imaging im, int x0, int y0, Imaging bitmap,
|
||||
const void* ink, int op);
|
||||
extern int ImagingDrawChord(Imaging im, int x0, int y0, int x1, int y1,
|
||||
int start, int end, const void* ink, int fill,
|
||||
float start, float end, const void* ink, int fill,
|
||||
int op);
|
||||
extern int ImagingDrawEllipse(Imaging im, int x0, int y0, int x1, int y1,
|
||||
const void* ink, int fill, int op);
|
||||
|
@ -358,7 +358,7 @@ extern int ImagingDrawLine(Imaging im, int x0, int y0, int x1, int y1,
|
|||
extern int ImagingDrawWideLine(Imaging im, int x0, int y0, int x1, int y1,
|
||||
const void* ink, int width, int op);
|
||||
extern int ImagingDrawPieslice(Imaging im, int x0, int y0, int x1, int y1,
|
||||
int start, int end, const void* ink, int fill,
|
||||
float start, float end, const void* ink, int fill,
|
||||
int op);
|
||||
extern int ImagingDrawPoint(Imaging im, int x, int y, const void* ink, int op);
|
||||
extern int ImagingDrawPolygon(Imaging im, int points, int *xy,
|
||||
|
|
Loading…
Reference in New Issue
Block a user