2011-10-04 15:55:55 +00:00
|
|
|
use Test::More;
|
2011-10-10 09:00:19 +00:00
|
|
|
use strict;
|
|
|
|
use warnings;
|
2011-10-04 15:55:55 +00:00
|
|
|
|
2013-09-09 22:40:46 +00:00
|
|
|
plan skip_all => 'temporarily disabled';
|
2013-09-12 09:09:03 +00:00
|
|
|
plan tests => 16;
|
2011-10-04 15:55:55 +00:00
|
|
|
|
|
|
|
BEGIN {
|
|
|
|
use FindBin;
|
|
|
|
use lib "$FindBin::Bin/../lib";
|
2017-08-18 07:58:50 +00:00
|
|
|
use local::lib "$FindBin::Bin/../local-lib";
|
2011-10-04 15:55:55 +00:00
|
|
|
}
|
|
|
|
|
2013-09-12 09:09:03 +00:00
|
|
|
# temporarily disable compilation errors due to constant not being exported anymore
|
|
|
|
sub Slic3r::TriangleMesh::I_B {}
|
|
|
|
sub Slic3r::TriangleMesh::I_FACET_EDGE {}
|
|
|
|
sub Slic3r::TriangleMesh::FE_BOTTOM {
|
|
|
|
sub Slic3r::TriangleMesh::FE_TOP {}}
|
|
|
|
|
2011-10-04 15:55:55 +00:00
|
|
|
use Slic3r;
|
2017-07-19 08:45:39 +00:00
|
|
|
use Slic3r::Geometry qw(X Y Z);
|
2011-10-04 15:55:55 +00:00
|
|
|
|
|
|
|
my @lines;
|
|
|
|
my $z = 20;
|
2011-12-22 10:24:46 +00:00
|
|
|
my @points = ([3, 4], [8, 5], [1, 9]); # XY coordinates of the facet vertices
|
2011-10-04 15:55:55 +00:00
|
|
|
|
2012-05-01 10:18:59 +00:00
|
|
|
# NOTE:
|
|
|
|
# the first point of the intersection lines is replaced by -1 because TriangleMesh.pm
|
|
|
|
# is saving memory and doesn't store point A anymore since it's not actually needed.
|
|
|
|
|
2013-06-22 18:32:39 +00:00
|
|
|
# We disable this test because intersect_facet() now assumes we never feed a horizontal
|
|
|
|
# facet to it.
|
|
|
|
# is_deeply lines(20, 20, 20), [
|
|
|
|
# [ -1, $points[1] ], # $points[0]
|
|
|
|
# [ -1, $points[2] ], # $points[1]
|
|
|
|
# [ -1, $points[0] ], # $points[2]
|
|
|
|
# ], 'horizontal';
|
2011-10-04 15:55:55 +00:00
|
|
|
|
2012-05-01 10:18:59 +00:00
|
|
|
is_deeply lines(22, 20, 20), [ [ -1, $points[2] ] ], 'lower edge on layer'; # $points[1]
|
|
|
|
is_deeply lines(20, 20, 22), [ [ -1, $points[1] ] ], 'lower edge on layer'; # $points[0]
|
|
|
|
is_deeply lines(20, 22, 20), [ [ -1, $points[0] ] ], 'lower edge on layer'; # $points[2]
|
2011-12-22 10:24:46 +00:00
|
|
|
|
2012-05-01 10:18:59 +00:00
|
|
|
is_deeply lines(20, 20, 10), [ [ -1, $points[0] ] ], 'upper edge on layer'; # $points[1]
|
|
|
|
is_deeply lines(10, 20, 20), [ [ -1, $points[1] ] ], 'upper edge on layer'; # $points[2]
|
|
|
|
is_deeply lines(20, 10, 20), [ [ -1, $points[2] ] ], 'upper edge on layer'; # $points[0]
|
2011-12-22 10:24:46 +00:00
|
|
|
|
2011-10-04 15:55:55 +00:00
|
|
|
is_deeply lines(20, 15, 10), [ ], 'upper vertex on layer';
|
|
|
|
is_deeply lines(28, 20, 30), [ ], 'lower vertex on layer';
|
2011-12-22 10:24:46 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
my @z = (24, 10, 16);
|
|
|
|
is_deeply lines(@z), [
|
|
|
|
[
|
2012-05-01 10:18:59 +00:00
|
|
|
-1, # line_plane_intersection([ vertices(@z)->[0], vertices(@z)->[1] ]),
|
2012-02-18 19:36:14 +00:00
|
|
|
line_plane_intersection([ vertices(@z)->[2], vertices(@z)->[0] ]),
|
2011-12-22 10:24:46 +00:00
|
|
|
]
|
|
|
|
], 'two edges intersect';
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
my @z = (16, 24, 10);
|
|
|
|
is_deeply lines(@z), [
|
|
|
|
[
|
2012-05-01 10:18:59 +00:00
|
|
|
-1, # line_plane_intersection([ vertices(@z)->[1], vertices(@z)->[2] ]),
|
2011-12-22 10:24:46 +00:00
|
|
|
line_plane_intersection([ vertices(@z)->[0], vertices(@z)->[1] ]),
|
|
|
|
]
|
|
|
|
], 'two edges intersect';
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
my @z = (10, 16, 24);
|
|
|
|
is_deeply lines(@z), [
|
|
|
|
[
|
2012-05-01 10:18:59 +00:00
|
|
|
-1, # line_plane_intersection([ vertices(@z)->[2], vertices(@z)->[0] ]),
|
2011-12-22 10:24:46 +00:00
|
|
|
line_plane_intersection([ vertices(@z)->[1], vertices(@z)->[2] ]),
|
|
|
|
]
|
|
|
|
], 'two edges intersect';
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
my @z = (24, 10, 20);
|
|
|
|
is_deeply lines(@z), [
|
|
|
|
[
|
2012-05-01 10:18:59 +00:00
|
|
|
-1, # line_plane_intersection([ vertices(@z)->[0], vertices(@z)->[1] ]),
|
2012-02-18 19:36:14 +00:00
|
|
|
$points[2],
|
2011-12-22 10:24:46 +00:00
|
|
|
]
|
|
|
|
], 'one vertex on plane and one edge intersects';
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
my @z = (10, 20, 24);
|
|
|
|
is_deeply lines(@z), [
|
|
|
|
[
|
2012-05-01 10:18:59 +00:00
|
|
|
-1, # line_plane_intersection([ vertices(@z)->[2], vertices(@z)->[0] ]),
|
2011-12-22 10:24:46 +00:00
|
|
|
$points[1],
|
|
|
|
]
|
|
|
|
], 'one vertex on plane and one edge intersects';
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
my @z = (20, 24, 10);
|
|
|
|
is_deeply lines(@z), [
|
|
|
|
[
|
2012-05-01 10:18:59 +00:00
|
|
|
-1, # line_plane_intersection([ vertices(@z)->[1], vertices(@z)->[2] ]),
|
2011-12-22 10:24:46 +00:00
|
|
|
$points[0],
|
|
|
|
]
|
|
|
|
], 'one vertex on plane and one edge intersects';
|
|
|
|
}
|
2011-10-04 15:55:55 +00:00
|
|
|
|
2012-02-18 19:36:14 +00:00
|
|
|
my @lower = intersect(22, 20, 20);
|
|
|
|
my @upper = intersect(20, 20, 10);
|
2012-05-01 10:18:59 +00:00
|
|
|
is $lower[0][Slic3r::TriangleMesh::I_FACET_EDGE], Slic3r::TriangleMesh::FE_BOTTOM, 'bottom edge on layer';
|
|
|
|
is $upper[0][Slic3r::TriangleMesh::I_FACET_EDGE], Slic3r::TriangleMesh::FE_TOP, 'upper edge on layer';
|
2011-10-04 20:27:45 +00:00
|
|
|
|
2013-05-18 14:48:26 +00:00
|
|
|
my $mesh;
|
2011-10-04 15:55:55 +00:00
|
|
|
|
2013-05-18 14:48:26 +00:00
|
|
|
sub intersect {
|
|
|
|
$mesh = Slic3r::TriangleMesh->new(
|
|
|
|
facets => [],
|
|
|
|
vertices => [],
|
|
|
|
);
|
2012-02-18 19:36:14 +00:00
|
|
|
push @{$mesh->facets}, [ [0,0,0], @{vertices(@_)} ];
|
2013-05-15 15:38:50 +00:00
|
|
|
$mesh->analyze;
|
2013-05-18 14:48:26 +00:00
|
|
|
return map Slic3r::TriangleMesh::unpack_line($_), $mesh->intersect_facet($#{$mesh->facets}, $z);
|
2012-02-18 19:36:14 +00:00
|
|
|
}
|
|
|
|
|
2013-05-18 14:48:26 +00:00
|
|
|
sub vertices {
|
|
|
|
push @{$mesh->vertices}, map [ @{$points[$_]}, $_[$_] ], 0..2;
|
|
|
|
[ ($#{$mesh->vertices}-2) .. $#{$mesh->vertices} ]
|
2012-02-18 19:36:14 +00:00
|
|
|
}
|
|
|
|
|
2011-10-04 15:55:55 +00:00
|
|
|
sub lines {
|
2012-02-18 19:36:14 +00:00
|
|
|
my @lines = intersect(@_);
|
2012-05-01 10:18:59 +00:00
|
|
|
#$_->a->[X] = sprintf('%.0f', $_->a->[X]) for @lines;
|
|
|
|
#$_->a->[Y] = sprintf('%.0f', $_->a->[Y]) for @lines;
|
|
|
|
$_->[Slic3r::TriangleMesh::I_B][X] = sprintf('%.0f', $_->[Slic3r::TriangleMesh::I_B][X]) for @lines;
|
|
|
|
$_->[Slic3r::TriangleMesh::I_B][Y] = sprintf('%.0f', $_->[Slic3r::TriangleMesh::I_B][Y]) for @lines;
|
|
|
|
return [ map [ -1, $_->[Slic3r::TriangleMesh::I_B] ], @lines ];
|
2011-10-04 15:55:55 +00:00
|
|
|
}
|
2011-12-22 10:24:46 +00:00
|
|
|
|
|
|
|
sub line_plane_intersection {
|
|
|
|
my ($line) = @_;
|
2012-02-17 16:16:13 +00:00
|
|
|
@$line = map $mesh->vertices->[$_], @$line;
|
2011-12-22 10:24:46 +00:00
|
|
|
|
|
|
|
return [
|
|
|
|
map sprintf('%.0f', $_),
|
2017-07-19 08:45:39 +00:00
|
|
|
map +($line->[1][$_] + ($line->[0][$_] - $line->[1][$_]) * ($z - $line->[1][Z]) / ($line->[0][Z] - $line->[1][Z])),
|
2011-12-22 10:24:46 +00:00
|
|
|
(X,Y)
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
__END__
|