#include <iostream>
#include <fstream>
#include <string>
#include <filesystem>
#include <cmath>
namespace TMU{

using namespace std;
string str(double x){
    return to_string(x);
};
string str(int x){
    return to_string(x);
};
struct R2{
    double x;
    double y;
    R2(double x_, double y_){
        x = x_; y = y_;
    }
    R2(){x = 0; y = 0;}
    double len(){
        return std::sqrt(x*x + y*y);
    }
};
inline R2 operator+(R2 a, R2 b){ // better to write inline for functions in header file
    R2 r;
    r.x = a.x + b.x;
    r.y = a.y + b.y;
    return r;
}

inline R2 operator-(R2 a, R2 b){
    R2 r;
    r.x = a.x - b.x;
    r.y = a.y - b.y;
    return r;
}
inline R2 operator*(double a, R2 b){
    R2 r;
    r.x = a*b.x;
    r.y = a*b.y;
    return r;
}
struct SVGGraph{
    double vx0, vy0, H, W;
    double scale;
    double r;
  	string s;
    SVGGraph(){
        scale = 210; // firefox が小数点以下の座標をうまく表示しないため座標を大きく引き延ばすための値
        vx0 = -1.2; vy0 = -1.2; W= 2.4; H= 2.4; r=0.1;
        s = "";

    }
    void setPointSize(double r_){
        r = r_;
    }
	void circle(R2 p, double c=0){
        s += "<circle r='" + str(r*scale) + "' cx='" +str(p.x*scale) + "' cy='"+str(-p.y*scale) + "' fill='rgb(" +str(c * 255) + ", 0,0)' />\n";	
	}
    void drawVAxis(string title){
        s += "<text style='font-size:" + str(0.05*scale) + ";'  transform='translate(" + str(-1.1*scale) + ", 0) rotate(-90)'>"+title + "</text>\n";
        s += "<line x1='" + str(-1*scale) + "' y1='"+str(1*scale) + "' x2='" + str(-1*scale)+"' y2='" + str(-1*scale)+ "' style='stroke:rgb(0,0,0);stroke-width:"+ str(0.01*scale) + "' />\n";
        for(double y = int(vy0);y<vy0+H;y+=0.2){    
            s += "<line x1='" + str(-1*scale) + "' y1='"+str(-y*scale) + "' x2='" + str(1*scale)+"' y2='" + str(-y*scale)+ "' style='stroke:rgb(200,200,200);stroke-width:"+ str(0.002*scale) + "' />\n";
        }
    }
    void drawHAxis(string title){
        s += "<text style='font-size:" + str(0.05*scale) + ";'  transform='translate( 0, " + str(1.1*scale) + ") rotate(0)'>"+title + "</text>";
        s += "<line x1='" + str(-1*scale) + "' y1='"+str(1*scale) + "' x2='" + str(1*scale)+"' y2='" + str(1*scale)+ "' style='stroke:rgb(0,0,0);stroke-width:"+ str(0.01*scale) + "' />\n";
        for(double x = int(vx0);x<vx0+W;x+=0.2){    
            s += "<line x1='" + str(-x*scale) + "' y1='"+str(-1*scale) + "' x2='" + str(-x*scale)+"' y2='" + str(1*scale)+ "' style='stroke:rgb(200,200,200);stroke-width:"+ str(0.002*scale) + "' />\n";
            std::ostringstream oss;
            oss << std::fixed << std::setprecision(1) << x; 
            std::string ts = oss.str(); 
            s += "<text style='font-size:" + str(0.04*scale) + ";'  transform='translate("+str((x-0.04)*scale)+ " , " + str(1.04*scale) + ") rotate(0)'>"+ts+ "</text>\n";
        }
    }

	string serialize(){
        string r = "<svg xmlns='http://www.w3.org/2000/svg' viewBox='"+to_string(vx0*scale)+" " + to_string(vy0*scale) + " " + to_string(W*scale) + " " + to_string(H*scale) + "'>\n";
        r = r + s + "</svg>\n";
        return r;
	}
};


}
