本文整理汇总了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;
}