/** * Adds a <code>Rectangle2D</code> object to this * <code>Rectangle2D</code>. The resulting <code>Rectangle2D</code> * is the union of the two <code>Rectangle2D</code> objects. * @param r the <code>Rectangle2D</code> to add to this * <code>Rectangle2D</code>. * @since 1.2 */ public void add(ProjectionRect r) { double x1 = Math.min(getMinX(), r.getMinX()); double x2 = Math.max(getMaxX(), r.getMaxX()); double y1 = Math.min(getMinY(), r.getMinY()); double y2 = Math.max(getMaxY(), r.getMaxY()); setRect(x1, y1, x2 - x1, y2 - y1); }
/** * Adds a <code>Rectangle2D</code> object to this * <code>Rectangle2D</code>. The resulting <code>Rectangle2D</code> * is the union of the two <code>Rectangle2D</code> objects. * @param r the <code>Rectangle2D</code> to add to this * <code>Rectangle2D</code>. * @since 1.2 */ public void add(ProjectionRect r) { double x1 = Math.min(getMinX(), r.getMinX()); double x2 = Math.max(getMaxX(), r.getMaxX()); double y1 = Math.min(getMinY(), r.getMinY()); double y2 = Math.max(getMaxY(), r.getMaxY()); setRect(x1, y1, x2 - x1, y2 - y1); }
/** * Copy Constructor * * @param r rectangle to copy */ public ProjectionRect(ProjectionRect r) { this(r.getMinX(), r.getMinY(), r.getMaxX(), r.getMaxY()); }
/** * Copy Constructor * * @param r rectangle to copy */ public ProjectionRect(ProjectionRect r) { this(r.getMinX(), r.getMinY(), r.getMaxX(), r.getMaxY()); }
/** * Adds a point, specified by the double precision arguments * <code>newx</code> and <code>newy</code>, to this * <code>Rectangle2D</code>. The resulting <code>Rectangle2D</code> * is the smallest <code>Rectangle2D</code> that * contains both the original <code>Rectangle2D</code> and the * specified point. * <p> * After adding a point, a call to <code>contains</code> with the * added point as an argument does not necessarily return * <code>true</code>. The <code>contains</code> method does not * return <code>true</code> for points on the right or bottom * edges of a rectangle. Therefore, if the added point falls on * the left or bottom edge of the enlarged rectangle, * <code>contains</code> returns <code>false</code> for that point. * @param newx the X coordinate of the new point * @param newy the Y coordinate of the new point * @since 1.2 */ public void add(double newx, double newy) { double x1 = Math.min(getMinX(), newx); double x2 = Math.max(getMaxX(), newx); double y1 = Math.min(getMinY(), newy); double y2 = Math.max(getMaxY(), newy); setRect(x1, y1, x2 - x1, y2 - y1); }
/** * Intersects the pair of specified source <code>Rectangle2D</code> * objects and puts the result into the specified destination * <code>Rectangle2D</code> object. One of the source rectangles * can also be the destination to avoid creating a third Rectangle2D * object, but in this case the original points of this source * rectangle will be overwritten by this method. * @param src1 the first of a pair of <code>Rectangle2D</code> * objects to be intersected with each other * @param src2 the second of a pair of <code>Rectangle2D</code> * objects to be intersected with each other * @param dest the <code>Rectangle2D</code> that holds the * results of the intersection of <code>src1</code> and * <code>src2</code> * @since 1.2 */ public static void intersect(ProjectionRect src1, ProjectionRect src2, ProjectionRect dest) { double x1 = Math.max(src1.getMinX(), src2.getMinX()); double y1 = Math.max(src1.getMinY(), src2.getMinY()); double x2 = Math.min(src1.getMaxX(), src2.getMaxX()); double y2 = Math.min(src1.getMaxY(), src2.getMaxY()); dest.setRect(x1, y1, x2 - x1, y2 - y1); }
/** * Intersects the pair of specified source <code>Rectangle2D</code> * objects and puts the result into the specified destination * <code>Rectangle2D</code> object. One of the source rectangles * can also be the destination to avoid creating a third Rectangle2D * object, but in this case the original points of this source * rectangle will be overwritten by this method. * @param src1 the first of a pair of <code>Rectangle2D</code> * objects to be intersected with each other * @param src2 the second of a pair of <code>Rectangle2D</code> * objects to be intersected with each other * @param dest the <code>Rectangle2D</code> that holds the * results of the intersection of <code>src1</code> and * <code>src2</code> * @since 1.2 */ public static void intersect(ProjectionRect src1, ProjectionRect src2, ProjectionRect dest) { double x1 = Math.max(src1.getMinX(), src2.getMinX()); double y1 = Math.max(src1.getMinY(), src2.getMinY()); double x2 = Math.min(src1.getMaxX(), src2.getMaxX()); double y2 = Math.min(src1.getMaxY(), src2.getMaxY()); dest.setRect(x1, y1, x2 - x1, y2 - y1); }
public LatLonRect projToLatLonBB(ProjectionRect world) { double startLat = world.getMinY(); double startLon = world.getMinX(); double deltaLat = world.getHeight(); double deltaLon = world.getWidth(); LatLonPoint llpt = new LatLonPointImpl(startLat, startLon); return new LatLonRect(llpt, deltaLat, deltaLon); }
public LatLonRect projToLatLonBB(ProjectionRect world) { double startLat = world.getMinY(); double startLon = world.getMinX(); double deltaLat = world.getHeight(); double deltaLon = world.getWidth(); LatLonPoint llpt = new LatLonPointImpl(startLat, startLon); return new LatLonRect(llpt, deltaLat, deltaLon); }
public LatLonRect projToLatLonBB(ProjectionRect world) { double startLat = world.getMinY(); double startLon = world.getMinX(); double deltaLat = world.getHeight(); double deltaLon = world.getWidth(); LatLonPoint llpt = new LatLonPointImpl(startLat, startLon); return new LatLonRect(llpt, deltaLat, deltaLon); }
public LatLonRect projToLatLonBB(ProjectionRect world) { double startLat = world.getMinY(); double startLon = world.getMinX(); double deltaLat = world.getHeight(); double deltaLon = world.getWidth(); LatLonPoint llpt = new LatLonPointImpl(startLat, startLon); return new LatLonRect(llpt, deltaLat, deltaLon); }
CdmrFeatureProto.Rectangle.Builder encodeRectangle(ProjectionRect rect) { CdmrFeatureProto.Rectangle.Builder builder = CdmrFeatureProto.Rectangle.newBuilder(); // this(r.getMinX(), r.getMinY(), r.getMaxX(), r.getMaxY()); builder.setStartx(rect.getMinX()); builder.setStarty(rect.getMaxX()); builder.setIncx(rect.getWidth()); builder.setIncy(rect.getHeight()); return builder; }
@Test public void testGetWidth1() { // getX() should give the y value for the upper left corner double minX = projectionRect.getMinX(); double maxX = projectionRect.getMaxX(); double testWidth = maxX - minX; double width = projectionRect.getWidth(); assertEquals(testWidth, width, 0); }
/** * Returns {@code true} if this bounding box contains {@code point}. * * @param point a point in projection coordinates. * @return {@code true} if this bounding box contains {@code point}. */ public boolean contains(ProjectionPoint point) { return DoubleMath.fuzzyCompare(point.getX(), getMinX(), 1e-6) >= 0 && DoubleMath.fuzzyCompare(point.getX(), getMaxX(), 1e-6) <= 0 && DoubleMath.fuzzyCompare(point.getY(), getMinY(), 1e-6) >= 0 && DoubleMath.fuzzyCompare(point.getY(), getMaxY(), 1e-6) <= 0; }
@Test public void testGetX() { // getX() should give the x value for the upper left corner double getX = projectionRect.getX(); double getMinX = projectionRect.getMinX(); double getMaxX = projectionRect.getMaxX(); assertEquals(getX, getMinX, 0); assertNotEquals(getX, getMaxX); }
/** * Returns {@code true} if this bounding box contains {@code point}. * * @param point a point in projection coordinates. * @return {@code true} if this bounding box contains {@code point}. */ public boolean contains(ProjectionPoint point) { return DoubleMath.fuzzyCompare(point.getX(), getMinX(), 1e-6) >= 0 && DoubleMath.fuzzyCompare(point.getX(), getMaxX(), 1e-6) <= 0 && DoubleMath.fuzzyCompare(point.getY(), getMinY(), 1e-6) >= 0 && DoubleMath.fuzzyCompare(point.getY(), getMaxY(), 1e-6) <= 0; }
@Test public void testSetX() { double x = projectionRect.getX(); double x2 = x * x + 1d; projectionRect.setX(x2); assertEquals(x2, projectionRect.getX(),0); assertEquals(x2, projectionRect.getMinX(), 0); assertNotEquals(x, x2); }
@Test public void testGetLowerLeftPoint() { ProjectionPoint getllp = projectionRect.getLowerLeftPoint(); double llx = projectionRect.getMinX(); double lly = projectionRect.getMinY(); double urx = projectionRect.getMaxX(); double ury = projectionRect.getMaxY(); assertEquals(llx, getllp.getX(), 0); assertEquals(lly, getllp.getY(), 0); assertNotEquals(urx, getllp.getX()); assertNotEquals(ury, getllp.getY()); }
@Test public void testGetUpperRightPoint() { ProjectionPoint geturp = projectionRect.getUpperRightPoint(); double llx = projectionRect.getMinX(); double lly = projectionRect.getMinY(); double urx = projectionRect.getMaxX(); double ury = projectionRect.getMaxY(); assertEquals(urx, geturp.getX(), 0); assertEquals(ury, geturp.getY(), 0); assertNotEquals(llx, geturp.getX()); assertNotEquals(lly, geturp.getY()); }
@Test public void testContainsPoint() { // contains the center point? -> YES assert(projectionRect.contains(new ProjectionPointImpl(projectionRect.getCenterX(), projectionRect.getCenterY()))); // contains a point outside the rectangle? -> NO assert(!projectionRect.contains(new ProjectionPointImpl((projectionRect.getMinX() - projectionRect.getWidth()), (projectionRect.getMinY() - projectionRect.getHeight())))); assert(!projectionRect.contains(new ProjectionPointImpl((projectionRect.getMaxX() + projectionRect.getWidth()), (projectionRect.getMaxY() + projectionRect.getHeight())))); // contains a point on the rectangle border -> YES assert(projectionRect.contains(new ProjectionPointImpl(projectionRect.getMinPoint()))); }