Skip to content

Commit c1b2fa2

Browse files
committed
move realcoords to only place that uses it
1 parent 14dadbf commit c1b2fa2

2 files changed

Lines changed: 41 additions & 41 deletions

File tree

lib/PDL/Graphics/TriD.pm

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -800,46 +800,6 @@ BEGIN {
800800
our $Settings;
801801
sub tridsettings {$Settings}
802802

803-
# Allowable forms:
804-
# x(3,..) [x(..),y(..),z(..)]
805-
sub realcoords {
806-
my($type,$c) = @_;
807-
if (ref $c ne "ARRAY") {
808-
my $dim0 = $c->getdim(0);
809-
barf "If one ndarray given for coordinate, must be (2|3,...) or have default interpretation" if $dim0 != 2 and $dim0 != 3;
810-
return $c->float;
811-
}
812-
my @c = @$c;
813-
if (!ref $c[0]) {$type = shift @c}
814-
barf "Must have 1..3 array members for coordinates" if !@c || @c>3;
815-
if (@c == 1 and $type eq "SURF2D") {
816-
# surf2d -> this is z axis
817-
@c = ($c[0]->xvals,$c[0]->yvals,$c[0]);
818-
} elsif (@c == 1 and $type eq "POLAR2D") {
819-
my $t = 6.283 * $c[0]->xvals / ($c[0]->getdim(0)-1);
820-
my $r = $c[0]->yvals / ($c[0]->getdim(1)-1);
821-
@c = ($r * sin($t), $r * cos($t), $c[0]);
822-
} elsif (@c == 1 and $type eq "COLOR") {
823-
# color -> 1 ndarray = grayscale
824-
@c = @c[0,0,0];
825-
} elsif (@c == 1 and $type eq "LINE") {
826-
@c = ($c[0]->xvals, $c[0], 0);
827-
} elsif (@c == 2 and $type eq "LINE") {
828-
@c = (@c[0,1], $c[0]->xvals);
829-
}
830-
# XXX
831-
barf "Must have 3 coordinates if no interpretation (here '$type')" if @c != 3;
832-
# allow a constant (either pdl or not) to be introduced in one dimension
833-
foreach(0..2) {
834-
if (ref($c[$_]) ne "PDL" or $c[$_]->nelem==1) {
835-
$c[$_] = $c[$_]*(PDL->ones($c[($_+1)%3]->dims));
836-
}
837-
}
838-
my $g = PDL::ImageND::combcoords(@c);
839-
$g->dump if $PDL::Graphics::TriD::verbose;
840-
$g;
841-
}
842-
843803
sub checkargs {
844804
return unless ref $_[-1] eq "HASH" and $PDL::Graphics::TriD::verbose;
845805
print "enter checkargs \n";

lib/PDL/Graphics/TriD/Object.pm

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,50 @@ sub normalise_as {
3535
die "Given 1D ndarray as colour but no points to match" if !defined $points;
3636
return $this->cdummies($what->float,$points);
3737
}
38-
return PDL::Graphics::TriD::realcoords($as, $what) if !defined $points or defined $what;
38+
return realcoords($as, $what) if !defined $points or defined $what;
3939
$this->cdummies(PDL->pdl(PDL::float(),1,1,1),$points);
4040
}
4141

42+
# Allowable forms:
43+
# x(3,..) [x(..),y(..),z(..)]
44+
sub realcoords {
45+
my($type,$c) = @_;
46+
if (ref $c ne "ARRAY") {
47+
my $dim0 = $c->getdim(0);
48+
confess "If one ndarray given for coordinate, must be (2|3,...) or have default interpretation" if $dim0 != 2 and $dim0 != 3;
49+
return $c->float;
50+
}
51+
my @c = @$c;
52+
if (!ref $c[0]) {$type = shift @c}
53+
confess "Must have 1..3 array members for coordinates" if !@c || @c>3;
54+
if (@c == 1 and $type eq "SURF2D") {
55+
# surf2d -> this is z axis
56+
@c = ($c[0]->xvals,$c[0]->yvals,$c[0]);
57+
} elsif (@c == 1 and $type eq "POLAR2D") {
58+
my $t = 6.283 * $c[0]->xvals / ($c[0]->getdim(0)-1);
59+
my $r = $c[0]->yvals / ($c[0]->getdim(1)-1);
60+
@c = ($r * sin($t), $r * cos($t), $c[0]);
61+
} elsif (@c == 1 and $type eq "COLOR") {
62+
# color -> 1 ndarray = grayscale
63+
@c = @c[0,0,0];
64+
} elsif (@c == 1 and $type eq "LINE") {
65+
@c = ($c[0]->xvals, $c[0], 0);
66+
} elsif (@c == 2 and $type eq "LINE") {
67+
@c = (@c[0,1], $c[0]->xvals);
68+
}
69+
# XXX
70+
confess "Must have 3 coordinates if no interpretation (here '$type')" if @c != 3;
71+
# allow a constant (either pdl or not) to be introduced in one dimension
72+
foreach(0..2) {
73+
if (ref($c[$_]) ne "PDL" or $c[$_]->nelem==1) {
74+
$c[$_] = $c[$_]*(PDL->ones($c[($_+1)%3]->dims));
75+
}
76+
}
77+
my $g = PDL::ImageND::combcoords(@c);
78+
$g->dump if $PDL::Graphics::TriD::verbose;
79+
$g;
80+
}
81+
4282
sub check_options {
4383
my ($this) = @_;
4484
my $opts = $this->get_valid_options();

0 commit comments

Comments
 (0)