From kde-commits Wed Dec 31 16:48:40 2003 From: Cies Breijs Date: Wed, 31 Dec 2003 16:48:40 +0000 To: kde-commits Subject: kdenonbeta/kturtle/src Message-Id: <20031231164840.E6A4993DE () office ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=107288935727684 CVS commit by cies: nearly FIXED some annoying wrapping bug... (took me 10+ hours to get this far >:-} ) M +27 -9 canvas.cpp 1.4 M +1 -0 canvas.h 1.4 --- kdenonbeta/kturtle/src/canvas.cpp #1.3:1.4 @@ -50,21 +50,39 @@ void Canvas::Line(int xa, int ya, int xb i->setZ(1); i->show(); - if ( Wrap && !TurtleCanvas->onCanvas(xb, yb) && repeat == false ) { + kdDebug(0)<<"Line:: "<onCanvas(xb, yb) ) { intpair offset = Offset(xb, yb); int xi = offset.x; int yi = offset.y; - while ( xi != 0 ) { + if ( CrossingBorder(xa, ya, xb, yb, false) && offset.x != 0 ) { + kdDebug(0)<<"-Xtranlation"< 0) { xi--; } else if (xi < 0) { xi++; } // offset.x > 0 ? offset.x-- : offset.x++; - } - while ( yi != 0 ) { + } else if ( CrossingBorder(xa, ya, xb, yb, true) && offset.y != 0 ) { + kdDebug(0)<<"-Ytranlation"< 0) { yi--; } else if (yi < 0) { yi++; } // offset.y > 0 ? offset.y-- : offset.y++; } } } +bool Canvas::CrossingBorder(int xa, int ya, int xb, int yb, bool XorY) { + // this class returns true it the top/bottom border of the canvas is crossed + // and return false if the left/right border is crossed + // y = A * x + B + float A = (float)( yb - ya ) / (float)( xb - xa ); + int B = ya - (int)( ( A * xa ) ); + int x_sT = (int)( ( -B ) / A ); // A * x_sT + B = 0 => x_sT = -B / A + int x_sB = (int)( ( CanvasHeight - B ) / A ); // A * x_sB + B = CW => x_sB = (CW - B) / A + int y_sL = B; // A * 0 + B = y_sL => y_sL = B + int y_sR = (int)( A * CanvasWidth ) + B; + kdDebug(0)<<"CB:: "<onCanvas(x, y) ) { intpair offset = Offset(x, y); - kdDebug(0)<<"offset:"<