<s> from collections import namedtuple <EOL> import itertools <EOL> _Vector = namedtuple ( "<STR_LIT>" , ( "<STR_LIT:x>" , "<STR_LIT:y>" , "<STR_LIT:z>" ) ) <EOL> class Vector ( _Vector ) : <EOL> __slots__ = ( ) <EOL> def __add__ ( self , other ) : <EOL> return Vector ( self [ <NUM_LIT:0> ] + other [ <NUM_LIT:0> ] , self [ <NUM_LIT:1> ] + other [ <NUM_LIT:1> ] , self [ <NUM_LIT:2> ] + other [ <NUM_LIT:2> ] ) <EOL> def __sub__ ( self , other ) : <EOL> return Vector ( self [ <NUM_LIT:0> ] - other [ <NUM_LIT:0> ] , self [ <NUM_LIT:1> ] - other [ <NUM_LIT:1> ] , self [ <NUM_LIT:2> ] - other [ <NUM_LIT:2> ] ) <EOL> def __mul__ ( self , other ) : <EOL> return Vector ( self [ <NUM_LIT:0> ] * other [ <NUM_LIT:0> ] , self [ <NUM_LIT:1> ] * other [ <NUM_LIT:1> ] , self [ <NUM_LIT:2> ] * other [ <NUM_LIT:2> ] ) <EOL> class BoundingBox ( object ) : <EOL> type = int <EOL> def __init__ ( self , origin = ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) , size = ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) ) : <EOL> if isinstance ( origin , BoundingBox ) : <EOL> self . _origin = origin . _origin <EOL> self . _size = origin . _size <EOL> else : <EOL> self . _origin , self . _size = Vector ( * ( self . type ( a ) for a in origin ) ) , Vector ( * ( self . type ( a ) for a in size ) ) <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" . format ( self . origin , self . size ) <EOL> @ property <EOL> def origin ( self ) : <EOL> "<STR_LIT>" <EOL> return self . _origin <EOL> @ property <EOL> def size ( self ) : <EOL> "<STR_LIT>" <EOL> return self . _size <EOL> @ property <EOL> def width ( self ) : <EOL> "<STR_LIT>" <EOL> return self . _size . x <EOL> @ property <EOL> def height ( self ) : <EOL> "<STR_LIT>" <EOL> return self . _size . y <EOL> @ property <EOL> def length ( self ) : <EOL> "<STR_LIT>" <EOL> return self . _size . z <EOL> @ property <EOL> def minx ( self ) : <EOL> return self . origin . x <EOL> @ property <EOL> def miny ( self ) : <EOL> return self . origin . y <EOL> @ property <EOL> def minz ( self ) : <EOL> return self . origin . z <EOL> @ property <EOL> def maxx ( self ) : <EOL> return self . origin . x + self . size . x <EOL> @ property <EOL> def maxy ( self ) : <EOL> return self . origin . y + self . size . y <EOL> @ property <EOL> def maxz ( self ) : <EOL> return self . origin . z + self . size . z <EOL> @ property <EOL> def maximum ( self ) : <EOL> "<STR_LIT>" <EOL> return self . _origin + self . _size <EOL> @ property <EOL> def volume ( self ) : <EOL> "<STR_LIT>" <EOL> return self . size . x * self . size . y * self . size . z <EOL> @ property <EOL> def positions ( self ) : <EOL> """<STR_LIT>""" <EOL> return itertools . product ( <EOL> xrange ( self . minx , self . maxx ) , <EOL> xrange ( self . miny , self . maxy ) , <EOL> xrange ( self . minz , self . maxz ) <EOL> ) <EOL> def intersect ( self , box ) : <EOL> """<STR_LIT>""" <EOL> if ( self . minx > box . maxx or self . maxx < box . minx or <EOL> self . miny > box . maxy or self . maxy < box . miny or <EOL> self . minz > box . maxz or self . maxz < box . minz ) : <EOL> return BoundingBox ( ) <EOL> origin = Vector ( <EOL> max ( self . minx , box . minx ) , <EOL> max ( self . miny , box . miny ) , <EOL> max ( self . minz , box . minz ) , <EOL> ) <EOL> maximum = Vector ( <EOL> min ( self . maxx , box . maxx ) , <EOL> min ( self . maxy , box . maxy ) , <EOL> min ( self . maxz , box . maxz ) , <EOL> ) <EOL> return BoundingBox ( origin , maximum - origin ) <EOL> def union ( self , box ) : <EOL> """<STR_LIT>""" <EOL> origin = Vector ( <EOL> min ( self . minx , box . minx ) , <EOL> min ( self . miny , box . miny ) , <EOL> min ( self . minz , box . minz ) , <EOL> ) <EOL> maximum = Vector ( <EOL> max ( self . maxx , box . maxx ) , <EOL> max ( self . maxy , box . maxy ) , <EOL> max ( self . maxz , box . maxz ) , <EOL> ) <EOL> return BoundingBox ( origin , maximum - origin ) <EOL> def expand ( self , dx , dy = None , dz = None ) : <EOL> """<STR_LIT>""" <EOL> if dz is None : <EOL> dz = dx <EOL> if dy is None : <EOL> dy = dx <EOL> origin = self . origin - ( dx , dy , dz ) <EOL> size = self . size + ( dx * <NUM_LIT:2> , dy * <NUM_LIT:2> , dz * <NUM_LIT:2> ) <EOL> return BoundingBox ( origin , size ) <EOL> def __contains__ ( self , pos ) : <EOL> x , y , z = pos <EOL> if x < self . minx or x >= self . maxx : <EOL> return False <EOL> if y < self . miny or y >= self . maxy : <EOL> return False <EOL> if z < self . minz or z >= self . maxz : <EOL> return False <EOL> return True <EOL> def __cmp__ ( self , b ) : <EOL> return cmp ( ( self . origin , self . size ) , ( b . origin , b . size ) ) <EOL> @ property <EOL> def mincx ( self ) : <EOL> "<STR_LIT>" <EOL> return self . origin . x >> <NUM_LIT:4> <EOL> @ property <EOL> def mincz ( self ) : <EOL> "<STR_LIT>" <EOL> return self . origin . z >> <NUM_LIT:4> <EOL> @ property <EOL> def maxcx ( self ) : <EOL> "<STR_LIT>" <EOL> return ( ( self . origin . x + self . size . x - <NUM_LIT:1> ) >> <NUM_LIT:4> ) + <NUM_LIT:1> <EOL> @ property <EOL> def maxcz ( self ) : <EOL> "<STR_LIT>" <EOL> return ( ( self . origin . z + self . size . z - <NUM_LIT:1> ) >> <NUM_LIT:4> ) + <NUM_LIT:1> <EOL> def chunkBox ( self , level ) : <EOL> """<STR_LIT>""" <EOL> box = self <EOL> return BoundingBox ( ( box . mincx << <NUM_LIT:4> , <NUM_LIT:0> , box . mincz << <NUM_LIT:4> ) , <EOL> ( box . maxcx - box . mincx << <NUM_LIT:4> , level . Height , box . maxcz - box . mincz << <NUM_LIT:4> ) ) <EOL> @ property <EOL> def chunkPositions ( self ) : <EOL> return itertools . product ( xrange ( self . mincx , self . maxcx ) , xrange ( self . mincz , self . maxcz ) ) <EOL> @ property <EOL> def chunkCount ( self ) : <EOL> return ( self . maxcx - self . mincx ) * ( self . maxcz - self . mincz ) <EOL> @ property <EOL> def isChunkAligned ( self ) : <EOL> return ( self . origin . x & <NUM_LIT> == <NUM_LIT:0> ) and ( self . origin . z & <NUM_LIT> == <NUM_LIT:0> ) <EOL> class FloatBox ( BoundingBox ) : <EOL> type = float </s>
