//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; import java.util.Vector; /** * this class manage a serie of connected BasicPoints * the Path has no selfcuts and can build a circle */ public class Path{ /** creates a new empty Path */ public Path(){ Points = new Vector(); } /** check the emptyness of this path */ public boolean isEmpty(){ return Points.size()==0; } /** deletes all points from this path */ public void makeEmpty(){ if(Points.size()>0) Points = new Vector(); } /** returns this path in a readable form */ public String toString(){ if(Points.size()==0) return("empty Path"); else{ String result = ""; int max = Points.size(); for(int i=0;iresult.maxX) result.maxX = x; if(yresult.maxY) result.maxY = y; } result.Points.add(BP); } } return result; } /** returns the length(number of containing Points) of * this Path */ public int length(){ int result = Points.size(); // check of circle if(result>1) if (Points.get(0).equals(Points.get(result-1))) result--; return result; } /** returns the BasicPoint on position pos */ public BasicPoint getPoint(int pos){ if( pos<0 | pos>= Points.size()) return null; else return (BasicPoint) Points.get(pos); } /** returns the first Point in Path */ public BasicPoint getFirstPoint(){ if(Points.size()==0) return null; else return (BasicPoint) Points.get(0); } /** returns the last Point in Path */ public BasicPoint getLastPoint(){ if(Points.size()==0) return null; else return (BasicPoint) Points.get(Points.size()-1); } /** extend the Path with P * the first Point of P must be equals to the last Point * of this Path, this Path can not be a circle * this Path and P can not have cuts * @return true if sucessfull */ public boolean extend(Path P){ int length = Points.size(); int Plength = P.Points.size(); if( Plength==0) return true; // no change this Path BasicPoint OldLast = (BasicPoint) Points.get(length-1); BasicPoint NewFirst = (BasicPoint) P.Points.get(0); if(!OldLast.equals(NewFirst)) return false; boolean overlappingLine = false; BasicSegment FromThis; BasicSegment FromExtend; for(int i=0;imaxX) maxX = P.maxX; if(P.minXmaxY) maxY=P.maxY; if(P.minYmaxX) maxX = x; if(ymaxY) maxY=y; return true; } /** returns the number of containing segments */ public int getNumberOfSegments(){ int NOP = Points.size(); return NOP-1; } /** returns the segment on position no */ public BasicSegment getSegment(int no){ if(no<0 | no>getNumberOfSegments()) return null; else return new BasicSegment((BasicPoint)Points.get(no), (BasicPoint)Points.get(no+1)); } /** * returns the length of this path * (sum of lengths of the containing segments) */ public double getLength(){ int max = getNumberOfSegments(); double Length=0; for(int i=0;imaxX) maxX=x; if(ymaxY) maxY=y; } } } protected Vector Points; /** the Bounding Box */ /** the minimum X of the bounding box */ protected int minX =0; /** the minimum Y of the bounding box */ protected int minY =0; /** the maximum X of the bounding box */ protected int maxX =0; /** the maximum Y of the bounding box */ protected int maxY =0; }