``````package Algorithm::QuadTree;

use strict;
use Carp;

our \$VERSION = 0.1;

1;

###############################
#
# sub new() - constructor
#
# Arguments are a hash:
#
# -xmin  => minimum x value
# -xmax  => maximum x value
# -ymin  => minimum y value
# -ymax  => maximum y value
# -depth => depth of tree
#
# Creating a new QuadTree objects automatically
# segments the given area into quadtrees of the
# specified depth.
#
###############################

sub new {
my \$self  = shift;
my \$class = ref(\$self) || \$self;

my \$obj   = bless {} => \$class;

\$obj->{BACKREF} = {};
\$obj->{OBJECTS} = [];
\$obj->{ORIGIN}  = [0, 0];
\$obj->{SCALE}   = 1;

my %args  = @_;

for my \$arg (qw/xmin ymin xmax ymax depth/) {
unless (exists \$args{"-\$arg"}) {
carp "- must specify \$arg";
return undef;
}

\$obj->{uc \$arg} = \$args{"-\$arg"};
}

\$obj->_segment;

return \$obj;
}

###############################
#
# sub _segment() - private method
#
# This method does the actual segmentation
# and stores everything internally.
#
###############################

sub _segment {
my \$obj = shift;

\$obj->{XMIN},
\$obj->{YMIN},
\$obj->{XMAX},
\$obj->{YMAX},
1,             # current depth
0,             # current index
undef,         # parent index
);

}

###############################
#
# sub _addLevel() - private method
#
# This method segments a given area
# and adds a level to the tree.
#
###############################