ft_put_arcw.c 2.34 KB
Newer Older
Raphael's avatar
Raphael committed
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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   ft_put_arcw.c                                      :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: gmoindro <marvin@42.fr>                    +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2019/12/02 18:37:32 by gmoindro          #+#    #+#             */
/*   Updated: 2019/12/02 18:47:52 by gmoindro         ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include "lem_in.h"

static void	ft_put_arcw_init(t_node *end)
{
	t_list	*tmp;
	t_node	*node;

	tmp = end->father;
	end->passed_flag = 2;
	while (tmp)
	{
		node = (t_node *)tmp->content;
		node->passed_flag = 2;
		tmp = node->father;
	}
}

static void	ft_put_arcw_flag_start(t_list **list)
{
	t_list	*tmp;
	t_node	*node;
	t_node	*start;

	start = ft_find_t_node_with_start(list);
	tmp = start->next;
	start->passed_flag = 3;
	while (tmp)
	{
		node = (t_node *)tmp->content;
		if (node->passed_flag == 2 && tmp->arcw <= 0)
		{
			node->passed_flag = 3;
			if (tmp->arcw == -1)
				tmp->arcw = 0;
			else
				tmp->arcw = 1;
			tmp = node->next;
		}
		else
			tmp = tmp->next;
	}
}

static void	ft_put_arcw_end(t_node *end, t_list **list)
{
	ft_put_arcw_init(end);
	ft_put_arcw_flag_start(list);
	end->passed_flag = 0;
}

void		ft_put_arcw(t_node *end, t_list **list)
{
	t_list	*tmp;
	t_node	*node;

	tmp = end->next;
	ft_put_arcw_end(end, list);
	while (tmp)
	{
		node = (t_node *)tmp->content;
		if (node->passed_flag == 3 && tmp->arcw >= 0)
		{
			node->passed_flag = 0;
			if (tmp->arcw == 1)
				ft_test_voisin(node, tmp);
			else
			{
				tmp->arcw = -1;
				node->passed_flag = 5;
			}
			tmp = node->next;
		}
		else
			tmp = tmp->next;
	}
}

void		ft_test_voisin(t_node *node, t_list *tmp)
{
	int		count;

	count = 0;
	tmp->arcw = 0;
	tmp = node->next;
	while (tmp)
	{
		if (tmp->arcw == 1)
			count++;
		tmp = tmp->next;
	}
	if (count < 1)
		node->passed_flag = 0;
	else
		node->passed_flag = 5;
}