summaryrefslogtreecommitdiff
path: root/src/Xw/Xw_get_marker_index.cxx
blob: d57d4867bf507a932e84569d485bfe6a1074f7d3 (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

#include <Xw_Extension.h>

	/* ifdef then trace on */
#ifdef TRACE
#define TRACE_GET_MARKER_INDEX
#endif

/*
   XW_STATUS Xw_get_marker_index(amarkmap,length,spoint,xpoint,ypoint,index):

   XW_EXT_MARKMAP *amarkmap	Markmap extension structure
   int length ;		Style Descriptor length
   int *spoint;		Marker status point vector
   float *xpoint;	Marker x coordinate vector
   float *ypoint;	Marker y coordinate vector
   int *index ;		Return Marker index 0 >= x < MAXMARKER

	Gets the nearest marker index from Style Descriptor values.

	Returns XW_ERROR if BadMarker Index or marker is not defined
	Returns XW_SUCCESS if Successful

*/

#ifdef XW_PROTOTYPE
XW_STATUS Xw_get_marker_index(void *amarkmap,int length,
			int *spoint, float *xpoint, float *ypoint, int *index)
#else
XW_STATUS Xw_get_marker_index(amarkmap,length,spoint,xpoint,ypoint,index)
void *amarkmap ;
int length ;
int *spoint;
float *xpoint;
float *ypoint;
int *index ;
#endif /*XW_PROTOTYPE*/
{
XW_EXT_MARKMAP *pmarkmap = (XW_EXT_MARKMAP*) amarkmap ;
XW_STATUS status = XW_ERROR ;
int i,j,k,l ;

    if( !pmarkmap ) {
	/*ERROR*Bad EXT_MARKMAP Address*/
	Xw_set_error( 46,"Xw_get_marker_index",pmarkmap ) ;
	return( XW_ERROR ) ;
    }

    if( length > 0 ) {
        for( i=k=0 ; i<pmarkmap->maxmarker ; i++ ) {
	    l = pmarkmap->npoint[i];
	    if( l == length ) {
	      int *s = pmarkmap->spoint[i];
	      float *x = pmarkmap->xpoint[i];
	      float *y = pmarkmap->ypoint[i];
	      for( j=0 ; j<l ; j++,s++,x++,y++ ) {
		if( *s != spoint[j] || 
			*x != xpoint[j] || *y != ypoint[j] ) break;
	      }
	      if( j >= l ) break;
	    } else if( !l && !k ) k = i ;
        }

	if( i<pmarkmap->maxmarker ) {
	    *index = i ;
	    status = XW_SUCCESS ;
	} else {
	    *index = k ;
	    status = Xw_def_marker (pmarkmap,k,length,spoint,xpoint,ypoint) ;
	}
    } else {
	*index = 0 ;
	status = XW_SUCCESS ;
    }

#ifdef TRACE_GET_MARKER_INDEX
if( Xw_get_trace() > 1 ) {
    printf(" %d = Xw_get_marker_index(%lx,%d,%d)\n",
			status,(long ) pmarkmap,length,*index) ;
}
#endif

	return( status ) ;
}