From 48f6053acf17daee67264298f7b5983a53b91fca Mon Sep 17 00:00:00 2001 From: Tom Keffer Date: Mon, 3 Apr 2023 18:54:28 -0700 Subject: [PATCH] Put coordinates in proper order for drawing a rectangle. Fixes issue #862. --- bin/weeplot/utilities.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/bin/weeplot/utilities.py b/bin/weeplot/utilities.py index 73e955bd..f1c9d33a 100644 --- a/bin/weeplot/utilities.py +++ b/bin/weeplot/utilities.py @@ -431,14 +431,20 @@ class ScaledDraw(object): def rectangle(self, box, **options): """Draw a scaled rectangle. - - box: A pair of 2-way tuples, containing coordinates of opposing corners - of the box. - + + box: A pair of 2-way tuples for the lower-left, then upper-right corners of + the box [(llx, lly), (urx, ury)] + options: passed on to draw.rectangle. Usually contains 'fill' (the color) """ - box_scaled = [(coord[0] * self.xscale + self.xoffset + 0.5, - coord[1] * self.yscale + self.yoffset + 0.5) for coord in box] + # Unpack the box + (llsx, llsy), (ursx, ursy) = box + + ulix = int(llsx * self.xscale + self.xoffset + 0.5) + uliy = int(ursy * self.yscale + self.yoffset + 0.5) + lrix = int(ursx * self.xscale + self.xoffset + 0.5) + lriy = int(llsy * self.yscale + self.yoffset + 0.5) + box_scaled = ((ulix, uliy), (lrix, lriy)) self.draw.rectangle(box_scaled, **options) def vector(self, x, vec, vector_rotate, **options):