public void removePoint( PolygonPoint p ) { PolygonPoint next, prev; next = p.getNext(); prev = p.getPrevious(); prev.setNext( next ); next.setPrevious( prev ); _points.remove( p ); }
/** * Will add a point after the last point added * * @param p */ public void addPoint(PolygonPoint p ) { p.setPrevious( _last ); p.setNext( _last.getNext() ); _last.setNext( p ); _points.add( p ); }
private static Polygon convert(PolygonList2d polygon) { return new Polygon(polygon.getPoints().stream() .map(p -> new PolygonPoint(p.x, p.y)).collect(Collectors.toCollection(ArrayList<PolygonPoint>::new))); } }
/** * Requires atleast 3 points * @param points - ordered list of points forming the polygon. * No duplicates are allowed */ public Polygon( List<PolygonPoint> points ) { // Lets do one sanity check that first and last point hasn't got same position // Its something that often happen when importing polygon data from other formats if( points.get(0).equals( points.get(points.size()-1) ) ) { logger.warn( "Removed duplicate point"); points.remove( points.size()-1 ); } _points.addAll( points ); }
public static Polygon RandomCircleSweep2( double scale, int vertexCount ) { PolygonPoint point; PolygonPoint[] points; double radius = scale/4; points = new PolygonPoint[vertexCount]; for(int i=0; i<vertexCount; i++) { do { radius += scale/5*(0.5 - Math.random()); radius = radius > scale/2 ? scale/2 : radius; radius = radius < scale/10 ? scale/10 : radius; } while( radius < scale/10 || radius > scale/2 ); point = new PolygonPoint( radius*Math.cos( (PI_2*i)/vertexCount ), radius*Math.sin( (PI_2*i)/vertexCount ) ); points[i] = point; } return new Polygon( points ); } }
public void addPoints( List<PolygonPoint> list ) { PolygonPoint first; for( PolygonPoint p : list ) { p.setPrevious( _last ); if( _last != null ) { p.setNext( _last.getNext() ); _last.setNext( p ); } _last = p; _points.add( p ); } first = (PolygonPoint)_points.get(0); _last.setNext( first ); first.setPrevious( _last ); }
radius = radius < scale/10 ? scale/10 : radius; } while( radius < scale/10 || radius > scale/2 ); point = new PolygonPoint( radius*Math.cos( (PI_2*i)/vertexCount ), radius*Math.sin( (PI_2*i)/vertexCount ) ); points[i] = point;
/** * Will insert a point in the polygon after given point */ public void insertPointAfter( PolygonPoint a, PolygonPoint newPoint ) { // Validate that int index = _points.indexOf( a ); if( index != -1 ) { newPoint.setNext( a.getNext() ); newPoint.setPrevious( a ); a.getNext().setPrevious( newPoint ); a.setNext( newPoint ); _points.add( index+1, newPoint ); } else { throw new RuntimeException( "Tried to insert a point into a Polygon after a point not belonging to the Polygon" ); } }
private org.poly2tri.geometry.polygon.Polygon makePolygon(LineString lineString) { PolygonPoint[] points = new PolygonPoint[lineString.getNumPoints() - 1]; for(int idPoint=0; idPoint < points.length; idPoint++) { Coordinate point = lineString.getCoordinateN(idPoint); points[idPoint] = new PolygonPoint(r(point.x), r(point.y), Double.isNaN(point.z) ? 0 : r(point.z)); } return new org.poly2tri.geometry.polygon.Polygon(points); }
private org.poly2tri.geometry.polygon.Polygon makePolygon(LineString lineString) { PolygonPoint[] points = new PolygonPoint[lineString.getNumPoints() - 1]; for(int idPoint=0; idPoint < points.length; idPoint++) { Coordinate point = lineString.getCoordinateN(idPoint); points[idPoint] = new PolygonPoint(r(point.x), r(point.y), Double.isNaN(point.z) ? 0 : r(point.z)); } return new org.poly2tri.geometry.polygon.Polygon(points); }
private org.poly2tri.geometry.polygon.Polygon makePolygon(LineString lineString) { PolygonPoint[] points = new PolygonPoint[lineString.getNumPoints() - 1]; for(int idPoint=0; idPoint < points.length; idPoint++) { Coordinate point = lineString.getCoordinateN(idPoint); points[idPoint] = new PolygonPoint(r(point.x), r(point.y), Double.isNaN(point.z) ? 0 : r(point.z)); } return new org.poly2tri.geometry.polygon.Polygon(points); }