Calculate ids of ways whose polygon inherits part elements.
162823
protected void handleImplicitWayRelations() {
        if (!this.tagValues) {
            return;
        }

        /*int progressImplicitRelations = 0;
        float limitImplicitRelations = this.tilesToPartElements.entrySet().size();*/

        // Iterate through tiles which contain parts
        for (Map.Entry<TileCoordinate, TLongHashSet> tilePartElementEntry : this.tilesToPartElements.entrySet()) {
            TLongHashSet tileRootElementSet = this.tilesToRootElements.get(tilePartElementEntry.getKey());

            // Continue if no part or no roots are in list; maybe unnecessary
            if (tileRootElementSet == null || tileRootElementSet.isEmpty()
                    || tilePartElementEntry.getValue().isEmpty()) {
                continue;
            }

            // Log
            /*String wayRelLog = "Progress: Implicit relations "
                    + ((int) ((progressImplicitRelations / limitImplicitRelations) * 100))
                    + "%% - Tile (" + tilePartElementEntry.getKey().getX()
                    + ", " + tilePartElementEntry.getKey().getY() + ")";
            progressImplicitRelations++;
            int nRootElements = 0;*/

            // Load parts only once in cache
            List<TDWay> pElems = new ArrayList<>();
            TLongIterator tilePartElementIterator = tilePartElementEntry.getValue().iterator();
            while (tilePartElementIterator.hasNext()) {
                TDWay pElem = getWay(tilePartElementIterator.next());
                pElems.add(pElem);
            }

            // Iterate through potential roots
            TLongIterator tileRootElementIterator = tileRootElementSet.iterator();
            while (tileRootElementIterator.hasNext()) {
                /*if(this.progressLogs) {
                    if (++nRootElements % 1000 == 0) {
                        System.out.print((wayRelLog + " - Elements " + nfCounts.format(nRootElements) + "\r"));
                    }
                }*/

                // Init root element
                TDWay rElem = getWay(tileRootElementIterator.next());
                BoundingBox rBox = GeoUtils.mapWayToBoundingBox(rElem);
                if (rBox == null) {
                    continue;
                }
                Polygon rPolygon = null; // Lazy initialization, because root may not be needed

                // Iterate through parts
                for (int i = pElems.size() - 1; i >= 0; i--) {
                    TDWay pElem = pElems.get(i);

                    // Exclude most elements with bounding box
                    if (pElem.getWayNodes().length < 3) {
                        continue;
                    }
                    if (!rBox.contains(LatLongUtils.microdegreesToDegrees(pElem.getWayNodes()[0].getLatitude()),
                            LatLongUtils.microdegreesToDegrees(pElem.getWayNodes()[0].getLongitude()))) {
                        continue;
                    }

                    // Now calculate exact polygons
                    Polygon pPolygon = GeoUtils.mapWayToPolygon(pElem);
                    if (pPolygon == null) {
                        continue;
                    }

                    if (rPolygon == null) {
                        rPolygon = GeoUtils.mapWayToPolygon(rElem);
                        if (rPolygon == null) {
                            continue;
                        }
                    }

                    /* Use interior point cause
                     * - boundary points may intersect with other geometries
                     * - part polygon often not completely covered by root polygon
                     */
                    if (rPolygon.covers(pPolygon.getInteriorPoint())) {
                        // Memorize multi-polygons
                        if (!this.partRootRelations.containsKey(rElem.getId())) {
                            this.partRootRelations.put(rElem.getId(), null); // Add root element
                        }
                        this.partRootRelations.put(pElem.getId(), rElem.getId()); // Add part element

                        // Remove part which is already referenced
                        pElems.remove(pElem);
                        tilePartElementEntry.getValue().remove(pElem.getId());
                    }
                }
            }
        }
        LOGGER.info("calculated " + nfCounts.format(partRootRelations.size()) + " implicit relations");
    }
791071
def name_parts(self):
        """"""

        default = PartialMixin.ANY

        np = ([(k, default, True)
               for k, _, _ in super(NameQuery, self).name_parts]
              +
              [(k, default, True)
               for k, _, _ in Name._generated_names]
              )

        return np
910761
def allPolygons(self):
        
        polygons = self.polygons[:]
        if self.front: 
            polygons.extend(self.front.allPolygons())
        if self.back: 
            polygons.extend(self.back.allPolygons())
        return polygons
925456
def each_object_id(collection):
    """"""
    c_path = collection_path(collection)
    paths = glob('%s/*.%s' % (c_path, _ext))
    for path in paths:
        match = regex.match(r'.+/(.+)\.%s$' % _ext, path)
        yield match.groups()[0]
146316
private static Map<Elements, String> casIds() {
        Map<Elements, String> result = ids;
        if (result == null) {
            synchronized (LOCK) {
                result = ids;
                if (result == null) {
                    ids = result = initCasIds();
                }
            }
        }
        return result;
    }
1092453
def _coords(shape):
    

    assert shape.geom_type == 'Polygon'
    coords = [list(shape.exterior.coords)]
    for interior in shape.interiors:
        coords.append(list(interior.coords))
    return coords
73532
private void assignAsymIds(List<List<Chain>> polys, List<List<Chain>> nonPolys, List<List<Chain>> waters) {

		for (int i=0; i<polys.size(); i++) {
			String asymId = "A";

			for (Chain poly:polys.get(i)) {
				poly.setId(asymId);
				asymId = getNextAsymId(asymId);
			}
			for (Chain nonPoly:nonPolys.get(i)) {
				nonPoly.setId(asymId);
				asymId = getNextAsymId(asymId);
			}
			for (Chain water:waters.get(i)) {
				water.setId(asymId);
				asymId = getNextAsymId(asymId);
			}
		}
	}
150495
def __regpoly_coords(self, x0, y0, x1, y1, sides, start, extent):
        """"""

        coords = []
        if extent == 0:
            return coords

        xm = (x0 + x1) / 2.
        ym = (y0 + y1) / 2.
        rx = xm - x0
        ry = ym - y0

        n = sides
        if n == 0: # 0 sides => circle
            n = round((rx + ry) * .5)
            if n < 2:
                n = 4

        # Extent can be negative
        dirv = 1 if extent > 0 else -1
        if abs(extent) > 360:
            extent = dirv * abs(extent) % 360

        step = dirv * 360 / n
        numsteps = 1 + extent / float(step)
        numsteps_int = int(numsteps)

        i = 0
        while i < numsteps_int:
            rad = (start - i * step) * DEG2RAD
            x = rx * math.cos(rad)
            y = ry * math.sin(rad)
            coords.append((xm+x, ym-y))
            i += 1

        # Figure out where last segment should end
        if numsteps != numsteps_int:
            # Vecter V1 is last drawn vertext (x,y) from above
            # Vector V2 is the edge of the polygon
            rad2 = (start - numsteps_int * step) * DEG2RAD
            x2 = rx * math.cos(rad2) - x
            y2 = ry * math.sin(rad2) - y

            # Vector V3 is unit vector in direction we end at
            rad3 = (start - extent) * DEG2RAD
            x3 = math.cos(rad3)
            y3 = math.sin(rad3)

            # Find where V3 crosses V1+V2 => find j s.t.  V1 + kV2 = jV3
            j = (x*y2 - x2*y) / (x3*y2 - x2*y3)

            coords.append((xm + j * x3, ym - j * y3))

        return coords
471561
def partsphere(self, x):
        """"""
        self.counter += 1
        # return np.random.rand(1)[0]**0 * sum(x**2) + 1 * np.random.rand(1)[0]
        dim = len(x)
        x = array([x[i % dim] for i in xrange(2 * dim)])
        N = 8
        i = self.counter % dim
        # f = sum(x[i:i + N]**2)
        f = sum(x[np.random.randint(dim, size=N)]**2)
        return f
585453
def neighbors(self, node_id):
        """"""
        node = self.get_node(node_id)
        flattened_nodes_list = []
        for a, b in [self.get_edge(edge_id)['vertices'] for edge_id in node['edges']]:
            flattened_nodes_list.append(a)
            flattened_nodes_list.append(b)
        node_set = set(flattened_nodes_list)
        if node_id in node_set:
            node_set.remove(node_id)
        return [nid for nid in node_set]
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
  }
}
857713
def multi_polygons_data(element):
    
    paths = element.split(datatype='array', dimensions=element.kdims)
    xs, ys = ([path[:, idx] for path in paths] for idx in (0, 1))
    holes = element.holes()
    xsh, ysh = [], []
    for x, y, multi_hole in zip(xs, ys, holes):
        xhs = [[h[:, 0] for h in hole] for hole in multi_hole]
        yhs = [[h[:, 1] for h in hole] for hole in multi_hole]
        array = np.column_stack([x, y])
        splits = np.where(np.isnan(array[:, :2].astype('float')).sum(axis=1))[0]
        arrays = np.split(array, splits+1) if len(splits) else [array]
        multi_xs, multi_ys = [], []
        for i, (path, hx, hy) in enumerate(zip(arrays, xhs, yhs)):
            if i != (len(arrays)-1):
                path = path[:-1]
            multi_xs.append([path[:, 0]]+hx)
            multi_ys.append([path[:, 1]]+hy)
        xsh.append(multi_xs)
        ysh.append(multi_ys)
    return xsh, ysh
704224
def get_child_ids(self):
        """"""
        if self.has_magic_children():
            if self._child_parts is None:
                self.generate_children()
            child_ids = list()
            for part in self._child_parts:
                child_ids.append(part.get_id())
            return IdList(child_ids,
                          runtime=self.my_osid_object._runtime,
                          proxy=self.my_osid_object._runtime)
        raise IllegalState()
794101
function(o) {
        for (i in o) {
            if (!!o[i] && typeof(o[i]) == "object") {
                if (!o[i].length && o[i].type === 'tag') {
                    nodeCount += 1;
                    o[i]._id = nodeCount;
                }
                traverseIds(o[i]);
            }
        }
    }
514772
private int segdir(double xend, double yend, int[] ij) {
        if (YMATCH(yend, y[ij[1]])) {
            if (ij[1] == 0) {
                return 0;
            }
            ij[1] -= 1;
            return 3;
        }

        if (XMATCH(xend, x[ij[0]])) {
            if (ij[0] == 0) {
                return 0;
            }
            ij[0] -= 1;
            return 4;
        }

        if (YMATCH(yend, y[ij[1] + 1])) {
            if (ij[1] >= y.length - 1) {
                return 0;
            }
            ij[1] += 1;
            return 1;
        }

        if (XMATCH(xend, x[ij[0] + 1])) {
            if (ij[0] >= x.length - 1) {
                return 0;
            }
            ij[0] += 1;
            return 2;
        }

        return 0;
    }
1062010
function getCentroidFeatureForPolygon (coordinates, properties, newProperties) {
    let centroid = Geo.centroid(coordinates);
    if (!centroid) {
        return;
    }

    // clone properties and mixix newProperties
    let centroid_properties = {};
    Object.assign(centroid_properties, properties, newProperties);

    return {
        type: 'Feature',
        properties: centroid_properties,
        geometry: {
            type: 'Point',
            coordinates: centroid
        }
    };
}
1059920
function polygonDecomp(polygon){
    var edges = polygonGetCutEdges(polygon);
    if(edges.length > 0){
        return polygonSlice(polygon, edges);
    } else {
        return [polygon];
    }
}