From b88e6367286df55a972073c53cc21b52ccd99272 Mon Sep 17 00:00:00 2001 From: Aaron Griffith Date: Sun, 29 Jan 2012 16:45:23 -0500 Subject: [PATCH] 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. --- overviewer_core/settingsValidators.py | 9 +++-- overviewer_core/world.py | 56 ++++++++++++++------------- 2 files changed, 35 insertions(+), 30 deletions(-) diff --git a/overviewer_core/settingsValidators.py b/overviewer_core/settingsValidators.py index 4d9d3a2..9163689 100644 --- a/overviewer_core/settingsValidators.py +++ b/overviewer_core/settingsValidators.py @@ -3,6 +3,7 @@ import os import os.path import rendermodes +from world import UPPER_LEFT, UPPER_RIGHT, LOWER_LEFT, LOWER_RIGHT class ValidationException(Exception): pass @@ -34,10 +35,10 @@ def validateNorthDirection(direction, **kwargs): if type(direction) == int: intdir = direction else: - if direction == "upper-left": intdir = 0 - if direction == "upper-right": intdir = 1 - if direction == "lower-right": intdir = 2 - if direction == "lower-left": intdir = 3 + if direction == "upper-left": intdir = UPPER_LEFT + if direction == "upper-right": intdir = UPPER_RIGHT + if direction == "lower-right": intdir = LOWER_RIGHT + if direction == "lower-left": intdir = LOWER_LEFT if intdir < 0 or intdir > 3: raise ValidationException("%r is not a valid north direction" % direction) return intdir diff --git a/overviewer_core/world.py b/overviewer_core/world.py index fdcdb35..b927fb9 100644 --- a/overviewer_core/world.py +++ b/overviewer_core/world.py @@ -400,41 +400,45 @@ class RegionSet(object): y = int(p[2]) 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) -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) -UPPER_RIGHT = 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, - } +LOWER_LEFT = 3 ## - Return the world such that north is down the -X axis (rotate 90 degrees clockwise) class RotatedRegionSet(RegionSet): """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): self.north_dir = north_dir - self.unrotate = unrotation_funcs[north_dir] - self.rotate = rotation_funcs[north_dir] + self.unrotate = self._unrotation_funcs[north_dir] + self.rotate = self._rotation_funcs[north_dir] super(RotatedRegionSet, self).__init__(regiondir)