Skip to content

Commit c2e0fb1

Browse files
committed
move GObject option-checking into Object
1 parent b1befac commit c2e0fb1

File tree

2 files changed

+26
-26
lines changed

2 files changed

+26
-26
lines changed

lib/PDL/Graphics/TriD/Object.pm

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,40 @@ package PDL::Graphics::TriD::Object;
33
use strict;
44
use warnings;
55

6-
use fields qw(Objects ValidList ChangedSub List);
6+
use fields qw(Objects ValidList ChangedSub List Options);
77

88
$PDL::Graphics::TriD::verbose //= 0;
99

10-
sub new{
10+
sub new {
11+
my $options = ref($_[-1]) eq 'HASH' ? pop : {};
1112
my $class = shift;
1213
my $self = fields::new($class);
14+
$self->{Options} = $options;
15+
$self->check_options;
1316
$self;
1417
}
1518

19+
sub check_options {
20+
my ($this) = @_;
21+
my $opts = $this->get_valid_options();
22+
$this->{Options} = $opts, return if !$this->{Options};
23+
print "FETCHOPT: $this ".(join ',',%$opts)."\n" if $PDL::Graphics::TriD::verbose;
24+
my %newopts = (%$opts, %{$this->{Options}});
25+
my @invalid = grep !exists $opts->{$_}, keys %newopts;
26+
die "$this: invalid options left: @invalid" if @invalid;
27+
$this->{Options} = \%newopts;
28+
}
29+
30+
sub get_valid_options { +{
31+
UseDefcols => 0,
32+
}}
33+
1634
sub clear_objects {
1735
my($this) = @_;
1836
$this->{Objects} = [];
1937
$this->{ValidList} = 0;
2038
}
2139

22-
2340
sub delete_object {
2441
my($this,$object) = @_;
2542
return unless(defined $object && defined $this->{Objects});

lib/PDL/Graphics/TriD/Objects.pm

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -32,46 +32,29 @@ properly. All the points used by the object must be in the member
3232
=head2 PDL::Graphics::TriD::GObject
3333
3434
Inherits from base PDL::Graphics::TriD::Object and adds fields Points,
35-
Colors and Options.
35+
and Colors.
36+
It is for primitive objects rather than containers.
3637
3738
=cut
3839

3940
package PDL::Graphics::TriD::GObject;
4041
use strict;
4142
use warnings;
4243
use base qw/PDL::Graphics::TriD::Object/;
43-
use fields qw/Points Colors Options/;
44+
use fields qw/Points Colors/;
4445

4546
$PDL::Graphics::TriD::verbose //= 0;
4647

4748
sub new {
4849
my $options = ref($_[-1]) eq 'HASH' ? pop : {};
4950
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);
51+
my $this = $type->SUPER::new($options);
5752
$this->{Points} = $points = PDL::Graphics::TriD::realcoords($type->r_type,$points);
58-
print "GObject new - back from realcoords\n" if($PDL::Graphics::TriD::verbose);
53+
$this->{Options}{UseDefcols} = 1 if !defined $colors; # for VRML efficiency
5954
$this->{Colors} = defined $colors
6055
? PDL::Graphics::TriD::realcoords("COLOR",$colors)
6156
: $this->cdummies(PDL->pdl(PDL::float(),1,1,1),$points);
62-
print "GObject new - returning\n" if($PDL::Graphics::TriD::verbose);
63-
return $this;
64-
}
65-
66-
sub check_options {
67-
my($this) = @_;
68-
my $opts = $this->get_valid_options();
69-
$this->{Options} = $opts, return if !$this->{Options};
70-
print "FETCHOPT: $this ".(join ',',%$opts)."\n" if $PDL::Graphics::TriD::verbose;
71-
my %newopts = (%$opts, %{$this->{Options}});
72-
my @invalid = grep !exists $opts->{$_}, keys %newopts;
73-
die "$this: invalid options left: @invalid" if @invalid;
74-
$this->{Options} = \%newopts;
57+
$this;
7558
}
7659

7760
sub set_colors {

0 commit comments

Comments
 (0)