changed settings to emit correct north values, north values now represent rotations
each north value is an integer representing how many times to rotate the map by 90 degrees counterclockwise.
This commit is contained in:
@@ -3,6 +3,7 @@ import os
|
|||||||
import os.path
|
import os.path
|
||||||
|
|
||||||
import rendermodes
|
import rendermodes
|
||||||
|
from world import UPPER_LEFT, UPPER_RIGHT, LOWER_LEFT, LOWER_RIGHT
|
||||||
|
|
||||||
class ValidationException(Exception):
|
class ValidationException(Exception):
|
||||||
pass
|
pass
|
||||||
@@ -34,10 +35,10 @@ def validateNorthDirection(direction, **kwargs):
|
|||||||
if type(direction) == int:
|
if type(direction) == int:
|
||||||
intdir = direction
|
intdir = direction
|
||||||
else:
|
else:
|
||||||
if direction == "upper-left": intdir = 0
|
if direction == "upper-left": intdir = UPPER_LEFT
|
||||||
if direction == "upper-right": intdir = 1
|
if direction == "upper-right": intdir = UPPER_RIGHT
|
||||||
if direction == "lower-right": intdir = 2
|
if direction == "lower-right": intdir = LOWER_RIGHT
|
||||||
if direction == "lower-left": intdir = 3
|
if direction == "lower-left": intdir = LOWER_LEFT
|
||||||
if intdir < 0 or intdir > 3:
|
if intdir < 0 or intdir > 3:
|
||||||
raise ValidationException("%r is not a valid north direction" % direction)
|
raise ValidationException("%r is not a valid north direction" % direction)
|
||||||
return intdir
|
return intdir
|
||||||
|
|||||||
@@ -400,41 +400,45 @@ class RegionSet(object):
|
|||||||
y = int(p[2])
|
y = int(p[2])
|
||||||
yield (x, y, path)
|
yield (x, y, path)
|
||||||
|
|
||||||
# see RegionSet.rotate. These values are chosen so that they can be passed directly to rot90
|
# see RegionSet.rotate. These values are chosen so that they can be
|
||||||
|
# passed directly to rot90; this means that they're the number of
|
||||||
|
# times to rotate by 90 degrees CCW
|
||||||
UPPER_LEFT = 0 ## - Return the world such that north is down the -Z axis (no rotation)
|
UPPER_LEFT = 0 ## - Return the world such that north is down the -Z axis (no rotation)
|
||||||
LOWER_LEFT = 1 ## - Return the world such that north is down the -X axis (rotate 90 degrees counterclockwise)
|
UPPER_RIGHT = 1 ## - Return the world such that north is down the +X axis (rotate 90 degrees counterclockwise)
|
||||||
LOWER_RIGHT = 2 ## - Return the world such that north is down the +Z axis (rotate 180 degrees)
|
LOWER_RIGHT = 2 ## - Return the world such that north is down the +Z axis (rotate 180 degrees)
|
||||||
UPPER_RIGHT = 3 ## - Return the world such that north is down the +X axis (rotate 90 degrees clockwise)
|
LOWER_LEFT = 3 ## - Return the world such that north is down the -X axis (rotate 90 degrees clockwise)
|
||||||
|
|
||||||
NO_ROTATION = lambda x,z: (x,z)
|
|
||||||
ROTATE_CLOCKWISE = lambda x,z: (-z,x)
|
|
||||||
ROTATE_COUNTERCLOCKWISE = lambda x,z: (z,-x)
|
|
||||||
ROTATE_180 = lambda x,z: (-x,-z)
|
|
||||||
|
|
||||||
# These take rotated coords and translate into un-rotated coords
|
|
||||||
unrotation_funcs = {
|
|
||||||
UPPER_LEFT: NO_ROTATION,
|
|
||||||
UPPER_RIGHT: ROTATE_CLOCKWISE,
|
|
||||||
LOWER_LEFT: ROTATE_COUNTERCLOCKWISE,
|
|
||||||
LOWER_RIGHT: ROTATE_180,
|
|
||||||
}
|
|
||||||
|
|
||||||
# These translate un-rotated coordinates into rotated coordinates
|
|
||||||
rotation_funcs = {
|
|
||||||
UPPER_LEFT: NO_ROTATION,
|
|
||||||
UPPER_RIGHT: ROTATE_COUNTERCLOCKWISE,
|
|
||||||
LOWER_LEFT: ROTATE_CLOCKWISE,
|
|
||||||
LOWER_RIGHT: ROTATE_180,
|
|
||||||
}
|
|
||||||
|
|
||||||
class RotatedRegionSet(RegionSet):
|
class RotatedRegionSet(RegionSet):
|
||||||
"""A regionset, only rotated such that north points in the given direction
|
"""A regionset, only rotated such that north points in the given direction
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# some class-level rotation constants
|
||||||
|
_NO_ROTATION = lambda x,z: (x,z)
|
||||||
|
_ROTATE_CLOCKWISE = lambda x,z: (-z,x)
|
||||||
|
_ROTATE_COUNTERCLOCKWISE = lambda x,z: (z,-x)
|
||||||
|
_ROTATE_180 = lambda x,z: (-x,-z)
|
||||||
|
|
||||||
|
# These take rotated coords and translate into un-rotated coords
|
||||||
|
_unrotation_funcs = {
|
||||||
|
0: _NO_ROTATION,
|
||||||
|
1: _ROTATE_COUNTERCLOCKWISE,
|
||||||
|
2: _ROTATE_180,
|
||||||
|
3: _ROTATE_CLOCKWISE,
|
||||||
|
}
|
||||||
|
|
||||||
|
# These translate un-rotated coordinates into rotated coordinates
|
||||||
|
_rotation_funcs = {
|
||||||
|
0: _NO_ROTATION,
|
||||||
|
1: _ROTATE_CLOCKWISE,
|
||||||
|
2: _ROTATE_180,
|
||||||
|
3: _ROTATE_COUNTERCLOCKWISE,
|
||||||
|
}
|
||||||
|
|
||||||
def __init__(self, regiondir, north_dir):
|
def __init__(self, regiondir, north_dir):
|
||||||
self.north_dir = north_dir
|
self.north_dir = north_dir
|
||||||
self.unrotate = unrotation_funcs[north_dir]
|
self.unrotate = self._unrotation_funcs[north_dir]
|
||||||
self.rotate = rotation_funcs[north_dir]
|
self.rotate = self._rotation_funcs[north_dir]
|
||||||
|
|
||||||
super(RotatedRegionSet, self).__init__(regiondir)
|
super(RotatedRegionSet, self).__init__(regiondir)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user