// Angle converts this ChordAngle to an Angle.
199532
func (c ChordAngle) Angle() Angle {
	if c < 0 {
		return -1 * Radian
	}
	if c.isInf() {
		return InfAngle()
	}
	return Angle(2 * math.Asin(0.5*math.Sqrt(float64(c))))
}
525824
func (u Vec) Rotated(angle float64) Vec {
	sin, cos := math.Sincos(angle)
	return Vec{
		u.X*cos - u.Y*sin,
		u.X*sin + u.Y*cos,
	}
}
1271861
func Tangent(pointA, tangentA, pointB, tangentB *vec3.T, t float64) vec3.T {
	t2 := t * t
	t3 := t2 * t

	f := 2*t3 - 3*t2
	result := pointA.Scaled(f)

	f = t3 - 2*t2 + 1
	tAf := tangentA.Scaled(f)
	result.Add(&tAf)

	f = t3 - t2
	tBf := tangentB.Scaled(f)
	result.Add(&tBf)

	f = -2*t3 + 3*t2
	pAf := pointB.Scaled(f)
	result.Add(&pAf)

	return result
}
1247608
func (c Cell) DistanceToEdge(a, b Point) s1.ChordAngle {
	// Possible optimizations:
	//  - Currently the (cell vertex, edge endpoint) distances are computed
	//    twice each, and the length of AB is computed 4 times.
	//  - To fix this, refactor GetDistance(target) so that it skips calculating
	//    the distance to each cell vertex. Instead, compute the cell vertices
	//    and distances in this function, and add a low-level UpdateMinDistance
	//    that allows the XA, XB, and AB distances to be passed in.
	//  - It might also be more efficient to do all calculations in UVW-space,
	//    since this would involve transforming 2 points rather than 4.

	// First, check the minimum distance to the edge endpoints A and B.
	// (This also detects whether either endpoint is inside the cell.)
	minDist := minChordAngle(c.Distance(a), c.Distance(b))
	if minDist == 0 {
		return minDist
	}

	// Otherwise, check whether the edge crosses the cell boundary.
	crosser := NewChainEdgeCrosser(a, b, c.Vertex(3))
	for i := 0; i < 4; i++ {
		if crosser.ChainCrossingSign(c.Vertex(i)) != DoNotCross {
			return 0
		}
	}

	// Finally, check whether the minimum distance occurs between a cell vertex
	// and the interior of the edge AB. (Some of this work is redundant, since
	// it also checks the distance to the endpoints A and B again.)
	//
	// Note that we don't need to check the distance from the interior of AB to
	// the interior of a cell edge, because the only way that this distance can
	// be minimal is if the two edges cross (already checked above).
	for i := 0; i < 4; i++ {
		minDist, _ = UpdateMinDistance(c.Vertex(i), a, b, minDist)
	}
	return minDist
}
906769
func (quat *T) AxisAngle() (axis vec3.T, angle float64) {
	cos := quat[3]
	sin := math.Sqrt(1 - cos*cos)
	angle = math.Acos(cos)

	var ooSin float64
	if math.Abs(sin) < 0.0005 {
		ooSin = 1
	} else {
		ooSin = 1 / sin
	}
	axis[0] = quat[0] * ooSin
	axis[1] = quat[1] * ooSin
	axis[2] = quat[2] * ooSin

	return axis, angle
}
303391
func (i *Image) Rotate(a Angle) ([]byte, error) {
	options := Options{Rotate: a}
	return i.Process(options)
}
247926
func BuildTriangle(sideLength, height float64) string {
	halfWidth := sideLength / 2

	return fmt.Sprintf("%v,0,%v,%v,0,%v,%v,0", halfWidth, sideLength, height, height, halfWidth)
}
582662
func (l *Loop) turningAngleMaxError() float64 {
	// The maximum error can be bounded as follows:
	//   2.24 * dblEpsilon    for RobustCrossProd(b, a)
	//   2.24 * dblEpsilon    for RobustCrossProd(c, b)
	//   3.25 * dblEpsilon    for Angle()
	//   2.00 * dblEpsilon    for each addition in the Kahan summation
	//   ------------------
	//   9.73 * dblEpsilon
	maxErrorPerVertex := 9.73 * dblEpsilon
	return maxErrorPerVertex * float64(len(l.vertices))
}
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
}
626829
func (vec *T) Rotate(angle float64) *T {
	*vec = vec.Rotated(angle)
	return vec
}
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)
}
189597
func Geometry(box orb.Bound, g orb.Geometry, o orb.Orientation) orb.Geometry {
	if g == nil {
		return nil
	}

	if g.Dimensions() != 2 {
		return clip.Geometry(box, g)
	}

	var mp orb.MultiPolygon
	switch g := g.(type) {
	case orb.Ring:
		mp = Ring(box, g, o)
	case orb.Polygon:
		mp = Polygon(box, g, o)
	case orb.MultiPolygon:
		mp = MultiPolygon(box, g, o)
	case orb.Bound:
		return clip.Geometry(box, g)
	case orb.Collection:
		var result orb.Collection
		for _, c := range g {
			c := Geometry(box, c, o)
			if c != nil {
				result = append(result, c)
			}
		}

		if len(result) == 1 {
			return result[0]
		}

		return result
	default:
		panic(fmt.Sprintf("geometry type not supported: %T", g))
	}

	if mp == nil {
		return nil
	}

	if len(mp) == 1 {
		return mp[0]
	}

	return mp
}
1034244
func (g *Virtual) Degree(v int) int {
	if v < 0 || v >= g.order {
		panic("vertex out of range")
	}
	return g.degree(v)
}
128316
func (c ChordAngle) Sub(other ChordAngle) ChordAngle {
	if other == 0 {
		return c
	}
	if c <= other {
		return 0
	}
	x := float64(c * (1 - 0.25*other))
	y := float64(other * (1 - 0.25*c))
	return ChordAngle(math.Max(0.0, x+y-2*math.Sqrt(x*y)))
}
734956
func ChordAngleFromAngle(a Angle) ChordAngle {
	if a < 0 {
		return NegativeChordAngle
	}
	if a.isInf() {
		return InfChordAngle()
	}
	l := 2 * math.Sin(0.5*math.Min(math.Pi, a.Radians()))
	return ChordAngle(l * l)
}
949348
func Normalize(angle float64) float64 {
	for angle > math.Pi {
		angle -= piTimes2
	}
	for angle <= -math.Pi {
		angle += piTimes2
	}
	return angle
}
784445
func (l Line) Rotated(around Vec, angle float64) Line {
	// Move the line so we can use `Vec.Rotated`
	lineShifted := l.Moved(around.Scaled(-1))

	lineRotated := Line{
		A: lineShifted.A.Rotated(angle),
		B: lineShifted.B.Rotated(angle),
	}

	return lineRotated.Moved(around)
}