TODO move into ddogleg? primitive flip  <--- I think this is specific to polygons
960190
public static void flip( int []a , int N ) {
		int H = N/2;

		for (int i = 1; i <= H; i++) {
			int j = N-i;
			int tmp = a[i];
			a[i] = a[j];
			a[j] = tmp;
		}
	}
913005
function polygonClosed(coordinates) {
  var a = coordinates[0],
      b = coordinates[coordinates.length - 1];
  return !(a[0] - b[0] || a[1] - b[1]);
}
695171
static boolean pointInPolygon(float[] pt, float[] verts, int nverts) {
        // TODO: Replace pnpoly with triArea2D tests?
        int i, j;
        boolean c = false;
        for (i = 0, j = nverts - 1; i < nverts; j = i++) {
            int vi = i * 3;
            int vj = j * 3;
            if (((verts[vi + 2] > pt[2]) != (verts[vj + 2] > pt[2])) && (pt[0] < (verts[vj + 0] - verts[vi + 0])
                    * (pt[2] - verts[vi + 2]) / (verts[vj + 2] - verts[vi + 2]) + verts[vi + 0])) {
                c = !c;
            }
        }
        return c;
    }
116405
def is_clockwise(vertices):
    
    it = iterator.consecutive(cycle(vertices), 3)
    clockwise = 0
    counter = 0
    for _ in range(len(vertices)):
        p0, p1, p2 = next(it)
        cross = cross_product(p1, p2, p0)
        int_angle = interior_angle(p0, p2, p1)  # raises ValueError
        if cross < 0:
            clockwise += int_angle
            counter += 2 * pi - int_angle
        else:
            clockwise += 2 * pi - int_angle
            counter += int_angle
    if round(clockwise / pi) == len(vertices) - 2:
        return True
    elif round(counter / pi) == len(vertices) - 2:
        return False
    else:
        raise ValueError("the polygon is complex or overlapped")
843351
function polygonAt(polygon, i){
    var s = polygon.length;
    return polygon[i < 0 ? i % s + s : i % s];
}
934030
int filterClosePoints(double tolerance, boolean b_remove_last_vertices, boolean only_polygons) {
		int res = 0;
		for (int geometry = getFirstGeometry(); geometry != -1; geometry = getNextGeometry(geometry)) {
			int gt = getGeometryType(geometry);
			if (!Geometry.isMultiPath(gt))
				continue;
			if (only_polygons && gt != GeometryType.Polygon)
				continue;

			boolean b_polygon = getGeometryType(geometry) == Geometry.GeometryType.Polygon;

			for (int path = getFirstPath(geometry); path != -1;) {
				// We go from the start to the half of the path first, then we
				// go from the end to the half of the path.
				int vertex_counter = 0;
				for (int vertex = getFirstVertex(path); vertex_counter < getPathSize(path) / 2;) {
					int next = getNextVertex(vertex);
					if (next == -1)
						break;
					int vindex = getVertexIndex(vertex);
					Segment seg = getSegmentFromIndex_(vindex);
					double length = 0;
					if (seg != null) {
						length = seg.calculateLength2D();
					} else {
						int vindex_next = getVertexIndex(next);
						length = m_vertices._getShortestDistance(vindex,
								vindex_next);
					}

					if (length <= tolerance) {
						if (length == 0) {
							if (res == 0)
								res = -1;
						} else
							res = 1;

						if (next != getLastVertex(path)) {
							transferAllDataToTheVertex(next, vertex);
							removeVertex(next, true);
						}
					} else {
						vertex = getNextVertex(vertex);
					}
					vertex_counter++;
				}

				int first_vertex = getFirstVertex(path);
				for (int vertex = isClosedPath(path) ? first_vertex
						: getLastVertex(path); getPathSize(path) > 0;) {
					int prev = getPrevVertex(vertex);
					if (prev != -1) {
						int vindex_prev = getVertexIndex(prev);
						Segment seg = getSegmentFromIndex_(vindex_prev);
						double length = 0;
						if (seg != null) {
							length = seg.calculateLength2D();
						} else {
							int vindex = getVertexIndex(vertex);
							length = m_vertices._getShortestDistance(vindex,
									vindex_prev);
						}

						if (length <= tolerance) {
							if (length == 0) {
								if (res == 0)
									res = -1;
							} else
								res = 1;

							transferAllDataToTheVertex(prev, vertex);
							removeVertex(prev, false);
							if (first_vertex == prev)
								first_vertex = getFirstVertex(path);
						} else {
							vertex = getPrevVertex(vertex);
							if (vertex == first_vertex)
								break;
						}
					} else {
						removeVertex(vertex, true);// remove the last vertex in
													// the path
						if (res == 0)
							res = -1;
						break;
					}
				}

				int path_size = getPathSize(path);
				if (b_remove_last_vertices
						&& (b_polygon ? path_size < 3 : path_size < 2)) {
					path = removePath(path);
					res = path_size > 0 ? 1 : (res == 0 ? -1 : res);
				} else
					path = getNextPath(path);
			}
		}

		return res;
	}
152968
private void verbosePolyCmd(String pCmd, Rectangle pBounds, Polygon pPolygon) {
        System.out.println(pCmd + ": " + pBounds);
        System.out.print("Polygon points: ");
        if (pPolygon != null && pPolygon.npoints > 0) {
            System.out.print("(" + pPolygon.xpoints[0] + "," + pPolygon.ypoints[0] + ")");
        }
        for (int i = 1; pPolygon != null && i < pPolygon.npoints; i++) {
            System.out.print(", (" + pPolygon.xpoints[i] + "," + pPolygon.ypoints[i] + ")");
        }
        System.out.println();
    }
787183
def copy(self, invert=False):
        
        if invert:
            inverted = not self.inverted
        else:
            inverted = self.inverted

        return PolygonFilter(axes=self.axes,
                             points=self.points,
                             name=self.name,
                             inverted=inverted)
328993
public static <K, V> UnifiedSetMultimap<V, K> flip(SetMultimap<K, V> setMultimap)
    {
        final UnifiedSetMultimap<V, K> result = new UnifiedSetMultimap<V, K>();
        setMultimap.forEachKeyMultiValues(new Procedure2<K, Iterable<V>>()
        {
            public void value(final K key, Iterable<V> values)
            {
                Iterate.forEach(values, new Procedure<V>()
                {
                    public void value(V value)
                    {
                        result.put(value, key);
                    }
                });
            }
        });
        return result;
    }
745209
public static boolean convert( LineGeneral2D_F64[] lines , Polygon2D_F64 poly ) {

		for (int i = 0; i < poly.size(); i++) {
			int j = (i + 1) % poly.size();
			if( null == Intersection2D_F64.intersection(lines[i], lines[j], poly.get(j)) )
				return false;
		}

		return true;
	}
243511
function(polygons, bbox) {
        for (var i = 0; i < polygons.length; i++) {
            if (this.bboxIntersectsPolygon(polygons[i], bbox))
                return true;
        }
        return false;
    }
618043
function flip(obj) {
              var newObj = Object.create(null),
                  key;

              for (key in obj) {
                newObj[obj[key]] = key;
              }

              return newObj;
            }
164594
public static <K, V> HashBagMultimap<V, K> flip(BagMultimap<K, V> bagMultimap)
    {
        final HashBagMultimap<V, K> result = new HashBagMultimap<V, K>();
        bagMultimap.forEachKeyMultiValues(new Procedure2<K, Iterable<V>>()
        {
            public void value(final K key, Iterable<V> values)
            {
                Iterate.forEach(values, new Procedure<V>()
                {
                    public void value(V value)
                    {
                        result.put(value, key);
                    }
                });
            }
        });
        return result;
    }
1126710
function isPointInsidePoly(point, polygon) {
    let i,
        nvert = polygon.length,
        j = nvert - 1,
        c = false;
    for (i = 0; i < nvert; j = i++) {
        if (((polygon[i].lon > point.lon) !== (polygon[j].lon > point.lon)) &&
            (point.lat < (polygon[j].lat - polygon[i].lat) * (point.lon - polygon[i].lon) /
            (polygon[j].lon - polygon[i].lon) + polygon[i].lat)) {
            c = !c;
            //console.log(i, j, polygon[i].lon, '>', point.lon, c);
        }
    }
    return c;
}
1261095
public static int[] flip(int[] src, int[] dest, final int start, final int length)
	{
		if (dest == null || dest.length < length)
			dest = new int[length];

		int srcIndex = start + length;
		for (int i = 0; i < length; i++)
		{
			dest[i] = src[--srcIndex];
		}

		return dest;
	}
16989
function polygonToPSLG(loops, options) {
  if(!Array.isArray(loops)) {
    throw new Error('poly-to-pslg: Error, invalid polygon')
  }
  if(loops.length === 0) {
    return {
      points: [],
      edges:  []
    }
  }

  options = options || {}

  var nested = true
  if('nested' in options) {
    nested = !!options.nested
  } else if(loops[0].length === 2 && typeof loops[0][0] === 'number') {
    //Hack:  If use doesn't pass in a loop, then try to guess if it is nested
    nested = false
  }
  if(!nested) {
    loops = [loops]
  }

  //First we just unroll all the points in the dumb/obvious way
  var points = []
  var edges = []
  for(var i=0; i<loops.length; ++i) {
    var loop = loops[i]
    var offset = points.length
    for(var j=0; j<loop.length; ++j) {
      points.push(loop[j])
      edges.push([ offset+j, offset+(j+1)%loop.length ])
    }
  }

  //Then we run snap rounding to clean up self intersections and duplicate verts
  var clean = 'clean' in options ? true : !!options.clean
  if(clean) {
    cleanPSLG(points, edges)
  }

  //Finally, we return the resulting PSLG
  return {
    points: points,
    edges:  edges
  }
}
1136697
public boolean flip(int bitIndex)
    {
        int wordIndex = wordIndex(bitIndex);
        words[wordIndex] ^= (1L << bitIndex);
        
        return ((words[wordIndex] & (1L << bitIndex)) != 0);
    }