0

我有一个程序可以使用加载到其中的图像来制作六边形图块。它通过使用名为 inHex() 的函数将六边形之外的任何像素替换为透明像素来创建这些平铺图像。这行得通。

现在我想在六边形的内边缘创建一个边框。所以我修改了 inHex() 的副本,将 &&s 更改为 ||s,并为平坦边缘添加了两条线。问题是只绘制了上边界。

我试过改变语句的顺序,并用单独的 if 语句替换所有的 ors,没有骰子。在循环中使用 System.out.print 行我知道 hexEdge() 除了上面的行之外,它应该不会返回 true。

    public boolean hexEdge(int x, int y)
    {
        /**
         * returns true if the coordinates are inside the hexagon bounded by the width and height of the tile
         */
        double slope = (tileHeight/2.0)/(tileWidth);
        boolean inside=false;
        //check in acordance to sides
        if (x<(tileWidth/2 +1) )
        {
            inside= 
                    ( y == (int)(0.25*tileHeight-slope*x) ) ||//this works
                    ( y == (int)(0.75*tileHeight+slope*x) ) ||
                    (x==0 && y>(int)(0.25*tileHeight) && y<=(int)(0.25*tileHeight) );
        }else {
            int x2=x-tileWidth/2;
            inside =
                    (y == (int)(0+slope*x2) )||//this works
                    (y == (int)(tileHeight -slope*x2 ) )||
                    (x==tileWidth-1 && y>(int)(0.25*tileHeight) && y<=(int)(0.25*tileHeight) );
        }
        return inside;
    }
4

0 回答 0