【发布时间】:2017-06-19 20:50:48
【问题描述】:
我的应用中有一个圆圈数组列表。基本上,我正在绘制一个由六边形瓷砖制成的游戏板。我想在每个瓷砖的每个角上画圆圈。我将所有图块存储在一个 Tile 对象数组中。每个图块都有一个组成图块的点数组。所以我基本上循环遍历每个瓷砖和瓷砖的每个角落。我的问题是大多数瓷砖共享交叉点。因此,为共享该交叉点的每个图块绘制一个圆圈。但我只想在每个路口画一个。我需要做的是检查数组中是否存在具有特定坐标集的圆。如果确实存在,请不要画圆。我知道 ArrayList.contains(),但不知道如何将它用于我的目的。有什么想法吗?
for (int t = 0; t < tiles.length; t++) {
//Loop through the vertices of the current tile
for (int v = 0; v < tiles[t].vertices.length; v++) {
final double x = tiles[t].vertices[v].x;
final double y = tiles[t].vertices[v].y;
Platform.runLater(() -> {
//This if statement doesn't work because the arraylist contains shapes, not points!
if(!highlightedVertices.contains(new Point((int)x, (int)y))){
Circle cir = new Circle();
cir.setFill(Color.web("rgba(255, 235, 138, .3)"));
cir.setCenterX(x);
cir.setCenterY(y);
cir.setRadius(windowHeight * .025);
highlightedVertices.add(cir);
wrapperPane.getChildren().add(cir);
}
});
}
}
【问题讨论】:
-
圈内还是圈外?因为内圈永远不会到达六边形的角
-
外面。圆的中心与六边形的角相同。