2
0

CCHMapTreeUtils.h 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. //
  2. // CCHMapTreeUtils.h
  3. // CCHMapClusterController
  4. //
  5. // Copyright (C) 2013 Theodore Calmes
  6. // Copyright (C) 2013 Claus Höfele
  7. //
  8. // Permission is hereby granted, free of charge, to any person obtaining a copy
  9. // of this software and associated documentation files (the "Software"), to deal
  10. // in the Software without restriction, including without limitation the rights
  11. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. // copies of the Software, and to permit persons to whom the Software is
  13. // furnished to do so, subject to the following conditions:
  14. //
  15. // The above copyright notice and this permission notice shall be included in
  16. // all copies or substantial portions of the Software.
  17. //
  18. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. // THE SOFTWARE.
  25. //
  26. #import <Foundation/Foundation.h>
  27. @interface CCHMapTreeUnsafeMutableArray : NSObject
  28. @property (nonatomic, assign, readonly) id __unsafe_unretained *objects;
  29. @property (nonatomic, readonly) NSUInteger numObjects;
  30. - (instancetype)initWithCapacity:(NSUInteger)capacity;
  31. - (void)addObject:(__unsafe_unretained id)object;
  32. @end
  33. typedef struct CCHMapTreeNodeData {
  34. double x, y;
  35. void *data;
  36. } CCHMapTreeNodeData;
  37. NS_INLINE CCHMapTreeNodeData CCHMapTreeNodeDataMake(double x, double y, void *data) {
  38. return (CCHMapTreeNodeData){x, y, data};
  39. }
  40. typedef struct CCHMapTreeBoundingBox {
  41. double x0, y0, xf, yf;
  42. } CCHMapTreeBoundingBox;
  43. NS_INLINE CCHMapTreeBoundingBox CCHMapTreeBoundingBoxMake(double x0, double y0, double xf, double yf) {
  44. return (CCHMapTreeBoundingBox){x0, y0, xf, yf};
  45. }
  46. typedef struct CCHMapTreeNode {
  47. CCHMapTreeBoundingBox boundingBox;
  48. struct CCHMapTreeNode *northWest;
  49. struct CCHMapTreeNode *northEast;
  50. struct CCHMapTreeNode *southWest;
  51. struct CCHMapTreeNode *southEast;
  52. CCHMapTreeNodeData *points;
  53. unsigned long count;
  54. } CCHMapTreeNode;
  55. CCHMapTreeNode *CCHMapTreeNodeMake(CCHMapTreeBoundingBox boundary, unsigned long bucketCapacity);
  56. void CCHMapTreeFreeQuadTreeNode(CCHMapTreeNode *node);
  57. typedef void(^CCHMapTreeTraverseBlock)(CCHMapTreeNode *currentNode);
  58. void CCHMapTreeTraverse(CCHMapTreeNode *node, CCHMapTreeTraverseBlock block);
  59. typedef void(^TBDataReturnBlock)(CCHMapTreeNodeData data);
  60. void CCHMapTreeGatherDataInRange(CCHMapTreeNode *node, CCHMapTreeBoundingBox range, TBDataReturnBlock block);
  61. void CCHMapTreeGatherDataInRange2(CCHMapTreeNode *node, CCHMapTreeBoundingBox range, __unsafe_unretained NSMutableSet *annotations);
  62. void CCHMapTreeGatherDataInRange3(CCHMapTreeNode *node, CCHMapTreeBoundingBox range, __unsafe_unretained CCHMapTreeUnsafeMutableArray *annotations);
  63. CCHMapTreeNode *CCHMapTreeBuildWithData(CCHMapTreeNodeData *data, unsigned long count, CCHMapTreeBoundingBox boundingBox, unsigned long bucketCapacity);
  64. bool CCHMapTreeNodeInsertData(CCHMapTreeNode* node, CCHMapTreeNodeData data, unsigned long bucketCapacity);
  65. bool CCHMapTreeNodeRemoveData(CCHMapTreeNode* node, CCHMapTreeNodeData data); // only removes first matching item