Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""Returns a copy of a polyline simplified by using the Douglas-Peucker
algorithm.
This works very well on smooth or gently curved shapes, but not well on
straight edged or angular shapes.
:param polyline: Polyline to simplify.
:type polyline: [(float,float)]
:param float tolerance: A higher value means more error is tolerated.
:rtype: [(float,float)]
"""
_line = lib.cpPolylineSimplifyCurves(_to_chipmunk(polyline), tolerance)
simplified = []
for i in range(_line.count):
simplified.append(Vec2d._fromcffi(_line.verts[i]))
return simplified
def cf(_shape, point, normal, alpha, data):
shape = self._get_shape(_shape)
p = SegmentQueryInfo(
shape, Vec2d._fromcffi(point), Vec2d._fromcffi(normal), alpha)
self.__query_hits.append(p)
def f4(count, verts, radius, outline_color, fill_color, data):
vs = []
for i in range(count):
vs.append(Vec2d._fromcffi(verts[i]))
self.draw_polygon(
vs, radius,
self._c(outline_color), self._c(fill_color))
_options.drawPolygon = f4
def _get_normal(self):
return Vec2d._fromcffi(cp.cpSegmentShapeGetNormal(self._shape))
normal = property(_get_normal,
def _get_anchor_b(self):
return Vec2d._fromcffi(cp.cpPinJointGetAnchorB(self._constraint))
def _set_anchor_b(self, anchor):
def f3(a, b, radius, outline_color, fill_color, data):
self.draw_fat_segment(
Vec2d._fromcffi(a), Vec2d._fromcffi(b), radius,
self._c(outline_color), self._c(fill_color))
_options.drawFatSegment = f3
def _get_anchor_b(self):
return Vec2d._fromcffi(cp.cpSlideJointGetAnchorB(self._constraint))
def _set_anchor_b(self, anchor):
def _get_anchor_a(self):
return Vec2d._fromcffi(cp.cpPivotJointGetAnchorA(self._constraint))
def _set_anchor_a(self, anchor):
def _get_offset (self):
return Vec2d._fromcffi(cp.cpCircleShapeGetOffset(self._shape))
offset = property(_get_offset, doc="""Offset. (body space coordinates)""")
def segment_query(self, start, end, radius=0):
"""Check if the line segment from start to end intersects the shape.
:rtype: :py:class:`SegmentQueryInfo`
"""
info = ffi.new("cpSegmentQueryInfo *")
r = cp.cpShapeSegmentQuery(
self._shape, tuple(start), tuple(end), radius, info)
if r:
ud = cp.cpShapeGetUserData(info.shape)
assert ud == self._get_shapeid()
return SegmentQueryInfo(
self, Vec2d._fromcffi(info.point), Vec2d._fromcffi(info.normal), info.alpha)
else:
return SegmentQueryInfo(
None, Vec2d._fromcffi(info.point), Vec2d._fromcffi(info.normal), info.alpha)