cooptools 1.81__tar.gz → 1.83__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.
Files changed (203) hide show
  1. {cooptools-1.81 → cooptools-1.83}/PKG-INFO +4 -1
  2. {cooptools-1.81 → cooptools-1.83}/cooptools/os_manip.py +14 -7
  3. {cooptools-1.81 → cooptools-1.83}/cooptools/sectors/sectorTree/sectorTree.py +6 -0
  4. cooptools-1.83/cooptools/spatial/__init__.py +10 -0
  5. cooptools-1.83/cooptools/spatial/colliders.py +79 -0
  6. cooptools-1.83/cooptools/spatial/index.py +424 -0
  7. cooptools-1.83/cooptools/spatial/stores.py +220 -0
  8. {cooptools-1.81 → cooptools-1.83}/cooptools.egg-info/PKG-INFO +4 -1
  9. {cooptools-1.81 → cooptools-1.83}/cooptools.egg-info/SOURCES.txt +5 -0
  10. {cooptools-1.81 → cooptools-1.83}/cooptools.egg-info/requires.txt +3 -0
  11. {cooptools-1.81 → cooptools-1.83}/setup.py +4 -1
  12. {cooptools-1.81 → cooptools-1.83}/tests/test_os_manip.py +36 -0
  13. cooptools-1.83/tests/test_spatial_index.py +511 -0
  14. {cooptools-1.81 → cooptools-1.83}/MANIFEST.in +0 -0
  15. {cooptools-1.81 → cooptools-1.83}/README.md +0 -0
  16. {cooptools-1.81 → cooptools-1.83}/cooptools/__init__.py +0 -0
  17. {cooptools-1.81 → cooptools-1.83}/cooptools/anchor.py +0 -0
  18. {cooptools-1.81 → cooptools-1.83}/cooptools/asyncable.py +0 -0
  19. {cooptools-1.81 → cooptools-1.83}/cooptools/cli/CliAtomicUserInteraction.py +0 -0
  20. {cooptools-1.81 → cooptools-1.83}/cooptools/cli/CliMenu.py +0 -0
  21. {cooptools-1.81 → cooptools-1.83}/cooptools/cli/__init__.py +0 -0
  22. {cooptools-1.81 → cooptools-1.83}/cooptools/cli/fileContentReturn.py +0 -0
  23. {cooptools-1.81 → cooptools-1.83}/cooptools/cnxn_info.py +0 -0
  24. {cooptools-1.81 → cooptools-1.83}/cooptools/colors.py +0 -0
  25. {cooptools-1.81 → cooptools-1.83}/cooptools/commandDesignPattern/__init__.py +0 -0
  26. {cooptools-1.81 → cooptools-1.83}/cooptools/commandDesignPattern/commandController.py +0 -0
  27. {cooptools-1.81 → cooptools-1.83}/cooptools/commandDesignPattern/commandProtocol.py +0 -0
  28. {cooptools-1.81 → cooptools-1.83}/cooptools/commandDesignPattern/exceptions.py +0 -0
  29. {cooptools-1.81 → cooptools-1.83}/cooptools/common.py +0 -0
  30. {cooptools-1.81 → cooptools-1.83}/cooptools/config.py +0 -0
  31. {cooptools-1.81 → cooptools-1.83}/cooptools/coopDataclass.py +0 -0
  32. {cooptools-1.81 → cooptools-1.83}/cooptools/coopEnum.py +0 -0
  33. {cooptools-1.81 → cooptools-1.83}/cooptools/coopthreading.py +0 -0
  34. {cooptools-1.81 → cooptools-1.83}/cooptools/currency.py +0 -0
  35. {cooptools-1.81 → cooptools-1.83}/cooptools/dataRefresher/__init__.py +0 -0
  36. {cooptools-1.81 → cooptools-1.83}/cooptools/dataRefresher/dataHub.py +0 -0
  37. {cooptools-1.81 → cooptools-1.83}/cooptools/dataRefresher/dataRefresher.py +0 -0
  38. {cooptools-1.81 → cooptools-1.83}/cooptools/dataStore/__init__.py +0 -0
  39. {cooptools-1.81 → cooptools-1.83}/cooptools/dataStore/dataProcessor.py +0 -0
  40. {cooptools-1.81 → cooptools-1.83}/cooptools/dataStore/dataStoreProtocol.py +0 -0
  41. {cooptools-1.81 → cooptools-1.83}/cooptools/dataStore/dbConnectionURI.py +0 -0
  42. {cooptools-1.81 → cooptools-1.83}/cooptools/dataStore/inMemoryDataStore.py +0 -0
  43. {cooptools-1.81 → cooptools-1.83}/cooptools/date_utils.py +0 -0
  44. {cooptools-1.81 → cooptools-1.83}/cooptools/decay.py +0 -0
  45. {cooptools-1.81 → cooptools-1.83}/cooptools/decor.py +0 -0
  46. {cooptools-1.81 → cooptools-1.83}/cooptools/dictPolicies.py +0 -0
  47. {cooptools-1.81 → cooptools-1.83}/cooptools/exceptions.py +0 -0
  48. {cooptools-1.81 → cooptools-1.83}/cooptools/expertise/__init__.py +0 -0
  49. {cooptools-1.81 → cooptools-1.83}/cooptools/expertise/expertiseArgs.py +0 -0
  50. {cooptools-1.81 → cooptools-1.83}/cooptools/expertise/expertiseSchedules.py +0 -0
  51. {cooptools-1.81 → cooptools-1.83}/cooptools/expertise/expertise_state.py +0 -0
  52. {cooptools-1.81 → cooptools-1.83}/cooptools/finance/__init__.py +0 -0
  53. {cooptools-1.81 → cooptools-1.83}/cooptools/finance/dicounted_cashflow_analysis.py +0 -0
  54. {cooptools-1.81 → cooptools-1.83}/cooptools/finance/fund_projection.py +0 -0
  55. {cooptools-1.81 → cooptools-1.83}/cooptools/finance/fund_projection_renderer.py +0 -0
  56. {cooptools-1.81 → cooptools-1.83}/cooptools/finance/futureValueProjector.py +0 -0
  57. {cooptools-1.81 → cooptools-1.83}/cooptools/finance/growth_projections.py +0 -0
  58. {cooptools-1.81 → cooptools-1.83}/cooptools/finance/reports.py +0 -0
  59. {cooptools-1.81 → cooptools-1.83}/cooptools/finance/utils.py +0 -0
  60. {cooptools-1.81 → cooptools-1.83}/cooptools/geometry_utils/__init__.py +0 -0
  61. {cooptools-1.81 → cooptools-1.83}/cooptools/geometry_utils/circle_utils.py +0 -0
  62. {cooptools-1.81 → cooptools-1.83}/cooptools/geometry_utils/common.py +0 -0
  63. {cooptools-1.81 → cooptools-1.83}/cooptools/geometry_utils/curve_utils.py +0 -0
  64. {cooptools-1.81 → cooptools-1.83}/cooptools/geometry_utils/curves.py +0 -0
  65. {cooptools-1.81 → cooptools-1.83}/cooptools/geometry_utils/line_utils.py +0 -0
  66. {cooptools-1.81 → cooptools-1.83}/cooptools/geometry_utils/polygon_utils.py +0 -0
  67. {cooptools-1.81 → cooptools-1.83}/cooptools/geometry_utils/rect_utils.py +0 -0
  68. {cooptools-1.81 → cooptools-1.83}/cooptools/geometry_utils/triangle_utils.py +0 -0
  69. {cooptools-1.81 → cooptools-1.83}/cooptools/geometry_utils/vector_utils.py +0 -0
  70. {cooptools-1.81 → cooptools-1.83}/cooptools/graphs/__init__.py +0 -0
  71. {cooptools-1.81 → cooptools-1.83}/cooptools/graphs/astar_results_viewer.py +0 -0
  72. {cooptools-1.81 → cooptools-1.83}/cooptools/graphs/draw.py +0 -0
  73. {cooptools-1.81 → cooptools-1.83}/cooptools/graphs/flow_field.py +0 -0
  74. {cooptools-1.81 → cooptools-1.83}/cooptools/graphs/graph.py +0 -0
  75. {cooptools-1.81 → cooptools-1.83}/cooptools/graphs/graph_dcs.py +0 -0
  76. {cooptools-1.81 → cooptools-1.83}/cooptools/graphs/graph_definitions.py +0 -0
  77. {cooptools-1.81 → cooptools-1.83}/cooptools/graphs/utils.py +0 -0
  78. {cooptools-1.81 → cooptools-1.83}/cooptools/ideas/__init__.py +0 -0
  79. {cooptools-1.81 → cooptools-1.83}/cooptools/ideas/actionItemTracker/__init__.py +0 -0
  80. {cooptools-1.81 → cooptools-1.83}/cooptools/ideas/actionItemTracker/ai_tracker.py +0 -0
  81. {cooptools-1.81 → cooptools-1.83}/cooptools/ideas/actionItemTracker/dcs.py +0 -0
  82. {cooptools-1.81 → cooptools-1.83}/cooptools/ideas/discreteEventSimulator/__init__.py +0 -0
  83. {cooptools-1.81 → cooptools-1.83}/cooptools/ideas/discreteEventSimulator/discreteEventSimulator.py +0 -0
  84. {cooptools-1.81 → cooptools-1.83}/cooptools/ideas/jsonIO.py +0 -0
  85. {cooptools-1.81 → cooptools-1.83}/cooptools/ideas/metrics.py +0 -0
  86. {cooptools-1.81 → cooptools-1.83}/cooptools/ideas/triggerActionSystem/__init__.py +0 -0
  87. {cooptools-1.81 → cooptools-1.83}/cooptools/ideas/triggerActionSystem/signal.py +0 -0
  88. {cooptools-1.81 → cooptools-1.83}/cooptools/ideas/triggerActionSystem/trigger.py +0 -0
  89. {cooptools-1.81 → cooptools-1.83}/cooptools/loggingHelpers.py +0 -0
  90. {cooptools-1.81 → cooptools-1.83}/cooptools/marchingSquares.py +0 -0
  91. {cooptools-1.81 → cooptools-1.83}/cooptools/materialHandling/__init__.py +0 -0
  92. {cooptools-1.81 → cooptools-1.83}/cooptools/materialHandling/cli.py +0 -0
  93. {cooptools-1.81 → cooptools-1.83}/cooptools/materialHandling/dcs.py +0 -0
  94. {cooptools-1.81 → cooptools-1.83}/cooptools/materialHandling/selectionCriteria.py +0 -0
  95. {cooptools-1.81 → cooptools-1.83}/cooptools/matrixManipulation.py +0 -0
  96. {cooptools-1.81 → cooptools-1.83}/cooptools/pandasHelpers.py +0 -0
  97. {cooptools-1.81 → cooptools-1.83}/cooptools/pathing/__init__.py +0 -0
  98. {cooptools-1.81 → cooptools-1.83}/cooptools/pathing/catmullRomFollower.py +0 -0
  99. {cooptools-1.81 → cooptools-1.83}/cooptools/pathing/demo/__init__.py +0 -0
  100. {cooptools-1.81 → cooptools-1.83}/cooptools/pathing/demo/server.py +0 -0
  101. {cooptools-1.81 → cooptools-1.83}/cooptools/pathing/kinematicGoalSeeker.py +0 -0
  102. {cooptools-1.81 → cooptools-1.83}/cooptools/pathing/motion_profile_utils.py +0 -0
  103. {cooptools-1.81 → cooptools-1.83}/cooptools/pathing/orbit_fuzzer.py +0 -0
  104. {cooptools-1.81 → cooptools-1.83}/cooptools/pathing/path_utils.py +0 -0
  105. {cooptools-1.81 → cooptools-1.83}/cooptools/pathing/straightLineFollower.py +0 -0
  106. {cooptools-1.81 → cooptools-1.83}/cooptools/pathing/trajectory_provider.py +0 -0
  107. {cooptools-1.81 → cooptools-1.83}/cooptools/pathing/waypoint.py +0 -0
  108. {cooptools-1.81 → cooptools-1.83}/cooptools/pathing/waypointFollower.py +0 -0
  109. {cooptools-1.81 → cooptools-1.83}/cooptools/persistence/__init__.py +0 -0
  110. {cooptools-1.81 → cooptools-1.83}/cooptools/persistence/enum_state.py +0 -0
  111. {cooptools-1.81 → cooptools-1.83}/cooptools/persistence/stateful.py +0 -0
  112. {cooptools-1.81 → cooptools-1.83}/cooptools/physics/__init__.py +0 -0
  113. {cooptools-1.81 → cooptools-1.83}/cooptools/physics/kinematic.py +0 -0
  114. {cooptools-1.81 → cooptools-1.83}/cooptools/physics/kinematic_utils.py +0 -0
  115. {cooptools-1.81 → cooptools-1.83}/cooptools/physics/movement.py +0 -0
  116. {cooptools-1.81 → cooptools-1.83}/cooptools/physics/trajectory.py +0 -0
  117. {cooptools-1.81 → cooptools-1.83}/cooptools/plotting.py +0 -0
  118. {cooptools-1.81 → cooptools-1.83}/cooptools/printing.py +0 -0
  119. {cooptools-1.81 → cooptools-1.83}/cooptools/protocols.py +0 -0
  120. {cooptools-1.81 → cooptools-1.83}/cooptools/qualifiers/__init__.py +0 -0
  121. {cooptools-1.81 → cooptools-1.83}/cooptools/qualifiers/cli.py +0 -0
  122. {cooptools-1.81 → cooptools-1.83}/cooptools/qualifiers/qualifier.py +0 -0
  123. {cooptools-1.81 → cooptools-1.83}/cooptools/randoms.py +0 -0
  124. {cooptools-1.81 → cooptools-1.83}/cooptools/register.py +0 -0
  125. {cooptools-1.81 → cooptools-1.83}/cooptools/reservation/__init__.py +0 -0
  126. {cooptools-1.81 → cooptools-1.83}/cooptools/reservation/dcs.py +0 -0
  127. {cooptools-1.81 → cooptools-1.83}/cooptools/reservation/enums.py +0 -0
  128. {cooptools-1.81 → cooptools-1.83}/cooptools/reservation/reservationmanager.py +0 -0
  129. {cooptools-1.81 → cooptools-1.83}/cooptools/retry.py +0 -0
  130. {cooptools-1.81 → cooptools-1.83}/cooptools/sectors/__init__.py +0 -0
  131. {cooptools-1.81 → cooptools-1.83}/cooptools/sectors/grids/__init__.py +0 -0
  132. {cooptools-1.81 → cooptools-1.83}/cooptools/sectors/grids/gridState.py +0 -0
  133. {cooptools-1.81 → cooptools-1.83}/cooptools/sectors/grids/grid_base.py +0 -0
  134. {cooptools-1.81 → cooptools-1.83}/cooptools/sectors/grids/hexGrid.py +0 -0
  135. {cooptools-1.81 → cooptools-1.83}/cooptools/sectors/grids/rectGrid.py +0 -0
  136. {cooptools-1.81 → cooptools-1.83}/cooptools/sectors/hex_utils.py +0 -0
  137. {cooptools-1.81 → cooptools-1.83}/cooptools/sectors/sect_utils.py +0 -0
  138. {cooptools-1.81 → cooptools-1.83}/cooptools/sectors/sectorTree/__init__.py +0 -0
  139. {cooptools-1.81 → cooptools-1.83}/cooptools/statistics/__init__.py +0 -0
  140. {cooptools-1.81 → cooptools-1.83}/cooptools/statistics/activityReport.py +0 -0
  141. {cooptools-1.81 → cooptools-1.83}/cooptools/statistics/controlChart/__init__.py +0 -0
  142. {cooptools-1.81 → cooptools-1.83}/cooptools/statistics/controlChart/controlChart.py +0 -0
  143. {cooptools-1.81 → cooptools-1.83}/cooptools/statistics/controlChart/plotting.py +0 -0
  144. {cooptools-1.81 → cooptools-1.83}/cooptools/statistics/oee/__init__.py +0 -0
  145. {cooptools-1.81 → cooptools-1.83}/cooptools/statistics/oee/oeeHub.py +0 -0
  146. {cooptools-1.81 → cooptools-1.83}/cooptools/taskProcessing/__init__.py +0 -0
  147. {cooptools-1.81 → cooptools-1.83}/cooptools/taskProcessing/dcs.py +0 -0
  148. {cooptools-1.81 → cooptools-1.83}/cooptools/taskProcessing/taskProcessor.py +0 -0
  149. {cooptools-1.81 → cooptools-1.83}/cooptools/timeTracker/__init__.py +0 -0
  150. {cooptools-1.81 → cooptools-1.83}/cooptools/timeTracker/decay.py +0 -0
  151. {cooptools-1.81 → cooptools-1.83}/cooptools/timeTracker/timeTracker.py +0 -0
  152. {cooptools-1.81 → cooptools-1.83}/cooptools/timeWindow.py +0 -0
  153. {cooptools-1.81 → cooptools-1.83}/cooptools/toggles.py +0 -0
  154. {cooptools-1.81 → cooptools-1.83}/cooptools/transform.py +0 -0
  155. {cooptools-1.81 → cooptools-1.83}/cooptools/trends.py +0 -0
  156. {cooptools-1.81 → cooptools-1.83}/cooptools/typeProviders.py +0 -0
  157. {cooptools-1.81 → cooptools-1.83}/cooptools/typevalidation.py +0 -0
  158. {cooptools-1.81 → cooptools-1.83}/cooptools/version.py +0 -0
  159. {cooptools-1.81 → cooptools-1.83}/cooptools.egg-info/dependency_links.txt +0 -0
  160. {cooptools-1.81 → cooptools-1.83}/cooptools.egg-info/not-zip-safe +0 -0
  161. {cooptools-1.81 → cooptools-1.83}/cooptools.egg-info/top_level.txt +0 -0
  162. {cooptools-1.81 → cooptools-1.83}/requirements.txt +0 -0
  163. {cooptools-1.81 → cooptools-1.83}/setup.cfg +0 -0
  164. {cooptools-1.81 → cooptools-1.83}/tests/test_CliAtomicUserInteraction.py +0 -0
  165. {cooptools-1.81 → cooptools-1.83}/tests/test_asyncable.py +0 -0
  166. {cooptools-1.81 → cooptools-1.83}/tests/test_catmullRomFollower.py +0 -0
  167. {cooptools-1.81 → cooptools-1.83}/tests/test_cdp_bugs.py +0 -0
  168. {cooptools-1.81 → cooptools-1.83}/tests/test_commandDesignPattern.py +0 -0
  169. {cooptools-1.81 → cooptools-1.83}/tests/test_common.py +0 -0
  170. {cooptools-1.81 → cooptools-1.83}/tests/test_config.py +0 -0
  171. {cooptools-1.81 → cooptools-1.83}/tests/test_coopEnum.py +0 -0
  172. {cooptools-1.81 → cooptools-1.83}/tests/test_currency.py +0 -0
  173. {cooptools-1.81 → cooptools-1.83}/tests/test_curves.py +0 -0
  174. {cooptools-1.81 → cooptools-1.83}/tests/test_date_utils.py +0 -0
  175. {cooptools-1.81 → cooptools-1.83}/tests/test_expertise_state.py +0 -0
  176. {cooptools-1.81 → cooptools-1.83}/tests/test_flow_field.py +0 -0
  177. {cooptools-1.81 → cooptools-1.83}/tests/test_flow_field_perf.py +0 -0
  178. {cooptools-1.81 → cooptools-1.83}/tests/test_fund_projection.py +0 -0
  179. {cooptools-1.81 → cooptools-1.83}/tests/test_graph_node_classification.py +0 -0
  180. {cooptools-1.81 → cooptools-1.83}/tests/test_kinematicGoalSeeker.py +0 -0
  181. {cooptools-1.81 → cooptools-1.83}/tests/test_kinematic_utils.py +0 -0
  182. {cooptools-1.81 → cooptools-1.83}/tests/test_pandas.py +0 -0
  183. {cooptools-1.81 → cooptools-1.83}/tests/test_path_utils.py +0 -0
  184. {cooptools-1.81 → cooptools-1.83}/tests/test_persistence.py +0 -0
  185. {cooptools-1.81 → cooptools-1.83}/tests/test_polygon_utils.py +0 -0
  186. {cooptools-1.81 → cooptools-1.83}/tests/test_printing.py +0 -0
  187. {cooptools-1.81 → cooptools-1.83}/tests/test_qualifiers.py +0 -0
  188. {cooptools-1.81 → cooptools-1.83}/tests/test_sectors.py +0 -0
  189. {cooptools-1.81 → cooptools-1.83}/tests/test_sectors_hex.py +0 -0
  190. {cooptools-1.81 → cooptools-1.83}/tests/test_sectors_sectorTree.py +0 -0
  191. {cooptools-1.81 → cooptools-1.83}/tests/test_statistics.py +0 -0
  192. {cooptools-1.81 → cooptools-1.83}/tests/test_straightLineFollower.py +0 -0
  193. {cooptools-1.81 → cooptools-1.83}/tests/test_target_seek.py +0 -0
  194. {cooptools-1.81 → cooptools-1.83}/tests/test_tasks.py +0 -0
  195. {cooptools-1.81 → cooptools-1.83}/tests/test_toggles.py +0 -0
  196. {cooptools-1.81 → cooptools-1.83}/tests/test_trajectory.py +0 -0
  197. {cooptools-1.81 → cooptools-1.83}/tests/test_trends.py +0 -0
  198. {cooptools-1.81 → cooptools-1.83}/tests/test_typevalidation.py +0 -0
  199. {cooptools-1.81 → cooptools-1.83}/tests/test_vector_utils.py +0 -0
  200. {cooptools-1.81 → cooptools-1.83}/tests/test_version.py +0 -0
  201. {cooptools-1.81 → cooptools-1.83}/tests/test_waypointFollower.py +0 -0
  202. {cooptools-1.81 → cooptools-1.83}/tests/tests_graph.py +0 -0
  203. {cooptools-1.81 → cooptools-1.83}/tests/tests_gridsystem.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cooptools
3
- Version: 1.81
3
+ Version: 1.83
4
4
  Summary: Generic Tooling
5
5
  Home-page: https://github.com/tylertjburns/cooptools
6
6
  Author: tburns
@@ -21,6 +21,8 @@ Requires-Dist: pandas>=2.2.3
21
21
  Requires-Dist: pytz>=2024.1
22
22
  Requires-Dist: Pypubsub>=4.0.3
23
23
  Requires-Dist: python-dateutil>=2.9.0
24
+ Provides-Extra: spatial
25
+ Requires-Dist: shapely>=2.1.2; extra == "spatial"
24
26
  Dynamic: author
25
27
  Dynamic: author-email
26
28
  Dynamic: classifier
@@ -28,6 +30,7 @@ Dynamic: description
28
30
  Dynamic: description-content-type
29
31
  Dynamic: home-page
30
32
  Dynamic: license
33
+ Dynamic: provides-extra
31
34
  Dynamic: requires-dist
32
35
  Dynamic: requires-python
33
36
  Dynamic: summary
@@ -124,7 +124,7 @@ def rename_files(filepaths: List[StringProvider],
124
124
  if remove_spaces:
125
125
  new = new.replace(' ', '')
126
126
 
127
- os.rename(src=src, dst=fr"{path}\{new}")
127
+ os.rename(src=src, dst=os.path.join(path, new))
128
128
 
129
129
  def check_and_make_new_proj_localapp(app_root: StringProvider, proj_name: StringProvider):
130
130
  """ Verifies that the app_root exists at LOCALAPPDATA and then verifies that a subfolder exists at that directory
@@ -141,7 +141,7 @@ def root_and_name(root: StringProvider, name: StringProvider):
141
141
 
142
142
  root = resolve_string_provider(root)
143
143
  name = resolve_string_provider(name)
144
- return f"{root}\\{name}"
144
+ return os.path.join(root, name)
145
145
 
146
146
 
147
147
  def check_and_make_proj_path_dir(root, proj_name):
@@ -153,11 +153,18 @@ def check_and_make_proj_path_dir(root, proj_name):
153
153
  return proj_dir
154
154
 
155
155
 
156
+ def local_app_data() -> str:
157
+ """ The per-user application data directory: LOCALAPPDATA on Windows; where that isn't set (Linux,
158
+ macOS), XDG_DATA_HOME, else ~/.local/share"""
159
+ return (os.getenv(LOCALAPP_ROOT)
160
+ or os.getenv("XDG_DATA_HOME")
161
+ or os.path.join(os.path.expanduser("~"), ".local", "share"))
162
+
163
+
156
164
  def localapp_root(app_name: StringProvider):
157
165
  """ Returns the string of the directory that would be in the LOCALAPPDATA for the given app name"""
158
166
  app_name = resolve_string_provider(app_name)
159
- local_app_data = os.getenv(LOCALAPP_ROOT)
160
- return f"{local_app_data}\\{app_name}"
167
+ return os.path.join(local_app_data(), app_name)
161
168
 
162
169
 
163
170
  def localapp_root_exists(app_name: StringProvider):
@@ -238,8 +245,8 @@ def read_file(file_path: StringProvider, as_lines: bool=False):
238
245
 
239
246
  def filepath_at_check_and_make_dir(dir: StringProvider, file_name: StringProvider, file_type: FileType = None):
240
247
  file_name = resolve_string_provider(file_name)
241
- check_and_make_dirs(dir)
242
- file_path = f"{dir}\\{file_name}"
248
+ dir = check_and_make_dirs(dir)
249
+ file_path = os.path.join(dir, file_name)
243
250
  return clean_file_type(file_path, file_type)
244
251
 
245
252
 
@@ -340,7 +347,7 @@ def load_application_json(app_root: StringProvider, filename: StringProvider):
340
347
  def load_project_json(app_root: StringProvider, project: StringProvider, filename: StringProvider):
341
348
  proj_dir = check_and_make_new_proj_localapp(app_root, project)
342
349
  filename = resolve_string_provider(filename)
343
- file_path = f"{proj_dir}\\{filename}.json"
350
+ file_path = os.path.join(proj_dir, f"{filename}.json")
344
351
  return try_load_json_data_to_dict(file_path)
345
352
 
346
353
  def get_xml_root_from_file(file_path_provider: StringProvider) -> ET.Element:
@@ -234,6 +234,12 @@ class SectorTree:
234
234
  def nearby_clients(self,
235
235
  radius: float, pt: Tuple[float, float],
236
236
  client_types: Iterable[str] = None) -> Dict[Any, Tuple[float, float]]:
237
+ """
238
+ Clients in sectors near `pt`; polygons are tested by bounding box only.
239
+
240
+ For exact proximity, containment or nearest-neighbour questions over
241
+ moving clients, use `cooptools.spatial.SpatialIndex`.
242
+ """
237
243
  t0 = time.perf_counter()
238
244
 
239
245
  sectors_nearby = self._sectors_potentially_overlaps_radius(radius, pt)
@@ -0,0 +1,10 @@
1
+ """
2
+ Spatial indexing over mixed point and polygon colliders.
3
+
4
+ Needs the `spatial` extra: `pip install cooptools[spatial]`.
5
+ """
6
+
7
+ from cooptools.spatial.colliders import Collider, to_geometry
8
+ from cooptools.spatial.index import KindStats, SpatialIndex, SpatialIndexStats
9
+
10
+ __all__ = ["Collider", "KindStats", "SpatialIndex", "SpatialIndexStats", "to_geometry"]
@@ -0,0 +1,79 @@
1
+ """Turning the loose shapes callers hand in into points and shapely geometry."""
2
+
3
+ import math
4
+ import numbers
5
+ from typing import Sequence, Tuple, Union
6
+
7
+ import numpy as np
8
+ import shapely
9
+ from shapely.geometry import Point, Polygon
10
+ from shapely.geometry.base import BaseGeometry
11
+
12
+ Collider = Union[BaseGeometry, Tuple[float, float], Sequence[Tuple[float, float]]]
13
+ XY = Tuple[float, float]
14
+
15
+
16
+ def parse(collider: Collider) -> Union[XY, BaseGeometry]:
17
+ """
18
+ Read a collider's structure without validating any geometry.
19
+
20
+ - (x, y), [(x, y)], or a shapely Point -> an (x, y) tuple
21
+ - [(x, y), (x, y), (x, y), ...] -> Polygon
22
+ - any other shapely geometry -> used as-is
23
+
24
+ Points come back as plain coordinates because that is all the point store
25
+ keeps; building a shapely Point per moving client would cost more than
26
+ storing it. Two coordinate pairs are refused rather than guessed at: a
27
+ segment is a LineString, and the caller should say so.
28
+ """
29
+ if isinstance(collider, BaseGeometry):
30
+ if isinstance(collider, Point) and not collider.is_empty:
31
+ return _finite(collider.x, collider.y)
32
+ return collider
33
+
34
+ coords = list(collider)
35
+ if not coords:
36
+ raise ValueError("collider is empty")
37
+ if isinstance(coords[0], numbers.Real):
38
+ if len(coords) != 2:
39
+ raise ValueError(f"a flat collider must be (x, y), got {len(coords)} values")
40
+ return _finite(coords[0], coords[1])
41
+ if len(coords) == 1:
42
+ return _finite(coords[0][0], coords[0][1])
43
+ if len(coords) == 2:
44
+ raise ValueError("two coordinate pairs is a segment; pass a shapely LineString")
45
+ return Polygon(coords)
46
+
47
+
48
+ def validate_shapes(geoms: Sequence[BaseGeometry]) -> None:
49
+ """
50
+ Refuse empty or invalid geometry, checking the whole batch in one call.
51
+
52
+ Invalid geometry (a self-intersecting ring, say) is refused because
53
+ predicates evaluated against it return wrong answers without raising, and
54
+ by query time nothing points back at the client that caused it.
55
+ """
56
+ if not len(geoms):
57
+ return
58
+ arr = np.asarray(geoms, dtype=object)
59
+ bad = np.flatnonzero(shapely.is_empty(arr) | ~shapely.is_valid(arr))
60
+ if len(bad):
61
+ g = arr[bad[0]]
62
+ reason = "empty" if g.is_empty else f"invalid: {shapely.is_valid_reason(g)}"
63
+ raise ValueError(f"collider geometry is {reason}")
64
+
65
+
66
+ def to_geometry(collider: Collider) -> BaseGeometry:
67
+ """A collider as one valid, non-empty shapely geometry."""
68
+ parsed = parse(collider)
69
+ if isinstance(parsed, tuple):
70
+ return Point(parsed)
71
+ validate_shapes([parsed])
72
+ return parsed
73
+
74
+
75
+ def _finite(x, y) -> XY:
76
+ x, y = float(x), float(y)
77
+ if not (math.isfinite(x) and math.isfinite(y)):
78
+ raise ValueError(f"point collider has a non-finite coordinate: ({x}, {y})")
79
+ return x, y
@@ -0,0 +1,424 @@
1
+ import logging
2
+ from dataclasses import dataclass, field
3
+ from typing import (Callable, Dict, Generic, Hashable, Iterable, Iterator, List, Mapping, Optional, Sequence, Set,
4
+ Tuple, TypeVar, Union)
5
+
6
+ import numpy as np
7
+ import shapely
8
+ from shapely.geometry import Point
9
+ from shapely.geometry.base import BaseGeometry
10
+
11
+ from cooptools.spatial.colliders import Collider, parse, to_geometry, validate_shapes
12
+ from cooptools.spatial.stores import Bounds, PointStore, ShapeStore
13
+
14
+ logger = logging.getLogger(__name__)
15
+
16
+ K = TypeVar("K", bound=Hashable)
17
+ Kinds = Union[None, Hashable, Iterable[Hashable]]
18
+ Store = Union[PointStore, ShapeStore]
19
+
20
+ # Stands in for "no client to leave out" so a client whose id is None is not.
21
+ _NOBODY = object()
22
+
23
+
24
+ @dataclass(frozen=True)
25
+ class KindStats:
26
+ points: int
27
+ shapes: int
28
+ tree_rebuilds: int
29
+
30
+
31
+ @dataclass(frozen=True)
32
+ class SpatialIndexStats:
33
+ clients: int
34
+ generation: int
35
+ kinds: Dict[Hashable, KindStats] = field(default_factory=dict)
36
+
37
+
38
+ @dataclass(frozen=True)
39
+ class _Layout:
40
+ """Where each id in one id list lives, valid while `version` matches the index's."""
41
+ uids: List[Hashable]
42
+ version: int
43
+ groups: List[Tuple[PointStore, np.ndarray, np.ndarray]] # store, its rows, positions in uids
44
+ point_pos: np.ndarray
45
+ point_ids: List[Hashable]
46
+ others: List[Hashable] # ids that are not point clients
47
+
48
+
49
+ class SpatialIndex(Generic[K]):
50
+ """
51
+ A spatial index over any mix of point and polygon clients.
52
+
53
+ Each client is an id with one collider and one kind. The index picks where
54
+ to keep it: points go in a numpy array that a move writes into directly;
55
+ every other geometry goes in an STRtree that is rebuilt on the first query
56
+ after it changes. Storage is partitioned by kind, so filtering by kind
57
+ costs nothing. The caller never chooses a store, and every question is
58
+ answered across both.
59
+
60
+ Geometry is pushed in (`upsert`) or pulled from `collider_provider`
61
+ (`refresh`). The index never calls the provider during a query: a tree is
62
+ only valid while the index knows which clients changed, and asking every
63
+ provider on every question is the per-client Python cost this exists to
64
+ avoid. Tell it what changed.
65
+
66
+ Semantics:
67
+ - Distances are exact; a point inside a polygon is at distance 0.
68
+ - Boundaries count: a point on an edge shared by two polygons is in both.
69
+ - A query given as a client id never returns that client.
70
+ - Where a query could be read either way, a known client id wins over a
71
+ collider, so a tuple id that looks like a coordinate is the client.
72
+ - `kinds` is a single kind or an iterable of kinds; None means every kind.
73
+
74
+ Not thread-safe.
75
+ """
76
+
77
+ def __init__(self, collider_provider: Optional[Callable[[K], Collider]] = None):
78
+ self._provider = collider_provider
79
+ self._kind: Dict[K, Hashable] = {}
80
+ self._seq: Dict[K, int] = {}
81
+ self._where: Dict[K, Store] = {}
82
+ self._points: Dict[Hashable, PointStore] = {}
83
+ self._shapes: Dict[Hashable, ShapeStore] = {}
84
+ self._next_seq = 0
85
+ self._layout_version = 0
86
+ self._layout_cache: Optional[_Layout] = None
87
+ self.generation = 0
88
+
89
+ # ── Mutation ──────────────────────────────────────────────────────────────
90
+
91
+ def upsert(self, uid: K, collider: Optional[Collider] = None, kind: Optional[Hashable] = None) -> None:
92
+ """
93
+ Add a client or replace its geometry.
94
+
95
+ `collider=None` pulls the geometry from the provider. `kind=None` keeps
96
+ an existing client's kind and tags a new client with the kind None.
97
+ """
98
+ self._upsert_batch([(uid, collider)], kind)
99
+
100
+ def upsert_many(self, colliders: Mapping[K, Optional[Collider]], kind: Optional[Hashable] = None) -> None:
101
+ """`upsert` for many clients. If any collider is refused, none are applied."""
102
+ self._upsert_batch(list(colliders.items()), kind)
103
+
104
+ def refresh(self, uids: Optional[Iterable[K]] = None) -> None:
105
+ """Re-pull geometry from the provider for `uids`, or for every client."""
106
+ if self._provider is None:
107
+ raise ValueError("refresh() needs a collider_provider")
108
+ self._upsert_batch([(uid, None) for uid in (list(self._kind) if uids is None else uids)], None)
109
+
110
+ def move_points(self, uids: Sequence[K], xy) -> None:
111
+ """
112
+ Move existing point clients to new coordinates in bulk.
113
+
114
+ `xy` is anything numpy reads as one (x, y) row per id. Every id must be
115
+ a point client already; changing a client's geometry kind goes through
116
+ `upsert`. Passing the same id list frame after frame is the fast path:
117
+ where each id's row lives is worked out once and reused until a point
118
+ client is added or removed.
119
+ """
120
+ xy = np.asarray(xy, dtype=float).reshape(-1, 2)
121
+ if len(xy) != len(uids):
122
+ raise ValueError(f"{len(uids)} ids but {len(xy)} coordinates")
123
+ layout = self._layout(uids)
124
+ if layout.others:
125
+ uid = layout.others[0]
126
+ raise KeyError(f"{uid!r} is not a point client" if uid in self._where else uid)
127
+ for store, rows, pos in layout.groups:
128
+ store.write_rows(rows, xy[pos])
129
+ self.generation += 1
130
+
131
+ def remove(self, uids: Iterable[K]) -> None:
132
+ """Remove clients. Ids the index does not hold are ignored."""
133
+ for uid in uids:
134
+ store = self._where.pop(uid, None)
135
+ if store is None:
136
+ continue
137
+ store.remove(uid)
138
+ if isinstance(store, PointStore):
139
+ self._layout_version += 1
140
+ del self._kind[uid]
141
+ del self._seq[uid]
142
+ self.generation += 1
143
+
144
+ def _upsert_batch(self, items: List[Tuple[K, Optional[Collider]]], kind: Optional[Hashable]):
145
+ """Parse and validate every collider first, so a refusal leaves the index untouched."""
146
+ parsed = []
147
+ for uid, collider in items:
148
+ if collider is None:
149
+ if self._provider is None:
150
+ raise ValueError(f"no collider given for {uid!r} and no collider_provider to pull one from")
151
+ collider = self._provider(uid)
152
+ parsed.append((uid, parse(collider)))
153
+ validate_shapes([p for _, p in parsed if not isinstance(p, tuple)])
154
+ for uid, p in parsed:
155
+ self._place(uid, p, kind)
156
+ self.generation += 1
157
+
158
+ def _place(self, uid: K, parsed, kind: Optional[Hashable]):
159
+ if kind is None and uid in self._kind:
160
+ kind = self._kind[uid]
161
+ is_point = isinstance(parsed, tuple)
162
+ table = self._points if is_point else self._shapes
163
+ target = table.get(kind)
164
+ if target is None:
165
+ target = table[kind] = PointStore() if is_point else ShapeStore()
166
+
167
+ current = self._where.get(uid)
168
+ if current is not target:
169
+ if current is not None:
170
+ current.remove(uid)
171
+ if isinstance(current, PointStore):
172
+ self._layout_version += 1
173
+ if is_point:
174
+ self._layout_version += 1
175
+ self._where[uid] = target
176
+ if is_point:
177
+ target.put(uid, parsed[0], parsed[1])
178
+ else:
179
+ target.put(uid, parsed)
180
+
181
+ self._kind[uid] = kind
182
+ if uid not in self._seq:
183
+ self._seq[uid] = self._next_seq
184
+ self._next_seq += 1
185
+
186
+ def _layout(self, uids: Sequence[K]) -> _Layout:
187
+ """Where each id's point row lives, cached for a repeated id list."""
188
+ cached = self._layout_cache
189
+ if cached is not None and cached.version == self._layout_version and cached.uids == uids:
190
+ return cached
191
+ groups: Dict[int, Tuple[PointStore, List[int], List[int]]] = {}
192
+ others: List[K] = []
193
+ point_pos: List[int] = []
194
+ for i, uid in enumerate(uids):
195
+ store = self._where.get(uid)
196
+ if isinstance(store, PointStore):
197
+ group = groups.get(id(store))
198
+ if group is None:
199
+ group = groups[id(store)] = (store, [], [])
200
+ group[1].append(store.row_of(uid))
201
+ group[2].append(i)
202
+ point_pos.append(i)
203
+ else:
204
+ others.append(uid)
205
+ layout = _Layout(
206
+ uids=list(uids),
207
+ version=self._layout_version,
208
+ groups=[(s, np.asarray(rows, dtype=np.intp), np.asarray(pos, dtype=np.intp))
209
+ for s, rows, pos in groups.values()],
210
+ point_pos=np.asarray(point_pos, dtype=np.intp),
211
+ point_ids=[uids[i] for i in point_pos],
212
+ others=others,
213
+ )
214
+ self._layout_cache = layout
215
+ return layout
216
+
217
+ # ── Questions ─────────────────────────────────────────────────────────────
218
+
219
+ def within(self, center: Union[K, Collider], radius: float, kinds: Kinds = None) -> Set[K]:
220
+ """Clients whose geometry lies within `radius` of `center` (exact distance)."""
221
+ if radius < 0:
222
+ raise ValueError(f"radius must be >= 0, got {radius}")
223
+ geom, exclude = self._resolve(center)
224
+ out: Set[K] = set()
225
+ for store in self._stores(kinds):
226
+ if isinstance(store, PointStore):
227
+ out.update(store.within(geom, radius))
228
+ else:
229
+ out.update(store.query(geom, "dwithin", radius))
230
+ out.discard(exclude)
231
+ return out
232
+
233
+ def intersecting(self, query: Union[K, Collider], kinds: Kinds = None) -> Set[K]:
234
+ """Clients whose geometry intersects the query's, boundaries included."""
235
+ geom, exclude = self._resolve(query)
236
+ out: Set[K] = set()
237
+ for store in self._stores(kinds):
238
+ if isinstance(store, PointStore):
239
+ out.update(store.intersecting(geom))
240
+ else:
241
+ out.update(store.query(geom, "intersects"))
242
+ out.discard(exclude)
243
+ return out
244
+
245
+ def containing(self, pt: Tuple[float, float], kinds: Kinds = None, tolerance: float = 0.0) -> Set[K]:
246
+ """
247
+ Clients that cover the point `pt`, or lie within `tolerance` of it.
248
+
249
+ `tolerance` absorbs floating-point gaps where neighbouring polygons
250
+ built from the same vertices do not quite meet.
251
+ """
252
+ geom = Point(float(pt[0]), float(pt[1]))
253
+ if tolerance > 0:
254
+ return self.within(geom, tolerance, kinds)
255
+ return self.intersecting(geom, kinds)
256
+
257
+ def locate(self, uids: Iterable[K], kinds: Kinds = None, tolerance: float = 0.0) -> Dict[K, Set[K]]:
258
+ """
259
+ `containing` for many clients at once: {uid: clients it lies in}.
260
+
261
+ Point clients are answered together, in one tree query per store,
262
+ which is what makes "where is every villager" cost one call rather than
263
+ one per villager. A non-point id is answered with `intersecting`.
264
+ """
265
+ uids = list(uids)
266
+ layout = self._layout(uids)
267
+ out: Dict[K, Set[K]] = {uid: set() for uid in uids}
268
+ for uid in layout.others:
269
+ if uid not in self._where:
270
+ raise KeyError(uid)
271
+ out[uid] = self.within(uid, tolerance, kinds) if tolerance > 0 else self.intersecting(uid, kinds)
272
+ if not layout.point_ids:
273
+ return out
274
+
275
+ xy = np.empty((len(uids), 2), dtype=float)
276
+ for store, rows, pos in layout.groups:
277
+ xy[pos] = store.xy[rows]
278
+ queries = shapely.points(xy[layout.point_pos])
279
+ predicate, distance = ("dwithin", tolerance) if tolerance > 0 else ("intersects", None)
280
+ point_ids = layout.point_ids
281
+ for store in self._stores(kinds):
282
+ qi, matched = store.match(queries, predicate, distance)
283
+ if isinstance(store, PointStore):
284
+ # Only a point store holds the query points themselves.
285
+ for q, other in zip(qi.tolist(), matched):
286
+ if other != point_ids[q]:
287
+ out[point_ids[q]].add(other)
288
+ else:
289
+ for q, other in zip(qi.tolist(), matched):
290
+ out[point_ids[q]].add(other)
291
+ return out
292
+
293
+ def nearest(self, query: Union[K, Collider], k: int = 1, kinds: Kinds = None,
294
+ max_distance: Optional[float] = None) -> List[Tuple[K, float]]:
295
+ """
296
+ Up to `k` clients closest to the query as (id, distance), nearest first.
297
+
298
+ Ties break by the order clients were first added. Fewer than `k` come
299
+ back when fewer exist (or lie within `max_distance`).
300
+ """
301
+ if k < 1:
302
+ raise ValueError(f"k must be >= 1, got {k}")
303
+ geom, exclude = self._resolve(query)
304
+ candidates: List[Tuple[K, float]] = []
305
+ for store in self._stores(kinds):
306
+ need = k + (1 if exclude in store else 0)
307
+ if isinstance(store, PointStore):
308
+ if not len(store):
309
+ continue
310
+ d = store.distances(geom)
311
+ if max_distance is not None:
312
+ keep = np.flatnonzero(d <= max_distance)
313
+ else:
314
+ keep = np.arange(len(d))
315
+ if len(keep) > need:
316
+ keep = keep[np.argpartition(d[keep], need - 1)[:need]]
317
+ candidates.extend((store.ids[i], float(d[i])) for i in keep)
318
+ else:
319
+ candidates.extend(store.nearest(geom, need, max_distance))
320
+ candidates = [(uid, d) for uid, d in candidates
321
+ if uid != exclude and (max_distance is None or d <= max_distance)]
322
+ candidates.sort(key=lambda c: (c[1], self._seq[c[0]]))
323
+ return candidates[:k]
324
+
325
+ def pairs(self, kinds_a: Kinds = None, kinds_b: Kinds = None) -> Iterator[Tuple[K, K]]:
326
+ """
327
+ Every intersecting (a, b) with a's kind in `kinds_a` and b's in `kinds_b`.
328
+
329
+ A pair that qualifies in both orders is yielded once, earliest-added
330
+ client first.
331
+ """
332
+ want_a, want_b = self._kind_set(kinds_a), self._kind_set(kinds_b)
333
+ side_a = self.ids(kinds_a)
334
+ if not side_a:
335
+ return
336
+ queries = np.array([self.geometry(uid) for uid in side_a], dtype=object)
337
+ seen: Set[Tuple[K, K]] = set()
338
+ for store in self._stores(kinds_b):
339
+ qi, matched = store.match(queries, "intersects", None)
340
+ for q, b in zip(qi, matched):
341
+ a = side_a[q]
342
+ if a == b:
343
+ continue
344
+ a_is_b_side = want_b is None or self._kind[a] in want_b
345
+ b_is_a_side = want_a is None or self._kind[b] in want_a
346
+ if a_is_b_side and b_is_a_side:
347
+ pair = (a, b) if self._seq[a] < self._seq[b] else (b, a)
348
+ else:
349
+ pair = (a, b)
350
+ if pair not in seen:
351
+ seen.add(pair)
352
+ yield pair
353
+
354
+ # ── Introspection ─────────────────────────────────────────────────────────
355
+
356
+ def geometry(self, uid: K) -> BaseGeometry:
357
+ store = self._where[uid]
358
+ if isinstance(store, PointStore):
359
+ return Point(store.point(uid))
360
+ return store.geometry(uid)
361
+
362
+ def point(self, uid: K) -> Tuple[float, float]:
363
+ store = self._where[uid]
364
+ if not isinstance(store, PointStore):
365
+ raise KeyError(f"{uid!r} is not a point client")
366
+ return store.point(uid)
367
+
368
+ def kind_of(self, uid: K) -> Hashable:
369
+ return self._kind[uid]
370
+
371
+ def bounds(self, uid: K) -> Bounds:
372
+ store = self._where[uid]
373
+ if isinstance(store, PointStore):
374
+ x, y = store.point(uid)
375
+ return x, y, x, y
376
+ return tuple(float(v) for v in store.geometry(uid).bounds)
377
+
378
+ def ids(self, kinds: Kinds = None) -> List[K]:
379
+ """Client ids in the order they were first added."""
380
+ wanted = self._kind_set(kinds)
381
+ return [uid for uid, kind in self._kind.items() if wanted is None or kind in wanted]
382
+
383
+ def stats(self) -> SpatialIndexStats:
384
+ kinds = {}
385
+ for kind in set(self._points) | set(self._shapes):
386
+ p, s = self._points.get(kind), self._shapes.get(kind)
387
+ kinds[kind] = KindStats(points=len(p) if p else 0,
388
+ shapes=len(s) if s else 0,
389
+ tree_rebuilds=s.rebuilds if s else 0)
390
+ return SpatialIndexStats(clients=len(self._kind), generation=self.generation, kinds=kinds)
391
+
392
+ def __len__(self) -> int:
393
+ return len(self._kind)
394
+
395
+ def __contains__(self, uid) -> bool:
396
+ try:
397
+ return uid in self._kind
398
+ except TypeError:
399
+ return False
400
+
401
+ # ── Internals ─────────────────────────────────────────────────────────────
402
+
403
+ def _resolve(self, query) -> Tuple[BaseGeometry, object]:
404
+ """A query's geometry, plus the client id to leave out of the answer."""
405
+ if not isinstance(query, BaseGeometry) and query in self:
406
+ return self.geometry(query), query
407
+ return to_geometry(query), _NOBODY
408
+
409
+ @staticmethod
410
+ def _kind_set(kinds: Kinds) -> Optional[Set[Hashable]]:
411
+ if kinds is None:
412
+ return None
413
+ if isinstance(kinds, (str, bytes)) or not isinstance(kinds, Iterable):
414
+ return {kinds}
415
+ return set(kinds)
416
+
417
+ def _stores(self, kinds: Kinds) -> List[Store]:
418
+ wanted = self._kind_set(kinds)
419
+ out: List[Store] = []
420
+ for table in (self._points, self._shapes):
421
+ for kind, store in table.items():
422
+ if len(store) and (wanted is None or kind in wanted):
423
+ out.append(store)
424
+ return out