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

📄 rect.java

📁 关于R+树的java源码
💻 JAVA
字号:
/*
	COMP 630C project
	Re-implementation of R+ tree

	Group member:
	Cheng Wing Hang, Nelson
	Cheung Kwok Ho, Steven
	Ngai Ming Wai, Ryan
	Shiu Hoi Nam
	Tsui Chi Man
*/


import java.*;
import java.util.Random;

public class RECT {

	float low[] = new float[2]; // Coordinates of lower left corner.
	float high[] = new float[2];  // Coordinates of upper right corner.

	// constructor function: The coordinates are generated randomly.
	public RECT() { 
		
		Random  rg = new Random();

		int     limit = 101;	    // Maximum value of a coordinate.
		int     temp1, temp2;	   // Dummy variables.
		int     counter;		// Counter in a for-loop.
		int     max_loop = 4096;	// The maximum number of loops.


		// A loop to make sure that the seed (i.e. time) is new.
		for (counter = 0; counter < max_loop; counter++) {
			Random rg2 = new Random(rg.nextInt());
			rg2 = rg;
		}


		// Generate two random numbers.
		temp1 = rg.nextInt() % limit;
		if (temp1 < 0) {
			temp1 *= -1;
		}
		temp2 = rg.nextInt() % limit;
		if (temp2 < 0) {
			temp2 *= -1;
		}


		// Make sure that the two numbers are different.
		if (temp1 == temp2) {
			temp2 = (temp2 + 1) % limit;
		}


		// Fill the x-coordinates.
		if (temp1 < temp2) {
			this.low[0] = temp1;
			this.high[0] = temp2;
		}
		else {
			this.low[0] = temp2;
			this.high[0] = temp1;
		}


		// Generate another two random numbers. 
		temp1 = rg.nextInt() % limit;
		if (temp1 < 0) {
			temp1 *= -1;
		}
		temp2 = rg.nextInt() % limit;
		if (temp2 < 0) {
			temp2 *= -1;
		}


		// Again make sure that the two numbers are different.
		if (temp1 == temp2) {
			temp2 = (temp2 + 1) % limit;
		}


		// Fill the y-coordinates.
		if (temp1 < temp2) {
			this.low[1] = temp1;
			this.high[1] = temp2;
		}
		else {
			this.low[1] = temp2;
			this.high[1] = temp1;
		}

	}

        public RECT(RECT rect)
        {
                this.low[0]=rect.low[0];
                this.high[0]=rect.high[0];
                this.low[1]=rect.low[1];
                this.high[1]=rect.high[1];

        }

	public RECT(float xl, float yl, float xh, float yh)
	{
		this.low[0]=xl;
		this.low[1]=yl;
		this.high[0]=xh;
		this.high[1]=yh;
	}

   // Check whether the given rectangle intersect with current one
	public RECT intersect(RECT r) 
	{
		float	low_x, low_y, high_x, high_y;
		RECT	result;
	
		if (this.low[0] < r.low[0]) {
			low_x = r.low[0];
		}
		else {
			low_x = this.low[0];
		}
		if (this.high[0] > r.high[0]) {
			high_x = r.high[0];
		}
		else {
			high_x = this.high[0];
		}
		if (this.low[1] < r.low[1]) {
			low_y = r.low[1];
		}
		else {
			low_y = this.low[1];
		}
		if (this.high[1] > r.high[1]) {
			high_y = r.high[1];
		}
		else {
			high_y = this.high[1];
		}
			
		result = new RECT(low_x, low_y, high_x, high_y);
		return result;
	}

   // Return the area of the rectangle
	public float area()
	{
		return ((high[1] - low[1]) * (high[0] - low[0]));
	}

   // Print the coordinate of the Rectangle 
	public void print()
	{
		System.out.println("(  (" + this.low[0] + ", " + this.low[1] + "), (" +
			       this.high[0] + ", " + this.high[1] + ")  )");
	}
}

⌨️ 快捷键说明

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