Skip to content

Commit 5f7d198

Browse files
committed
stack-trace if add_scale gets undef $inds
1 parent 9c19b02 commit 5f7d198

1 file changed

Lines changed: 39 additions & 36 deletions

File tree

lib/PDL/Graphics/TriD/Graph.pm

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ sub bind_default {
6363
}
6464

6565
sub set_axis {
66-
my($this,$axis,$name) = @_;
67-
$this->{Axis}{$name} = $axis;
68-
$this->changed();
66+
my ($this,$axis,$name) = @_;
67+
$this->{Axis}{$name} = $axis;
68+
$this->changed();
6969
}
7070

7171
# Bind all unbound things here...
@@ -99,15 +99,15 @@ sub get_points {
9999
}
100100

101101
sub clear_data {
102-
my($this) = @_;
103-
$this->{$_} = {} for qw(Data DataBind UnBound);
104-
$this->changed;
102+
my ($this) = @_;
103+
$this->{$_} = {} for qw(Data DataBind UnBound);
104+
$this->changed;
105105
}
106106

107107
sub delete_data {
108-
my($this,$name) = @_;
109-
delete $this->{$_}{$name} for qw(Data DataBind UnBound);
110-
$this->changed;
108+
my ($this,$name) = @_;
109+
delete $this->{$_}{$name} for qw(Data DataBind UnBound);
110+
$this->changed;
111111
}
112112

113113
use constant { DEFAULT_AXIS=>'Euclid3', DEFAULT_AXIS_CLASS=>'PDL::Graphics::TriD::EuclidAxes', DEFAULT_INDICES=>[0,1,2] };
@@ -119,9 +119,9 @@ sub default_axes {
119119
}
120120

121121
sub set_default_axis {
122-
my($this,$name,$axes) = @_;
123-
$this->{DefaultAxisName} = $name;
124-
$this->{DefaultAxes} = $axes;
122+
my ($this,$name,$axes) = @_;
123+
$this->{DefaultAxisName} = $name;
124+
$this->{DefaultAxes} = $axes;
125125
}
126126

127127
sub changed {}
@@ -156,12 +156,13 @@ sub new {
156156
}
157157

158158
sub init_scale {
159-
my($this) = @_;
159+
my ($this) = @_;
160160
$this->{Scale} = undef;
161161
}
162162

163163
sub add_scale {
164-
my($this,$data,$inds) = @_;
164+
my ($this,$data,$inds) = @_;
165+
PDL::barf "no \$inds given" if !defined $inds;
165166
$data = $data->dice_axis(0, $inds);
166167
my $to_minmax = $data->clump(1..$data->ndims-1); # xyz,...
167168
$to_minmax = $to_minmax->glue(1, $this->{Scale}); # include old min/max
@@ -170,7 +171,7 @@ sub add_scale {
170171
}
171172

172173
sub finish_scale {
173-
my($this) = @_;
174+
my ($this) = @_;
174175
# Normalize the smallest differences away.
175176
my ($min, $max) = $this->{Scale}->dog;
176177
my $diff = $max - $min;
@@ -185,7 +186,7 @@ sub finish_scale {
185186

186187
# Add 0..1 to each axis.
187188
sub transform {
188-
my($this,$point,$data,$inds) = @_;
189+
my ($this,$point,$data,$inds) = @_;
189190
my ($min, $max) = map $this->{Scale}->slice("0:$#$inds,$_"), 0, 1;
190191
$point->slice("0:$#$inds") +=
191192
($data->dice_axis(0, $inds) - $min) / ($max - $min);
@@ -205,17 +206,18 @@ use fields qw/Name Scale/;
205206
use PDL::Core '';
206207

207208
sub new {
208-
my($type) = @_;
209-
bless {Names => [qw(LON LAT Pressure)]},$type;
209+
my ($type) = @_;
210+
bless {Names => [qw(LON LAT Pressure)]},$type;
210211
}
211212

212213
sub init_scale {
213-
my($this) = @_;
214-
$this->{Scale} = [];
214+
my ($this) = @_;
215+
$this->{Scale} = [];
215216
}
216217

217218
sub add_scale {
218-
my($this,$data,$inds) = @_;
219+
my ($this,$data,$inds) = @_;
220+
PDL::barf "no \$inds given" if !defined $inds;
219221
my $i = 0;
220222
for (@$inds) {
221223
my $d = $data->slice("($_)");
@@ -244,17 +246,17 @@ sub add_scale {
244246
}
245247
# Should make the projection center an option
246248
$this->{Center} = [$this->{Scale}[0][0]+($this->{Scale}[0][1]-$this->{Scale}[0][0])/2,
247-
0];
249+
0];
248250
}
249251

250252
sub finish_scale {
251-
my($this) = @_;
253+
my ($this) = @_;
252254
my @dist;
253255
# Normalize the smallest differences away.
254256
for (@{$this->{Scale}}) {
255257
if (abs($_->[0] - $_->[1]) < 0.000001) {
256258
$_->[1] = $_->[0] + 1;
257-
}
259+
}
258260
push(@dist,$_->[1]-$_->[0]);
259261
}
260262
# for the z coordinate reverse the min and max values
@@ -273,7 +275,7 @@ sub finish_scale {
273275
} elsif ($dist[0] > $dist[1]) {
274276
$this->{Scale}[1][0] -= (90-$dist[1])/2;
275277
$this->{Scale}[1][1] += (90-$dist[1])/2;
276-
}
278+
}
277279
my (@nadd,@nc,@ns);
278280
for my $dim (0..1) {
279281
my $width = $this->{Scale}[$dim][1]-$this->{Scale}[$dim][0];
@@ -300,7 +302,7 @@ sub finish_scale {
300302
}
301303

302304
sub transform {
303-
my($this,$point,$data,$inds) = @_;
305+
my ($this,$point,$data,$inds) = @_;
304306
barf "Wrong number of arguments to transform $this\n" if @$inds != 3;
305307
my $i = 0;
306308
my $pio180 = 0.017453292;
@@ -320,17 +322,18 @@ package PDL::Graphics::TriD::PolarStereoAxes;
320322
use PDL::Core '';
321323

322324
sub new {
323-
my($type) = @_;
324-
bless {Names => [qw(LONGITUDE LATITUDE HEIGHT)]},$type;
325+
my ($type) = @_;
326+
bless {Names => [qw(LONGITUDE LATITUDE HEIGHT)]},$type;
325327
}
326328

327329
sub init_scale {
328-
my($this) = @_;
329-
$this->{Scale} = [];
330+
my ($this) = @_;
331+
$this->{Scale} = [];
330332
}
331333

332334
sub add_scale {
333-
my($this,$data,$inds) = @_;
335+
my ($this,$data,$inds) = @_;
336+
PDL::barf "no \$inds given" if !defined $inds;
334337
my $i = 0;
335338
for (@$inds) {
336339
my $d = $data->slice("($_)");
@@ -358,17 +361,17 @@ sub add_scale {
358361
$i++;
359362
}
360363
$this->{Center} = [$this->{Scale}[0][0]+($this->{Scale}[0][1]-$this->{Scale}[0][0])/2,
361-
$this->{Scale}[1][0]+($this->{Scale}[1][1]-$this->{Scale}[1][0])/2];
364+
$this->{Scale}[1][0]+($this->{Scale}[1][1]-$this->{Scale}[1][0])/2];
362365
}
363366

364367
sub finish_scale {
365-
my($this) = @_;
368+
my ($this) = @_;
366369
my @dist;
367370
# Normalize the smallest differences away.
368371
for (@{$this->{Scale}}) {
369372
if (abs($_->[0] - $_->[1]) < 0.000001) {
370373
$_->[1] = $_->[0] + 1;
371-
}
374+
}
372375
push(@dist,$_->[1]-$_->[0]);
373376
}
374377
# for the z coordinate reverse the min and max values
@@ -387,11 +390,11 @@ sub finish_scale {
387390
} elsif ($dist[0] > $dist[1]) {
388391
$this->{Scale}[1][0] -= (90-$dist[1])/2;
389392
$this->{Scale}[1][1] += (90-$dist[1])/2;
390-
}
393+
}
391394
}
392395

393396
sub transform {
394-
my($this,$point,$data,$inds) = @_;
397+
my ($this,$point,$data,$inds) = @_;
395398
my $i = 0;
396399
barf "Wrong number of arguments to transform $this\n" if @$inds != 3;
397400
my $pio180 = 0.017453292;

0 commit comments

Comments
 (0)