Files
secondo/Javagui/viewer/fuzzy2d/BoundingBox2D.java

135 lines
3.1 KiB
Java
Raw Normal View History

2026-01-23 17:03:45 +08:00
//This file is part of SECONDO.
//Copyright (C) 2004, University in Hagen, Department of Computer Science,
//Database Systems for New Applications.
//SECONDO is free software; you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation; either version 2 of the License, or
//(at your option) any later version.
//SECONDO is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.
//You should have received a copy of the GNU General Public License
//along with SECONDO; if not, write to the Free Software
//Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package viewer.fuzzy2d;
import viewer.viewer3d.graphic3d.BoundingBox3D;
public class BoundingBox2D{
/** creates a new 2dim Bounding Box with given values*/
public BoundingBox2D(double minx,double miny,double maxx,double maxy){
super();
setTo(minx,miny,maxx,maxy);
}
/** creates a new BoundingBox2D */
public BoundingBox2D(){
this(0,0,0,0);
}
/** returns a readable represemntation of the BoundingBox */
public String toString(){
return "[ ("+minx+","+miny+")->("+maxx+","+maxy+")]";
}
/** set the Values to a projection from BB3*/
public void readFrom(BoundingBox3D BB){
minx = BB.getMinX();
miny = BB.getMinY();
maxx = BB.getMaxX();
maxy = BB.getMaxY();
}
/** extends this BoundingBox with BB2*/
public void union(BoundingBox2D BB2){
minx=min(minx,BB2.minx);
miny=min(miny,BB2.miny);
maxx=max(maxx,BB2.maxx);
maxy=max(maxy,BB2.maxy);
}
/** set the Values of this BoundingBox */
public void setTo(double minx,double miny,double maxx,double maxy){
this.minx=min(minx,maxx);
this.miny=min(miny,maxy);
this.maxx=max(minx,maxx);
this.maxy=max(miny,maxy);
}
/** extends this Bounding Box so that (x,y) in inside from this Bounding Box */
public void include(double x , double y){
minx = min(x,minx);
maxx = max(x,maxx);
miny = min(y,miny);
maxy = max(y,maxy);
}
/** set the values frtom this to the values from BB2 */
public void equalize(BoundingBox2D BB2){
minx = BB2.minx;
maxx = BB2.maxx;
miny = BB2.miny;
maxy = BB2.maxy;
}
/** returns the width of this Bounding box */
public double getWidth(){ return maxx-minx;}
/** returns thze heigt of this Bounding Box */
public double getHeight(){return maxy-miny;}
public double getMinX(){return minx;}
public double getMinY(){return miny;}
public double getMaxX(){return maxx;}
public double getMaxY(){return maxy;}
/** returns true if this and BB2 have common points */
public boolean intersect(BoundingBox2D BB2){
if(minx>BB2.maxx) return false; //right from BB2
if(maxx<BB2.minx) return false; // left from BB2
if(miny>BB2.maxy) return false; // above BB2
if(maxy<BB2.miny) return false; // under BB2
return true;
}
private double min(double x, double y){
return (x<y)? x : y;
}
private double max(double x, double y){
return (x>y)? x : y;
}
private double minx,miny;
private double maxx,maxy;
}