]> rtime.felk.cvut.cz Git - hubacji1/bcar.git/commitdiff
Enable plotting same opts in example code
authorJiri Vlasak <hubacji1@fel.cvut.cz>
Thu, 20 Jan 2022 22:17:20 +0000 (23:17 +0100)
committerJiri Vlasak <hubacji1@fel.cvut.cz>
Thu, 20 Jan 2022 22:17:21 +0000 (23:17 +0100)
src/gen_for_gnuplot.cc

index 29731adae96dbdefe58db3df19a05795de426ffc..bc5e6c07db0059384bcf5cd68eecb0dd7ad4efbb 100644 (file)
 #define V v
 #define INIT_V vector<M> V;
 #define P(W) V.push_back(M(#W)); V.back().o.W = true;
+#define LC V.back().c
 
 class M {
 public:
+       static unsigned int cntr;
        std::string fn;
+       std::string fc;
        std::ofstream f;
        bcar::BicycleCar c;
        bcar::BicycleCar::GenPlotOpts o;
@@ -35,12 +38,14 @@ public:
        }
        M(std::string fn) : fn(fn)
        {
-               this->f.open(this->fn);
+               this->fc = std::to_string(this->cntr++);
+               this->f.open(this->fn + this->fc);
                this->o.ALL = false;
        }
        M(M const& m) : fn(m.fn), c(m.c), o(m.o)
        {
-               this->f.open(this->fn);
+               this->fc = std::to_string(this->cntr++);
+               this->f.open(this->fn + this->fc);
        }
        M& operator=(M m)
        {
@@ -53,16 +58,18 @@ public:
                f.f.close();
                t.f.close();
                swap(f.fn, t.fn);
+               swap(f.fc, t.fc);
                swap(f.c, t.c);
                swap(f.o, t.o);
-               f.f.open(f.fn);
-               t.f.open(t.fn);
+               f.f.open(f.fn + f.fc);
+               t.f.open(t.fn + t.fc);
        }
        M(M&& m) noexcept
        {
                swap(*this, m);
        }
 };
+unsigned int M::cntr = 0;
 
 void
 gpl_slot(bcar::ParkingSlot& s, std::string fn = "")
@@ -84,6 +91,7 @@ gen_pl_script(std::vector<M>& ms, std::string with_slot)
        ofstream f;
        f.open("plot.pl");
        f << "#!/usr/bin/gnuplot" << endl;
+       f << "unset key" << endl;
        f << "set size ratio -1" << endl;
        if (with_slot.compare("") != 0) {
                f << "plot '" << with_slot << "' w l,";
@@ -91,7 +99,7 @@ gen_pl_script(std::vector<M>& ms, std::string with_slot)
                f << "plot";
        }
        for (auto& m: ms) {
-               f << " '" << m.fn << "'" << " w l,";
+               f << " '" << (m.fn + m.fc) << "'" << " w l,";
        }
        f << endl;
        f << "pause -1" << endl;
@@ -113,14 +121,12 @@ main()
        s.compute_entries();
 
        INIT_V
-       P(RF_POINT)
-       P(RFM_POINT)
-       P(RRA_POINT)
-       P(RR_POINT)
-
-       for (auto& m: V) {
-               m.c = s._entries.front();
-               m.c.st(m.c.st() * -1.0);
+       for (auto e: s._entries) {
+               P(RRA_POINT)
+               LC = e;
+               LC.st(LC.st() * -1.0);
+               P(RRA_POINT)
+               LC = e;
        }
        for (unsigned int i = 0; i < STEPS; i++) {
                for (auto& m: V) {