List of usage examples for java.awt.geom Rectangle2D intersectsLine
public boolean intersectsLine(double x1, double y1, double x2, double y2)
From source file:TransferableScribblePane.java
public boolean intersects(Rectangle2D r) { if (numsegs < 1) return false; float lastx = x0, lasty = y0; for (int i = 0; i < numsegs; i++) { // loop through the segments float x = coords[i * 2] + x0; float y = coords[i * 2 + 1] + y0; // See if this line segment intersects the rectangle if (r.intersectsLine(x, y, lastx, lasty)) return true; // Otherwise move on to the next segment lastx = x;//from w w w .j av a 2s .c om lasty = y; } return false; // No line segment intersected the rectangle }
From source file:ScribbleDragAndDrop.java
/** * Determine if the scribble intersects the specified rectangle by testing * each line segment individually/* ww w . j a v a2 s.co m*/ */ public boolean intersects(Rectangle2D r) { if (numPoints < 4) return false; int i = 0; double x1, y1, x2 = 0.0, y2 = 0.0; while (i < numPoints) { if (Double.isNaN(points[i])) { // If we're beginning a new line i++; // Skip the NaN x2 = points[i++]; y2 = points[i++]; } else { x1 = x2; y1 = y2; x2 = points[i++]; y2 = points[i++]; if (r.intersectsLine(x1, y1, x2, y2)) return true; } } return false; }