Transform a rectangle by the CTM to produce a rectangle in the transformed coordinate system. @param inRect The rectangle in the original coordinate system @return Rectangle2D The rectangle in the transformed coordinate system.
(Rectangle2D inRect)
| 228 | * @return Rectangle2D The rectangle in the transformed coordinate system. |
| 229 | */ |
| 230 | public Rectangle2D transform(Rectangle2D inRect) { |
| 231 | // Store as 2 sets of 2 points and transform those, then |
| 232 | // recalculate the width and height |
| 233 | int x1t = (int)(inRect.getX() * a + inRect.getY() * c + e); |
| 234 | int y1t = (int)(inRect.getX() * b + inRect.getY() * d + f); |
| 235 | int x2t = (int)((inRect.getX() + inRect.getWidth()) * a |
| 236 | + (inRect.getY() + inRect.getHeight()) * c + e); |
| 237 | int y2t = (int)((inRect.getX() + inRect.getWidth()) * b |
| 238 | + (inRect.getY() + inRect.getHeight()) * d + f); |
| 239 | // Normalize with x1 < x2 |
| 240 | if (x1t > x2t) { |
| 241 | int tmp = x2t; |
| 242 | x2t = x1t; |
| 243 | x1t = tmp; |
| 244 | } |
| 245 | if (y1t > y2t) { |
| 246 | int tmp = y2t; |
| 247 | y2t = y1t; |
| 248 | y1t = tmp; |
| 249 | } |
| 250 | return new Rectangle(x1t, y1t, x2t - x1t, y2t - y1t); |
| 251 | } |
| 252 | |
| 253 | /** |
| 254 | * Get string for this transform. |