Skip to content

Polygon needs to be able to handle 'None' as an input #3

@MatthewLeeCode

Description

@MatthewLeeCode
def __init__(self, shell: np.ndarray, holes:list[np.ndarray]=[]):
        """ Creates a polygon.
        
        Args:
            shell (np.ndarray): The shell of the polygon. Expects a numpy array of shape (n, 2).
                If the shape is (n, 1, 2), it will be reshaped to (n, 2). This is useful for cv2.findContours.
            holes (list[np.ndarray]): The holes in the polygon.
        """
        # Reshape the shell if needed
        if len(shell.shape) == 3:
            shell = shell.reshape(shell.shape[0], 2)
        
        # Reshape the holes if needed
        if len(holes) > 0:
            for i, hole in enumerate(holes):
                if len(hole.shape) == 3:
                    holes[i] = hole.reshape(hole.shape[0], 2)
        
        self.shell = shell
        self.holes = holes
        self._calculate_key_points()

If 'None' is entered for 'holes' it raises a TypeError

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions