Example #1
0
File: parse.c Project: Remaii/FdF
void		parsemap(t_mlx *fdf, int fd)
{
	int		i;
	int		j;
	t_list	*pts;
	char	*line;
	char	**lines;

	i = 0;
	while (get_next_line(fd, &line))
	{
		lines = ft_strsplit(line, ' ');
		j = 0;
		while (lines[j] != NULL)
		{
			ft_lstadd(&pts, ft_lstnew(n_pts(j, i, ft_atoi(lines[j])),\
													sizeof(t_pts)));
			j++;
		}
		i++;
	}
	fdf->x = j;
	fdf->y = i;
	lst_map(pts, fdf, j, i);
}
Example #2
0
int RangeNode::SubtractRange(RangeNode *sub) {
    // Try to subtract an entire range
    if (sub->n_pts() == 1) {
	return SubtractVal(sub->start);
    } else if ( (sub->start < start && sub->end < start) \
		|| (sub->start > end && sub->end > end) ) {
	// No overlap, just ignore
    } else if (step == sub->step || step == -sub->step) {
	// steps are synchronized.  Only effect if same phase
	if ( (start%step) == (sub->start % step) ) {
	    int start_index = (sub->start - start)/step;
	    int end_index = (sub->end - start)/step;
	    if (end_index < start_index) { 
		int t = start_index; start_index = end_index; end_index = t;
	    }
	    if (start_index <= 0 && end_index >= ((int)n_pts())-1) {
		// everything wiped out - make n_pts() == 0
		end = start - step;
	    } else if ( start_index > 0 && end_index < ((int)n_pts())-1) {
		// fully-included range - have to split list
		next = new RangeNode(next, start+step*(end_index+1), end,step);
		end = start+step*(start_index - 1);
	    } else if ( start_index > 0) {
		// just an initial sublist
		end = start+step*(start_index - 1);
	    } else {
		assert(end_index < ((int)n_pts())-1);
		start += step*(end_index+1);
	    }
	}
	// else nothing
    } else {
	// The overlap and they have different steps - do it 
	// point by point
	int i;
	for (i = sub->start; i <= sub->end; i += sub->step) {
	    SubtractVal(i);
	}
    }
    return (n_pts() > 0);
}
Example #3
0
int RangeNode::SubtractVal(int val) {
    // Knock out one value from this node, which may involve splitting
    // it into two nodes, which will be silently inserted into the list.
    fixup_end();
    if ( !(val < start || val > end || ((val-start)%step) != 0)) {
	if (val == start) {
	    start += step;
	} else if (val == end) {
	    end -= step;
	} else {
	    // Need to split the list
	    next = new RangeNode(next, val + step, end, step);
	    end = val - step;
	}
    }
    return (n_pts() > 0);
}