Skip to content

Commit

Permalink
fixed overly-rigid parsing of ASCII STL files - #504
Browse files Browse the repository at this point in the history
  • Loading branch information
mohawk2 committed Nov 27, 2024
1 parent e6f96d5 commit d6f2981
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 3 deletions.
1 change: 1 addition & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
- split Graphics/Limits out to separate PDL::Graphics::Limits distro
- split IO/Browser out to separate PDL::IO::Browser distro
- split Perldl2 out to separate PDL::Perldl2 distro
- fixed overly-rigid parsing of ASCII STL files (#504) - thanks Shugo for report

2.095 2024-11-03
- add PDL_GENTYPE_IS_{REAL,FLOATREAL,COMPLEX,SIGNED,UNSIGNED}_##ppsym (#502)
Expand Down
8 changes: 5 additions & 3 deletions IO/STL/STL.pm
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,12 @@ sub _read_ascii {
$part = $1;
next;
}
elsif($line =~ m/^\s*endsolid (.*)/) {
elsif($line =~ m/^\s*endsolid\s*(.*)/) {
my $name = $1;
barf "invalid 'endsolid' entry with no current part" if !defined $part;
barf "end of part '$name' should have been '$part'" if $name ne $part;
if (length $name) { # only catch if wrong; if absent, fine
barf "invalid 'endsolid' entry with no current part" if !defined $part;
barf "end of part '$name' should have been '$part'" if $name ne $part;
}
$part = undef;
last;
}
Expand Down
7 changes: 7 additions & 0 deletions IO/STL/t/basic.t
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,11 @@ like $@, qr/Usage:/, 'wstl error right';
is_pdl $v2->dice_axis(1, $f2->flat)->splitdim(1,3), $cubev;
}

($vertices, $faceidx) = rstl(catfile qw(t blenderasc.stl));
is_pdl $vertices->dice_axis(1, $faceidx->flat)->splitdim(1,3), float '
[0.0017237 0.102913 -0.00153113; 0.00195483 0.104636 -0.00253355; 0.00243758 0.104636 -0.00153113]
[0.00138235 0.103254 -0.00253355; 0.000767261 0.103869 -0.00322725; 0.00108497 0.104636 -0.00322725]
[0.00138235 0.103254 -0.00253355; 0.00108497 0.104636 -0.00322725; 0.00195483 0.104636 -0.00253355]
';

done_testing;
23 changes: 23 additions & 0 deletions IO/STL/t/blenderasc.stl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
solid Apple'sFinder and Blender can read
facet normal 0.84410374399741939 -0.34963905512334476 -0.40649895510566048
outer loop
vertex 0.0017237013671547174 0.10291291773319244 -0.0015311292372643948
vertex 0.0019548346754163504 0.10463636368513107 -0.0025335513055324554
vertex 0.0024375757202506065 0.10463636368513107 -0.0015311292372643948
endloop
endfacet
facet normal 0.60368325273783552 -0.25005312352273268 -0.75699403285652889
outer loop
vertex 0.0013823517365381122 0.10325426608324051 -0.0025335513055324554
vertex 0.00076726125553250313 0.10386935621500015 -0.0032272490207105875
vertex 0.0010849653044715524 0.10463636368513107 -0.0032272490207105875
endloop
endfacet
facet normal 0.60368283778508947 -0.25005334258074174 -0.75699429141040397
outer loop
vertex 0.0013823517365381122 0.10325426608324051 -0.0025335513055324554
vertex 0.0010849653044715524 0.10463636368513107 -0.0032272490207105875
vertex 0.0019548346754163504 0.10463636368513107 -0.0025335513055324554
endloop
endfacet
endsolid
1 change: 1 addition & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ IO/STL/Makefile.PL
IO/STL/owl.stl
IO/STL/STL.pm
IO/STL/t/basic.t
IO/STL/t/blenderasc.stl
IO/STL/t/cube.stl
IO/STL/t/cube_binary.stl
Libtmp/Filter/Linear.pm
Expand Down

0 comments on commit d6f2981

Please sign in to comment.