// Direction computes the direction the line is pointing from A() to B().
// The units are radians from the positive x-axis.
// Range same as math.Atan2, [-Pi, Pi]
10836
func (l *Line) Direction() float64 {
	return math.Atan2(l.b[1]-l.a[1], l.b[0]-l.a[0])
}
459566
func AngleOrientation(ang1, ang2 float64) orientation.Type {
	crossproduct := math.Sin(ang2 - ang1)

	switch {
	case crossproduct > 0:
		return orientation.CounterClockwise
	case crossproduct < 0:
		return orientation.Clockwise
	default:
		return orientation.Collinear
	}
}
401680
func (ellipsoid Ellipsoid) Location(lat1, lon1, x, y float64) (lat, lon float64) {
	degreesPerRadian := 180.0 / math.Pi

	range1 := math.Sqrt(x*x + y*y)
	bearing1 := math.Atan2(x, y)

	if ellipsoid.Units == Degrees {
		bearing1 *= degreesPerRadian
	}

	return ellipsoid.At(lat1, lon1, range1, bearing1)
}
116549
func Angle(a, b *T) float32 {
	v := Dot(a, b) / (a.Length() * b.Length())
	// prevent NaN
	if v > 1. {
		v = v - 2
	} else if v < -1. {
		v = v + 2
	}
	return math.Acos(v)
}
710937
func (p Point) Bearing(heading Point) float64 {
	var (
		hn = p.Latitude / 180 * math.Pi
		he = p.Longitude / 180 * math.Pi
		n  = heading.Latitude / 180 * math.Pi
		e  = heading.Longitude / 180 * math.Pi
		co = math.Cos(he-e)*math.Cos(hn)*math.Cos(n) + math.Sin(hn)*math.Sin(n)
		ca = math.Atan(math.Abs(math.Sqrt(1-co*co) / co))
	)

	if co < 0.0 {
		ca = math.Pi - ca
	}

	var si = math.Sin(e-he) * math.Cos(n) * math.Cos(hn)
	co = math.Sin(n) - math.Sin(hn)*math.Cos(ca)
	var az = math.Atan(math.Abs(si / co))
	if co < 0.0 {
		az = math.Pi - az
	}
	if si < 0.0 {
		az = -az
	}
	if az < 0.0 {
		az = az + 2.0 + math.Pi
	}
	return az * 180 / math.Pi
}
41325
func (l *Line) Project(point *Point) float64 {
	if point.Equals(&l.a) {
		return 0.0
	}

	if point.Equals(&l.b) {
		return 1.0
	}

	dx := l.b[0] - l.a[0]
	dy := l.b[1] - l.a[1]
	d := (dx*dx + dy*dy)
	if d == 0 {
		return 0
	}

	return ((point[0]-l.a[0])*dx + (point[1]-l.a[1])*dy) / d
}
1164020
func (herm *T) Point(t float64) vec2.T {
	return Point(&herm.A.Point, &herm.A.Tangent, &herm.B.Point, &herm.B.Tangent, t)
}
290788
func Bearing(from, to orb.Point) float64 {
	dLon := deg2rad(to[0] - from[0])

	fromLatRad := deg2rad(from[1])
	toLatRad := deg2rad(to[1])

	y := math.Sin(dLon) * math.Cos(toLatRad)
	x := math.Cos(fromLatRad)*math.Sin(toLatRad) - math.Sin(fromLatRad)*math.Cos(toLatRad)*math.Cos(dLon)

	return rad2deg(math.Atan2(y, x))
}
183367
func latitude(p Point) s1.Angle {
	return s1.Angle(math.Atan2(p.Z, math.Sqrt(p.X*p.X+p.Y*p.Y))) * s1.Radian
}
824877
func (ll LatLng) Distance(ll2 LatLng) s1.Angle {
	// Haversine formula, as used in C++ S2LatLng::GetDistance.
	lat1, lat2 := ll.Lat.Radians(), ll2.Lat.Radians()
	lng1, lng2 := ll.Lng.Radians(), ll2.Lng.Radians()
	dlat := math.Sin(0.5 * (lat2 - lat1))
	dlng := math.Sin(0.5 * (lng2 - lng1))
	x := dlat*dlat + dlng*dlng*math.Cos(lat1)*math.Cos(lat2)
	return s1.Angle(2*math.Atan2(math.Sqrt(x), math.Sqrt(math.Max(0, 1-x)))) * s1.Radian
}
436670
func (p *Point) format() string {
	if p.X == nil && p.Y == nil {
		return "(inf,inf)"
	}
	return fmt.Sprintf("(%s,%s)", hex.EncodeToString(p.X.Bytes()), hex.EncodeToString(p.Y.Bytes()))
}
848781
func (dc *Context) Rotate(angle float64) {
	dc.matrix = dc.matrix.Rotate(angle)
}
895473
func (g *Geometry) Point(n int) (*Geometry, error) {
	return geomFromC("Point", cGEOSGeomGetPointN(g.g, C.int(n)))
}
426362
func (l *Line) Reverse() *Line {
	l.a, l.b = l.b, l.a
	return l
}
541416
func (c Coord) String() string {
	return fmt.Sprintf("%f %f", c.X, c.Y)
}
1335240
func (s *StepperDriver) step() error {
	if s.direction == "forward" {
		s.stepNum++
	} else {
		s.stepNum--
	}

	if s.stepNum >= int(s.stepsPerRev) {
		s.stepNum = 0
	} else if s.stepNum < 0 {
		s.stepNum = int(s.stepsPerRev) - 1
	}

	r := int(math.Abs(float64(s.stepNum))) % len(s.phase)

	for i, v := range s.phase[r] {
		if err := s.connection.DigitalWrite(s.pins[i], v); err != nil {
			return err
		}
	}

	return nil
}
1036000
func (p *Polyline) Reverse() {
	for i := 0; i < len(*p)/2; i++ {
		(*p)[i], (*p)[len(*p)-i-1] = (*p)[len(*p)-i-1], (*p)[i]
	}
}