# An Efficient Flood Visit Algorithm

August 1994/An Efficient Flood Visit Algorithm/Listing 1

#### Listing 1 An algorithm which prevents a child's shadow from falling on its parent line

```/*****************************************************
* UFLOOD.C - unoptimized flood visit
*
* for ANSI C
*
* by Anton Treuenfels
* last revision:  04/12/94
****************************************************/

/*****************************
* HEADER SECTION - UFLOOD.H *
****************************/

#ifndef SEEN_UFLOOD
#define SEEN_UFLOOD

/* function prototype */

int uflood(int, int, int (*)(int. int));

#endif

/***************************
* CODE SECTION - UFLOOD.C *
**************************/

#include <stdlib.h>

#include "usrdef.h"

typedef struct shdw {
struct shdw *next;  /* forward link */
int lft, rgt;       /* endpoints */
int row, par;       /* row and parent row */
Boolean ok;         /* valid flag */

/* visit coordinate function */

static int (*isInterior)(int, int);

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

static void newshadow(int slft, int srgt, int srow, int prow) {

if ((new = malloc(sizeof(shadow))) == NULL)
exit(EXIT_FAILURE);

new->lft = slft;    new->rgt = srgt;
new->row = srow;    new->par = prow;
new->ok = TRUE;
}

/* clip off ends of overlapped shadow */

if (s->lft < (clip->lft - 1))
newshadow(s->lft, clip->lft - 2, s->row, s->par);
if (s->rgt > (clip->rgt + 1))
newshadow(clip->rgt + 2, s->rgt, s->row, s->par);
}

/* remove overlapped segment from shadow pair */

if ((s->row == o->par) && (s->ok) &&
(s->lft <= o->rgt) && (s->rgt >= o->lft)) {
s->ok= o->ok = FALSE;
return;
}
}
}

/* make shadows of one child line */

static void makeshadows(int lft, int rgt, int row) {

newshadow(lft, rgt, row + 1, row);
newshadow(lft, rgt, row - 1, row);

if ((p->row == row) && (p->ok) &&
!((p->lft > rgt) || (p->rgt < lft)))
removeoverlap(p);
}
}

/* fill all child lines found within one shadow */

int col, row, lft;

col++) {
if ((*isInterior)(col, row)) {
if ((lft = col) == seedShadow->lft) {
while ((*isInterior)(--lft, row))
;
lft++;
}
while ((*isInterior)(++col, row))
;

}
}
}

/* flood visit */

int uflood(int seedx, int seedy, int (*visit)(int, int)) {

isInterior = visit;
}
}

/* End of File
```

### More Insights

 To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.