
/* $XConsortium: iss3.pi,v 5.2 94/04/17 20:47:17 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.

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


## iss3.pi -  
## Test requirements:
##   Test that incremental spatial search operation works with search filter

source macro.pi
source shmacro.pi

tbegintest("iss3","incremental spatial search - search filter");

# INITIALIZE: data for a polyline, found and paths expected paths, normal and
#             inverted filters, reference point, and namesets
pts = IA_Ppoint(2, 0.3,0.5, 0.7,0.5);
pl = I_Ppoint_list(2,pts);
refpt = I_Ppoint(0.5,0.5);
buf = malloc(128);

er01 = I_Pelem_ref(0,1);
startexecref = IA_Pelem_ref(1, er01);
startpath = I_Pelem_ref_list(1,startexecref);
foundpath = I_Pelem_ref_list(0,buf);

er03 = I_Pelem_ref(0,3);
er07 = I_Pelem_ref(0,7);
er011 = I_Pelem_ref(0,11);
expexecref1 = IA_Pelem_ref(1, er03);
expexecref2 = IA_Pelem_ref(1, er07);
expexecref3 = IA_Pelem_ref(1, er011);
exppath1 = I_Pelem_ref_list(1, expexecref1);
exppath2 = I_Pelem_ref_list(1, expexecref2);
exppath3 = I_Pelem_ref_list(1, expexecref3);
exppath4 = I_Pelem_ref_list(0, NULL);

ia0 = IA_Pint(1,0);
ia1 = IA_Pint(1,1);
ia2 = IA_Pint(1,2);
ia3 = IA_Pint(1,3);
ia4 = IA_Pint(1,4);
ia5 = IA_Pint(1,5);
ia04 = IA_Pint(2, 0,4);
ia12 = IA_Pint(2, 1,2);

ilst0 = I_Pint_list(1,ia0);
ilst1 = I_Pint_list(1,ia1);
ilst2 = I_Pint_list(1,ia2);
ilst3 = I_Pint_list(1,ia3);
ilst4 = I_Pint_list(1,ia4);
ilst5 = I_Pint_list(1,ia5);

filt1 = I_Pfilter(ilst0,ilst1);
filt2 = I_Pfilter(ilst4,ilst5);
filt3 = I_Pfilter(ilst2,ilst3);
normarr = IA_Pfilter(2,filt1,filt2);
normfilter = I_Pfilter_list(2,normarr);
invarr = IA_Pfilter(1,filt3);
invfilter = I_Pfilter_list(1,invarr);

nset04 = I_Pint_list(2, ia04);
nset12 = I_Pint_list(2, ia12);
nset1 = I_Pint_list(1, ia1);
nset2 = I_Pint_list(1, ia2);
nset3 = I_Pint_list(1, ia3);
nset5 = I_Pint_list(1, ia5);

# SETUP: open phigs, set up structure such that the current name set
#        contains different values during structure traversal

i_open_phigs(NULL,0);
popen_struct(0);
# name set = (), polyline at position 1
	ppolyline(&pl);
	padd_names_set(&nset04);
# name set = (0,4), polyline at position 3
	ppolyline(&pl);
	padd_names_set(&nset2);
# name set = (0,2,4), polyline at position 5
	ppolyline(&pl);
	padd_names_set(&nset3);
# name set = (0,2,3,4), polyline at position 7
	ppolyline(&pl);
	padd_names_set(&nset1);
# name set = (0,1,2,3,4), polyline at position 9
	ppolyline(&pl);
	premove_names_set(&nset12);
# name set = (0,3,4), polyline at position 11
	ppolyline(&pl);
	padd_names_set(&nset5);
# name set = (0,3,4,5), polyline at position 13
	ppolyline(&pl);
pclose_struct();

#OPERATIONS and VERIFICATIONS
#  . iss with a reference point and distance such that the primitive always 
#    	lies withing the search space
#  . iss without a ceiling (ceiling = 1)
#  . The search normal filter list contains two filters:  
#    	normal filter 1: included - (0), excluded (1)
#    	normal filter 2: included - (4), excluded (5)
#  . The search normal filter list contains one filter:  
#    	inverted filter 1: included - (2), excluded (3)
#
#  The current name set has been set up in such a way that only the
#  polyline primtive at element position 3,7,11 can be searched sucessfully.


# start path=(0,1) expected found path = (0,3)

err = i_bogus_error();
pincr_spa_search(&refpt,0.0,&startpath,PIND_NO_CLIP,1,&normfilter,&invfilter,
	128,0,&err,&foundpath,&total_len);
	im_ifneq(err,0,"ERROR: %d in pincr_spa_search\n",err);
im_confirm_isspath(foundpath,exppath1,
	"failed: found path != expected for start path = (0,1)\n");

# start path=(0,3) expected found path = (0,7)
pincr_spa_search(&refpt,0.0,&exppath1,PIND_NO_CLIP,1,&normfilter,&invfilter,
	128,0,&err,&foundpath,&total_len);
	im_ifneq(err,0,"ERROR: %d in pincr_spa_search\n",err);
im_confirm_isspath(foundpath,exppath2,
	"failed: found path != expected for start path = (0,3)\n");

# start path=(0,7) expected found path = (0,11)
pincr_spa_search(&refpt,0.0,&exppath2,PIND_NO_CLIP,1,&normfilter,&invfilter,
	128,0,&err,&foundpath,&total_len);
	im_ifneq(err,0,"ERROR: %d in pincr_spa_search\n",err);
im_confirm_isspath(foundpath,exppath3,
	"failed: found path != expected for start path = (0,7)\n");

# start path=(0,11) expected found path = NULL
pincr_spa_search(&refpt,0.0,&exppath3,PIND_NO_CLIP,1,&normfilter,&invfilter,
	128,0,&err,&foundpath,&total_len);
	im_ifneq(err,0,"ERROR: %d in pincr_spa_search\n",err);
im_confirm_isspath(foundpath,exppath4,
	"failed: found path != expected for start path = (0,11)\n");

tendtest();
