class ParsePolygon implements Parcelable {

  public boolean containsPoint(ParseGeoPoint point) {
    double minX = coordinates.get(0).getLatitude();
    double maxX = coordinates.get(0).getLatitude();
    double minY = coordinates.get(0).getLongitude();
    double maxY = coordinates.get(0).getLongitude();

    for ( int i = 1; i < coordinates.size(); i += 1) {
        ParseGeoPoint geoPoint = coordinates.get(i);
        minX = Math.min(geoPoint.getLatitude(), minX);
        maxX = Math.max(geoPoint.getLatitude(), maxX);
        minY = Math.min(geoPoint.getLongitude(), minY);
        maxY = Math.max(geoPoint.getLongitude(), maxY);
    }

    boolean outside = point.getLatitude() < minX || point.getLatitude() > maxX || point.getLongitude() < minY || point.getLongitude() > maxY;
    if (outside) {
        return false;
    }

    boolean inside = false;
    for (int i = 0, j = coordinates.size() - 1 ; i < coordinates.size(); j = i++) {
      double startX = coordinates.get(i).getLatitude();
      double startY = coordinates.get(i).getLongitude();
      double endX = coordinates.get(j).getLatitude();
      double endY = coordinates.get(j).getLongitude();

      boolean intersect = (( startY > point.getLongitude() ) != ( endY > point.getLongitude() ) &&
          point.getLatitude() < ( endX - startX ) * ( point.getLongitude() - startY ) / ( endY - startY ) + startX);

        if (intersect) {
            inside = !inside;
        }
    }
    return inside;
  }

  public  ParsePolygon(List<ParseGeoPoint> coords);
  public  ParsePolygon(ParsePolygon polygon);
  protected  ParsePolygon(Parcel source);
    ParsePolygon(Parcel source, ParseParcelDecoder decoder);

}