Base Object Classes

This page groups the foundational scene objects used throughout DiscoPygal, including scene containers, obstacles, robots, and path-related classes.

These classes are imported through discopygal.solvers_infra and are shared by solvers, geometry utilities, and GUI tooling.

class discopygal.solvers_infra.Obstacle(data)

Bases: object

Abstract class that represents the notion of an obstacle in the scene. The obstacle has some geometry.

Parameters:

data (object) – Any metadata appended to the obstacle (could be None)

static from_dict(d)

Load json dict to object

Parameters:

d (dict) – dict representing json export

to_dict()

Convert current object to json dict

Returns:

dict representing json export

Return type:

dict

class discopygal.solvers_infra.ObstacleDisc(location, radius, data=None)

Bases: Obstacle

Disc obstacle in the scene. Its geometry is given as a location and radius.

Parameters:
  • location (Point_2) – Disc obstacle location point, as a CGAL point

  • radius (FT) – Disc radius, as a CGAL field type

static from_dict(d)

Load json dict to object

Parameters:

d (dict) – dict representing json export

to_dict()

Convert current object to json dict

Returns:

dict representing json export

Return type:

dict

class discopygal.solvers_infra.ObstaclePolygon(poly, data=None)

Bases: Obstacle

Polygon obstacle in the scene. Its geometry is given as a polygon.

Parameters:

poly (Polygon2) – Polygon obstacle geometry, as a CGAL polygon

static from_dict(d)

Load json dict to object

Parameters:

d (dict) – dict representing json export

to_dict()

Convert current object to json dict

Returns:

dict representing json export

Return type:

dict

class discopygal.solvers_infra.Path(points: list[~discopygal.solvers_infra.PathPoint], metric=<class 'discopygal.solvers_infra.metrics.Metric_Euclidean'>)

Bases: object

Representation of the path a single robot does

Parameters:

points (list<PathPoint>) – points along the path

calculate_length()

Return the total length of the path (sum of length between each two points)

Parameters:

metric (Metric) – The metric to use for calculating the distance between two points

Returns:

The length of the path

Return type:

FT

static path_from_points(points, metric=<class 'discopygal.solvers_infra.metrics.Metric_Euclidean'>) Path

Create a Path object from points as Point_2 or Point_d (not as PathPoint) Converts each point to PathPoint (with default constructor)

Parameters:

points (list<Point_2 or Point_d>) – List of points

Returns:

Path object

Return type:

Path

point_to_segment_index_and_fraction(point: Point_2)

For a point on the path return the index of the segment it is on the and fraction in the segment. For a point on two segments, returns as segment_index the smaller segment index, and 1 as fraction.

class discopygal.solvers_infra.PathCollection(paths=None, metric=<class 'discopygal.solvers_infra.metrics.Metric_Euclidean'>, add_padding_to_paths=True)

Bases: object

Collection of the paths of all the robots in the scene. This is the objects that is returned by a solver.

Parameters:

paths (dict<Robot, Path>) – collection of paths

add_padding_to_paths()

Add more points (end points) to the paths that are shorter than the maximum path so all paths will be at the same size

add_robot_path(robot, path)

Add a robot’s path to the collection

Parameters:
  • robot (Robot) – the robot we add

  • path (Path) – robot’s path

static from_dict(state, metric: ~discopygal.solvers_infra.metrics.Metric = <class 'discopygal.solvers_infra.metrics.Metric_Euclidean'>)

Load json dict to PathCollection object

Parameters:

state (dict) – dict representing json export

Returns:

PathCollection object

Return type:

PathCollection

to_dict()

Convert current object to json dict

Returns:

dict representing json export

Return type:

dict

class discopygal.solvers_infra.PathPoint(location, data=None)

Bases: object

A single point in the path (of some robot). Has a 2D location and additional data

Parameters:
  • location (Point_2) – location of point

  • data (dict) – attached data to point

class discopygal.solvers_infra.Robot(start, end, data=None)

Bases: object

Abstact class that represents the notion of a robot in a scene. Reference point is always the origin of the given geometry.

Parameters:
  • start (Point_2) – The start location of the robot, as a CGAL point (unless stated otherwise)

  • end (Point_2) – The end location of the robot, as a CGAL point (unless stated otherwise)

  • data (object) – Any metadata appended to the robot (could be None)

static from_dict(d)

Load json dict to object

Parameters:

d (dict) – dict representing json export

to_dict()

Convert current object to json dict

Returns:

dict representing json export

Return type:

dict

class discopygal.solvers_infra.RobotDisc(radius, start, end, data=None)

Bases: Robot

A disc robot. Its geometry is defined by its radius.

Parameters:
  • radius (FT) – The radius of the disc robot, as a CGAL field type

  • start (Point_2) – The start location of the robot, as a CGAL point

  • end (Point_2) – The end location of the robot, as a CGAL point

  • data (object) – Any metadata appended to the robot (could be None)

static from_dict(d)

Load json dict to object

Parameters:

d (dict) – dict representing json export

to_dict()

Convert current object to json dict

Returns:

dict representing json export

Return type:

dict

class discopygal.solvers_infra.RobotPolygon(poly, start, end, data=None)

Bases: Robot

A polygonal robot. Its geometry is given as a CGAL 2D polygon.

Parameters:
  • poly (Polygon2) – The geometry of the robot, as a CGAL 2D Polygon

  • start (Point_2) – The start location of the robot, as a CGAL point

  • end (Point_2) – The end location of the robot, as a CGAL point

  • data (object) – Any metadata appended to the robot (could be None)

static from_dict(d)

Load json dict to object

Parameters:

d (dict) – dict representing json export

to_dict()

Convert current object to json dict

Returns:

dict representing json export

Return type:

dict

class discopygal.solvers_infra.RobotRod(length, start, end, data=None)

Bases: Robot

A rod robot. Its geometry is defined by its length.

Parameters:
  • length (FT) – The length of the rod, as a CGAL field type

  • start ((Point_2, FT)) – The start location and angle of the robot, as a tuple of CGAL point and angle

  • end ((Point_2, FT)) – The end location and angle of the robot, as a tuple of CGAL point and angle

  • data (object) – Any metadata appended to the robot (could be None)

static from_dict(d)

Load json dict to object

Parameters:

d (dict) – dict representing json export

to_dict()

Convert current object to json dict

Returns:

dict representing json export

Return type:

dict

class discopygal.solvers_infra.Scene(obstacles: list[Obstacle] = None, robots: list[Robot] = None, metadata: dict = None)

Bases: object

The notion of “scene” in DiscoPygal, which is the setting where we conduct motion planning. A scene has robots that can move inside it, and obstacles. Also the scene can have any metadata, saved as a dictionary.

Parameters:
  • obstacles (list<Obstacle>) – list of obstacles

  • robots (list<Robot>) – list of robots

  • metadata (dict) – dict with metadata on the scene

JSON Serialization Format:

Scenes are serialized to JSON with the following structure:

{
    "__class__": "Scene",
    "obstacles": [
        {
            "__class__": "ObstacleDisc",
            "location": [x, y],
            "radius": float_value,
            "data": {
                "color": "HSV h,s,v",
                "name": "obstacle_name",
                ...
            }
        },
        {
            "__class__": "ObstaclePolygon",
            "poly": [[x1, y1], [x2, y2], ...],
            "data": {...}
        },
        ...
    ],
    "robots": [
        {
            "__class__": "RobotDisc",
            "radius": float_value,
            "start": [x, y],
            "end": [x, y],
            "data": {
                "color": "HSV h,s,v",
                "name": "robot_name",
                ...
            }
        },
        {
            "__class__": "RobotRod",
            "length": float_value,
            "start": [[x, y], angle],
            "end": [[x, y], angle],
            "data": {...}
        },
        {
            "__class__": "RobotPolygon",
            "poly": [[x1, y1], [x2, y2], ...],
            "start": [x, y],
            "end": [x, y],
            "data": {...}
        },
        ...
    ],
    "metadata": {
        "version": "version_string",
        "solvers": "SolverName1, SolverName2",
        "scene_details": "Scene description",
        ...
    }
}

Serialization Process:

  • Use to_dict() to convert a Scene object to a dictionary suitable for JSON export

  • Use from_dict() to reconstruct a Scene object from a dictionary (loaded from JSON)

  • Use from_file() to load a Scene directly from a JSON file

Key Points:

  • Each object (obstacle/robot) has a "__class__" field indicating its type

  • All coordinates are stored as [x, y] coordinate pairs (floats)

  • Rod robots store start/end as [[x, y], angle] tuples

  • The data field stores metadata like color, name, and custom user-defined values

  • Scene-level metadata is preserved in the metadata dictionary

add_obstacle(obstacle: Obstacle)

Add a obstacle to the scene

Parameters:

obstacle (Obstacle) – obstacle to add

add_robot(robot)

Add a robot to the scene

Parameters:

robot (Robot) – Robot to add

calc_max_robot_size() FT

Return the size of the largest robot in the scene For RobotDisc the is it’s diameter For RobotRod the size is it’s length

create_single_robot_scene(robot: Robot) Scene

Create from the current a scene a new scene containing only the given robot. This means it creates a scene with the original obstacles and only the given robot

Parameters:

robot (Robot) – The only robot to set in the scene

Returns:

The new created scene

Return type:

Scene

static from_dict(d: dict) Scene

Load json dict to object

Parameters:

d (dict) – dict representing json export

Returns:

A scene object build from the given dict

Return type:

Scene

static from_file(scene_path: str) Scene

Load scene from json file

Parameters:

scene_path (str) – Path to scene json file

Returns:

A scene object build from the given file

Return type:

Scene

remove_obstacle(obstacle: Obstacle)

Remove a obstacle from the scene

Parameters:

obstacle (Obstacle) – obstacle to remove

remove_robot(robot: Robot)

Remove a robot from the scene

Parameters:

robot (Robot) – Robot to remove

to_dict() dict

Convert current object to json dict

Returns:

dict representing json export

Return type:

dict

class discopygal.solvers_infra.SceneDrawer(gui, scene)

Bases: object

Object for lookup tables and drawing scene objects

Parameters:
clear_scene()

Clear (only) the DiscoPygal scene objects from the GUI

deselect_entity(entity)
draw_obstacle(obstacle, color_select=False)

Draw a single obstacle to the scene You can affect its color by having the data of the obstacle as a dict, and having “color” value (with a string confining to gui.gui.color).

Parameters:
  • obstacle (Obstacle) – obstacle to draw

  • color_select (bool) – if true override color to select color

draw_robot(robot, color_select=False)

Draw a single robot to the scene You can affect its color by having the data of the robot as a dict, and having “color” value (with a string confining to gui.gui.color).

Parameters:
  • obstacle (Robot) – robot to draw

  • color_select (bool) – if true override color to select color

draw_scene()

Draw the scene to the selected GUI

select_entity(entity)
discopygal.solvers_infra.load_object_from_dict(d)

Load a seriallized object from a dict In order for this to work, the dict should have a “__class__” property, which is equal to the exact python name of the class

Parameters:

d (dict) – dict describing an object

Returns:

the serialized object

Return type:

object