Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. package sonc.quad;
  2.  
  3. import java.util.HashSet;
  4. import java.util.Set;
  5.  
  6. /**
  7. *
  8. * This class follows the <b>Facade</b> design pattern and presents a presents a single
  9. * access point to manage <i>quad trees</i>. It provides methods for inserting,
  10. * deleting and finding elements implementing {@link HasPoint}.
  11. * This class corresponds to the <b>Client</b> in the <b>Composite</b> design pattern used in
  12. * this package.
  13. *
  14. * @author Rodrigo
  15. *
  16. */
  17. public class PointQuadtree<T extends HasPoint> {
  18.  
  19. private Trie<T> root;
  20.  
  21. public PointQuadtree(double topLeftX, double topLeftY, double bottomRightX, double bottomRightY) {
  22. this.root = new NodeTrie<>(topLeftX, topLeftY, bottomRightX, bottomRightY);
  23. }
  24.  
  25. /**
  26. * Find a recorded point with the same coordinates of given point
  27. *
  28. * @param point with requested coordinates
  29. * @return recorded point, if found; null otherwise
  30. */
  31. public T find(T point) {
  32. return root.find(point);
  33. }
  34.  
  35. /**
  36. * Insert given point in the QuadTree
  37. *
  38. * @param point to be inserted
  39. */
  40. public void insert(T point) {
  41. root.insert(point);
  42. }
  43.  
  44. /**
  45. * Insert point, replacing existing point in the same position
  46. *
  47. * @param point point to be inserted
  48. */
  49. public void insertReplace(T point) {
  50. root.insertReplace(point);
  51. }
  52.  
  53. /**
  54. * Returns a set of points at a distance smaller or equal to radius from point
  55. * with given coordinates.
  56. *
  57. * @param x coordinate of point
  58. * @param y coordinate of point
  59. * @param radius from given point
  60. * @return set of instances of type {@link HasPoint}
  61. */
  62. public Set<T> findNear(double x, double y, double radius) {
  63. Set<T> set = new HashSet<T>();
  64. root.collectNear(x, y, radius, set);
  65. return set;
  66. }
  67.  
  68. /**
  69. * Delete given point from QuadTree, if it exists there
  70. *
  71. * @param point to be deleted
  72. */
  73. public void delete(T point) {
  74. root.delete(point);
  75. }
  76.  
  77. /**
  78. * A set with all points in the QuadTree
  79. *
  80. * @return set of instances of type HasPoint
  81. */
  82. public Set<T> getAll() {
  83. Set<T> set = new HashSet<T>();
  84. root.collectAll(set);
  85. return set;
  86. }
  87.  
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement