本文整理匯總了Java中java.awt.geom.Rectangle2D.intersectsLine方法的典型用法代碼示例。如果您正苦於以下問題:Java Rectangle2D.intersectsLine方法的具體用法?Java Rectangle2D.intersectsLine怎麽用?Java Rectangle2D.intersectsLine使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.awt.geom.Rectangle2D
的用法示例。
在下文中一共展示了Rectangle2D.intersectsLine方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: collides
import java.awt.geom.Rectangle2D; //導入方法依賴的package包/類
@Override
public Point2D collides(final Line2D rayCast) {
final Point2D rayCastSource = new Point2D.Double(rayCast.getX1(), rayCast.getY1());
final List<Rectangle2D> collBoxes = this.getAllCollisionBoxes();
collBoxes.sort((rect1, rect2) -> {
final Point2D rect1Center = new Point2D.Double(rect1.getCenterX(), rect1.getCenterY());
final Point2D rect2Center = new Point2D.Double(rect2.getCenterX(), rect2.getCenterY());
final double dist1 = rect1Center.distance(rayCastSource);
final double dist2 = rect2Center.distance(rayCastSource);
if (dist1 < dist2) {
return -1;
}
if (dist1 > dist2) {
return 1;
}
return 0;
});
for (final Rectangle2D collisionBox : collBoxes) {
if (collisionBox.intersectsLine(rayCast)) {
double closestDist = -1;
Point2D closestPoint = null;
for (final Point2D intersection : GeometricUtilities.getIntersectionPoints(rayCast, collisionBox)) {
final double dist = intersection.distance(rayCastSource);
if (closestPoint == null || dist < closestDist) {
closestPoint = intersection;
closestDist = dist;
}
}
return closestPoint;
}
}
return null;
}