summaryrefslogtreecommitdiff
path: root/xc/test/xsuite/xtest/lib/gc/line-widt.mc
blob: b76e0c31b64d8c1315674c8df6c09b720045d5bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
/*
 
Copyright (c) 1990, 1991  X Consortium

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION 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 be
used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization from the X Consortium.

 *
 * Copyright 1990, 1991 by UniSoft Group Limited.
 * 
 * Permission to use, copy, modify, distribute, and sell this software and
 * its documentation for any purpose is hereby granted without fee,
 * provided that the above copyright notice appear in all copies and that
 * both that copyright notice and this permission notice appear in
 * supporting documentation, and that the name of UniSoft not be
 * used in advertising or publicity pertaining to distribution of the
 * software without specific, written prior permission.  UniSoft
 * makes no representations about the suitability of this software for any
 * purpose.  It is provided "as is" without express or implied warranty.
 *
 * $XConsortium: line-widt.mc,v 1.13 94/04/17 21:14:46 rws Exp $
 */
>># >>ASSERTION Good A
>># 	suppressed during drafting stage
>># When unmodified by the
>># .M join-style
>># or
>># .M cap-style ,
>># then the bounding box of a wide line with endpoints [x1, y1], [x2, y2] and
>># width w is a rectangle with vertices at the real coordinates
>># 	[x1-(w*sn/2), y1+(w*cs/2)], [x1+(w*sn/2), y1-(w*cs/2)],
>># 	[x2-(w*sn/2), y2+(w*cs/2)], [x2+(w*sn/2), y2-(w*cs/2)]
>># where sn is the sine of the angle of the line
>># and cs is the cosine of the angle of the line.
>>ASSERTION Good A
When 
.M line_width 
is greater than or equal to one, and 
the center of a pixel is fully inside the boundary,
then the pixel is drawn.
>>STRATEGY
Draw a variety of lines with various widths.
Pixmap verify.
>>CODE
XVisualInfo	*vp;
static	struct	linedata {
	unsigned int 	width;
	int 	x1;
	int 	y1;
	int 	x2;
	int 	y2;
} linedata[] = {
	{1, 15, 10, 50, 30},
	{5, 50, 4, 43, 21},
	{8, 70, 6, 55, 27},
	{2, 13, 13, 15, 24},
	{15, 10, 51, 49, 60},
	};
struct	linedata	*lp;

#define NLINEDATA (sizeof(linedata)/sizeof(linedata[0]))

	for (resetvinf(VI_WIN_PIX); nextvinf(&vp); ) {
		A_DRAWABLE = makewin(A_DISPLAY, vp);
		A_GC = makegc(A_DISPLAY, A_DRAWABLE);

		for (lp = linedata; lp < &linedata[NLINEDATA]; lp++) {

			setwidth(A_DISPLAY, A_GC, lp->width);
			drawline(lp->x1, lp->y1, lp->x2, lp->y2);
		}
		PIXCHECK(A_DISPLAY, A_DRAWABLE);
	}

	CHECKPASS(nvinf());
>>ASSERTION Good A
When 
.M line_width 
is greater than or equal to one, and 
the center of the pixel is exactly on the boundary,
and the boundary is not horizontal, and
the interior is immediately to its right (x increasing direction),
then the pixel is drawn.
>>STRATEGY
Draw sloping line.
Verify that a pixel on the boundary is set.
(More complicated cases are covered by pixel verification elsewhere.)
>>CODE
#if T_XDrawRectangle || T_XDrawRectangles || T_XDrawArc || T_XDrawArcs
>># Next line should be left blank

	report("This test purpose does not apply to %s", TestName);
	report("as %s cannot generate sloping lines", TestName);
	tet_result(TET_NOTINUSE);
#else
XVisualInfo	*vp;

	for (resetvinf(VI_WIN_PIX); nextvinf(&vp); ) {
		A_DRAWABLE = makewin(A_DISPLAY, vp);
		A_GC = makegc(A_DISPLAY, A_DRAWABLE);

		setwidth(A_DISPLAY, A_GC, (unsigned)10);
		drawline(6, 13, 14, 7);

		/*
		 * Pixel at 13,14 should be unset whereas the one at 7,6 should
		 * be set.
		 */
		if (checkpixel(A_DISPLAY, A_DRAWABLE, 13, 14, W_BG))
			CHECK;
		else {
			report("pixel at 13,14 was set");
			FAIL;
		}
		if (checkpixel(A_DISPLAY, A_DRAWABLE, 7, 6, W_FG))
			CHECK;
		else {
			report("pixel at 7,6 was not set");
			FAIL;
		}
	}

	CHECKPASS(2*nvinf());
#endif
>>ASSERTION Good A
When 
.M line_width 
is greater than or equal to one, and 
the center of the pixel is exactly on the boundary,
and the boundary is horizontal, and
the interior or the boundary is immediately below 
(y increasing direction), and the interior or the boundary is immediately
to the right (x increasing direction),
then the pixel is drawn.
>>STRATEGY
Draw horizontal line.
Verify that pixels on boundary with interior below are set.
Verify that pixels on boundary with interior above are not set.
Verify that pixels on boundary with interior to the right are set.
Verify that pixels on boundary with interior to the left are not set.
>>CODE
XVisualInfo	*vp;
XImage	*lwimp;
unsigned int 	lwwidth = 8;
int 	begx = 10, begy = 10, len = 60;
int 	i;

	for (resetvinf(VI_WIN_PIX); nextvinf(&vp); ) {
		A_DRAWABLE = makewin(A_DISPLAY, vp);
		A_GC = makegc(A_DISPLAY, A_DRAWABLE);

		setwidth(A_DISPLAY, A_GC, lwwidth);

		drawline(begx, begy, begx+len, begy);

		lwimp = savimage(A_DISPLAY, A_DRAWABLE);
		for (i = 0; i < len; i++) {
			if (XGetPixel(lwimp, begx+i, begy-lwwidth/2) == W_FG)
				CHECK;
			else {
				report("Pixel with interior below was not drawn");
				FAIL;
			}
		}
		for (i = 0; i < len; i++) {
			if (XGetPixel(lwimp, begx+i, begy+lwwidth/2) == W_BG)
				CHECK;
			else {
				report("Pixel with interior above was drawn");
				FAIL;
			}
		}

		for (i = 0; i < lwwidth; i++) {
			if (XGetPixel(lwimp, 10, begy-lwwidth/2+i) == W_FG)
				CHECK;
			else {
				report("Pixel with interior to the right was not drawn");
				FAIL;
			}
		}
		for (i = 0; i < lwwidth; i++) {
			if (XGetPixel(lwimp, 70, begy-lwwidth/2+i) == W_BG)
				CHECK;
			else {
				report("Pixel with interior to the left was drawn");
				FAIL;
			}
		}

	}

	CHECKPASS(nvinf()*(2*len+2*lwwidth));
>>ASSERTION Good B 2
When 
.M line_width
is zero, then a one pixel wide line is drawn using an
unspecified, device-dependent algorithm.
>>STRATEGY
Draw horizontal zero width line.
Issue warning message if line is not one pixel in width.
Report assertion UNTESTED.
>>CODE
XVisualInfo	*vp;
struct	area	area;

	for (resetvinf(VI_WIN_PIX); nextvinf(&vp); ) {
		A_DRAWABLE = makewin(A_DISPLAY, vp);
		A_GC = makegc(A_DISPLAY, A_DRAWABLE);

		setwidth(A_DISPLAY, A_GC, (unsigned)0);
		drawline(10, 10, 70, 10);

		setarea(&area, 10, 10, 61, 1);
		if (!checkarea(A_DISPLAY, A_DRAWABLE,
				&area, W_FG, W_BG, CHECK_ALL)) {
			/*
			 * The spec doesn't even require that horizontal lines be drawn
			 * properly.  So we can only warn about suprises.
			 */
			trace("Horizontal thin line was not drawn one pixel in width as expected");
		}
	}

	tet_result(TET_UNTESTED);
>>ASSERTION Good A
When 
.M line_width
is zero,
and a line is drawn unclipped from [x1, y1] to [x2, y2] and
another line is drawn unclipped from [x1+dx, y1+dy] to [x2+dx, y2+dy], 
and a point [x, y] is touched by drawing the first line,
then point [x+dx, y+dy] is touched by drawing the second line.
>>STRATEGY
Draw thin line.
Save image with origin based on line position.
Draw thin line displaced by fixed amount.
Save image with origin in same position relative to line.
Compare images.
>>CODE
XVisualInfo	*vp;
XImage	*lwim1, *lwim2;
int 	x1, x2, y1, y2;
int 	lwx, lwy;
unsigned int 	lwwidth = 70;
unsigned int 	lwheight = 50;

	for (resetvinf(VI_WIN_PIX); nextvinf(&vp); ) {
		A_DRAWABLE = makewin(A_DISPLAY, vp);
		A_GC = makegc(A_DISPLAY, A_DRAWABLE);

		x1 = 10; y1 = 10;
		x2 = 63; y2 = 43;

		setwidth(A_DISPLAY, A_GC, (unsigned)0);

		drawline(x1, y1, x2, y2);
		lwim1 = XGetImage(A_DISPLAY, A_DRAWABLE, x1, y1, lwwidth, lwheight, AllPlanes, ZPixmap);

		if (isdeleted())
			return;

		x1 += 12;
		x2 += 12;

		y1 += 17;
		y2 += 17;

		dclear(A_DISPLAY, A_DRAWABLE);
		drawline(x1, y1, x2, y2);
		lwim2 = XGetImage(A_DISPLAY, A_DRAWABLE, x1, y1, lwwidth, lwheight, AllPlanes, ZPixmap);

		if (isdeleted())
			return;

		for (lwy = 0; lwy < lwheight; lwy++) {
			for (lwx = 0; lwx < lwwidth; lwx++) {
				if (XGetPixel(lwim1, lwx, lwy) != XGetPixel(lwim2, lwx, lwy)) {
					report("Thin line differed after displacement");
					report("Point is %d,%d", lwx, lwy);
					FAIL;

					lwy = lwheight;
					break;
				}
			}
		}
		CHECK;
	}

	CHECKPASS(nvinf());

>>ASSERTION def
When 
.M line_width
is zero,
and a line is drawn unclipped from [x1, y1] to [x2, y2] and
another line is drawn unclipped from [x1+dx, y1+dy] to [x2+dx, y2+dy], 
and a point [x, y] is not touched by drawing the first line,
then point [x+dx, y+dy] is not touched by drawing the second line.
>>ASSERTION def
>># This is done in clip-mask
When a line is clipped, and the point is inside the clipping region, and
the point would be touched by the unclipped line, then the pixel is drawn.