Permalink
Browse files

Cleanup: Check whether a point is in the level's bounds using `in sel…

…f.bounds`
  • Loading branch information...
1 parent a43cfa1 commit 3c51ed835ed429fd1d6c27cab95e9f31bd25ddde @codewarrior0 codewarrior0 committed Nov 14, 2012
Showing with 6 additions and 12 deletions.
  1. +6 −12 level.py
View
@@ -295,14 +295,12 @@ def getChunkSlices(self, box):
if self.containsChunk(*cPos))
def containsPoint(self, x, y, z):
- return (x >= 0 and x < self.Width and
- y >= 0 and y < self.Height and
- z >= 0 and z < self.Length)
+ return (x, y, z) in self.bounds
def containsChunk(self, cx, cz):
- # w+15 to allow non 16 aligned schematics
- return (cx >= 0 and cx < (self.Width + 15 >> 4) and
- cz >= 0 and cz < (self.Length + 15 >> 4))
+ bounds = self.bounds
+ return ((bounds.mincx <= cx < bounds.maxcx) and
+ (bounds.mincz <= cz < bounds.maxcz))
def fakeBlocksForChunk(self, cx, cz):
# return a 16x16xH block array for rendering. Alpha levels can
@@ -345,16 +343,12 @@ def blockLightAt(self, x, y, z):
return 15
def blockAt(self, x, y, z):
- if x < 0 or y < 0 or z < 0:
- return 0
- if x >= self.Width or y >= self.Height or z >= self.Length:
+ if (x, y, z) not in self.bounds:
return 0
return self.Blocks[x, z, y]
def setBlockAt(self, x, y, z, blockID):
- if x < 0 or y < 0 or z < 0:
- return 0
- if x >= self.Width or y >= self.Height or z >= self.Length:
+ if (x, y, z) not in self.bounds:
return 0
self.Blocks[x, z, y] = blockID

0 comments on commit 3c51ed8

Please sign in to comment.