void ClipLine( POINT &Start, POINT &End ) { INT32 ThisSector = GetSector( End ) ; switch ( CaseTable[(INT32)LastSector][(INT32)ThisSector] ) { case 01 : GenLineToBelowLeft() ; break ; case 02 : GenLineToBelowRight() ; break ; case 03 : GenLineToAboveLeft() ; break ; case 04 : GenLineToAboveRight() ; break ; case 05 : GenLine(Start) ; GenLine(End) ; break ; case 06 : if ( OFirstPoint ) GenLine(Start) ; GenLine(End) ; break ; case 07 : POINT Middle ; Middle.x = (Start.x+End.x) >> 1 ; Middle.y = (Start.y+End.y) >> 1 ; ClipLine( Start,Middle ) ; ClipLine( Middle,End ) ; return ; case 10 : GenLineToBelowLeft() ; GenLineToBelowRight() ; break ; case 11 : GenLineToBelowLeft() ; GenLineToAboveLeft() ; break ; case 12 : GenLineToBelowRight() ; GenLineToAboveRight() ; break ; case 13 : GenLineToBelowRight() ; GenLineToBelowLeft() ; break ; case 14 : GenLineToAboveLeft() ; GenLineToAboveRight() ; break ; case 15 : GenLineToAboveLeft() ; GenLineToBelowLeft() ; break ; case 16 : GenLineToAboveRight() ; GenLineToBelowRight() ; break ; case 17 : GenLineToAboveRight() ; GenLineToAboveLeft() ; break ; } LastSector = ThisSector ; }
void CGroundLine::Paint( ) { vgui::Panel *pPanel = GetParent(); int wide, tall; pPanel->GetSize( wide, tall ); float tPrev = 0; float xPrev, yPrev; CMinimapPanel::MinimapPanel()->WorldToMinimap( MINIMAP_NOCLIP, m_vStart, xPrev, yPrev ); int nSegs = 20; for( int iSeg=1; iSeg <= nSegs; iSeg++ ) { float t = (float)iSeg / nSegs; Vector v3DPos; VectorLerp( m_vStart, m_vEnd, t, v3DPos ); float x, y; CMinimapPanel::MinimapPanel()->WorldToMinimap( MINIMAP_NOCLIP, v3DPos, x, y ); // Clip the line segment on X, then Y. if( ClipLine( xPrev, yPrev, x, y, 0, 1 ) && ClipLine( xPrev, yPrev, x, y, wide, -1 ) && ClipLine( yPrev, xPrev, y, x, 0, 1 ) && ClipLine( yPrev, xPrev, y, x, tall, -1 ) ) { Vector vColor; VectorLerp( m_vStartColor, m_vEndColor, t, vColor ); vColor *= 255.9f; vgui::surface()->DrawSetColor( (unsigned char)RoundFloatToInt( vColor.x ), (unsigned char)RoundFloatToInt( vColor.y ), (unsigned char)RoundFloatToInt( vColor.z ), 255 ); vgui::surface()->DrawLine( xPrev, yPrev, x, y ); } tPrev = t; xPrev = x; yPrev = y; } // Draw a marker at the endpoint. float xEnd, yEnd; if( CMinimapPanel::MinimapPanel()->WorldToMinimap( MINIMAP_NOCLIP, m_vEnd, xEnd, yEnd ) ) { int ix = RoundFloatToInt( xEnd ); int iy = RoundFloatToInt( yEnd ); int rectSize=1; vgui::surface()->DrawSetColor( 255, 255, 255, 255 ); vgui::surface()->DrawOutlinedRect( ix-rectSize, iy-rectSize, ix+rectSize, iy+rectSize ); } }
void ClipLine(ClipVertex* a, ClipVertex* b, const ViewState& s, int plane) // Clips the line defined by the given vertices against the clipping // plane of the given view state indexed by the 'plane' parameter. Recurses // on the next clipping plane, if there is one. When it runs out of clip // planes, it passes the line to DrawUnclippedLine(). { // Check to see if we're done clipping. if (plane >= s.ClipPlaneCount) { DrawUnclippedLine(a, b, s); return; } // Figure out which side of the clipping plane each of the vertices is on. int mask = 1 << plane; bool aclip, bclip; aclip = a->GetOutcode() & mask ? true : false; bclip = b->GetOutcode() & mask ? true : false; int clipcount = int(aclip) + int(bclip); // See if all the vertices are on the right side of the clipping plane. if (clipcount == 0) { // No clipping against this plane is needed. ClipLine(a, b, s, plane + 1); return; } // See if all the vertices are on the wrong side of the clipping plane. if (clipcount == 2) { // line is not visible. return; } // Sort so that a is on the right side. if (aclip) { ClipVertex* temp = a; a = b; b = temp; } // Convenience variables. const vec3& Normal = s.ClipPlane[plane].Normal; float D = s.ClipPlane[plane].D; // Find the vertex at the intersection of clipped line. ClipVertex c; FindIntersection(&c, *a, *b, Normal, D); c.Preprocess(s); // Draw the visible fragment. ClipLine(a, &c, s, plane + 1); }
void Line2(Array<unsigned>& pBuffer, Point pt1, Point pt2, int width, int height) { int ecount; int x_step, y_step; Point sizeScaled(width*XY_ONE, height*XY_ONE); if (!ClipLine(sizeScaled, pt1, pt2)) return; int dx = pt2.x - pt1.x; int dy = pt2.y - pt1.y; int j = dx < 0 ? -1 : 0; int ax = (dx ^ j) - j; int i = dy < 0 ? -1 : 0; int ay = (dy ^ i) - i; if (ax > ay) { dx = ax; dy = (dy ^ j) - j; pt1.x ^= pt2.x & j; pt2.x ^= pt1.x & j; pt1.x ^= pt2.x & j; pt1.y ^= pt2.y & j; pt2.y ^= pt1.y & j; pt1.y ^= pt2.y & j; x_step = XY_ONE; y_step = (int)(((int64)dy << XY_SHIFT) / (ax | 1)); ecount = (pt2.x - pt1.x) >> XY_SHIFT; }
int ConvexVolume::LineOverlap(const Line3D& l, Real& tmin, Real& tmax) const { Real oldTmin=tmin, oldTmax=tmax; for(size_t i=0; i<planes.size(); i++) if(!ClipLine(l.source,l.direction,planes[i],tmin,tmax)) return EXCLUSION; if(tmin == oldTmin && tmax == oldTmax) return INCLUSION; return INTERSECT; }
bool ClipLine(const Vector2& x, const Vector2& v, const ConvexPolygon2D& p, Real& u1, Real& u2) { Plane2D plane; for(size_t i=0; i<p.vertices.size(); i++) { p.getPlane((int)i,plane); if(!ClipLine(x,v,plane,u1,u2)) return false; } return true; }
static void DrawRegistrationMarks( drawCmd_p d ) { long x, y, delta, divisor; coOrd p0, p1, qq, q0, q1; POS_T len; char msg[10]; wFont_p fp; wFontSize_t fs; fp = wStandardFont( F_TIMES, FALSE, FALSE ); if ( units==UNITS_METRIC ) { delta = 10; divisor = 100; } else { delta = 3; divisor = 12; } for ( x=delta; (POS_T)x<PutDim(mapD.size.x); x+=delta ) { qq.x = p0.x = p1.x = (POS_T)GetDim(x); p0.y = 0.0; p1.y = mapD.size.y; if (!ClipLine( &p0, &p1, d->orig, d->angle, d->size )) continue; for ( y=(long)(ceil(PutDim(p0.y)/delta)*delta); (POS_T)y<PutDim(p1.y); y+=delta ) { qq.y = (POS_T)GetDim(y); q0.x = q1.x = qq.x; if ( x%divisor == 0 && y%divisor == 0 ) { len = 0.25; fs = 12.0; } else { len = 0.125; fs = 8.0; } q0.y = qq.y-len; q1.y = qq.y+len; DrawLine( d, q0, q1, 0, wDrawColorBlack ); q0.y = q1.y = qq.y; q0.x = qq.x-len; q1.x = qq.x+len; DrawLine( d, q0, q1, 0, wDrawColorBlack ); q0.x = qq.x + len/4;; q0.y = qq.y + len/4;; if (units == UNITS_METRIC) sprintf( msg, "%0.1fm", (DOUBLE_T)x/100.0 ); else sprintf( msg, "%ld\' %ld\"", x/12, x%12 ); DrawString( d, q0, 0.0, msg, fp, fs, wDrawColorBlack ); q0.y = qq.y - len*3/4; if (units == UNITS_METRIC) sprintf( msg, "%0.1fm", (DOUBLE_T)y/100.0 ); else sprintf( msg, "%ld\' %ld\"", y/12, y%12 ); DrawString( d, q0, 0.0, msg, fp, fs, wDrawColorBlack ); } } }
void NS_DIM_PREFIX UgInverseLine (COORD_POINT point1, COORD_POINT point2) { SHORT_POINT out[2]; INT reject,dummy; #ifdef ModelP if (me != master) return; #endif if (ClipLine (point1,point2,&(out[0]),&(out[1]),&reject,&dummy,&dummy)) return; if (!reject) (*CurrentOutputDevice->InversePolyline)(out,2); }
Bool DCClipLine(CDC *dc,I64 *x1,I64 *y1,I64 *x2,I64 *y2,I64 width=0,I64 height=0) { //also converts window to screen coordinates I64 left,top,right,bottom; CTask *win_task; if (GrLimits(dc,&left,&top,&right,&bottom,width,height)) { if (dc->flags & DCF_SCREEN_BITMAP) { win_task=dc->win_task; *x1+=win_task->win_pixel_left+win_task->win_scroll_x; *y1+=win_task->win_pixel_top+win_task->win_scroll_y; *x2+=win_task->win_pixel_left+win_task->win_scroll_x; *y2+=win_task->win_pixel_top+win_task->win_scroll_y; } return ClipLine(x1,y1,x2,y2,left,top,right,bottom); } else return FALSE; }
void DrawClippedLine(ClipVertex* a, ClipVertex* b, const ViewState& s) // Clips the line defined by the given vertices, projects the // vertices if necessary, and passes any visible fragment to the // renderer. { // Make sure the outcodes are set. if (a->GetOutcode() == -1) a->Preprocess(s); if (b->GetOutcode() == -1) b->Preprocess(s); // Check for trivial cull. if ((a->GetOutcode() & b->GetOutcode()) != 0) { // All the vertices are on the wrong side of some clip plane. Don't need to draw. return; } ClipLine(a, b, s, 0); }
void ghid_draw_line (hidGC gc, int x1, int y1, int x2, int y2) { double dx1, dy1, dx2, dy2; dx1 = Vx ((double) x1); dy1 = Vy ((double) y1); dx2 = Vx ((double) x2); dy2 = Vy ((double) y2); if (!ClipLine (0, 0, gport->width, gport->height, &dx1, &dy1, &dx2, &dy2, gc->width / gport->zoom)) return; USE_GC (gc); gdk_draw_line (gport->drawable, gport->u_gc, dx1, dy1, dx2, dy2); }
void NS_DIM_PREFIX UgLine (COORD_POINT point1, COORD_POINT point2) { SHORT_POINT out1,out2; INT reject,dummy; #ifdef ModelP if (me != master) return; #endif if (ClipLine (point1,point2,&out1,&out2,&reject,&dummy,&dummy)) return; if (!reject) { (*CurrentOutputDevice->Move)(out1); (*CurrentOutputDevice->Draw)(out2); } }
bool Camera::TransformClip(Pointf3 a, Pointf3 b, Pointf& outa, Pointf& outb) const { Pointf3 a1 = a * transform_matrix, b1 = b * transform_matrix; double az = a1.z + z_delta, bz = b1.z + z_delta; bool na = (az <= 0), nb = (bz <= 0); bool fa = (az >= 1), fb = (bz >= 1); if(na && nb || fa && fb) return false; /**/ if(na) a1 += (b1 - a1) * (0 - az) / (b1.z - a1.z); else if(nb) b1 += (a1 - b1) * (0 - bz) / (a1.z - b1.z); /**/ if(fa) a1 += (b1 - a1) * (1 - az) / (b1.z - a1.z); else if(fb) b1 += (a1 - b1) * (1 - bz) / (a1.z - b1.z); outa.x = a1.x / a1.z; outa.y = a1.y / a1.z; outb.x = b1.x / b1.z; outb.y = b1.y / b1.z; return ClipLine(outa, outb, Rectf(-view_px, -view_py, +view_px, +view_py)); }
void ghid_draw_line (hidGC gc, Coord x1, Coord y1, Coord x2, Coord y2) { double dx1, dy1, dx2, dy2; render_priv *priv = gport->render_priv; dx1 = Vx ((double) x1); dy1 = Vy ((double) y1); dx2 = Vx ((double) x2); dy2 = Vy ((double) y2); if (!ClipLine (0, 0, gport->width, gport->height, &dx1, &dy1, &dx2, &dy2, gc->width / gport->view.coord_per_px)) return; USE_GC (gc); gdk_draw_line (gport->drawable, priv->u_gc, dx1, dy1, dx2, dy2); }
void NS_DIM_PREFIX UgPolyLine (COORD_POINT *points, INT n) { SHORT_POINT out1,out2; INT reject,dummy,k; #ifdef ModelP if (me != master) return; #endif for (k=1; k<n; k++) if (ClipLine ( points[k-1],points[k],&out1,&out2,&reject,&dummy,&dummy)) return; else if (!reject) { (*CurrentOutputDevice->Move)(out1); (*CurrentOutputDevice->Draw)(out2); } }
bool DrawClipLine(RenderContext* render, int fromx, int fromy, int tox, int toy, UINT color, int lpitch) { // this function draws a clipped line int clip_x_start, cilp_y_start, clip_x_end, clip_y_end; // clip and draw each line clip_x_start = fromx; cilp_y_start = fromy; clip_x_end = tox; clip_y_end = toy; // clip the line if (ClipLine(clip_x_start, cilp_y_start, clip_x_end, clip_y_end)) DrawLine(render, clip_x_start, cilp_y_start, clip_x_end, clip_y_end, color, lpitch); // return success return true; }
void CompositeVerticalLine(Bitmap *bitmap,int x,int y,int len,Pixel c,CompositionMode comp) { if(ClipLine(&y,&x,&len,bitmap->height,bitmap->width)) CompositeVerticalLineNoClip(bitmap,x,y,len,c,comp); }
static INT ClipPolygon (COORD_POINT *in, INT nin, SHORT_POINT *out, INT *nout) { INT i,FillupStart,side1,side2,FirstSide,reject,flag,left,leftmark,right,rightmark,orientation; SHORT_POINT out1,out2; COORD_POINT point[3]; DOUBLE norm, lambda, ScalarPrd; /* initializations */ *nout = 0; /* check if polygon is degenerated */ if (nin<3) return (0); /* decide whether polygon is left or right handed */ left = right = orientation = 0; for (i=0; i<nin; i++) { if (((in[i].x-in[(i-1+nin)%nin].x)*(in[(i+1)%(nin)].y-in[i].y)) >= ((in[i].y-in[(i-1+nin)%nin].y)*(in[(i+1)%(nin)].x-in[i].x))) left++; else leftmark = i; if (((in[i].x-in[(i-1+nin)%nin].x)*(in[(i+1)%(nin)].y-in[i].y)) <= ((in[i].y-in[(i-1+nin)%nin].y)*(in[(i+1)%(nin)].x-in[i].x))) right++; else rightmark = i; } if (left == nin) orientation = CLOCKWISE; else if (right == nin) orientation = COUNTERCLOCKWISE; else if (left == nin-1) { SubtractCoordPoint(in[leftmark],in[(leftmark-1+nin)%nin],&(point[0])); SubtractCoordPoint(in[(leftmark+1)%nin],in[(leftmark-1+nin)%nin],&(point[1])); EuklidNormCoordPoint(point[1],&norm); ScalarProductCoordPoint(point[0],point[1],&ScalarPrd); if (norm < SMALL_C) lambda = 1.0; else lambda = ScalarPrd/norm/norm; LinCombCoordPoint(1.0, in[(leftmark-1+nin)%nin], lambda, point[1], &(point[2])); SubtractCoordPoint(in[leftmark],point[2],&(point[0])); EuklidNormCoordPoint(point[0],&norm); in[leftmark] = point[2]; orientation = CLOCKWISE; } else if (right == nin-1) { SubtractCoordPoint(in[rightmark],in[(rightmark-1+nin)%nin],&(point[0])); SubtractCoordPoint(in[(rightmark+1)%nin],in[(rightmark-1+nin)%nin],&(point[1])); EuklidNormCoordPoint(point[1],&norm); ScalarProductCoordPoint(point[0],point[1],&ScalarPrd); if (norm < SMALL_C) lambda = 1.0; else lambda = ScalarPrd/norm/norm; LinCombCoordPoint(1.0, in[(rightmark-1+nin)%nin], lambda, point[1], &(point[2])); SubtractCoordPoint(in[rightmark],point[2],&(point[0])); EuklidNormCoordPoint(point[0],&norm); in[rightmark] = point[2]; orientation = COUNTERCLOCKWISE; } else return(1); /* the main loop */ FillupStart = -1; flag = 0; for(i=0; i<nin; i++) { ClipLine(in[i],in[(i+1)%(nin)],&out1,&out2,&reject,&side1,&side2); if (!reject) { if (flag == 0) { FirstSide = side1; flag = 1; } if (FillupStart != -1) FillUp (FillupStart,side1,orientation,out,nout); FillupStart = side2; out[(*nout)++] = out1; if (side2 != -1) out[(*nout)++] = out2; } } if (flag && (FirstSide!=-1)) FillUp (FillupStart,FirstSide,orientation,out,nout); if (!flag) { /* test if zero vector is in the interior of the polygon */ if (orientation==1) { left = 0; for (i=0; i<nin; i++) left += (in[(i+1)%(nin)].x*in[i].y >= in[i].x*in[(i+1)%(nin)].y); /*if (left == nin) FillUpTot(out,nout);*/ } else { right = 0; for (i=0; i<nin; i++) right += (in[(i+1)%(nin)].x*in[i].y <= in[i].x*in[(i+1)%(nin)].y); /* if (right == nin) FillUpTot(out,nout); */ } } return (0); }
void DrawVerticalLine(Bitmap *bitmap,int x,int y,int len,Pixel c) { if(ClipLine(&y,&x,&len,bitmap->height,bitmap->width)) DrawVerticalLineNoClip(bitmap,x,y,len,c); }
void DrawHorizontalLine(Bitmap *bitmap,int x,int y,int len,Pixel c) { if(ClipLine(&x,&y,&len,bitmap->width,bitmap->height)) DrawHorizontalLineNoClip(bitmap,x,y,len,c); }
UINT CEditView::PrintInsideRect(CDC* pDC, RECT& rectLayout, UINT nIndexStart, UINT nIndexStop) // worker function for laying out text in a rectangle. { ASSERT_VALID(this); ASSERT_VALID(pDC); BOOL bWordWrap = (GetStyle() & ES_AUTOHSCROLL) == 0; // get buffer and real starting and ending postions UINT nLen = GetBufferLength(); if (nIndexStart >= nLen) return nLen; LPCTSTR lpszText = LockBuffer(); if (nIndexStop > nLen) nIndexStop = nLen; ASSERT(nIndexStart < nLen); // calculate text & tab metrics TEXTMETRIC tm; pDC->GetTextMetrics(&tm); int cyChar = tm.tmHeight + tm.tmExternalLeading; #ifndef _MAC int nTabStop = m_nTabStops * pDC->GetTabbedTextExtent(_T("\t"), 1, 0, NULL).cx / 8 / 4; #else int nTabStop = pDC->GetTextExtent(_T("\t"), 1).cx; #endif int aCharWidths[256]; pDC->GetCharWidth(0, 255, aCharWidths); int y = rectLayout.top; UINT cx = rectLayout.right - rectLayout.left; UINT nIndex = nIndexStart; VERIFY(pDC->SaveDC() != 0); BOOL bLayoutOnly = pDC->IntersectClipRect(&rectLayout) == NULLREGION; do { UINT nIndexEnd = EndOfLine(lpszText, nIndexStop, nIndex); if (nIndex == nIndexEnd) { y += cyChar; } else if (bWordWrap) { // word-wrap printing do { UINT nIndexWrap = ClipLine(pDC, aCharWidths, cx, nTabStop, lpszText, nIndex, nIndexEnd); UINT nIndexWord = nIndexWrap; if (nIndexWord != nIndexEnd) { while (nIndexWord > nIndex && !isspace(lpszText[nIndexWord])) { nIndexWord--; } if (nIndexWord == nIndex) nIndexWord = nIndexWrap; } CRect rect(rectLayout.left, y, rectLayout.right, y+cyChar); if (!bLayoutOnly && pDC->RectVisible(rect)) { #ifndef _MAC pDC->TabbedTextOut(rect.left, y, (LPCTSTR)(lpszText+nIndex), nIndexWord-nIndex, 1, &nTabStop, rect.left); #else pDC->TextOut(rect.left, y, (LPCTSTR)(lpszText+nIndex), nIndexWord-nIndex); #endif } y += cyChar; nIndex = nIndexWord; while (nIndex < nIndexEnd && isspace(lpszText[nIndex])) nIndex++; } while (nIndex < nIndexEnd && y+cyChar <= rectLayout.bottom); nIndexEnd = nIndex; } else { // non-word wrap printing (much easier and faster) CRect rect(rectLayout.left, y, rectLayout.right, y+cyChar); if (!bLayoutOnly && pDC->RectVisible(rect)) { UINT nIndexClip = ClipLine(pDC, aCharWidths, cx, nTabStop, lpszText, nIndex, nIndexEnd); if (nIndexClip < nIndexEnd) { if (_istlead(*(lpszText+nIndexClip))) nIndexClip++; nIndexClip++; } #ifndef _MAC pDC->TabbedTextOut(rect.left, y, (LPCTSTR)(lpszText+nIndex), nIndexClip-nIndex, 1, &nTabStop, rect.left); #else pDC->TextOut(rect.left, y, (LPCTSTR)(lpszText+nIndex), nIndexClip-nIndex); #endif } y += cyChar; } nIndex = NextLine(lpszText, nIndexStop, nIndexEnd); } while (nIndex < nIndexStop && y+cyChar <= rectLayout.bottom); pDC->RestoreDC(-1); UnlockBuffer(); ASSERT_VALID(this); rectLayout.bottom = y; return nIndex; }
void CompositeHorizontalLine(Bitmap *bitmap,int x,int y,int len,Pixel c,CompositionMode comp) { if(ClipLine(&x,&y,&len,bitmap->width,bitmap->height)) CompositeHorizontalLineNoClip(bitmap,x,y,len,c,comp); }
void NS_DIM_PREFIX UgStyledLine (COORD_POINT point1, COORD_POINT point2, DOUBLE dash_length, DOUBLE space_length ) { SHORT_POINT out1,out2, end; INT reject,dummy; register double x1, y1, x2, y2; double dx_dash, dy_dash, dx_space, dy_space; COORD_POINT temp; #ifdef ModelP if (me != master) return; #endif /* to avoid rounding errors if the same line is drawn twice, one time p1->p2 and the other time p2->p1, order the points in a general way */ if ( point1.x > point2.x ) { temp = point1; point1 = point2; point2 = temp; } if (ClipLine (point1,point2,&out1,&out2,&reject,&dummy,&dummy)) return; if (reject) return; /* adjust the dash- and spacelength to fit exactly into the line; the line will start and end with a dash */ /* misuse of x1 and y1 as the slopes and x2 as linelength; y2 as temp */ x1 = (double)(out2.x - out1.x); y1 = (double)(out2.y - out1.y); x2 = sqrt( x1*x1 + y1 * y1 ); if( fabs(x2) < 1e-20 ) { /* linelength very small */ (*CurrentOutputDevice->Move)(out1); (*CurrentOutputDevice->Draw)(out2); return; } /* adjust the dash- and spacelength to fit exactly into the line; the line will start and end with a dash! */ dummy = x2 / (dash_length + space_length) + 0.5; /* how many pairs of dash+space fit completely into the line? */ y2 = x2 / ( (dummy+1)*dash_length + dummy*space_length ); /* scaling factor */ dash_length *= y2; space_length *= y2; /* increments for dashes and spaces */ dx_dash = x1 * dash_length / x2; dy_dash = y1 * dash_length / x2; dx_space = x1 * space_length / x2; dy_space = y1 * space_length / x2; x1 = out1.x; y1 = out1.y; end = out2; /* save end point */ out2 = out1; /* reset */ while ( out2.x != end.x || out2.y != end.y ) { x2 = x1 + dx_dash; y2 = y1 + dy_dash; out2.x = (short)(x2 + 0.5 ); out2.y = (short)(y2 + 0.5 ); /* rounding */ (*CurrentOutputDevice->Move)(out1); (*CurrentOutputDevice->Draw)(out2); x1 = x2 + dx_space; y1 = y2 + dy_space; out1.x = (short)(x1 + 0.5 ); out1.y = (short)(y1 + 0.5 ); /* rounding */ } }
bool ClipLine(const Vector3& x, const Vector3& v, const ConvexPolyhedron3D& p, Real& u1, Real& u2) { for(int i=0; i<p.numPlanes; i++) if(!ClipLine(x,v,p.planes[i],u1,u2)) return false; return true; }
static void ChangeDim( void ) { int x, y, x0, x1, y0, y1; coOrd p0; int size; bitmap_t tmpBm; BOOL_T selected; MapGrid( zero, mapD.size, 0.0, currPrintGrid.orig, currPrintGrid.angle, currPrintGrid.size.x, currPrintGrid.size.y, &x0, &x1, &y0, &y1 ); #ifdef LATER d0 = sqrt( mapD.size.x * mapD.size.x + mapD.size.y * mapD.size.y ); Translate( &p1, currPrintGrid.orig, currPrintGrid.angle, d0 ); p0 = currPrintGrid.orig; ClipLine( &p0, &p1, zero, 0.0, mapD.size ); d1 = FindDistance( currPrintGrid.orig, p1 ); y1 = (int)ceil(d1/currPrintGrid.size.y); Translate( &p1, currPrintGrid.orig, currPrintGrid.angle+180, d0 ); p0 = currPrintGrid.orig; ClipLine( &p0, &p1, zero, 0.0, mapD.size ); d1 = FindDistance( currPrintGrid.orig, p1 ); y0 = -(int)floor(d1/currPrintGrid.size.y); Translate( &p1, currPrintGrid.orig, currPrintGrid.angle+90, d0 ); p0 = currPrintGrid.orig; ClipLine( &p0, &p1, zero, 0.0, mapD.size ); d1 = FindDistance( currPrintGrid.orig, p1 ); x1 = (int)ceil(d1/currPrintGrid.size.x); Translate( &p1, currPrintGrid.orig, currPrintGrid.angle+270, d0 ); p0 = currPrintGrid.orig; ClipLine( &p0, &p1, zero, 0.0, mapD.size ); d1 = FindDistance( currPrintGrid.orig, p1 ); x0 = -(int)floor(d1/currPrintGrid.size.x); #endif if ( x0==bm.x0 && x1==bm.x1 && y0==bm.y0 && y1==bm.y1 ) return; size = (x1-x0) * (y1-y0); if (size > bm0.memsize) { bm0.bm = MyRealloc( bm0.bm, size ); bm0.memsize = size; } bm0.x0 = x0; bm0.x1 = x1; bm0.y0 = y0; bm0.y1 = y1; memset( bm0.bm, 0, bm0.memsize ); pageCount = 0; if (bm.bm) { for ( x=bm.x0; x<bm.x1; x++ ) { for ( y=bm.y0; y<bm.y1; y++ ) { selected = BITMAP( bm, x, y ); if (selected) { p0.x = bm.orig.x + x * bm.size.x + bm.size.x/2.0; p0.y = bm.orig.y + y * bm.size.y + bm.size.y/2.0; Rotate( &p0, bm.orig, bm.angle ); p0.x -= currPrintGrid.orig.x; p0.y -= currPrintGrid.orig.y; Rotate( &p0, zero, -currPrintGrid.angle ); x0 = (int)floor(p0.x/currPrintGrid.size.x); y0 = (int)floor(p0.y/currPrintGrid.size.y); if ( x0>=bm0.x0 && x0<bm0.x1 && y0>=bm0.y0 && y0<bm0.y1 ) { if ( BITMAP( bm0, x0, y0 ) == FALSE ) { pageCount++; BITMAP( bm0, x0, y0 ) = TRUE; } } } } } } tmpBm = bm0; bm0 = bm; bm = tmpBm; bm.orig = currPrintGrid.orig; bm.size = currPrintGrid.size; bm.angle = currPrintGrid.angle; sprintf( message, _("%d pages"), pageCount ); ParamLoadMessage( &printPG, I_PAGECNT, message ); ParamDialogOkActive( &printPG, pageCount!=0 ); }
void DrawLine(int x0,int y0,int x1,int y1,Uint32 color){ if (ClipLine(x0, y0, x1, y1) == 0) { return; } int pitchWidth = gSurface->pitch >> 2; int dx = x1 - x0; int dy = y1 - y0; // test x int x_inc; if (dx >= 0) { x_inc = 1; }else{ x_inc = -1; dx = -dx; } // test y int y_inc; if (dy >= 0) { y_inc = pitchWidth; }else{ y_inc = -pitchWidth; dy = -dy; } // compute (dx,dy) * 2 int dx2 = dx << 1; int dy2 = dy << 1; // pre-compute first pixel address in video buffer based on 32bit data Uint32* vb_start = (Uint32 *)gSurface->pixels + x0 + y0 * pitchWidth; int error; // now based on which delta is greater we can draw the line if (dx > dy) { // initialize error term error = dy2 - dx; for (int index = 0; index <= dx; ++index) { // set pixel *vb_start = color; //test if error has overflowed if (error >= 0) { error-=dx2; //move to next line vb_start += y_inc; } // adjust the error term error += dy2; vb_start += x_inc; } // end for }else{ // initialize error term error = dx2 - dy; // draw the line for (int index=0; index <= dy; index++) { // set the pixel *vb_start = color; // test if error overflowed if (error >= 0) { error-=dy2; // move to next line vb_start+=x_inc; } // end if error overflowed // adjust the error term error+=dx2; // move to the next pixel vb_start+=y_inc; } // end for } }
LONG CutBlock2(struct InstData *data, BOOL Clipboard, BOOL NoCut, struct marking *newblock, BOOL update) { LONG tvisual_y, error; LONG startx, stopx; LONG res = 0; struct line_node *startline, *stopline; ENTER(); startx = newblock->startx; stopx = newblock->stopx; startline = newblock->startline; stopline = newblock->stopline; //D(DBF_STARTUP, "CutBlock2: %ld-%ld %lx-%lx %ld %ld", startx, stopx, startline, stopline, Clipboard, NoCut); if(startline != stopline) { struct line_node *c_startline = startline->next; data->update = FALSE; if(Clipboard == TRUE) { if(InitClipboard(data, IFFF_WRITE)) { D(DBF_CLIPBOARD, "writing FORM"); error = PushChunk(data->iff, ID_FTXT, ID_FORM, IFFSIZE_UNKNOWN); SHOWVALUE(DBF_CLIPBOARD, error); ClipChars(startx, startline, startline->line.Length-startx, data); } else { Clipboard = FALSE; } } while(c_startline != stopline) { if(Clipboard == TRUE) { ClipLine(c_startline, data); } if(NoCut == FALSE) { struct line_node *cc_startline = c_startline; MyFreePooled(data->mypool, c_startline->line.Contents); if(c_startline->line.Styles != NULL) MyFreePooled(data->mypool, c_startline->line.Styles); data->totallines -= c_startline->visual; c_startline = c_startline->next; //D(DBF_STARTUP, "FreeLine %08lx", cc_startline); FreeLine(cc_startline, data); } else c_startline = c_startline->next; } if(Clipboard == TRUE) { if(stopx != 0) ClipChars(0, stopline, stopx, data); EndClipSession(data); } if(NoCut == FALSE) { startline->next = stopline; stopline->previous = startline; //D(DBF_STARTUP, "RemoveChars: %ld %ld %08lx %ld", startx, stopx, startline, startline->line.Length); if(startline->line.Length-startx-1 > 0) RemoveChars(startx, startline, startline->line.Length-startx-1, data); if(stopx != 0) RemoveChars(0, stopline, stopx, data); data->CPos_X = startx; data->actualline = startline; MergeLines(startline, data); } } else { if(Clipboard == TRUE) { if(InitClipboard(data, IFFF_WRITE)) { D(DBF_CLIPBOARD, "writing FORM"); error = PushChunk(data->iff, ID_FTXT, ID_FORM, IFFSIZE_UNKNOWN); SHOWVALUE(DBF_CLIPBOARD, error); ClipChars(startx, startline, stopx-startx, data); EndClipSession(data); } if(update == TRUE && NoCut == TRUE) { MarkText(data->blockinfo.startx, data->blockinfo.startline, data->blockinfo.stopx, data->blockinfo.stopline, data); goto end; } } if(NoCut == FALSE) { data->CPos_X = startx; RemoveChars(startx, startline, stopx-startx, data); if(update == TRUE) goto end; } } tvisual_y = LineToVisual(startline, data)-1; if(tvisual_y < 0 || tvisual_y > data->maxlines) { //D(DBF_STARTUP, "ScrollIntoDisplay"); ScrollIntoDisplay(data); tvisual_y = 0; } if(update == TRUE) { //D(DBF_STARTUP, "DumpText! %ld %ld %ld", data->visual_y, tvisual_y, data->maxlines); data->update = TRUE; DumpText(data->visual_y+tvisual_y, tvisual_y, data->maxlines, TRUE, data); } res = tvisual_y; end: RETURN(res); return res; }
//---------------------------------------------------- // edits the color table with the given stroke line //---------------------------------------------------- // void QFunctionEditor:: DoLine( int &start_x, int &start_y, int &end_x, int &end_y) { bool bChanged = false; ClipLine(end_x, end_y, start_x, start_y); int x1 = start_x; int x2 = end_x; Q_ASSERT((x1 >= 0) && (x1 < 256)); Q_ASSERT((x2 >= 0) && (x2 < 256)); float y1 = (float) start_y; float y2 = (float) end_y; int xstep = 1; int value; if(x1 > x2) { xstep = -1; } int i; float ystep = (y2-y1) / (float) (xstep * (x2-x1)); for(int x = x1; x != x2+xstep; x+= xstep) { value = 255 - (int) (y1+0.5); if(value > 255) { value = 255; } else if(value < 0) { value = 0; } i = 4*x; if(m_nInternalMode == INTERNAL_MODE_COLOR_TABLE) { if(m_nMode & 1) { m_pColorTableBuffer[i ] = (unsigned char)value; } if(m_nMode & 2) { m_pColorTableBuffer[i+1] = (unsigned char)value; } if(m_nMode & 4) { m_pColorTableBuffer[i+2] = (unsigned char)value; } if(m_nMode & 8) { m_pColorTableBuffer[i+3] = (unsigned char)value; } } else { if(m_nMode & 1) { m_pColorMapBuffer->set1Value(x*4, (float)value / 255.0F); } if(m_nMode & 2) { m_pColorMapBuffer->set1Value(x*4+1, (float)value / 255.0F); } if(m_nMode & 4) { m_pColorMapBuffer->set1Value(x*4+2, (float)value / 255.0F); } if(m_nMode & 8) { m_pColorMapBuffer->set1Value(x*4+3, (float)value / 255.0F); } } y1 += ystep; bChanged = true; } if(bChanged) { emit(tableChanged()); } }
size_t FuzzyClip( PPOINT IPoints, PBYTE ITypes, size_t ILength, BOOL IsClosed, RECT *InnerRect, RECT *OuterRect, PPOINT pOPoints, PBYTE pOTypes, size_t pOMaxLength ) { IRect = (GRECT*) InnerRect ; ORect = (GRECT*) OuterRect ; OPoints = pOPoints ; OTypes = pOTypes ; OMaxLength = pOMaxLength ; OLength = 0 ; if ( ILength <= 0 ) return 0 ; try { Index = 0 ; while ( Index<ILength ) { OFirstPoint = TRUE ; POINT StartPoint = IPoints[Index++] ; LastSector = GetSector( StartPoint ) ; LastPoint = StartPoint ; while ( Index<ILength && (IsLine(ITypes[Index]) || IsCurve(ITypes[Index])) ) { if ( IsLine(ITypes[Index]) ) { ClipLine( LastPoint,IPoints[Index] ) ; LastPoint = IPoints[Index++] ; } else { ClipCurve( LastPoint,IPoints[Index],IPoints[Index+1],IPoints[Index+2] ) ; LastPoint = IPoints[Index+2] ; Index += 3 ; } } if ( IsClosed || (ITypes[Index-1] & PT_CLOSEFIGURE) ) { ClipLine( LastPoint,StartPoint ) ; if ( !OFirstPoint ) *(OTypes-1) |= PT_CLOSEFIGURE ; } if ( !OFirstPoint && IsMove(*(OTypes-1)) ) { OTypes-- ; OPoints-- ; OLength-- ; } } } catch ( INT32 ) { OLength = (size_t)-1 ; } return OLength ; }