// MultiPolygon creates a tile cover for the multi-polygon.
357459
func MultiPolygon(mp orb.MultiPolygon, z maptile.Zoom) maptile.Set {
	set := make(maptile.Set)
	for _, p := range mp {
		polygon(set, p, z)
	}

	return set
}
1065542
func (p *Polygon) initNested() {
	if len(p.loops) == 1 {
		p.initOneLoop()
		return
	}

	lm := make(loopMap)

	for _, l := range p.loops {
		lm.insertLoop(l, nil)
	}
	// The loops have all been added to the loopMap for ordering. Clear the
	// loops slice because we add all the loops in-order in initLoops.
	p.loops = nil

	// Reorder the loops in depth-first traversal order.
	p.initLoops(lm)
	p.initLoopProperties()
}
49888
func MultiPolygon(b orb.Bound, mp orb.MultiPolygon) orb.MultiPolygon {
	var result orb.MultiPolygon
	for _, polygon := range mp {
		p := Polygon(b, polygon)
		if p != nil {
			result = append(result, p)
		}
	}

	return result
}
850473
func (p *Polygon) initLoops(lm loopMap) {
	var stack loopStack
	stack.push(nil)
	depth := -1

	for len(stack) > 0 {
		loop := stack.pop()
		if loop != nil {
			depth = loop.depth
			p.loops = append(p.loops, loop)
		}
		children := lm[loop]
		for i := len(children) - 1; i >= 0; i-- {
			child := children[i]
			child.depth = depth + 1
			stack.push(child)
		}
	}
}
262108
func NewPolygon(verts Vertices, offset vect.Vect) *Shape {
	if verts == nil {
		log.Printf("Error: no vertices passed!")
		return nil
	}

	shape := newShape()
	poly := &PolygonShape{Shape: shape}

	poly.SetVerts(verts, offset)

	shape.ShapeClass = poly
	return shape
}
1367418
func (stc *ScatterConn) multiGo(
	ctx context.Context,
	name string,
	rss []*srvtopo.ResolvedShard,
	tabletType topodatapb.TabletType,
	action shardActionFunc,
) (allErrors *concurrency.AllErrorRecorder) {
	allErrors = new(concurrency.AllErrorRecorder)
	if len(rss) == 0 {
		return allErrors
	}

	oneShard := func(rs *srvtopo.ResolvedShard, i int) {
		var err error
		startTime, statsKey := stc.startAction(name, rs.Target)
		defer stc.endAction(startTime, allErrors, statsKey, &err, nil)
		err = action(rs, i)
	}

	if len(rss) == 1 {
		// only one shard, do it synchronously.
		oneShard(rss[0], 0)
		return allErrors
	}

	var wg sync.WaitGroup
	for i, rs := range rss {
		wg.Add(1)
		go func(rs *srvtopo.ResolvedShard, i int) {
			defer wg.Done()
			oneShard(rs, i)
		}(rs, i)
	}
	wg.Wait()
	return allErrors
}
652881
func NewMultiLayerNet(layers []int) *MultiLayerNet {
	return &MultiLayerNet{
		nil,
		make(map[base.Attribute]int),
		layers,
		0,
		0,
		0.001,
		500,
		0.90,
	}
}
812825
func (o *outerJoinEliminator) isDuplicateAgnosticAgg(p LogicalPlan) (_ bool, cols []*expression.Column) {
	agg, ok := p.(*LogicalAggregation)
	if !ok {
		return false, nil
	}
	cols = agg.groupByCols
	for _, aggDesc := range agg.AggFuncs {
		if !aggDesc.HasDistinct &&
			aggDesc.Name != ast.AggFuncFirstRow &&
			aggDesc.Name != ast.AggFuncMax &&
			aggDesc.Name != ast.AggFuncMin {
			return false, nil
		}
		for _, expr := range aggDesc.Args {
			if col, ok := expr.(*expression.Column); ok {
				cols = append(cols, col)
			} else {
				return false, nil
			}
		}
	}
	return true, cols
}
486116
func Ring(box orb.Bound, r orb.Ring, o orb.Orientation) orb.MultiPolygon {
	if len(r) == 0 {
		return nil
	}

	open, closed := clipRings(box, []orb.Ring{r})
	if len(open) == 0 {
		// nothing was clipped
		if len(closed) == 0 {
			return nil // everything outside bound
		}

		return orb.MultiPolygon{{r}} // everything inside bound
	}

	// in a well defined ring there will be no closed sections
	return smartWrap(box, open, o)
}
98127
func (calc *AreaCentroidCalculator) AddPolygon(polygon *geom.Polygon) {
	calc.setBasePoint(polygon.Coord(0))

	calc.addShell(polygon.LinearRing(0).FlatCoords())
	for i := 1; i < polygon.NumLinearRings(); i++ {
		calc.addHole(polygon.LinearRing(i).FlatCoords())
	}
}
656439
public static MultiPolygon removeHolesMultiPolygon(MultiPolygon multiPolygon) {
        int num = multiPolygon.getNumGeometries();
        Polygon[] polygons = new Polygon[num];
        for (int i = 0; i < num; i++) {
            polygons[i] = removeHolesPolygon((Polygon) multiPolygon.getGeometryN(i));
        }
        return multiPolygon.getFactory().createMultiPolygon(polygons);
    }
670718
func (b *Bounds) Polygon() *Polygon {
	if b.IsEmpty() {
		return NewPolygonFlat(XY, nil, nil)
	}
	x1, y1 := b.min[0], b.min[1]
	x2, y2 := b.max[0], b.max[1]
	flatCoords := []float64{
		x1, y1,
		x1, y2,
		x2, y2,
		x2, y1,
		x1, y1,
	}
	return NewPolygonFlat(XY, flatCoords, []int{len(flatCoords)})
}
281942
func (mp MultiPolygon) Equal(multiPolygon MultiPolygon) bool {
	if len(mp) != len(multiPolygon) {
		return false
	}

	for i, p := range mp {
		if !p.Equal(multiPolygon[i]) {
			return false
		}
	}

	return true
}
553655
func (mp MultiPolygon) WKT() string {
	var result string
	switch len(mp.Coordinates) {
	case 0:
		result = "MULTIPOLYGON EMPTY"
	default:
		result = fmt.Sprintf("MULTIPOLYGON (%v)", array4ToWKTCoordinates(mp.Coordinates))
	}
	return result
}
819253
func (shape *Shape) GetAsPolygon() *PolygonShape {
	if poly, ok := shape.ShapeClass.(*PolygonShape); ok {
		return poly
	}

	return nil
}
1132543
func (p *Polygon) excludesNonCrossingComplementShells(o *Polygon) bool {
	// Special case to handle the complement of the empty or full polygons.
	if o.IsEmpty() {
		return !p.IsFull()
	}
	if o.IsFull() {
		return true
	}

	// Otherwise the complement of B may be obtained by inverting loop(0) and
	// then swapping the shell/hole status of all other loops. This implies
	// that the shells of the complement consist of loop 0 plus all the holes of
	// the original polygon.
	for j, l := range o.loops {
		if j > 0 && !l.IsHole() {
			continue
		}

		// The interior of the complement is to the right of loop 0, and to the
		// left of the loops that were originally holes.
		if p.containsNonCrossingBoundary(l, j == 0) {
			return false
		}
	}
	return true
}
590364
func (g *MultiPolygon) Polygon(i int) *Polygon {
	offset := 0
	if i > 0 {
		ends := g.endss[i-1]
		offset = ends[len(ends)-1]
	}
	ends := make([]int, len(g.endss[i]))
	if offset == 0 {
		copy(ends, g.endss[i])
	} else {
		for j, end := range g.endss[i] {
			ends[j] = end - offset
		}
	}
	return NewPolygonFlat(g.layout, g.flatCoords[offset:g.endss[i][len(g.endss[i])-1]], ends)
}