2019-04-26 21:21:50 +02:00
|
|
|
# See LICENSE for licensing information.
|
|
|
|
|
#
|
2021-01-22 20:23:28 +01:00
|
|
|
# Copyright (c) 2016-2021 Regents of the University of California and The Board
|
2019-06-14 17:43:41 +02:00
|
|
|
# of Regents for the Oklahoma Agricultural and Mechanical College
|
|
|
|
|
# (acting for and on behalf of Oklahoma State University)
|
|
|
|
|
# All rights reserved.
|
2019-04-26 21:21:50 +02:00
|
|
|
#
|
2018-09-07 23:46:58 +02:00
|
|
|
from enum import Enum
|
2022-07-13 19:57:56 +02:00
|
|
|
from base.vector3d import vector3d
|
2021-02-23 22:32:13 +01:00
|
|
|
import debug
|
|
|
|
|
|
2018-09-07 23:46:58 +02:00
|
|
|
|
|
|
|
|
class direction(Enum):
|
|
|
|
|
NORTH = 1
|
|
|
|
|
SOUTH = 2
|
|
|
|
|
EAST = 3
|
|
|
|
|
WEST = 4
|
|
|
|
|
UP = 5
|
|
|
|
|
DOWN = 6
|
2018-11-02 19:11:32 +01:00
|
|
|
NORTHEAST = 7
|
|
|
|
|
NORTHWEST = 8
|
|
|
|
|
SOUTHEAST = 9
|
|
|
|
|
SOUTHWEST = 10
|
2018-10-29 21:49:29 +01:00
|
|
|
|
|
|
|
|
def get_offset(direct):
|
2020-11-03 15:29:17 +01:00
|
|
|
"""
|
2018-10-29 21:49:29 +01:00
|
|
|
Returns the vector offset for a given direction.
|
|
|
|
|
"""
|
|
|
|
|
if direct==direction.NORTH:
|
2021-02-23 22:32:13 +01:00
|
|
|
offset = vector3d(0, 1, 0)
|
2018-10-29 21:49:29 +01:00
|
|
|
elif direct==direction.SOUTH:
|
2021-02-23 22:32:13 +01:00
|
|
|
offset = vector3d(0, -1 ,0)
|
2018-10-29 21:49:29 +01:00
|
|
|
elif direct==direction.EAST:
|
2021-02-23 22:32:13 +01:00
|
|
|
offset = vector3d(1, 0, 0)
|
2018-10-29 21:49:29 +01:00
|
|
|
elif direct==direction.WEST:
|
2021-02-23 22:32:13 +01:00
|
|
|
offset = vector3d(-1, 0, 0)
|
2018-10-29 21:49:29 +01:00
|
|
|
elif direct==direction.UP:
|
2021-02-23 22:32:13 +01:00
|
|
|
offset = vector3d(0, 0, 1)
|
2018-10-29 21:49:29 +01:00
|
|
|
elif direct==direction.DOWN:
|
2021-02-23 22:32:13 +01:00
|
|
|
offset = vector3d(0, 0, -1)
|
2018-11-02 19:11:32 +01:00
|
|
|
elif direct==direction.NORTHEAST:
|
2021-02-23 22:32:13 +01:00
|
|
|
offset = vector3d(1, 1, 0)
|
2018-11-02 19:11:32 +01:00
|
|
|
elif direct==direction.NORTHWEST:
|
2021-02-23 22:32:13 +01:00
|
|
|
offset = vector3d(-1, 1, 0)
|
2018-11-02 19:11:32 +01:00
|
|
|
elif direct==direction.SOUTHEAST:
|
2021-02-23 22:32:13 +01:00
|
|
|
offset = vector3d(1, -1, 0)
|
2018-11-02 19:11:32 +01:00
|
|
|
elif direct==direction.SOUTHWEST:
|
2021-02-23 22:32:13 +01:00
|
|
|
offset = vector3d(-1, -1, 0)
|
2018-10-29 21:49:29 +01:00
|
|
|
else:
|
2018-11-02 19:11:32 +01:00
|
|
|
debug.error("Invalid direction {}".format(direct))
|
2018-10-29 21:49:29 +01:00
|
|
|
|
|
|
|
|
return offset
|
2018-10-30 20:24:13 +01:00
|
|
|
|
2018-11-02 22:57:40 +01:00
|
|
|
def cardinal_directions(up_down_too=False):
|
|
|
|
|
temp_dirs = [direction.NORTH, direction.EAST, direction.SOUTH, direction.WEST]
|
|
|
|
|
if up_down_too:
|
|
|
|
|
temp_dirs.extend([direction.UP, direction.DOWN])
|
|
|
|
|
return temp_dirs
|
2020-11-03 15:29:17 +01:00
|
|
|
|
2018-11-02 22:57:40 +01:00
|
|
|
def cardinal_offsets(up_down_too=False):
|
|
|
|
|
return [direction.get_offset(d) for d in direction.cardinal_directions(up_down_too)]
|
2018-10-30 20:24:13 +01:00
|
|
|
|
2018-11-02 19:11:32 +01:00
|
|
|
def all_directions():
|
|
|
|
|
return [direction.NORTH, direction.EAST, direction.SOUTH, direction.WEST,
|
|
|
|
|
direction.NORTHEAST, direction.NORTHWEST, direction.SOUTHEAST, direction.SOUTHWEST]
|
2020-11-03 15:29:17 +01:00
|
|
|
|
2018-11-02 19:11:32 +01:00
|
|
|
def all_offsets():
|
|
|
|
|
return [direction.get_offset(d) for d in direction.all_directions()]
|
|
|
|
|
|
|
|
|
|
def all_neighbors(cell):
|
2021-02-23 22:32:13 +01:00
|
|
|
return [cell + x for x in direction.all_offsets()]
|
2018-11-02 19:11:32 +01:00
|
|
|
|
|
|
|
|
def cardinal_neighbors(cell):
|
2021-02-23 22:32:13 +01:00
|
|
|
return [cell + x for x in direction.cardinal_offsets()]
|
2020-11-03 15:29:17 +01:00
|
|
|
|