Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package sonc.quad;
- import java.util.Set;
- /**
- * A Trie that has no descendants. This class corresponds to the Leaf in the
- * <b>Composite</b> design pattern.
- */
- class LeafTrie<T extends HasPoint> extends Trie<T> {
- private Set<T> points;
- protected LeafTrie(double topLeftX, double topLeftY, double bottomRightX, double bottomRightY) {
- super(topLeftX, topLeftY, bottomRightX, bottomRightY);
- }
- Trie<T> insertReplace(T point) {
- points.clear();
- return insert(point);
- }
- Trie<T> insert(T point) {
- if (points.size() < getCapacity()){
- points.add(point);
- return this;
- }
- NodeTrie node = new NodeTrie(topLeftX, topLeftY,bottomRightX, bottomRightY);
- node.q.get(node.quadrantOf(point)).insert(point);
- for (T p : points) {
- node.q.get(node.quadrantOf(p)).insert(p);
- }
- return node;
- }
- void collectAll(java.util.Set<T> nodes){
- for (p : points) {
- nodes.add(p);
- }
- }
- void collectNear(double x, double y, double radius, java.util.Set<T> nodes){
- for (p : points) {
- if(getDistance(x,y,p.getX(),p.getY()) < radius) nodes.add(p);
- }
- }
- T find(T point){
- for (T p : points) {
- if(p.getX() == point.getX() && p.getY() == point.getY()) return point;
- }
- return null;
- }
- void delete(T point) {
- points.remove(point);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement