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 ); }
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 ); } }
private org.poly2tri.geometry.polygon.Polygon makePolygon(Polygon polygon) { org.poly2tri.geometry.polygon.Polygon poly = makePolygon(polygon.getExteriorRing()); // Add holes for(int idHole = 0; idHole < polygon.getNumInteriorRing(); idHole++) { poly.addHole(makePolygon(polygon.getInteriorRingN(idHole))); } return poly; }
/** * Triangulate a PolygonSet * * @param ps */ public void triangulate( PolygonSet ps ) { _triangulations.clear(); _triangulations.addAll( ps.getPolygons() ); start(); }
/** * 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 ); }
hint += p.pointCount();
private static List<Triangle2d> convert(Polygon p) { List<DelaunayTriangle> triangles = p.getTriangles(); if (triangles == null || triangles.size() == 0) { return null; } List<Triangle2d> out = new ArrayList<Triangle2d>(); for (DelaunayTriangle t : triangles) { Triangle2d triangle = new Triangle2d( new Point2d(t.points[0].getX(), t.points[0].getY()), new Point2d(t.points[1].getX(), t.points[1].getY()), new Point2d(t.points[2].getX(), t.points[2].getY())); out.add(triangle); } return out; }
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))); } }
private org.poly2tri.geometry.polygon.Polygon makePolygon(Polygon polygon) { org.poly2tri.geometry.polygon.Polygon poly = makePolygon(polygon.getExteriorRing()); // Add holes for(int idHole = 0; idHole < polygon.getNumInteriorRing(); idHole++) { poly.addHole(makePolygon(polygon.getInteriorRingN(idHole))); } return poly; }
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 ); }
public static void triangulate( PolygonSet ps ) { TriangulationContext<?> tcx = createContext( _defaultAlgorithm ); for( Polygon p : ps.getPolygons() ) { tcx.prepareTriangulation( p ); triangulate( tcx ); tcx.clear(); } }
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 );
private org.poly2tri.geometry.polygon.Polygon makePolygon(Polygon polygon) { org.poly2tri.geometry.polygon.Polygon poly = makePolygon(polygon.getExteriorRing()); // Add holes for(int idHole = 0; idHole < polygon.getNumInteriorRing(); idHole++) { poly.addHole(makePolygon(polygon.getInteriorRingN(idHole))); } return poly; }
/** * 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 static Polygon convert(PolygonWithHolesList2d polygonWithHoles) { Polygon outer = convert(polygonWithHoles.getOuter()); if (polygonWithHoles.getInner() != null) { for (PolygonList2d inner : polygonWithHoles.getInner()) { outer.addHole(convert(inner)); } } return outer; }
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); }