comparison orpg/mapper/region.py @ 71:449a8900f9ac ornery-dev

Code refining almost completed, for this round. Some included files are still in need of some clean up, but this is test worthy.
author sirebral
date Thu, 20 Aug 2009 03:00:39 -0500
parents 072ffc1d466f
children dcae32e219f1
comparison
equal deleted inserted replaced
70:52a5fa913008 71:449a8900f9ac
154 154
155 def subtract(self,pt): 155 def subtract(self,pt):
156 return IRect().make(self.left+pt.X,self.top+pt.Y,self.right+pt.X,self.bottom+pt.Y) 156 return IRect().make(self.left+pt.X,self.top+pt.Y,self.right+pt.X,self.bottom+pt.Y)
157 157
158 def intersect(self,rect): 158 def intersect(self,rect):
159 return IRect().make(max(self.left,rect.left),max(self.top,rect.top),min(self.right,rect.right),min(self.bottom,rect.bottom)) 159 return IRect().make(max(self.left,rect.left),
160 max(self.top,rect.top),min(self.right,rect.right),
161 min(self.bottom,rect.bottom))
160 162
161 def union(self,rect): 163 def union(self,rect):
162 return IRect().make(min(self.left,rect.left),min(self.top,rect.top),max(self.right,rect.right),max(self.bottom,rect.bottom)) 164 return IRect().make(min(self.left,rect.left),
165 min(self.top,rect.top),max(self.right,rect.right),
166 max(self.bottom,rect.bottom))
163 167
164 def equals(self,rect): 168 def equals(self,rect):
165 if (self.top==rect.top and self.bottom==rect.bottom and self.left==rect.left and self.right==rect.right): return 1 169 if (self.top==rect.top and self.bottom==rect.bottom and self.left==rect.left and self.right==rect.right): return 1
166 return 0 170 return 0
167 171
204 x="[" 208 x="["
205 for y in self.GetList(): x+=" "+str(y.bounds)+" " 209 for y in self.GetList(): x+=" "+str(y.bounds)+" "
206 x+="]" 210 x+="]"
207 return x 211 return x
208 212
209 #remove all rectangles from list 213 #remove all rectangles from list
210 def Clear(self): 214 def Clear(self):
211 while(self.first): 215 while(self.first):
212 rect=self.first 216 rect=self.first
213 self.first=self.first.next 217 self.first=self.first.next
214 del rect 218 del rect
215 self.last=None 219 self.last=None
216 self.count=0 220 self.count=0
217 221
218 #add a new clipping rectangle to list 222 #add a new clipping rectangle to list
219 def AddRect(self,rect): 223 def AddRect(self,rect):
220 rect.prev=None 224 rect.prev=None
221 rect.next=self.first 225 rect.next=self.first
222 if not (self.first is None): self.first.prev=rect 226 if not (self.first is None): self.first.prev=rect
223 self.first=rect 227 self.first=rect
224 if self.last is None: self.last=rect 228 if self.last is None: self.last=rect
225 self.count += 1 229 self.count += 1
226 230
227 #removes the passed clipping rectangle from the list 231 #removes the passed clipping rectangle from the list
228 def RemoveRect(self,rect): 232 def RemoveRect(self,rect):
229 if not (rect.prev is None): rect.prev.next=rect.next 233 if not (rect.prev is None): rect.prev.next=rect.next
230 else: self.first=rect.next 234 else: self.first=rect.next
231 if not (rect.next is None): rect.next.prev=rect.prev 235 if not (rect.next is None): rect.next.prev=rect.prev
232 else: self.last=rect.prev 236 else: self.last=rect.prev
233 self.count -= 1 237 self.count -= 1
234 238
235 # find the clipping rectangle at the the beginning of the list, remove it, 239 # find the clipping rectangle at the the beginning of the list, remove it,
236 # and return it 240 # and return it
237 def RemoveHead(self): 241 def RemoveHead(self):
238 if self.count==0: return None 242 if self.count==0: return None
239 rect=self.first 243 rect=self.first
240 self.first=rect.next 244 self.first=rect.next
241 if (self.first is None): self.last=None 245 if (self.first is None): self.last=None
242 self.count -= 1 246 self.count -= 1
243 return rect 247 return rect
244 248
245 # stealrects -- appends the list of clipping rectangles in pclist to the current 249 # stealrects -- appends the list of clipping rectangles in pclist to the current
246 # list. removes the entries from pclist 250 # list. removes the entries from pclist
247 def StealRects(self,pclist): 251 def StealRects(self,pclist):
248 if pclist.first is None: return 252 if pclist.first is None: return
249 if self.first is None: 253 if self.first is None:
250 self.first=pclist.first 254 self.first=pclist.first
251 self.last=pclist.last 255 self.last=pclist.last
256 self.count += pclist.count 260 self.count += pclist.count
257 pclist.first = None 261 pclist.first = None
258 pclist.last = None 262 pclist.last = None
259 pclist.count = 0 263 pclist.count = 0
260 264
261 # utilitarian procedure to return all clipping rectangles as a Python list 265 # utilitarian procedure to return all clipping rectangles as a Python list
262 def GetList(self): 266 def GetList(self):
263 result=[] 267 result=[]
264 f = self.first 268 f = self.first
265 while f: 269 while f:
266 result.append(f) 270 result.append(f)