imforge.utils module

imforge.utils.clip_polygon(polygon, width, height)

Clip given polygon with rectangle of given width and height.

Parameters
  • polygon (list[tuple[int,int]]) – the list of points coordinates of the polygon to clip

  • width (int) – width of the clipping rectangle

  • height (int) – height of the clipping rectangle

Returns

the clipped polygon

Return type

list[tuple[int,int]]

imforge.utils.is_clockwise(polygon, check_convexity=False)

Return whether or not given polygon is clockwise oriented or not.

If check_convexity is False (the default), it’s assumed that given polygon is convex, so we only check for orientation based on the first vertex. If check_convexity is True, then we check orientation for all vertices and they must all have the same orientation (i.e. the polygon is convex)

Parameters
  • polygon (list[tuple[int,int]]) – the list of polygon vertices which for we want orientation

  • check_convexity (bool) – specify whether or not we have to check convexity of polygon. If False (the default) we compute orientation based on the first vertex.

Returns

True if polygon is clockwise oriented. False if it is counterclockwise oriented.

Return type

bool

Raises

ValueError

  • if polygon does not contain at least 3 distinct vertices

  • if check_convexity is True, and the polygon is not convex

  • if 3 consecutive vertices of polygon are aligned