package biduledres;

import java.util.*;

public class UsinePolyedre {
    public static Polyedre getNieme(Polyedre polyedre0, int n) {
        Polyedre p = polyedre0;
        for(int i = 0; i < n; i++) {
            System.out.println("[" + i  + "]  " + p.getNombres());
            p = getSuivant(p);
        }
        return p;
    }
        
    public static Polyedre getSuivant(Polyedre polyedre) {
        Iterator iFaces = polyedre.getListeFace().iterator();
        Iterator iSommets = polyedre.getListeSommet().iterator();
        
        ListeFace newListeFace = new ListeFace();
        
        while(iFaces.hasNext())
            newListeFace.add(getSousFace((Face) iFaces.next()));
        
        while(iSommets.hasNext())
            newListeFace.add(getSousFace(polyedre, (Sommet) iSommets.next()));
        
        return new Polyedre(newListeFace);
    }
        
    public static Face getSousFace(Face f) {
        ListeArete listeAretes = f.getListeArete();
        ListeSommet nouveauxSommets = new ListeSommet();
        Iterator i = listeAretes.iterator();
        while(i.hasNext())
            nouveauxSommets.add(((Arete) i.next()).getMilieu());
        return new Face(nouveauxSommets);
    }
    
    public static Face getSousFace(Polyedre polyedre, Sommet sommet) {
        Face retour = new Face();
        Iterator i = polyedre.getListeArete(sommet).iterator();
        // calcule la face médiane
        while(i.hasNext()) retour.add(((Arete) i.next()).getMilieu());
        return retour;
    }
}