コード例 #1
0
ファイル: plus_struct.c プロジェクト: GRASS-GIS/grass-ci
int dig_Rd_P_isle(struct Plus_head *Plus, int n, struct gvfile * fp)
{
    int cnt;
    struct P_isle *ptr;

    G_debug(4, "dig_Rd_P_isle()");

    if (0 >= dig__fread_port_P(&cnt, 1, fp))
	return (-1);

    if (cnt == 0) {		/* dead */
	Plus->Isle[n] = NULL;
	return 0;
    }

    ptr = dig_alloc_isle();

    /* boundaries */
    ptr->n_lines = cnt;

    if (dig_isle_alloc_line(ptr, ptr->n_lines) == -1)
	return -1;

    if (ptr->n_lines)
	if (0 >= dig__fread_port_P(ptr->lines, ptr->n_lines, fp))
	    return -1;

    /* area */
    if (0 >= dig__fread_port_P(&(ptr->area), 1, fp))
	return -1;

    Plus->Isle[n] = ptr;

    return (0);
}
コード例 #2
0
ファイル: plus_area.c プロジェクト: AsherBond/MondocosmOS
/*!
 * \brief Allocate space for new island and create boundary info from array.
 *
 * The order of input lines is expected to be counter clockwise.
 * Then for each line in isle, update line (right,left) info.
 *
 *  Area number the island is within is not filled.
 *
 * \param[in] plus pointer to Plus_head structure
 * \param[in] n_lines number of lines
 * \param[in] lines array of lines, negative for reverse direction 
 *
 * \return number of new isle
 * \return -1 on error
 */
int dig_add_isle(struct Plus_head *plus, int n_lines, plus_t * lines,
		 struct bound_box *box)
{
    register int i;
    register int isle, line;
    struct P_isle *Isle;
    struct P_line *Line;
    struct P_topo_b *topo;

    G_debug(3, "dig_add_isle():");
    /* First look if we have space in array of pointers to isles
     *  and reallocate if necessary */
    if (plus->n_isles >= plus->alloc_isles) {	/* array is full */
	if (dig_alloc_isles(plus, 1000) == -1)
	    return -1;
    }

    /* allocate isle structure */
    isle = plus->n_isles + 1;
    Isle = dig_alloc_isle();
    if (Isle == NULL)
	return -1;

    if ((dig_isle_alloc_line(Isle, n_lines)) == -1)
	return -1;

    Isle->area = 0;

    for (i = 0; i < n_lines; i++) {
	line = lines[i];
	G_debug(3, " i = %d line = %d", i, line);
	Isle->lines[i] = line;
	Line = plus->Line[abs(line)];
	topo = (struct P_topo_b *)Line->topo;
	if (plus->do_uplist)
	    dig_line_add_updated(plus, abs(line));
	if (line < 0) {		/* revers direction -> isle on left */
	    if (topo->left != 0) {
		G_warning(_("Line %d already has area/isle %d to left"), line,
			  topo->left);
		return -1;
	    }
	    topo->left = -isle;
	}
	else {
	    if (topo->right != 0) {
		G_warning(_("Line %d already has area/isle %d to left"), line,
			  topo->right);
		return -1;
	    }

	    topo->right = -isle;
	}
    }

    Isle->n_lines = n_lines;

    plus->Isle[isle] = Isle;

    dig_spidx_add_isle(plus, isle, box);

    plus->n_isles++;

    return (isle);
}