<commit_before>/** Copyright (C) 2013 <NAME> - Released under terms of the AGPLv3 License */
#include "infill.h"
#include "functional"
#include "utils/polygonUtils.h"
#include "utils/logoutput.h"

namespace cura {

int Infill::computeScanSegmentIdx(int x, int line_width)
{
    if (x < 0)
    {
        return (x + 1) / line_width - 1;
        // - 1 because -1 belongs to scansegment -1
        // + 1 because -line_width belongs to scansegment -1
    }
    return x / line_width;
}

void Infill::generate(Polygons& result_polygons, Polygons& result_lines)
{
    if (in_outline.size() == 0) return;
    if (line_distance == 0) return;
    Polygons outline_offsetted;
    switch(pattern)
    {
    case EFillMethod::GRID:
        generateGridInfill(result_lines);
        break;
    case EFillMethod::LINES:
        generateLineInfill(result_lines, line_distance, fill_angle, 0);
        break;
    case EFillMethod::CUBIC:
        generateCubicInfill(result_lines);
        break;
    case EFillMethod::TETRAHEDRAL:
        generateTetrahedralInfill(result_lines);
        break;
    case EFillMethod::TRIANGLES:
        generateTriangleInfill(result_lines);
        break;
    case EFillMethod::CONCENTRIC:
        outline_offsetted = in_outline.offset(outline_offset - infill_line_width / 2); // - infill_line_width / 2 cause generateConcentricInfill expects [outline] to be the outer most polygon instead of the outer outline 
        generateConcentricInfill(outline_offsetted, result_polygons, line_distance);
        break;
    case EFillMethod::CONCENTRIC_3D:
        generateConcentric3DInfill(result_polygons);
        break;
    case EFillMethod::ZIG_ZAG:
        generateZigZagInfill(result_lines, line_distance, fill_angle, connected_zigzags, use_endpieces);
        break;
    default:
        logError("Fill pattern has unknown value.\n");
        break;
    }
}

void Infill::generateConcentricInfill(Polygons& first_concentric_wall, Polygons& result, int inset_value)
{
    while(first_concentric_wall.size() > 0)
    {
        result.add(first_concentric_wall);
        first_concentric_wall = first_concentric_wall.offset(-inset_value);
    } 
}

void Infill::generateConcentric3DInfill(Polygons& result)
{
    int period = line_distance * 2;
    int shift = int64_t(one_over_sqrt_2 * z) % period;<commit_msg>fix: concentric infill doesn't start right next to the inner wall any more (CURA-2772)<commit_after>/** Copyright (C) 2013 <NAME> - Released under terms of the AGPLv3 License */
#include "infill.h"
#include "functional"
#include "utils/polygonUtils.h"
#include "utils/logoutput.h"

namespace cura {

int Infill::computeScanSegmentIdx(int x, int line_width)
{
    if (x < 0)
    {
        return (x + 1) / line_width - 1;
        // - 1 because -1 belongs to scansegment -1
        // + 1 because -line_width belongs to scansegment -1
    }
    return x / line_width;
}

void Infill::generate(Polygons& result_polygons, Polygons& result_lines)
{
    if (in_outline.size() == 0) return;
    if (line_distance == 0) return;
    Polygons outline_offsetted;
    switch(pattern)
    {
    case EFillMethod::GRID:
        generateGridInfill(result_lines);
        break;
    case EFillMethod::LINES:
        generateLineInfill(result_lines, line_distance, fill_angle, 0);
        break;
    case EFillMethod::CUBIC:
        generateCubicInfill(result_lines);
        break;
    case EFillMethod::TETRAHEDRAL:
        generateTetrahedralInfill(result_lines);
        break;
    case EFillMethod::TRIANGLES:
        generateTriangleInfill(result_lines);
        break;
    case EFillMethod::CONCENTRIC:
        outline_offsetted = in_outline.offset(outline_offset - line_distance + infill_line_width / 2); // - infill_line_width / 2 cause generateConcentricInfill expects [outline] to be the outer most polygon instead of the outer outline
        generateConcentricInfill(outline_offsetted, result_polygons, line_distance);
        break;
    case EFillMethod::CONCENTRIC_3D:
        generateConcentric3DInfill(result_polygons);
        break;
    case EFillMethod::ZIG_ZAG:
        generateZigZagInfill(result_lines, line_distance, fill_angle, connected_zigzags, use_endpieces);
        break;
    default:
        logError("Fill pattern has unknown value.\n");
        break;
    }
}

void Infill::generateConcentricInfill(Polygons& first_concentric_wall, Polygons& result, int inset_value)
{
    while(first_concentric_wall.size() > 0)
    {
        result.add(first_concentric_wall);
        first_concentric_wall = first_concentric_wall.offset(-inset_value);
    } 
}

void Infill::generateConcentric3DInfill(Polygons& result)
{
    int period = line_distance * 2;
    int shift = int64_t(one_over_sqrt_2 * z) % period;
{'fraction_non_alphanumeric': 0.09317032040472176, 'fraction_numerical': 0.011804384485666104, 'mean_word_length': 3.4180633147113593, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7436579', 'n_tokens_mistral': 1600, 'n_tokens_neox': 1533, 'n_words': 335}