class Voronoi{ int NUMPOINTS; int order; ArrayList initialPoints; ArrayList initialSegments; ArrayList bisectors; ArrayList borders; ArrayList bisectorIntersections; ArrayList cells; color fillColor; color strokeColor; Voronoi(final int n, final ArrayList borders, final int o, final color fc,final color sc){ order=o; NUMPOINTS=n; initializeLists(); this.borders.addAll(borders); generateInitialPoints(); generateInitialSegments(); generateBisectors(); generateBisectorIntersections(); generateVoronoiSegments(); fillColor=fc; strokeColor=sc; } Voronoi(final int n, final ArrayList borders, final ArrayList points, final int o, final color fc,final color sc){ order=o; NUMPOINTS=n; initializeLists(); this.borders.addAll(borders); this.initialPoints.addAll(points); generateInitialSegments(); generateBisectors(); generateBisectorIntersections(); generateVoronoiSegments(); fillColor=fc; strokeColor=sc; } Segment2D extendToBorder(final Segment2D segment, final ArrayList borders){ Point2D startPoint = null ; Iterator itr = borders.iterator(); int border=-1; Segment2D currentBorder=new Segment2D(); while ((itr.hasNext( ))&&(startPoint == null)){ currentBorder=(Segment2D)itr.next(); startPoint = segmentIntersectionWithLine(currentBorder,segment); border++; } if(startPoint != null){ startPoint.onBorder=border; currentBorder.add(startPoint); } Point2D endPoint = null ; while ((itr.hasNext( ))&&(endPoint == null)){ currentBorder=(Segment2D)itr.next(); endPoint = segmentIntersectionWithLine(currentBorder,segment); border++; } if(endPoint != null){ endPoint.onBorder=border; currentBorder.add(endPoint); } if((startPoint != null)&&(endPoint != null)) return new Segment2D(startPoint,endPoint); return new Segment2D(segment); } void initializeLists(){ initialPoints = new ArrayList(); initialSegments = new ArrayList(); bisectors = new ArrayList(); borders = new ArrayList(); bisectorIntersections = new ArrayList(); cells = new ArrayList(); } void generateInitialPoints(){ float minx,maxx,miny,maxy; minx=miny=20000000; maxx=maxy=-1; Iterator borderItr = borders.iterator(); while(borderItr.hasNext()){ Segment2D currentBorder =(Segment2D) borderItr.next(); minx=min(minx,currentBorder.start.x); minx=min(minx,currentBorder.end.x); miny=min(miny,currentBorder.start.y); miny=min(miny,currentBorder.end.y); maxx=max(maxx,currentBorder.start.x); maxx=max(maxx,currentBorder.end.x); maxy=max(maxy,currentBorder.start.y); maxy=max(maxy,currentBorder.end.y); } for(int i=0;i0.01f)){ intersect = true; break; } } if(!intersect){ Point2D peripheryPoint = new Point2D(currentSweepPoint); periphery.add(peripheryPoint); } } } segmentItr = borders.iterator(); while(segmentItr.hasNext()){ Segment2D currentSegment = (Segment2D)segmentItr.next(); Iterator sweepPointItr = currentSegment.points.iterator(); while(sweepPointItr.hasNext()){ Point2D currentSweepPoint = (Point2D)sweepPointItr.next(); Segment2D currentSweepRay = new Segment2D(currentCenterPoint,currentSweepPoint); Iterator sweepSegmentItr = currentCenterPoint.belongsToSegment.iterator(); boolean intersect = false; while(sweepSegmentItr.hasNext()){ Segment2D currentSweepSegment =(Segment2D)sweepSegmentItr.next(); Segment2D currentSweepBisector=currentSweepSegment.bisector; Point2D sweepIntersection = segmentIntersectionWithSegment(currentSweepRay, currentSweepBisector); if ((sweepIntersection!=null)&&(dist(sweepIntersection,currentSweepPoint)>0.01f)){ intersect = true; break; } } if(!intersect){ Point2D peripheryPoint = new Point2D(currentSweepPoint); periphery.add(peripheryPoint); } } } Cell cell = new Cell(currentCenterPoint.convertToPoint2D()); cell.periphery.addAll(periphery); cell.update(); cells.add(cell); } } }