# HG changeset patch # User postspectacular # Date 1326687943 0 # Node ID 4239f3c325bf054e59ae3b72b5cfb4a33fe8e78a # Parent 46e6bbb5606bbcbf77fd74546858df9a37ad8497 bug fix Rect constructor for 2 points, ensuring width/height are always positive diff -r 46e6bbb5606bbcbf77fd74546858df9a37ad8497 -r 4239f3c325bf054e59ae3b72b5cfb4a33fe8e78a src.core/toxi/geom/Rect.java --- a/src.core/toxi/geom/Rect.java Mon Jan 16 04:20:08 2012 +0000 +++ b/src.core/toxi/geom/Rect.java Mon Jan 16 04:25:43 2012 +0000 @@ -95,17 +95,18 @@ } /** - * Constructs a new rectangle defined by its top left and bottom right - * points. + * Constructs a new rectangle defined by the two points given. * - * @param topLeft - * @param bottomRight + * @param p1 + * @param p2 */ - public Rect(ReadonlyVec2D topLeft, ReadonlyVec2D bottomRight) { - x = topLeft.x(); - y = topLeft.y(); - width = bottomRight.x() - x; - height = bottomRight.y() - y; + public Rect(ReadonlyVec2D p1, ReadonlyVec2D p2) { + Vec2D tl = Vec2D.min(p1, p2); + Vec2D br = Vec2D.min(p1, p2); + x = tl.x; + y = tl.y; + width = br.x - x; + height = br.y - y; } /** @@ -563,4 +564,5 @@ float h = y2 - y1; return new Rect(x1, y1, w, h); } -} + +} \ No newline at end of file