public void Polygon_Segment( ref ZLineCoords LineCoords ) { float dx, dy, Divider, x, y, dwidth, dheight; int xint, yint; int Steps; dwidth = Width; dheight = Height; x = LineCoords.Start.x; y = LineCoords.Start.y; dx = LineCoords.End.x - LineCoords.Start.x; dy = LineCoords.End.y - LineCoords.Start.y; Divider = ( Math.Abs( dy ) > Math.Abs( dx ) ) ? Math.Abs( dy ) : Math.Abs( dx ); dx /= Divider; dy /= Divider; for( Steps = (int)Divider; Steps >= 0; Steps-- ) { if( x >= 0.0 && x < dwidth ) { xint = (int)x; if( y > MinMax_H[xint].Max ) MinMax_H[xint].Max = y; if( y < MinMax_H[xint].Min ) MinMax_H[xint].Min = y; } if( y >= 0.0 && y < dheight ) { yint = (int)y; if( x > MinMax_V[yint].Max ) MinMax_V[yint].Max = x; if( x < MinMax_V[yint].Min ) MinMax_V[yint].Min = x; } x += dx; y += dy; } }
public void Line( ref ZLineCoords LineCoords, byte Color ) { float dx, dy, x, y; uint i, Steps; // Line Clipping algorithm : Clip lines into canva and don't draw if completely out of the drawing area. if( !ClipCoords( ref LineCoords ) ) return; // Compute line delta. x = LineCoords.Start.x; y = LineCoords.Start.y; dx = LineCoords.End.x - LineCoords.Start.x; dy = LineCoords.End.y - LineCoords.Start.y; Steps = (uint)( ( Math.Abs( dx ) > Math.Abs( dy ) ) ? Math.Abs( dx ) : Math.Abs( dy ) ); dx /= Steps; dy /= Steps; for( i = 0; i < Steps; i++ ) { SetPoint_Secure( (int)x, (int)y, Color ); x += dx; y += dy; } SetPoint_Secure( (int)LineCoords.End.x, (int)LineCoords.End.y, Color ); }
public bool ClipCoords( ref ZLineCoords LineCoords ) { CLIP Start_ClipCode, End_ClipCode; float sx, sy, ex, ey, dwidth, dheight; sx = LineCoords.Start.x; sy = LineCoords.Start.y; ex = LineCoords.End.x; ey = LineCoords.End.y; dwidth = Width - 1; dheight = Height - 1; Start_ClipCode = EvalPoint( sx, sy ); End_ClipCode = EvalPoint( ex, ey ); while( true ) { if( ( Start_ClipCode | End_ClipCode ) == 0 ) { LineCoords.Start.x = sx; LineCoords.Start.y = sy; LineCoords.End.x = ex; LineCoords.End.y = ey; return ( true ); // Line is visible and in the frame, so draw it. } if( ( Start_ClipCode & End_ClipCode ) != 0 ) { LineCoords.Start.x = sx; LineCoords.Start.y = sy; LineCoords.End.x = ex; LineCoords.End.y = ey; return ( false ); // Line is out of the frame, so don't draw it. } if( ( Start_ClipCode ) == 0 ) { if( ( Start_ClipCode & CLIP.LEFT ) != 0 ) { sy = sy + ( ey - sy ) / ( ex - sx ) * ( 0 - sx ); sx = 0; } else if( ( Start_ClipCode & CLIP.RIGHT ) != 0 ) { sy = sy + ( ey - sy ) / ( ex - sx ) * ( dwidth - sx ); sx = dwidth; } else if( ( Start_ClipCode & CLIP.TOP ) != 0 ) { sx = sx + ( ex - sx ) / ( ey - sy ) * ( 0 - sy ); sy = 0; } else if( ( Start_ClipCode & CLIP.BOTTOM ) != 0 ) { sx = sx + ( ex - sx ) / ( ey - sy ) * ( dheight - sy ); sy = dheight; } Start_ClipCode = EvalPoint( sx, sy ); } else { if( ( End_ClipCode & CLIP.LEFT ) != 0 ) { ey = sy + ( ey - sy ) / ( ex - sx ) * ( 0 - sx ); ex = 0; } else if( ( End_ClipCode & CLIP.RIGHT ) != 0 ) { ey = sy + ( ey - sy ) / ( ex - sx ) * ( dwidth - sx ); ex = dwidth; } else if( ( End_ClipCode & CLIP.TOP ) != 0 ) { ex = sx + ( ex - sx ) / ( ey - sy ) * ( 0 - sy ); ey = 0; } else if( ( End_ClipCode & CLIP.BOTTOM ) != 0 ) { ex = sx + ( ex - sx ) / ( ey - sy ) * ( dheight - sy ); ey = dheight; } End_ClipCode = EvalPoint( ex, ey ); } } return ( false ); }