Back to project page zmap.
The source code is released under:
GNU Lesser General Public License
If you think the Android project zmap listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.zmap.geom; // ww w . j a v a2 s . c om public class Envelope implements IEnvelope { public Envelope() { minX = Double.NaN; maxX = Double.NaN; minY = Double.NaN; maxY = Double.NaN; } public Envelope(double minX, double minY, double maxX, double maxY) { set(minX, minY, maxX, maxY); } public Envelope(IEnvelope envelope) { this(envelope.getMinX(), envelope.getMinY(), envelope.getMaxX(), envelope.getMaxY()); } @Override public double getMinX() { return minX; } @Override public double getMinY() { return minY; } @Override public double getMaxX() { return maxX; } @Override public double getMaxY() { return maxY; } @Override public void set(double minX, double minY, double maxX, double maxY) { this.minX = Math.min(minX, maxX); this.minY = Math.min(minY, maxY); this.maxX = Math.max(minX, maxX); this.maxY = Math.max(minY, maxY); } @Override public boolean isEmpty() { return Double.isNaN(minX) && Double.isNaN(minY) && Double.isNaN(maxX) && Double.isNaN(maxY); } @Override public boolean isContains(IPoint point) { if(point == null){ throw new NullPointerException(); } if(point.isEmpty()){ throw new IllegalArgumentException(); } double px = point.getX(); double py = point.getY(); return minX <= px && maxX >= px && minY <= py && maxY >= py; } @Override public boolean isContains(IEnvelope envelope) { if(envelope == null){ throw new NullPointerException(); } if(envelope.isEmpty()){ throw new IllegalArgumentException(); } return minX <= envelope.getMinX() && maxX >= envelope.getMaxX() && minY <= envelope.getMinY() && maxY >= envelope.getMaxY(); } @Override public boolean isIntersect(IEnvelope envelope) { if(envelope == null){ throw new NullPointerException(); } if(envelope.isEmpty()){ throw new IllegalArgumentException(); } return minX <= envelope.getMaxX() && maxX >= envelope.getMinX() && minY <= envelope.getMaxY() && maxY >= envelope.getMinY(); } @Override public IEnvelope union(IEnvelope envelope) { if(envelope == null){ throw new NullPointerException(); } if(envelope.isEmpty()){ throw new IllegalArgumentException(); } double maxX = Math.max(this.maxX, envelope.getMaxX()); double minX = Math.min(this.minX, envelope.getMinX()); double maxY = Math.max(this.maxY, envelope.getMaxY()); double minY = Math.min(this.minY, envelope.getMinY()); return new Envelope(minX, minY, maxX, maxY); } @Override public IEnvelope intersect(IEnvelope envelope) { if(envelope == null){ throw new NullPointerException(); } if(envelope.isEmpty()){ throw new IllegalArgumentException(); } if(!isIntersect(envelope)){ // return empty envelope. return new Envelope(); } double maxX = Math.min(this.maxX, envelope.getMaxX()); double minX = Math.max(this.minX, envelope.getMinX()); double maxY = Math.min(this.maxY, envelope.getMaxY()); double minY = Math.max(this.minY, envelope.getMinY()); return new Envelope(minX, minY, maxX, maxY); } @Override public IEnvelope union(IPoint point) { double x = point.getX(); double y = point.getY(); double minX = Math.min(this.minX, x); double minY = Math.min(this.minY, y); double maxX = Math.max(this.maxX, x); double maxY = Math.max(this.maxY, y); return new Envelope(minX, minY, maxX, maxY); } @Override public void unionWith(IEnvelope envelope) { double minX = Math.min(getMinX(), envelope.getMinX()); double minY = Math.min(getMinY(), envelope.getMinY()); double maxX = Math.max(getMaxX(), envelope.getMaxX()); double maxY = Math.max(getMaxY(), envelope.getMaxY()); set(minX, minY, maxX, maxY); } @Override public void unionWith(IPoint point) { double x = point.getX(); double y = point.getY(); double minX = Math.min(this.minX, x); double minY = Math.min(this.minY, y); double maxX = Math.max(this.maxX, x); double maxY = Math.max(this.maxY, y); set(minX, minY, maxX, maxY); } private double minX, minY, maxX, maxY; }