# -*- coding: utf-8 -*-
from collections import namedtuple

Size = namedtuple("Size", ["width", "height"])
Box = namedtuple("Box", ["point", "size"])

class Point(namedtuple("Point", ["x", "y"])):
    """Point in a two-dimensional space.

    Named tuple implementation that allows for addition and subtraction.
    """
    __slots__ = ()

    def __add__(self, other):
        """Overrides the default ``+`` implementation to sum each element
        in the point.

        Because this is based on :py:obj:`tuple`, the default implementation
        would create a 4-tuple with the elements from both points.
        """
        x = self.x + other.x
        y = self.y + other.y
        return Point(x, y)

    def __sub__(self, other):
        """Implement a subtract function so that each element is subtracted
        from the corresponding element in ``other``.
        """
        x = self.x - other.x
        y = self.y - other.y
        return Point(x, y)

class Rectangle(namedtuple("Rectangle", ["x0", "y0", "x1", "y1"])):
    def __contains__(self, other):
        """Check if this rectangle and ``other`` overlaps eachother.

        Essentially this is a bit of a hack to be able to write
        ``rect1 in rect2``.

        :param other: Other rectangle to check if overlaps.
        :return: ``True`` if this rectangle and ``other`` overlaps eachother.
        """
        if self.x0 < other.x1 and self.x1 > other.x0 and \
                self.y0 < other.y1 and self.y1 > other.y0:
            return True
        return False

    @classmethod
    def from_sizes(cls, size, position):
        """Create a rectangle with a given size and position.

        :param size: The :py:class:`~skald.geometry.Size` of the rectangle.
        :param position: The :py:class:`~skald.geometry.Point` representing
            the position of the rectangle.
        """
        return cls(
            x0=point.x,
            y0=point.y,
            x1=point.x+size.width,
            y1=point.y+size.height
        )

    @property
    def center(self):
        """The :py:class:`~skald.geometry.Point` at the center of the
        rectangle.
        """
        return Point(x=(self.x0+self.x1)/2, y=(self.y0+self.y1)/2)

    @property
    def size(self):
        """The :py:class:`~skald.geometry.Size` of the rectangle."""
        return Size(width=self.x1-self.x0, height=self.y1-self.y0)

    @property
    def position(self):
        """The :py:class:`~skald.geometry.Point` for the top left position
        of the rectangle.
        """
        return Point(x=self.x0, y=self.y0)

    @property
    def box(self):
        """The :py:class:`~skald.geometry.Box` representation of itself."""
        return Box(
            point=self.position,
            size=self.size
        )

@@ -2016,16 +2016,1311 @@
      )%0A%0A
+    def __sub__(self, other):%0A        %22%22%22Move the rectangle by subtracting from it's position.%0A%0A        :param other: A two element :py:obj:%60list%60 or :py:obj:%60tuple%60, e.g.%0A            :py:class:%60~skald.geometry.Point%60.%0A        %22%22%22%0A        if not isinstance(other, (list, tuple)) and len(other) == 2:%0A            raise TypeError(%0A                    %22Unsupported operand type(s) for -: '%25s' and '%25s'%22 %25 %5C%0A                    (type(self).__name__, type(other).__name__)%0A            )%0A        return Rectangle(%0A            x0=self.x0-other%5B0%5D,%0A            y0=self.y0-other%5B1%5D,%0A            x1=self.x1-other%5B0%5D,%0A            y1=self.y1-other%5B1%5D,%0A        )%0A%0A    def __add__(self, other):%0A        %22%22%22Move the rectangle by adding to it's position.%0A%0A        :param other: A two element :py:obj:%60list%60 or :py:obj:%60tuple%60, e.g.%0A            :py:class:%60~skald.geometry.Point%60.%0A        %22%22%22%0A        if not isinstance(other, (list, tuple)) and len(other) == 2:%0A            raise TypeError(%0A                    %22Unsupported operand type(s) for +: '%25s' and '%25s'%22 %25 %5C%0A                    (type(self).__name__, type(other).__name__)%0A            )%0A        return Rectangle(%0A            x0=self.x0+other%5B0%5D,%0A            y0=self.y0+other%5B1%5D,%0A            x1=self.x1+other%5B0%5D,%0A            y1=self.y1+other%5B1%5D,%0A        )%0A%0A
     @pro

Support moving recangles through add and sub