simplify_breakpoints¶
- emlib.misc.simplify_breakpoints(bps, coordsfunc, tolerance=0.01)[source]¶
Simplify breakpoints in a breakpoint function
Assuming a list of some objects building a multisegmented line in 2D, simplify this line by eliminating superfluous breakpoints which don’t contribute (enough) to the resolution of this line
- Parameters:
bps (
list
[TypeVar
(T
)]) – a list of breakpointscoordsfunc (
Callable
) – a function of the form (breakpoint) -> (x, y)tolerance (
Union
[float
,Rational
]) – if the difference between two consecutive slopes is below this threshold we assume that the two lines are colinear and we don’t need the middle point
- Return type:
list
[TypeVar
(T
)]- Returns:
the list of simplified breakpoints. The first and last breakpoints of the original will always be part of the result
Example:
>>> @dataclasses.dataclass ... class Point: ... name: str ... x: float ... y: float >>> points = [Point("A", 0, 0), ... Point("B", 2, 0), ... Point("C", 3, 0), ... Point("D", 4, 1), ... Point("E", 5, 2)] >>> simplify_breakpoints(points, coordsfunc=(lambda p: p.x, p.y)) [Point(name="A", x=0, y=0), Point(name="C", x=3, y=0), Point(name="E", x=5, y=2)]