Little optimizations in slicing
This commit is contained in:
parent
398e66572d
commit
db266cde9f
@ -459,10 +459,9 @@ sub intersect_facet {
|
|||||||
my @edge_ids = @{$self->facets_edges->[$facet_id]};
|
my @edge_ids = @{$self->facets_edges->[$facet_id]};
|
||||||
my @edge_vertices_ids = $self->_facet_edges($facet_id);
|
my @edge_vertices_ids = $self->_facet_edges($facet_id);
|
||||||
|
|
||||||
my (@lines, @points, @intersection_points, @points_on_layer) = ();
|
my (@points, @intersection_points, @points_on_layer) = ();
|
||||||
|
|
||||||
for my $e (0..2) {
|
for my $e (0..2) {
|
||||||
my $edge_id = $edge_ids[$e];
|
|
||||||
my ($a_id, $b_id) = @{$edge_vertices_ids[$e]};
|
my ($a_id, $b_id) = @{$edge_vertices_ids[$e]};
|
||||||
my ($a, $b) = @vertices{$a_id, $b_id};
|
my ($a, $b) = @vertices{$a_id, $b_id};
|
||||||
#printf "Az = %f, Bz = %f, z = %f\n", $a->[Z], $b->[Z], $z;
|
#printf "Az = %f, Bz = %f, z = %f\n", $a->[Z], $b->[Z], $z;
|
||||||
@ -474,7 +473,9 @@ sub intersect_facet {
|
|||||||
($a, $b) = ($b, $a);
|
($a, $b) = ($b, $a);
|
||||||
($a_id, $b_id) = ($b_id, $a_id);
|
($a_id, $b_id) = ($b_id, $a_id);
|
||||||
}
|
}
|
||||||
push @lines, pack I_FMT, (
|
# We assume that this method is never being called for horizontal
|
||||||
|
# facets, so no other edge is going to be on this layer.
|
||||||
|
return pack I_FMT, (
|
||||||
$b->[X], $b->[Y], # I_B
|
$b->[X], $b->[Y], # I_B
|
||||||
$a_id, # I_A_ID
|
$a_id, # I_A_ID
|
||||||
$b_id, # I_B_ID
|
$b_id, # I_B_ID
|
||||||
@ -504,14 +505,13 @@ sub intersect_facet {
|
|||||||
$b->[X] + ($a->[X] - $b->[X]) * ($z - $b->[Z]) / ($a->[Z] - $b->[Z]),
|
$b->[X] + ($a->[X] - $b->[X]) * ($z - $b->[Z]) / ($a->[Z] - $b->[Z]),
|
||||||
$b->[Y] + ($a->[Y] - $b->[Y]) * ($z - $b->[Z]) / ($a->[Z] - $b->[Z]),
|
$b->[Y] + ($a->[Y] - $b->[Y]) * ($z - $b->[Z]) / ($a->[Z] - $b->[Z]),
|
||||||
undef,
|
undef,
|
||||||
$edge_id,
|
$edge_ids[$e],
|
||||||
];
|
];
|
||||||
push @intersection_points, $#points;
|
push @intersection_points, $#points;
|
||||||
#print "Intersects at $z!\n";
|
#print "Intersects at $z!\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return @lines if @lines;
|
|
||||||
if (@points_on_layer == 2 && @intersection_points == 1) {
|
if (@points_on_layer == 2 && @intersection_points == 1) {
|
||||||
$points[ $points_on_layer[1] ] = undef;
|
$points[ $points_on_layer[1] ] = undef;
|
||||||
@points = grep $_, @points;
|
@points = grep $_, @points;
|
||||||
|
14
t/slice.t
14
t/slice.t
@ -2,7 +2,7 @@ use Test::More;
|
|||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
|
|
||||||
plan tests => 17;
|
plan tests => 16;
|
||||||
|
|
||||||
BEGIN {
|
BEGIN {
|
||||||
use FindBin;
|
use FindBin;
|
||||||
@ -20,11 +20,13 @@ my @points = ([3, 4], [8, 5], [1, 9]); # XY coordinates of the facet vertices
|
|||||||
# the first point of the intersection lines is replaced by -1 because TriangleMesh.pm
|
# 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.
|
# is saving memory and doesn't store point A anymore since it's not actually needed.
|
||||||
|
|
||||||
is_deeply lines(20, 20, 20), [
|
# We disable this test because intersect_facet() now assumes we never feed a horizontal
|
||||||
[ -1, $points[1] ], # $points[0]
|
# facet to it.
|
||||||
[ -1, $points[2] ], # $points[1]
|
# is_deeply lines(20, 20, 20), [
|
||||||
[ -1, $points[0] ], # $points[2]
|
# [ -1, $points[1] ], # $points[0]
|
||||||
], 'horizontal';
|
# [ -1, $points[2] ], # $points[1]
|
||||||
|
# [ -1, $points[0] ], # $points[2]
|
||||||
|
# ], 'horizontal';
|
||||||
|
|
||||||
is_deeply lines(22, 20, 20), [ [ -1, $points[2] ] ], 'lower edge on layer'; # $points[1]
|
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, 20, 22), [ [ -1, $points[1] ] ], 'lower edge on layer'; # $points[0]
|
||||||
|
Loading…
Reference in New Issue
Block a user