@@ -64,64 +64,55 @@ value using the set_color_table function.
6464
6565=cut
6666
67- sub new{
68- my ($type ,$data ,$points ,$colors ,$options ) = @_ ;
69-
70- if (! defined $points ){
71- $points = [$data -> xvals,$data -> yvals,$data -> zvals];
72- }
73-
74- if (ref ($colors ) eq " HASH" ){
75- $options =$colors ;
76- undef $colors ;
77- }
78-
79- $colors = PDL::Graphics::TriD::realcoords(" COLOR" ,pdl[1,1,1]) unless defined $colors ;
80-
67+ sub new {
68+ my $options = ref ($_ [-1]) eq ' HASH' ? pop : $_ [0]-> get_valid_options;
69+ my ($type ,$data ,$points ,$colors ) = @_ ;
70+ $points //= [$data -> xvals,$data -> yvals,$data -> zvals];
8171 my $this = $type -> SUPER::new($points ,$colors ,$options );
72+ $options = $this -> {Options };
8273
8374 my $fac =1;
8475 my ($min ,$max ) = $data -> minmax;
8576
86- unless (defined $this -> {Options }{ContourMin }){
87- while ($fac *($max -$min )<10){
77+ unless (defined $options -> {ContourMin }){
78+ my $valuerange = $max -$min ;
79+ while ($fac *$valuerange <10){
8880 $fac *=10;
8981 }
90- $this -> { Options } {ContourMin } = int ($fac *$min ) == $fac *$min ? $min : int ($fac *$min +1)/$fac ;
91- print " ContourMin = " ,$this -> { Options } {ContourMin }," \n "
82+ $options -> {ContourMin } = int ($fac *$min ) == $fac *$min ? $min : int ($fac *$min +1)/$fac ;
83+ print " ContourMin = " ,$options -> {ContourMin }," \n "
9284 if $PDL::Graphics::TriD::verbose ;
9385 }
94- unless (defined $this -> { Options } {ContourMax } &&
95- $this -> {Options }{ ContourMax } > $this -> { Options } {ContourMin } ){
96- if (defined $this -> { Options } {ContourInt }){
97- $this -> {Options }{ ContourMax } = $this -> { Options } {ContourMin };
98- while ($this -> {Options }{ ContourMax }+$this -> { Options } {ContourInt } < $max ){
99- $this -> {Options }{ ContourMax }= $this -> {Options }{ ContourMax }+$this -> { Options } {ContourInt };
86+ unless (defined $options -> {ContourMax } &&
87+ $options -> {ContourMax } > $options -> {ContourMin } ){
88+ if (defined $options -> {ContourInt }){
89+ $options -> {ContourMax } = $options -> {ContourMin };
90+ while ($options -> {ContourMax }+$options -> {ContourInt } < $max ){
91+ $options -> {ContourMax }= $options -> {ContourMax }+$options -> {ContourInt };
10092 }
10193 }else {
102- $this -> { Options } {ContourMax } = int ($fac *$max ) == $fac *$max ? $max : (int ($fac *$max )-1)/$fac ;
94+ $options -> {ContourMax } = int ($fac *$max ) == $fac *$max ? $max : (int ($fac *$max )-1)/$fac ;
10395 }
104- print " ContourMax = " ,$this -> { Options } {ContourMax }," \n "
96+ print " ContourMax = " ,$options -> {ContourMax }," \n "
10597 if $PDL::Graphics::TriD::verbose ;
10698 }
107- unless (defined $this -> {Options }{ ContourInt } && $this -> { Options } {ContourInt }>0){
108- $this -> {Options }{ ContourInt } = int ($fac *($this -> {Options }{ ContourMax }-$this -> { Options } {ContourMin }))/(10*$fac );
109- print " ContourInt = " ,$this -> { Options } {ContourInt }," \n "
99+ unless (defined $options -> {ContourInt } && $options -> {ContourInt }>0){
100+ $options -> {ContourInt } = int ($fac *($options -> {ContourMax }-$options -> {ContourMin }))/(10*$fac );
101+ print " ContourInt = " ,$options -> {ContourInt }," \n "
110102 if ($PDL::Graphics::TriD::verbose );
111103 }
112104#
113105# The user could also name cvals
114106#
115107 my $cvals ;
116- if (!defined ($this -> {Options }{ ContourVals }) || $this -> { Options } {ContourVals }-> isempty){
117- $cvals =zeroes(float(), int (($this -> {Options }{ ContourMax }-$this -> {Options }{ ContourMin })/$this -> { Options } {ContourInt }+1));
118- $cvals = $cvals -> xlinvals($this -> { Options }{ ContourMin }, $this -> { Options }{ ContourMax });
108+ if (!defined ($options -> {ContourVals }) || $options -> {ContourVals }-> isempty){
109+ $cvals =zeroes(float(), int (($options -> {ContourMax }-$options -> {ContourMin })/$options -> {ContourInt }+1));
110+ $cvals = $cvals -> xlinvals(@$options { qw( ContourMin ContourMax) });
119111 }else {
120- $cvals = $this -> {Options }{ContourVals };
121- $this -> {Options }{ContourMax }=$cvals -> max-> sclr;
122- $this -> {Options }{ContourMin }=$cvals -> min-> sclr;
112+ $cvals = $options -> {ContourVals };
113+ @$options {qw( ContourMin ContourMax) } = $cvals -> minmax;
123114 }
124- $this -> { Options } {ContourVals } = $cvals ;
115+ $options -> {ContourVals } = $cvals ;
125116 print " Cvals = $cvals \n " if $PDL::Graphics::TriD::verbose ;
126117
127118 my ($pi , $p ) = contour_polylines($cvals ,$data ,$this -> {Points });
@@ -139,9 +130,9 @@ sub new{
139130 $pcnt += 1; $pval += $thispi_maxval + 1;
140131 }
141132
142- $this -> addlabels($this -> {Options }{ Labels }) if defined $this -> { Options } {Labels };
133+ $this -> addlabels($options -> {Labels }) if defined $options -> {Labels };
143134
144- return $this ;
135+ $this ;
145136}
146137
147138sub get_valid_options { +{
0 commit comments