You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
3nar/code/spaceAround.py

82 lines
2.8 KiB

import numpy as np
from sympy.utilities.iterables import multiset_permutations
import copy
def findCoordAround(center, nbAround):
nbDimention = len(center)
find = []
for i in range(1, nbDimention + 1):
find = getNCoordDifferente(center, find, i, nbAround)
return find
def getNCoordDifferente(center, find, nbDifferanteValue, nbAround):
coord = []
for i in range(nbDifferanteValue):
if -nbAround + i > nbAround:
return find
coord.append(-nbAround + i)
find = getCompletVariationOfCoord(center, find, coord)
while True:
modified = False
cursor = len(coord) - 1
while not modified:
if cursor < 0 or cursor == len(coord):
return find
if coord[cursor] + len(coord) - 1 - cursor < nbAround:
modified = True
coord[cursor] += 1
val = coord[cursor] + 1
cursor += 1
while cursor < len(coord):
coord[cursor] = val
cursor += 1
val += 1
else:
cursor -= 1
find = getCompletVariationOfCoord(center, find, coord)
def getCompletVariationOfCoord(center, find, partialCoord):
coord = partialCoord[:]
while len(coord) != len(center):
coord.append(partialCoord[0])
find = getPermutationOfCoord(center, find, coord)
while True:
modified = False
cursor = len(coord) - 1
while not modified:
if cursor == len(partialCoord) - 1:
return find
if coord[cursor] != partialCoord[len(partialCoord) - 1]:
modified = True
afterCursor = 0
while afterCursor < len(partialCoord) and coord[cursor] != partialCoord[afterCursor]:
afterCursor += 1
afterCursor += 1
while cursor < len(coord):
coord[cursor] = partialCoord[afterCursor]
cursor += 1
else:
cursor -= 1
find = getPermutationOfCoord(center, find, coord)
def getPermutationOfCoord(center, find, coord):
for perm in multiset_permutations(coord):
find.append(list(perm))
return find
def applySapceAroundToCase(center,spaceAround,space):
reelSpaceAround = []
spaceAroundCopy = copy.deepcopy(spaceAround)
for y in range(len(spaceAround)):
estBon = True
for i in range(len(spaceAroundCopy[y])):
if not estBon:
continue
else :
spaceAroundCopy[y][i] += center[i]
estBon = estBon and 0 <= spaceAroundCopy[y][i] <= space.nbSubdivisions-1
if estBon:
reelSpaceAround.append(spaceAroundCopy[y])
return reelSpaceAround