Exemplo n.º 1
0
    def __eq__(self, other):
        """
        Two sizes are equal if their widths and heights are equal.

        :param other: `Size`
        :return: are the sizes equal?
        """
        if self is other:
            return True

        if not isinstance(other, Size):
            return False

        return are_close_enough(self.width, other.width) \
               and are_close_enough(self.height, other.height)
Exemplo n.º 2
0
    def __eq__(self, other):
        """
        Two `Vector` instances are equal if their projections are
        equal.

        :param other: `Vector`
        :return: are the vectors equal?
        """
        if self is other:
            return True

        if not isinstance(other, Vector):
            return False

        return nums.are_close_enough(self.u, other.u) and \
               nums.are_close_enough(self.v, other.v)
Exemplo n.º 3
0
    def __eq__(self, other):
        """
        Two points are equal if their coordinates are equal (or
        close enough).

        :param other: `Point`
        :return: are the points equal?
        """
        if self is other:
            return True

        if not isinstance(other, Point):
            return False

        return nums.are_close_enough(self.x, other.x) and \
               nums.are_close_enough(self.y, other.y)
Exemplo n.º 4
0
    def __eq__(self, other):
        """
        Two circles are equal if their center points and radii are
        equal.

        :param other: `Circle`
        :return: are the circles equal?
        """
        if self is other:
            return True

        if not isinstance(other, Circle):
            return False

        return self.center == other.center \
               and are_close_enough(self.radius, other.radius)
Exemplo n.º 5
0
    def contains_point(self, point):
        """
        Tests whether the polygon contains the given point.

        :param point: `Point`
        :return: `bool` contains point?
        """
        if point in self.vertices:
            return True

        vecs = [make_vector_between(point, vertex) for vertex in self.vertices]
        paired_vecs = make_round_pairs(vecs)
        angle_sum = reduce(operator.add,
                           [v1.angle_to(v2) for v1, v2 in paired_vecs])

        return are_close_enough(angle_sum, 2 * math.pi)
Exemplo n.º 6
0
    def __eq__(self, other):
        """
        Two affine transformations are equal if all its values are
        equal: sx, sy, shx, shy, tx and ty.

        :param other: `AffineTransform`
        :return: are the affine transformations equal?
        """
        if self is other:
            return True

        if not isinstance(other, AffineTransform):
            return False

        return are_close_enough(self.sx, other.sx) \
               and are_close_enough(self.sy, other.sy) \
               and are_close_enough(self.tx, other.tx) \
               and are_close_enough(self.ty, other.ty) \
               and are_close_enough(self.shx, other.shx) \
               and are_close_enough(self.shy, other.shy)