우선 수천 개의 사각형을 검사하는 것이 Java (또는 플러그인)에 큰 도움이되지는 않습니다. 간단한 수학은 밀리 초 단위로 수행되어야합니다. 당신의 소유자 문제를 다루기 위해서 당신은 내 자신의 사각형과 소유자 클래스를 생성 할 것을 권한다. 따라서 사각형에 정의 된 소유자가있을 수 있으며 현재 플레이어가 자신이 속한 영역의 소유자인지 간단히 확인할 수 있습니다.
public class custom_Area extends Rectangle{
private owner o;
public owner getOwner() {
return o;
}
public void setOwner(owner o) {
this.o = o;
}
}
편집 :
난 그냥 100.000 임의의 사각형을 만들고 그 중 하나가 다른 사람과 교차할지 어떨지를 체크하여 테스트했습니다.
--Custom 사각형 클래스
public class area extends Rectangle{
private owner o;
public area(owner o, int i, int i1, int i2, int i3) {
super(i, i1, i2, i3);
this.o = o;
}
public owner getO() {
return o;
}
public void setO(owner o) {
this.o = o;
}
}
--Custom 소유자 클래스
public class owner {
String name;
public owner(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
--main 클래스
public class Rectanglesearch {
public static area a[] = new area[100000];
public static owner o[] = new owner[10];
public static int intersectCounter = 0;
public static int ownerCounter = 0;
public static void main(String[] args) {
for(int y = 0; y<10;y++){
o[y] = new owner("y");
}
for (int i = 0; i < 100000; i++) {
a[i] = new area(o[(int)(Math.random() * 10)],random(),random(),random(),random());
}
checkArea(a[10]);
checkOwner(o[3]);
System.out.println("Area a[10] intersects with "+intersectCounter+" out of "+a.length);
System.out.println("Owner o[3] owns "+ownerCounter+" areas out of "+a.length);
}
public static int random(){
return (int)(Math.random() * 100000) + 1;
}
public static void checkArea(area ab){
for (area a1 : a) {
if (ab.intersects(a1)) {
intersectCounter +=1;
}
}
}
public static void checkOwner(owner ob){
for (area a1 : a){
if(a1.getOwner()==ob){
ownerCounter +=1;
}
}
}
}
checkArea (영역 AB)은 남자 영역과 교차 방법을 반환
방법 영역 AB 방법 checkOwner (소유자 산부인과) 매뉴얼 영역을 소유하는 방법