Menu

BresenhamLine Bug?

Adam Gates
2008-01-15
2013-05-02
  • Adam Gates

    Adam Gates - 2008-01-15

    I think there is a bug in the BresenhamLine class. In the plot function I think that this:

            if (dx > 0)
                error = dx >> 1;
            else
                error = dy >> 1;

    Should be:

            if (dx > dy)
                error = dx >> 1;
            else
                error = dy >> 1;

    I had a test calling: plot(10, 10, 11, 20).
    Before the change the output was:
    pos: 10, 11
    pos: 10, 12
    pos: 10, 13
    pos: 10, 14
    pos: 10, 15
    pos: 10, 16
    pos: 10, 17
    pos: 10, 18
    pos: 10, 19
    pos: 11, 20

    After the change the output is:
    pos: 10, 11
    pos: 10, 12
    pos: 10, 13
    pos: 10, 14
    pos: 11, 15
    pos: 11, 16
    pos: 11, 17
    pos: 11, 18
    pos: 11, 19
    pos: 11, 20

    Adam.

     
    • Sid D

      Sid D - 2008-01-16

      Yes I found the error and fixed it.

      Thanks a lot! Adam.

      -Sid

       

Log in to post a comment.

MongoDB Logo MongoDB