Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. package sonc.quad;
  2.  
  3. import java.util.Set;
  4.  
  5. /**
  6. * A Trie that has no descendants. This class corresponds to the Leaf in the
  7. * <b>Composite</b> design pattern.
  8. */
  9. class LeafTrie<T extends HasPoint> extends Trie<T> {
  10.  
  11. private Set<T> points;
  12.  
  13. protected LeafTrie(double topLeftX, double topLeftY, double bottomRightX, double bottomRightY) {
  14. super(topLeftX, topLeftY, bottomRightX, bottomRightY);
  15. }
  16.  
  17. Trie<T> insertReplace(T point) {
  18. points.clear();
  19. return insert(point);
  20. }
  21.  
  22. Trie<T> insert(T point) {
  23. if (points.size() < getCapacity()){
  24. points.add(point);
  25. return this;
  26. }
  27.  
  28. NodeTrie node = new NodeTrie(topLeftX, topLeftY,bottomRightX, bottomRightY);
  29. node.q.get(node.quadrantOf(point)).insert(point);
  30. for (T p : points) {
  31. node.q.get(node.quadrantOf(p)).insert(p);
  32. }
  33. return node;
  34. }
  35.  
  36. void collectAll(java.util.Set<T> nodes){
  37. for (p : points) {
  38. nodes.add(p);
  39. }
  40. }
  41.  
  42. void collectNear(double x, double y, double radius, java.util.Set<T> nodes){
  43. for (p : points) {
  44. if(getDistance(x,y,p.getX(),p.getY()) < radius) nodes.add(p);
  45. }
  46.  
  47. }
  48. T find(T point){
  49. for (T p : points) {
  50. if(p.getX() == point.getX() && p.getY() == point.getY()) return point;
  51. }
  52. return null;
  53. }
  54. void delete(T point) {
  55. points.remove(point);
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement