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

plan tests => 43;

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

use List::Util qw(first sum);
use Slic3r;
use Slic3r::Geometry qw(X Y scale unscale convex_hull);
use Slic3r::Geometry::Clipper qw(union diff_ex offset);
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([ Slic3r::Point->new(0, 0), Slic3r::Point->new(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,
        angle        => 0,
    );
    my $surface = Slic3r::Surface->new(
        surface_type    => S_TYPE_TOP,
        expolygon       => $expolygon,
    );
    my $flow = Slic3r::Flow->new(
        width           => 0.69,
        height          => 0.4,
        nozzle_diameter => 0.50,
    );
    foreach my $angle (0, 45) {
        $surface->expolygon->rotate(Slic3r::Geometry::deg2rad($angle), [0,0]);
        my ($params, @paths) = $filler->fill_surface($surface, flow => $flow, layer_height => 0.4, 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 $flow = Slic3r::Flow->new(
            width           => $flow_spacing,
            height          => 0.4,
            nozzle_diameter => $flow_spacing,
        );
        my ($params, @paths) = $filler->fill_surface(
            $surface,
            flow            => $flow,
            layer_height    => $flow->height,
            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],<commit_msg>Adapt t/fill.t to the new infill internal API<commit_after>use Test::More;
use strict;
use warnings;

plan tests => 43;

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

use List::Util qw(first sum);
use Slic3r;
use Slic3r::Geometry qw(X Y scale unscale convex_hull);
use Slic3r::Geometry::Clipper qw(union diff_ex offset);
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([ Slic3r::Point->new(0, 0), Slic3r::Point->new(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,
        angle        => 0,
    );
    my $surface = Slic3r::Surface->new(
        surface_type    => S_TYPE_TOP,
        expolygon       => $expolygon,
    );
    my $flow = Slic3r::Flow->new(
        width           => 0.69,
        height          => 0.4,
        nozzle_diameter => 0.50,
    );
    $filler->spacing($flow->spacing);
    foreach my $angle (0, 45) {
        $surface->expolygon->rotate(Slic3r::Geometry::deg2rad($angle), [0,0]);
        my @paths = $filler->fill_surface($surface, layer_height => 0.4, 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 $flow = Slic3r::Flow->new(
            width           => $flow_spacing,
            height          => 0.4,
            nozzle_diameter => $flow_spacing,
        );
        $filler->spacing($flow->spacing);
        my @paths = $filler->fill_surface(
            $surface,
            layer_height    => $flow->height,
            density         => $density // 1,
        );
        
        # check whether any part was left uncovered
        my @grown_paths = map @{Slic3r::Polyline->new(@$_)->grow(scale $filler->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],
{'fraction_non_alphanumeric': 0.15491530331547707, 'fraction_numerical': 0.04140726798899667, 'mean_word_length': 2.0245183887915936, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 118, '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': '4831903', 'n_tokens_mistral': 2532, 'n_tokens_neox': 2319, 'n_words': 482}