<commit_before>package Slic3r::Fill::Rectilinear;
use Moo;

extends 'Slic3r::Fill::Base';

has 'cache'         => (is => 'rw', default => sub {{}});

use Slic3r::Geometry qw(X1 Y1 X2 Y2 A B X Y scale unscale scaled_epsilon);

sub fill_surface {
    my $self = shift;
    my ($surface, %params) = @_;
    
    # rotate polygons so that we can work with vertical lines here
    my $expolygon = $surface->expolygon->clone;
    my $rotate_vector = $self->infill_direction($surface);
    $self->rotate_points($expolygon, $rotate_vector);
    
    my ($expolygon_off) = $expolygon->offset_ex(scale $params{flow_spacing}/2);
    return {} if !$expolygon_off;  # skip some very small polygons (which shouldn't arrive here)
    
    my $flow_spacing = $params{flow_spacing};
    my $min_spacing = scale $params{flow_spacing};
    my $distance_between_lines = $min_spacing / $params{density};
    my $line_oscillation = $distance_between_lines - $min_spacing;
    my $is_line_pattern = $self->isa('Slic3r::Fill::Line');
    
    my $cache_id = sprintf "d%s_s%s_a%s",
        $params{density}, $params{flow_spacing}, $rotate_vector->[0][0];
    
    if (!$self->cache->{$cache_id}) {
        # compute bounding box
        my $bounding_box = $self->bounding_box;
        {
            my $bb_expolygon = Slic3r::ExPolygon->new(Slic3r::Polygon->new_from_bounding_box($bounding_box));
            $self->rotate_points($bb_expolygon, $rotate_vector);
            $bounding_box = [ $bb_expolygon->bounding_box ];
        }
        
        # define flow spacing according to requested density
        if ($params{density} == 1 && !$params{dont_adjust}) {
            $distance_between_lines = $self->adjust_solid_spacing(
                width       => $bounding_box->[X2] - $bounding_box->[X1],
                distance    => $distance_between_lines,
            );
            $flow_spacing = unscale $distance_between_lines;
        }
        
        # generate the basic pattern
        my $x = $bounding_box->[X1];
        my @vertical_lines = ();
        for (my $i = 0; $x <= $bounding_box->[X2] + scaled_epsilon; $i++) {
            my $vertical_line = Slic3r::Line->new([$x, $bounding_box->[Y2]], [$x, $bounding_box->[Y1]]);
            if ($is_line_pattern && $i % 2) {
                $vertical_line->[A][X] += $line_oscillation;
                $vertical_line->[B][X] -= $line_oscillation;<commit_msg>Fix for rectilinear infill failing in plates with new caching<commit_after>package Slic3r::Fill::Rectilinear;
use Moo;

extends 'Slic3r::Fill::Base';

has 'cache'         => (is => 'rw', default => sub {{}});

use Slic3r::Geometry qw(X1 Y1 X2 Y2 A B X Y scale unscale scaled_epsilon);

sub fill_surface {
    my $self = shift;
    my ($surface, %params) = @_;
    
    # rotate polygons so that we can work with vertical lines here
    my $expolygon = $surface->expolygon->clone;
    my $rotate_vector = $self->infill_direction($surface);
    $self->rotate_points($expolygon, $rotate_vector);
    
    my ($expolygon_off) = $expolygon->offset_ex(scale $params{flow_spacing}/2);
    return {} if !$expolygon_off;  # skip some very small polygons (which shouldn't arrive here)
    
    my $flow_spacing = $params{flow_spacing};
    my $min_spacing = scale $params{flow_spacing};
    my $distance_between_lines = $min_spacing / $params{density};
    my $line_oscillation = $distance_between_lines - $min_spacing;
    my $is_line_pattern = $self->isa('Slic3r::Fill::Line');
    
    my $cache_id = sprintf "d%s_s%s_a%s",
        $params{density}, $params{flow_spacing}, $rotate_vector->[0][0];
    
    if (!$self->cache->{$cache_id}) {
        # compute bounding box
        my $bounding_box = [ @{$self->bounding_box} ];  # clone
        $bounding_box->[$_] = 0 for X1, Y1;
        {
            my $bb_expolygon = Slic3r::ExPolygon->new(Slic3r::Polygon->new_from_bounding_box($bounding_box));
            $self->rotate_points($bb_expolygon, $rotate_vector);
            $bounding_box = [ $bb_expolygon->bounding_box ];
        }
        
        # define flow spacing according to requested density
        if ($params{density} == 1 && !$params{dont_adjust}) {
            $distance_between_lines = $self->adjust_solid_spacing(
                width       => $bounding_box->[X2] - $bounding_box->[X1],
                distance    => $distance_between_lines,
            );
            $flow_spacing = unscale $distance_between_lines;
        }
        
        # generate the basic pattern
        my $x = $bounding_box->[X1];
        my @vertical_lines = ();
        for (my $i = 0; $x <= $bounding_box->[X2] + scaled_epsilon; $i++) {
            my $vertical_line = Slic3r::Line->new([$x, $bounding_box->[Y2]], [$x, $bounding_box->[Y1]]);
            if ($is_line_pattern && $i % 2) {
                $vertical_line->[A][X] += $line_oscillation;
                $vertical_line->[B][X] -= $line_oscillation;
{'fraction_non_alphanumeric': 0.14818589482266611, 'fraction_numerical': 0.009987770077456177, 'mean_word_length': 2.83359375, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 62, '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': '2621583', 'n_tokens_mistral': 1696, 'n_tokens_neox': 1632, 'n_words': 334}