From e1e4f34f0ac427b032a96c521f225f2466a5190c Mon Sep 17 00:00:00 2001 From: supermerill Date: Mon, 30 Aug 2021 10:26:00 +0200 Subject: [PATCH] remove some warnings change some scale/unscale for better types. --- src/libslic3r/Arrange.cpp | 6 +- src/libslic3r/BoundingBox.cpp | 6 +- src/libslic3r/BoundingBox.hpp | 2 +- src/libslic3r/ClipperUtils.cpp | 2 +- src/libslic3r/EdgeGrid.cpp | 22 +++--- src/libslic3r/EdgeGrid.hpp | 12 ++-- src/libslic3r/ElephantFootCompensation.cpp | 14 ++-- src/libslic3r/ExPolygon.hpp | 22 +++--- src/libslic3r/Extruder.cpp | 4 +- src/libslic3r/ExtrusionEntity.hpp | 2 +- src/libslic3r/Fill/FillAdaptive.cpp | 8 +-- src/libslic3r/Fill/FillBase.cpp | 8 +-- src/libslic3r/Fill/FillConcentric.cpp | 4 +- src/libslic3r/Fill/FillGyroid.cpp | 2 +- src/libslic3r/Fill/FillLine.cpp | 2 +- src/libslic3r/Fill/FillRectilinear.cpp | 30 ++++---- src/libslic3r/GCode.cpp | 42 +++++------ src/libslic3r/GCode/GCodeProcessor.cpp | 2 +- src/libslic3r/GCodeWriter.cpp | 2 +- src/libslic3r/MedialAxis.cpp | 75 ++++++++++---------- src/libslic3r/MedialAxis.hpp | 2 +- src/libslic3r/Milling/MillingPostProcess.cpp | 14 ++-- src/libslic3r/Polyline.hpp | 2 +- src/libslic3r/libslic3r.h | 9 ++- 24 files changed, 147 insertions(+), 147 deletions(-) diff --git a/src/libslic3r/Arrange.cpp b/src/libslic3r/Arrange.cpp index 3800d49e3..46722d1d6 100644 --- a/src/libslic3r/Arrange.cpp +++ b/src/libslic3r/Arrange.cpp @@ -528,10 +528,10 @@ inline coord_t width(const BoundingBox& box) { return box.max.x() - box.min.x(); inline coord_t height(const BoundingBox& box) { return box.max.y() - box.min.y(); } inline double area(const BoundingBox& box) { return double(width(box)) * height(box); } inline double poly_area(const Points &pts) { return std::abs(Polygon::area(pts)); } -inline double distance_to(const Point& p1, const Point& p2) +inline coordf_t distance_to(const Point& p1, const Point& p2) { - double dx = p2.x() - p1.x(); - double dy = p2.y() - p1.y(); + coordf_t dx = coordf_t(p2.x() - p1.x()); + coordf_t dy = coordf_t(p2.y() - p1.y()); return std::sqrt(dx*dx + dy*dy); } diff --git a/src/libslic3r/BoundingBox.cpp b/src/libslic3r/BoundingBox.cpp index eb4e042a0..de02ac18b 100644 --- a/src/libslic3r/BoundingBox.cpp +++ b/src/libslic3r/BoundingBox.cpp @@ -161,11 +161,11 @@ BoundingBox3Base::size() const template Vec3f BoundingBox3Base::size() const; template Vec3d BoundingBox3Base::size() const; -template double BoundingBoxBase::radius() const +template coordf_t BoundingBoxBase::radius() const { assert(this->defined); - double x = this->max(0) - this->min(0); - double y = this->max(1) - this->min(1); + coordf_t x = coordf_t(this->max(0) - this->min(0)); + coordf_t y = coordf_t(this->max(1) - this->min(1)); return 0.5 * sqrt(x*x+y*y); } template double BoundingBoxBase::radius() const; diff --git a/src/libslic3r/BoundingBox.hpp b/src/libslic3r/BoundingBox.hpp index 8de28af5c..5262c48d3 100644 --- a/src/libslic3r/BoundingBox.hpp +++ b/src/libslic3r/BoundingBox.hpp @@ -43,7 +43,7 @@ public: void merge(const BoundingBoxBase &bb); void scale(double factor); PointClass size() const; - double radius() const; + coordf_t radius() const; void translate(coordf_t x, coordf_t y) { assert(this->defined); PointClass v(x, y); this->min += v; this->max += v; } void translate(const Vec2d &v) { this->min += v; this->max += v; } void offset(coordf_t delta); diff --git a/src/libslic3r/ClipperUtils.cpp b/src/libslic3r/ClipperUtils.cpp index 0528c137a..45bb08599 100644 --- a/src/libslic3r/ClipperUtils.cpp +++ b/src/libslic3r/ClipperUtils.cpp @@ -1230,7 +1230,7 @@ ExPolygons variable_offset_inner_ex(const ExPolygon &expoly, const std::vector cell_inside2(cell_inside); for (int r = 1; r + 1 < int(cell_rows); ++ r) { for (int c = 1; c + 1 < int(cell_cols); ++ c) { - int addr = r * cell_cols + c; + int addr = r * int(cell_cols) + c; if ((cell_inside2[addr - 1] && cell_inside2[addr + 1]) || (cell_inside2[addr - cell_cols] && cell_inside2[addr + cell_cols])) cell_inside[addr] = true; @@ -1483,8 +1483,8 @@ bool EdgeGrid::Grid::has_intersecting_edges() const void EdgeGrid::save_png(const EdgeGrid::Grid &grid, const BoundingBox &bbox, coord_t resolution, const char *path, size_t scale) { - unsigned int w = (bbox.max(0) - bbox.min(0) + resolution - 1) / resolution; - unsigned int h = (bbox.max(1) - bbox.min(1) + resolution - 1) / resolution; + uint32_t w = uint32_t((bbox.max(0) - bbox.min(0) + resolution - 1) / resolution); + uint32_t h = uint32_t((bbox.max(1) - bbox.min(1) + resolution - 1) / resolution); std::vector pixels(w * h * 3, 0); @@ -1501,7 +1501,7 @@ void EdgeGrid::save_png(const EdgeGrid::Grid &grid, const BoundingBox &bbox, coo #else if (grid.signed_distance(pt, search_radius, min_dist)) { #endif - float s = 255 * std::abs(min_dist) / float(display_blend_radius); + float s = float(255 * std::abs(min_dist)) / float(display_blend_radius); int is = std::max(0, std::min(255, int(floor(s + 0.5f)))); if (min_dist < 0) { if (on_segment) { @@ -1548,7 +1548,7 @@ void EdgeGrid::save_png(const EdgeGrid::Grid &grid, const BoundingBox &bbox, coo } } - float dgrid = fabs(min_dist) / float(grid.resolution()); + float dgrid = fabs(float(min_dist)) / float(grid.resolution()); float igrid = floor(dgrid + 0.5f); dgrid = std::abs(dgrid - igrid) * float(grid.resolution()) / float(resolution); if (dgrid < 1.f) { @@ -1559,7 +1559,7 @@ void EdgeGrid::save_png(const EdgeGrid::Grid &grid, const BoundingBox &bbox, coo pxl[2] = (unsigned char)(t * pxl[2]); if (igrid > 0.f) { // Other than zero iso contour. - int g = pxl[1] + 255.f * (1.f - t); + int g = int(pxl[1] + 255.f * (1.f - t)); pxl[1] = std::min(g, 255); } } @@ -1572,7 +1572,7 @@ void EdgeGrid::save_png(const EdgeGrid::Grid &grid, const BoundingBox &bbox, coo // Find all pairs of intersectiong edges from the set of polygons. std::vector> intersecting_edges(const Polygons &polygons) { - double len = 0; + coordf_t len = 0; size_t cnt = 0; BoundingBox bbox; for (const Polygon &poly : polygons) { @@ -1592,7 +1592,7 @@ std::vector> bbox.offset(20); EdgeGrid::Grid grid; grid.set_bbox(bbox); - grid.create(polygons, len); + grid.create(polygons, coord_t(len)); out = grid.intersecting_edges(); } return out; @@ -1612,7 +1612,7 @@ void export_intersections_to_svg(const std::string &filename, const Polygons &po intersecting_contours.insert(ie.second.first); } // Highlight the contours with intersections. - coord_t line_width = coord_t(scale_(0.01)); + coord_t line_width = scale_t(0.01); for (const Points *ic : intersecting_contours) { svg.draw_outline(Polygon(*ic), "green"); svg.draw_outline(Polygon(*ic), "black", line_width); diff --git a/src/libslic3r/EdgeGrid.hpp b/src/libslic3r/EdgeGrid.hpp index c3bc869d4..3141b440f 100644 --- a/src/libslic3r/EdgeGrid.hpp +++ b/src/libslic3r/EdgeGrid.hpp @@ -88,10 +88,10 @@ public: assert(m_bbox.contains(p2)); p1 -= m_bbox.min; p2 -= m_bbox.min; - assert(p1.x() >= 0 && p1.x() < m_cols * m_resolution); - assert(p1.y() >= 0 && p1.y() < m_rows * m_resolution); - assert(p2.x() >= 0 && p2.x() < m_cols * m_resolution); - assert(p2.y() >= 0 && p2.y() < m_rows * m_resolution); + assert(p1.x() >= 0 && p1.x() < coord_t(m_cols) * m_resolution); + assert(p1.y() >= 0 && p1.y() < coord_t(m_rows) * m_resolution); + assert(p2.x() >= 0 && p2.x() < coord_t(m_cols) * m_resolution); + assert(p2.y() >= 0 && p2.y() < coord_t(m_rows) * m_resolution); // Get the cells of the end points. coord_t ix = p1(0) / m_resolution; coord_t iy = p1(1) / m_resolution; @@ -248,9 +248,9 @@ public: std::pair>::const_iterator, std::vector>::const_iterator> cell_data_range(coord_t row, coord_t col) const { assert(row >= 0); - assert(row < m_rows); + assert(row < (coord_t)m_rows); assert(col >= 0); - assert(col < m_cols); + assert(col < (coord_t)m_cols); const EdgeGrid::Grid::Cell &cell = m_cells[row * m_cols + col]; return std::make_pair(m_cell_data.begin() + cell.begin, m_cell_data.begin() + cell.end); } diff --git a/src/libslic3r/ElephantFootCompensation.cpp b/src/libslic3r/ElephantFootCompensation.cpp index 83288929c..fac733c5b 100644 --- a/src/libslic3r/ElephantFootCompensation.cpp +++ b/src/libslic3r/ElephantFootCompensation.cpp @@ -536,14 +536,14 @@ static bool validate_expoly_orientation(const ExPolygon &expoly) #endif /* NDEBUG */ ExPolygon elephant_foot_compensation(const ExPolygon &input_expoly, double min_contour_width, const double compensation) -{ +{ assert(validate_expoly_orientation(input_expoly)); - double scaled_compensation = scale_(compensation); - min_contour_width = scale_(min_contour_width); - double min_contour_width_compensated = min_contour_width + 2. * scaled_compensation; + coordf_t scaled_compensation = scale_d(compensation); + coordf_t scaled_min_contour_width = scale_d(min_contour_width); + coordf_t min_contour_width_compensated = scaled_min_contour_width + 2. * scaled_compensation; // Make the search radius a bit larger for the averaging in contour_distance over a fan of rays to work. - double search_radius = min_contour_width_compensated + min_contour_width * 0.5; + coordf_t search_radius = min_contour_width_compensated + scaled_min_contour_width * 0.5; BoundingBox bbox = get_extents(input_expoly.contour); Point bbox_size = bbox.size(); @@ -578,12 +578,12 @@ ExPolygon elephant_foot_compensation(const ExPolygon &input_expoly, double min_c for (float &d : dists) { // printf("Point %d, Distance: %lf\n", int(&d - dists.data()), unscale(d)); // Convert contour width to available compensation distance. - if (d < min_contour_width) + if (d < scaled_min_contour_width) d = 0.f; else if (d > min_contour_width_compensated) d = - float(scaled_compensation); else - d = - (d - float(min_contour_width)) / 2.f; + d = - (d - float(scaled_min_contour_width)) / 2.f; assert(d >= - float(scaled_compensation) && d <= 0.f); } // smooth_compensation(dists, 0.4f, 10); diff --git a/src/libslic3r/ExPolygon.hpp b/src/libslic3r/ExPolygon.hpp index fbb5ed75a..c827025f9 100644 --- a/src/libslic3r/ExPolygon.hpp +++ b/src/libslic3r/ExPolygon.hpp @@ -202,10 +202,10 @@ inline Polylines to_polylines(ExPolygon &&src) Polyline &pl = polylines[idx ++]; pl.points = std::move(src.contour.points); pl.points.push_back(pl.points.front()); - for (Polygons::const_iterator ith = src.holes.begin(); ith != src.holes.end(); ++ith) { + for (Polygon& ith : src.holes) { Polyline &pl = polylines[idx ++]; - pl.points = std::move(ith->points); - pl.points.push_back(ith->points.front()); + pl.points = std::move(ith.points); + pl.points.push_back(pl.points.front()); } assert(idx == polylines.size()); return polylines; @@ -216,14 +216,14 @@ inline Polylines to_polylines(ExPolygons &&src) Polylines polylines; polylines.assign(number_polygons(src), Polyline()); size_t idx = 0; - for (ExPolygons::const_iterator it = src.begin(); it != src.end(); ++it) { + for (ExPolygon& ex_poly : src) { Polyline &pl = polylines[idx ++]; - pl.points = std::move(it->contour.points); + pl.points = std::move(ex_poly.contour.points); pl.points.push_back(pl.points.front()); - for (Polygons::const_iterator ith = it->holes.begin(); ith != it->holes.end(); ++ith) { + for (Polygon& ith : ex_poly.holes) { Polyline &pl = polylines[idx ++]; - pl.points = std::move(ith->points); - pl.points.push_back(ith->points.front()); + pl.points = std::move(ith.points); + pl.points.push_back(pl.points.front()); } } assert(idx == polylines.size()); @@ -243,9 +243,9 @@ inline Polygons to_polygons(const ExPolygons &src) { Polygons polygons; polygons.reserve(number_polygons(src)); - for (ExPolygons::const_iterator it = src.begin(); it != src.end(); ++it) { - polygons.push_back(it->contour); - polygons.insert(polygons.end(), it->holes.begin(), it->holes.end()); + for (const ExPolygon& ex_poly : src) { + polygons.push_back(ex_poly.contour); + polygons.insert(polygons.end(), ex_poly.holes.begin(), ex_poly.holes.end()); } return polygons; } diff --git a/src/libslic3r/Extruder.cpp b/src/libslic3r/Extruder.cpp index e9783a75d..d6c0fc49f 100644 --- a/src/libslic3r/Extruder.cpp +++ b/src/libslic3r/Extruder.cpp @@ -221,12 +221,12 @@ double Extruder::retract_restart_extra_toolchange() const int16_t Extruder::temp_offset() const { - return m_config->extruder_temperature_offset.get_at(m_id); + return int16_t(m_config->extruder_temperature_offset.get_at(m_id)); } int8_t Extruder::fan_offset() const { - return m_config->extruder_fan_offset.get_at(m_id); + return int8_t(m_config->extruder_fan_offset.get_at(m_id)); } double Mill::retract_lift() const { diff --git a/src/libslic3r/ExtrusionEntity.hpp b/src/libslic3r/ExtrusionEntity.hpp index c062456de..a675ae9e7 100644 --- a/src/libslic3r/ExtrusionEntity.hpp +++ b/src/libslic3r/ExtrusionEntity.hpp @@ -435,7 +435,7 @@ public: ExtrusionLoop(ExtrusionPaths &&paths, ExtrusionLoopRole role = elrDefault) : paths(std::move(paths)), m_loop_role(role) { assert(this->first_point() == this->paths.back().polyline.points.back()); } ExtrusionLoop(const ExtrusionPath &path, ExtrusionLoopRole role = elrDefault) : m_loop_role(role) { this->paths.push_back(path); } - ExtrusionLoop(const ExtrusionPath &&path, ExtrusionLoopRole role = elrDefault) : m_loop_role(role) + ExtrusionLoop(ExtrusionPath &&path, ExtrusionLoopRole role = elrDefault) : m_loop_role(role) { this->paths.emplace_back(std::move(path)); } virtual bool is_loop() const override{ return true; } virtual bool can_reverse() const override { return false; } diff --git a/src/libslic3r/Fill/FillAdaptive.cpp b/src/libslic3r/Fill/FillAdaptive.cpp index 14515f511..fc49e9b88 100644 --- a/src/libslic3r/Fill/FillAdaptive.cpp +++ b/src/libslic3r/Fill/FillAdaptive.cpp @@ -638,11 +638,11 @@ static inline Intersection* get_nearest_intersection(std::vectorvector().cast().normalized()) * (intersection.left ? scaled_offset : - scaled_offset)).cast()); // Extend the line by a small value to guarantee a collision with adjacent lines - offset_line.extend(coord_t(scaled_offset * 1.16)); // / cos(PI/6) + offset_line.extend(coordf_t(coord_t(scaled_offset * 1.16))); // / cos(PI/6) return offset_line; } @@ -1385,8 +1385,8 @@ void Filler::_fill_surface_single( } #endif /* ADAPTIVE_CUBIC_INFILL_DEBUG_OUTPUT */ - const auto hook_length = coordf_t(std::min(std::numeric_limits::max(), scale_(params.anchor_length))); - const auto hook_length_max = coordf_t(std::min(std::numeric_limits::max(), scale_(params.anchor_length_max))); + const coordf_t hook_length = std::min((coordf_t)std::numeric_limits::max(), scale_d(params.anchor_length)); + const coordf_t hook_length_max = std::min((coordf_t)std::numeric_limits::max(), scale_d(params.anchor_length_max)); Polylines all_polylines_with_hooks = all_polylines.size() > 1 ? connect_lines_using_hooks(std::move(all_polylines), expolygon, this->get_spacing(), hook_length, hook_length_max) : std::move(all_polylines); diff --git a/src/libslic3r/Fill/FillBase.cpp b/src/libslic3r/Fill/FillBase.cpp index d028e4510..619b41629 100644 --- a/src/libslic3r/Fill/FillBase.cpp +++ b/src/libslic3r/Fill/FillBase.cpp @@ -243,8 +243,8 @@ Fill::do_gap_fill(const ExPolygons& gapfill_areas, const FillParams& params, Ext // offset2_ex(gapfill_areas, double(-max / 2), double(+max / 2)), // true); ExPolygons gapfill_areas_collapsed = offset2_ex(gapfill_areas, double(-min / 2), double(+min / 2)); - double minarea = params.flow.scaled_width() * params.flow.scaled_width(); - if (params.config != nullptr) minarea = scale_(params.config->gap_fill_min_area.get_abs_value(params.flow.width)) * params.flow.scaled_width(); + double minarea = double(params.flow.scaled_width()) * double(params.flow.scaled_width()); + if (params.config != nullptr) minarea = scale_d(params.config->gap_fill_min_area.get_abs_value(params.flow.width)) * double(params.flow.scaled_width()); for (const ExPolygon& ex : gapfill_areas_collapsed) { //remove too small gaps that are too hard to fill. //ie one that are smaller than an extrusion with width of min and a length of max. @@ -2109,8 +2109,8 @@ void connect_infill(Polylines&& infill_ordered, const std::vector= 0.); assert(params.anchor_length_max >= 0.01f); assert(params.anchor_length_max >= params.anchor_length); - const double anchor_length = scale_(params.anchor_length); - const double anchor_length_max = scale_(params.anchor_length_max); + const coordf_t anchor_length = scale_d(params.anchor_length); + const coordf_t anchor_length_max = scale_d(params.anchor_length_max); #if 0 append(polylines_out, infill_ordered); diff --git a/src/libslic3r/Fill/FillConcentric.cpp b/src/libslic3r/Fill/FillConcentric.cpp index 10b76c357..86de14193 100644 --- a/src/libslic3r/Fill/FillConcentric.cpp +++ b/src/libslic3r/Fill/FillConcentric.cpp @@ -174,8 +174,8 @@ FillConcentricWGapFill::fill_surface_extrusion( ExPolygons gapfill_areas = diff_ex({ surface->expolygon }, offset_ex(expp, double(scale_(0.5 * this->get_spacing())))); gapfill_areas = union_ex(gapfill_areas, true); if (gapfill_areas.size() > 0) { - double minarea = params.flow.scaled_width() * params.flow.scaled_width(); - if (params.config != nullptr) minarea = scale_(params.config->gap_fill_min_area.get_abs_value(params.flow.width)) * params.flow.scaled_width(); + double minarea = double(params.flow.scaled_width()) * double(params.flow.scaled_width()); + if (params.config != nullptr) minarea = scale_d(params.config->gap_fill_min_area.get_abs_value(params.flow.width)) * double(params.flow.scaled_width()); for (int i = 0; i < gapfill_areas.size(); i++) { if (gapfill_areas[i].area() < minarea) { gapfill_areas.erase(gapfill_areas.begin() + i); diff --git a/src/libslic3r/Fill/FillGyroid.cpp b/src/libslic3r/Fill/FillGyroid.cpp index 8209bc3b0..c51cdf914 100644 --- a/src/libslic3r/Fill/FillGyroid.cpp +++ b/src/libslic3r/Fill/FillGyroid.cpp @@ -184,7 +184,7 @@ void FillGyroid::_fill_surface_single( if (! polylines.empty()) { // Remove very small bits, but be careful to not remove infill lines connecting thin walls! // The infill perimeter lines should be separated by around a single infill line width. - const double minlength = scale_(0.8 * this->get_spacing()); + const coordf_t minlength = scale_d(0.8 * this->get_spacing()); polylines.erase( std::remove_if(polylines.begin(), polylines.end(), [minlength](const Polyline &pl) { return pl.length() < minlength; }), polylines.end()); diff --git a/src/libslic3r/Fill/FillLine.cpp b/src/libslic3r/Fill/FillLine.cpp index de4df4893..eb2a17af5 100644 --- a/src/libslic3r/Fill/FillLine.cpp +++ b/src/libslic3r/Fill/FillLine.cpp @@ -94,7 +94,7 @@ void FillLine::_fill_surface_single( // offset the expolygon by max(min_spacing/2, extra) ExPolygon expolygon_off; { - ExPolygons expolygons_off = offset_ex(expolygon, this->_min_spacing/2); + ExPolygons expolygons_off = offset_ex(expolygon, coordf_t(this->_min_spacing / 2)); if (! expolygons_off.empty()) { // When expanding a polygon, the number of islands could only shrink. Therefore the offset_ex shall generate exactly one expanded island for one input island. assert(expolygons_off.size() == 1); diff --git a/src/libslic3r/Fill/FillRectilinear.cpp b/src/libslic3r/Fill/FillRectilinear.cpp index e47e121f8..1dd8acd3d 100644 --- a/src/libslic3r/Fill/FillRectilinear.cpp +++ b/src/libslic3r/Fill/FillRectilinear.cpp @@ -2819,8 +2819,8 @@ bool FillRectilinear::fill_surface_by_lines(const Surface *surface, const FillPa ExPolygonWithOffset poly_with_offset( surface->expolygon, - rotate_vector.first, - float(scale_(0 /*this->overlap*/ - (0.5 - INFILL_OVERLAP_OVER_SPACING) * this->get_spacing())), - float(scale_(0 /*this->overlap*/ - 0.5f * this->get_spacing()))); + (scale_t(0 /*this->overlap*/ - (0.5 - INFILL_OVERLAP_OVER_SPACING) * this->get_spacing())), + (scale_t(0 /*this->overlap*/ - 0.5f * this->get_spacing()))); if (poly_with_offset.n_contours_inner == 0) { // Not a single infill line fits. //Prusa: maybe one shall trigger the gap fill here? @@ -2956,24 +2956,24 @@ bool FillRectilinear::fill_surface_by_multilines(const Surface* surface, FillPar { assert(sweep_params.size() > 1); assert(!params.full_infill()); - params.density /= double(sweep_params.size()); + params.density /= float(sweep_params.size()); assert(params.density > 0.0001f && params.density <= 1.f); - ExPolygonWithOffset poly_with_offset_base(surface->expolygon, 0, float(scale_(this->overlap - 0.5 * this->get_spacing()))); + ExPolygonWithOffset poly_with_offset_base(surface->expolygon, 0, scale_t(this->overlap - 0.5 * this->get_spacing())); if (poly_with_offset_base.n_contours == 0) // Not a single infill line fits. return true; Polylines fill_lines; - coord_t line_width = coord_t(scale_(this->get_spacing())); - coord_t line_spacing = coord_t(scale_(this->get_spacing()) / params.density); + coord_t line_width = scale_t(this->get_spacing()); + coord_t line_spacing = scale_t(this->get_spacing() / params.density); std::pair rotate_vector = this->_infill_direction(surface); for (const SweepParams& sweep : sweep_params) { size_t n_fill_lines_initial = fill_lines.size(); // Rotate polygons so that we can work with vertical lines here double angle = rotate_vector.first + sweep.angle_base; - ExPolygonWithOffset poly_with_offset(poly_with_offset_base, -angle); + ExPolygonWithOffset poly_with_offset(poly_with_offset_base, float(-angle)); BoundingBox bounding_box = poly_with_offset.bounding_box_src(); // Don't produce infill lines, which fully overlap with the infill perimeter. coord_t x_min = bounding_box.min.x() + line_width + coord_t(SCALED_EPSILON); @@ -3096,10 +3096,10 @@ FillRectilinearPeri::fill_surface_extrusion(const Surface *surface, const FillPa Polylines polylines_1; //generate perimeter: ExPolygons path_perimeter = offset2_ex(surface->expolygon, - scale_(-this->get_spacing()), scale_(this->get_spacing() / 2), - ClipperLib::jtMiter, scale_(this->get_spacing()) * 10); + scale_d(-this->get_spacing()), scale_d(this->get_spacing() / 2), + ClipperLib::jtMiter, scale_d(this->get_spacing()) * 10); //fix a bug that can happens when (positive) offsetting with a big miter limit and two island merge. See https://github.com/supermerill/SuperSlicer/issues/609 - path_perimeter = intersection_ex(path_perimeter, offset_ex(surface->expolygon, scale_(-this->get_spacing() / 2))); + path_perimeter = intersection_ex(path_perimeter, offset_ex(surface->expolygon, scale_d(-this->get_spacing() / 2))); for (ExPolygon &expolygon : path_perimeter) { expolygon.contour.make_counter_clockwise(); polylines_1.push_back(expolygon.contour.split_at_index(0)); @@ -3133,7 +3133,7 @@ FillRectilinearPeri::fill_surface_extrusion(const Surface *surface, const FillPa Polylines polylines_2; bool canFill = true; //50% overlap with the new perimeter - ExPolygons path_inner = offset2_ex(surface->expolygon, scale_(-this->get_spacing() * 1.5), scale_(this->get_spacing())); + ExPolygons path_inner = offset2_ex(surface->expolygon, scale_d(-this->get_spacing() * 1.5), scale_d(this->get_spacing())); for (ExPolygon &expolygon : path_inner) { Surface surfInner(*surface, expolygon); if (!fill_surface_by_lines(&surfInner, params, 0.f, 0.f, polylines_2)) { @@ -3203,7 +3203,7 @@ Polylines FillScatteredRectilinear::fill_surface(const Surface *surface, const F Polylines polylines_out; // Offset the pattern randomly using the current layer index as the generator - float offset = randomFloatFromSeed((uint32_t) layer_id) * 0.5f * this->get_spacing(); + float offset = (float)randomFloatFromSeed((uint32_t) layer_id) * 0.5f * this->get_spacing(); if (!fill_surface_by_lines(surface, params, 0.f, offset, polylines_out)) { printf("FillScatteredRectilinear::fill_surface() failed to fill a region.\n"); @@ -3307,7 +3307,7 @@ FillRectilinearSawtooth::fill_surface_extrusion(const Surface *surface, const Fi current_extrusion->push_back(last, tooth_zhop); // add new extrusion that go down with no nozzle_flow / sqrt(2) - extrusions->paths.push_back(ExtrusionPath3D(good_role, params.flow.mm3_per_mm() / std::sqrt(2), params.flow.width / std::sqrt(2), params.flow.height)); + extrusions->paths.push_back(ExtrusionPath3D(good_role, params.flow.mm3_per_mm() / std::sqrt(2), float(params.flow.width / std::sqrt(2)), params.flow.height)); current_extrusion = &(extrusions->paths.back()); current_extrusion->push_back(last, tooth_zhop); //add next point @@ -3438,7 +3438,7 @@ FillRectilinearWGapFill::fill_surface_extrusion(const Surface *surface, const Fi eec->entities, polylines_rectilinear, good_role, params.flow.mm3_per_mm() * params.flow_mult * flow_mult_exact_volume, - params.flow.width * params.flow_mult * flow_mult_exact_volume, + params.flow.width * params.flow_mult * float(flow_mult_exact_volume), params.flow.height); coll_nosort->entities.push_back(eec); @@ -3452,7 +3452,7 @@ FillRectilinearWGapFill::fill_surface_extrusion(const Surface *surface, const Fi gapfill_areas.insert(gapfill_areas.end(), unextruded_areas.begin(), unextruded_areas.end()); gapfill_areas = union_ex(gapfill_areas, true); if (gapfill_areas.size() > 0) { - const double minarea = scale_(params.config->gap_fill_min_area.get_abs_value(params.flow.width)) * params.flow.scaled_width(); + const double minarea = scale_d(params.config->gap_fill_min_area.get_abs_value(params.flow.width)) * double(params.flow.scaled_width()); for (int i = 0; i < gapfill_areas.size(); i++) { if (gapfill_areas[i].area() < minarea) { gapfill_areas.erase(gapfill_areas.begin() + i); diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index 6895786de..fc26fde9d 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -175,7 +175,7 @@ std::string Wipe::wipe(GCode& gcodegen, bool toolchange) /* Calculate how long we need to travel in order to consume the required amount of retraction. In other words, how far do we move in XY at wipe_speed for the time needed to consume retract_length at retract_speed? */ - double wipe_dist = scale_(length / gcodegen.writer().tool()->retract_speed() * wipe_speed); + coordf_t wipe_dist = scale_d(length / gcodegen.writer().tool()->retract_speed() * wipe_speed); /* Take the stored wipe path and replace first point with the current actual position (they might be different, for example, in case of loop clipping). */ @@ -2875,8 +2875,8 @@ std::string GCode::extrude_loop_vase(const ExtrusionLoop &original_loop, const s // apply the small/external? perimeter speed if (speed == -1 && is_perimeter(paths.front().role()) && loop.length() <= scale_(this->m_config.small_perimeter_max_length.get_abs_value(EXTRUDER_CONFIG_WITH_DEFAULT(nozzle_diameter, 0)))) { - double min_length = scale_(this->m_config.small_perimeter_min_length.get_abs_value(EXTRUDER_CONFIG_WITH_DEFAULT(nozzle_diameter, 0))); - double max_length = scale_(this->m_config.small_perimeter_max_length.get_abs_value(EXTRUDER_CONFIG_WITH_DEFAULT(nozzle_diameter, 0))); + coordf_t min_length = scale_d(this->m_config.small_perimeter_min_length.get_abs_value(EXTRUDER_CONFIG_WITH_DEFAULT(nozzle_diameter, 0))); + coordf_t max_length = scale_d(this->m_config.small_perimeter_max_length.get_abs_value(EXTRUDER_CONFIG_WITH_DEFAULT(nozzle_diameter, 0))); if (loop.length() <= min_length) { speed = m_config.small_perimeter_speed.get_abs_value(m_config.perimeter_speed); } else { @@ -2923,7 +2923,7 @@ std::string GCode::extrude_loop_vase(const ExtrusionLoop &original_loop, const s Vec2d p1 = paths.front().polyline.points.front().cast(); Vec2d p2 = paths.front().polyline.points[1].cast(); Vec2d v = p2 - p1; - double nd = scale_(EXTRUDER_CONFIG_WITH_DEFAULT(nozzle_diameter, paths.front().width)); + double nd = scale_d(EXTRUDER_CONFIG_WITH_DEFAULT(nozzle_diameter, paths.front().width)); double l2 = v.squaredNorm(); // Shift by no more than a nozzle diameter. //FIXME Hiding the seams will not work nicely for very densely discretized contours! @@ -3071,7 +3071,7 @@ std::string GCode::extrude_loop_vase(const ExtrusionLoop &original_loop, const s Vec2d p1 = paths.front().polyline.points.front().cast(); Vec2d p2 = paths.front().polyline.points[1].cast(); Vec2d v = p2 - p1; - double nd = scale_(EXTRUDER_CONFIG_WITH_DEFAULT(nozzle_diameter, paths.front().width)); + coordf_t nd = scale_d(EXTRUDER_CONFIG_WITH_DEFAULT(nozzle_diameter, paths.front().width)); double l2 = v.squaredNorm(); // Shift by no more than a nozzle diameter. //FIXME Hiding the seams will not work nicely for very densely discretized contours! @@ -3192,8 +3192,8 @@ std::string GCode::extrude_loop(const ExtrusionLoop &original_loop, const std::s // apply the small perimeter speed if (speed == -1 && is_perimeter(paths.front().role()) && loop.length() <= scale_(this->m_config.small_perimeter_max_length.get_abs_value(EXTRUDER_CONFIG_WITH_DEFAULT(nozzle_diameter, 0)))) { - double min_length = scale_(this->m_config.small_perimeter_min_length.get_abs_value(EXTRUDER_CONFIG_WITH_DEFAULT(nozzle_diameter, 0))); - double max_length = scale_(this->m_config.small_perimeter_max_length.get_abs_value(EXTRUDER_CONFIG_WITH_DEFAULT(nozzle_diameter, 0))); + double min_length = scale_d(this->m_config.small_perimeter_min_length.get_abs_value(EXTRUDER_CONFIG_WITH_DEFAULT(nozzle_diameter, 0))); + double max_length = scale_d(this->m_config.small_perimeter_max_length.get_abs_value(EXTRUDER_CONFIG_WITH_DEFAULT(nozzle_diameter, 0))); if (loop.length() <= min_length) { speed = m_config.small_perimeter_speed.get_abs_value(m_config.perimeter_speed); } else { @@ -3228,7 +3228,7 @@ std::string GCode::extrude_loop(const ExtrusionLoop &original_loop, const std::s //extra wipe before the little move. if (EXTRUDER_CONFIG_WITH_DEFAULT(wipe_extra_perimeter, 0) > 0) { - coord_t wipe_dist = scale_(EXTRUDER_CONFIG_WITH_DEFAULT(wipe_extra_perimeter,0)); + coordf_t wipe_dist = scale_(EXTRUDER_CONFIG_WITH_DEFAULT(wipe_extra_perimeter,0)); ExtrusionPaths paths_wipe; for (int i = 0; i < paths.size(); i++) { ExtrusionPath& path = paths[i]; @@ -3286,7 +3286,7 @@ std::string GCode::extrude_loop(const ExtrusionLoop &original_loop, const std::s Vec2d current_pos = current_point.cast(); Vec2d next_pos = next_point.cast(); Vec2d vec_dist = next_pos - current_pos; - double nd = scale_(EXTRUDER_CONFIG_WITH_DEFAULT(nozzle_diameter,0)); + double nd = scale_d(EXTRUDER_CONFIG_WITH_DEFAULT(nozzle_diameter,0)); double l2 = vec_dist.squaredNorm(); // Shift by no more than a nozzle diameter. //FIXME Hiding the seams will not work nicely for very densely discretized contours! @@ -3379,7 +3379,7 @@ void GCode::use(const ExtrusionEntityCollection &collection) { std::string GCode::extrude_path(const ExtrusionPath &path, const std::string &description, double speed_mm_per_sec) { ExtrusionPath simplifed_path = path; - const double scaled_min_length = scale_(this->config().min_length.value); + const coordf_t scaled_min_length = scale_d(this->config().min_length.value); const double max_gcode_per_second = this->config().max_gcode_per_second.value; double current_scaled_min_length = scaled_min_length; if (max_gcode_per_second > 0) { @@ -3390,7 +3390,7 @@ std::string GCode::extrude_path(const ExtrusionPath &path, const std::string &de //ensure that it's a continous thing if (m_last_too_small.last_point().distance_to_square(path.first_point()) < current_scaled_min_length * current_scaled_min_length /*&& m_last_too_small.first_point().distance_to_square(path.first_point()) > EPSILON*/) { //descr += " ! fusion " + std::to_string(simplifed_path.polyline.points.size()); - simplifed_path.height = (m_last_too_small.height * m_last_too_small.length() + simplifed_path.height * simplifed_path.length()) / (m_last_too_small.length() + simplifed_path.length()); + simplifed_path.height = float(m_last_too_small.height * m_last_too_small.length() + simplifed_path.height * simplifed_path.length()) / float(m_last_too_small.length() + simplifed_path.length()); simplifed_path.mm3_per_mm = (m_last_too_small.mm3_per_mm * m_last_too_small.length() + simplifed_path.mm3_per_mm * simplifed_path.length()) / (m_last_too_small.length() + simplifed_path.length()); simplifed_path.polyline.points.insert(simplifed_path.polyline.points.begin(), m_last_too_small.polyline.points.begin(), m_last_too_small.polyline.points.end()-1); assert(simplifed_path.height == simplifed_path.height); @@ -3560,11 +3560,11 @@ void GCode::_post_process(std::string& what, bool flush) { if (this->m_fan_mover.get() == nullptr) this->m_fan_mover.reset(new Slic3r::FanMover( this->m_writer, - std::abs(this->config().fan_speedup_time.value), + std::abs((float)this->config().fan_speedup_time.value), this->config().fan_speedup_time.value > 0, this->config().use_relative_e_distances.value, this->config().fan_speedup_overhangs.value, - this->config().fan_kickstart.value)); + (float)this->config().fan_kickstart.value)); what = this->m_fan_mover->process_gcode(what, flush); } @@ -3695,7 +3695,7 @@ std::string GCode::_extrude(const ExtrusionPath &path, const std::string &descri double mult2 = 1 - coeff; double sum = 0; //Create a point - Point inter_point1 = line.point_at(scale_(length1)); + Point inter_point1 = line.point_at(scale_d(length1)); //extrude very reduced gcode += m_writer.extrude_to_xy( this->point_to_gcode(inter_point1), @@ -3704,7 +3704,7 @@ std::string GCode::_extrude(const ExtrusionPath &path, const std::string &descri sum += e_per_mm * (length1) * mult1; if (line_length - length1 > length2) { - Point inter_point2 = line.point_at(scale_(length2)); + Point inter_point2 = line.point_at(scale_d(length2)); //extrude reduced gcode += m_writer.extrude_to_xy( this->point_to_gcode(inter_point2), @@ -3758,7 +3758,7 @@ double_t GCode::_compute_speed_mm_per_sec(const ExtrusionPath& path, double spee if (speed < 0) { //if speed == -1, then it's means "choose yourself, but if it's -1 < speed <0 , then it's a scaling from small_periemter. //it's a bit hacky, so if you want to rework it, help yourself. - float factor = (-speed); + float factor = float(-speed); if (path.role() == erPerimeter) { speed = m_config.get_abs_value("perimeter_speed"); } else if (path.role() == erExternalPerimeter) { @@ -3790,7 +3790,7 @@ double_t GCode::_compute_speed_mm_per_sec(const ExtrusionPath& path, double spee } //don't modify bridge speed if (factor < 1 && !(is_bridge(path.role()))) { - float small_speed = m_config.small_perimeter_speed.get_abs_value(m_config.perimeter_speed); + float small_speed = (float)m_config.small_perimeter_speed.get_abs_value(m_config.perimeter_speed); //apply factor between feature speed and small speed speed = (speed * factor) + double((1.f - factor) * small_speed); } @@ -3885,7 +3885,7 @@ std::string GCode::_before_extrude(const ExtrusionPath &path, const std::string coordf_t length = poly_start.length(); if (length > SCALED_EPSILON) { Polyline poly_end; - coordf_t min_length = scale_(EXTRUDER_CONFIG_WITH_DEFAULT(nozzle_diameter, 0.5)) * 20; + coordf_t min_length = scale_d(EXTRUDER_CONFIG_WITH_DEFAULT(nozzle_diameter, 0.5)) * 20; if (poly_start.size() > 2 && length > min_length * 3) { //if complex travel, try to deccelerate only at the end, unless it's less than ~ 20 nozzle if (poly_start.lines().back().length() < min_length) { @@ -4304,9 +4304,9 @@ Vec2d GCode::point_to_gcode(const Point &point) const // convert a model-space scaled point into G-code coordinates Vec3d GCode::point_to_gcode(const Point &point, const coord_t z_offset) const { Vec2d extruder_offset = EXTRUDER_CONFIG_WITH_DEFAULT(extruder_offset, Vec2d(0, 0)); //FIXME : mill ofsset - Vec3d ret_vec(unscale_(point.x()) + m_origin.x() - extruder_offset.x(), - unscale_(point.y()) + m_origin.y() - extruder_offset.y(), - unscale_(z_offset)); + Vec3d ret_vec(unscaled(point.x()) + m_origin.x() - extruder_offset.x(), + unscaled(point.y()) + m_origin.y() - extruder_offset.y(), + unscaled(z_offset)); return ret_vec; } diff --git a/src/libslic3r/GCode/GCodeProcessor.cpp b/src/libslic3r/GCode/GCodeProcessor.cpp index 7269a05c8..874ff4be1 100644 --- a/src/libslic3r/GCode/GCodeProcessor.cpp +++ b/src/libslic3r/GCode/GCodeProcessor.cpp @@ -1955,7 +1955,7 @@ void GCodeProcessor::process_G1(const GCodeReader::GCodeLine& line) // time estimate section auto move_length = [](const AxisCoords& delta_pos) { - float sq_xyz_length = (float)sqr(delta_pos[X]) + sqr(delta_pos[Y]) + sqr(delta_pos[Z]); + float sq_xyz_length = (float)sqr(delta_pos[X]) + (float)sqr(delta_pos[Y]) + (float)sqr(delta_pos[Z]); return (sq_xyz_length > 0.0f) ? std::sqrt(sq_xyz_length) : std::abs(delta_pos[E]); }; diff --git a/src/libslic3r/GCodeWriter.cpp b/src/libslic3r/GCodeWriter.cpp index e9ababa33..2211e521a 100644 --- a/src/libslic3r/GCodeWriter.cpp +++ b/src/libslic3r/GCodeWriter.cpp @@ -27,7 +27,7 @@ std::string to_string_nozero(double value, int32_t max_precision) { //first, get the int part, to see how many digit it takes int long10 = 0; if (intpart > 9) - long10 = std::floor(std::log10(std::abs(intpart))); + long10 = (int)std::floor(std::log10(std::abs(intpart))); //set the usable precision: there is only 15-16 decimal digit in a double ss << std::fixed << std::setprecision(int(std::min(15 - long10, int(max_precision)))) << value; std::string ret = ss.str(); diff --git a/src/libslic3r/MedialAxis.cpp b/src/libslic3r/MedialAxis.cpp index c243f7c86..22a26950a 100644 --- a/src/libslic3r/MedialAxis.cpp +++ b/src/libslic3r/MedialAxis.cpp @@ -354,9 +354,9 @@ remove_point_too_near(ThickPolyline* to_reduce) void add_point_same_percent(ThickPolyline* pattern, ThickPolyline* to_modify) { - const double to_modify_length = to_modify->length(); + const coordf_t to_modify_length = to_modify->length(); const double percent_epsilon = SCALED_EPSILON / to_modify_length; - const double pattern_length = pattern->length(); + const coordf_t pattern_length = pattern->length(); double percent_length = 0; for (size_t idx_point = 1; idx_point < pattern->points.size() - 1; ++idx_point) { @@ -394,10 +394,10 @@ add_point_same_percent(ThickPolyline* pattern, ThickPolyline* to_modify) /// return 1 for an angle of 90° and 0 for an angle of 0° or 180° double get_coeff_from_angle_countour(Point &point, const ExPolygon &contour, coord_t min_dist_between_point) { - double nearest_dist = point.distance_to(contour.contour.points.front()); + coordf_t nearest_dist = point.distance_to(contour.contour.points.front()); Point point_nearest = contour.contour.points.front(); size_t id_nearest = 0; - double near_dist = nearest_dist; + coordf_t near_dist = nearest_dist; Point point_near = point_nearest; size_t id_near = 0; for (size_t id_point = 1; id_point < contour.contour.points.size(); ++id_point) { @@ -585,8 +585,8 @@ MedialAxis::remove_bits(ThickPolylines &pp) if (polyline.width.back() > 0) continue; //check my length is small - coord_t length = (coord_t)polyline.length(); - if (length > max_width*1.5) { + coordf_t length = polyline.length(); + if (length > coordf_t(max_width) * 1.5) { continue; } @@ -613,11 +613,11 @@ MedialAxis::remove_bits(ThickPolylines &pp) if (nb_better_than_me < 2) continue; //check if the length of the polyline is small vs width of the other lines - double max_width = 0; + coord_t max_width = 0; for (int i = 0; i < crosspoint.size(); i++) { max_width = std::max(max_width, pp[crosspoint[i]].width[0]); } - if (length > max_width + min_width) + if (length > coordf_t(max_width + min_width)) continue; //delete the now unused polyline @@ -823,10 +823,10 @@ MedialAxis::extends_line(ThickPolyline& polyline, const ExPolygons& anchors, con }*/ // find anchor Point best_anchor; - double shortest_dist = (double)max_width; + coordf_t shortest_dist = (coordf_t)max_width; for (const ExPolygon& a : anchors) { Point p_maybe_inside = a.contour.centroid(); - double test_dist = new_bound.distance_to(p_maybe_inside) + new_back.distance_to(p_maybe_inside); + coordf_t test_dist = new_bound.distance_to(p_maybe_inside) + new_back.distance_to(p_maybe_inside); //if (test_dist < max_width / 2 && (test_dist < shortest_dist || shortest_dist < 0)) { double angle_test = new_back.ccw_angle(p_maybe_inside, line.a); if (angle_test > PI) angle_test = 2 * PI - angle_test; @@ -1096,12 +1096,12 @@ MedialAxis::main_fusion(ThickPolylines& pp) polyline.width[idx_point] = max_width; //failsafe: try to not go out of the radius of the section, take the width of the merging point for that. (and with some offset) coord_t main_branch_width = pp[biggest_main_branch_id].width.front(); - coord_t main_branch_dist = pp[biggest_main_branch_id].points.front().distance_to(polyline.points[idx_point]); - coord_t max_width_from_main = std::sqrt(main_branch_width*main_branch_width + main_branch_dist*main_branch_dist); + coordf_t main_branch_dist = pp[biggest_main_branch_id].points.front().distance_to(polyline.points[idx_point]); + coord_t max_width_from_main = (coord_t)std::sqrt(main_branch_width*main_branch_width + main_branch_dist*main_branch_dist); if (find_main_branch && polyline.width[idx_point] > max_width_from_main) polyline.width[idx_point] = max_width_from_main; if (find_main_branch && polyline.width[idx_point] > pp[biggest_main_branch_id].width.front() * 1.1) - polyline.width[idx_point] = pp[biggest_main_branch_id].width.front() * 1.1; + polyline.width[idx_point] = coord_t(pp[biggest_main_branch_id].width.front() * 1.1); //std::cout << "main fusion, max dist : " << max_width_from_main << "\n"; ++idx_point; @@ -1381,7 +1381,7 @@ MedialAxis::remove_too_short_polylines(ThickPolylines& pp, const coord_t min_siz while (changes) { changes = false; - double shortest_size = min_size; + coordf_t shortest_size = (coordf_t) min_size; size_t shortest_idx = -1; for (size_t i = 0; i < pp.size(); ++i) { ThickPolyline& polyline = pp[i]; @@ -1407,19 +1407,19 @@ MedialAxis::remove_too_short_polylines(ThickPolylines& pp, const coord_t min_siz } void -MedialAxis::check_width(ThickPolylines& pp, double max_width, std::string msg) +MedialAxis::check_width(ThickPolylines& pp, coord_t max_width, std::string msg) { //remove empty polyline int nb = 0; for (size_t i = 0; i < pp.size(); ++i) { for (size_t j = 0; j < pp[i].width.size(); ++j) { - if (pp[i].width[j] > max_width * 1.01) { - std::cout << "Error " << msg << " width " << unscaled(pp[i].width[j]) << "(" << i << ":" << j << ") > " << unscaled(max_width) << "\n"; + if (pp[i].width[j] > coord_t(max_width * 1.01)) { + BOOST_LOG_TRIVIAL(error) << "Error " << msg << " width " << unscaled(pp[i].width[j]) << "(" << i << ":" << j << ") > " << unscaled(max_width) << "\n"; nb++; } } } - if (nb > 0) std::cout << "== nbBig = " << nb << " ==\n"; + if (nb > 0) BOOST_LOG_TRIVIAL(error) << "== nbBig = " << nb << " ==\n"; } void @@ -1432,7 +1432,7 @@ MedialAxis::ensure_not_overextrude(ThickPolylines& pp) for (ThickPolyline& polyline : pp) { for (ThickLine &l : polyline.thicklines()) { surface += l.length() * (l.a_width + l.b_width) / 2; - double width_mean = (l.a_width + l.b_width) / 2; + coord_t width_mean = (l.a_width + l.b_width) / 2; volume += height * (width_mean - height * (1. - 0.25 * PI)) * l.length(); } } @@ -1453,8 +1453,8 @@ MedialAxis::ensure_not_overextrude(ThickPolylines& pp) //reduce width double reduce_by = boundsVolume / volume; for (ThickPolyline& polyline : pp) { - for (coordf_t &width : polyline.width) { - width *= reduce_by; + for (coord_t &width : polyline.width) { + width = coord_t( double(width) * reduce_by); } } } @@ -1515,9 +1515,10 @@ MedialAxis::grow_to_nozzle_diameter(ThickPolylines& pp, const ExPolygons& anchor //compute the min width coord_t min_width = this->nozzle_diameter; if (this->height > 0) min_width = Flow::new_from_spacing( - float(unscale_(this->nozzle_diameter)), - float(unscale_(this->nozzle_diameter)), - float(unscale_(this->height)), false).scaled_width(); + float(unscaled(this->nozzle_diameter)), + float(unscaled(this->nozzle_diameter)), + float(unscaled(this->height)), + false).scaled_width(); //ensure the width is not lower than min_width. for (ThickPolyline& polyline : pp) { for (int i = 0; i < polyline.points.size(); ++i) { @@ -1538,8 +1539,8 @@ void MedialAxis::taper_ends(ThickPolylines& pp) { // minimum size of the taper: be sure to extrude at least the "round edges" of the extrusion (0-spacing extrusion). - const coord_t min_size = std::max(this->nozzle_diameter * 0.1, this->height * (1. - 0.25 * PI)); - const coordf_t length = std::min(this->taper_size, (this->nozzle_diameter - min_size) / 2); + const coord_t min_size = (coord_t) std::max(this->nozzle_diameter * 0.1, this->height * (1. - 0.25 * PI)); + const coordf_t length = (coordf_t) std::min(this->taper_size, (this->nozzle_diameter - min_size) / 2); if (length <= SCALED_RESOLUTION) return; //ensure the width is not lower than min_size. for (ThickPolyline& polyline : pp) { @@ -1593,9 +1594,9 @@ check_circular(ExPolygon& expolygon, coord_t max_variation) { if (expolygon.contour.concave_points().empty() && expolygon.contour.points.size() > 3) { // Computing circle center Point center = expolygon.contour.centroid(); - double radius_min = std::numeric_limits::max(), radius_max = 0; + coordf_t radius_min = std::numeric_limits::max(), radius_max = 0; for (int i = 0; i < expolygon.contour.points.size(); ++i) { - double dist = expolygon.contour.points[i].distance_to(center); + coordf_t dist = expolygon.contour.points[i].distance_to(center); radius_min = std::min(radius_min, dist); radius_max = std::max(radius_max, dist); } @@ -1634,7 +1635,7 @@ MedialAxis::build(ThickPolylines &polylines_out) if (this->expolygon.area() < this->min_width * this->min_width) return; //check for circular shape - double radius = check_circular(this->expolygon, this->min_width/4); + coordf_t radius = check_circular(this->expolygon, this->min_width/4); if (radius > 0 && this->expolygon.contour.points.size() > 4) { ExPolygons miniPeri = offset_ex(this->expolygon.contour, -radius / 2); if (miniPeri.size() == 1 && miniPeri[0].holes.size() == 0) { @@ -1742,9 +1743,9 @@ MedialAxis::build(ThickPolylines &polylines_out) /* Find the maximum width returned; we're going to use this for validating and filtering the output segments. */ - double max_w = 0; + coord_t max_w = 0; for (ThickPolylines::const_iterator it = pp.begin(); it != pp.end(); ++it) - max_w = std::max(max_w, *std::max_element(it->width.begin(), it->width.end())); + max_w = std::max(max_w, (coord_t)*std::max_element(it->width.begin(), it->width.end())); //for (auto &p : pp) { // std::cout << "Start polyline : "; @@ -1847,7 +1848,7 @@ MedialAxis::build(ThickPolylines &polylines_out) // svg.Close(); //} - remove_too_short_polylines(pp, (coord_t)max_w * 2); + remove_too_short_polylines(pp, max_w * 2); //{ // std::stringstream stri; // stri << "medial_axis_8_tooshort_" << id << ".svg"; @@ -1907,7 +1908,7 @@ thin_variable_width(const ThickPolylines &polylines, ExtrusionRole role, Flow fl // this value determines granularity of adaptive width, as G-code does not allow // variable extrusion within a single move; this value shall only affect the amount // of segments, and any pruning shall be performed before we apply this tolerance - const double tolerance = 4*SCALED_RESOLUTION;//scale_(0.05); + const coord_t tolerance = 4 * SCALED_RESOLUTION;//scale_(0.05); ExtrusionEntityCollection coll; for (const ThickPolyline &p : polylines) { @@ -1923,16 +1924,16 @@ thin_variable_width(const ThickPolylines &polylines, ExtrusionRole role, Flow fl assert(line.a_width >= 0); assert(line.b_width >= 0); - double thickness_delta = fabs(line.a_width - line.b_width); - if (thickness_delta > tolerance && ceil(thickness_delta / tolerance) > 2) { - const uint16_t segments = 1+(uint16_t) std::min(16000.0, ceil(thickness_delta / tolerance)); + coord_t thickness_delta = std::abs(line.a_width - line.b_width); + if (thickness_delta > tolerance && ceil(float(thickness_delta) / float(tolerance)) > 2) { + const uint16_t segments = 1 + (uint16_t) std::min((uint32_t)16000, (uint32_t)ceil(float(thickness_delta) / float(tolerance))); Points pp; std::vector width; { for (size_t j = 0; j < segments; ++j) { pp.push_back(line.a.interpolate(((double)j) / segments, line.b)); double percent_width = ((double)j) / (segments-1); - width.push_back(line.a_width*(1 - percent_width) + line.b_width*percent_width); + width.push_back(line.a_width * (1 - percent_width) + line.b_width * percent_width); } pp.push_back(line.b); diff --git a/src/libslic3r/MedialAxis.hpp b/src/libslic3r/MedialAxis.hpp index bc208e3f5..69bd94268 100644 --- a/src/libslic3r/MedialAxis.hpp +++ b/src/libslic3r/MedialAxis.hpp @@ -109,7 +109,7 @@ class MedialAxis { /// taper the ends of polylines (don't activate that for gapfill) void taper_ends(ThickPolylines& pp); //cleaning method - void check_width(ThickPolylines& pp, double max_width, std::string msg); + void check_width(ThickPolylines& pp, coord_t max_width, std::string msg); //removing small extrusion that won't be useful and will harm print. A bit like fusion_corners but more lenient and with just del. void remove_bits(ThickPolylines& pp); }; diff --git a/src/libslic3r/Milling/MillingPostProcess.cpp b/src/libslic3r/Milling/MillingPostProcess.cpp index 4e40ce553..9a26e1979 100644 --- a/src/libslic3r/Milling/MillingPostProcess.cpp +++ b/src/libslic3r/Milling/MillingPostProcess.cpp @@ -8,7 +8,7 @@ namespace Slic3r { void MillingPostProcess::getExtrusionLoop(const Layer* layer, Polygon& poly, Polylines& entrypoints, ExtrusionEntityCollection& out_coll) { - const double milling_diameter = scale_(this->print_config->milling_diameter.get_at(0)); + const coord_t milling_diameter = scale_t(this->print_config->milling_diameter.get_at(0)); //get the longest polyline Polyline best_polyline; @@ -22,8 +22,8 @@ namespace Slic3r { //get two pair of points that are at less than max_dist. int32_t first_point_extract_idx = 1; int32_t first_point_idx = -1; - const double dist_max_square = milling_diameter * milling_diameter / 4; - double best_dist = dist_max_square; + const coordf_t dist_max_square = coordf_t(milling_diameter) * coordf_t(milling_diameter / 4); + coordf_t best_dist = dist_max_square; for (int32_t idx = 0; idx < poly.points.size(); idx++) { if (poly.points[idx].distance_to_square(best_polyline.points[first_point_extract_idx]) < best_dist) { best_dist = poly.points[idx].distance_to_square(best_polyline.points[first_point_extract_idx]); @@ -91,7 +91,7 @@ namespace Slic3r { if (contour.polyline.points.size() > 3) contour.polyline.points.push_back(contour.polyline.points[1]); contour.mm3_per_mm = 0; - contour.width = this->print_config->milling_diameter.get_at(0); + contour.width = (float)this->print_config->milling_diameter.get_at(0); contour.height = (float)layer->height; out_coll.append(std::move(contour)); return; @@ -102,18 +102,18 @@ namespace Slic3r { { if (!can_be_milled(layer)) return ExtrusionEntityCollection(); - const double milling_diameter = scale_(this->print_config->milling_diameter.get_at(0)); + const coord_t milling_diameter = scale_t(this->print_config->milling_diameter.get_at(0)); ExPolygons milling_lines; for (const Surface& surf : slices->surfaces) { - ExPolygons surf_milling = offset_ex(surf.expolygon, milling_diameter/2, ClipperLib::jtRound); + ExPolygons surf_milling = offset_ex(surf.expolygon, double(milling_diameter / 2), ClipperLib::jtRound); for (const ExPolygon& expoly : surf_milling) // expoly.simplify(SCALED_RESOLUTION, &milling_lines); // should already be done milling_lines.push_back(expoly); } milling_lines = union_ex(milling_lines); - ExPolygons secured_points = offset_ex(milling_lines, milling_diameter / 3); + ExPolygons secured_points = offset_ex(milling_lines, double(milling_diameter / 3)); ExPolygons entrypoints; for (const ExPolygon& expoly : secured_points) // expoly.simplify(SCALED_RESOLUTION, &entrypoints); // should already be done diff --git a/src/libslic3r/Polyline.hpp b/src/libslic3r/Polyline.hpp index 4abf3b66f..d3250484a 100644 --- a/src/libslic3r/Polyline.hpp +++ b/src/libslic3r/Polyline.hpp @@ -154,7 +154,7 @@ class ThickPolyline : public Polyline { public: enum StartPos : int8_t{tpspBegin = -1, tpspBoth = 0, tpspEnd = 1}; /// width size must be == point size - std::vector width; + std::vector width; /// if true => it's an endpoint, if false it join an other ThickPolyline. first is at front(), second is at back() std::pair endpoints; //if it's important to begin at a specific bit. diff --git a/src/libslic3r/libslic3r.h b/src/libslic3r/libslic3r.h index 71103513b..98c3778f3 100644 --- a/src/libslic3r/libslic3r.h +++ b/src/libslic3r/libslic3r.h @@ -99,11 +99,10 @@ extern Semver SEMVER; template inline T unscale(Q v) { return T(v) * T(SCALING_FACTOR); } -inline double unscaled(double v) { return v * SCALING_FACTOR; } -inline coordf_t unscale_(coord_t v) { return v * SCALING_FACTOR; } -inline coord_t scale_t(coordf_t v) { return (coord_t)(v * UNSCALING_FACTOR); } -inline double scale_d(coordf_t v) { return (v * UNSCALING_FACTOR); } -inline double scale_d(coord_t v) { return (double(v) * UNSCALING_FACTOR); } +inline double unscaled(coord_t v) { return double(v) * SCALING_FACTOR; } +inline double unscaled(coordf_t v) { return v * SCALING_FACTOR; } +inline coord_t scale_t(double v) { return coord_t(v * UNSCALING_FACTOR); } +inline coordf_t scale_d(double v) { return coordf_t(v * UNSCALING_FACTOR); } enum Axis { X=0,