139 const std::string & note =
"")
143 std::filesystem::create_directories(out_dir, ec);
145 const std::filesystem::path out_file =
148 std::ofstream
out(out_file);
161 for (
size_t i = 0; i < all_points.
size(); ++i)
163 const double x = all_points(i).get_x().get_d();
164 const double y = all_points(i).get_y().get_d();
173 xmin = std::min(xmin, x);
174 xmax = std::max(xmax, x);
175 ymin = std::min(ymin,
y);
176 ymax = std::max(ymax,
y);
186 double dx = xmax - xmin;
187 double dy = ymax - ymin;
201 double pad = std::max(dx, dy) * 0.08;
211 constexpr double width = 960.0;
212 constexpr double height = 720.0;
213 constexpr double margin = 32.0;
214 constexpr double drawable_w = width - 2.0 * margin;
215 constexpr double drawable_h = height - 2.0 * margin;
216 const double scale = std::min(drawable_w / dx, drawable_h / dy);
217 const double xoff = margin + (drawable_w - scale * dx) * 0.5;
218 const double yoff = margin + (drawable_h - scale * dy) * 0.5;
220 const auto map_point = [=](const ::Point & p)
222 const double x = xoff + (p.get_x().get_d() - xmin) * scale;
223 const double y = height - (yoff + (p.get_y().get_d() - ymin) * scale);
224 return std::pair<double, double>{x,
y};
227 out <<
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
228 out <<
"<svg xmlns=\"http://www.w3.org/2000/svg\" "
229 <<
"width=\"" <<
static_cast<int>(width) <<
"\" "
230 <<
"height=\"" <<
static_cast<int>(height) <<
"\" "
231 <<
"viewBox=\"0 0 " <<
static_cast<int>(width) <<
" "
232 <<
static_cast<int>(height) <<
"\">\n";
233 out <<
" <rect x=\"0\" y=\"0\" width=\"" <<
static_cast<int>(width)
234 <<
"\" height=\"" <<
static_cast<int>(height)
235 <<
"\" fill=\"#ffffff\"/>\n";
236 out <<
" <rect x=\"1\" y=\"1\" width=\"" <<
static_cast<int>(width - 2)
237 <<
"\" height=\"" <<
static_cast<int>(height - 2)
238 <<
"\" fill=\"none\" stroke=\"#e5e7eb\" stroke-width=\"2\"/>\n";
240 if (not note.empty())
241 out <<
" <text x=\"16\" y=\"22\" font-size=\"14\" "
242 <<
"font-family=\"monospace\" fill=\"#111827\">"
245 static constexpr std::array<const char *, 8> stroke_colors = {
246 "#2563eb",
"#16a34a",
"#ea580c",
"#7c3aed",
247 "#0f766e",
"#b91c1c",
"#1d4ed8",
"#0369a1"
249 static constexpr std::array<const char *, 8> fill_colors = {
250 "#bfdbfe",
"#bbf7d0",
"#fed7aa",
"#ddd6fe",
251 "#99f6e4",
"#fecaca",
"#c7d2fe",
"#bae6fd"
254 out << std::fixed << std::setprecision(3);
258 const ::Polygon & poly = scene.
polygons(pi);
259 if (poly.size() == 0)
261 std::ostringstream pts_stream;
265 const auto [x,
y] = map_point(it.get_current_vertex());
268 pts_stream << x <<
',' <<
y;
275 const char * stroke = stroke_colors[pi % stroke_colors.size()];
276 const char *
fill = fill_colors[pi % fill_colors.size()];
277 if (poly.is_closed()
and count >= 3)
278 out <<
" <polygon points=\"" << pts_stream.str()
279 <<
"\" fill=\"" <<
fill
280 <<
"\" fill-opacity=\"0.22\" stroke=\"" << stroke
281 <<
"\" stroke-width=\"2\"/>\n";
283 out <<
" <polyline points=\"" << pts_stream.str()
284 <<
"\" fill=\"none\" stroke=\"" << stroke
285 <<
"\" stroke-width=\"2\"/>\n";
289 const auto [vx, vy] = map_point(it.get_current_vertex());
290 out <<
" <circle cx=\"" << vx <<
"\" cy=\"" << vy
291 <<
"\" r=\"3.0\" fill=\"" << stroke
292 <<
"\" stroke=\"#ffffff\" stroke-width=\"1\"/>\n";
298 const ::Segment & seg = scene.
segments(si);
299 const auto [x1,
y1] = map_point(seg.get_src_point());
300 const auto [x2, y2] = map_point(seg.get_tgt_point());
301 out <<
" <line x1=\"" << x1 <<
"\" y1=\"" <<
y1
302 <<
"\" x2=\"" << x2 <<
"\" y2=\"" << y2
303 <<
"\" stroke=\"#4b5563\" stroke-width=\"2.0\"/>\n";
306 for (
size_t i = 0; i < scene.
points.
size(); ++i)
308 const auto [x,
y] = map_point(scene.
points(i));
309 out <<
" <circle cx=\"" << x <<
"\" cy=\"" <<
y
310 <<
"\" r=\"3.2\" fill=\"#111827\" stroke=\"#ffffff\" "
311 <<
"stroke-width=\"0.9\"/>\n";
317 out <<
" <circle cx=\"" << x <<
"\" cy=\"" <<
y
318 <<
"\" r=\"4.3\" fill=\"#dc2626\" stroke=\"#ffffff\" "
319 <<
"stroke-width=\"1.2\"/>\n";
322 out <<
" <text x=\"16\" y=\"" <<
static_cast<int>(height - 14)
323 <<
"\" font-size=\"12\" font-family=\"monospace\" fill=\"#4b5563\">"