direction.py 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. """
  2. Directions identifiers 3D, central position is 14.
  3. niv -1: 1 2 3
  4. 4 5 6
  5. 7 8 9
  6. niv 0: 10 11 12
  7. 13 14 15
  8. 16 17 18
  9. niv 1: 19 20 21
  10. 22 23 24
  11. 25 26 27
  12. """
  13. directions = (0, 27)
  14. directions_under_level = (0, 9)
  15. directions_same_level = (10, 18)
  16. directions_upper_level = (19, 27)
  17. directions_modifiers = {
  18. # (z, x, y)
  19. 1: (-1, -1, -1),
  20. 2: (-1, 0, -1),
  21. 3: (-1, 1, -1),
  22. 4: (-1, -1, 0),
  23. 5: (-1, 0, 0),
  24. 6: (-1, 1, 0),
  25. 7: (-1, -1, 1),
  26. 8: (-1, 0, 1),
  27. 9: (-1, 1, 1),
  28. # (z, x, y)
  29. 10: (0, -1, -1),
  30. 11: (0, 0, -1),
  31. 12: (0, 1, -1),
  32. 13: (0, -1, 0),
  33. 14: (0, 0, 0),
  34. 15: (0, 1, 0),
  35. 16: (0, -1, 1),
  36. 17: (0, 0, 1),
  37. 18: (0, 1, 1),
  38. # (z, x, y)
  39. 19: (1, -1, -1),
  40. 20: (1, 0, -1),
  41. 21: (1, 1, -1),
  42. 22: (1, -1, 0),
  43. 23: (1, 0, 0),
  44. 24: (1, 1, 0),
  45. 25: (1, -1, 1),
  46. 26: (1, 0, 1),
  47. 27: (1, 1, 1),
  48. }
  49. """
  50. Directions identifiers 3D, central position is 14.
  51. niv -1: 1 2 3
  52. 4 5 6
  53. 7 8 9
  54. niv 0: 10 11 12
  55. 13 14 15
  56. 16 17 18
  57. niv 1: 19 20 21
  58. 22 23 24
  59. 25 26 27
  60. """
  61. directions_slighty = {
  62. 1: (1, 2, 4, 13, 10, 11),
  63. 2: (1, 2, 3, 10, 11, 12),
  64. 3: (2, 3, 6, 11, 12, 15),
  65. 4: (1, 4, 7, 10, 13, 16),
  66. 5: (1, 2, 3, 4, 5, 6, 7, 8, 9),
  67. 6: (2, 3, 6, 12, 15, 18),
  68. 7: (4, 7, 8, 13, 16, 17),
  69. 8: (7, 8, 9, 16, 17, 18),
  70. 9: (6, 9, 8, 15, 18, 17),
  71. # (z, x, y)
  72. 10: (13, 10, 11),
  73. 11: (10, 11, 12),
  74. 12: (11, 12, 15),
  75. 13: (10, 13, 16),
  76. 14: (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27),
  77. 15: (12, 15, 18),
  78. 16: (13, 16, 17),
  79. 17: (16, 17, 18),
  80. 18: (15, 18, 17),
  81. # (z, x, y)
  82. 19: (22, 19, 20, 13, 10, 11),
  83. 20: (19, 20, 21, 10, 11, 12),
  84. 21: (20, 21, 24, 11, 12, 15),
  85. 22: (19, 22, 25, 10, 13, 16),
  86. 23: (19, 20, 21, 22, 23, 24, 25, 26, 27),
  87. 24: (21, 24, 27, 12, 15, 18),
  88. 25: (22, 25, 26, 13, 16, 17),
  89. 26: (25, 26, 27, 16, 17, 18),
  90. 27: (24, 27, 26, 15, 18, 17),
  91. }
  92. directions_degrees = {
  93. (0, 22): 11,
  94. (22, 67): 12,
  95. (68, 112): 15,
  96. (112, 158): 18,
  97. (158, 201): 17,
  98. (201, 246): 16,
  99. (246, 291): 13,
  100. (291, 338): 10,
  101. (338, 0): 11
  102. }
  103. def get_direction_for_degrees(degrees):
  104. if degrees < 0:
  105. degrees = 360 - degrees - degrees - degrees # TODO: math absolute !!!
  106. for plage in directions_degrees:
  107. if degrees >= plage[0] and degrees <= plage[1]:
  108. return directions_degrees[plage]
  109. raise IndexError() # TODO: personnalised exception
  110. """
  111. niv 0: 10 11 12
  112. 13 14 15
  113. 16 17 18
  114. """
  115. directions_opposites = {
  116. 10: 18,
  117. 11: 17,
  118. 12: 16,
  119. 13: 15,
  120. 15: 13,
  121. 16: 12,
  122. 17: 11,
  123. 18: 10
  124. }
  125. def get_direction_opposite(direction):
  126. return directions_opposites[direction]