rect2.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:pygorithm 作者: OmkarPathak 项目源码 文件源码
def contains_point(rect, point):
        """
        Determine if the rect contains the point

        Distinguish between points that are on the edge of the
        rect and those that are not.

        .. tip::

            This will never return ``True, True``

        :param rect: the rect
        :type rect: :class:`pygorithm.geometry.rect2.Rect2`
        :param point: the point
        :type point: :class:`pygorithm.geometry.vector2.Vector2`
        :returns: point on edge, point inside
        :rtype: bool, bool
        """

        edge_x = math.isclose(rect.mincorner.x, point.x, abs_tol=1e-07) or math.isclose(rect.mincorner.x + rect.width, point.x, abs_tol=1e-07)
        edge_y = math.isclose(rect.mincorner.y, point.y, abs_tol=1e-07) or math.isclose(rect.mincorner.y + rect.height, point.y, abs_tol=1e-07)
        if edge_x and edge_y:
            return True, False

        contains = (edge_x or (point.x > rect.mincorner.x and point.x < rect.mincorner.x + rect.width)) and \
                   (edge_y or (point.y > rect.mincorner.y and point.y < rect.mincorner.y + rect.height))
        if not contains:
            return False, False
        elif edge_x or edge_y:
            return True, False
        else:
            return False, True
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号