Here you can find the source of smallestBoundingBox( java.awt.Point.Double[] points)
Parameter | Description |
---|---|
points | a parameter |
public static Rectangle2D smallestBoundingBox( java.awt.Point.Double[] points)
//package com.java2s; /**//from w w w . java 2 s .com * This file is part of VisiCut. * Copyright (C) 2011 - 2013 Thomas Oster <thomas.oster@rwth-aachen.de> * RWTH Aachen University - 52062 Aachen, Germany * * VisiCut is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * VisiCut 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with VisiCut. If not, see <http://www.gnu.org/licenses/>. **/ import java.awt.Rectangle; import java.awt.Shape; import java.awt.geom.AffineTransform; import java.awt.geom.PathIterator; import java.awt.geom.Rectangle2D; public class Main { /** * Returns the smalles BoundingBox, which contains a number of Poins * @param points * @return */ public static Rectangle2D smallestBoundingBox( java.awt.Point.Double[] points) { double minX = points[0].x; double minY = points[0].y; double maxX = points[0].x; double maxY = points[0].y; for (java.awt.Point.Double p : points) { if (p.x < minX) { minX = p.x; } if (p.y < minY) { minY = p.y; } if (p.x > maxX) { maxX = p.x; } if (p.y > maxY) { maxY = p.y; } } return new Rectangle.Double(minX, minY, maxX - minX, maxY - minY); } public static Rectangle2D smallestBoundingBox(Shape s, AffineTransform t) { double minX = 0; double maxX = 0; double minY = 0; double maxY = 0; PathIterator pi = s.getPathIterator(t, 1); double[] last = null; boolean first = true; while (!pi.isDone()) { double[] d = new double[8]; switch (pi.currentSegment(d)) { case PathIterator.SEG_LINETO: { if (last != null) { if (first) { minX = last[0]; maxX = last[0]; minY = last[1]; maxY = last[1]; first = false; } else { if (last[0] < minX) { minX = last[0]; } if (last[0] > maxX) { maxX = last[0]; } if (last[1] < minY) { minY = last[1]; } if (last[1] > maxY) { maxY = last[1]; } } } if (first) { minX = d[0]; maxX = d[0]; minY = d[1]; maxY = d[1]; first = false; } else { if (d[0] < minX) { minX = d[0]; } if (d[0] > maxX) { maxX = d[0]; } if (d[1] < minY) { minY = d[1]; } if (d[1] > maxY) { maxY = d[1]; } } break; } case PathIterator.SEG_MOVETO: { last = d; break; } } pi.next(); } return new Rectangle.Double(minX, minY, maxX - minX, maxY - minY); } }