java.awt.geom.Line2D#intersects ( )源码实例Demo

下面列出了java.awt.geom.Line2D#intersects ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: gcs   文件: PolylineShape.java
/**
 * Checks if one of the lines in the polyline intersects
 * with a given rectangle.
 * @see java.awt.Shape#intersects(java.awt.geom.Rectangle2D)
 */
public boolean intersects(Rectangle2D r) {
	if(np==0)return false;
	Line2D line = new Line2D.Double(x[0],y[0],x[0],y[0]);
	for (int i = 1; i < np; i++) {
		line.setLine(x[i-1], y[i-1], x[i], y[i]);
		if(line.intersects(r))return true;
	}
	return false;
}
 
源代码2 项目: itext2   文件: PolylineShape.java
/**
 * Checks if one of the lines in the polyline intersects
 * with a given rectangle.
 * @see java.awt.Shape#intersects(java.awt.geom.Rectangle2D)
 */
public boolean intersects(Rectangle2D r) {
	if(np==0)return false;
	Line2D line = new Line2D.Double(x[0],y[0],x[0],y[0]);
	for (int i = 1; i < np; i++) {
		line.setLine(x[i-1], y[i-1], x[i], y[i]);
		if(line.intersects(r))return true;
	}
	return false;
}
 
源代码3 项目: swcv   文件: ProximityMetric.java
private boolean close(LayoutResult layout, Word first, Word second, List<Word> words)
{
    SWCRectangle rect1 = layout.getWordPosition(first);
    SWCRectangle rect2 = layout.getWordPosition(second);

    if (rect1 == null || rect2 == null)
        return false;

    if (touching(rect1, rect2))
        return true; // proximities should be a superset of adjacencies

    double c_x = rect1.getX() + rect1.getX() - rect1.getCenterX();
    double c_y = rect1.getY() + rect1.getY() - rect1.getCenterY();

    double e_width = rect1.getWidth() * 2;
    double e_height = rect1.getHeight() * 2;

    Ellipse2D elip = new Ellipse2D.Double(c_x, c_y, e_width, e_height);

    boolean inRange = elip.intersects(rect2.getX(), rect2.getY(), rect2.getWidth(), rect2.getHeight());

    // case: word 2 is not within the ellipse surrounding word 1
    if (!inRange)
        return false;

    // line connecting the two close words
    Line2D connection = new Line2D.Double(rect1.getCenterX(), rect1.getCenterY(), rect2.getCenterX(), rect2.getCenterY());

    // check for a word between our two "close" words
    // TODO: this could be more efficient, since only words that are close might have the possibility of intersection
    for (Word w : words)
    {

        // dont check collisions with the close words
        if (w.equals(first) || w.equals(second))
            continue;

        SWCRectangle tmpRect = layout.getWordPosition(w);

        // see if our line intersects any of the words
        if (connection.intersects(tmpRect.getX(), tmpRect.getY(), tmpRect.getWidth(), tmpRect.getHeight()))
            return false;
    }

    return true;

}