<commit_before>use Test::More;
use strict;
use warnings;

plan tests => 32;

BEGIN {
    use FindBin;
    use lib "$FindBin::Bin/../lib";
}

use Slic3r;
use Slic3r::Geometry qw(scale X Y);
use Slic3r::Geometry::Clipper qw(diff_ex);
use Slic3r::Surface qw(:types);
use Slic3r::Test;

sub scale_points (@) { map [scale $_->[X], scale $_->[Y]], @_ }

{
    my $print = Slic3r::Print->new;
    $print->init_extruders;
    my $filler = Slic3r::Fill::Rectilinear->new(
        print           => $print,
        bounding_box    => Slic3r::Geometry::BoundingBox->new_from_points([ [0, 0], [10, 10] ]),
    );
    my $surface_width = 250;
    my $distance = $filler->adjust_solid_spacing(
        width       => $surface_width,
        distance    => 100,
    );
    is $distance, 125, 'adjusted solid distance';
    is $surface_width % $distance, 0, 'adjusted solid distance';
}

{
    my $expolygon = Slic3r::ExPolygon->new([ scale_points [0,0], [50,0], [50,50], [0,50] ]);
    my $filler = Slic3r::Fill::Rectilinear->new(
        bounding_box => $expolygon->bounding_box,
    );
    my $surface = Slic3r::Surface->new(
        surface_type    => S_TYPE_TOP,
        expolygon       => $expolygon,
    );
    foreach my $angle (0, 45) {
        $surface->expolygon->rotate(Slic3r::Geometry::deg2rad($angle), [0,0]);
        my ($params, @paths) = $filler->fill_surface($surface, flow_spacing => 0.69, density => 0.4);
        is scalar @paths, 1, 'one continuous path';
    }
}

{
    my $test = sub {
        my ($expolygon, $flow_spacing) = @_;
        
        my $filler = Slic3r::Fill::Rectilinear->new(
            bounding_box    => $expolygon->bounding_box,
            angle           => 0,
        );
        my $surface = Slic3r::Surface->new(
            surface_type    => S_TYPE_BOTTOM,
            expolygon       => $expolygon,
        );
        my ($params, @paths) = $filler->fill_surface($surface, flow_spacing => $flow_spacing, density => 1);
        
        # check whether any part was left uncovered
        my @grown_paths = map Slic3r::Polyline->new(@$_)->grow(scale $params->{flow_spacing}/2), @paths;
        my $uncovered = diff_ex([ @$expolygon ], [ @grown_paths ], 1);
        
        # ignore very small dots
        @$uncovered = grep $_->area > (scale $flow_spacing)**2, @$uncovered;
        
        is scalar(@$uncovered), 0, 'solid surface is fully filled';
        
        if (0 && @$uncovered) {
            require "Slic3r/SVG.pm";
            Slic3r::SVG::output(
                "uncovered.svg",
                expolygons => [$expolygon],
                red_expolygons => $uncovered,
            );
            exit;
        }
    };
    
    my $expolygon = Slic3r::ExPolygon->new([
        [6883102, 9598327.01296997],
        [6883102, 20327272.01297],
        [3116896, 20327272.01297],
        [3116896, 9598327.01296997],
    ]);
    $test->($expolygon, 0.55);
    
    for (1..20) {
        $expolygon->scale(1.05);
        $test->($expolygon, 0.55);
    }
    
    $expolygon = Slic3r::ExPolygon->new(
        [[59515297,5422499],[59531249,5578697],[59695801,6123186],[59965713,6630228],[60328214,7070685],[60773285,7434379],[61274561,7702115],[61819378,7866770],[62390306,7924789],[62958700,7866744],[63503012,7702244],[64007365,7434357],[64449960,7070398],[64809327,6634999],[65082143,6123325],[65245005,5584454],[65266967,5422499],[66267307,5422499],[66269190,8310081],[66275379,17810072],[66277259,20697500],[65267237,20697500],[65245004,20533538],[65082082,19994444],[64811462,19488579],[64450624,19048208],[64012101,18686514],[63503122,18415781],[62959151,18251378],[62453416,18198442],[62390147,18197355],[62200087,18200576],[61813519,18252990],[61274433,18415918],[60768598,18686517],[60327567,19047892],[59963609,19493297],[59695865,19994587],[59531222,20539379],[59515153,20697500],[58502480,20697500],[58502480,5422499]]
    );
    $test->($expolygon, 0.524341649025257);
}

{
    my $collection = Slic3r::Polyline::Collection->new(polylines => [
        Slic3r::Polyline->new([0,15], [0,18], [0,20]),
        Slic3r::Polyline->new([0,10], [0,8], [0,5]),
    ]);
    is_deeply
        [ map $_->[Y], map @$_, $collection->chained_path(Slic3r::Point->new(0,30)) ],
        [20, 18, 15, 10, 8, 5],
        'chained path';
}

{
    my $collection = Slic3r::Polyline::Collection->new(polylines => [
        Slic3r::Polyline->new([4,0], [10,0], [15,0]),
        Slic3r::Polyline->new([10,5], [15,5], [20,5]),
    ]);
    is_deeply<commit_msg>Regression test for fix 36596bf569a2764f527ab80a26992039daed9c67. #1387<commit_after>use Test::More;
use strict;
use warnings;

plan tests => 33;

BEGIN {
    use FindBin;
    use lib "$FindBin::Bin/../lib";
}

use Slic3r;
use Slic3r::Geometry qw(scale X Y);
use Slic3r::Geometry::Clipper qw(diff_ex);
use Slic3r::Surface qw(:types);
use Slic3r::Test;

sub scale_points (@) { map [scale $_->[X], scale $_->[Y]], @_ }

{
    my $print = Slic3r::Print->new;
    $print->init_extruders;
    my $filler = Slic3r::Fill::Rectilinear->new(
        print           => $print,
        bounding_box    => Slic3r::Geometry::BoundingBox->new_from_points([ [0, 0], [10, 10] ]),
    );
    my $surface_width = 250;
    my $distance = $filler->adjust_solid_spacing(
        width       => $surface_width,
        distance    => 100,
    );
    is $distance, 125, 'adjusted solid distance';
    is $surface_width % $distance, 0, 'adjusted solid distance';
}

{
    my $expolygon = Slic3r::ExPolygon->new([ scale_points [0,0], [50,0], [50,50], [0,50] ]);
    my $filler = Slic3r::Fill::Rectilinear->new(
        bounding_box => $expolygon->bounding_box,
    );
    my $surface = Slic3r::Surface->new(
        surface_type    => S_TYPE_TOP,
        expolygon       => $expolygon,
    );
    foreach my $angle (0, 45) {
        $surface->expolygon->rotate(Slic3r::Geometry::deg2rad($angle), [0,0]);
        my ($params, @paths) = $filler->fill_surface($surface, flow_spacing => 0.69, density => 0.4);
        is scalar @paths, 1, 'one continuous path';
    }
}

{
    my $test = sub {
        my ($expolygon, $flow_spacing, $angle, $density) = @_;
        
        my $filler = Slic3r::Fill::Rectilinear->new(
            bounding_box    => $expolygon->bounding_box,
            angle           => $angle // 0,
        );
        my $surface = Slic3r::Surface->new(
            surface_type    => S_TYPE_BOTTOM,
            expolygon       => $expolygon,
        );
        my ($params, @paths) = $filler->fill_surface(
            $surface,
            flow_spacing    => $flow_spacing,
            density         => $density // 1,
        );
        
        # check whether any part was left uncovered
        my @grown_paths = map Slic3r::Polyline->new(@$_)->grow(scale $params->{flow_spacing}/2), @paths;
        my $uncovered = diff_ex([ @$expolygon ], [ @grown_paths ], 1);
        
        # ignore very small dots
        @$uncovered = grep $_->area > (scale $flow_spacing)**2, @$uncovered;
        
        is scalar(@$uncovered), 0, 'solid surface is fully filled';
        
        if (0 && @$uncovered) {
            require "Slic3r/SVG.pm";
            Slic3r::SVG::output(
                "uncovered.svg",
                expolygons => [$expolygon],
                red_expolygons => $uncovered,
            );
            exit;
        }
    };
    
    my $expolygon = Slic3r::ExPolygon->new([
        [6883102, 9598327.01296997],
        [6883102, 20327272.01297],
        [3116896, 20327272.01297],
        [3116896, 9598327.01296997],
    ]);
    $test->($expolygon, 0.55);
    
    for (1..20) {
        $expolygon->scale(1.05);
        $test->($expolygon, 0.55);
    }
    
    $expolygon = Slic3r::ExPolygon->new(
        [[59515297,5422499],[59531249,5578697],[59695801,6123186],[59965713,6630228],[60328214,7070685],[60773285,7434379],[61274561,7702115],[61819378,7866770],[62390306,7924789],[62958700,7866744],[63503012,7702244],[64007365,7434357],[64449960,7070398],[64809327,6634999],[65082143,6123325],[65245005,5584454],[65266967,5422499],[66267307,5422499],[66269190,8310081],[66275379,17810072],[66277259,20697500],[65267237,20697500],[65245004,20533538],[65082082,19994444],[64811462,19488579],[64450624,19048208],[64012101,18686514],[63503122,18415781],[62959151,18251378],[62453416,18198442],[62390147,18197355],[62200087,18200576],[61813519,18252990],[61274433,18415918],[60768598,18686517],[60327567,19047892],[59963609,19493297],[59695865,19994587],[59531222,20539379],[59515153,20697500],[58502480,20697500],[58502480,5422499]]
    );
    $test->($expolygon, 0.524341649025257);
    
    $expolygon = Slic3r::ExPolygon->new([ scale_points [0,0], [98,0], [98,10], [0,10] ]);
    $test->($expolygon, 0.5, 45, 0.99);  # non-solid infill
}

{
    my $collection = Slic3r::Polyline::Collection->new(polylines => [
        Slic3r::Polyline->new([0,15], [0,18], [0,20]),
        Slic3r::Polyline->new([0,10], [0,8], [0,5]),
    ]);
    is_deeply
        [ map $_->[Y], map @$_, $collection->chained_path(Slic3r::Point->new(0,30)) ],
        [20, 18, 15, 10, 8, 5],
        'chained path';
}

{
    my $collection = Slic3r::Polyline::Collection->new(polylines => [
        Slic3r::Polyline->new([4,0], [10,0], [15,0]),
        Slic3r::Polyline->new([10,5], [15,5], [20,5]),
    ]);
    is_deeply
{'fraction_non_alphanumeric': 0.1815153143471252, 'fraction_numerical': 0.19580870499731326, 'mean_word_length': 3.0268282128948507, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 121, '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': '2380468', 'n_tokens_mistral': 4647, 'n_tokens_neox': 3510, 'n_words': 520}