Skip to content

Commit a178db1

Browse files
committed
Objects better $options-extract
1 parent edd12a3 commit a178db1

File tree

1 file changed

+18
-23
lines changed

1 file changed

+18
-23
lines changed

lib/PDL/Graphics/TriD/Objects.pm

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -45,26 +45,22 @@ use fields qw/Points Colors Options/;
4545
$PDL::Graphics::TriD::verbose //= 0;
4646

4747
sub new {
48-
my($type,$points,$colors,$options) = @_;
49-
print "GObject new.. calling SUPER::new...\n" if($PDL::Graphics::TriD::verbose);
50-
my $this = $type->SUPER::new();
51-
print "GObject new - back (SUPER::new returned $this)\n" if($PDL::Graphics::TriD::verbose);
52-
if(!defined $options and ref $colors eq "HASH") {
53-
$options = $colors;
54-
undef $colors;
55-
}
56-
$options = { $options ? %$options : () };
57-
$options->{UseDefcols} = 1 if !defined $colors; # for VRML efficiency
58-
$this->{Options} = $options;
59-
$this->check_options;
60-
print "GObject new - calling realcoords\n" if($PDL::Graphics::TriD::verbose);
61-
$this->{Points} = $points = PDL::Graphics::TriD::realcoords($type->r_type,$points);
62-
print "GObject new - back from realcoords\n" if($PDL::Graphics::TriD::verbose);
63-
$this->{Colors} = defined $colors
64-
? PDL::Graphics::TriD::realcoords("COLOR",$colors)
65-
: $this->cdummies(PDL->pdl(PDL::float(),1,1,1),$points);
66-
print "GObject new - returning\n" if($PDL::Graphics::TriD::verbose);
67-
return $this;
48+
my $options = ref($_[-1]) eq 'HASH' ? pop : {};
49+
my ($type,$points,$colors) = @_;
50+
print "GObject new.. calling SUPER::new...\n" if $PDL::Graphics::TriD::verbose;
51+
my $this = $type->SUPER::new();
52+
print "GObject new - back (SUPER::new returned $this)\n" if $PDL::Graphics::TriD::verbose;
53+
$options->{UseDefcols} = 1 if !defined $colors; # for VRML efficiency
54+
$this->{Options} = $options;
55+
$this->check_options;
56+
print "GObject new - calling realcoords\n" if($PDL::Graphics::TriD::verbose);
57+
$this->{Points} = $points = PDL::Graphics::TriD::realcoords($type->r_type,$points);
58+
print "GObject new - back from realcoords\n" if($PDL::Graphics::TriD::verbose);
59+
$this->{Colors} = defined $colors
60+
? PDL::Graphics::TriD::realcoords("COLOR",$colors)
61+
: $this->cdummies(PDL->pdl(PDL::float(),1,1,1),$points);
62+
print "GObject new - returning\n" if($PDL::Graphics::TriD::verbose);
63+
return $this;
6864
}
6965

7066
sub check_options {
@@ -142,11 +138,10 @@ sub get_valid_options { +{
142138
package PDL::Graphics::TriD::Trigrid;
143139
use base qw/PDL::Graphics::TriD::GObject/;
144140
sub new {
145-
my($type,$points,$faceidx,$colors,$options) = @_;
141+
my $options = ref($_[-1]) eq 'HASH' ? pop : {};
142+
my($type,$points,$faceidx,$colors) = @_;
146143
# faceidx is 2D pdl of indices into points for each face
147144
$faceidx = $faceidx->ulong;
148-
if(!defined $options and ref $colors eq "HASH") {
149-
$options = $colors;undef $colors; }
150145
$points = PDL::Graphics::TriD::realcoords($type->r_type,$points);
151146
if(!defined $colors) { $colors = PDL->pdl(PDL::float(),0.8,0.8,0.8);
152147
$colors = $type->cdummies($colors,$points);

0 commit comments

Comments
 (0)