Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unexpected type casting issues #2139

Merged
merged 6 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ConicalOverhang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void ConicalOverhang::apply(Slicer* slicer, const Mesh& mesh)
const coord_t layer_thickness = mesh.settings_.get<coord_t>("layer_height");
coord_t max_dist_from_lower_layer = std::llround(tan_angle * static_cast<double>(layer_thickness)); // max dist which can be bridged

for (LayerIndex layer_nr = slicer->layers.size() - 2; static_cast<int>(layer_nr) >= 0; layer_nr--)
for (LayerIndex layer_nr = LayerIndex(slicer->layers.size()) - 2; layer_nr >= 0; layer_nr--)
{
SlicerLayer& layer = slicer->layers[static_cast<size_t>(layer_nr)];
SlicerLayer& layer_above = slicer->layers[static_cast<size_t>(layer_nr) + 1ul];
Expand Down
29 changes: 13 additions & 16 deletions src/FffGcodeWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ void FffGcodeWriter::processRaft(const SliceDataStorage& storage)
const size_t surface_extruder_nr = mesh_group_settings.get<ExtruderTrain&>("raft_surface_extruder_nr").extruder_nr_;

coord_t z = 0;
const LayerIndex initial_raft_layer_nr = -Raft::getTotalExtraLayers();
const LayerIndex initial_raft_layer_nr = -LayerIndex(Raft::getTotalExtraLayers());
const Settings& interface_settings = mesh_group_settings.get<ExtruderTrain&>("raft_interface_extruder_nr").settings_;
const size_t num_interface_layers = interface_settings.get<size_t>("raft_interface_layers");
const Settings& surface_settings = mesh_group_settings.get<ExtruderTrain&>("raft_surface_extruder_nr").settings_;
Expand Down Expand Up @@ -764,7 +764,7 @@ void FffGcodeWriter::processRaft(const SliceDataStorage& storage)

z += raft_interface_z_offset;

for (LayerIndex raft_interface_layer = 1; static_cast<size_t>(raft_interface_layer) <= num_interface_layers; ++raft_interface_layer)
for (LayerIndex raft_interface_layer = 1; raft_interface_layer <= LayerIndex(num_interface_layers); ++raft_interface_layer)
{ // raft interface layer
const LayerIndex layer_nr = initial_raft_layer_nr + raft_interface_layer;
z += interface_layer_height;
Expand Down Expand Up @@ -925,7 +925,7 @@ void FffGcodeWriter::processRaft(const SliceDataStorage& storage)

z += raft_surface_z_offset;

for (LayerIndex raft_surface_layer = 1; static_cast<size_t>(raft_surface_layer) <= num_surface_layers; raft_surface_layer++)
for (LayerIndex raft_surface_layer = 1; raft_surface_layer <= LayerIndex(num_surface_layers); raft_surface_layer++)
{ // raft surface layers
const LayerIndex layer_nr = initial_raft_layer_nr + 1 + num_interface_layers + raft_surface_layer - 1; // +1: 1 base layer
z += surface_layer_height;
Expand Down Expand Up @@ -1538,7 +1538,7 @@ void FffGcodeWriter::calculateExtruderOrderPerLayer(const SliceDataStorage& stor
extruder_order_per_layer.init(true, storage.print_layer_count);

const std::vector<bool> extruders_used = storage.getExtrudersUsed();
for (LayerIndex layer_nr = -Raft::getTotalExtraLayers(); layer_nr < static_cast<LayerIndex>(storage.print_layer_count); layer_nr++)
for (LayerIndex layer_nr = -LayerIndex(Raft::getTotalExtraLayers()); layer_nr < LayerIndex(storage.print_layer_count); layer_nr++)
{
std::vector<ExtruderUse> extruder_order = getUsedExtrudersOnLayer(storage, last_extruder, layer_nr, extruders_used);
extruder_order_per_layer.push_back(extruder_order);
Expand All @@ -1557,7 +1557,7 @@ void FffGcodeWriter::calculateExtruderOrderPerLayer(const SliceDataStorage& stor

void FffGcodeWriter::calculatePrimeLayerPerExtruder(const SliceDataStorage& storage)
{
LayerIndex first_print_layer = -Raft::getTotalExtraLayers();
LayerIndex first_print_layer = -LayerIndex(Raft::getTotalExtraLayers());
for (size_t extruder_nr = 0; extruder_nr < MAX_EXTRUDERS; ++extruder_nr)
{
if (getExtruderNeedPrimeBlobDuringFirstLayer(storage, extruder_nr))
Expand All @@ -1567,7 +1567,7 @@ void FffGcodeWriter::calculatePrimeLayerPerExtruder(const SliceDataStorage& stor
}
}

for (LayerIndex layer_nr = first_print_layer; layer_nr < static_cast<LayerIndex>(storage.print_layer_count); ++layer_nr)
for (LayerIndex layer_nr = first_print_layer; layer_nr < LayerIndex(storage.print_layer_count); ++layer_nr)
{
const std::vector<bool> used_extruders = storage.getExtrudersUsed(layer_nr);
for (size_t extruder_nr = 0; extruder_nr < used_extruders.size(); ++extruder_nr)
Expand All @@ -1591,7 +1591,7 @@ std::vector<ExtruderUse> FffGcodeWriter::getUsedExtrudersOnLayer(
assert(static_cast<int>(extruder_count) > 0);
std::vector<ExtruderUse> ret;
std::vector<bool> extruder_is_used_on_this_layer = storage.getExtrudersUsed(layer_nr);
const LayerIndex raft_base_layer_nr = -Raft::getTotalExtraLayers();
const LayerIndex raft_base_layer_nr = -LayerIndex(Raft::getTotalExtraLayers());
Raft::LayerType layer_type = Raft::getLayerType(layer_nr);

if (layer_type == Raft::RaftBase)
Expand Down Expand Up @@ -1827,8 +1827,7 @@ void FffGcodeWriter::addMeshPartToGCode(
added_something = added_something | processSkin(storage, gcode_layer, mesh, extruder_nr, mesh_config, part);

// After a layer part, make sure the nozzle is inside the comb boundary, so we do not retract on the perimeter.
if (added_something
&& (! mesh_group_settings.get<bool>("magic_spiralize") || gcode_layer.getLayerNr() < static_cast<LayerIndex>(mesh.settings.get<size_t>("initial_bottom_layers"))))
if (added_something && (! mesh_group_settings.get<bool>("magic_spiralize") || gcode_layer.getLayerNr() < LayerIndex(mesh.settings.get<size_t>("initial_bottom_layers"))))
{
coord_t innermost_wall_line_width = mesh.settings.get<coord_t>((mesh.settings.get<size_t>("wall_line_count") > 1) ? "wall_line_width_x" : "wall_line_width_0");
if (gcode_layer.getLayerNr() == 0)
Expand Down Expand Up @@ -2930,20 +2929,18 @@ bool FffGcodeWriter::processInsets(
if (Application::getInstance().current_slice_->scene.current_mesh_group->settings.get<bool>("magic_spiralize"))
{
const size_t initial_bottom_layers = mesh.settings.get<size_t>("initial_bottom_layers");
wawanbreton marked this conversation as resolved.
Show resolved Hide resolved
const int layer_nr = gcode_layer.getLayerNr();
if ((layer_nr < static_cast<LayerIndex>(initial_bottom_layers)
&& part.wall_toolpaths.empty()) // The bottom layers in spiralize mode are generated using the variable width paths
|| (layer_nr >= static_cast<LayerIndex>(initial_bottom_layers) && part.spiral_wall.empty())) // The rest of the layers in spiralize mode are using the spiral wall
const auto layer_nr = gcode_layer.getLayerNr();
if ((layer_nr < LayerIndex(initial_bottom_layers) && part.wall_toolpaths.empty()) // The bottom layers in spiralize mode are generated using the variable width paths
|| (layer_nr >= LayerIndex(initial_bottom_layers) && part.spiral_wall.empty())) // The rest of the layers in spiralize mode are using the spiral wall
{
// nothing to do
return false;
}
if (gcode_layer.getLayerNr() >= static_cast<LayerIndex>(initial_bottom_layers))
if (gcode_layer.getLayerNr() >= LayerIndex(initial_bottom_layers))
{
spiralize = true;
}
if (spiralize && gcode_layer.getLayerNr() == static_cast<LayerIndex>(initial_bottom_layers)
&& extruder_nr == mesh.settings.get<ExtruderTrain&>("wall_0_extruder_nr").extruder_nr_)
if (spiralize && gcode_layer.getLayerNr() == LayerIndex(initial_bottom_layers) && extruder_nr == mesh.settings.get<ExtruderTrain&>("wall_0_extruder_nr").extruder_nr_)
{ // on the last normal layer first make the outer wall normally and then start a second outer wall from the same hight, but gradually moving upward
added_something = true;
gcode_layer.setIsInside(true); // going to print stuff inside print object
Expand Down
8 changes: 4 additions & 4 deletions src/FffPolygonGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ void FffPolygonGenerator::processInfillMesh(SliceDataStorage& storage, const siz
coord_t surface_line_width = mesh.settings.get<coord_t>("wall_line_width_0");

mesh.layer_nr_max_filled_layer = -1;
for (LayerIndex layer_idx = 0; layer_idx < static_cast<LayerIndex>(mesh.layers.size()); layer_idx++)
for (LayerIndex layer_idx = 0; layer_idx < LayerIndex(mesh.layers.size()); layer_idx++)
{
SliceLayer& layer = mesh.layers[layer_idx];

Expand Down Expand Up @@ -585,7 +585,7 @@ void FffPolygonGenerator::processInfillMesh(SliceDataStorage& storage, const siz
break; // all previous meshes have been processed
}
SliceMeshStorage& other_mesh = *storage.meshes[other_mesh_idx];
if (layer_idx >= static_cast<LayerIndex>(other_mesh.layers.size()))
if (layer_idx >= LayerIndex(other_mesh.layers.size()))
{ // there can be no interaction between the infill mesh and this other non-infill mesh
continue;
}
Expand Down Expand Up @@ -875,7 +875,7 @@ void FffPolygonGenerator::computePrintHeightStatistics(SliceDataStorage& storage
}
for (size_t extruder_nr = 0; extruder_nr < extruder_count; extruder_nr++)
{
for (LayerIndex layer_nr = static_cast<LayerIndex>(mesh.layers.size()) - 1; layer_nr > max_print_height_per_extruder[extruder_nr]; layer_nr--)
for (LayerIndex layer_nr = LayerIndex(mesh.layers.size()) - 1; layer_nr > max_print_height_per_extruder[extruder_nr]; layer_nr--)
{
if (mesh.getExtruderIsUsed(extruder_nr, layer_nr))
{
Expand Down Expand Up @@ -1097,7 +1097,7 @@ void FffPolygonGenerator::processFuzzyWalls(SliceMeshStorage& mesh)
return false;
};

for (LayerIndex layer_nr = start_layer_nr; layer_nr < mesh.layers.size(); layer_nr++)
for (LayerIndex layer_nr = start_layer_nr; layer_nr < LayerIndex(mesh.layers.size()); layer_nr++)
{
SliceLayer& layer = mesh.layers[layer_nr];
for (SliceLayerPart& part : layer.parts)
Expand Down
4 changes: 2 additions & 2 deletions src/InterlockingGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,10 @@ void InterlockingGenerator::addBoundaryCells(const std::vector<Shape>& layers, c

std::vector<Shape> InterlockingGenerator::computeUnionedVolumeRegions() const
{
const size_t max_layer_count = std::max(mesh_a_.layers.size(), mesh_b_.layers.size()) + 1; // introduce ghost layer on top for correct skin computation of topmost layer.
const auto max_layer_count = std::max(mesh_a_.layers.size(), mesh_b_.layers.size()) + 1; // introduce ghost layer on top for correct skin computation of topmost layer.
std::vector<Shape> layer_regions(max_layer_count);

for (LayerIndex layer_nr = 0; layer_nr < max_layer_count; layer_nr++)
for (LayerIndex layer_nr = 0; layer_nr < LayerIndex(max_layer_count); layer_nr++)
{
Shape& layer_region = layer_regions[static_cast<size_t>(layer_nr)];
for (Slicer* mesh : { &mesh_a_, &mesh_b_ })
Expand Down
4 changes: 2 additions & 2 deletions src/slicer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1017,13 +1017,13 @@ void Slicer::makePolygons(Mesh& mesh, SlicingTolerance slicing_tolerance, std::v
switch (slicing_tolerance)
{
case SlicingTolerance::INCLUSIVE:
for (LayerIndex layer_nr = 0; layer_nr + 1 < layers.size(); layer_nr++)
for (size_t layer_nr = 0; layer_nr + 1 < layers.size(); layer_nr++)
{
layers[layer_nr].polygons_ = layers[layer_nr].polygons_.unionPolygons(layers[layer_nr + 1].polygons_);
}
break;
case SlicingTolerance::EXCLUSIVE:
for (LayerIndex layer_nr = 0; layer_nr + 1 < layers.size(); layer_nr++)
for (size_t layer_nr = 0; layer_nr + 1 < layers.size(); layer_nr++)
{
layers[layer_nr].polygons_ = layers[layer_nr].polygons_.intersection(layers[layer_nr + 1].polygons_);
}
Expand Down
Loading