⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 miarc.c

📁 远程桌面连接工具
💻 C
📖 第 1 页 / 共 5 页
字号:
/***********************************************************Copyright (c) 1987  X ConsortiumPermission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included inall copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THEX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER INAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR INCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.Except as contained in this notice, the name of the X Consortium shall not beused in advertising or otherwise to promote the sale, use or other dealingsin this Software without prior written authorization from the X Consortium.Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.                        All Rights ReservedPermission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and thatboth that copyright notice and this permission notice appear in supporting documentation, and that the name of Digital not beused in advertising or publicity pertaining to distribution of thesoftware without specific, written prior permission.  DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDINGALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALLDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES ORANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THISSOFTWARE.******************************************************************//* $XConsortium: miarc.c /main/90 1996/08/01 19:25:10 dpw $ *//* Author: Keith Packard and Bob Scheifler *//* Warning: this code is toxic, do not dally very long here. *//* $XFree86: xc/programs/Xserver/mi/miarc.c,v 3.4.2.1 1997/07/13 14:45:05 dawes Exp $ */#ifdef _XOPEN_SOURCE#include <math.h>#else#define _XOPEN_SOURCE	/* to get prototype for hypot on some systems */#include <math.h>#undef _XOPEN_SOURCE#endif#include "X.h"#include "Xprotostr.h"#include "misc.h"#include "gcstruct.h"#include "scrnintstr.h"#include "pixmapstr.h"#include "windowstr.h"#include "mifpoly.h"#include "mi.h"#include "mifillarc.h"#include "Xfuncproto.h"static double miDsin(), miDcos(), miDasin(), miDatan2();double	cbrt(#if NeedFunctionPrototypes	     double#endif);#ifdef ICEILTEMPDECLICEILTEMPDECL#endif/* * some interesting sematic interpretation of the protocol: * * Self intersecting arcs (i.e. those spanning 360 degrees)  *  never join with other arcs, and are drawn without caps *  (unless on/off dashed, in which case each dash segment *  is capped, except when the last segment meets the *  first segment, when no caps are drawn) * * double dash arcs are drawn in two parts, first the *  odd dashes (drawn in background) then the even dashes *  (drawn in foreground).  This means that overlapping *  sections of foreground/background are drawn twice, *  first in background then in foreground.  The double-draw *  occurs even when the function uses the destination values *  (e.g. xor mode).  This is the same way the wide-line *  code works and should be "fixed". * */#undef max#undef min#if defined (__GNUC__) && defined (__STDC__) && !defined (__STRICT_ANSI__)#define USE_INLINE#endif#ifdef USE_INLINE__inline static const int max (const int x, const int y){	return x>y? x:y;}__inline static const int min (const int x, const int y){	return x<y? x:y;}#elsestatic intmax (x, y){	return x>y? x:y;}static intmin (x, y){	return x<y? x:y;}#endifstruct bound {	double	min, max;};struct ibound {	int	min, max;};#define boundedLe(value, bounds)\	((bounds).min <= (value) && (value) <= (bounds).max)struct line {	double	m, b;	int	valid;};#define intersectLine(y,line) (line.m * (y) + line.b)/* * these are all y value bounds */struct arc_bound {	struct bound	ellipse;	struct bound	inner;	struct bound	outer;	struct bound	right;	struct bound	left;	struct ibound	inneri;	struct ibound	outeri;};struct accelerators {	double		tail_y;	double		h2;	double		w2;	double		h4;	double		w4;	double		h2mw2;	double		h2l;	double		w2l;	double		fromIntX;	double		fromIntY;	struct line	left, right;	int		yorgu;	int		yorgl;	int		xorg;};struct arc_def {	double	w, h, l;	double	a0, a1;};# define todeg(xAngle)	(((double) (xAngle)) / 64.0)# define RIGHT_END	0# define LEFT_END	1typedef struct _miArcJoin {	int	arcIndex0, arcIndex1;	int	phase0, phase1;	int	end0, end1;} miArcJoinRec, *miArcJoinPtr;typedef struct _miArcCap {	int		arcIndex;	int		end;		} miArcCapRec, *miArcCapPtr;typedef struct _miArcFace {	SppPointRec	clock;	SppPointRec	center;	SppPointRec	counterClock;} miArcFaceRec, *miArcFacePtr;typedef struct _miArcData {	xArc		arc;	int		render;		/* non-zero means render after drawing */	int		join;		/* related join */	int		cap;		/* related cap */	int		selfJoin;	/* final dash meets first dash */	miArcFaceRec	bounds[2];	double		x0, y0, x1, y1;} miArcDataRec, *miArcDataPtr;/* * This is an entire sequence of arcs, computed and categorized according * to operation.  miDashArcs generates either one or two of these. */typedef struct _miPolyArc {	int		narcs;	miArcDataPtr	arcs;	int		ncaps;	miArcCapPtr	caps;	int		njoins;	miArcJoinPtr	joins;} miPolyArcRec, *miPolyArcPtr;#define GCValsFunction		0#define GCValsForeground 	1#define GCValsBackground 	2#define GCValsLineWidth 	3#define GCValsCapStyle 		4#define GCValsJoinStyle		5#define GCValsMask		(GCFunction | GCForeground | GCBackground | \				 GCLineWidth | GCCapStyle | GCJoinStyle)static CARD32 gcvals[6];static void fillSpans(), newFinalSpan();static void drawArc(), drawQuadrant(), drawZeroArc();static void miArcJoin(), miArcCap(), miRoundCap(), miFreeArcs();static int computeAngleFromPath();static miPolyArcPtr miComputeArcs ();static int miGetArcPts();# define CUBED_ROOT_2	1.2599210498948732038115849718451499938964# define CUBED_ROOT_4	1.5874010519681993173435330390930175781250/* * draw one segment of the arc using the arc spans generation routines */static voidmiArcSegment(pDraw, pGC, tarc, right, left)    DrawablePtr   pDraw;    GCPtr         pGC;    xArc          tarc;    miArcFacePtr	right, left;{    int l = pGC->lineWidth;    int a0, a1, startAngle, endAngle;    miArcFacePtr	temp;    if (!l)	l = 1;    if (tarc.width == 0 || tarc.height == 0) {    	drawZeroArc (pDraw, pGC, &tarc, l, left, right);	return;    }    if (pGC->miTranslate) {	tarc.x += pDraw->x;	tarc.y += pDraw->y;    }    a0 = tarc.angle1;    a1 = tarc.angle2;    if (a1 > FULLCIRCLE)	a1 = FULLCIRCLE;    else if (a1 < -FULLCIRCLE)	a1 = -FULLCIRCLE;    if (a1 < 0) {    	startAngle = a0 + a1;	endAngle = a0;	temp = right;	right = left;	left = temp;    } else {	startAngle = a0;	endAngle = a0 + a1;    }    /*     * bounds check the two angles     */    if (startAngle < 0)	startAngle = FULLCIRCLE - (-startAngle) % FULLCIRCLE;    if (startAngle >= FULLCIRCLE)	startAngle = startAngle % FULLCIRCLE;    if (endAngle < 0)	endAngle = FULLCIRCLE - (-endAngle) % FULLCIRCLE;    if (endAngle > FULLCIRCLE)	endAngle = (endAngle-1) % FULLCIRCLE + 1;    if ((startAngle == endAngle) && a1) {	startAngle = 0;	endAngle = FULLCIRCLE;    }    drawArc (&tarc, l, startAngle, endAngle, right, left);}/*Three equations combine to describe the boundaries of the arcx^2/w^2 + y^2/h^2 = 1			ellipse itself(X-x)^2 + (Y-y)^2 = r^2			circle at (x, y) on the ellipse(Y-y) = (X-x)*w^2*y/(h^2*x)		normal at (x, y) on the ellipseThese lead to a quartic relating Y and yy^4 - (2Y)y^3 + (Y^2 + (h^4 - w^2*r^2)/(w^2 - h^2))y^2    - (2Y*h^4/(w^2 - h^2))y + (Y^2*h^4)/(w^2 - h^2) = 0The reducible cubic obtained from this quartic isz^3 - (3N)z^2 - 2V = 0whereN = (Y^2 + (h^4 - w^2*r^2/(w^2 - h^2)))/6V = w^2*r^2*Y^2*h^4/(4 *(w^2 - h^2)^2)Lett = z - Np = -N^2q = -N^3 - VThen we gett^3 + 3pt + 2q = 0The discriminant of this cubic isD = q^2 + p^3When D > 0, a real root is obtained asz = N + cbrt(-q+sqrt(D)) + cbrt(-q-sqrt(D))When D < 0, a real root is obtained asz = N - 2m*cos(acos(-q/m^3)/3)wherem = sqrt(|p|) * sign(q)Given a real root Z of the cubic, the roots of the quartic are the rootsof the two quadraticsy^2 + ((b+A)/2)y + (Z + (bZ - d)/A) = 0where A = +/- sqrt(8Z + b^2 - 4c)b, c, d are the cubic, quadratic, and linear coefficients of the quarticSome experimentation is then required to determine which solutionscorrespond to the inner and outer boundaries.*/typedef struct {    short lx, lw, rx, rw;} miArcSpan;typedef struct {    miArcSpan *spans;    int count1, count2, k;    char top, bot, hole;} miArcSpanData;typedef struct {    unsigned long lrustamp;    unsigned short lw;    unsigned short width, height;    miArcSpanData *spdata;} arcCacheRec;#define CACHESIZE 25static arcCacheRec arcCache[CACHESIZE];static unsigned long lrustamp;static arcCacheRec *lastCacheHit = &arcCache[0];static RESTYPE cacheType;/* * External so it can be called when low on memory. * Call with a zero ID in that case. *//*ARGSUSED*/intmiFreeArcCache (data, id)    pointer	    data;    XID		    id;{    int k;    arcCacheRec *cent;    if (id)	cacheType = 0;    for (k = CACHESIZE, cent = &arcCache[0]; --k >= 0; cent++)    {	if (cent->spdata)	{	    cent->lrustamp = 0;	    cent->lw = 0;	    xfree(cent->spdata);	    cent->spdata = NULL;	}    }    lrustamp = 0;    return Success;}static voidmiComputeCircleSpans(lw, parc, spdata)    int lw;    xArc *parc;    miArcSpanData *spdata;{    register miArcSpan *span;    int doinner;    register int x, y, e;    int xk, yk, xm, ym, dx, dy;    register int slw, inslw;    int inx, iny, ine;    int inxk, inyk, inxm, inym;    doinner = -lw;    slw = parc->width - doinner;    y = parc->height >> 1;    dy = parc->height & 1;    dx = 1 - dy;    MIWIDEARCSETUP(x, y, dy, slw, e, xk, xm, yk, ym);    inslw = parc->width + doinner;    if (inslw > 0)    {	spdata->hole = spdata->top;	MIWIDEARCSETUP(inx, iny, dy, inslw, ine, inxk, inxm, inyk, inym);    }    else    {	spdata->hole = FALSE;	doinner = -y;    }    spdata->count1 = -doinner - spdata->top;    spdata->count2 = y + doinner;    span = spdata->spans;    while (y)    {	MIFILLARCSTEP(slw);	span->lx = dy - x;	if (++doinner <= 0) 	{	    span->lw = slw;	    span->rx = 0;	    span->rw = span->lx + slw;	}	else	{	    MIFILLINARCSTEP(inslw);	    span->lw = x - inx;	    span->rx = dy - inx + inslw;	    span->rw = inx - x + slw - inslw;	}	span++;    }    if (spdata->bot)    {	if (spdata->count2)	    spdata->count2--;	else	{	    if (lw > (int)parc->height)		span[-1].rx = span[-1].rw = -((lw - (int)parc->height) >> 1);	    else		span[-1].rw = 0;	    spdata->count1--;	}    }}static voidmiComputeEllipseSpans(lw, parc, spdata)    int lw;    xArc *parc;    miArcSpanData *spdata;{    register miArcSpan *span;    double w, h, r, xorg;    double Hs, Hf, WH, K, Vk, Nk, Fk, Vr, N, Nc, Z, rs;    double A, T, b, d, x, y, t, inx, outx, hepp, hepm;    int flip, solution;    w = (double)parc->width / 2.0;    h = (double)parc->height / 2.0;    r = lw / 2.0;    rs = r * r;    Hs = h * h;    WH = w * w - Hs;    Nk = w * r;    Vk = (Nk * Hs) / (WH + WH);    Hf = Hs * Hs;    Nk = (Hf - Nk * Nk) / WH;    Fk = Hf / WH;    hepp = h + EPSILON;    hepm = h - EPSILON;    K = h + ((lw - 1) >> 1);    span = spdata->spans;    if (parc->width & 1)	xorg = .5;    else	xorg = 0.0;    if (spdata->top)    {	span->lx = 0;	span->lw = 1;	span++;    }    spdata->count1 = 0;    spdata->count2 = 0;    spdata->hole = (spdata->top &&		 (int)parc->height * lw <= (int)(parc->width * parc->width) &&		    lw < (int)parc->height);    for (; K > 0.0; K -= 1.0)    {	N = (K * K + Nk) / 6.0;	Nc = N * N * N;	Vr = Vk * K;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -