cooptools 1.80__tar.gz → 1.81__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {cooptools-1.80 → cooptools-1.81}/PKG-INFO +1 -1
- {cooptools-1.80 → cooptools-1.81}/cooptools/geometry_utils/polygon_utils.py +38 -1
- {cooptools-1.80 → cooptools-1.81}/cooptools/pathing/straightLineFollower.py +11 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/pathing/waypointFollower.py +24 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools.egg-info/PKG-INFO +1 -1
- {cooptools-1.80 → cooptools-1.81}/cooptools.egg-info/SOURCES.txt +1 -0
- {cooptools-1.80 → cooptools-1.81}/setup.py +1 -1
- cooptools-1.81/tests/test_polygon_utils.py +62 -0
- {cooptools-1.80 → cooptools-1.81}/tests/test_straightLineFollower.py +13 -0
- {cooptools-1.80 → cooptools-1.81}/tests/test_waypointFollower.py +78 -0
- {cooptools-1.80 → cooptools-1.81}/MANIFEST.in +0 -0
- {cooptools-1.80 → cooptools-1.81}/README.md +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/__init__.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/anchor.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/asyncable.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/cli/CliAtomicUserInteraction.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/cli/CliMenu.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/cli/__init__.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/cli/fileContentReturn.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/cnxn_info.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/colors.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/commandDesignPattern/__init__.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/commandDesignPattern/commandController.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/commandDesignPattern/commandProtocol.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/commandDesignPattern/exceptions.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/common.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/config.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/coopDataclass.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/coopEnum.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/coopthreading.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/currency.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/dataRefresher/__init__.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/dataRefresher/dataHub.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/dataRefresher/dataRefresher.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/dataStore/__init__.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/dataStore/dataProcessor.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/dataStore/dataStoreProtocol.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/dataStore/dbConnectionURI.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/dataStore/inMemoryDataStore.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/date_utils.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/decay.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/decor.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/dictPolicies.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/exceptions.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/expertise/__init__.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/expertise/expertiseArgs.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/expertise/expertiseSchedules.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/expertise/expertise_state.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/finance/__init__.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/finance/dicounted_cashflow_analysis.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/finance/fund_projection.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/finance/fund_projection_renderer.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/finance/futureValueProjector.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/finance/growth_projections.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/finance/reports.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/finance/utils.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/geometry_utils/__init__.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/geometry_utils/circle_utils.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/geometry_utils/common.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/geometry_utils/curve_utils.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/geometry_utils/curves.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/geometry_utils/line_utils.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/geometry_utils/rect_utils.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/geometry_utils/triangle_utils.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/geometry_utils/vector_utils.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/graphs/__init__.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/graphs/astar_results_viewer.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/graphs/draw.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/graphs/flow_field.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/graphs/graph.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/graphs/graph_dcs.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/graphs/graph_definitions.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/graphs/utils.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/ideas/__init__.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/ideas/actionItemTracker/__init__.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/ideas/actionItemTracker/ai_tracker.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/ideas/actionItemTracker/dcs.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/ideas/discreteEventSimulator/__init__.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/ideas/discreteEventSimulator/discreteEventSimulator.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/ideas/jsonIO.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/ideas/metrics.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/ideas/triggerActionSystem/__init__.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/ideas/triggerActionSystem/signal.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/ideas/triggerActionSystem/trigger.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/loggingHelpers.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/marchingSquares.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/materialHandling/__init__.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/materialHandling/cli.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/materialHandling/dcs.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/materialHandling/selectionCriteria.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/matrixManipulation.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/os_manip.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/pandasHelpers.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/pathing/__init__.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/pathing/catmullRomFollower.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/pathing/demo/__init__.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/pathing/demo/server.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/pathing/kinematicGoalSeeker.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/pathing/motion_profile_utils.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/pathing/orbit_fuzzer.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/pathing/path_utils.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/pathing/trajectory_provider.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/pathing/waypoint.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/persistence/__init__.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/persistence/enum_state.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/persistence/stateful.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/physics/__init__.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/physics/kinematic.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/physics/kinematic_utils.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/physics/movement.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/physics/trajectory.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/plotting.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/printing.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/protocols.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/qualifiers/__init__.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/qualifiers/cli.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/qualifiers/qualifier.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/randoms.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/register.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/reservation/__init__.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/reservation/dcs.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/reservation/enums.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/reservation/reservationmanager.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/retry.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/sectors/__init__.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/sectors/grids/__init__.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/sectors/grids/gridState.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/sectors/grids/grid_base.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/sectors/grids/hexGrid.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/sectors/grids/rectGrid.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/sectors/hex_utils.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/sectors/sect_utils.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/sectors/sectorTree/__init__.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/sectors/sectorTree/sectorTree.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/statistics/__init__.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/statistics/activityReport.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/statistics/controlChart/__init__.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/statistics/controlChart/controlChart.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/statistics/controlChart/plotting.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/statistics/oee/__init__.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/statistics/oee/oeeHub.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/taskProcessing/__init__.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/taskProcessing/dcs.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/taskProcessing/taskProcessor.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/timeTracker/__init__.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/timeTracker/decay.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/timeTracker/timeTracker.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/timeWindow.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/toggles.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/transform.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/trends.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/typeProviders.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/typevalidation.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools/version.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools.egg-info/dependency_links.txt +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools.egg-info/not-zip-safe +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools.egg-info/requires.txt +0 -0
- {cooptools-1.80 → cooptools-1.81}/cooptools.egg-info/top_level.txt +0 -0
- {cooptools-1.80 → cooptools-1.81}/requirements.txt +0 -0
- {cooptools-1.80 → cooptools-1.81}/setup.cfg +0 -0
- {cooptools-1.80 → cooptools-1.81}/tests/test_CliAtomicUserInteraction.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/tests/test_asyncable.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/tests/test_catmullRomFollower.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/tests/test_cdp_bugs.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/tests/test_commandDesignPattern.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/tests/test_common.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/tests/test_config.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/tests/test_coopEnum.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/tests/test_currency.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/tests/test_curves.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/tests/test_date_utils.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/tests/test_expertise_state.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/tests/test_flow_field.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/tests/test_flow_field_perf.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/tests/test_fund_projection.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/tests/test_graph_node_classification.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/tests/test_kinematicGoalSeeker.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/tests/test_kinematic_utils.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/tests/test_os_manip.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/tests/test_pandas.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/tests/test_path_utils.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/tests/test_persistence.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/tests/test_printing.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/tests/test_qualifiers.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/tests/test_sectors.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/tests/test_sectors_hex.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/tests/test_sectors_sectorTree.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/tests/test_statistics.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/tests/test_target_seek.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/tests/test_tasks.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/tests/test_toggles.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/tests/test_trajectory.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/tests/test_trends.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/tests/test_typevalidation.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/tests/test_vector_utils.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/tests/test_version.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/tests/tests_graph.py +0 -0
- {cooptools-1.80 → cooptools-1.81}/tests/tests_gridsystem.py +0 -0
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import math
|
|
2
|
+
from typing import Optional, Tuple
|
|
1
3
|
from cooptools.geometry_utils import vector_utils as vec
|
|
2
4
|
from cooptools.geometry_utils import line_utils as lin
|
|
5
|
+
|
|
3
6
|
def sides_in_poly(poly: vec.IterVec):
|
|
4
7
|
for i1 in range(len(poly)):
|
|
5
8
|
if i1 == len(poly) - 1:
|
|
@@ -43,7 +46,7 @@ def point_in_poly(point: vec.FloatVec, poly: vec.IterVec) -> bool:
|
|
|
43
46
|
def do_convex_polygons_intersect(poly_a: vec.IterVec, poly_b: vec.IterVec):
|
|
44
47
|
#https: // stackoverflow.com / questions / 10962379 / how - to - check - intersection - between - 2 - rotated - rectangles
|
|
45
48
|
for polygon in [poly_a, poly_b]:
|
|
46
|
-
for i1 in range(len(
|
|
49
|
+
for i1 in range(len(polygon)):
|
|
47
50
|
i2 = (i1 + 1) % len(polygon)
|
|
48
51
|
p1 = polygon[i1]
|
|
49
52
|
p2 = polygon[i2]
|
|
@@ -75,6 +78,40 @@ def do_convex_polygons_intersect(poly_a: vec.IterVec, poly_b: vec.IterVec):
|
|
|
75
78
|
return True
|
|
76
79
|
|
|
77
80
|
|
|
81
|
+
def _project(poly: vec.IterVec, axis: vec.FloatVec) -> Tuple[float, float]:
|
|
82
|
+
projections = [p[0] * axis[0] + p[1] * axis[1] for p in poly]
|
|
83
|
+
return min(projections), max(projections)
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def minimum_translation_vector(poly_a: vec.IterVec, poly_b: vec.IterVec) -> Optional[vec.FloatVec]:
|
|
87
|
+
"""The shortest move that takes convex `poly_a` clear of convex `poly_b`, or None
|
|
88
|
+
when they do not overlap (polygons that only touch do not overlap).
|
|
89
|
+
|
|
90
|
+
A separating-axis test over both polygons' unit edge normals: on each axis the
|
|
91
|
+
escape is the smaller of pushing `poly_a` past either end of `poly_b`, and the
|
|
92
|
+
axis with the smallest escape gives the vector."""
|
|
93
|
+
best: Optional[Tuple[float, vec.FloatVec]] = None
|
|
94
|
+
for polygon in (poly_a, poly_b):
|
|
95
|
+
for p1, p2 in sides_in_poly(polygon):
|
|
96
|
+
length = math.hypot(p2[0] - p1[0], p2[1] - p1[1])
|
|
97
|
+
if length == 0:
|
|
98
|
+
continue
|
|
99
|
+
axis = ((p2[1] - p1[1]) / length, (p1[0] - p2[0]) / length)
|
|
100
|
+
min_a, max_a = _project(poly_a, axis)
|
|
101
|
+
min_b, max_b = _project(poly_b, axis)
|
|
102
|
+
forward = max_b - min_a # moving a along +axis until its min clears b's max
|
|
103
|
+
backward = max_a - min_b # moving a along -axis until its max clears b's min
|
|
104
|
+
if forward <= 0 or backward <= 0:
|
|
105
|
+
return None
|
|
106
|
+
if forward <= backward:
|
|
107
|
+
candidate = (forward, (axis[0] * forward, axis[1] * forward))
|
|
108
|
+
else:
|
|
109
|
+
candidate = (backward, (-axis[0] * backward, -axis[1] * backward))
|
|
110
|
+
if best is None or candidate[0] < best[0]:
|
|
111
|
+
best = candidate
|
|
112
|
+
return best[1] if best is not None else None
|
|
113
|
+
|
|
114
|
+
|
|
78
115
|
if __name__ == "__main__":
|
|
79
116
|
def test01():
|
|
80
117
|
ret = do_convex_polygons_intersect(
|
|
@@ -125,6 +125,17 @@ class StraightLineFollower:
|
|
|
125
125
|
self._max_acceleration = max_acceleration
|
|
126
126
|
self._v_max = velocity_magnitude_bounds[1] if velocity_magnitude_bounds is not None else None
|
|
127
127
|
|
|
128
|
+
@property
|
|
129
|
+
def MaxSpeed(self) -> Optional[float]:
|
|
130
|
+
"""The speed cap every plan obeys; None for no cap."""
|
|
131
|
+
return self._v_max
|
|
132
|
+
|
|
133
|
+
@MaxSpeed.setter
|
|
134
|
+
def MaxSpeed(self, value: Optional[float]):
|
|
135
|
+
"""Takes effect from the next plan: a follower already moving keeps its current
|
|
136
|
+
trajectory until it replans (`WaypointFollower.replan()` forces one)."""
|
|
137
|
+
self._v_max = value
|
|
138
|
+
|
|
128
139
|
def plan(self,
|
|
129
140
|
start_pos: vec.FloatVec,
|
|
130
141
|
start_velocity: vec.FloatVec,
|
|
@@ -105,6 +105,30 @@ class WaypointFollower:
|
|
|
105
105
|
self._pending_override_velocity = velocity
|
|
106
106
|
self._needs_replan = True
|
|
107
107
|
|
|
108
|
+
def replan(self) -> None:
|
|
109
|
+
"""Plans afresh from the current position and velocity on the next update(),
|
|
110
|
+
for when the trajectory provider's limits have changed (a lower speed cap)."""
|
|
111
|
+
self._needs_replan = True
|
|
112
|
+
|
|
113
|
+
def nudge(self, offset: vec.FloatVec, absorb_velocity: bool = True) -> None:
|
|
114
|
+
"""Shifts the position by `offset` immediately, as an outside push (a collision)
|
|
115
|
+
would, and replans from there on the next update(). Works whether or not any
|
|
116
|
+
waypoints are queued.
|
|
117
|
+
|
|
118
|
+
With `absorb_velocity`, the part of the velocity heading against the push is
|
|
119
|
+
dropped, so a follower pressed into an obstacle stops at it rather than keeping
|
|
120
|
+
full speed it cannot use; motion along or away from the push is kept."""
|
|
121
|
+
self._pos = tuple(p + o for p, o in zip(self._pos, offset))
|
|
122
|
+
if self._pending_override_pos is not None:
|
|
123
|
+
self._pending_override_pos = tuple(p + o for p, o in zip(self._pending_override_pos, offset))
|
|
124
|
+
if absorb_velocity:
|
|
125
|
+
direction = vec.unit_vector(offset)
|
|
126
|
+
if direction is not None:
|
|
127
|
+
into = vec.dot(self._velocity_vec, direction)
|
|
128
|
+
if into < 0:
|
|
129
|
+
self._velocity_vec = tuple(v - into * d for v, d in zip(self._velocity_vec, direction))
|
|
130
|
+
self._needs_replan = True
|
|
131
|
+
|
|
108
132
|
def stop(self):
|
|
109
133
|
dim = len(self._pos)
|
|
110
134
|
self._velocity_vec = vec.zero_vector(dim)
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import math
|
|
2
|
+
import unittest
|
|
3
|
+
|
|
4
|
+
from cooptools.geometry_utils import polygon_utils as poly
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def _rect(cx, cy, w, h, rot=0.0):
|
|
8
|
+
c, s = math.cos(rot), math.sin(rot)
|
|
9
|
+
corners = [(-w / 2, -h / 2), (w / 2, -h / 2), (w / 2, h / 2), (-w / 2, h / 2)]
|
|
10
|
+
return [(cx + x * c - y * s, cy + x * s + y * c) for x, y in corners]
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class Test_DoConvexPolygonsIntersect(unittest.TestCase):
|
|
14
|
+
|
|
15
|
+
def test__polygons_with_different_vertex_counts__tests_every_edge(self):
|
|
16
|
+
square = [(0, 0), (10, 0), (10, 10), (0, 10)]
|
|
17
|
+
triangle = [(20, 0), (30, 0), (25, 10)]
|
|
18
|
+
|
|
19
|
+
self.assertFalse(poly.do_convex_polygons_intersect(triangle, square))
|
|
20
|
+
self.assertFalse(poly.do_convex_polygons_intersect(square, triangle))
|
|
21
|
+
self.assertTrue(poly.do_convex_polygons_intersect(square, [(5, 5), (15, 5), (10, 15)]))
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class Test_MinimumTranslationVector(unittest.TestCase):
|
|
25
|
+
|
|
26
|
+
def test__apart__is_none(self):
|
|
27
|
+
self.assertIsNone(poly.minimum_translation_vector(_rect(0, 0, 10, 10), _rect(20, 0, 10, 10)))
|
|
28
|
+
|
|
29
|
+
def test__touching__is_none(self):
|
|
30
|
+
self.assertIsNone(poly.minimum_translation_vector(_rect(0, 0, 10, 10), _rect(10, 0, 10, 10)))
|
|
31
|
+
|
|
32
|
+
def test__axis_aligned_overlap__pushes_a_away_from_b_along_the_shallow_axis(self):
|
|
33
|
+
mtv = poly.minimum_translation_vector(_rect(0, 0, 10, 10), _rect(8, 1, 10, 10))
|
|
34
|
+
|
|
35
|
+
self.assertAlmostEqual(mtv[0], -2)
|
|
36
|
+
self.assertAlmostEqual(mtv[1], 0)
|
|
37
|
+
|
|
38
|
+
def test__direction_flips_with_the_order(self):
|
|
39
|
+
a, b = _rect(0, 0, 10, 10), _rect(0, 7, 10, 10)
|
|
40
|
+
|
|
41
|
+
self.assertAlmostEqual(poly.minimum_translation_vector(a, b)[1], -3)
|
|
42
|
+
self.assertAlmostEqual(poly.minimum_translation_vector(b, a)[1], 3)
|
|
43
|
+
|
|
44
|
+
def test__applying_it_separates_rotated_rectangles(self):
|
|
45
|
+
a, b = _rect(0, 0, 50, 25, rot=0.4), _rect(30, 10, 50, 25, rot=-0.7)
|
|
46
|
+
mtv = poly.minimum_translation_vector(a, b)
|
|
47
|
+
self.assertIsNotNone(mtv)
|
|
48
|
+
|
|
49
|
+
moved = [(x + mtv[0] * 1.001, y + mtv[1] * 1.001) for x, y in a]
|
|
50
|
+
|
|
51
|
+
self.assertIsNone(poly.minimum_translation_vector(moved, b))
|
|
52
|
+
self.assertFalse(poly.do_convex_polygons_intersect(moved, b))
|
|
53
|
+
|
|
54
|
+
def test__contained_polygon__escapes_by_the_nearest_side(self):
|
|
55
|
+
mtv = poly.minimum_translation_vector(_rect(8, 0, 2, 2), _rect(0, 0, 20, 20))
|
|
56
|
+
|
|
57
|
+
self.assertAlmostEqual(mtv[0], 3)
|
|
58
|
+
self.assertAlmostEqual(mtv[1], 0)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
if __name__ == '__main__':
|
|
62
|
+
unittest.main()
|
|
@@ -128,6 +128,19 @@ class Test_StraightLineFollower_VelocityCap(unittest.TestCase):
|
|
|
128
128
|
self.assertEqual(final.pos, (0, 100))
|
|
129
129
|
self.assertEqual(final.velocity, (0, 0))
|
|
130
130
|
|
|
131
|
+
def test__max_speed__lowered__next_plan_obeys_it_and_clamps_a_faster_start(self):
|
|
132
|
+
follower = StraightLineFollower(max_acceleration=5.0, velocity_magnitude_bounds=(0, 10.0))
|
|
133
|
+
follower.MaxSpeed = 4.0
|
|
134
|
+
self.assertEqual(follower.MaxSpeed, 4.0)
|
|
135
|
+
|
|
136
|
+
trajectory = follower.plan(
|
|
137
|
+
start_pos=(0, 0), start_velocity=(0, 10.0),
|
|
138
|
+
waypoints=[Waypoint(end_pos=(0, 100), is_destination=True)],
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
for t in [i / 20 for i in range(21)]:
|
|
142
|
+
self.assertLessEqual(vec.vector_len(trajectory.at(t).velocity), 4.0 + 1e-6)
|
|
143
|
+
|
|
131
144
|
|
|
132
145
|
class Test_StraightLineFollower_OffAxisVelocity(unittest.TestCase):
|
|
133
146
|
|
|
@@ -617,5 +617,83 @@ class Test_WaypointFollower_OrbitingRisk(unittest.TestCase):
|
|
|
617
617
|
)
|
|
618
618
|
|
|
619
619
|
|
|
620
|
+
class Test_WaypointFollower_Replan(unittest.TestCase):
|
|
621
|
+
|
|
622
|
+
def test__replan__after_lowering_the_speed_cap__slows_at_once(self):
|
|
623
|
+
provider = StraightLineFollower(max_acceleration=1000.0, velocity_magnitude_bounds=(0, 20))
|
|
624
|
+
follower = _make_follower(start=(0, 0), provider=provider)
|
|
625
|
+
follower.add_waypoints([Waypoint(end_pos=(1000, 0), is_destination=True)])
|
|
626
|
+
for _ in range(30):
|
|
627
|
+
follower.update(delta_time_ms=16)
|
|
628
|
+
self.assertAlmostEqual(vec.vector_len(follower.Velocity.CurrentVelocity_M_S), 20, places=3)
|
|
629
|
+
|
|
630
|
+
provider.MaxSpeed = 8
|
|
631
|
+
follower.replan()
|
|
632
|
+
follower.update(delta_time_ms=16)
|
|
633
|
+
|
|
634
|
+
self.assertLessEqual(vec.vector_len(follower.Velocity.CurrentVelocity_M_S), 8 + 1e-6)
|
|
635
|
+
|
|
636
|
+
|
|
637
|
+
class Test_WaypointFollower_Nudge(unittest.TestCase):
|
|
638
|
+
|
|
639
|
+
def test__nudge__idle_follower__moves_immediately_and_stays(self):
|
|
640
|
+
follower = _make_follower(start=(10, 10))
|
|
641
|
+
|
|
642
|
+
follower.nudge((3, -4))
|
|
643
|
+
follower.update(delta_time_ms=16)
|
|
644
|
+
|
|
645
|
+
self.assertEqual(follower.Position, (13, 6))
|
|
646
|
+
|
|
647
|
+
def test__nudge__moving_follower__replans_from_the_new_position(self):
|
|
648
|
+
provider = StraightLineFollower(max_acceleration=50.0, velocity_magnitude_bounds=(0, 20))
|
|
649
|
+
follower = _make_follower(start=(0, 0), provider=provider)
|
|
650
|
+
follower.add_waypoints([Waypoint(end_pos=(100, 0), is_destination=True)])
|
|
651
|
+
for _ in range(30):
|
|
652
|
+
follower.update(delta_time_ms=16)
|
|
653
|
+
before = follower.Position
|
|
654
|
+
|
|
655
|
+
follower.nudge((0, 5), absorb_velocity=False)
|
|
656
|
+
self.assertEqual(follower.Position, (before[0], before[1] + 5))
|
|
657
|
+
follower.update(delta_time_ms=16)
|
|
658
|
+
|
|
659
|
+
# still heading for the destination, from the pushed position rather than the old path
|
|
660
|
+
self.assertGreater(follower.Position[0], before[0])
|
|
661
|
+
self.assertLess(follower.Position[1], before[1] + 5 + 1e-9)
|
|
662
|
+
self.assertGreater(follower.Position[1], before[1])
|
|
663
|
+
|
|
664
|
+
def test__nudge__absorbs_velocity_against_the_push(self):
|
|
665
|
+
provider = StraightLineFollower(max_acceleration=1000.0, velocity_magnitude_bounds=(0, 20))
|
|
666
|
+
follower = _make_follower(start=(0, 0), provider=provider)
|
|
667
|
+
follower.add_waypoints([Waypoint(end_pos=(1000, 0), is_destination=True)])
|
|
668
|
+
for _ in range(30):
|
|
669
|
+
follower.update(delta_time_ms=16)
|
|
670
|
+
self.assertAlmostEqual(follower.Velocity.CurrentVelocity_M_S[0], 20, places=3)
|
|
671
|
+
|
|
672
|
+
follower.nudge((-1, 0))
|
|
673
|
+
|
|
674
|
+
self.assertAlmostEqual(follower.Velocity.CurrentVelocity_M_S[0], 0, places=9)
|
|
675
|
+
|
|
676
|
+
def test__nudge__keeps_velocity_along_the_push(self):
|
|
677
|
+
follower = _make_follower(start=(0, 0), initial_velocity=(5, 2))
|
|
678
|
+
|
|
679
|
+
follower.nudge((0, 3))
|
|
680
|
+
|
|
681
|
+
self.assertEqual(tuple(follower.Velocity.CurrentVelocity_M_S), (5, 2))
|
|
682
|
+
|
|
683
|
+
def test__nudge__pressed_into_an_obstacle__makes_no_progress(self):
|
|
684
|
+
provider = StraightLineFollower(max_acceleration=40.0, velocity_magnitude_bounds=(0, 40))
|
|
685
|
+
follower = _make_follower(start=(0, 0), provider=provider)
|
|
686
|
+
follower.add_waypoints([Waypoint(end_pos=(1000, 0), is_destination=True)])
|
|
687
|
+
wall = 50.0
|
|
688
|
+
for _ in range(600):
|
|
689
|
+
follower.update(delta_time_ms=16)
|
|
690
|
+
overshoot = follower.Position[0] - wall
|
|
691
|
+
if overshoot > 0:
|
|
692
|
+
follower.nudge((-overshoot, 0))
|
|
693
|
+
|
|
694
|
+
self.assertLessEqual(follower.Position[0], wall + 1e-9)
|
|
695
|
+
self.assertLess(abs(follower.Velocity.CurrentVelocity_M_S[0]), 1.0)
|
|
696
|
+
|
|
697
|
+
|
|
620
698
|
if __name__ == '__main__':
|
|
621
699
|
unittest.main()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{cooptools-1.80 → cooptools-1.81}/cooptools/ideas/discreteEventSimulator/discreteEventSimulator.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|