Mapper
macbu.c
Go to the documentation of this file.
1 
2 #define X 0
3 #define Y 1
4 
5 /* shoot a test ray along +X axis - macmartinized by me, a bit messier */
7 double pgon[50000][2] ;
8 int numverts ;
9 double point[2] ;
10 {
11 int inside_flag, xflag0 ;
12 double *p, *stop ;
13 int crossings ;
14 double tx, ty, y ;
15 
16  crossings = 0 ;
17 
18  tx = point[X] ;
19  ty = point[Y] ;
20  y = pgon[numverts-1][Y] ;
21 
22  p = (double *)pgon + 1 ;
23  if ( ( y >= ty ) != ( *p >= ty ) ) {
24  /* x crossing */
25  if ( ( xflag0 = ( pgon[numverts-1][X] >= tx ) ) ==
26  ( *(double *)pgon >= tx ) ) {
27 
28  if ( xflag0 ) crossings++ ;
29  } else {
30  /* compute intersection of pgon segment with X ray, note
31  * if > point's X.
32  */
33  crossings += ( pgon[numverts-1][X] -
34  (y-ty)*( *(double *)pgon - pgon[numverts-1][X])/(*p-y)) >= tx ;
35  }
36  }
37 
38  stop = pgon[numverts] ;
39 
40  for ( y=*p,p += 2 ; p < stop ; y=*p,p+=2) {
41 
42  if ( y >= ty ) {
43  while ( (p < stop) && (*p >= ty) ) p+=2 ;
44  if ( p >= stop ) goto Exit ;
45  /* y crosses */
46  if ( ( xflag0 = ( *(p-3) >= tx ) ) ==
47  ( *(p-1) >= tx ) ) {
48 
49  if ( xflag0 ) crossings++ ;
50  } else {
51  /* compute intersection of pgon segment with X ray, note
52  * if > point's X.
53  */
54  crossings += ( *(p-3) -
55  (*(p-2)-ty)*( *(p-1)-*(p-3))/(*p-*(p-2))) >= tx ;
56  }
57  } else {
58  while ( (p < stop) && (*p < ty)) p+=2 ;
59  if ( p >= stop ) goto Exit ;
60  /* y crosses */
61  if ( ( xflag0 = ( *(p-3) >= tx ) ) ==
62  ( *(p-1) >= tx ) ) {
63 
64  if ( xflag0 ) crossings++ ;
65  } else {
66  /* compute intersection of pgon segment with X ray, note
67  * if > point's X.
68  */
69  crossings += ( *(p-3) -
70  (*(p-2)-ty)*( *(p-1)-*(p-3))/(*p-*(p-2))) >= tx ;
71  }
72  }
73  }
74 
75  Exit:
76  /* test if crossings is odd */
77  /* if we care about is winding number > 0, then just:
78  inside_flag = crossings > 0 ;
79  */
80  inside_flag = crossings & 0x01 ;
81 
82  return (inside_flag) ;
83 }
double pgon[5000][2]
Definition: build_hrap.c:5
#define X
Definition: macbu.c:2
#define Y
Definition: macbu.c:3
int macmartintest(pgon, numverts, point)
Definition: macbu.c:6
int numverts
Definition: mapper.c:91
Definition: mapp2h.h:29