Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Line.pm « Slic3r « lib - github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 541689d242901b79e56a0fa141d2b1aaa21d3613 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package Slic3r::Line;
use strict;
use warnings;

use Slic3r::Geometry qw(A B X Y);

sub new {
    my $class = shift;
    my $self;
    if (@_ == 2) {
        $self = [ @_ ];
    } elsif (ref $_[0] eq 'ARRAY') {
        $self = [ $_[0][0], $_[0][1] ];
    } elsif ($_[0]->isa(__PACKAGE__)) {
        return $_[0];
    } else {
        die "Invalid argument for $class->new";
    }
    bless $self, $class;
    bless $_, 'Slic3r::Point' for @$self;
    return $self;
}

sub cast {
    my $class = shift;
    my ($line) = @_;
    return $line if ref $line eq __PACKAGE__;
    return $class->new($line);
}

sub a { $_[0][0] }
sub b { $_[0][1] }

sub id {
    my $self = shift;
    return $self->a->id . "-" . $self->b->id;
}

sub ordered_id {
    my $self = shift;
    return join('-', sort map $_->id, @$self);
}

sub coordinates {
    my $self = shift;
    return ($self->a->coordinates, $self->b->coordinates);
}

sub coincides_with {
    my $self = shift;
    my ($line) = @_;
    
    return ($self->a->coincides_with($line->a) && $self->b->coincides_with($line->b))
        || ($self->a->coincides_with($line->b) && $self->b->coincides_with($line->a));
}

sub has_endpoint {
    my $self = shift;
    my ($point) = @_;
    return $point->coincides_with($self->a) || $point->coincides_with($self->b);
}

sub has_segment {
    my $self = shift;
    my ($line) = @_;
    
    # a segment belongs to another segment if its points belong to it
    return Slic3r::Geometry::point_in_segment($line->[0], $self)
        && Slic3r::Geometry::point_in_segment($line->[1], $self);
}

sub parallel_to {
    my $self = shift;
    my ($line) = @_;
    return Slic3r::Geometry::lines_parallel($self, $line);
}

sub length {
    my $self = shift;
    return Slic3r::Geometry::line_length($self);
}

sub atan {
    my $self = shift;
    return Slic3r::Geometry::line_atan($self);
}

sub direction {
    my $self = shift;
    return Slic3r::Geometry::line_direction($self);
}

sub intersection {
    my $self = shift;
    my ($line, $require_crossing) = @_;
    return Slic3r::Geometry::line_intersection($self, $line, $require_crossing);
}

sub point_on_left {
    my $self = shift;
    my ($point) = @_;
    return Slic3r::Geometry::point_is_on_left_of_segment($point, $self);
}

sub midpoint {
    my $self = shift;
    return Slic3r::Point->new(
        ($self->[A][X] + $self->[B][X]) / 2,
        ($self->[A][Y] + $self->[B][Y]) / 2,
    );
}

sub reverse {
    my $self = shift;
    @$self = reverse @$self;
}

1;