transform.c revision e32e2dab
1/*
2
3Copyright 1993, 1998  The Open Group
4
5Permission to use, copy, modify, distribute, and sell this software and its
6documentation for any purpose is hereby granted without fee, provided that
7the above copyright notice appear in all copies and that both that
8copyright notice and this permission notice appear in supporting
9documentation.
10
11The above copyright notice and this permission notice shall be included
12in all copies or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
18OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20OTHER DEALINGS IN THE SOFTWARE.
21
22Except as contained in this notice, the name of The Open Group shall
23not be used in advertising or otherwise to promote the sale, use or
24other dealings in this Software without prior written authorization
25from The Open Group.
26
27*/
28
29
30/*
31 * transformed coordinate system objects for X
32 */
33
34#include	<X11/Xlib.h>
35#include	"transform.h"
36#include	<stdlib.h>
37
38static XPoint *
39TranslatePoints(TPoint *points, int n_points,
40		Transform *t, int mode)
41{
42	XPoint	*xpoints;
43	double	xoff = 0.0, yoff = 0.0;
44
45	xpoints = (XPoint *) malloc ((unsigned)n_points * sizeof (*xpoints));
46	if (!xpoints)
47		return NULL;
48	for (int i = 0; i < n_points; i++) {
49		xpoints[i].x = Xx(points[i].x + xoff, points[i].y + yoff, t);
50		xpoints[i].y = Xy(points[i].x + xoff, points[i].y + yoff, t);
51		if (mode == CoordModePrevious) {
52			xoff += points[i].x;
53			yoff += points[i].y;
54		}
55	}
56	return xpoints;
57}
58
59void
60TFillPolygon (register Display *dpy, Drawable d, GC gc, Transform *t,
61	      TPoint *points, int n_points, int shape, int mode)
62{
63	XPoint	*xpoints;
64
65	xpoints = TranslatePoints (points, n_points, t, mode);
66	if (xpoints) {
67		XFillPolygon (dpy, d, gc, xpoints, n_points, shape,
68				CoordModeOrigin);
69		free (xpoints);
70	}
71}
72
73void
74TFillArc (register Display *dpy, Drawable d, GC gc, Transform *t,
75	  double x, double y, double width, double height,
76	  int angle1, int angle2)
77{
78	int	xx, xy, xw, xh;
79
80	xx = Xx(x,y,t);
81	xy = Xy(x,y,t);
82	xw = Xwidth (width, height, t);
83	xh = Xheight (width, height, t);
84	if (xw < 0) {
85		xx += xw;
86		xw = -xw;
87	}
88	if (xh < 0) {
89		xy += xh;
90		xh = -xh;
91	}
92	XFillArc (dpy, d, gc, xx, xy, xw, xh, angle1, angle2);
93}
94
95void
96SetTransform (Transform *t, int xx1, int xx2, int xy1, int xy2,
97	      double tx1, double tx2, double ty1, double ty2)
98{
99	t->mx = ((double) xx2 - xx1) / (tx2 - tx1);
100	t->bx = ((double) xx1) - t->mx * tx1;
101	t->my = ((double) xy2 - xy1) / (ty2 - ty1);
102	t->by = ((double) xy1) - t->my * ty1;
103}
104