#include "plot.h"
#include <fstream> 

using namespace std;

Plot::Plot() {
    points = {};
    size = 0;
}

Plot::Plot(plot_t _points) {
    points = _points;
    size = points.size();
}

point_t Plot::get(int i){
    return points.at(i);
}

double Plot::get_x(int i){
    return points.at(i).first;
}

double Plot::get_y(int i){
    return points.at(i).second;
}

void Plot::add(point_t point) {
    points.push_back(point);
    size++;
}

void Plot::display(){
    vector<double> x;
    vector<double> y;
    for (point_t pt : points) {
        x.push_back(pt.first);
        y.push_back(pt.second);
    }
}

void Plot::write_in_file(string filename) {
    ofstream outFile(filename);
    if (!outFile) {
        cerr << "Le fichier n'est pas ouvert\n";
    }
    for (point_t point : points) {
        outFile << point.first << " " << point.second;
        outFile << "\n";
    }
    outFile.close();
}

ostream& operator<<(ostream &out, Plot const& plot) {
    for (point_t pt : plot.points) {
        double a = pt.first;
        double b = pt.second;
        out << a << " " << b << "\n";
    }
    return out;
}