pymunk.autogeometry
Module¶
-
class
pymunk.autogeometry.
PolylineSet
[source]¶ Bases:
collections.abc.Sequence
A set of Polylines.
Mainly intended to be used for its collect_segment() function when generating geometry with the march_soft() and march_hard() functions.
-
collect_segment
(v0, v1)[source]¶ Add a line segment to a polyline set.
A segment will either start a new polyline, join two others, or add to or loop an existing polyline. This is mostly intended to be used as a callback directly from march_soft() or march_hard().
-
count
(value) → integer -- return number of occurrences of value¶
-
index
(value) → integer -- return first index of value.¶ Raises ValueError if the value is not present.
-
-
pymunk.autogeometry.
convex_decomposition
(polyline, tolerance)[source]¶ Get an approximate convex decomposition from a polyline.
Returns a list of convex hulls that match the original shape to within tolerance.
NOTE: If the input is a self intersecting polygon, the output might end up overly simplified.
Parameters: - polyline : [(x,y)] or [Vec2d]
The polyline to get the convex hulls for.
- tolerance : float
A higher value means more error is tolerated.
-
pymunk.autogeometry.
is_closed
(polyline)[source]¶ Returns true if the first vertex is equal to the last.
Parameters: - polyline : [(x,y)] or [Vec2d]
Polyline to simplify.
-
pymunk.autogeometry.
march_hard
(bb, x_samples, y_samples, threshold, segment_func, sample_func)[source]¶ Trace an aliased curve of an image along a particular threshold.
The given number of samples will be taken and spread across the bounding box area using the sampling function and context.
Parameters: - bb : BB
bounding box of the area to sample within.
- x_samples : int
Number of samples in x
- y_samples : int
Number of samples in y
- threshold : float
A higher value means more error is tolerated
- segment_func :
The segment function will be called for each segment detected that lies along the density contour for threshold. v0 and v1 are Vec2d.
- sample_func :
The sample function will be called for x_samples * y_samples spread across the bounding box area, and should return a float. point is a Vec2d.
func(v0, v1)
func(point) -> float
-
pymunk.autogeometry.
march_soft
(bb, x_samples, y_samples, threshold, segment_func, sample_func)[source]¶ Trace an anti-aliased contour of an image along a particular threshold.
The given number of samples will be taken and spread across the bounding box area using the sampling function and context.
Parameters: - bb : BB
bounding box of the area to sample within.
- x_samples : int
Number of samples in x
- y_samples : int
Number of samples in y
- threshold : float
A higher value means more error is tolerated
- segment_func :
The segment function will be called for each segment detected that lies along the density contour for threshold. v0 and v1 are Vec2d.
- sample_func :
The sample function will be called for x_samples * y_samples spread across the bounding box area, and should return a float. point is a Vec2d.
func(v0, v1)
func(point) -> float
-
pymunk.autogeometry.
simplify_curves
(polyline, tolerance)[source]¶ 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.
Parameters: - polyline : [(x,y)] or [Vec2d]
Polyline to simplify.
- tolerance : float
A higher value means more error is tolerated.
-
pymunk.autogeometry.
simplify_vertexes
(polyline, tolerance)[source]¶ Returns a copy of a polyline simplified by discarding “flat” vertexes.
This works well on straigt edged or angular shapes, not as well on smooth shapes.
Parameters: - polyline : [(x,y)] or [Vec2d]
Polyline to simplify.
- tolerance : float
A higher value means more error is tolerated.