Fix Linux

../src/libslic3r/NSVGUtils.cpp:162:91: error: call of overloaded ‘to_chars(std::array<char, 128>::pointer, std::array<char, 128>::pointer, float&)’ is ambiguous
This commit is contained in:
Filip Sykala - NTB T15p 2023-09-06 14:46:10 +02:00
parent a4afcc1f4e
commit 40703143dc
2 changed files with 102 additions and 102 deletions

View File

@ -130,106 +130,106 @@ size_t get_shapes_count(const NSVGimage &image)
return count; return count;
} }
void save(const NSVGimage &image, std::ostream &data) //void save(const NSVGimage &image, std::ostream &data)
{ //{
data << "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>"; // data << "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>";
//
// tl .. top left // // tl .. top left
Vec2f tl(std::numeric_limits<float>::max(), std::numeric_limits<float>::max()); // Vec2f tl(std::numeric_limits<float>::max(), std::numeric_limits<float>::max());
// br .. bottom right // // br .. bottom right
Vec2f br(std::numeric_limits<float>::min(), std::numeric_limits<float>::min()); // Vec2f br(std::numeric_limits<float>::min(), std::numeric_limits<float>::min());
bounds(image, tl, br); // bounds(image, tl, br);
//
tl.x() = std::floor(tl.x()); // tl.x() = std::floor(tl.x());
tl.y() = std::floor(tl.y()); // tl.y() = std::floor(tl.y());
//
br.x() = std::ceil(br.x()); // br.x() = std::ceil(br.x());
br.y() = std::ceil(br.y()); // br.y() = std::ceil(br.y());
Vec2f s = br - tl; // Vec2f s = br - tl;
Point size = s.cast<Point::coord_type>(); // Point size = s.cast<Point::coord_type>();
//
data << "<svg xmlns=\"http://www.w3.org/2000/svg\" " // data << "<svg xmlns=\"http://www.w3.org/2000/svg\" "
<< "width=\"" << size.x() << "mm\" " // << "width=\"" << size.x() << "mm\" "
<< "height=\"" << size.y() << "mm\" " // << "height=\"" << size.y() << "mm\" "
<< "viewBox=\"0 0 " << size.x() << " " << size.y() << "\" >\n"; // << "viewBox=\"0 0 " << size.x() << " " << size.y() << "\" >\n";
data << "<!-- Created with PrusaSlicer (https://www.prusa3d.com/prusaslicer/) -->\n"; // data << "<!-- Created with PrusaSlicer (https://www.prusa3d.com/prusaslicer/) -->\n";
//
std::array<char, 128> buffer; // std::array<char, 128> buffer;
auto write_point = [&tl, &buffer](std::string &d, const float *p) { // auto write_point = [&tl, &buffer](std::string &d, const float *p) {
float x = p[0] - tl.x(); // float x = p[0] - tl.x();
float y = p[1] - tl.y(); // float y = p[1] - tl.y();
auto to_string = [&buffer](float f) -> std::string { // auto to_string = [&buffer](float f) -> std::string {
auto [ptr, ec] = std::to_chars(buffer.data(), buffer.data() + buffer.size(), f); // auto [ptr, ec] = std::to_chars(buffer.data(), buffer.data() + buffer.size(), f);
if (ec != std::errc{}) // if (ec != std::errc{})
return "0"; // return "0";
return std::string(buffer.data(), ptr); // return std::string(buffer.data(), ptr);
}; // };
d += to_string(x) + "," + to_string(y) + " "; // d += to_string(x) + "," + to_string(y) + " ";
}; // };
//
for (const NSVGshape *shape = image.shapes; shape != NULL; shape = shape->next) { // for (const NSVGshape *shape = image.shapes; shape != NULL; shape = shape->next) {
enum struct Type { move, line, curve, close }; // https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/d // enum struct Type { move, line, curve, close }; // https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/d
Type type = Type::move; // Type type = Type::move;
std::string d = "M "; // move on start point // std::string d = "M "; // move on start point
for (const NSVGpath *path = shape->paths; path != NULL; path = path->next) { // for (const NSVGpath *path = shape->paths; path != NULL; path = path->next) {
if (path->npts <= 1) // if (path->npts <= 1)
continue; // continue;
//
if (type == Type::close) { // if (type == Type::close) {
Type type = Type::move; // type = Type::move;
// NOTE: After close must be a space // // NOTE: After close must be a space
d += " M "; // move on start point // d += " M "; // move on start point
} // }
write_point(d, path->pts); // write_point(d, path->pts);
size_t path_size = static_cast<size_t>(path->npts - 1); // size_t path_size = static_cast<size_t>(path->npts - 1);
//
if (path->closed) { // if (path->closed) {
// Do not use last point in path it is duplicit // // Do not use last point in path it is duplicit
if (path->npts <= 4) // if (path->npts <= 4)
continue; // continue;
path_size = static_cast<size_t>(path->npts - 4); // path_size = static_cast<size_t>(path->npts - 4);
} // }
//
for (size_t i = 0; i < path_size; i += 3) { // for (size_t i = 0; i < path_size; i += 3) {
const float *p = &path->pts[i * 2]; // const float *p = &path->pts[i * 2];
if (!::is_line(p)) { // if (!::is_line(p)) {
if (type != Type::curve) { // if (type != Type::curve) {
type = Type::curve; // type = Type::curve;
d += "C "; // start sequence of triplets defining curves // d += "C "; // start sequence of triplets defining curves
} // }
write_point(d, &p[2]); // write_point(d, &p[2]);
write_point(d, &p[4]); // write_point(d, &p[4]);
} else { // } else {
//
if (type != Type::line) { // if (type != Type::line) {
type = Type::line; // type = Type::line;
d += "L "; // start sequence of line points // d += "L "; // start sequence of line points
} // }
} // }
write_point(d, &p[6]); // write_point(d, &p[6]);
} // }
if (path->closed) { // if (path->closed) {
type = Type::close; // type = Type::close;
d += "Z"; // start sequence of line points // d += "Z"; // start sequence of line points
} // }
} // }
if (type != Type::close) { // if (type != Type::close) {
//type = Type::close; // //type = Type::close;
d += "Z"; // closed path // d += "Z"; // closed path
} // }
data << "<path fill=\"#D2D2D2\" d=\"" << d << "\" />\n"; // data << "<path fill=\"#D2D2D2\" d=\"" << d << "\" />\n";
} // }
data << "</svg>\n"; // data << "</svg>\n";
} //}
//
bool save(const NSVGimage &image, const std::string &svg_file_path) //bool save(const NSVGimage &image, const std::string &svg_file_path)
{ //{
std::ofstream file{svg_file_path}; // std::ofstream file{svg_file_path};
if (!file.is_open()) // if (!file.is_open())
return false; // return false;
save(image, file); // save(image, file);
return true; // return true;
} //}
} // namespace Slic3r } // namespace Slic3r
namespace { namespace {

View File

@ -79,7 +79,7 @@ NSVGimage_ptr nsvgParse(const std::string& file_data, const char *units = "mm",
/// <returns>Count of shapes</returns> /// <returns>Count of shapes</returns>
size_t get_shapes_count(const NSVGimage &image); size_t get_shapes_count(const NSVGimage &image);
void save(const NSVGimage &image, std::ostream &data); //void save(const NSVGimage &image, std::ostream &data);
bool save(const NSVGimage &image, const std::string &svg_file_path); //bool save(const NSVGimage &image, const std::string &svg_file_path);
} // namespace Slic3r } // namespace Slic3r
#endif // slic3r_NSVGUtils_hpp_ #endif // slic3r_NSVGUtils_hpp_