// Fill wedge with center (xi,yi), radius ri from alpha to beta with style.
// Any combination of phi, psi allowed as long 0 <= phi < psi < 2pi.
778510
func fillWedge(mg MinimalGraphics, xi, yi, ro, ri int, phi, psi, epsilon float64, style Style) {
	// ls := Style{LineColor: style.FillColor, LineWidth: 1, Symbol: style.Symbol}

	qPhi := quadrant(phi)
	qPsi := quadrant(psi)
	// DebugLogger.Printf("fillWedge from %.1f (%d) to %.1f (%d).", 180*phi/math.Pi, qPhi, 180*psi/math.Pi, qPsi)

	// prepare styles for filling
	style.LineColor = style.FillColor
	style.LineWidth = 1
	style.LineStyle = SolidLine
	blank := Style{
		Symbol:    ' ',
		LineColor: color.NRGBA{0xff, 0xff, 0xff, 0x00},
		FillColor: color.NRGBA{0xff, 0xff, 0xff, 0x00},
	}

	for qPhi != qPsi {
		// DebugLogger.Printf("qPhi = %d", qPhi)
		w := float64(qPhi+1) * math.Pi / 2
		if math.Abs(w-phi) > 0.01 {
			fillQuarterWedge(mg, xi, yi, ro, mapQ(phi, qPhi), mapQ(w, qPhi), epsilon, style, qPhi)
			if ri > 0 {
				fillQuarterWedge(mg, xi, yi, ri, mapQ(phi, qPhi), mapQ(w, qPhi), epsilon, blank, qPhi)
			}
		}
		phi = w
		qPhi++
		if qPhi == 4 {
			// DebugLogger.Printf("Wrapped phi around")
			phi, qPhi = 0, 0
		}
	}
	if phi != psi {
		// DebugLogger.Printf("Last wedge")
		fillQuarterWedge(mg, xi, yi, ro, mapQ(phi, qPhi), mapQ(psi, qPhi), epsilon, style, qPhi)
		if ri > 0 {
			fillQuarterWedge(mg, xi, yi, ri, mapQ(phi, qPhi), mapQ(psi, qPhi), epsilon, blank, qPhi)
		}
	}
}
996393
func FilledCircleRGBA(renderer *sdl.Renderer, x, y, rad int32, r, g, b, a uint8) bool {
	_x := C.Sint16(x)
	_y := C.Sint16(y)
	_rad := C.Sint16(rad)
	_r := C.Uint8(r)
	_g := C.Uint8(g)
	_b := C.Uint8(b)
	_a := C.Uint8(a)
	return C.filledCircleRGBA((*C.SDL_Renderer)(unsafe.Pointer(renderer)), _x, _y, _rad, _r, _g, _b, _a) == 0
}
391285
func (rgc *RasterGraphicContext) Fill(paths ...*Path) {
	paths = append(paths, rgc.current.Path)
	rgc.fillRasterizer.UseNonZeroWinding = rgc.current.FillRule == FillRuleWinding

	flattener := Transformer{Tr: rgc.current.Tr, Flattener: FtLineBuilder{Adder: rgc.fillRasterizer}}
	for _, p := range paths {
		Flatten(p, flattener, rgc.current.Tr.GetScale())
	}

	rgc.paint(rgc.fillRasterizer, rgc.current.FillColor)
}
1350546
func FilledCircleColor(renderer *sdl.Renderer, x, y, rad int32, color sdl.Color) bool {
	_x := C.Sint16(x)
	_y := C.Sint16(y)
	_rad := C.Sint16(rad)
	_color := C.Uint32(gfxColor(color))
	return C.filledCircleColor((*C.SDL_Renderer)(unsafe.Pointer(renderer)), _x, _y, _rad, _color) == 0
}
307075
func (b *Bound) Center() *Point {
	p := &Point{}
	p.SetX((b.ne.X() + b.sw.X()) / 2.0)
	p.SetY((b.ne.Y() + b.sw.Y()) / 2.0)

	return p
}
257396
func (f *Filler) Fill(variable interface{}) {
	fields := f.getFields(variable)
	f.SetDefaultValues(fields)
}
1103693
func sloper(x1, y1, x2, y2 int) (m, r float64) {
	dy := float64(y1 - y2)
	dx := float64(x1 - x2)
	m = dy / dx
	r = math.Atan2(dy, dx) * (180 / math.Pi)
	return m, r
}
717893
func WedgeRelation(a0, ab1, a2, b0, b2 Point) WedgeRel {
	// There are 6 possible edge orderings at a shared vertex (all
	// of these orderings are circular, i.e. abcd == bcda):
	//
	//  (1) a2 b2 b0 a0: A contains B
	//  (2) a2 a0 b0 b2: B contains A
	//  (3) a2 a0 b2 b0: A and B are disjoint
	//  (4) a2 b0 a0 b2: A and B intersect in one wedge
	//  (5) a2 b2 a0 b0: A and B intersect in one wedge
	//  (6) a2 b0 b2 a0: A and B intersect in two wedges
	//
	// We do not distinguish between 4, 5, and 6.
	// We pay extra attention when some of the edges overlap.  When edges
	// overlap, several of these orderings can be satisfied, and we take
	// the most specific.
	if a0 == b0 && a2 == b2 {
		return WedgeEquals
	}

	// Cases 1, 2, 5, and 6
	if OrderedCCW(a0, a2, b2, ab1) {
		// The cases with this vertex ordering are 1, 5, and 6,
		if OrderedCCW(b2, b0, a0, ab1) {
			return WedgeProperlyContains
		}

		// We are in case 5 or 6, or case 2 if a2 == b2.
		if a2 == b2 {
			return WedgeIsProperlyContained
		}
		return WedgeProperlyOverlaps

	}
	// We are in case 2, 3, or 4.
	if OrderedCCW(a0, b0, b2, ab1) {
		return WedgeIsProperlyContained
	}

	if OrderedCCW(a0, b0, a2, ab1) {
		return WedgeIsDisjoint
	}
	return WedgeProperlyOverlaps
}
1356782
func (s *ScalableBloomFilter) FillRatio() float64 {
	sum := 0.0
	for _, filter := range s.filters {
		sum += filter.FillRatio()
	}
	return sum / float64(len(s.filters))
}
330725
func findEndVertex(p Polyline, tolerance s1.Angle, index int) int {
	// The basic idea is to keep track of the "pie wedge" of angles
	// from the starting vertex such that a ray from the starting
	// vertex at that angle will pass through the discs of radius
	// tolerance centered around all vertices processed so far.
	//
	// First we define a coordinate frame for the tangent and normal
	// spaces at the starting vertex. Essentially this means picking
	// three orthonormal vectors X,Y,Z such that X and Y span the
	// tangent plane at the starting vertex, and Z is up. We use
	// the coordinate frame to define a mapping from 3D direction
	// vectors to a one-dimensional ray angle in the range (-π,
	// π]. The angle of a direction vector is computed by
	// transforming it into the X,Y,Z basis, and then calculating
	// atan2(y,x). This mapping allows us to represent a wedge of
	// angles as a 1D interval. Since the interval wraps around, we
	// represent it as an Interval, i.e. an interval on the unit
	// circle.
	origin := p[index]
	frame := getFrame(origin)

	// As we go along, we keep track of the current wedge of angles
	// and the distance to the last vertex (which must be
	// non-decreasing).
	currentWedge := s1.FullInterval()
	var lastDistance s1.Angle

	for index++; index < len(p); index++ {
		candidate := p[index]
		distance := origin.Distance(candidate)

		// We don't allow simplification to create edges longer than
		// 90 degrees, to avoid numeric instability as lengths
		// approach 180 degrees. We do need to allow for original
		// edges longer than 90 degrees, though.
		if distance > math.Pi/2 && lastDistance > 0 {
			break
		}

		// Vertices must be in increasing order along the ray, except
		// for the initial disc around the origin.
		if distance < lastDistance && lastDistance > tolerance {
			break
		}

		lastDistance = distance

		// Points that are within the tolerance distance of the origin
		// do not constrain the ray direction, so we can ignore them.
		if distance <= tolerance {
			continue
		}

		// If the current wedge of angles does not contain the angle
		// to this vertex, then stop right now. Note that the wedge
		// of possible ray angles is not necessarily empty yet, but we
		// can't continue unless we are willing to backtrack to the
		// last vertex that was contained within the wedge (since we
		// don't create new vertices). This would be more complicated
		// and also make the worst-case running time more than linear.
		direction := toFrame(frame, candidate)
		center := math.Atan2(direction.Y, direction.X)
		if !currentWedge.Contains(center) {
			break
		}

		// To determine how this vertex constrains the possible ray
		// angles, consider the triangle ABC where A is the origin, B
		// is the candidate vertex, and C is one of the two tangent
		// points between A and the spherical cap of radius
		// tolerance centered at B. Then from the spherical law of
		// sines, sin(a)/sin(A) = sin(c)/sin(C), where a and c are
		// the lengths of the edges opposite A and C. In our case C
		// is a 90 degree angle, therefore A = asin(sin(a) / sin(c)).
		// Angle A is the half-angle of the allowable wedge.
		halfAngle := math.Asin(math.Sin(tolerance.Radians()) / math.Sin(distance.Radians()))
		target := s1.IntervalFromPointPair(center, center).Expanded(halfAngle)
		currentWedge = currentWedge.Intersection(target)
	}

	// We break out of the loop when we reach a vertex index that
	// can't be included in the line segment, so back up by one
	// vertex.
	return index - 1
}
598433
func (renderer *Renderer) FillRect(rect *Rect) error {
	return errorFromInt(int(
		C.SDL_RenderFillRect(renderer.cptr(), rect.cptr())))
}
1106551
func (_m Map) Fill(m Map) {
	for key, value := range _m {
		m[key] = value
	}
}
1223130
func (cr *Context) FillPreserve() {
	C.cairo_fill_preserve(cr.Ptr)
	if err := cr.status(); err != nil {
		panic(err)
	}
}
1229436
func (k *TriangleKMeans) Distortion() float64 {
	var sum float64
	for i := range k.trainingSet {
		sum += diff(k.trainingSet[i], k.Centroids[int(k.guesses[i])])
	}

	return sum
}
745907
func (c *HistChart) widthFactor() (gf, sf float64) {
	if c.Stacked || !c.Shifted {
		gf = c.Gap
		sf = -1
		return
	}

	switch len(c.Data) {
	case 1:
		gf = c.Gap
		sf = -1
		return
	case 2:
		gf = 1.0 / 4.0
		sf = -1.0 / 3.0
	case 3:
		gf = 1.0 / 5.0
		sf = -1.0 / 2.0
	case 4:
		gf = 1.0 / 6.0
		sf = -2.0 / 3.0
	default:
		gf = 1.0 / 6.0
		sf = -2.0 / 4.0
	}

	if c.Gap != 0 {
		gf = c.Gap
	}
	if c.Sep != 0 {
		sf = c.Sep
	}
	return
}
933946
func (c Cap) Expanded(distance s1.Angle) Cap {
	if c.IsEmpty() {
		return EmptyCap()
	}
	return CapFromCenterChordAngle(c.center, c.radius.Add(s1.ChordAngleFromAngle(distance)))
}
343168
func (p *PartitionedBloomFilter) FillRatio() float64 {
	t := float64(0)
	for i := uint(0); i < p.k; i++ {
		sum := uint32(0)
		for j := uint(0); j < p.partitions[i].Count(); j++ {
			sum += p.partitions[i].Get(j)
		}
		t += (float64(sum) / float64(p.s))
	}
	return t / float64(p.k)
}