Пример #1
0
int
whatpos(obj *p, int corner, float *px, float *py)	/* what is the position (no side effect) */
{
	float	x, y, bnd[4];

	if (corner >= EAST && corner <= SW) {
		get_bounds(p, bnd, 2);	/* 2=>disregard line width */
					/* changed 3/18/91 by DBK  */
		switch (corner) {
	case NE:	x = bnd[2];		y = bnd[3];	break;
	case SW:	x = bnd[0];		y = bnd[1];	break;
	case SE:	x = bnd[2];		y = bnd[1];	break;
	case NW:	x = bnd[0];		y = bnd[3];	break;
	case NORTH:	x = (bnd[0]+bnd[2])/2;	y = bnd[3];	break;
	case SOUTH:	x = (bnd[0]+bnd[2])/2;	y = bnd[1];	break;
	case EAST:	x = bnd[2];	y = (bnd[1]+bnd[3])/2;	break;
	case WEST:	x = bnd[0];	y = (bnd[1]+bnd[3])/2;	break;
		}
	}
	else {	/* DBK--note that get_bounds returns the transformed position,
		   but the following calculations do not!! */
		x = p->o_x;
		y = p->o_y;

/* futz around for special cases: */

		switch (p->o_type) {
	case BLOCK:	if (corner == START)
				whatpos(p->o_next, START, &x, &y);
			else if (corner == END)
				whatpos(p->o_val[N_VAL+1].o->o_prev,END,&x,&y);
			break;
	case ARC:	if (corner == START) {
				x = p->o_val[N_VAL+2].f;
				y = p->o_val[N_VAL+3].f;
			}
			else if (corner == END)	{
				x = p->o_val[N_VAL+4].f;
				y = p->o_val[N_VAL+5].f;
			}
			break;
	case LINE:
	case SPLINE:
	case ARROW:	switch (corner) {
				int	n;
		case START:	x = p->o_val[N_VAL+4].f;
				y = p->o_val[N_VAL+5].f;
				break;
		case END:	n = N_VAL + 4 + 2*p->o_val[N_VAL+3].f;
				x = p->o_val[n].f;
				y = p->o_val[n+1].f;
				break;
			}
			break;
		}
	}
	*px = x;
	*py = y;
	return 1;
}
Пример #2
0
obj *getpos(obj *p, int corner)	/* find position of point */
{
	double x, y;

	whatpos(p, corner, &x, &y);
	return makepos(x, y);
}
Пример #3
0
obj *
getpos(obj *p, int corner)	/* find position of point */
{
	float	x, y;

	if (pic_compat && (p->o_type == CIRCLE || p->o_type == ELLIPSE) &&
		(corner == NE || corner == NW || corner == SW || corner == SE))
			return getnth(p, corner == NE ? 2 : corner == NW ? 4 :
							corner == SW ? 6 : 8);
	if (corner == -1 ) {
		if (pic_compat && (p->o_type == LINE || p->o_type == ARROW ||
							p->o_type == SPLINE))
			corner = START;
		else
			return p;
	}
	whatpos(p, corner, &x, &y);
	return makepos(x,y,corner,(corner < EAST || corner > SW)? p: (obj *)0);
}
Пример #4
0
int whatpos(obj *p, int corner, double *px, double *py)	/* what is the position (no side effect) */
{
	double x, y, x1, y1;

	if (p == NULL)
		ERROR "null object" FATAL;
	dprintf("whatpos %o %d %d\n", p, p->o_type, corner);
	x = p->o_x;
	y = p->o_y;
	if (p->o_type != PLACE && p->o_type != MOVE) {
		x1 = p->o_val[0];
		y1 = p->o_val[1];
	}
	switch (p->o_type) {
	case PLACE:
		break;
	case BOX:
	case BLOCK:
	case TEXT:
		switch (corner) {
		case NORTH:	y += y1 / 2; break;
		case SOUTH:	y -= y1 / 2; break;
		case EAST:	x += x1 / 2; break;
		case WEST:	x -= x1 / 2; break;
		case NE:	x += x1 / 2; y += y1 / 2; break;
		case SW:	x -= x1 / 2; y -= y1 / 2; break;
		case SE:	x += x1 / 2; y -= y1 / 2; break;
		case NW:	x -= x1 / 2; y += y1 / 2; break;
		case START:
			if (p->o_type == BLOCK)
				return whatpos(objlist[(int)p->o_val[2]], START, px, py);
		case END:
			if (p->o_type == BLOCK)
				return whatpos(objlist[(int)p->o_val[3]], END, px, py);
		}
		break;
	case ARC:
		switch (corner) {
		case START:
			if (p->o_attr & CW_ARC) {
				x = p->o_val[2]; y = p->o_val[3];
			} else {
				x = x1; y = y1;
			}
			break;
		case END:
			if (p->o_attr & CW_ARC) {
				x = x1; y = y1;
			} else {
				x = p->o_val[2]; y = p->o_val[3];
			}
			break;
		}
		if (corner == START || corner == END)
			break;
		x1 = y1 = sqrt((x1-x)*(x1-x) + (y1-y)*(y1-y));
		/* Fall Through! */
	case CIRCLE:
	case ELLIPSE:
		switch (corner) {
		case NORTH:	y += y1; break;
		case SOUTH:	y -= y1; break;
		case EAST:	x += x1; break;
		case WEST:	x -= x1; break;
		case NE:	x += 0.707 * x1; y += 0.707 * y1; break;
		case SE:	x += 0.707 * x1; y -= 0.707 * y1; break;
		case NW:	x -= 0.707 * x1; y += 0.707 * y1; break;
		case SW:	x -= 0.707 * x1; y -= 0.707 * y1; break;
		}
		break;
	case LINE:
	case SPLINE:
	case ARROW:
		switch (corner) {
		case START:	break;	/* already in place */
		case END:	x = x1; y = y1; break;
		default: /* change! */
		case CENTER:	x = (x+x1)/2; y = (y+y1)/2; break;
		case NORTH:	if (y1 > y) { x = x1; y = y1; } break;
		case SOUTH:	if (y1 < y) { x = x1; y = y1; } break;
		case EAST:	if (x1 > x) { x = x1; y = y1; } break;
		case WEST:	if (x1 < x) { x = x1; y = y1; } break;
		}
		break;
	case MOVE:
		/* really ought to be same as line... */
		break;
	}
	dprintf("whatpos returns %g %g\n", x, y);
	*px = x;
	*py = y;
	return 1;
}