(Rectangle bounds)
| 227 | * Author: Marcel Boeglin |
| 228 | */ |
| 229 | public Overlay crop(Rectangle bounds) { |
| 230 | if (bounds==null) |
| 231 | return duplicate(); |
| 232 | Overlay overlay2 = create(); |
| 233 | Roi[] allRois = toArray(); |
| 234 | for (Roi roi: allRois) { |
| 235 | Rectangle roiBounds = roi.getBounds(); |
| 236 | if (roiBounds.width==0) roiBounds.width=1; |
| 237 | if (roiBounds.height==0) roiBounds.height=1; |
| 238 | if (bounds.intersects(roiBounds)) |
| 239 | overlay2.add((Roi)roi.clone()); |
| 240 | } |
| 241 | int dx = bounds.x>0?bounds.x:0; |
| 242 | int dy = bounds.y>0?bounds.y:0; |
| 243 | if (dx>0 || dy>0) |
| 244 | overlay2.translate(-dx, -dy); |
| 245 | return overlay2; |
| 246 | } |
| 247 | |
| 248 | /** Removes ROIs having positions outside of the |
| 249 | * interval defined by firstSlice and lastSlice. |
no test coverage detected