]> rtime.felk.cvut.cz Git - hubacji1/bcar.git/blob - src/gen_for_gnuplot.cc
Require compiler version in CMakeLists
[hubacji1/bcar.git] / src / gen_for_gnuplot.cc
1 /*
2  * SPDX-FileCopyrightText: 2021 Jiri Vlasak <jiri.vlasak.2@cvut.cz>
3  *
4  * SPDX-License-Identifier: GPL-3.0-only
5  */
6
7 #include <fstream>
8 #include <iostream>
9 #include <vector>
10 #include "pslot.hh"
11
12 #define SP 0.5
13 #define STEPS 60
14
15 #define V v
16 #define INIT_V vector<M> V;
17 #define P(W) V.push_back(M(#W)); V.back().o.W = true;
18 #define LC V.back().c
19
20 class M {
21 public:
22         static unsigned int cntr;
23         std::string fn;
24         std::string fc;
25         std::ofstream f;
26         bcar::BicycleCar c;
27         bcar::BicycleCar::GenPlotOpts o;
28
29         void gpl()
30         {
31                 this->c.gen_gnuplot_to(this->f, this->o);
32                 this->c.next();
33         }
34
35         ~M()
36         {
37                 this->f.close();
38         }
39         M(std::string fn) : fn(fn)
40         {
41                 this->fc = std::to_string(this->cntr++);
42                 this->f.open(this->fn + this->fc);
43                 this->o.ALL = false;
44         }
45         M(M const& m) : fn(m.fn), c(m.c), o(m.o)
46         {
47                 this->fc = std::to_string(this->cntr++);
48                 this->f.open(this->fn + this->fc);
49         }
50         M& operator=(M m)
51         {
52                 swap(*this, m);
53                 return *this;
54         }
55         friend void swap(M& f, M& t)
56         {
57                 using std::swap;
58                 f.f.close();
59                 t.f.close();
60                 swap(f.fn, t.fn);
61                 swap(f.fc, t.fc);
62                 swap(f.c, t.c);
63                 swap(f.o, t.o);
64                 f.f.open(f.fn + f.fc);
65                 t.f.open(t.fn + t.fc);
66         }
67         M(M&& m) noexcept
68         {
69                 swap(*this, m);
70         }
71 };
72 unsigned int M::cntr = 0;
73
74 void
75 gpl_slot(bcar::ParkingSlot& s, std::string fn = "")
76 {
77         if (fn.compare("") == 0) {
78                 return;
79         }
80         using namespace std;
81         ofstream f;
82         f.open(fn);
83         s.gen_gnuplot_to(f);
84         f.close();
85 }
86
87 void
88 gen_pl_script(std::vector<M>& ms, std::string with_slot)
89 {
90         using namespace std;
91         ofstream f;
92         f.open("plot.pl");
93         f << "#!/usr/bin/gnuplot" << endl;
94         f << "unset key" << endl;
95         f << "set size ratio -1" << endl;
96         if (with_slot.compare("") != 0) {
97                 f << "plot '" << with_slot << "' w l,";
98         } else {
99                 f << "plot";
100         }
101         for (auto& m: ms) {
102                 f << " '" << (m.fn + m.fc) << "'" << " w l,";
103         }
104         f << endl;
105         f << "pause -1" << endl;
106         f.close();
107 }
108
109 int
110 main()
111 {
112         using namespace std;
113         cout << fixed;
114         cerr << fixed;
115
116         bcar::ParkingSlot s(bcar::Point(0, 0), 0, 2.5, 6);
117         string sn("slot");
118         gpl_slot(s, sn);
119
120         s.fe(bcar::BicycleCar());
121         s.compute_entries();
122
123         INIT_V
124         for (auto e: s._entries) {
125                 P(RRA_POINT)
126                 LC = e;
127                 LC.st(LC.st() * -1.0);
128                 P(LRA_POINT)
129                 LC = e;
130         }
131         for (unsigned int i = 0; i < STEPS; i++) {
132                 for (auto& m: V) {
133                         m.gpl();
134                 }
135         }
136         gen_pl_script(V, sn);
137         return 0;
138 }