mappymatch.matchers.lcss.utils#
Functions
|
Compress adjacent cutting points by keeping only the middle point of each group. |
|
Merge items in a list by combining matching items with the next eligible element (left-to-right). |
|
Merge items in a list using both forward and reverse merging to handle edge cases. |
|
Merge items in a list by combining matching items with the previous eligible element (right-to-left). |
- mappymatch.matchers.lcss.utils.forward_merge(merge_list: List, condition: Callable[[Any], bool]) List[source]#
Merge items in a list by combining matching items with the next eligible element (left-to-right).
This function scans through the list from left to right. When it encounters items that satisfy the condition, it combines them with the next item that doesn't satisfy the condition. This is useful for merging small trajectory segments with their neighbors.
- Args:
merge_list: The list of items to merge. Items should support addition (+) for combining. condition: A function that returns True for items that should be merged forward. Items satisfying this condition will be combined with the next non-matching item.
- Returns:
A new list with matching items merged into subsequent items
- mappymatch.matchers.lcss.utils.reverse_merge(merge_list: List, condition: Callable[[Any], bool]) List[source]#
Merge items in a list by combining matching items with the previous eligible element (right-to-left).
This function scans through the list from right to left. When it encounters items that satisfy the condition, it combines them with the previous item that doesn't satisfy the condition. This is the reverse of forward_merge.
- Args:
merge_list: The list of items to merge. Items should support addition (+) for combining. condition: A function that returns True for items that should be merged backward. Items satisfying this condition will be combined with the previous non-matching item.
- Returns:
A new list with matching items merged into preceding items
- mappymatch.matchers.lcss.utils.merge(merge_list: List, condition: Callable[[Any], bool]) List[source]#
Merge items in a list using both forward and reverse merging to handle edge cases.
This function first performs a forward merge, then checks if any items still satisfy the condition. If so, it performs a reverse merge to handle items at the end of the list that couldn't be merged forward.
This two-pass approach ensures that items at both ends of the list can be successfully merged with their neighbors.
- Args:
merge_list: The list of items to merge. Items should support addition (+) for combining. condition: A function that returns True for items that should be merged with neighbors.
- Returns:
A new list with all matching items merged into neighbors
- mappymatch.matchers.lcss.utils.compress(cutting_points: List) Generator[source]#
Compress adjacent cutting points by keeping only the middle point of each group.
When multiple cutting points are directly adjacent (differ by 1 index), this function collapses them into a single representative cutting point. For each group, the middle point is selected as the representative.
This prevents the LCSS algorithm from creating too many tiny segments when several adjacent points all have poor matches.
- Args:
cutting_points: A list of CuttingPoint objects to compress
- Yields:
CuttingPoint objects: One representative cutting point for each group of adjacent cutting points. The middle point of each group is selected.