第1页 / 共5页
第2页 / 共5页
第3页 / 共5页
第4页 / 共5页
第5页 / 共5页
Title:
* *Description:
* *Copyright: Copyright (c) 2010
* *Company:
* * @author An Zhiqiang (Email: 343887157@qq.com) * @version 1.0 (上午 11:34:06 2010) */ public class QuadTreeNode { NW = 0,NE = 1,SW = 2,SE = 3; public static final int NODE_NUMS = 4; public static final int /* * a quadrant defined below: * * * */ public int[] rect;// x,y,w,h public Vector vec; public QuadTreeNode[] node = new QuadTreeNode[NODE_NUMS]; -----------|----------- NW(0) | NE(1) SW(2) | SE(3) public QuadTreeNode(int x, int y, int w, int h) { init(x, y, w, h); } public QuadTreeNode() { } public void init(int x, int y, int w, int h) { int[] rect = new int[4]; rect[NW] = x; rect[NE] = y; rect[SW] = w; rect[SE] = h; this.rect = rect; vec = new Vector(); }Title:
* *Description:
* *Copyright: Copyright (c) 2010
Company:
* * @author An Zhiqiang (Email: 343887157@qq.com) * @version 1.0 (上午 11:34:35 2010) */ public class Util { /** * return true if rectA is inside rectB; * @param rectA * @param rectB */ public static boolean isInsideRect(int[] rectA,int[] rectB){ if(rectA[0]>rectB[0] && (rectA[0]+rectA[2])< (rectB[0]+rectB[2]) &&rectA[1]>rectB[1] && (rectA[1]+rectA[3])< (rectB[1]+rectB[3])){ return true; }else { return false; } } public static boolean isOverLapped(int[] rectA,int[] rectB){ if( rectA[0]+rectA[2]Title:
*Description:
* *Copyright: Copyright (c) 2010
* *Company:
* * @author An Zhiqiang (Email: 343887157@qq.com) * @version 1.0 (上午 11:34:15 2010) */ public class QuadTree { public QuadTreeNode root; public int depth; public int maxDepth; public QuadTree(int[] rect, int maxDepth) { depth = 0; this.maxDepth = maxDepth; root = new QuadTreeNode(); root.init(rect); } /* inserts a node into quadtree and return pointer to new node */ public QuadTreeNode insert(Object node_key, int[] rect) { depth = -1; debugNum = 0; return root.insertNode(this, rect, node_key); } /* searches nodes inside search_box */ void search(int[] search_box, Vector results_list) { root.searchNodes(search_box, results_list); } public static int debugNum; }