⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 labelbox.java

📁 生物物种进化历程的演示
💻 JAVA
字号:
package AccordionDrawer;/** * Axis-aligned bounding box class for label drawing. Stores * information in screen coordintes, checks for overlap with other * bounding boxes. *  * @author  Tamara Munzner */public class LabelBox extends Object implements Comparable{    protected int bl[] = new int[2];    protected int tr[] = new int[2];    protected int blbg[] = new int[2];    protected int center[] = new int[2];    protected int extent[] = new int[2];    protected int frameNum;    String name;    int  labelheight;    public LabelBox(int bottomLeft[], int topRight[], int bottomLeftBG[], int computedFrame, String name)    {    	for (int xy = 0; xy < 2; xy++)    	{    		this.bl[xy] = bottomLeft[xy];    		this.tr[xy] = topRight[xy];    		this.blbg[xy] = bottomLeftBG[xy];    		extent[xy] = tr[xy] - bl[xy];    		if (extent[xy] < 0)    			extent[xy] *= -1;    	}    	this.name = name;    	this.frameNum = computedFrame;    	center[0] = this.bl[0]+(extent[0]/2);    	center[1] = this.tr[1]+(extent[1]/2);    }	public LabelBox(int bottomLeft[], int bottomRight[], int topLeft[], int topRight[], int bottomLeftBG[], int computedFrame,			String name, int labelheight, double angle, int drawVert)	{    	for (int xy = 0; xy < 2; xy++)    	{    		this.bl[xy] = bottomLeft[xy];    		this.tr[xy] = topRight[xy];    		this.blbg[xy] = bottomLeftBG[xy];    		extent[xy] = tr[xy] - bl[xy];    		if (extent[xy] < 0)    			extent[xy] *= -1;    	}    	this.name = name;    	this.frameNum = computedFrame;    	center[0] = this.bl[0]+(extent[0]/2);    	center[1] = this.tr[1]+(extent[1]/2);	   }    /**     * @author Tamara Munzner     *      * Test for intersection between this and another box (assuming     * both are axis-aligned). Use cached frame number to judge     * whether other box was created this frame and should be counted,     * or it's left over from previous frame and can be ignored.     *      * @param otherBox Box to check for intersection against this one     */    public boolean intersectBoxes(LabelBox b) {	int D[] = new int[2];	int fabs, fsum;	//double x = (labelheight+5)/Math.tan(Math.toRadians(drawAngle));//	double x = (labelheight+4)/Math.tan(Math.toRadians(drawAngle));	if (frameNum < b.frameNum) return false;	// check y direction first - common case is lots of leaves at	// identical x distances but different y distances.	for (int xy = 1; xy >=0 ; xy--) {	    // compute difference of box centers, D = C1-C0	    D[xy] = b.center[xy] - center[xy];	    //fabs = Math.abs(D[xy]);	   //fsum = extent[xy]/2 + b.extent[xy]/2;	    fabs = (D[xy] < 0) ? - D[xy] : D[xy];		fsum = (extent[xy]>>1) + (b.extent[xy]>>1);                  // fsum = (b.size(xy)+size(xy)) >> 1;//	    System.out.println(xy + " d " + D[xy] + " fabs " + fabs + " fsum " + fsum + " ext " + extent[xy] + " bext " + b.extent[xy] + " cent " + center[xy] + " bcent " + b.center[xy] + " fr " + frameNum + " bfr " + b.frameNum + " extent[xy]>>1 " + (extent[xy]>>1) + " extent/2 " + (extent[xy]/2));//	    if(drawVertical == 0)//	    {	      if ( fabs > fsum)		   return false;//	    } else if(drawVertical ==1)//	    {//		   if( Math.abs(b.bl[0] - br[0]) > x&& fabs > fsum )//		   return false;//	    } else//	    {//	    	if(Math.abs(b.tl[0] - tr[0]) > x && fabs > fsum )//	    	return false;//	    }	}  	return true;    }    /** implement Comparable interface - sort on y values */    public int compareTo(Object o) {    	LabelBox other = (LabelBox)o;    	if (center[1] - extent[1]/2 == other.center[1] - other.extent[1]/2) // y overlap only??    		return 0;    	else if (center[1] < other.center[1]) // sort on Y center    		return -1;    	return 1;    }	public boolean compareBtoT(LabelBox target, int low, int high)	{		return this.bl[1] < target.tr[1] && !(low==high);	}		public boolean bottomBiggerThanTop(LabelBox target)	{		return bl[1] >= target.tr[1];	}		public int pos(int xy)	{		return blbg[xy];	}    	public int topRightPos(int xy)	{		return tr[xy];	}	/**	 * @return	 */	public String getName() {		return name;	}		public int size(int xy)	{//		if (xy == 0)		int temp = tr[xy]-blbg[xy];		return temp < 0 ? -temp : temp;//		else //		{//			if(drawVertical != 2)		//			return blbg[xy]-tr[xy]+1;//		   else//		    return br[xy]-blbg[xy]+1;//		}	}};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -