# Path: intelligine/cst.py
# POINTS_SMELL = IncrementedNamedInt.get('intelligine.points_smell')
# 
# MOLECULES = IncrementedNamedInt.get('intelligine.molecules')
# 
# MOLECULES_DIRECTION = IncrementedNamedInt.get('intelligine.mol.direction')
# 
# Path: intelligine/core/exceptions.py
# class NoMolecule(MoleculeException):
#     pass
# 
# Path: intelligine/synergy/event/move/direction.py
# def get_direction_for_degrees(degrees):
#     if degrees < 0:
#         degrees = 360 - abs(degrees)
#     for plage in directions_degrees:
#         if plage[0] <= degrees <= plage[1]:
#             return directions_degrees[plage]
#     raise Exception("Unknow plage for degree \"" + str(degrees) + '"')


from intelligine.cst import POINTS_SMELL, MOLECULES, MOLECULES_DIRECTION
from intelligine.core.exceptions import NoMolecule
from random import shuffle
from synergine_xyz.geometry import get_degree_from_north
from intelligine.synergy.event.move.direction import get_direction_for_degrees
            flavour = context.molecules().get_flavour(around_point)
            try:
                around_molecule = flavour.get_molecule(category=MOLECULES_DIRECTION, type=molecule_type)
                if molecule_filter(around_molecule):
                    around_molecules_points.append((around_point, around_molecule))
            except NoMolecule:
                pass  # No molecule, ok continue to sniff around

        return around_molecules_points

    @classmethod
    def get_best_molecule_direction_in(cls, context, reference_point, points, molecule_type):
        around_molecules_points = []
        for around_point in points:
            flavour = context.molecules().get_flavour(around_point)
            try:
                around_molecule = flavour.get_molecule(category=MOLECULES_DIRECTION, type=molecule_type)
                around_molecules_points.append((around_point, around_molecule))
            except NoMolecule:
                pass  # Ok, no molecule, continue to sniff around

        if not around_molecules_points \
           or (len(around_molecules_points) == 1 and around_molecules_points[0][0] == reference_point):
            raise NoMolecule()

        shuffle(around_molecules_points)
        around_molecules_sorted = sorted(around_molecules_points, key=lambda x: x[1].get_intensity(), reverse=True)
        go_to_point = around_molecules_sorted[0][0]

        direction_degrees = get_degree_from_north(reference_point, go_to_point)

# Path: intelligine/cst.py
# POINTS_SMELL = IncrementedNamedInt.get('intelligine.points_smell')
# 
# MOLECULES = IncrementedNamedInt.get('intelligine.molecules')
# 
# MOLECULES_DIRECTION = IncrementedNamedInt.get('intelligine.mol.direction')
# 
# Path: intelligine/core/exceptions.py
# class NoMolecule(MoleculeException):
#     pass
# 
# Path: intelligine/synergy/event/move/direction.py
# def get_direction_for_degrees(degrees):
#     if degrees < 0:
#         degrees = 360 - abs(degrees)
#     for plage in directions_degrees:
#         if plage[0] <= degrees <= plage[1]:
#             return directions_degrees[plage]
#     raise Exception("Unknow plage for degree \"" + str(degrees) + '"')


# Path: intelligine/simulation/molecule/DirectionMolecule.py
from intelligine.cst import POINTS_SMELL, MOLECULES, MOLECULES_DIRECTION
from intelligine.core.exceptions import NoMolecule
from random import shuffle
from synergine_xyz.geometry import get_degree_from_north
from intelligine.synergy.event.move.direction import get_direction_for_degrees

            flavour = context.molecules().get_flavour(around_point)
            try:
                around_molecule = flavour.get_molecule(category=MOLECULES_DIRECTION, type=molecule_type)
                if molecule_filter(around_molecule):
                    around_molecules_points.append((around_point, around_molecule))
            except NoMolecule:
                pass  # No molecule, ok continue to sniff around

        return around_molecules_points

    @classmethod
    def get_best_molecule_direction_in(cls, context, reference_point, points, molecule_type):
        around_molecules_points = []
        for around_point in points:
            flavour = context.molecules().get_flavour(around_point)
            try:
                around_molecule = flavour.get_molecule(category=MOLECULES_DIRECTION, type=molecule_type)
                around_molecules_points.append((around_point, around_molecule))
            except NoMolecule:
                pass  # Ok, no molecule, continue to sniff around

        if not around_molecules_points \
           or (len(around_molecules_points) == 1 and around_molecules_points[0][0] == reference_point):
            raise NoMolecule()

        shuffle(around_molecules_points)
        around_molecules_sorted = sorted(around_molecules_points, key=lambda x: x[1].get_intensity(), reverse=True)
        go_to_point = around_molecules_sorted[0][0]

        direction_degrees = get_degree_from_north(reference_point, go_to_point)

        direction = get_direction_for_degrees(direction_degrees)