Java Code Examples for java.awt.geom.Rectangle2D#intersectsLine()

The following examples show how to use java.awt.geom.Rectangle2D#intersectsLine() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StyledSegment.java    From pdfxtk with Apache License 2.0 5 votes vote down vote up
/**
 * Checks whether the rectangular intersects the shape of the segment.
 * 
 * @param rec The rectangular you want to check
 * @return Returns true if the rectangular intersects the shape of the segment, false otherwise
 */
public boolean intersects(Rectangle2D rec) {
	
	//If segment is not printed at all the user can't select it
	if (!style.isPrintable()) {
		
		return false;
	}
	
	//Make sure to check whether its a lined shape or a rectangular one
	return (style.getShape() == Shapes.line) ? rec.intersectsLine(x, y, x+width, y+height) : rec.intersects(x, y, width, height);
}
 
Example 2
Source File: GeoPath.java    From libreveris with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Check whether the flattened path intersects the provided rectangle.
 *
 * @param rect     the provided rectangle to check for intersection
 * @param flatness maximum distance used for line segment approximation
 * @return true if intersection found
 */
public boolean intersects (Rectangle2D rect,
                           double flatness)
{
    final double[] buffer = new double[6];
    double x1 = 0;
    double y1 = 0;

    for (PathIterator it = getPathIterator(null, flatness); !it.isDone();
            it.next()) {
        int segmentKind = it.currentSegment(buffer);
        int count = countOf(segmentKind);
        final double x2 = buffer[count - 2];
        final double y2 = buffer[count - 1];

        switch (segmentKind) {
        case SEG_MOVETO:
            x1 = x2;
            y1 = y2;

            break;

        case SEG_LINETO:

            if (rect.intersectsLine(x1, y1, x2, y2)) {
                return true;
            }

            break;

        case SEG_CLOSE:
            break;

        default:
            throw new RuntimeException(
                    "Illegal segmentKind " + segmentKind);
        }
    }

    return false;
}