Android Open Source - zmap Envelope






From Project

Back to project page zmap.

License

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.

Java Source Code

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;
}




Java Source Code List

com.zmap.MainActivity.java
com.zmap.geom.EmptyGeometryException.java
com.zmap.geom.Envelope.java
com.zmap.geom.GeometryUtil.java
com.zmap.geom.IEnvelope.java
com.zmap.geom.IGeomCollection.java
com.zmap.geom.IGeomObject.java
com.zmap.geom.ILineOperator.java
com.zmap.geom.IPointCollectionEdit.java
com.zmap.geom.IPointCollection.java
com.zmap.geom.IPoint.java
com.zmap.geom.IPolygon.java
com.zmap.geom.IPolyline.java
com.zmap.geom.IRingCollection.java
com.zmap.geom.IRing.java
com.zmap.geom.IVector.java
com.zmap.geom.InvalidGeometryException.java
com.zmap.geom.PointCollection.java
com.zmap.geom.Point.java
com.zmap.geom.Polyline.java
com.zmap.geom.Ring.java
com.zmap.geom.Vector.java