/* $XConsortium: wsxf5.pi,v 5.2 94/04/17 20:47:32 rws Exp $ */

/*****************************************************************

Copyright (c) 1989, 1990, 1991,1990  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 (c) 1989, 1990, 1991,1990 by Sun Microsystems, Inc.

                        All Rights Reserved

Permission 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 that
both that copyright notice and this permission notice appear in 
supporting documentation, and that the names of Sun Microsystems,
and the X Consortium, not be used in advertising or publicity 
pertaining to distribution of the software without specific, written 
prior permission.  

SUN MICROSYSTEMS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT 
SHALL SUN MICROSYSTEMS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL 
DAMAGES OR ANY 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 THIS
SOFTWARE.

******************************************************************/


## wsxf5.pi -  
## Test workstation clipping
## Draw several polylines and verify the presence of pixels inside the
## ws window and the absence of pixels outside the ws window.

source macro.pi

tbegintest("wsxf5","workstation clipping");

# INITIALIZE: ws type, ws window, viewport and a polyline that represents the
#	boundary of the ws window (2D and 3D), and a text string
wstype = i_get_ws_type("phigs_ws_type_x_drawable");
window = I_Plimit(0.4,0.8,0.4,0.8);
viewport = I_Plimit(25.0,75.0,25.0,75.0);
box = IA_Ppoint(5, 0.4,0.4, 0.4,0.8, 0.8,0.8, 0.8,0.4, 0.4,0.4);
window3 = I_Plimit3(0.4,0.8,0.4,0.8,0.4,0.8);
viewport3 = I_Plimit3(25.0,75.0,25.0,75.0,0.25,0.75);
box3 = IA_Ppoint3(5, 0.4,0.4,0.6, 0.4,0.8,0.6, 0.8,0.8,0.6, 0.8,0.4,0.6, 0.4,0.4,0.6);
plbox = I_Ppoint_list(5,box);
plbox3 = I_Ppoint_list3(5,box3);
text = malloc(128);

# SETUP: open phigs and a workstation, open and post a structure
i_open_phigs(NULL,PDEF_MEM_SIZE);
i_make_xwindow(&xdisplay,&xwindow,&conn,0,0,100,100);
popen_ws(1,&conn,wstype);
popen_struct(1);
ppost_struct(1,1,1.0);


# OPERATION, VERIFICATION begin:

# testing 2D case

# set ws transformation, 
# draw the polyline that represent the boundary of the ws window 
pset_ws_win(1,&window);
pset_ws_vp(1,&viewport);
ppolyline(&plbox);

foreach @x1 @y1 @x2 @y2 @on1 @on2 @text (
	0.5; 0.5; 0.7; 0.7; 1; 1; "2D line entirely in";
	0.6; 0.6; 0.3; 0.4; 1; 0; "2D line crossing left edge";
	0.6; 0.6; 0.9; 0.4; 1; 0; "2D line crossing right edge";
	0.6; 0.6; 0.7; 0.9; 1; 0; "2D line crossing top edge";
	0.6; 0.6; 0.5; 0.3; 1; 0; "2D line crossing bottom edge";
	0.3; 0.3; 0.8; 0.3; 0; 0; "2D line entirely out";
)
	# pixel validation
	line = IA_2_Ppoint(@x1,@y1,@x2,@y2);
	pl = I_Ppoint_list(2,line);
	ppolyline(&pl);
	testpt1 = I_Ppoint3(@x1,@y1,0.0);
	testpt2 = I_Ppoint3(@x2,@y2,0.0);
	im_confirm_point3(xdisplay,xwindow,1,0,testpt1,@on1,5,1,@text);
	im_confirm_point3(xdisplay,xwindow,1,0,testpt2,@on2,5,1,@text);
	i_pause();

	# remove polyline element from structure
	pdel_elem();
end

# testing 3D case

# set ws transformation, remove polyline element from 2D case 
# draw the polyline that represent the boundary of the ws window 
pset_ws_win3(1,&window3);
pset_ws_vp3(1,&viewport3);
pempty_struct(1);
ppolyline3(&plbox3);

foreach @x1 @y1 @z1 @x2 @y2 @z2 @on1 @on2 @text (
	0.5; 0.5; 0.6; 0.7; 0.7; 0.6; 1; 1; "3D line entirely in";
	0.6; 0.6; 0.6; 0.3; 0.4; 0.6; 1; 0; "3D line crossing left edge";
	0.6; 0.6; 0.6; 0.9; 0.4; 0.6; 1; 0; "3D line crossing right edge";
	0.6; 0.6; 0.6; 0.7; 0.9; 0.6; 1; 0; "3D line crossing top edge";
	0.6; 0.6; 0.6; 0.5; 0.3; 0.6; 1; 0; "3D line crossing bottom edge";
	0.3; 0.3; 0.6; 0.8; 0.3; 0.6; 0; 0; "3D line entirely out";
	0.5; 0.5; 0.1; 0.7; 0.7; 0.6; 0; 1; "3D line crossing front edge";
	0.5; 0.5; 0.6; 0.7; 0.7; 0.9; 1; 0; "3D line crossing back edge";
)

	# pixel validation
	line3 = IA_2_Ppoint3(@x1,@y1,@z1,@x2,@y2,@z2);
	pl3 = I_Ppoint_list3(2,line3);
	ppolyline3(&pl3);
	testpt1 = I_Ppoint3(@x1,@y1,@z1);
	testpt2 = I_Ppoint3(@x2,@y2,@z2);
	im_confirm_point3(xdisplay,xwindow,1,0,testpt1,@on1,5,1,@text);
	im_confirm_point3(xdisplay,xwindow,1,0,testpt2,@on2,5,1,@text);
	i_pause();

	# remove polyline element from structure
	pdel_elem();
end

tendtest();
