<commit_before>package Slic3r::STL;
use Moose;

use CAD::Format::STL;
use XXX;

use constant X => 0;
use constant Y => 1;
use constant Z => 2;

sub parse_file {
    my $self = shift;
    my ($file) = @_;
    
    my $print = Slic3r::Print->new;
    
    my $stl = CAD::Format::STL->new->load($file);
    
    # we only want to work with positive coordinates, so let's 
    # find our object extents to calculate coordinate displacements
    my @extents = (map [99999999, -99999999], X,Y,Z);
    foreach my $facet ($stl->part->facets) {
        my ($normal, @vertices) = @$facet;
        foreach my $vertex (@vertices) {
            for (X,Y,Z) {
                $extents[$_][0] = $vertex->[$_] if $vertex->[$_] < $extents[$_][0];
                $extents[$_][1] = $vertex->[$_] if $vertex->[$_] > $extents[$_][0];
            }
        }
    }
    
    # calculate the displacements needed to 
    # have lowest value for each axis at coordinate 0
    my @shift = map 0 - $extents[$_][0], X,Y,Z;
    printf "shift = %d, %d, %d\n", @shift[X,Y,Z];
    
    # process facets
    foreach my $facet ($stl->part->facets) {
        
        # transform vertex coordinates
        my ($normal, @vertices) = @$facet;
        foreach my $vertex (@vertices) {
            $vertex->[$_] = sprintf('%.0f', ($vertex->[$_] + $shift[$_]) / $Slic3r::resolution) 
                for X,Y,Z;
        }
        
        $self->_facet($print, @$facet);
    }
    
    print "\n==> PROCESSING SLICES:\n";
    foreach my $layer (@{ $print->layers }) {
        printf "Processing layer %d:\n", $layer->id;
    <commit_msg>Bugfix (harmless for now) in calculation of extents; using constants now for code readability<commit_after>package Slic3r::STL;
use Moose;

use CAD::Format::STL;
use XXX;

use constant X => 0;
use constant Y => 1;
use constant Z => 2;
use constant MIN => 0;
use constant MAX => 1;

sub parse_file {
    my $self = shift;
    my ($file) = @_;
    
    my $print = Slic3r::Print->new;
    
    my $stl = CAD::Format::STL->new->load($file);
    
    # we only want to work with positive coordinates, so let's 
    # find our object extents to calculate coordinate displacements
    my @extents = (map [99999999, -99999999], X,Y,Z);
    foreach my $facet ($stl->part->facets) {
        my ($normal, @vertices) = @$facet;
        foreach my $vertex (@vertices) {
            for (X,Y,Z) {
                $extents[$_][MIN] = $vertex->[$_] if $vertex->[$_] < $extents[$_][MIN];
                $extents[$_][MAX] = $vertex->[$_] if $vertex->[$_] > $extents[$_][MAX];
            }
        }
    }
    
    # calculate the displacements needed to 
    # have lowest value for each axis at coordinate 0
    my @shift = map 0 - $extents[$_][MIN], X,Y,Z;
    printf "shift = %d, %d, %d\n", @shift[X,Y,Z];
    
    # process facets
    foreach my $facet ($stl->part->facets) {
        
        # transform vertex coordinates
        my ($normal, @vertices) = @$facet;
        foreach my $vertex (@vertices) {
            $vertex->[$_] = sprintf('%.0f', ($vertex->[$_] + $shift[$_]) / $Slic3r::resolution) 
                for X,Y,Z;
        }
        
        $self->_facet($print, @$facet);
    }
    
    print "\n==> PROCESSING SLICES:\n";
    foreach my $layer (@{ $print->layers }) {
        printf "Processing layer %d:\n", $layer->id;
    
{'fraction_non_alphanumeric': 0.17376950780312125, 'fraction_numerical': 0.017106842737094837, 'mean_word_length': 2.274066797642436, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, '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': '5349777', 'n_tokens_mistral': 1202, 'n_tokens_neox': 1136, 'n_words': 313}