/** * Returns the difference between the maximum and minimum x values. * *@return max x - min x, or 0 if this is a null <code>Envelope</code> */ public double getWidth() { if (isNull()) { return 0; } return maxx - minx; }
/** * Returns the difference between the maximum and minimum y values. * *@return max y - min y, or 0 if this is a null <code>Envelope</code> */ public double getHeight() { if (isNull()) { return 0; } return maxy - miny; }
/** * Check if the region defined by <code>other</code> * overlaps (intersects) the region of this <code>Envelope</code>. * *@param other the <code>Envelope</code> which this <code>Envelope</code> is * being checked for overlapping *@return <code>true</code> if the <code>Envelope</code>s overlap */ public boolean intersects(Envelope other) { if (isNull() || other.isNull()) { return false; } return !(other.minx > maxx || other.maxx < minx || other.miny > maxy || other.maxy < miny); } /**
/** * Check if the point <code>(x, y)</code> * overlaps (lies inside) the region of this <code>Envelope</code>. * *@param x the x-ordinate of the point *@param y the y-ordinate of the point *@return <code>true</code> if the point overlaps this <code>Envelope</code> */ public boolean intersects(double x, double y) { if (isNull()) return false; return ! (x > maxx || x < minx || y > maxy || y < miny); } /**
/** * Tests if the given point lies in or on the envelope. * *@param x the x-coordinate of the point which this <code>Envelope</code> is * being checked for containing *@param y the y-coordinate of the point which this <code>Envelope</code> is * being checked for containing *@return <code>true</code> if <code>(x, y)</code> lies in the interior or * on the boundary of this <code>Envelope</code>. */ public boolean covers(double x, double y) { if (isNull()) return false; return x >= minx && x <= maxx && y >= miny && y <= maxy; }
/** * Enlarges this <code>Envelope</code> so that it contains * the given point. * Has no effect if the point is already on or within the envelope. * *@param x the value to lower the minimum x to or to raise the maximum x to *@param y the value to lower the minimum y to or to raise the maximum y to */ public void expandToInclude(double x, double y) { if (isNull()) { minx = x; maxx = x; miny = y; maxy = y; } else { if (x < minx) { minx = x; } if (x > maxx) { maxx = x; } if (y < miny) { miny = y; } if (y > maxy) { maxy = y; } } }
/** * Inserts an item having the given bounds into the tree. */ public void insert(Envelope itemEnv, Object item) { if (itemEnv.isNull()) { return; } super.insert(itemEnv, item); }
/** * Expands this envelope by a given distance in all directions. * Both positive and negative distances are supported. * * @param deltaX the distance to expand the envelope along the the X axis * @param deltaY the distance to expand the envelope along the the Y axis */ public void expandBy(double deltaX, double deltaY) { if (isNull()) return; minx -= deltaX; maxx += deltaX; miny -= deltaY; maxy += deltaY; // check for envelope disappearing if (minx > maxx || miny > maxy) setToNull(); }
public static double diagonalSize(Envelope env) { if (env.isNull()) return 0.0; double width = env.getWidth(); double hgt = env.getHeight(); return Math.sqrt(width * width + hgt * hgt); } }
/** * Computes the intersection of two {@link Envelope}s. * * @param env the envelope to intersect with * @return a new Envelope representing the intersection of the envelopes (this will be * the null envelope if either argument is null, or they do not intersect */ public Envelope intersection(Envelope env) { if (isNull() || env.isNull() || ! intersects(env)) return new Envelope(); double intMinX = minx > env.minx ? minx : env.minx; double intMinY = miny > env.miny ? miny : env.miny; double intMaxX = maxx < env.maxx ? maxx : env.maxx; double intMaxY = maxy < env.maxy ? maxy : env.maxy; return new Envelope(intMinX, intMaxX, intMinY, intMaxY); }
/** * Gets the minimum extent of this envelope across both dimensions. * * @return the minimum extent of this envelope */ public double minExtent() { if (isNull()) return 0.0; double w = getWidth(); double h = getHeight(); if (w < h) return w; return h; }
/** * Gets the maximum extent of this envelope across both dimensions. * * @return the maximum extent of this envelope */ public double maxExtent() { if (isNull()) return 0.0; double w = getWidth(); double h = getHeight(); if (w > h) return w; return h; }
public boolean equals(Object other) { if (!(other instanceof Envelope)) { return false; } Envelope otherEnvelope = (Envelope) other; if (isNull()) { return otherEnvelope.isNull(); } return maxx == otherEnvelope.getMaxX() && maxy == otherEnvelope.getMaxY() && minx == otherEnvelope.getMinX() && miny == otherEnvelope.getMinY(); }
/** * Tests if the <code>Envelope other</code> * lies wholely inside this <code>Envelope</code> (inclusive of the boundary). * *@param other the <code>Envelope</code> to check *@return true if this <code>Envelope</code> covers the <code>other</code> */ public boolean covers(Envelope other) { if (isNull() || other.isNull()) { return false; } return other.getMinX() >= minx && other.getMaxX() <= maxx && other.getMinY() >= miny && other.getMaxY() <= maxy; }
/** * Computes the coordinate of the centre of this envelope (as long as it is non-null * * @return the centre coordinate of this envelope * <code>null</code> if the envelope is null */ public Coordinate centre() { if (isNull()) return null; return new Coordinate( (getMinX() + getMaxX()) / 2.0, (getMinY() + getMaxY()) / 2.0); }
/** * Translates this envelope by given amounts in the X and Y direction. * * @param transX the amount to translate along the X axis * @param transY the amount to translate along the Y axis */ public void translate(double transX, double transY) { if (isNull()) { return; } init(getMinX() + transX, getMaxX() + transX, getMinY() + transY, getMaxY() + transY); }
if (envelope.isNull()) { return createPoint((CoordinateSequence)null);
private Float32Bounds(Envelope doublePrecisionEnv) { if ((doublePrecisionEnv == null) || (doublePrecisionEnv.isNull())) { return; //done! } set(doublePrecisionEnv); }
public static double diagonalSize(Envelope env) { if (env.isNull()) return 0.0; double width = env.getWidth(); double hgt = env.getHeight(); return Math.sqrt(width * width + hgt * hgt); } }