/** * Create a point at the center of a cell * * @param xIndex * horizontal cell index * @param yIndex * vertical cell index * @return Point at the center of the cell at (xIndex, yIndex) */ private Point middleOfCell(int xIndex, int yIndex) { double middleXCell = indexRegion.minX() + xIndex * xSize + xSize / 2; double middleYCell = indexRegion.minY() + yIndex * ySize + ySize / 2; return new Point(middleXCell, middleYCell); } }
/** * Finds a triangle near the given point * * @param point * a query point * @return a triangle at the same cell of the point */ public Triangle findCellTriangleOf(Point point) { int xIndex = (int) ((point.getX() - indexRegion.minX()) / xSize); int yIndex = (int) ((point.getY() - indexRegion.minY()) / ySize); return grid[xIndex][yIndex]; }
/** * Locates the grid cell point covering the given coordinate * * @param coordinate * world coordinate to locate * @return cell covering the coordinate */ private PointInt getCellOf(Point coordinate) { int xCell = (int) ((coordinate.getX() - indexRegion.minX()) / xSize); int yCell = (int) ((coordinate.getY() - indexRegion.minY()) / ySize); return new PointInt(xCell, yCell); }