pydistsim.network.environment.Environment2D

class Environment2D(path='', scale=None, shape=None)[source]

Bases: Environment

Base class for 2D environment. The Environment2D allows to define map and scale of 2D environment.

Parameters:
  • path – Optional. The path to an image file to load as the environment. If not provided, a default environment will be created.

  • scale – Optional. The scale factor for the environment image. If not provided, the default scale factor will be used.

  • shape – Optional. The shape of the environment. If not provided, the default shape will be used.

Methods

__init__

are_visible

Returns true if there is line of sight between source (x0,y0) and destination (x1,y1).

find_random_pos

Returns a random position in the environment.

is_space

Returns true if selected space (x,y) is space.

Attributes

dim

image

are_visible(xy0, xy1)[source]

Returns true if there is line of sight between source (x0,y0) and destination (x1,y1).

Parameters:
  • xy0 (tuple) – Tuple representing the coordinates of the source point (x0, y0).

  • xy1 (tuple) – Tuple representing the coordinates of the destination point (x1, y1).

Returns:

True if there is line of sight between the source and destination points, False otherwise.

Return type:

bool

This is a floating point version of the Bresenham algorithm that does not spread on diagonal pixels.

find_random_pos(n=100)[source]

Returns a random position in the environment.

Parameters:

n (int) – The maximum number of iterations to find a free space.

Returns:

The random position found.

Return type:

tuple

is_space(xy)[source]

Returns true if selected space (x,y) is space. If point xy is exactly on the edge or crossing check surrounding pixels.

Parameters:

xy (tuple) – A tuple representing the coordinates (x, y) of the space to check.

Returns:

True if the selected space is a space, False otherwise.

Return type:

bool