//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 fuzzyobjects.basic; public class Basic{ /** * computes the BasicPoint nearest to (x,y) in R2 */ public static BasicPoint getNearestBasicPoint(int x,int y) { int ltx = (x / a) * a; // lefttop_x int lty = (y / b) * b; // lefttop_y if(x<0) ltx=ltx-a; if(y<0) lty=lty-b; int minx = ltx; // the current nearest point int miny = lty; double mindist = (x-ltx)*(x-ltx) + (y-lty)*(y-lty); // quad distance int curx = ltx; // the current point int cury = lty+b; double curmindist = (x-curx)*(x-curx) + (y-cury)*(y-cury); if (curmindist (ltx+a,lty) ?? boolean lt = (y*a <= b*(a-x)); // under the other diagonale boolean lb = (y*a) >= b*x; BasicPoint P1,P2,P3; P1 = new BasicPoint(ltx+a/2,lty+b/2); // have all triangles if (lt) { P2 = new BasicPoint(ltx,lty); if (lb) P3 = new BasicPoint(ltx,lty+b); else P3 = new BasicPoint(ltx+a,lty); } else{ // !lt P2 = new BasicPoint(ltx+a,lty+b); if(lb) P3 = new BasicPoint(ltx,lty+b); else P3 = new BasicPoint(ltx+a,lty); } return new BasicTriangle(P1,P2,P3); } /** * computes the BasicSegment nearest to (x,y) */ public static BasicSegment getNearestBasicSegment(int x, int y) { int ltx = (x/a)*a; // left top of "rectangle" int lty = (y/b)*b; if(x<0) ltx -=a; if(y<0) lty -=b; x = x-ltx; // move Rectangle to (0,0) y = y-lty; // compute quadratic distances to vertical and horizontal lines double [] Ldist = new double[5]; Ldist[0] = y*y; Ldist[1] = x*x; Ldist[2] = (b-y)*(b-y); Ldist[3] = (a-x)*(a-x); // which diagonle is a candidate ? boolean left = x