From 230c2e260ddf89a920b070ee48832199b18e212a Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 7 Jan 2018 22:57:21 +0000 Subject: [PATCH] distort-stl: better, but still needs work --- distort-stl | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/distort-stl b/distort-stl index f898992..9dab4ed 100755 --- a/distort-stl +++ b/distort-stl @@ -41,8 +41,13 @@ sub shift_arg () { scalar shift @ARGV; } +#no warnings qw(recursion); + sub subdivide_triangle ($$) { my ($t, $fn) = @_; + + #print STDERR 'SUBDIV', Dumper($t, $fn); + my @mids; foreach my $ix (0..2) { my $jx = ($ix+1) % 3; @@ -50,12 +55,14 @@ sub subdivide_triangle ($$) { foreach my $ci (0..2) { push @midp, 0.5 * ($t->[$ix][$ci] + $t->[$jx][$ci]); } - push @mids, @midp; + push @mids, \@midp; } foreach my $ix (0..2) { + #print STDERR 'SUBDIV IX ', $ix, "\n"; my $kx = ($ix+2) % 3; - $fn->([ $t->[$ix], $mids[$ix], $t->[$kx] ]); + $fn->([ $t->[$ix], $mids[$ix], $mids[$kx] ]); } + #print STDERR 'SUBDIV MID\n'; $fn->(\@mids); } @@ -67,6 +74,8 @@ our $project_cylinder_max_d_theta; sub project_cylinder_tri { my ($t) = @_; + #print STDERR 'PROJECT', Dumper($t); + my $radius = $project_cylinder_radius; my @thetas = map { $_->[0] / $radius } @$t; @@ -80,7 +89,7 @@ sub project_cylinder_tri { } my @ot; - foreach my $p ($t) { + foreach my $p (@$t) { my ($x,$y,$z) = @$p; my $r = $radius - $y; my $theta = $x / $radius; @@ -171,7 +180,9 @@ print "solid distort-stl\n"; foreach my $t (@triangles) { print " facet normal 0 0 0\n"; print " outer loop\n"; + die unless @$t==3; foreach my $p (@$t) { + die unless @$p==3; print " vertex"; printf " %.18g", $_ foreach @$p; print "\n"; -- 2.30.2