// ExtractInsidePolygon returns the first found InsidePolygonOption from the
// given variadic arguments or nil otherwise.
328648
func ExtractInsidePolygon(opts ...interface{}) *opt.InsidePolygonOption {
	for _, o := range opts {
		if v, ok := o.(*opt.InsidePolygonOption); ok {
			return v
		}
	}
	return nil
}
115265
func ExtractDisableTypoToleranceOnWords(opts ...interface{}) *opt.DisableTypoToleranceOnWordsOption {
	for _, o := range opts {
		if v, ok := o.(*opt.DisableTypoToleranceOnWordsOption); ok {
			return v
		}
	}
	return nil
}
189958
func (o *InsidePolygonOption) Get() ([][]float64, string) {
	if o == nil {
		return nil, ""
	}
	return o.polygons, o.coordinates
}
310135
func (self *AttributeImpl) removeIn(id int) {
	for i, e := range self.edge {
		if e.dest().id() == self.id() && e.src().id() == id {
			self.dropIthEdge(i)
			//MUST break here because the content of self.edge changed
			break
		}
	}
}
1271185
func pointInPolygon(x float64, y float64, points []float64) bool {
	if len(points) < 8 { // 只有2个以上的点，才能组成闭合多边形
		return false
	}

	// 大致算法如下：
	// 把整个平面以给定的测试点为原点分两部分:
	// - y>0，包含(x>0 && y==0)
	// - y<0，包含(x<0 && y==0)
	// 依次扫描每一个点，当该点与前一个点处于不同部分时（即一个在 y>0 区，一个在 y<0 区），
	// 则判断从前一点到当前点是顺时针还是逆时针（以给定的测试点为原点），如果是顺时针 r++，否则 r--。
	// 结果为：2==abs(r)。

	r := 0
	x1, y1 := points[0], points[1]
	prev := (y1 > y) || ((x1 > x) && (y1 == y))
	for i := 2; i < len(points); i += 2 {
		x2, y2 := points[i], points[i+1]
		curr := (y2 > y) || ((x2 > x) && (y2 == y))

		if curr == prev {
			x1, y1 = x2, y2
			continue
		}

		mul := (x1-x)*(y2-y) - (x2-x)*(y1-y)
		if mul > 0 {
			r++
		} else if mul < 0 {
			r--
		}
		x1, y1 = x2, y2
		prev = curr
	}

	return r == 2 || r == -2
}
808657
func ExtractFacets(opts ...interface{}) *opt.FacetsOption {
	for _, o := range opts {
		if v, ok := o.(*opt.FacetsOption); ok {
			return v
		}
	}
	return nil
}
999231
func (l *Loop) initOriginAndBound() {
	if len(l.vertices) < 3 {
		// Check for the special "empty" and "full" loops (which have one vertex).
		if !l.isEmptyOrFull() {
			l.originInside = false
			return
		}

		// This is the special empty or full loop, so the origin depends on if
		// the vertex is in the southern hemisphere or not.
		l.originInside = l.vertices[0].Z < 0
	} else {
		// Point containment testing is done by counting edge crossings starting
		// at a fixed point on the sphere (OriginPoint). We need to know whether
		// the reference point (OriginPoint) is inside or outside the loop before
		// we can construct the ShapeIndex. We do this by first guessing that
		// it is outside, and then seeing whether we get the correct containment
		// result for vertex 1. If the result is incorrect, the origin must be
		// inside the loop.
		//
		// A loop with consecutive vertices A,B,C contains vertex B if and only if
		// the fixed vector R = B.Ortho is contained by the wedge ABC. The
		// wedge is closed at A and open at C, i.e. the point B is inside the loop
		// if A = R but not if C = R. This convention is required for compatibility
		// with VertexCrossing. (Note that we can't use OriginPoint
		// as the fixed vector because of the possibility that B == OriginPoint.)
		l.originInside = false
		v1Inside := OrderedCCW(Point{l.vertices[1].Ortho()}, l.vertices[0], l.vertices[2], l.vertices[1])
		if v1Inside != l.ContainsPoint(l.vertices[1]) {
			l.originInside = true
		}
	}

	// We *must* call initBound before initializing the index, because
	// initBound calls ContainsPoint which does a bounds check before using
	// the index.
	l.initBound()

	// Create a new index and add us to it.
	l.index = NewShapeIndex()
	l.index.Add(l)
}
934749
func ExtractPrimary(opts ...interface{}) *opt.PrimaryOption {
	for _, o := range opts {
		if v, ok := o.(*opt.PrimaryOption); ok {
			return v
		}
	}
	return nil
}
637089
func (s *ISOService) GetIsoID(name string, isofilter string, zoneid string, opts ...OptionFunc) (string, int, error) {
	p := &ListIsosParams{}
	p.p = make(map[string]interface{})

	p.p["name"] = name
	p.p["isofilter"] = isofilter
	p.p["zoneid"] = zoneid

	for _, fn := range append(s.cs.options, opts...) {
		if err := fn(s.cs, p); err != nil {
			return "", -1, err
		}
	}

	l, err := s.ListIsos(p)
	if err != nil {
		return "", -1, err
	}

	if l.Count == 0 {
		return "", l.Count, fmt.Errorf("No match found for %s: %+v", name, l)
	}

	if l.Count == 1 {
		return l.Isos[0].Id, l.Count, nil
	}

	if l.Count > 1 {
		for _, v := range l.Isos {
			if v.Name == name {
				return v.Id, l.Count, nil
			}
		}
	}
	return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", name, l)
}
1172784
func ExtractQuery(opts ...interface{}) *opt.QueryOption {
	for _, o := range opts {
		if v, ok := o.(*opt.QueryOption); ok {
			return v
		}
	}
	return nil
}
1219535
func (o InsidePolygonOption) MarshalJSON() ([]byte, error) {
	if o.coordinates != "" {
		return json.Marshal(o.coordinates)
	}
	return json.Marshal(o.polygons)
}
371437
func MultiPolygon(mp orb.MultiPolygon, proj orb.Projection) orb.MultiPolygon {
	for i := range mp {
		mp[i] = Polygon(mp[i], proj)
	}

	return mp
}
382942
func ExtractRestrictIndices(opts ...interface{}) *opt.RestrictIndicesOption {
	for _, o := range opts {
		if v, ok := o.(*opt.RestrictIndicesOption); ok {
			return v
		}
	}
	return nil
}
1195251
func ExtractDecompoundedAttributes(opts ...interface{}) *opt.DecompoundedAttributesOption {
	for _, o := range opts {
		if v, ok := o.(*opt.DecompoundedAttributesOption); ok {
			return v
		}
	}
	return nil
}
1135877
func ExtractQueryType(opts ...interface{}) *opt.QueryTypeOption {
	for _, o := range opts {
		if v, ok := o.(*opt.QueryTypeOption); ok {
			return v
		}
	}
	return nil
}
334880
func (o *InsidePolygonOption) UnmarshalJSON(data []byte) error {
	if string(data) == "null" {
		return nil
	}

	var polygons [][]float64
	if err := json.Unmarshal(data, &polygons); err == nil {
		o.polygons = polygons
		return nil
	}

	var coordinates string
	if err := json.Unmarshal(data, &coordinates); err == nil {
		o.coordinates = coordinates
		return nil
	}

	return errs.ErrJSONDecode(data, "InsidePolygon")
}
346132
func ExtractFilters(opts ...interface{}) *opt.FiltersOption {
	for _, o := range opts {
		if v, ok := o.(*opt.FiltersOption); ok {
			return v
		}
	}
	return nil
}