from quadtree import QuadTree
from point import Point
from point import RandomPointGenerator
from rectangle import Rectangle
import itertools as it


################################################################################


def take(n, iterable):
    '''
    Return first n items of the iterable as a list
    '''
    return list(it.islice(iterable, n))


################################################################################


print 'Construct a quadtree (granularity 2) with 20 random points ...'
granularity = 2
area = Rectangle(Point(0, 0), Point(10, 10))
points = take(20, RandomPointGenerator(area))
tree = QuadTree(points, granularity)

print 'report all points ...'
for point in tree:
    print point

print 'report all points in Rectangle(Point(0, 0), Point(5, 5))'
reported_points = []
for point in tree.report_points_in_rectangle(Rectangle(Point(0, 0), Point(5, 5))):
    reported_points.append(point)
    print point
for point in points:
    if point not in reported_points:
        assert(point not in Rectangle(Point(0, 0), Point(5, 5)))

        
################################################################################
