当前位置: 首页>>代码示例>>Python>>正文


Python Polygon.nPoints方法代码示例

本文整理汇总了Python中Polygon.Polygon.nPoints方法的典型用法代码示例。如果您正苦于以下问题:Python Polygon.nPoints方法的具体用法?Python Polygon.nPoints怎么用?Python Polygon.nPoints使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Polygon.Polygon的用法示例。


在下文中一共展示了Polygon.nPoints方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from Polygon import Polygon [as 别名]
# 或者: from Polygon.Polygon import nPoints [as 别名]

#.........这里部分代码省略.........
        """
        return bool(self.poly.covers(other.poly))

    def __repr__(self):
        kwarg_strs = []
        for arg, value in self._kwargs.items():
            if isinstance(value, str):
                value_str = "'{}'".format(value)
            elif isinstance(value, np.ndarray):
                value_str = "[{}, {}]".format(*value)
            else:
                value_str = str(value)
            kwarg_strs.append(arg + "=" + value_str)
        kwargs = ",\n" + ", ".join(kwarg_strs)

        return "{cls}({points}{kwargs})".format(
            cls=type(self).__name__,
            points="[{}]".format(",\n".join("[{}, {}]".format(x, y) for x, y in self.vertices)),
            kwargs=kwargs,
        )

    def __eq__(self, other):
        if isinstance(other, Shape):
            if len(self) != len(other):
                return False
            return (
                np.all(np.isclose(np.sort(self.vertices, axis=0), np.sort(other.vertices, axis=0)))
                and self.colors == other.colors
                and self.color == other.color
                and np.all(np.isclose(self.velocity, other.velocity))
            )
        else:
            return False

    def __bool__(self):
        return True

    def __getitem__(self, item):
        return self.vertices[item]

    def __len__(self):
        return self.poly.nPoints()

    def __add__(self, other):
        if isinstance(other, Shape):
            return type(self)(self.poly + other.poly)
        return type(self)(self.vertices + other, **self._kwargs)

    __radd__ = __add__

    def __sub__(self, other):
        if isinstance(other, Shape):
            return type(self)(self.poly - other.poly)
        return type(self)(self.vertices - other, **self._kwargs)

    def __mul__(self, other):
        return type(self)(self.vertices * other, **self._kwargs)

    def __rmul__(self, other):
        return type(self)(other * self.vertices, **self._kwargs)

    def __truediv__(self, other):
        return type(self)(self.vertices / other, **self._kwargs)

    __div__ = __truediv__

    def __xor__(self, other):
        return type(self)(self.poly ^ other.poly, **self._kwargs)

    def __and__(self, other):
        return type(self)(self.poly & other.poly, **self._kwargs)

    def __or__(self, other):
        return type(self)(self.poly | other.poly, **self._kwargs)

    def __iadd__(self, other):
        self.translate(other)
        return self

    def __isub__(self, other):
        self.translate(-np.asarray(other))
        return self

    def __imul__(self, other):
        if isinstance(other, int) or isinstance(other, float):
            self.poly.scale(other, other)
        elif len(other) == 2:
            self.poly.scale(*other)
        return self

    def __itruediv__(self, other):
        if isinstance(other, int) or isinstance(other, float):
            self.poly.scale(1 / other, 1 / other)
        elif len(other) == 2:
            self.poly.scale(1 / other[0], 1 / other[1])
        return self

    __idiv__ = __itruediv__

    position = center
开发者ID:hsharrison,项目名称:pyglet2d,代码行数:104,代码来源:pyglet2d.py


注:本文中的Polygon.Polygon.nPoints方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。