# Path: twyg/geom.py
# class Rectangle(object):
#     def __init__(self, x, y, w, h):
#         self.x = x
#         self.y = y
#         self.w = w
#         self.h = h
# 
#     def __repr__(self):
#         return '(x=%s, y=%s, w=%s, h=%s)' % (self.x, self.y, self.w, self.h)
# 
#     def params(self):
#         return self.x, self.y, self.w, self.h
# 
#     def points(self):
#         return [Point2D(self.x,          self.y),
#                 Point2D(self.x + self.w, self.y),
#                 Point2D(self.x + self.w, self.y + self.h),
#                 Point2D(self.x,          self.y + self.h)]
# 
#     def expand(self, rect):
#         r1x1 = self.x
#         r1y1 = self.y
#         r1x2 = r1x1 + self.w
#         r1y2 = r1y1 + self.h
# 
#         r2x1 = rect.x
#         r2y1 = rect.y
#         r2x2 = r2x1 + rect.w
#         r2y2 = r2y1 + rect.h
# 
#         x1 = min(r1x1, r2x1)
#         y1 = min(r1y1, r2y1)
#         x2 = max(r1x2, r2x2)
#         y2 = max(r1y2, r2y2)
# 
#         self.x = x1
#         self.y = y1
#         self.w = x2 - x1
#         self.h = y2 - y1


from twyg.hyphenator import hyphenate_word
from twyg.geom import Rectangle


_hyphenate_word_cache = {}


def _calc_inside_rects(points):
    """
    Calculate a list of horizontal rectangles fitting into a convex
    shape.

    ``points``
        A list of intersection point-pairs of a set of equidistant
        horizontal lines intersecting the segments defining shape
        (should be calculated by ``slice_shape``).

    Rectangles are returned as a list of ``[x, y, width, height]``
    arrays.
    """
    rects = []
    for i in range(len(points) - 1):
        p11, p12 = points[i]
        p21, p22 = points[i + 1]

        x = max(p11.x, p21.x)
        y = p11.y
        w = min(p12.x, p22.x) - x
        h = p21.y - p11.y


# Path: twyg/geom.py
# class Rectangle(object):
#     def __init__(self, x, y, w, h):
#         self.x = x
#         self.y = y
#         self.w = w
#         self.h = h
# 
#     def __repr__(self):
#         return '(x=%s, y=%s, w=%s, h=%s)' % (self.x, self.y, self.w, self.h)
# 
#     def params(self):
#         return self.x, self.y, self.w, self.h
# 
#     def points(self):
#         return [Point2D(self.x,          self.y),
#                 Point2D(self.x + self.w, self.y),
#                 Point2D(self.x + self.w, self.y + self.h),
#                 Point2D(self.x,          self.y + self.h)]
# 
#     def expand(self, rect):
#         r1x1 = self.x
#         r1y1 = self.y
#         r1x2 = r1x1 + self.w
#         r1y2 = r1y1 + self.h
# 
#         r2x1 = rect.x
#         r2y1 = rect.y
#         r2x2 = r2x1 + rect.w
#         r2y2 = r2y1 + rect.h
# 
#         x1 = min(r1x1, r2x1)
#         y1 = min(r1y1, r2y1)
#         x2 = max(r1x2, r2x2)
#         y2 = max(r1y2, r2y2)
# 
#         self.x = x1
#         self.y = y1
#         self.w = x2 - x1
#         self.h = y2 - y1


# Path: twyg/textwrap.py
from twyg.hyphenator import hyphenate_word
from twyg.geom import Rectangle



_hyphenate_word_cache = {}


def _calc_inside_rects(points):
    """
    Calculate a list of horizontal rectangles fitting into a convex
    shape.

    ``points``
        A list of intersection point-pairs of a set of equidistant
        horizontal lines intersecting the segments defining shape
        (should be calculated by ``slice_shape``).

    Rectangles are returned as a list of ``[x, y, width, height]``
    arrays.
    """
    rects = []
    for i in range(len(points) - 1):
        p11, p12 = points[i]
        p21, p22 = points[i + 1]

        x = max(p11.x, p21.x)
        y = p11.y
        w = min(p12.x, p22.x) - x
        h = p21.y - p11.y


        rects.append(Rectangle(x, y, w, h))