package projet_freyja.math;

import java.io.Serializable;

public class ApplicationLineaire implements Serializable{
    //Attributs
    protected String libelle;
    protected EspaceVectoriel depart;
    protected EspaceVectoriel arrivee;
    protected Vecteur[] matAssociee;
    
    //Methode
    //****Constructeurs****
    
    public ApplicationLineaire(){
        this.libelle = "";
        this.depart = new EspaceVectoriel();
        this.arrivee = new EspaceVectoriel();
        this.matAssociee = null;
    }
    
    public ApplicationLineaire(String l, EspaceVectoriel d, EspaceVectoriel a, Vecteur[] mat){
        this.libelle = l;
        this.depart = d;
        this.arrivee = a;
        this.matAssociee = mat;
    }
    
    //****Setter&Getter****
    
    public void setLibelle(String l) {
        this.libelle = l;
    }

    public void setDepart(EspaceVectoriel d) {
        this.depart = d;
    }

    public void setArrivee(EspaceVectoriel a) {
        this.arrivee = a;
    }
    
    public void setMatriceAssociee(Vecteur[] mat){
        this.matAssociee = mat;
    }

    public String getLibelle() {
        return libelle;
    }

    public EspaceVectoriel getDepart() {
        return depart;
    }

    public EspaceVectoriel getArrivee() {
        return arrivee;
    }
    
    public Vecteur[] getMatriceAssociee(){
        return matAssociee;
    }
    
    //****toString****
    
    @Override
    public String toString() {
        return "ApplicationLineaire{" + "libelle=" + libelle + ", depart=" + depart.toString() + ", arrivee=" + arrivee.toString() + '}';
    }
    
    public String matToString(){
        String res = "";
        for(int i = 0; i < matAssociee[0].getValeurs().length; i++){
            for(int j = 0; j < matAssociee.length; j++){
                if(j == 0){
                    res += matAssociee[j].getElement(i);
                }
                else{
                    res += "    "+matAssociee[j].getElement(i);
                }
            }
            res += "\n";
        }
        return res;
    }
    
    //****Autres méthodes****
    
    public int calculerRang(){
        return 0; 
    }
    
    public Vecteur calculerImage(Vecteur v){
        double retenue = 0; 
        String[] coeffRes = new String[v.getValeurs().length];
        Vecteur res = new Vecteur("Res", coeffRes); 
        for(int i = 0; i < matAssociee[0].getValeurs().length; i++){
            for(int j = 0; j < matAssociee.length; j++){
                retenue += Double.parseDouble(matAssociee[j].getElement(i))*Double.parseDouble(v.getElement(j));
                res.setElement(i, Double.toString(retenue)); 
            }
            retenue = 0;
        }
        res.toString();
        return res;
    }
}
