// PointFromLatLng returns an Point for the given LatLng.
// The maximum error in the result is 1.5 * dblEpsilon. (This does not
// include the error of converting degrees, E5, E6, or E7 into radians.)
557168
func PointFromLatLng(ll LatLng) Point {
	phi := ll.Lat.Radians()
	theta := ll.Lng.Radians()
	cosphi := math.Cos(phi)
	return Point{r3.Vector{math.Cos(theta) * cosphi, math.Sin(theta) * cosphi, math.Sin(phi)}}
}
1318546
func GeoPointFromString(latLon string) (*GeoPoint, error) {
	latlon := strings.SplitN(latLon, ",", 2)
	if len(latlon) != 2 {
		return nil, fmt.Errorf("elastic: %s is not a valid geo point string", latLon)
	}
	lat, err := strconv.ParseFloat(latlon[0], 64)
	if err != nil {
		return nil, err
	}
	lon, err := strconv.ParseFloat(latlon[1], 64)
	if err != nil {
		return nil, err
	}
	return &GeoPoint{Lat: lat, Lon: lon}, nil
}
866678
func referencePointAtVertex(shape Shape, vTest Point) (ReferencePoint, bool) {
	var ref ReferencePoint

	// Let P be an unbalanced vertex. Vertex P is defined to be inside the
	// region if the region contains a particular direction vector starting from
	// P, namely the direction p.Ortho(). This can be calculated using
	// ContainsVertexQuery.

	containsQuery := NewContainsVertexQuery(vTest)
	n := shape.NumEdges()
	for e := 0; e < n; e++ {
		edge := shape.Edge(e)
		if edge.V0 == vTest {
			containsQuery.AddEdge(edge.V1, 1)
		}
		if edge.V1 == vTest {
			containsQuery.AddEdge(edge.V0, -1)
		}
	}
	containsSign := containsQuery.ContainsVertex()
	if containsSign == 0 {
		return ref, false // There are no unmatched edges incident to this vertex.
	}
	ref.Point = vTest
	ref.Contained = containsSign > 0

	return ref, true
}
77862
func (p Point) String() string {
	return fmt.Sprintf("Point(%f, %f)", p.Latitude, p.Longitude)
}
872828
func (csf *CubicSplineFunction) EvalPoint(x float64) *Point {
	return NewPoint(x, csf.Eval(x))
}
72290
func (l *Line) SquaredDistanceFrom(point *Point) float64 {
	x := l.a[0]
	y := l.a[1]
	dx := l.b[0] - x
	dy := l.b[1] - y

	if dx != 0 || dy != 0 {
		t := ((point[0]-x)*dx + (point[1]-y)*dy) / (dx*dx + dy*dy)

		if t > 1 {
			x = l.b[0]
			y = l.b[1]
		} else if t > 0 {
			x += dx * t
			y += dy * t
		}
	}

	dx = point[0] - x
	dy = point[1] - y

	return dx*dx + dy*dy
}
22778
func tableForPointer(m *DbMap, i interface{}, checkPk bool) (*TableMap, reflect.Value, error) {
	v := reflect.ValueOf(i)
	if v.Kind() != reflect.Ptr {
		return nil, v, fmt.Errorf("value %v not a pointer", v)
	}
	v = v.Elem()
	t := m.TableForType(v.Type())
	if t == nil {
		return nil, v, fmt.Errorf("could not find table for %v", v.Type())
	}
	if checkPk && len(t.Keys) < 1 {
		return t, v, &NoKeysErr{t}
	}
	return t, v, nil
}
417357
func (ln *LocalNode) UDPEndpointStatement(fromaddr, endpoint *net.UDPAddr) {
	ln.mu.Lock()
	defer ln.mu.Unlock()

	ln.udpTrack.AddStatement(fromaddr.String(), endpoint.String())
	ln.updateEndpoints()
}
586698
func NewPointFromBytes(b []byte) (Point, error) {
	p := &point{}
	if err := p.UnmarshalBinary(b); err != nil {
		return nil, err
	}

	// This does some basic validation to ensure there are fields and they
	// can be unmarshalled as well.
	iter := p.FieldIterator()
	var hasField bool
	for iter.Next() {
		if len(iter.FieldKey()) == 0 {
			continue
		}
		hasField = true
		switch iter.Type() {
		case Float:
			_, err := iter.FloatValue()
			if err != nil {
				return nil, fmt.Errorf("unable to unmarshal field %s: %s", string(iter.FieldKey()), err)
			}
		case Integer:
			_, err := iter.IntegerValue()
			if err != nil {
				return nil, fmt.Errorf("unable to unmarshal field %s: %s", string(iter.FieldKey()), err)
			}
		case Unsigned:
			_, err := iter.UnsignedValue()
			if err != nil {
				return nil, fmt.Errorf("unable to unmarshal field %s: %s", string(iter.FieldKey()), err)
			}
		case String:
			// Skip since this won't return an error
		case Boolean:
			_, err := iter.BooleanValue()
			if err != nil {
				return nil, fmt.Errorf("unable to unmarshal field %s: %s", string(iter.FieldKey()), err)
			}
		}
	}

	if !hasField {
		return nil, ErrPointMustHaveAField
	}

	return p, nil
}
532475
func (l *Line) Intersection(line *Line) *Point {
	den := (line.b[1]-line.a[1])*(l.b[0]-l.a[0]) - (line.b[0]-line.a[0])*(l.b[1]-l.a[1])
	U1 := (line.b[0]-line.a[0])*(l.a[1]-line.a[1]) - (line.b[1]-line.a[1])*(l.a[0]-line.a[0])
	U2 := (l.b[0]-l.a[0])*(l.a[1]-line.a[1]) - (l.b[1]-l.a[1])*(l.a[0]-line.a[0])

	if den == 0 {
		// collinear, all bets are off
		if U1 == 0 && U2 == 0 {
			return InfinityPoint
		}

		return nil
	}

	if U1/den < 0 || U1/den > 1 || U2/den < 0 || U2/den > 1 {
		return nil
	}

	return l.Interpolate(U1 / den)
}
1341634
func (lsf *LeastSquaresFunction) EvalPoint(x float64) *Point {
	return NewPoint(x, lsf.Eval(x))
}
135882
func (pattern *MeshPattern) SetControlPoint(pointNum int, x, y float64) {
	C.cairo_mesh_pattern_set_control_point(pattern.Ptr, C.uint(pointNum), C.double(x), C.double(y))
	if err := pattern.status(); err != nil {
		panic(err)
	}
}
1184370
func GetPointerToInt64(p *float64) *int64 {
	if p == nil {
		return nil
	}
	i := int64(*p)
	return &i
}
980527
func PointIntersectsLine(strategy Strategy, point, lineStart, lineEnd geom.Coord) (hasIntersection bool) {
	intersectorData := &lineIntersectorData{
		strategy:           strategy,
		inputLines:         [2][2]geom.Coord{{lineStart, lineEnd}, {}},
		intersectionPoints: [2]geom.Coord{{0, 0}, {0, 0}},
	}

	intersectorData.pa = intersectorData.intersectionPoints[0]
	intersectorData.pb = intersectorData.intersectionPoints[1]

	strategy.computePointOnLineIntersection(intersectorData, point, lineStart, lineEnd)

	return intersectorData.intersectionType != lineintersection.NoIntersection
}
238422
func (s GeoDistanceSort) Point(lat, lon float64) GeoDistanceSort {
	s.points = append(s.points, GeoPointFromLatLon(lat, lon))
	return s
}
1208518
func pointSide(b orb.Bound, p orb.Point) uint8 {
	if p[1] == b.Max[1] {
		return 4
	} else if p[1] == b.Min[1] {
		return 2
	} else if p[0] == b.Max[0] {
		return 3
	} else if p[0] == b.Min[0] {
		return 1
	}

	return notOnSide
}
342512
func (ps PointSet) DistanceFrom(point *Point) (float64, int) {
	dist := math.Inf(1)
	index := 0

	for i := range ps {
		if d := ps[i].SquaredDistanceFrom(point); d < dist {
			dist = d
			index = i
		}
	}

	return math.Sqrt(dist), index
}