The class Quadtree (object) :
MaxObjects=10
MaxLevels=5
Level=0
Objects=[]
Bounds=[]
Nodes=[[], [], [], []]
VerticalMidpoint=0
HorizontalMidpoint=0
Def __init__ (self, level, bound) :
Self. Level=Level
The self. The Bounds=bound
Def the Clear (self) :
The self. The Objects. The clear ()
N=len (self) Nodes)
For I in range (0, n) :
Self. Nodes [I]=[]
Def Split (self) :
SubWidth=self. Bounds. GetWidth ()/2
SubHeight=self. Bounds. GetHeight ()/2
X=self. Bounds. GetX ()
Y=self. Bounds. GetY ()
The self. The Nodes [2]=Quadtree (self. The Level + 1, a Rectangle ([x + SubWidth, y + SubHeight], SubWidth, SubHeight))
The self. The Nodes [3]=Quadtree (self. The Level + 1, a Rectangle ([x, y + SubHeight], SubWidth, SubHeight))
The self. The Nodes [0]=Quadtree (self. The Level + 1, a Rectangle ((x, y), SubWidth, SubHeight))
Self. Nodes [1]=Quadtree (self. The Level + 1, a Rectangle ([x + SubWidth, y], SubWidth SubHeight))
Def GetIndex (self, particle) :
The index=1
A=0
Self. VerticalMidpoint=self. Bounds. GetX () + self. The Bounds. GetWidth ()/2
Self. HorizontalMidpoint=self. Bounds. GetY () + self. The Bounds. GetHeight ()/2
If particle. The Location [1]
The else:
A='BottomQuadrant'
If particle. The Location [0]
The index=3
Elif a=='BottomQuadrant:
The index=0
Elif particle. The Location [0] & gt; Self. VerticalMidpoint:
If a=='TopQuadrant:
The index=2
Elif a=='BottomQuadrant:
The index=1
Return index
Def Insert (self, particle) :
If the self. The Nodes [0]!=[] :
The index=self. GetIndex (particle)
If the index!=1:
Self. Nodes [index]. Append (particle)
Self. Objects. Append (particle)
If len (self. Objects) & gt; Self. MaxObjects and self. Level
The self. The Split ()
I=0
While i
If the index!=1:
Self. Nodes [index]. Append (self) Objects [I])
Del self. Objects [I]
The else:
I +=1
Def Retrieve (self, returnObjects, particle) :
The index=particle. GetIndex (self)
If the index!=1 and the self. The Nodes [0]!=[] :
For n in the self. Nodes [index] :
ReturnObjects. Append (n)
Return returnObjects
This is the specific error code
Bosses give advice or comments, appreciate