package ij.process;
import java.awt.Rectangle;
import java.awt.Polygon;
import java.awt.geom.Rectangle2D;
/** Used by the Roi classes to return float coordinate arrays and to
determine if a point is inside or outside of spline fitted selections. */
public class FloatPolygon {
private Rectangle bounds;
private float minX, minY, maxX, maxY;
/** The number of points. */
public int npoints;
/* The array of x coordinates. */
public float xpoints[];
/* The array of y coordinates. */
public float ypoints[];
/** Constructs an empty FloatPolygon. */
public FloatPolygon() {
npoints = 0;
xpoints = new float[10];
ypoints = new float[10];
}
/** Constructs a FloatPolygon from x and y arrays. */
public FloatPolygon(float xpoints[], float ypoints[]) {
if (xpoints.length!=ypoints.length)
throw new IllegalArgumentException("xpoints.length!=ypoints.length");
this.npoints = xpoints.length;
this.xpoints = xpoints;
this.ypoints = ypoints;
}
/** Constructs a FloatPolygon from x and y arrays. */
public FloatPolygon(float xpoints[], float ypoints[], int npoints) {
this.npoints = npoints;
this.xpoints = xpoints;
this.ypoints = ypoints;
}
/* Constructs a FloatPolygon from a Polygon.
public FloatPolygon(Polygon polygon) {
npoints = polygon.npoints;
xpoints = new float[npoints];
ypoints = new float[npoints];
for (int i=0; iy)!=(ypoints[j]>y)) &&
(x<(xpoints[j]-xpoints[i])*(y-ypoints[i])/(ypoints[j]-ypoints[i])+xpoints[i]))
inside = !inside;
}
return inside;
}
public Rectangle getBounds() {
if (npoints==0)
return new Rectangle();
if (bounds==null)
calculateBounds(xpoints, ypoints, npoints);
return bounds.getBounds();
}
public Rectangle2D.Double getFloatBounds() {
if (npoints==0)
return new Rectangle2D.Double();
if (bounds==null)
calculateBounds(xpoints, ypoints, npoints);
return new Rectangle2D.Double(minX, minY, maxX-minX, maxY-minY);
}
void calculateBounds(float[] xpoints, float[] ypoints, int npoints) {
minX = Float.MAX_VALUE;
minY = Float.MAX_VALUE;
maxX = Float.MIN_VALUE;
maxY = Float.MIN_VALUE;
for (int i=0; i
Ads help maintain this website.