Path-Hilbert

 view release on metacpan or  search on metacpan

lib/Path/Hilbert.pm  view on Meta::CPAN

    else {
        *xy2d = \&_xy2d;
        *d2xy = \&_d2xy;
    }
};

# optional constructor if you want OO-style
sub new {
    my $class = shift;
    my ($n) = @_;
    return bless { n => $n } => $class;
}

# convert (x,y) to d
sub _xy2d {
    my ($side, $x, $y) = @_;
    my $n = _valid_n($side);
    my ($X, $Y) = map { int($_ + 0.5) } ($x, $y);
    my $D;
    {
        use integer;

lib/Path/Hilbert/BigInt.pm  view on Meta::CPAN

use Exporter qw( import );

our @EXPORT = qw( xy2d d2xy );

our $VERSION = '2.000';

# optional constructor if you want OO-style
sub new {
    my $class = shift;
    my ($n) = @_;
    return bless { n => $n } => $class;
}

# convert (x,y) to d
sub xy2d {
    my ($side, $x, $y) = @_;
    my $n = _valid_n($side);
    ($x, $y) = map { Math::BigInt->new("$_") } ($x, $y);
    my $d = Math::BigInt->bzero();
    for (my $s = $n->copy()->brsft(1); $s->bcmp(0) > 0; $s->brsft(1)) {
        my $rx = Math::BigInt->new($x->copy()->band($s)->bcmp(0) > 0 ? "1" : "0");

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 1.797 second using v1.00-cache-2.02-grep-82fe00e-cpan-f5108d614456 )