Don't reverse the bounds, reverse the rendering.
Think about this...
In the images above, the only thing that has changed is the start and end points. The size of the rectangle has not changed.
All bounds must work with positive values. In Swing, there is no such thing as a rectangle that has a negative size.
Now my examples were rendered using a java.awt.Point
, but the basic concept remains...
// Find the smallest point between the two
int x = Math.min(p1.x, p2.x);
int y = Math.min(p1.y, p2.y);
// Size is based on the maximum value of the two points differences...
int width = Math.max(p1.x - p2.x, p2.x - p1.x);
int height = Math.max(p1.y - p2.y, p2.y - p1.y);
This now gives you the size of the effect area. Drawing the line is just a matter of drawing a line between the two points (rather then 0, 0, width, height
which you have used)