text:
/**
 * Great Circle
 *
 * Code is pretty rough; I got it working for creating circles returning JSONArray
 *
 * Still could use some refinement.
 *
 */
package org.jennings.geomtools;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Random;
import org.json.JSONArray;
import org.json.JSONObject;

/**
 *
 * @author jenningd
 */
public class GreatCircle {

    private final double D2R = Math.PI / 180.0;
    private final double R2D = 180.0 / Math.PI;

    private final static DecimalFormat df8 = new DecimalFormat("###0.00000000");
    private final static DecimalFormat df5 = new DecimalFormat("###0.00000");
    private final static DecimalFormat df3 = new DecimalFormat("###0.000");

    final boolean debug = false;

    public DistanceBearing getDistanceBearing(GeographicCoordinate coord1, GeographicCoordinate coord2) {

        double lon1 = coord1.getLon();
        double lat1 = coord1.getLat();

        double lon2 = coord2.getLon();
        double lat2 = coord2.getLat();
        return getDistanceBearing(lon1, lat1, lon2, lat2);
    }

    /**
     *
     * @param coord1 First Coordinate
     * @param coord2 Second Coordinate
     * @return Distance (km) and Bearing (-180 to 180 from North)
     */
    public DistanceBearing getDistanceBearing(double lon1, double lat1, double lon2, double lat2) {

        DistanceBearing distB = new DistanceBearing();

        double gcDist = 0.0;
        double bearing = 0.0;

        try {

            double lon1R = lon1 * D2R;
            double lat1R = lat1 * D2R;
            double lon2R = lon2 * D2R;
            double lat2R = lat2 * D2R;

            /*
            Functions are a little whacky around the north and south pole.
            The only valid bearing from north pole is -180.
            I wouldn't trust the program for points near the poles.
             */
            if (Math.abs(lat1 - 90.0) < 0.00001) {
                // very close to north pole distance R * theta
                double l = 90.0 - lat2;
                gcDist = Earth.Radius * l * D2R / 1000.0;
                // let bearing in lon2
                bearing = lon2;
            } else if (Math.abs(lat1 + 90) < 0.00001) {
                // very close to south pole distance R * theta
                double l = lat2 + 90.0;
                gcDist = Earth.Radius * l * D2R / 1000.0;
                bearing = lon2;

            } else {

                // law of Cosines
                double lambda = Math.abs(lon2R - lon1R);

                double x1 = Math.cos(lat2R) * Math.sin(lambda);

                double x2 = Math.cos(lat1R) * Math.sin(lat2R)
                        - Math.sin(lat1R) * Math.cos(lat2R) * Math.cos(lambda);

                double x3 = Math.sin(lat1R) * Math.sin(lat2R)
                        + Math.cos(lat1R) * Math.cos(lat2R) * Math.cos(lambda);

                double x4 = Math.sqrt(x1 * x1 + x2 * x2);

                double sigma = Math.atan2(x4, x3);

                gcDist = sigma * Earth.Radius / 1000.0;

                double y1 = Math.sin(lon2R - lon1R) * Math.cos(lat2R);

                double y2 = Math.cos(lat1R) * Math.sin(lat2R)
                        - Math.sin(lat1R) * Math.cos(lat2R) * Math.cos(lon2R - lon1R);

                double y3 = Math.atan2(y1, y2);

                bearing = (y3 * R2D) % 360;

                // Convert to value from -180 to 180
                bearing = bearing > 180.0 ? bearing - 360.0 : bearing;

            }
        } catch (Exception e) {
            gcDist = -1;
            bearing = 0;
        }

        distB = new DistanceBearing(gcDist, bearing);

        return distB;
    }

    public GeographicCoordinate getNewCoordPair(double lon1, double lat1, double distance, double bearing) {
        DistanceBearing distB = new DistanceBearing(distance, bearing);
        GeographicCoordinate coord1 = new GeographicCoordinate(lon1, lat1);
        return getNewCoordPair(coord1, distB);
    }

    public GeographicCoordinate getNewCoordPair(GeographicCoordinate coord1, DistanceBearing distB) {

        double lat1 = coord1.getLat();
        double lon1 = coord1.getLon();
        double lat2 = 0.0;
        double lon2 = 0.0;

        boolean bln360 = false;

        try {

            // Allow for lon values 180 to 360 (adjust them to -180 to 0)
            double lonDD = lon1;
            if (lonDD > 180.0 && lonDD <= 360) {
                lonDD = lonDD - 360;
                lon1 = lonDD;
                bln360 = true;
            }

            double alpha;
            double l;
            double k;
            double gamma;
            double phi;
            double theta;
            double hdng2;

            double hdng = distB.getBearing();

            if (hdng < 0) {
                hdng = hdng + 360;
            }

            // Round the input
            BigDecimal bd = new BigDecimal(hdng);
            bd = bd.setScale(6, BigDecimal.ROUND_HALF_UP);
            hdng = bd.doubleValue();

            double dist = distB.getDistance() * 1000;

            if (lat1 == 90 || lat1 == -90) {
                // hdng doesn't make a lot of since at the poles assume this is just the lon
                lon2 = hdng;
                alpha = dist / Earth.Radius;
                if (lat1 == 90) {
                    lat2 = 90 - alpha * R2D;
                } else {
                    lat2 = -90 + alpha * R2D;
                }

            } else if (hdng == 0 || hdng == 360) {
                // going due north within some rounded number
                alpha = dist / Earth.Radius;
                lat2 = lat1 + alpha * R2D;
                lon2 = lon1;
            } else if (hdng == 180) {
                // going due south witin some rounded number
                alpha = dist / Earth.Radius;
                lat2 = lat1 - alpha * R2D;
                lon2 = lon1;
            } else if (hdng == 90) {
                lat2 = lat1;
                l = 90 - lat1;
                alpha = dist / Earth.Radius / Math.sin(l * D2R);
                //phi = Math.asin(Math.sin(alpha)/ Math.sin(l*D2R));
                lon2 = lon1 + alpha * R2D;
            } else if (hdng == 270) {
                lat2 = lat1;
                l = 90 - lat1;
                alpha = dist / Earth.Radius / Math.sin(l * D2R);
                //phi = Math.asin(Math.sin(alpha)/ Math.sin(l*D2R));
                lon2 = lon1 - alpha * R2D;
            } else if (hdng > 0 && hdng < 180) {
                l = 90 - lat1;
                alpha = dist / Earth.Radius;
                k = Math.acos(Math.cos(alpha) * Math.cos(l * D2R)
                        + Math.sin(alpha) * Math.sin(l * D2R) * Math.cos(hdng * D2R));
                lat2 = 90 - k * R2D;
                double n = (Math.cos(alpha) - Math.cos(k) * Math.cos(l * D2R))
                        / (Math.sin(k) * Math.sin(l * D2R));
                if (n > 1) {
                    n = 1;
                }
                if (n < -1) {
                    n = -1;
                }
                phi = Math.acos(n);
                lon2 = lon1 + phi * R2D;
                theta = Math.sin(phi) * Math.sin(l * D2R) / Math.sin(alpha);
                hdng2 = 180 - theta * R2D;
            } else if (hdng > 180 && hdng < 360) {
                gamma = 360 - hdng;
                l = 90 - lat1;
                alpha = dist / Earth.Radius;
                k = Math.acos(Math.cos(alpha) * Math.cos(l * D2R)
                        + Math.sin(alpha) * Math.sin(l * D2R) * Math.cos(gamma * D2R));
                lat2 = 90 - k * R2D;
                double n = (Math.cos(alpha) - Math.cos(k) * Math.cos(l * D2R))
                        / (Math.sin(k) * Math.sin(l * D2R));
                if (n > 1) {
                    n = 1;
                }
                if (n < -1) {
                    n = -1;
                }
                phi = Math.acos(n);
                lon2 = lon1 - phi * R2D;
                theta = Math.sin(phi) * Math.sin(l * D2R) / Math.sin(alpha);
                hdng2 = 180 - theta * R2D;
            }

            int decimalPlaces = 12;
            bd = new BigDecimal(lat2);
            bd = bd.setScale(decimalPlaces, BigDecimal.ROUND_HALF_UP);
            lat2 = bd.doubleValue();

            bd = new BigDecimal(lon2);
            bd = bd.setScale(decimalPlaces, BigDecimal.ROUND_HALF_UP);
            lon2 = bd.doubleValue();

            if (lat2 > 90) {
                lat2 = 180 - lat2;
                lon2 = (lon2 + 180) % 360;
            }

            if (lon2 > 180) {
                lon2 = lon2 - 360;
            }

            if (lat2 < -90) {
                lat2 = -180 - lat2;
                lon2 = (lon2 - 180) % 360;
            }
            if (lon2 < -180) {
                lon2 = lon2 + 360;
            }

            // adjust the lon back to 360 scale if input was like that
            if (bln360) {
                if (lon2 < 0) {
                    lon2 = lon2 + 360;
                }
            }

        } catch (Exception e) {
            lon2 = -1000;
            lat2 = -1000;
        }

        if (lon2 < -180.0) {
            System.out.println(lon2);
            System.out.println(distB.getBearing());

        }

        GeographicCoordinate nc = new GeographicCoordinate(lon2, lat2);

        return nc;
    }

    public double findCrossing(double x1, double y1, double x2, double y2, double x) {
        double m = (y2 - y1) / (x2 - x1);

        return m * (x - x1) + y1;
    }

//    /**
//     * Generates coordinates for a circle around a Geographic Center
//     *
//     * @param center
//     * @param radiusKM
//     * @param numPoints
//     * @return
//     */
//    public GeographicCoordinate[] createCircle(GeographicCoordinate center, Double radiusKM, Integer numPoints, boolean isClockwise) {
//
//        GeographicCoordinate[] coords = new GeographicCoordinate[numPoints];
//
//        try {
//            if (numPoints == null) {
//                // if null default to 20 points
//                numPoints = 20;
//            }
//
//            if (radiusKM == null) {
//                // default to 50 meters or 0.050 km
//                radiusKM = 0.050;
//            }
//
//            double d = 360.0 / (numPoints - 1);
//            int i = 0;
//            GeographicCoordinate nc1 = new GeographicCoordinate();
//            while (i < numPoints - 1) {
//                double theta = 0.0;
//                if (isClockwise) {
//                    theta = i * d - 180.0;
//                } else {
//                    theta = 180.0 - i * d;
//                }
//
//                DistanceBearing distb = new DistanceBearing(radiusKM, theta);
//
//                GeographicCoordinate nc = getNewCoordPair(center, distb);
//
//                coords[i] = nc;
//
//                i++;
//                if (i == 1) {
//                    nc1 = nc;
//                }
//            }
//
//            // last point same as first
//            coords[i] = nc1;
//
//        } catch (Exception e) {
//            coords = null;
//        }
//
//        return coords;
//    }
    /**
     * Return geometry object rings for Esri or coordinates for GeoJSON
     *
     * @param clon
     * @param clat
     * @param a
     * @param b
     * @param rotationDeg
     * @param radius
     * @param isClockwise
     * @param numPoints
     * @param isEsri
     * @return
     */
    public JSONArray createEllipse3(double clon, double clat, Double a, Double b, Double rotationDeg, Integer numPoints, boolean isClockwise) {

        if (numPoints == null) {
            numPoints = 20;
        }

        if (a == null) {
            // default to 500 meters or 0.50 km
            a = 0.50;
        }

        if (b == null) {
            // default to 50 meters or 0.050 km
            b = 0.050;
        }

        if (rotationDeg == null) {
            rotationDeg = 0.0;
        }

        if (a < b) {
            // Switch a and b
            // Semimajor axis should be the larger of the two
            double t = a;
            a = b;
            b = t;
        }

        double c = Math.sqrt(a*a-b*b);

        // If this was a circle then even distribuation would be d
        double d = 360.0 / (numPoints - 1);

        // The number of points returns will depend on eccentricity
        ArrayList<GeographicCoordinate> coords = new ArrayList<>();

        int i = 0;
        double v = 360.0;
        GeographicCoordinate coord1 = new GeographicCoordinate(clon, clat);

        GeographicCoordinate lastcoord = coord1;

        while (v > 0.0) {

            double r = v * D2R;
            double sv = Math.sin(r);
            double cv = Math.cos(r);
            double radiusKM = a * b / Math.sqrt(a * a * sv * sv + b * b * cv * cv);
            DistanceBearing distb = new DistanceBearing(radiusKM, v);

            if (rotationDeg != 0.0) {
                double bearing = (distb.getBearing() + rotationDeg) % 360.0;
                distb.setBearing(bearing);
            }

            GeographicCoordinate nc = getNewCoordPair(coord1, distb);

            // Only add the nc if it is different from previous
            double lon = nc.getLon();
            double lat = nc.getLat();

            if (Math.abs(lon - lastcoord.getLon()) < 0.00001 && Math.abs(lat - lastcoord.getLat()) < 0.00001) {
                // skip this point too close to previous
            } else {
                coords.add(nc);
                lastcoord = nc;
            }

            // Scale d based on distance
//            double scale = ((a / b - b / a) / (b - a)) * (distb.getDistance() - a) + b / a;
//            if (scale > 1.0) {
//                scale = 1.0;
//            }
//            double scale = 1.0;
//            if (distb.getDistance() > c) {
//                scale = 1/10;
//            }

//            if (debug) {
//                System.out.println(scale + "," + distb.getDistance() + "," + distb.getBearing() + "," + v + "," + nc.getLon() + "," + nc.getLat());
//            }
            // Densifying the points around 0/360 and 180; just 10 degrees out really improved the polygons
            if (v > 350 || v < 10 || (v > 170 && v < 190)) {
                v = v - d*b/a;
            } else {
                v = v - d;
            }

        }

        // Added code to prevent adding a last point that was too close to the end point.
        GeographicCoordinate firstPoint = coords.get(0);
        GeographicCoordinate lastPoint = coords.get(coords.size() - 1);

        if (Math.abs(firstPoint.getLon() - lastPoint.getLon()) < 0.00001 && Math.abs(firstPoint.getLat() - lastPoint.getLat()) < 0.00001) {
            // Replace last point with first
            coords.set(coords.size() - 1, firstPoint);
        } else {
            // Append firstpoint
            coords.add(firstPoint);

        }

        //coords.add(coords.get(0)); // Last point same as first

//        for (GeographicCoordinate tt: coords) {
//            System.out.println(tt.getLon() + "," + tt.getLat());
//        }
        GeographicCoordinate nc1 = new GeographicCoordinate();
        GeographicCoordinate nc2 = new GeographicCoordinate();

        JSONArray[] exteriorRing = new JSONArray[4];
        exteriorRing[0] = new JSONArray();
        exteriorRing[1] = new JSONArray();

        int ringNum = 0;
        int numRings = 1;

        nc1 = coords.get(0);
        i = 0;
        double lon1 = nc1.getLon();
        double lat1 = nc1.getLat();
        if (debug) {
            System.out.println(i + ":" + lon1 + "," + lat1);
        }
        JSONArray coord = new JSONArray("[" + lon1 + ", " + lat1 + "]");
        exteriorRing[ringNum].put(coord);
        i++;

        boolean crossedDTEast = false;
        boolean crossedDTWest = false;
        boolean crossedZeroEast = false;
        boolean crossedZeroWest = false;

        while (i < coords.size()) {

            nc2 = coords.get(i);
            // Compare coordinates
            double lon2 = nc2.getLon();
            double lat2 = nc2.getLat();

            if (lon2 >= 0.0 && lon1 <= 0.0) {

                if (Math.abs(lon2 - lon1) > 180.0) {
                    // Either gone from -179.xx to 179.xx (Crossing DT heading east)
                    if (debug) {
                        System.out.println("Crossing DT heading west");
                    }
                    crossedDTWest = true;

                    double x1 = (lon1 < 0) ? lon1 + 360.0 : lon1;
                    double x2 = (lon2 < 0) ? lon2 + 360.0 : lon2;
                    double crossing = findCrossing(x1, lat1, x2, lat2, 180.0);
                    if (debug) {
                        System.out.println(crossing);
                    }

                    // Add point to current ring
                    coord = new JSONArray("[-180.0, " + crossing + "]");
                    exteriorRing[ringNum].put(coord);

                    if (crossedZeroWest) {
                        // South Pole in Footprint
                        coord = new JSONArray("[-180.0, -90.0]");
                        exteriorRing[ringNum].put(coord);
                        coord = new JSONArray("[0.0, -90.0]");
                        exteriorRing[ringNum].put(coord);
                    }

                    // Swith to other ring
                    if (ringNum == 0) {
                        ringNum = 1;
                    } else if (ringNum == 1) {
                        ringNum = 0;
                    }

                    if (crossedZeroWest) {
                        // South Pole in Footprint
                        coord = new JSONArray("[0.0, -90.0]");
                        exteriorRing[ringNum].put(coord);
                        coord = new JSONArray("[180, -90.0]");
                        exteriorRing[ringNum].put(coord);
                    }

                    // Add point to other ring
                    coord = new JSONArray("[180.0, " + crossing + "]");
                    exteriorRing[ringNum].put(coord);

                } else {
                    // or gone from -1.xx to 1.xx  (Crossing 0 heading east)
                    if (debug) {
                        System.out.println("Crossing 0 heading east");
                    }

                    double x1 = lon1;
                    double x2 = lon2;
                    double crossing = findCrossing(x1, lat1, x2, lat2, 0.0);
                    if (debug) {
                        System.out.println(crossing);
                    }

                    // Add point to current ring
                    if (lon2 > 0.0) {
                        coord = new JSONArray("[0.0, " + crossing + "]");
                        exteriorRing[ringNum].put(coord);
                    }

                    if (crossedDTEast) {
                        // North Pole is in footprint add 180,90 and 0, 90
                        coord = new JSONArray("[0.0,90.0]");
                        exteriorRing[ringNum].put(coord);
                        coord = new JSONArray("[-180.0,90.0]");
                        exteriorRing[ringNum].put(coord);
                    }

                    // Swith to other ring
                    if (ringNum == 0) {
                        ringNum = 1;
                    } else if (ringNum == 1) {
                        ringNum = 0;
                    }

                    if (crossedDTEast) {
                        // North pole is in foot print add point 0,90, -180,90
                        coord = new JSONArray("[180.0,90.0]");
                        exteriorRing[ringNum].put(coord);
                        coord = new JSONArray("[0.0,90.0]");
                        exteriorRing[ringNum].put(coord);

                    }

                    // Add point to other ring
                    if (lon2 > 0.0) {
                        coord = new JSONArray("[0.0, " + crossing + "]");
                        exteriorRing[ringNum].put(coord);
                    }

                    crossedZeroEast = true;
                }

            } else if (lon2 < 0.0 && lon1 > 0.0) {

                if (Math.abs(lon2 - lon1) > 180.0) {
                    // Either gone from 179.xx to -179.xx (Crossing DT heading west)
                    if (debug) {
                        System.out.println("Crossing DT heading east");
                    }
                    crossedDTEast = true;

                    double x1 = (lon1 < 0) ? lon1 + 360.0 : lon1;
                    double x2 = (lon2 < 0) ? lon2 + 360.0 : lon2;
                    double crossing = findCrossing(x1, lat1, x2, lat2, 180.0);
                    if (debug) {
                        System.out.println(crossing);
                    }

                    coord = new JSONArray("[180.0, " + crossing + "]");
                    exteriorRing[ringNum].put(coord);

                    if (crossedZeroEast) {
                        // North Pole in Footprint
                        coord = new JSONArray("[180.0, 90.0]");
                        exteriorRing[ringNum].put(coord);
                        coord = new JSONArray("[0.0, 90.0]");
                        exteriorRing[ringNum].put(coord);
                    }

                    // Swith to other ring
                    if (ringNum == 0) {
                        ringNum = 1;
                    } else if (ringNum == 1) {
                        ringNum = 0;
                    }

                    if (crossedZeroEast) {
                        // North Pole in Footprint
                        coord = new JSONArray("[0.0, 90.0]");
                        exteriorRing[ringNum].put(coord);
                        coord = new JSONArray("[-180, 90.0]");
                        exteriorRing[ringNum].put(coord);
                    }

                    coord = new JSONArray("[-180.0, " + crossing + "]");
                    exteriorRing[ringNum].put(coord);

                } else {
                    if (debug) {
                        System.out.println("Crossing 0 heading west");
                    }
                    crossedZeroWest = true;

                    // or gone from 1.xx to -1.xx (Crossing 0 heading west
                    double x1 = lon1;
                    double x2 = lon2;
                    double crossing = findCrossing(x1, lat1, x2, lat2, 0.0);
                    if (debug) {
                        System.out.println(crossing);
                    }

                    // Add point to current ring
                    coord = new JSONArray("[0.0, " + crossing + "]");
                    exteriorRing[ringNum].put(coord);

                    if (crossedDTWest) {
                        // South Pole is in footprint
                        coord = new JSONArray("[0.0,-90.0]");
                        exteriorRing[ringNum].put(coord);
                        coord = new JSONArray("[180.0,-90.0]");
                        exteriorRing[ringNum].put(coord);
                    }

                    // Swith to other ring
                    if (ringNum == 0) {
                        ringNum = 1;
                    } else if (ringNum == 1) {
                        ringNum = 0;
                    }

                    if (crossedDTWest) {
                        // North pole is in foot print add point 0,90, -180,90
                        coord = new JSONArray("[-180.0,-90.0]");
                        exteriorRing[ringNum].put(coord);
                        coord = new JSONArray("[0.0,-90.0]");
                        exteriorRing[ringNum].put(coord);

                    }

                    // Add point to other ring
                    coord = new JSONArray("[0.0, " + crossing + "]");
                    exteriorRing[ringNum].put(coord);
                }
            }

            if (debug) {
                System.out.println(i + ":" + lon2 + "," + lat2);
            }

            if (i < coords.size() - 1) {
                // Inject last coord
                coord = new JSONArray("[" + lon2 + ", " + lat2 + "]");
                exteriorRing[ringNum].put(coord);
            }

            nc1 = nc2;
            lon1 = nc1.getLon();
            lat1 = nc1.getLat();
            i++;

        }

        JSONArray polys = new JSONArray();
        JSONArray poly = new JSONArray();

        double plon = clon;
        double plat = clat;

        for (i = 0; i < 2; i++) {
            poly = new JSONArray();
            if (exteriorRing[i].length() > 0) {
                // Add last point same as first
                exteriorRing[i].put(exteriorRing[i].get(0));

                // This code checks for points that are too close in final exterior Rings
//                int k = 0;
//                while (k < exteriorRing[i].length()) {
//                    JSONArray pts = (JSONArray) exteriorRing[i].get(k);
//                    double lon = pts.getDouble(0);
//                    double lat = pts.getDouble(1);
//                    if (Math.abs(lon - plon) < 0.00001 && Math.abs(lat - plat) < 0.00001) {
//                        System.out.println(plon + "," + plat + "," + lon + "," + lat);
//                    }
//                    plon = lon;
//                    plat = lat;
//
//                    k++;
//                }

                if (isClockwise) {
                    // Reverse order
                    JSONArray reversedPoly = new JSONArray();
                    int j = exteriorRing[i].length() - 1;
                    while (j >= 0) {
                        reversedPoly.put(exteriorRing[i].get(j));
                        j--;
                    }
                    poly.put(reversedPoly);
                } else {
                    poly.put(exteriorRing[i]);
                }
                polys.put(poly);
            }
        }

        if (debug) {
            System.out.println("HERE1");
            i = 0;
            while (i < exteriorRing[0].length()) {
                System.out.println(exteriorRing[0].get(i));
                i++;
            }

            System.out.println("HERE2");
            i = 0;
            while (i < exteriorRing[1].length()) {
                System.out.println(exteriorRing[1].get(i));
                i++;
            }

        }
        //System.out.println(poly);
        // Create the Geom
        return polys;

    }

    static double computeDpt(double a, double b, double theta) {
        double dp = 0.0;

        double dpt_sin = Math.pow(a * Math.sin(theta), 2.0);
        double dpt_cos = Math.pow(b * Math.cos(theta), 2.0);
        dp = Math.sqrt(dpt_sin + dpt_cos);

        return dp;
    }

    /**
     * Return geometry object rings for Esri or coordinates for GeoJSON
     *
     * @param clon
     * @param clat
     * @param a
     * @param b
     * @param rotationDeg
     * @param radius
     * @param isClockwise
     * @param numPoints
     * @param isEsri
     * @return
     */
    public JSONArray createEllipse2(double clon, double clat, Double a, Double b, Double rotationDeg, Integer numPoints, boolean isClockwise) {

        if (numPoints == null) {
            numPoints = 20;
        }

        if (a == null) {
            // default to 50 meters or 0.050 km
            a = 0.050;
        }

        if (b == null) {
            // default to 50 meters or 0.050 km
            a = 0.050;
        }

        if (rotationDeg == null) {
            rotationDeg = 0.0;
        }

        double theta = 0.0;
        double twoPi = Math.PI * 2.0;
        double deltaTheta = 0.0001;
        double numIntegrals = Math.round(twoPi / deltaTheta);
        double circ = 0.0;
        double dpt = 0.0;

        /* integrate over the elipse to get the circumference */
        for (int i = 0; i < numIntegrals; i++) {
            theta += i * deltaTheta;
            dpt = computeDpt(a, b, theta);
            circ += dpt;
        }
        System.out.println("number of interals = " + numIntegrals);
        System.out.println("circumference = " + circ * deltaTheta);

        int n = numPoints - 1; // Number of point
        int nextPoint = 0;
        double run = 0.0;
        theta = 0.0;

        GeographicCoordinate coord1 = new GeographicCoordinate(clon, clat);
        GeographicCoordinate coords[] = new GeographicCoordinate[numPoints];

        int cnt = 0;
        for (int i = 0; i < numIntegrals; i++) {
            theta += deltaTheta;
            double subIntegral = n * run / circ;
            if ((int) subIntegral >= nextPoint) {

                double sv = Math.sin(theta);
                double cv = Math.cos(theta);
                double radiusKM = a * b / Math.sqrt(a * a * sv * sv + b * b * cv * cv);
                DistanceBearing distb = new DistanceBearing(radiusKM, theta * R2D);
                GeographicCoordinate nc = getNewCoordPair(coord1, distb);

                double x = nc.getLon();
                double y = nc.getLat();
                coords[cnt] = nc;

                System.out.println(cnt + "," + "x=" + Math.round(x) + ", y=" + Math.round(y) + "," + theta);
                nextPoint++;
                cnt += 1;
            }
            run += computeDpt(a, b, theta);
        }

        coords[numPoints - 1] = coords[0]; // Last point same as first

        // Reverse the array
        for (int i = 0; i < coords.length / 2; i++) {
            GeographicCoordinate temp = coords[i];
            coords[i] = coords[coords.length - i - 1];
            coords[coords.length - i - 1] = temp;
        }

        GeographicCoordinate nc1 = new GeographicCoordinate();
        GeographicCoordinate nc2 = new GeographicCoordinate();
        GeographicCoordinate lastcoord = new GeographicCoordinate();

        JSONArray[] exteriorRing = new JSONArray[4];
        exteriorRing[0] = new JSONArray();
        exteriorRing[1] = new JSONArray();

        int ringNum = 0;
        int numRings = 1;

        nc1 = coords[0];
        int i = 0;
        double lon1 = nc1.getLon();
        double lat1 = nc1.getLat();
        if (debug) {
            System.out.println(i + ":" + lon1 + "," + lat1);
        }
        JSONArray coord = new JSONArray("[" + lon1 + ", " + lat1 + "]");
        exteriorRing[ringNum].put(coord);
        i++;

        boolean crossedDTEast = false;
        boolean crossedDTWest = false;
        boolean crossedZeroEast = false;
        boolean crossedZeroWest = false;

        while (i < numPoints) {
            nc2 = coords[i];
            // Compare coordinates
            double lon2 = nc2.getLon();
            double lat2 = nc2.getLat();

            if (lon2 >= 0.0 && lon1 <= 0.0) {

                if (Math.abs(lon2 - lon1) > 180.0) {
                    // Either gone from -179.xx to 179.xx (Crossing DT heading east)
                    if (debug) {
                        System.out.println("Crossing DT heading west");
                    }
                    crossedDTWest = true;

                    double x1 = (lon1 < 0) ? lon1 + 360.0 : lon1;
                    double x2 = (lon2 < 0) ? lon2 + 360.0 : lon2;
                    double crossing = findCrossing(x1, lat1, x2, lat2, 180.0);
                    if (debug) {
                        System.out.println(crossing);
                    }

                    // Add point to current ring
                    coord = new JSONArray("[-180.0, " + crossing + "]");
                    exteriorRing[ringNum].put(coord);

                    if (crossedZeroWest) {
                        // South Pole in Footprint
                        coord = new JSONArray("[-180.0, -90.0]");
                        exteriorRing[ringNum].put(coord);
                        coord = new JSONArray("[0.0, -90.0]");
                        exteriorRing[ringNum].put(coord);
                    }

                    // Swith to other ring
                    if (ringNum == 0) {
                        ringNum = 1;
                    } else if (ringNum == 1) {
                        ringNum = 0;
                    }

                    if (crossedZeroWest) {
                        // South Pole in Footprint
                        coord = new JSONArray("[0.0, -90.0]");
                        exteriorRing[ringNum].put(coord);
                        coord = new JSONArray("[180, -90.0]");
                        exteriorRing[ringNum].put(coord);
                    }

                    // Add point to other ring
                    coord = new JSONArray("[180.0, " + crossing + "]");
                    exteriorRing[ringNum].put(coord);

                } else {
                    // or gone from -1.xx to 1.xx  (Crossing 0 heading east)
                    if (debug) {
                        System.out.println("Crossing 0 heading east");
                    }

                    double x1 = lon1;
                    double x2 = lon2;
                    double crossing = findCrossing(x1, lat1, x2, lat2, 0.0);
                    if (debug) {
                        System.out.println(crossing);
                    }

                    // Add point to current ring
                    if (lon2 > 0.0) {
                        coord = new JSONArray("[0.0, " + crossing + "]");
                        exteriorRing[ringNum].put(coord);
                    }

                    if (crossedDTEast) {
                        // North Pole is in footprint add 180,90 and 0, 90
                        coord = new JSONArray("[0.0,90.0]");
                        exteriorRing[ringNum].put(coord);
                        coord = new JSONArray("[-180.0,90.0]");
                        exteriorRing[ringNum].put(coord);
                    }

                    // Swith to other ring
                    if (ringNum == 0) {
                        ringNum = 1;
                    } else if (ringNum == 1) {
                        ringNum = 0;
                    }

                    if (crossedDTEast) {
                        // North pole is in foot print add point 0,90, -180,90
                        coord = new JSONArray("[180.0,90.0]");
                        exteriorRing[ringNum].put(coord);
                        coord = new JSONArray("[0.0,90.0]");
                        exteriorRing[ringNum].put(coord);

                    }

                    // Add point to other ring
                    if (lon2 > 0.0) {
                        coord = new JSONArray("[0.0, " + crossing + "]");
                        exteriorRing[ringNum].put(coord);
                    }

                    crossedZeroEast = true;
                }

            } else if (lon2 < 0.0 && lon1 > 0.0) {

                if (Math.abs(lon2 - lon1) > 180.0) {
                    // Either gone from 179.xx to -179.xx (Crossing DT heading west)
                    if (debug) {
                        System.out.println("Crossing DT heading east");
                    }
                    crossedDTEast = true;

                    double x1 = (lon1 < 0) ? lon1 + 360.0 : lon1;
                    double x2 = (lon2 < 0) ? lon2 + 360.0 : lon2;
                    double crossing = findCrossing(x1, lat1, x2, lat2, 180.0);
                    if (debug) {
                        System.out.println(crossing);
                    }

                    coord = new JSONArray("[180.0, " + crossing + "]");
                    exteriorRing[ringNum].put(coord);

                    if (crossedZeroEast) {
                        // North Pole in Footprint
                        coord = new JSONArray("[180.0, 90.0]");
                        exteriorRing[ringNum].put(coord);
                        coord = new JSONArray("[0.0, 90.0]");
                        exteriorRing[ringNum].put(coord);
                    }

                    // Swith to other ring
                    if (ringNum == 0) {
                        ringNum = 1;
                    } else if (ringNum == 1) {
                        ringNum = 0;
                    }

                    if (crossedZeroEast) {
                        // North Pole in Footprint
                        coord = new JSONArray("[0.0, 90.0]");
                        exteriorRing[ringNum].put(coord);
                        coord = new JSONArray("[-180, 90.0]");
                        exteriorRing[ringNum].put(coord);
                    }

                    coord = new JSONArray("[-180.0, " + crossing + "]");
                    exteriorRing[ringNum].put(coord);

                } else {
                    if (debug) {
                        System.out.println("Crossing 0 heading west");
                    }
                    crossedZeroWest = true;

                    // or gone from 1.xx to -1.xx (Crossing 0 heading west
                    double x1 = lon1;
                    double x2 = lon2;
                    double crossing = findCrossing(x1, lat1, x2, lat2, 0.0);
                    if (debug) {
                        System.out.println(crossing);
                    }

                    // Add point to current ring
                    coord = new JSONArray("[0.0, " + crossing + "]");
                    exteriorRing[ringNum].put(coord);

                    if (crossedDTWest) {
                        // South Pole is in footprint
                        coord = new JSONArray("[0.0,-90.0]");
                        exteriorRing[ringNum].put(coord);
                        coord = new JSONArray("[180.0,-90.0]");
                        exteriorRing[ringNum].put(coord);
                    }

                    // Swith to other ring
                    if (ringNum == 0) {
                        ringNum = 1;
                    } else if (ringNum == 1) {
                        ringNum = 0;
                    }

                    if (crossedDTWest) {
                        // North pole is in foot print add point 0,90, -180,90
                        coord = new JSONArray("[-180.0,-90.0]");
                        exteriorRing[ringNum].put(coord);
                        coord = new JSONArray("[0.0,-90.0]");
                        exteriorRing[ringNum].put(coord);

                    }

                    // Add point to other ring
                    coord = new JSONArray("[0.0, " + crossing + "]");
                    exteriorRing[ringNum].put(coord);
                }
            }

            if (debug) {
                System.out.println(i + ":" + lon2 + "," + lat2);
            }

            if (i < numPoints - 1) {
                // Don't inject last point here
                coord = new JSONArray("[" + lon2 + ", " + lat2 + "]");
                exteriorRing[ringNum].put(coord);
            }

            nc1 = nc2;
            lon1 = nc1.getLon();
            lat1 = nc1.getLat();
            i++;

        }

        JSONArray polys = new JSONArray();
        JSONArray poly = new JSONArray();

        for (i = 0; i < 2; i++) {
            poly = new JSONArray();
            if (exteriorRing[i].length() > 0) {
                exteriorRing[i].put(exteriorRing[i].get(0));

                if (isClockwise) {
                    // Reverse order
                    JSONArray reversedPoly = new JSONArray();
                    int j = exteriorRing[i].length() - 1;
                    while (j >= 0) {
                        reversedPoly.put(exteriorRing[i].get(j));
                        j--;
                    }
                    poly.put(reversedPoly);
                } else {
                    poly.put(exteriorRing[i]);
                }
                polys.put(poly);
            }
        }

        if (debug) {
            System.out.println("HERE1");
            i = 0;
            while (i < exteriorRing[0].length()) {
                System.out.println(exteriorRing[0].get(i));
                i++;
            }

            System.out.println("HERE2");
            i = 0;
            while (i < exteriorRing[1].length()) {
                System.out.println(exteriorRing[1].get(i));
                i++;
            }

        }
        //System.out.println(poly);
        // Create the Geom
        return polys;

    }

    /**
     * Return geometry object rings for Esri or coordinates for GeoJSON
     *
     * @param clon
     * @param clat
     * @param a
     * @param b
     * @param rotationDeg
     * @param radius
     * @param isClockwise
     * @param numPoints
     * @param isEsri
     * @return
     */
    public JSONArray createEllipse(double clon, double clat, Double a, Double b, Double rotationDeg, Integer numPoints, boolean isClockwise) {

        if (numPoints == null) {
            numPoints = 20;
        }

        if (a == null) {
            // default to 50 meters or 0.050 km
            a = 0.050;
        }

        if (b == null) {
            // default to 50 meters or 0.050 km
            a = 0.050;
        }

        if (rotationDeg == null) {
            rotationDeg = 0.0;
        }

        double d = 360.0 / (numPoints - 1);

        GeographicCoordinate coords[] = new GeographicCoordinate[numPoints];

        int i = 0;
        while (i < numPoints - 1) {
            double v = 0.0;
            if (false) {  // default to counterclockwise
                v = i * d - 180.0;  // clockwise (Esri wants this)
            } else {
                v = 180.0 - i * d;  // counterclockwise (GeoJSON wants this)
            }

            GeographicCoordinate coord1 = new GeographicCoordinate(clon, clat);
            double r = v * D2R;
            double sv = Math.sin(r);
            double cv = Math.cos(r);
            double radiusKM = a * b / Math.sqrt(a * a * sv * sv + b * b * cv * cv);
            DistanceBearing distb = new DistanceBearing(radiusKM, v);

            if (rotationDeg != 0.0) {
                double bearing = (distb.getBearing() + rotationDeg) % 360.0;
                distb.setBearing(bearing);
            }

            GeographicCoordinate nc = getNewCoordPair(coord1, distb);

            coords[i] = nc;
            i++;

        }

        coords[numPoints - 1] = coords[0]; // Last point same as first

        GeographicCoordinate nc1 = new GeographicCoordinate();
        GeographicCoordinate nc2 = new GeographicCoordinate();
        GeographicCoordinate lastcoord = new GeographicCoordinate();

        JSONArray[] exteriorRing = new JSONArray[4];
        exteriorRing[0] = new JSONArray();
        exteriorRing[1] = new JSONArray();

        int ringNum = 0;
        int numRings = 1;

        nc1 = coords[0];
        i = 0;
        double lon1 = nc1.getLon();
        double lat1 = nc1.getLat();
        if (debug) {
            System.out.println(i + ":" + lon1 + "," + lat1);
        }
        JSONArray coord = new JSONArray("[" + lon1 + ", " + lat1 + "]");
        exteriorRing[ringNum].put(coord);
        i++;

        boolean crossedDTEast = false;
        boolean crossedDTWest = false;
        boolean crossedZeroEast = false;
        boolean crossedZeroWest = false;

        while (i < numPoints) {
            nc2 = coords[i];
            // Compare coordinates
            double lon2 = nc2.getLon();
            double lat2 = nc2.getLat();

            if (lon2 >= 0.0 && lon1 <= 0.0) {

                if (Math.abs(lon2 - lon1) > 180.0) {
                    // Either gone from -179.xx to 179.xx (Crossing DT heading east)
                    if (debug) {
                        System.out.println("Crossing DT heading west");
                    }
                    crossedDTWest = true;

                    double x1 = (lon1 < 0) ? lon1 + 360.0 : lon1;
                    double x2 = (lon2 < 0) ? lon2 + 360.0 : lon2;
                    double crossing = findCrossing(x1, lat1, x2, lat2, 180.0);
                    if (debug) {
                        System.out.println(crossing);
                    }

                    // Add point to current ring
                    coord = new JSONArray("[-180.0, " + crossing + "]");
                    exteriorRing[ringNum].put(coord);

                    if (crossedZeroWest) {
                        // South Pole in Footprint
                        coord = new JSONArray("[-180.0, -90.0]");
                        exteriorRing[ringNum].put(coord);
                        coord = new JSONArray("[0.0, -90.0]");
                        exteriorRing[ringNum].put(coord);
                    }

                    // Swith to other ring
                    if (ringNum == 0) {
                        ringNum = 1;
                    } else if (ringNum == 1) {
                        ringNum = 0;
                    }

                    if (crossedZeroWest) {
                        // South Pole in Footprint
                        coord = new JSONArray("[0.0, -90.0]");
                        exteriorRing[ringNum].put(coord);
                        coord = new JSONArray("[180, -90.0]");
                        exteriorRing[ringNum].put(coord);
                    }

                    // Add point to other ring
                    coord = new JSONArray("[180.0, " + crossing + "]");
                    exteriorRing[ringNum].put(coord);

                } else {
                    // or gone from -1.xx to 1.xx  (Crossing 0 heading east)
                    if (debug) {
                        System.out.println("Crossing 0 heading east");
                    }

                    double x1 = lon1;
                    double x2 = lon2;
                    double crossing = findCrossing(x1, lat1, x2, lat2, 0.0);
                    if (debug) {
                        System.out.println(crossing);
                    }

                    // Add point to current ring
                    if (lon2 > 0.0) {
                        coord = new JSONArray("[0.0, " + crossing + "]");
                        exteriorRing[ringNum].put(coord);
                    }

                    if (crossedDTEast) {
                        // North Pole is in footprint add 180,90 and 0, 90
                        coord = new JSONArray("[0.0,90.0]");
                        exteriorRing[ringNum].put(coord);
                        coord = new JSONArray("[-180.0,90.0]");
                        exteriorRing[ringNum].put(coord);
                    }

                    // Swith to other ring
                    if (ringNum == 0) {
                        ringNum = 1;
                    } else if (ringNum == 1) {
                        ringNum = 0;
                    }

                    if (crossedDTEast) {
                        // North pole is in foot print add point 0,90, -180,90
                        coord = new JSONArray("[180.0,90.0]");
                        exteriorRing[ringNum].put(coord);
                        coord = new JSONArray("[0.0,90.0]");
                        exteriorRing[ringNum].put(coord);

                    }

                    // Add point to other ring
                    if (lon2 > 0.0) {
                        coord = new JSONArray("[0.0, " + crossing + "]");
                        exteriorRing[ringNum].put(coord);
                    }

                    crossedZeroEast = true;
                }

            } else if (lon2 < 0.0 && lon1 > 0.0) {

                if (Math.abs(lon2 - lon1) > 180.0) {
                    // Either gone from 179.xx to -179.xx (Crossing DT heading west)
                    if (debug) {
                        System.out.println("Crossing DT heading east");
                    }
                    crossedDTEast = true;

                    double x1 = (lon1 < 0) ? lon1 + 360.0 : lon1;
                    double x2 = (lon2 < 0) ? lon2 + 360.0 : lon2;
                    double crossing = findCrossing(x1, lat1, x2, lat2, 180.0);
                    if (debug) {
                        System.out.println(crossing);
                    }

                    coord = new JSONArray("[180.0, " + crossing + "]");
                    exteriorRing[ringNum].put(coord);

                    if (crossedZeroEast) {
                        // North Pole in Footprint
                        coord = new JSONArray("[180.0, 90.0]");
                        exteriorRing[ringNum].put(coord);
                        coord = new JSONArray("[0.0, 90.0]");
                        exteriorRing[ringNum].put(coord);
                    }

                    // Swith to other ring
                    if (ringNum == 0) {
                        ringNum = 1;
                    } else if (ringNum == 1) {
                        ringNum = 0;
                    }

                    if (crossedZeroEast) {
                        // North Pole in Footprint
                        coord = new JSONArray("[0.0, 90.0]");
                        exteriorRing[ringNum].put(coord);
                        coord = new JSONArray("[-180, 90.0]");
                        exteriorRing[ringNum].put(coord);
                    }

                    coord = new JSONArray("[-180.0, " + crossing + "]");
                    exteriorRing[ringNum].put(coord);

                } else {
                    if (debug) {
                        System.out.println("Crossing 0 heading west");
                    }
                    crossedZeroWest = true;

                    // or gone from 1.xx to -1.xx (Crossing 0 heading west
                    double x1 = lon1;
                    double x2 = lon2;
                    double crossing = findCrossing(x1, lat1, x2, lat2, 0.0);
                    if (debug) {
                        System.out.println(crossing);
                    }

                    // Add point to current ring
                    coord = new JSONArray("[0.0, " + crossing + "]");
                    exteriorRing[ringNum].put(coord);

                    if (crossedDTWest) {
                        // South Pole is in footprint
                        coord = new JSONArray("[0.0,-90.0]");
                        exteriorRing[ringNum].put(coord);
                        coord = new JSONArray("[180.0,-90.0]");
                        exteriorRing[ringNum].put(coord);
                    }

                    // Swith to other ring
                    if (ringNum == 0) {
                        ringNum = 1;
                    } else if (ringNum == 1) {
                        ringNum = 0;
                    }

                    if (crossedDTWest) {
                        // North pole is in foot print add point 0,90, -180,90
                        coord = new JSONArray("[-180.0,-90.0]");
                        exteriorRing[ringNum].put(coord);
                        coord = new JSONArray("[0.0,-90.0]");
                        exteriorRing[ringNum].put(coord);

                    }

                    // Add point to other ring
                    coord = new JSONArray("[0.0, " + crossing + "]");
                    exteriorRing[ringNum].put(coord);
                }
            }

            if (debug) {
                System.out.println(i + ":" + lon2 + "," + lat2);
            }

            if (i < numPoints - 1) {
                // Don't inject last point here
                coord = new JSONArray("[" + lon2 + ", " + lat2 + "]");
                exteriorRing[ringNum].put(coord);
            }

            nc1 = nc2;
            lon1 = nc1.getLon();
            lat1 = nc1.getLat();
            i++;

        }

        JSONArray polys = new JSONArray();
        JSONArray poly = new JSONArray();

        for (i = 0; i < 2; i++) {
            poly = new JSONArray();
            if (exteriorRing[i].length() > 0) {
                exteriorRing[i].put(exteriorRing[i].get(0));

                if (isClockwise) {
                    // Reverse order
                    JSONArray reversedPoly = new JSONArray();
                    int j = exteriorRing[i].length() - 1;
                    while (j >= 0) {
                        reversedPoly.put(exteriorRing[i].get(j));
                        j--;
                    }
                    poly.put(reversedPoly);
                } else {
                    poly.put(exteriorRing[i]);
                }
                polys.put(poly);
            }
        }

        if (debug) {
            System.out.println("HERE1");
            i = 0;
            while (i < exteriorRing[0].length()) {
                System.out.println(exteriorRing[0].get(i));
                i++;
            }

            System.out.println("HERE2");
            i = 0;
            while (i < exteriorRing[1].length()) {
                System.out.println(exteriorRing[1].get(i));
                i++;
            }

        }
        //System.out.println(poly);
        // Create the Geom
        return polys;

    }

    /**
     * Return geometry object rings for Esri or coordinates for GeoJSON
     *
     * @param clon
     * @param clat
     * @param radius
     * @param numPoints
     * @param isEsri
     * @return
     */
    public JSONArray createCircle(double clon, double clat, Double radiusKM, Integer numPoints, boolean isClockwise) {

        if (numPoints == null) {
            numPoints = 20;
        }

        if (radiusKM == null) {
            // default to 50 meters or 0.050 km
            radiusKM = 0.050;
        }

        double d = 360.0 / (numPoints - 1);

        GeographicCoordinate coords[] = new GeographicCoordinate[numPoints];

        int i = 0;
        while (i < numPoints - 1) {
            double v = 0.0;
            if (false) {  // default to counterclockwise
                v = i * d - 180.0;  // clockwise (Esri wants this)
            } else {
                v = 180.0 - i * d;  // counterclockwise (GeoJSON wants this)
            }

            GeographicCoordinate coord1 = new GeographicCoordinate(clon, clat);
            DistanceBearing distb = new DistanceBearing(radiusKM, v);

            GeographicCoordinate nc = getNewCoordPair(coord1, distb);

            coords[i] = nc;
            i++;

        }

        coords[numPoints - 1] = coords[0]; // Last point same as first

        GeographicCoordinate nc1 = new GeographicCoordinate();
        GeographicCoordinate nc2 = new GeographicCoordinate();
        GeographicCoordinate lastcoord = new GeographicCoordinate();

        JSONArray[] exteriorRing = new JSONArray[4];
        exteriorRing[0] = new JSONArray();
        exteriorRing[1] = new JSONArray();

        int ringNum = 0;
        int numRings = 1;

        nc1 = coords[0];
        i = 0;
        double lon1 = nc1.getLon();
        double lat1 = nc1.getLat();
        if (debug) {
            System.out.println(i + ":" + lon1 + "," + lat1);
        }
        JSONArray coord = new JSONArray("[" + lon1 + ", " + lat1 + "]");
        exteriorRing[ringNum].put(coord);
        i++;

        boolean crossedDTEast = false;
        boolean crossedDTWest = false;
        boolean crossedZeroEast = false;
        boolean crossedZeroWest = false;

        while (i < numPoints) {
            nc2 = coords[i];
            // Compare coordinates
            double lon2 = nc2.getLon();
            double lat2 = nc2.getLat();

            if (lon2 >= 0.0 && lon1 <= 0.0) {

                if (Math.abs(lon2 - lon1) > 180.0) {
                    // Either gone from -179.xx to 179.xx (Crossing DT heading east)
                    if (debug) {
                        System.out.println("Crossing DT heading west");
                    }
                    crossedDTWest = true;

                    double x1 = (lon1 < 0) ? lon1 + 360.0 : lon1;
                    double x2 = (lon2 < 0) ? lon2 + 360.0 : lon2;
                    double crossing = findCrossing(x1, lat1, x2, lat2, 180.0);
                    if (debug) {
                        System.out.println(crossing);
                    }

                    // Add point to current ring
                    coord = new JSONArray("[-180.0, " + crossing + "]");
                    exteriorRing[ringNum].put(coord);

                    if (crossedZeroWest) {
                        // South Pole in Footprint
                        coord = new JSONArray("[-180.0, -90.0]");
                        exteriorRing[ringNum].put(coord);
                        coord = new JSONArray("[0.0, -90.0]");
                        exteriorRing[ringNum].put(coord);
                    }

                    // Swith to other ring
                    if (ringNum == 0) {
                        ringNum = 1;
                    } else if (ringNum == 1) {
                        ringNum = 0;
                    }

                    if (crossedZeroWest) {
                        // South Pole in Footprint
                        coord = new JSONArray("[0.0, -90.0]");
                        exteriorRing[ringNum].put(coord);
                        coord = new JSONArray("[180, -90.0]");
                        exteriorRing[ringNum].put(coord);
                    }

                    // Add point to other ring
                    coord = new JSONArray("[180.0, " + crossing + "]");
                    exteriorRing[ringNum].put(coord);

                } else {
                    // or gone from -1.xx to 1.xx  (Crossing 0 heading east)
                    if (debug) {
                        System.out.println("Crossing 0 heading east");
                    }

                    double x1 = lon1;
                    double x2 = lon2;
                    double crossing = findCrossing(x1, lat1, x2, lat2, 0.0);
                    if (debug) {
                        System.out.println(crossing);
                    }

                    // Add point to current ring
                    if (lon2 > 0.0) {
                        coord = new JSONArray("[0.0, " + crossing + "]");
                        exteriorRing[ringNum].put(coord);
                    }

                    if (crossedDTEast) {
                        // North Pole is in footprint add 180,90 and 0, 90
                        coord = new JSONArray("[0.0,90.0]");
                        exteriorRing[ringNum].put(coord);
                        coord = new JSONArray("[-180.0,90.0]");
                        exteriorRing[ringNum].put(coord);
                    }

                    // Swith to other ring
                    if (ringNum == 0) {
                        ringNum = 1;
                    } else if (ringNum == 1) {
                        ringNum = 0;
                    }

                    if (crossedDTEast) {
                        // North pole is in foot print add point 0,90, -180,90
                        coord = new JSONArray("[180.0,90.0]");
                        exteriorRing[ringNum].put(coord);
                        coord = new JSONArray("[0.0,90.0]");
                        exteriorRing[ringNum].put(coord);

                    }

                    // Add point to other ring
                    if (lon2 > 0.0) {
                        coord = new JSONArray("[0.0, " + crossing + "]");
                        exteriorRing[ringNum].put(coord);
                    }

                    crossedZeroEast = true;
                }

            } else if (lon2 < 0.0 && lon1 > 0.0) {

                if (Math.abs(lon2 - lon1) > 180.0) {
                    // Either gone from 179.xx to -179.xx (Crossing DT heading west)
                    if (debug) {
                        System.out.println("Crossing DT heading east");
                    }
                    crossedDTEast = true;

                    double x1 = (lon1 < 0) ? lon1 + 360.0 : lon1;
                    double x2 = (lon2 < 0) ? lon2 + 360.0 : lon2;
                    double crossing = findCrossing(x1, lat1, x2, lat2, 180.0);
                    if (debug) {
                        System.out.println(crossing);
                    }

                    coord = new JSONArray("[180.0, " + crossing + "]");
                    exteriorRing[ringNum].put(coord);

                    if (crossedZeroEast) {
                        // North Pole in Footprint
                        coord = new JSONArray("[180.0, 90.0]");
                        exteriorRing[ringNum].put(coord);
                        coord = new JSONArray("[0.0, 90.0]");
                        exteriorRing[ringNum].put(coord);
                    }

                    // Swith to other ring
                    if (ringNum == 0) {
                        ringNum = 1;
                    } else if (ringNum == 1) {
                        ringNum = 0;
                    }

                    if (crossedZeroEast) {
                        // North Pole in Footprint
                        coord = new JSONArray("[0.0, 90.0]");
                        exteriorRing[ringNum].put(coord);
                        coord = new JSONArray("[-180, 90.0]");
                        exteriorRing[ringNum].put(coord);
                    }

                    coord = new JSONArray("[-180.0, " + crossing + "]");
                    exteriorRing[ringNum].put(coord);

                } else {
                    if (debug) {
                        System.out.println("Crossing 0 heading west");
                    }
                    crossedZeroWest = true;

                    // or gone from 1.xx to -1.xx (Crossing 0 heading west
                    double x1 = lon1;
                    double x2 = lon2;
                    double crossing = findCrossing(x1, lat1, x2, lat2, 0.0);
                    if (debug) {
                        System.out.println(crossing);
                    }

                    // Add point to current ring
                    coord = new JSONArray("[0.0, " + crossing + "]");
                    exteriorRing[ringNum].put(coord);

                    if (crossedDTWest) {
                        // South Pole is in footprint
                        coord = new JSONArray("[0.0,-90.0]");
                        exteriorRing[ringNum].put(coord);
                        coord = new JSONArray("[180.0,-90.0]");
                        exteriorRing[ringNum].put(coord);
                    }

                    // Swith to other ring
                    if (ringNum == 0) {
                        ringNum = 1;
                    } else if (ringNum == 1) {
                        ringNum = 0;
                    }

                    if (crossedDTWest) {
                        // North pole is in foot print add point 0,90, -180,90
                        coord = new JSONArray("[-180.0,-90.0]");
                        exteriorRing[ringNum].put(coord);
                        coord = new JSONArray("[0.0,-90.0]");
                        exteriorRing[ringNum].put(coord);

                    }

                    // Add point to other ring
                    coord = new JSONArray("[0.0, " + crossing + "]");
                    exteriorRing[ringNum].put(coord);
                }
            }

            if (debug) {
                System.out.println(i + ":" + lon2 + "," + lat2);
            }

            if (i < numPoints - 1) {
                // Don't inject last point here
                coord = new JSONArray("[" + lon2 + ", " + lat2 + "]");
                exteriorRing[ringNum].put(coord);
            }

            nc1 = nc2;
            lon1 = nc1.getLon();
            lat1 = nc1.getLat();
            i++;

        }

        JSONArray polys = new JSONArray();
        JSONArray poly = new JSONArray();

        for (i = 0; i < 2; i++) {
            poly = new JSONArray();
            if (exteriorRing[i].length() > 0) {
                exteriorRing[i].put(exteriorRing[i].get(0));

                if (isClockwise) {
                    // Reverse order
                    JSONArray reversedPoly = new JSONArray();
                    int j = exteriorRing[i].length() - 1;
                    while (j >= 0) {
                        reversedPoly.put(exteriorRing[i].get(j));
                        j--;
                    }
                    poly.put(reversedPoly);
                } else {
                    poly.put(exteriorRing[i]);
                }
                polys.put(poly);
            }
        }

        if (debug) {
            System.out.println("HERE1");
            i = 0;
            while (i < exteriorRing[0].length()) {
                System.out.println(exteriorRing[0].get(i));
                i++;
            }

            System.out.println("HERE2");
            i = 0;
            while (i < exteriorRing[1].length()) {
                System.out.println(exteriorRing[1].get(i));
                i++;
            }

        }
        //System.out.println(poly);
        // Create the Geom
        return polys;

    }

    public JSONObject generateProperties(int i, double lon, double lat, double size) {
        JSONObject properties = new JSONObject();

        properties.put("fid", i);
        properties.put("longitude", lon);
        properties.put("latitude", lat);
        properties.put("size", size);
        properties.put("rndfield1", generateRandomWords(8));
        properties.put("rndfield2", generateRandomWords(8));
        properties.put("rndfield3", generateRandomWords(8));
        properties.put("rndfield4", generateRandomWords(8));

        return properties;
    }

    public String generateRandomWords(int numchars) {
        Random random = new Random();
        char[] word = new char[numchars];
        for (int j = 0; j < word.length; j++) {
            word[j] = (char) ('a' + random.nextInt(26));
        }
        return new String(word);
    }

    public void testCircles() {
        GreatCircle gc = new GreatCircle();

        GeographicCoordinate center = new GeographicCoordinate(0, 0);

//        // Create a circle; returns points in clockwise direction start from bearing of 0 (North)
//        GeographicCoordinate[] coords = gc.createCircle(center, 120.0, 39, true);
//
//        System.out.println(coords.length);
//
//        // Show the points
//        int i = 0;
//        for (GeographicCoordinate coord : coords) {
//            System.out.println(i + ":" + coord);
//            i++;
//        }
//
//        System.out.println();
//        i = coords.length;
//        // Show the points in reverse order
//        while (i > 0) {
//            i--;
//            System.out.println(i + ":" + coords[i]);
//        }
        // Create GeoJSON
        JSONObject featureCollection = new JSONObject();
        featureCollection.put("type", "FeatureCollection");

        JSONArray features = new JSONArray();

        JSONObject feature = new JSONObject();
        feature.put("type", "Feature");

        // Add properties (At least one is required)
        JSONObject properties = new JSONObject();
        properties.put("fid", 1);
        feature.put("properties", properties);

        // Get the coordinates
        JSONArray coords = gc.createCircle(-99.0, 33.0, 100.0, 100, false);

        JSONObject geom = new JSONObject();
        geom.put("type", "Polygon");
        geom.put("coordinates", coords);

        feature.put("geometry", geom);

        features.put(feature);
        featureCollection.put("features", features);

        //System.out.println(featureCollection.toString());
    }

    public void createEsriTest() {
        GreatCircle gc = new GreatCircle();

        double lon = -99.0;
        double lat = 33.0;
        double size = 300.0;
        int numPoints = 100;

        JSONArray features = new JSONArray();

        JSONObject feature = new JSONObject();

        // Add properties (At least one is required)
        JSONObject properties = gc.generateProperties(1, lon, lat, size);
        feature.put("feature", properties);

        // Get the coordinates
        JSONArray coords = gc.createCircle(lon, lat, size, numPoints, true);

        JSONObject geom = new JSONObject();
        geom.put("coordinates", coords);

        feature.put("geometry", geom);

        features.put(feature);

        JSONObject json = new JSONObject();
        json.put("features", features);

        //System.out.println(json.toString());
    }

    public void createGeojsonEllipseTest(double lon, double lat, double a, double b, double rot, int numPoints) {
        GreatCircle gc = new GreatCircle();

        JSONObject featureCollection = new JSONObject();
        featureCollection.put("type", "FeatureCollection");

        JSONArray features = new JSONArray();

        JSONObject feature = new JSONObject();
        feature.put("type", "Feature");

        // Add properties (At least one is required)
        JSONObject properties = gc.generateProperties(1, lon, lat, a);
        feature.put("properties", properties);

        // Get the coordinates
        JSONArray coords = gc.createEllipse3(lon, lat, a, b, rot, numPoints, false);

        JSONObject geom = new JSONObject();
        geom.put("type", "MultiPolygon");
        geom.put("coordinates", coords);

        feature.put("geometry", geom);

        features.put(feature);
        featureCollection.put("features", features);

        System.out.println(featureCollection.toString());
    }

    public void createGeojsonTest(double lon, double lat, double size, int numPoints) {
        GreatCircle gc = new GreatCircle();

        JSONObject featureCollection = new JSONObject();
        featureCollection.put("type", "FeatureCollection");

        JSONArray features = new JSONArray();

        JSONObject feature = new JSONObject();
        feature.put("type", "Feature");

        // Add properties (At least one is required)
        JSONObject properties = gc.generateProperties(1, lon, lat, size);
        feature.put("properties", properties);

        // Get the coordinates
        JSONArray coords = gc.createCircle(lon, lat, size, numPoints, false);

        JSONObject geom = new JSONObject();
        geom.put("type", "MultiPolygon");
        geom.put("coordinates", coords);

        feature.put("geometry", geom);

        features.put(feature);
        featureCollection.put("features", features);

        System.out.println(featureCollection.toString());

        //gc.testCircles();
    }

    public static void main(String[] args) {

        GreatCircle gc = new GreatCircle();

        GeographicCoordinate coord1 = new GeographicCoordinate(0,0);
        GeographicCoordinate coord2 = new GeographicCoordinate(1,1);

        DistanceBearing distB = gc.getDistanceBearing(coord1, coord2);
        System.out.println(distB.getDistance());
      //  gc.createGeojsonEllipseTest(-69.52,9.05,7,0.007, 0, 100);

//        JSONArray json = gc.createCircle(-1, 30, 200.0, 20, true);
//        int i = 0;
//        //System.out.println(++i);
//        Random rnd = new Random();
//        while (i < 1000) {
//
//            double a = rnd.nextDouble() * 1 + 0.01;  // a from 0.01 to 1.1km
//            double b = rnd.nextDouble() * 1 + 0.01;  // b from 0.01 to 1.1km
//            double r = rnd.nextDouble() * 360; // Rotation 0 to 360
//
//            double minLon = -180;
//            double maxLon = 180;
//            double lon = minLon + (maxLon - minLon) * rnd.nextDouble();
//
//            double minLat = -80;
//            double maxLat = 80;
//
//            double lat = minLat + (maxLat - minLat) * rnd.nextDouble();
//
//            gc.createGeojsonEllipseTest(lon, lat, a, b, r, 200);
//            i++;
//        }

//        JSONObject featureCollection = new JSONObject();
//        featureCollection.put("type", "FeatureCollection");
//
//        JSONArray features = new JSONArray();
//
//        JSONObject feature = new JSONObject();
//        feature.put("type", "Feature");
//
//        // Add properties (At least one is required)
//        JSONObject properties = new JSONObject();
//        properties.put("name", "test");
//        feature.put("properties", properties);
//
//
//        JSONArray polys = new JSONArray();
//        JSONArray poly = new JSONArray();
//        JSONArray ring = new JSONArray();
//        JSONArray coord = new JSONArray();
//
//        double lllon = -180.0;
//        double lllat = 89.0;
//
//        coord = new JSONArray("[" + (lllon) + "," + (lllat) + "]");
//        ring.put(coord);
//        coord = new JSONArray("[" + (lllon + 180.0)  + "," + (lllat) + "]");
//        ring.put(coord);
//        coord = new JSONArray("[" + (lllon + 180.0)  + "," + (lllat + 1.0) + "]");
//        ring.put(coord);
//        coord = new JSONArray("[" + (lllon)  + "," + (lllat + 1.0) + "]");;
//        ring.put(coord);
//        ring.put(ring.get(0));
//        poly.put(ring);
//        polys.put(poly);
//
//
//        poly = new JSONArray();
//        ring = new JSONArray();
//
//        lllon = 0.0;
//        lllat = 89.0;
//
//        coord = new JSONArray("[" + (lllon) + "," + (lllat) + "]");
//        ring.put(coord);
//        coord = new JSONArray("[" + (lllon + 180.0)  + "," + (lllat) + "]");
//        ring.put(coord);
//        coord = new JSONArray("[" + (lllon + 180.0)  + "," + (lllat + 1.0) + "]");
//        ring.put(coord);
//        coord = new JSONArray("[" + (lllon)  + "," + (lllat + 1.0) + "]");;
//        ring.put(coord);
//        ring.put(ring.get(0));
//        poly.put(ring);
//        polys.put(poly);
//
//
//        JSONObject geom = new JSONObject();
//        geom.put("type", "MultiPolygon");
//        geom.put("coordinates", polys);
//
//        feature.put("geometry", geom);
//
//        features.put(feature);
//        featureCollection.put("features", features);
//
//        System.out.println(featureCollection.toString());
    }

}


text:
namespace manipulation_msgs
{

  class GripperTranslation : public ros::Msg
  {
    public:
      geometry_msgs::Vector3Stamped direction;
      float desired_distance;
      float min_distance;

    virtual int serialize(unsigned char *outbuffer) const
    {
      int offset = 0;
      offset += this->direction.serialize(outbuffer + offset);
      union {
        float real;
        uint32_t base;
      } u_desired_distance;
      u_desired_distance.real = this->desired_distance;
      *(outbuffer + offset + 0) = (u_desired_distance.base >> (8 * 0)) & 0xFF;
      *(outbuffer + offset + 1) = (u_desired_distance.base >> (8 * 1)) & 0xFF;
      *(outbuffer + offset + 2) = (u_desired_distance.base >> (8 * 2)) & 0xFF;
      *(outbuffer + offset + 3) = (u_desired_distance.base >> (8 * 3)) & 0xFF;
      offset += sizeof(this->desired_distance);
      union {
        float real;
        uint32_t base;
      } u_min_distance;
      u_min_distance.real = this->min_distance;
      *(outbuffer + offset + 0) = (u_min_distance.base >> (8 * 0)) & 0xFF;
      *(outbuffer + offset + 1) = (u_min_distance.base >> (8 * 1)) & 0xFF;
      *(outbuffer + offset + 2) = (u_min_distance.base >> (8 * 2)) & 0xFF;
      *(outbuffer + offset + 3) = (u_min_distance.base >> (8 * 3)) & 0xFF;
      offset += sizeof(this->min_distance);
      return offset;
    }

    virtual int deserialize(unsigned char *inbuffer)
    {
      int offset = 0;
      offset += this->direction.deserialize(inbuffer + offset);
      union {
        float real;
        uint32_t base;
      } u_desired_distance;
      u_desired_distance.base = 0;
      u_desired_distance.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0);
      u_desired_distance.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1);
      u_desired_distance.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2);
      u_desired_distance.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3);
      this->desired_distance = u_desired_distance.real;
      offset += sizeof(this->desired_distance);
      union {
        float real;
        uint32_t base;
      } u_min_distance;
      u_min_distance.base = 0;
      u_min_distance.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0);
      u_min_distance.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1);
      u_min_distance.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2);
      u_min_distance.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3);
      this->min_distance = u_min_distance.real;
      offset += sizeof(this->min_distance);
     return offset;
    }

    const char * getType(){ return "manipulation_msgs/GripperTranslation"; };
    const char * getMD5(){ return "b53bc0ad0f717cdec3b0e42dec300121"; };

  };

}
#endif

redpajama_set_name: RedPajamaGithub


text:
NS_ASSUME_NONNULL_BEGIN

@interface WAMSectionInfo : NSObject

@property (nonatomic, readonly, copy) NSArray<WAMCellInfo *> *cellInfos;

@property (nonatomic, copy, nullable) NSString *alias;

///---------------------
/// @name section header
///---------------------

@property (nonatomic, copy, nullable) NSString *sectionHeaderText;
@property (nonatomic, assign) CGFloat sectionHeaderHeight; // default is 0.1

///---------------------
/// @name section footer
///---------------------

@property (nonatomic, copy, nullable) NSString *sectionFooterText;
@property (nonatomic, assign) CGFloat sectionFooterHeight; // default is 0.1

///---------------------
/// @name Initialization
///---------------------

+ (instancetype)infoWithCellInfos:(NSArray<WAMCellInfo *> *)cellInfos
                            alias:(nullable NSString *)alias;
- (instancetype)initWithCellInfos:(NSArray<WAMCellInfo *> *)cellInfos
                            alias:(nullable NSString *)alias;

@end

@interface WAMSectionInfo (IndexSearch)

- (NSUInteger)indexOfCellInfoWithAlias:(NSString *)alias;

@end

@interface WAMSectionInfo (Append)

- (BOOL)appendingCellInfo:(WAMCellInfo *)cellInfo;
- (BOOL)appendingCellInfo:(WAMCellInfo *)cellInfo atIndex:(NSUInteger)index;

@end

@interface WAMSectionInfo (Delete)

- (BOOL)removeCellInfo:(WAMCellInfo *)cellInfo;
- (BOOL)removeCellInfoAtIndex:(NSUInteger)index;
- (BOOL)removeCellInfoWithAlias:(NSString *)alias;

@end

@interface WAMSectionInfo (Replace)

- (BOOL)replaceCellInfo:(WAMCellInfo *)originalCellInfo with:(WAMCellInfo *)cellInfo;
- (BOOL)replaceCellInfoAtIndex:(NSUInteger)index with:(WAMCellInfo *)cellInfo;
- (BOOL)replaceCellInfoWithAlias:(NSString *)alias with:(WAMCellInfo *)cellInfo;

@end

NS_ASSUME_NONNULL_END


text:
package org.bonej.geometry;

import static org.junit.Assert.assertEquals;

import org.junit.Test;

public class TrigTest {

	double[] p0 = { 1, 2, 3 };
	double[] p1 = { 4, 5, 6 };

	@Test
	public void testDistance3DDoubleArrayDoubleArray() {
		final double result = Trig.distance3D(p0, p1);
		final double expected = Math.sqrt(27);
		assertEquals(expected, result, 1e-12);
	}

	@Test
	public void testDistance3DDoubleDoubleDoubleDoubleDoubleDouble() {
		final double result = Trig.distance3D(1, 2, 3, 4, 5, 6);
		final double expected = Math.sqrt(27);
		assertEquals(expected, result, 1e-12);
	}

	@Test
	public void testDistance3DDoubleDoubleDouble() {
		final double result = Trig.distance3D(1, 2, 3);
		final double expected = Math.sqrt(14);
		assertEquals(expected, result, 1e-12);
	}

	@Test
	public void testDistance3DDoubleArray() {
		final double result = Trig.distance3D(p1);
		final double expected = Math.sqrt(77);
		assertEquals(expected, result, 1e-12);
	}
}


text:
using System;
using LionFire.Persistence;

namespace LionFire.Vos
{
    public class MountHandleObject : INotifyOnSaving
    {
        public void OnSaving(object persistenceContext = null) => throw new NotSupportedException("Do not save this object");
    }
}


text:
import os
import sys
import time
if sys.platform != 'win32':
    import node_cli
else:
    import node_api
import unittest
import config

class Node:
    def __init__(self, nodeid, is_mtd=False, simulator=None):
        self.simulator = simulator
        self.interface = None

        if sys.platform != 'win32':
            self.interface = node_cli.otCli(nodeid, is_mtd, simulator=simulator)
        else:
            self.interface = node_api.otApi(nodeid)

        self.interface.clear_whitelist()
        self.interface.disable_whitelist()
        self.interface.set_timeout(100)

    def __del__(self):
        self.destroy()

    def destroy(self):
        if self.interface:
            self.interface.destroy()
            self.interface = None

    def set_mode(self, mode):
        self.interface.set_mode(mode)

    def debug(self, level):
        self.interface.debug(level)

    def interface_up(self):
        self.interface.interface_up()

    def interface_down(self):
        self.interface.interface_down()

    def thread_start(self):
        self.interface.thread_start()

    def thread_stop(self):
        self.interface.thread_stop()

    def commissioner_start(self):
        self.interface.commissioner_start()

    def commissioner_add_joiner(self, addr, psk):
        self.interface.commissioner_add_joiner(addr, psk)

    def joiner_start(self, pskd='', provisioning_url=''):
        self.interface.joiner_start(pskd, provisioning_url)

    def start(self):
        self.interface.interface_up()
        self.interface.thread_start()

    def stop(self):
        self.interface.thread_stop()
        self.interface.interface_down()

    def clear_whitelist(self):
        self.interface.clear_whitelist()

    def enable_whitelist(self):
        self.interface.enable_whitelist()

    def disable_whitelist(self):
        self.interface.disable_whitelist()

    def add_whitelist(self, addr, rssi=None):
        self.interface.add_whitelist(addr, rssi)

    def remove_whitelist(self, addr):
        self.interface.remove_whitelist(addr)

    def get_addr16(self):
        return self.interface.get_addr16()

    def get_router_id(self):
        return self.interface.get_router_id()

    def get_addr64(self):
        return self.interface.get_addr64()

    def get_eui64(self):
        return self.interface.get_eui64()

    def get_joiner_id(self):
        return self.interface.get_joiner_id()

    def get_channel(self):
        return self.interface.get_channel()

    def set_channel(self, channel):
        self.interface.set_channel(channel)

    def get_masterkey(self):
        return self.interface.get_masterkey()

    def set_masterkey(self, masterkey):
        self.interface.set_masterkey(masterkey)

    def get_key_sequence_counter(self):
        return self.interface.get_key_sequence_counter()

    def set_key_sequence_counter(self, key_sequence_counter):
        self.interface.set_key_sequence_counter(key_sequence_counter)

    def set_key_switch_guardtime(self, key_switch_guardtime):
        self.interface.set_key_switch_guardtime(key_switch_guardtime)

    def set_network_id_timeout(self, network_id_timeout):
        self.interface.set_network_id_timeout(network_id_timeout)

    def get_network_name(self):
        return self.interface.get_network_name()

    def set_network_name(self, network_name):
        self.interface.set_network_name(network_name)

    def get_panid(self):
        return self.interface.get_panid()

    def set_panid(self, panid = config.PANID):
        self.interface.set_panid(panid)

    def get_partition_id(self):
        return self.interface.get_partition_id()

    def set_partition_id(self, partition_id):
        self.interface.set_partition_id(partition_id)

    def set_router_upgrade_threshold(self, threshold):
        self.interface.set_router_upgrade_threshold(threshold)

    def set_router_downgrade_threshold(self, threshold):
        self.interface.set_router_downgrade_threshold(threshold)

    def release_router_id(self, router_id):
        self.interface.release_router_id(router_id)

    def get_state(self):
        return self.interface.get_state()

    def set_state(self, state):
        self.interface.set_state(state)

    def get_timeout(self):
        return self.interface.get_timeout()

    def set_timeout(self, timeout):
        self.interface.set_timeout(timeout)

    def set_max_children(self, number):
        self.interface.set_max_children(number)

    def get_weight(self):
        return self.interface.get_weight()

    def set_weight(self, weight):
        self.interface.set_weight(weight)

    def add_ipaddr(self, ipaddr):
        self.interface.add_ipaddr(ipaddr)

    def get_addrs(self):
        return self.interface.get_addrs()

    def get_addr(self, prefix):
        return self.interface.get_addr(prefix)

    def get_eidcaches(self):
        return self.interface.get_eidcaches()

    def add_service(self, enterpriseNumber, serviceData, serverData):
        self.interface.add_service(enterpriseNumber, serviceData, serverData)

    def remove_service(self, enterpriseNumber, serviceData):
        self.interface.remove_service(enterpriseNumber, serviceData)

    def get_ip6_address(self, address_type):
        return self.interface.get_ip6_address(address_type)

    def get_context_reuse_delay(self):
        return self.interface.get_context_reuse_delay()

    def set_context_reuse_delay(self, delay):
        self.interface.set_context_reuse_delay(delay)

    def add_prefix(self, prefix, flags, prf = 'med'):
        self.interface.add_prefix(prefix, flags, prf)

    def remove_prefix(self, prefix):
        self.interface.remove_prefix(prefix)

    def add_route(self, prefix, prf = 'med'):
        self.interface.add_route(prefix, prf)

    def remove_route(self, prefix):
        self.interface.remove_route(prefix)

    def register_netdata(self):
        self.interface.register_netdata()

    def energy_scan(self, mask, count, period, scan_duration, ipaddr):
        self.interface.energy_scan(mask, count, period, scan_duration, ipaddr)

    def panid_query(self, panid, mask, ipaddr):
        self.interface.panid_query(panid, mask, ipaddr)

    def scan(self):
        return self.interface.scan()

    def ping(self, ipaddr, num_responses=1, size=None, timeout=5):
        return self.interface.ping(ipaddr, num_responses, size, timeout)

    def reset(self):
        return self.interface.reset()

    def set_router_selection_jitter(self, jitter):
        self.interface.set_router_selection_jitter(jitter)

    def set_active_dataset(self, timestamp, panid=None, channel=None, channel_mask=None, master_key=None):
        self.interface.set_active_dataset(timestamp, panid, channel, channel_mask, master_key)

    def set_pending_dataset(self, pendingtimestamp, activetimestamp, panid=None, channel=None):
        self.interface.set_pending_dataset(pendingtimestamp, activetimestamp, panid, channel)

    def announce_begin(self, mask, count, period, ipaddr):
        self.interface.announce_begin(mask, count, period, ipaddr)

    def send_mgmt_active_set(self, active_timestamp=None, channel=None, channel_mask=None, extended_panid=None,
                             panid=None, master_key=None, mesh_local=None, network_name=None, binary=None):
        self.interface.send_mgmt_active_set(active_timestamp, channel, channel_mask, extended_panid, panid,
                                            master_key, mesh_local, network_name, binary)

    def send_mgmt_pending_set(self, pending_timestamp=None, active_timestamp=None, delay_timer=None, channel=None,
                              panid=None, master_key=None, mesh_local=None, network_name=None):
        self.interface.send_mgmt_pending_set(pending_timestamp, active_timestamp, delay_timer, channel, panid,
                                             master_key, mesh_local, network_name)

    def coaps_start_psk(self, psk, pskIdentity):
        self.interface.coaps_start_psk(psk, pskIdentity)

    def coaps_start_x509(self):
        self.interface.coaps_start_x509()

    def coaps_set_resource_path(self, path):
        self.interface.coaps_set_resource_path(path)

    def coaps_stop(self):
        self.interface.coaps_stop()

    def coaps_connect(self, ipaddr):
        self.interface.coaps_connect(ipaddr)

    def coaps_disconnect(self):
        self.interface.coaps_disconnect()

    def coaps_get(self):
        self.interface.coaps_get()

if __name__ == '__main__':
    unittest.main()


text:
import datetime
import boto3
session = boto3.Session(profile_name='admin')
client = session.client('emr')

def make_instances():
    return {
       'InstanceGroups': [
           {
           'InstanceRole': 'MASTER',
           'Market': 'SPOT',
           'BidPrice': '.6',
           'InstanceType': 'm1.medium',
           'InstanceCount': 1,
           'Configurations': [
               {"Classification":"emrfs-site",
               "Properties":{"fs.s3.consistent.retryPeriodSeconds":"10",
                   "consistent":"true",
                   "Consistent":"true",
                   "fs.s3.consistent.retryCount":"5",
                   "fs.s3.consistent.metadata.tableName":"EmrFSMetadata"},
               "Configurations":[]
               },
               ],
       },
           {
           'InstanceRole': 'CORE',
           'Market': 'SPOT',
           'BidPrice': '.6',
           'InstanceType': 'm3.xlarge',
           'InstanceCount': 15,
           'Configurations': [
               {"Classification":"emrfs-site",
               "Properties":{"fs.s3.consistent.retryPeriodSeconds":"10",
                   "consistent":"true",
                   "Consistent":"true",
                   "fs.s3.consistent.retryCount":"5",
                   "fs.s3.consistent.metadata.tableName":"EmrFSMetadata"},
               "Configurations":[]
               },
               ],

       }
           ],
       'Ec2KeyName': 'ubuntu-home',
       'KeepJobFlowAliveWhenNoSteps': True,
       'Ec2SubnetId': "subnet-0f159079",
   }

def make_bootstrap():
    return[
            {
                'Name': 'Generic bootstrap',
                'ScriptBootstrapAction': {
                    'Path': 's3://paulhtremblay/emr_bootstrap.sh',
                }
            },
            {
                'Name': 'ipython',
                'ScriptBootstrapAction': {
                    'Path': 's3://paulhtremblay/emr_bootstrap_ipython.sh',
                }
            },
        ]

response = client.run_job_flow(
   Name = "tutorial example {0}".format(datetime.datetime.now()),
   LogUri =  "s3n://paulhtremblay/emr-logs/",
   ReleaseLabel = 'emr-5.3.0',
   Instances = make_instances(),
   JobFlowRole = 'EMR_EC2_DefaultRole',
   ServiceRole = 'EMR_DefaultRole',
   BootstrapActions= make_bootstrap(),
   Steps=[{'HadoopJarStep': {'Args': ['spark-submit', '/usr/local/bin/upload_noaa1_to_s3.py', '--test' ], 'Jar': 'command-runner.jar'},
   Applications =  [
        {
            "Name": "Hadoop",
        },
        {
            "Name": "Spark",
        }
    ],

    Configurations = [{
        'Classification': 'spark-log4j',
        'Properties': {
            'log4j.rootCategory': 'ERROR, console'
        }
    }, {
        'Classification': 'spark-defaults',
        'Properties': {
            'spark.ui.showConsoleProgress': 'false'
            #'spark.eventLog.dir':'hdfs:///var/log/spark/apps'
            # could set above line to s3:
        }

    }, {
        'Classification': 'spark-env',
        'Properties': {},
        'Configurations': [{
            'Classification': 'export',
            'Properties': {
                'PYSPARK_PYTHON': 'python34',
                'PYSPARK_DRIVER_PYTHON': 'python34'
            }
        }]
    }],
   )
print(response)


text:
from msrest.serialization import Model

class KnowledgebasesDTO(Model):
    """Collection of knowledgebases owned by a user.

    :param knowledgebases: Collection of knowledgebase records.
    :type knowledgebases:
     list[~azure.cognitiveservices.knowledge.qnamaker.models.KnowledgebaseDTO]
    """

    _attribute_map = {
        'knowledgebases': {'key': 'knowledgebases', 'type': '[KnowledgebaseDTO]'},
    }

    def __init__(self, *, knowledgebases=None, **kwargs) -> None:
        super(KnowledgebasesDTO, self).__init__(**kwargs)
        self.knowledgebases = knowledgebases