// Cubic
//	x1, y1, cpx1, cpy1, cpx2, cpy2, x2, y2 float64
// SubdivideCubic a Bezier cubic curve in 2 equivalents Bezier cubic curves.
// c1 and c2 parameters are the resulting curves
170441
func SubdivideCubic(c, c1, c2 []float64) {
	// First point of c is the first point of c1
	c1[0], c1[1] = c[0], c[1]
	// Last point of c is the last point of c2
	c2[6], c2[7] = c[6], c[7]

	// Subdivide segment using midpoints
	c1[2] = (c[0] + c[2]) / 2
	c1[3] = (c[1] + c[3]) / 2

	midX := (c[2] + c[4]) / 2
	midY := (c[3] + c[5]) / 2

	c2[4] = (c[4] + c[6]) / 2
	c2[5] = (c[5] + c[7]) / 2

	c1[4] = (c1[2] + midX) / 2
	c1[5] = (c1[3] + midY) / 2

	c2[2] = (midX + c2[4]) / 2
	c2[3] = (midY + c2[5]) / 2

	c1[6] = (c1[4] + c2[2]) / 2
	c1[7] = (c1[5] + c2[3]) / 2

	// Last Point of c1 is equal to the first point of c2
	c2[0], c2[1] = c1[6], c1[7]
}
1140585
func SubdivideQuad(c, c1, c2 []float64) {
	// First point of c is the first point of c1
	c1[0], c1[1] = c[0], c[1]
	// Last point of c is the last point of c2
	c2[4], c2[5] = c[4], c[5]

	// Subdivide segment using midpoints
	c1[2] = (c[0] + c[2]) / 2
	c1[3] = (c[1] + c[3]) / 2
	c2[2] = (c[2] + c[4]) / 2
	c2[3] = (c[3] + c[5]) / 2
	c1[4] = (c1[2] + c2[2]) / 2
	c1[5] = (c1[3] + c2[3]) / 2
	c2[0], c2[1] = c1[4], c1[5]
	return
}
902886
func (u Vec) XY() (x, y float64) {
	return u.X, u.Y
}
770583
func (u Vec) Sub(v Vec) Vec {
	return Vec{
		u.X - v.X,
		u.Y - v.Y,
	}
}
649715
func linear(v0, v1, v2, v3 *uint32) {
	*v0 = ((*v0 << 13) | (*v0 >> (32 - 13)))
	*v2 = ((*v2 << 3) | (*v2 >> (32 - 3)))
	*v1 ^= *v0 ^ *v2
	*v3 ^= *v2 ^ (*v0 << 3)
	*v1 = (*v1 << 1) | (*v1 >> (32 - 1))
	*v3 = (*v3 << 7) | (*v3 >> (32 - 7))
	*v0 ^= *v1 ^ *v3
	*v2 ^= *v3 ^ (*v1 << 7)
	*v0 = (*v0 << 5) | (*v0 >> (32 - 5))
	*v2 = (*v2 << 22) | (*v2 >> (32 - 22))
}
1279855
func (rr *rasterRenderer) QuadCurveTo(cx, cy, x, y int) {
	rr.gc.QuadCurveTo(float64(cx), float64(cy), float64(x), float64(y))
}
1216824
func (g *Virtual) Subgraph(s VertexSet) *Virtual {
	n := g.Order()
	s = s.And(Range(0, n))
	m := s.size()
	switch {
	case m == 0:
		return null
	case m == 1:
		return singleton()
	case m == n:
		return g
	}

	cost := func(v, w int) int64 {
		return g.cost(s.get(v), s.get(w))
	}
	res := generic(m, cost, func(v, w int) bool {
		return g.edge(s.get(v), s.get(w))
	})
	res.visit = func(v int, a int, do func(w int, c int64) bool) (aborted bool) {
		if a >= m {
			return
		}
		v0 := s.get(v)
		s0 := s.And(Range(s.get(a), n))
		for _, in := range s0.set {
			if more := false; g.visit(v0, in.a, func(w0 int, c int64) (skip bool) {
				switch {
				case w0 >= in.b:
					more, skip = true, true
					return
				case do(s.rank(w0), c):
					return true
				default:
					return
				}
			}) && !more {
				return true
			}
		}
		return
	}
	return res
}
1194388
func SubU64x2(x, y U64x2) U64x2 {
	val := U64x2{}
	for i := 0; i < 2; i++ {
		val[i] = x[i] - y[i]
	}
	return val
}
796108
func (curve *KoblitzCurve) fieldJacobianToBigAffine(x, y, z *fieldVal) (*big.Int, *big.Int) {
	// Inversions are expensive and both point addition and point doubling
	// are faster when working with points that have a z value of one.  So,
	// if the point needs to be converted to affine, go ahead and normalize
	// the point itself at the same time as the calculation is the same.
	var zInv, tempZ fieldVal
	zInv.Set(z).Inverse()   // zInv = Z^-1
	tempZ.SquareVal(&zInv)  // tempZ = Z^-2
	x.Mul(&tempZ)           // X = X/Z^2 (mag: 1)
	y.Mul(tempZ.Mul(&zInv)) // Y = Y/Z^3 (mag: 1)
	z.SetInt(1)             // Z = 1 (mag: 1)

	// Normalize the x and y values.
	x.Normalize()
	y.Normalize()

	// Convert the field values for the now affine point to big.Ints.
	x3, y3 := new(big.Int), new(big.Int)
	x3.SetBytes(x.Bytes()[:])
	y3.SetBytes(y.Bytes()[:])
	return x3, y3
}
31596
func (v1 Vec2) Sub(v2 Vec2) Vec2 {
	return Vec2{v1[0] - v2[0], v1[1] - v2[1]}
}
1307257
func SubI32x4(x, y I32x4) I32x4 {
	val := I32x4{}
	for i := 0; i < 4; i++ {
		val[i] = x[i] - y[i]
	}
	return val
}
318837
func SubF32x4(x, y F32x4) F32x4 {
	val := F32x4{}
	for i := 0; i < 4; i++ {
		val[i] = x[i] - y[i]
	}
	return val
}
199313
func TraceQuad(t Liner, quad []float64, flatteningThreshold float64) {
	const curveLen = CurveRecursionLimit * 6
	const curveEndIndex = curveLen - 1
	const lastIteration = CurveRecursionLimit - 1

	// Allocates curves stack
	curves := make([]float64, curveLen)

	// copy 6 elements from the quad path to the stack
	copy(curves[0:6], quad[0:6])

	var i int
	var c []float64
	var dx, dy, d float64

	for i >= 0 {
		c = traceGetWindow(curves, i)
		dx, dy, d = traceCalcDeltas(c)

		// bail early if the distance is 0
		if d == 0 {
			return
		}

		// if it's flat then trace a line
		if traceIsFlat(dx, dy, d, flatteningThreshold) || i == lastIteration {
			t.LineTo(c[4], c[5])
			i--
		} else {
			SubdivideQuad(c, traceGetWindow(curves, i+1), traceGetWindow(curves, i))
			i++
		}
	}
}
975575
func SubI64x2(x, y I64x2) I64x2 {
	val := I64x2{}
	for i := 0; i < 2; i++ {
		val[i] = x[i] - y[i]
	}
	return val
}
907003
public SVGPath cubicTo(double[] c1xy, double[] c2xy, double[] xy) {
    return append(PATH_CUBIC_TO).append(c1xy[0]).append(c1xy[1]).append(c2xy[0]).append(c2xy[1]).append(xy[0]).append(xy[1]);
  }
1332320
function sampleCubicBézier(x0, y0, x1, y1, x2, y2, x3, y3) {
		// Calculate all the mid-points of the line segments
		const x01   = (x0 + x1) / 2,
		      y01   = (y0 + y1) / 2,
		      x12   = (x1 + x2) / 2,
		      y12   = (y1 + y2) / 2,
		      x23   = (x2 + x3) / 2,
		      y23   = (y2 + y3) / 2,
		      x012  = (x01 + x12) / 2,
		      y012  = (y01 + y12) / 2,
		      x123  = (x12 + x23) / 2,
		      y123  = (y12 + y23) / 2,
		      x0123 = (x012 + x123) / 2,
		      y0123 = (y012 + y123) / 2;

		// Try to approximate the full cubic curve by a single straight line
		const dx = x3-x0,
		      dy = y3-y0;

		const d1 = Math.abs(((x1-x3)*dy - (y1-y3)*dx)),
		      d2 = Math.abs(((x2-x3)*dy - (y2-y3)*dx));

		if (((d1+d2)*(d1+d2)) < (tolerance2 * (dx*dx + dy*dy))) add(x0123,y0123);
		else { // Continue subdivision
		  sampleCubicBézier(x0, y0, x01, y01, x012, y012, x0123, y0123); 
		  sampleCubicBézier(x0123, y0123, x123, y123, x23, y23, x3, y3); 
		}
   }
412180
func (dc *Context) QuadraticTo(x1, y1, x2, y2 float64) {
	if !dc.hasCurrent {
		dc.MoveTo(x1, y1)
	}
	x1, y1 = dc.TransformPoint(x1, y1)
	x2, y2 = dc.TransformPoint(x2, y2)
	p1 := Point{x1, y1}
	p2 := Point{x2, y2}
	dc.strokePath.Add2(p1.Fixed(), p2.Fixed())
	dc.fillPath.Add2(p1.Fixed(), p2.Fixed())
	dc.current = p2
}