JavaXT
|
|
Points Classpackage javaxt.geospatial.geometry; //****************************************************************************** //** Points Class //****************************************************************************** /** * Used to manage an array of points (Point) * ******************************************************************************/ public class Points { // implements Geometry private java.util.Vector<Point> points = new java.util.Vector<Point>(); //************************************************************************** //** Creates a new instance of Points //************************************************************************** public Points(Point[] points){ for (int i=0; i<points.length; i++){ Point point = points[i]; if (point!=null) this.points.add(point); } } public Points(){ } public Point[] getArray(){ Point[] arr = new Point[points.size()]; if (arr.length>0){ for (int i=0; i<arr.length; i++){ arr[i] = points.get(i); } } return arr; } public Point[] getPoints(){ return getArray(); } //************************************************************************** //** getFirstPoint //************************************************************************** /** Returns the first point in the point array */ public Point getFirstPoint(){ Point[] Points = getPoints(); if (Points!=null){ return Points[0]; } else{ return null; } } //************************************************************************** //** getLastPoint //************************************************************************** /** Returns the last point in the point array */ public Point getLastPoint(){ Point[] Points = getPoints(); if (Points!=null){ return Points[Points.length-1]; } else{ return null; } } //************************************************************************** //** getLength //************************************************************************** /** Returns the length of the point array */ public int getLength(){ Point[] Points = getPoints(); if (Points!=null){ return Points.length; } else{ return -1; } } //************************************************************************** //** addPoint //************************************************************************** /** Used to append a point to an array of points */ public Point[] addPoint(Point point){ if (point!=null) points.add(point); return getPoints(); } //************************************************************************** //** addPoint //************************************************************************** /** Used to append a point to an array of points */ public Point[] addPoint(double x, double y){ return addPoint(new Point(x,y)); } //************************************************************************** //** addPoints //************************************************************************** /** Used to append a point or multiple points to an array of points. * Attempts to convert input string into coordinate tuples. */ /* public Point[] addPoints(String Coordinates){ Parser CoordinateParser = new Parser(Coordinates); return addPoints((Points)CoordinateParser.getGeometry()); } */ //************************************************************************** //** addPoints //************************************************************************** /** Used to append a point or multiple points to an array of points. */ public Point[] addPoints(Points points){ return addPoints(points.getArray()); } //************************************************************************** //** addPoints //************************************************************************** /** Used to append a point or multiple points to an array of points. */ public Point[] addPoints(Point[] arr){ for (int i=0; i<arr.length; i++){ addPoint(arr[i]); } return getPoints(); } //************************************************************************** //** toString //************************************************************************** /** Used to convert a line to a String */ public String toString(){ Point[] Points = getPoints(); if (Points==null) return ""; else{ StringBuffer Coordinates = new StringBuffer(); for (int i=0; i<Points.length; i++){ Coordinates.append(Points[i].toString() + " "); } return Coordinates.toString().trim(); } } //************************************************************************** //** toString //************************************************************************** /** Used to convert a line to a String */ public String toString(String CoordinateSeparator, String TupleSeparator){ Point[] Points = getPoints(); if (Points==null) return ""; else{ StringBuffer Coordinates = new StringBuffer(); for (int i=0; i<Points.length; i++){ Coordinates.append(Points[i].toString(CoordinateSeparator) + TupleSeparator); } String ret = Coordinates.toString(); //.trim(); if (ret.endsWith(TupleSeparator)){ ret = ret.substring(0, (ret.length()-TupleSeparator.length())); } return ret; } } } |