Skip to content

Commit 408ab58

Browse files
committed
extract FaceAxes::normalise_scale
1 parent 705b025 commit 408ab58

1 file changed

Lines changed: 25 additions & 42 deletions

File tree

lib/PDL/Graphics/TriD/Graph.pm

Lines changed: 25 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,29 @@ package # hide from PAUSE
208208
PDL::Graphics::TriD::FaceAxes;
209209
use base qw(PDL::Graphics::TriD::AxesBase);
210210
use fields qw(LatticeObj Names Center);
211+
sub normalise_scale { # Normalize the smallest differences away.
212+
my ($this) = @_;
213+
my @dist;
214+
my $bounds = $this->{Bounds}->t->unpdl;
215+
for (@$bounds) {
216+
if (abs($_->[0] - $_->[1]) < 0.000001) {
217+
$_->[1] = $_->[0] + 1;
218+
}
219+
push(@dist,$_->[1]-$_->[0]);
220+
}
221+
# Normalize longitude and latitude bounds
222+
if ($dist[1] > $dist[0]) {
223+
$bounds->[0][0] -= ($dist[1]-$dist[0])/2;
224+
$bounds->[0][1] += ($dist[1]-$dist[0])/2;
225+
} elsif ($dist[0] > $dist[1] && $dist[0]<90) {
226+
$bounds->[1][0] -= ($dist[0]-$dist[1])/2;
227+
$bounds->[1][1] += ($dist[0]-$dist[1])/2;
228+
} elsif ($dist[0] > $dist[1]) {
229+
$bounds->[1][0] -= (90-$dist[1])/2;
230+
$bounds->[1][1] += (90-$dist[1])/2;
231+
}
232+
$bounds;
233+
}
211234
sub add_lattice_axis {
212235
my ($this) = @_;
213236
my @widths = $this->{Bounds}->slice('0:1')->t->diff2->list;
@@ -261,27 +284,7 @@ sub add_scale {
261284

262285
sub finish_scale {
263286
my ($this) = @_;
264-
my @dist;
265-
# Normalize the smallest differences away.
266-
my $bounds = $this->{Bounds}->t->unpdl;
267-
for (@$bounds) {
268-
if (abs($_->[0] - $_->[1]) < 0.000001) {
269-
$_->[1] = $_->[0] + 1;
270-
}
271-
push(@dist,$_->[1]-$_->[0]);
272-
}
273-
# Normalize longitude and latitude bounds
274-
if ($dist[1] > $dist[0]) {
275-
$bounds->[0][0] -= ($dist[1]-$dist[0])/2;
276-
$bounds->[0][1] += ($dist[1]-$dist[0])/2;
277-
} elsif ($dist[0] > $dist[1] && $dist[0]<90) {
278-
$bounds->[1][0] -= ($dist[0]-$dist[1])/2;
279-
$bounds->[1][1] += ($dist[0]-$dist[1])/2;
280-
} elsif ($dist[0] > $dist[1]) {
281-
$bounds->[1][0] -= (90-$dist[1])/2;
282-
$bounds->[1][1] += (90-$dist[1])/2;
283-
}
284-
$this->{Bounds} = PDL->pdl(PDL::float(), $bounds)->t;
287+
$this->{Bounds} = PDL->pdl(PDL::float(), $this->normalise_scale)->t;
285288
$this->add_lattice_axis;
286289
}
287290

@@ -338,27 +341,7 @@ sub add_scale {
338341

339342
sub finish_scale {
340343
my ($this) = @_;
341-
my @dist;
342-
# Normalize the smallest differences away.
343-
my $bounds = $this->{Bounds}->t->unpdl;
344-
for (@$bounds) {
345-
if (abs($_->[0] - $_->[1]) < 0.000001) {
346-
$_->[1] = $_->[0] + 1;
347-
}
348-
push(@dist,$_->[1]-$_->[0]);
349-
}
350-
# Normalize longitude and latitude bounds
351-
if ($dist[1] > $dist[0]) {
352-
$bounds->[0][0] -= ($dist[1]-$dist[0])/2;
353-
$bounds->[0][1] += ($dist[1]-$dist[0])/2;
354-
} elsif ($dist[0] > $dist[1] && $dist[0]<90) {
355-
$bounds->[1][0] -= ($dist[0]-$dist[1])/2;
356-
$bounds->[1][1] += ($dist[0]-$dist[1])/2;
357-
} elsif ($dist[0] > $dist[1]) {
358-
$bounds->[1][0] -= (90-$dist[1])/2;
359-
$bounds->[1][1] += (90-$dist[1])/2;
360-
}
361-
$this->{Bounds} = PDL->pdl(PDL::float(), $bounds)->t;
344+
$this->{Bounds} = PDL->pdl(PDL::float(), $this->normalise_scale)->t;
362345
$this->add_lattice_axis;
363346
}
364347

0 commit comments

Comments
 (0)