Exemple #1
0
    public List <IntegerVector2> rasterize(IntegerVector2 start, IntegerVector2 end)
    {
        List <IntegerVector2> toBeDrawn = new List <IntegerVector2>();

        int dx           = end.getX() - start.getX();
        int dy           = end.getY() - end.getY();
        int TwoDy        = 2 * dy;
        int TwoDYminusDX = TwoDy - dx;
        int p            = TwoDYminusDX;
        int y            = 0;

        bool XandYSwapped = false;

        if (dx < 0)
        {
            toBeDrawn = rasterize(end, start);
        }

        if (dy < 0)
        {
            toBeDrawn = rasterize(negateY(start), negateY(end));

            toBeDrawn = NegateYList(toBeDrawn);
        }

        if (dy > dx)
        {
            swapXandY(start);
            swapXandY(end);
            XandYSwapped = true;
        }

        y = start.getY();
        for (int i = start.getX(); i < end.getX(); i++)
        {
            if (p > 0)
            {
                y++;
                p = p - TwoDYminusDX;
            }

            else
            {
                p = p + TwoDy;
            }

            toBeDrawn.Add(new IntegerVector2(i, y));
        }



        if (XandYSwapped)
        {
            toBeDrawn = swapXandY(toBeDrawn);
        }

        return(toBeDrawn);
    }
Exemple #2
0
    public void swapXandY(IntegerVector2 point)
    {
        int holder = point.getX();

        point.setX(point.getY());
        point.setY(holder);
    }
Exemple #3
0
 public IntegerVector2 negateY(IntegerVector2 point)
 {
     return(new IntegerVector2(point.getX(), -point.getY()));
 }