private void thin_flat_line(int x1, int y1, int x2, int y2) {
      int nx1,ny1,nx2,ny2;

      // get the "dips" for the points to clip
      int code1 = thin_flat_line_clip_code(x1, y1);
      int code2 = thin_flat_line_clip_code(x2, y2);

      if ((code1 & code2)!=0) {
        return;
      } else {
        int dip = code1 | code2;
        if (dip != 0) {
          // now calculate the clipped points
          float a1 = 0, a2 = 1, a = 0;
          for (int i=0;i<4;i++) {
            if (((dip>>i)%2)==1) {
              a = thin_flat_line_slope((float)x1, (float)y1,
                                      (float)x2, (float)y2, i+1);
              if (((code1>>i)%2)==1) {
                a1 = (float)Math.max(a, a1);
              } else {
                a2 = (float)Math.min(a, a2);
              }
            }
          }
          if (a1>a2) return;
          else {
            nx1=(int) (x1+a1*(x2-x1));
            ny1=(int) (y1+a1*(y2-y1));
            nx2=(int) (x1+a2*(x2-x1));
            ny2=(int) (y1+a2*(y2-y1));
          }
          // line is fully visible/unclipped
        } else {
          nx1=x1; nx2=x2;
          ny1=y1; ny2=y2;
        }
      }

      // new "extremely fast" line code
      // adapted from http://www.edepot.com/linee.html

      boolean yLonger=false;
      int shortLen=ny2-ny1;
      int longLen=nx2-nx1;
      if (Math.abs(shortLen)>Math.abs(longLen)) {
        int swap=shortLen;
        shortLen=longLen;
        longLen=swap;
        yLonger=true;
      }
      int decInc;
      if (longLen==0) decInc=0;
      else decInc = (shortLen << 16) / longLen;

      if (nx1==nx2) {
        // special case: vertical line
        if (ny1>ny2) { int ty=ny1; ny1=ny2; ny2=ty; }
        int offset=ny1*width+nx1;
        for(int j=ny1; j<=ny2; j++) {
          thin_point_at_index(offset,0,strokeColor);
          offset+=width;
        }
        return;
      } else if (ny1==ny2) {
        // special case: horizontal line
        if (nx1>nx2) { int tx=nx1; nx1=nx2; nx2=tx; }
        int offset=ny1*width+nx1;
        for(int j=nx1; j<=nx2; j++) thin_point_at_index(offset++,0,strokeColor);
        return;
      } else if (yLonger) {
        if (longLen>0) {
          longLen+=ny1;
          for (int j=0x8000+(nx1<<16);ny1<=longLen;++ny1) {
            thin_point_at(j>>16, ny1, 0, strokeColor);
            j+=decInc;
          }
          return;
        }
        longLen+=ny1;
        for (int j=0x8000+(nx1<<16);ny1>=longLen;--ny1) {
          thin_point_at(j>>16, ny1, 0, strokeColor);
          j-=decInc;
        }
        return;
      } else if (longLen>0) {
        longLen+=nx1;
        for (int j=0x8000+(ny1<<16);nx1<=longLen;++nx1) {
          thin_point_at(nx1, j>>16, 0, strokeColor);
          j+=decInc;
        }
        return;
      }
      longLen+=nx1;
      for (int j=0x8000+(ny1<<16);nx1>=longLen;--nx1) {
        thin_point_at(nx1, j>>16, 0, strokeColor);
        j-=decInc;
      }
    }