// Vertex returns the k-th vertex of the cell (k = 0,1,2,3) in CCW order
// (lower left, lower right, upper right, upper left in the UV plane).
500415
func (c Cell) Vertex(k int) Point {
	return Point{faceUVToXYZ(int(c.face), c.uv.Vertices()[k].X, c.uv.Vertices()[k].Y).Normalize()}
}
33502
func (s *sccAcct) pop() Vertex {
	n := len(s.Stack)
	if n == 0 {
		return nil
	}
	vertex := s.Stack[n-1]
	s.Stack = s.Stack[:n-1]
	return vertex
}
1053432
func (m Mat2x4) Col(col int) Vec2 {
	return Vec2{m[col*2+0], m[col*2+1]}
}
362258
func (g *Mutable) Edge(v, w int) bool {
	if v < 0 || v >= g.Order() {
		return false
	}
	_, ok := g.edges[v][w]
	return ok
}
925567
func (c Cap) intersects(cell Cell, vertices [4]Point) bool {
	// If the cap is a hemisphere or larger, the cell and the complement of the cap
	// are both convex. Therefore since no vertex of the cell is contained, no other
	// interior point of the cell is contained either.
	if c.radius >= s1.RightChordAngle {
		return false
	}

	// We need to check for empty caps due to the center check just below.
	if c.IsEmpty() {
		return false
	}

	// Optimization: return true if the cell contains the cap center. This allows half
	// of the edge checks below to be skipped.
	if cell.ContainsPoint(c.center) {
		return true
	}

	// At this point we know that the cell does not contain the cap center, and the cap
	// does not contain any cell vertex. The only way that they can intersect is if the
	// cap intersects the interior of some edge.
	sin2Angle := c.radius.Sin2()
	for k := 0; k < 4; k++ {
		edge := cell.Edge(k).Vector
		dot := c.center.Vector.Dot(edge)
		if dot > 0 {
			// The center is in the interior half-space defined by the edge. We do not need
			// to consider these edges, since if the cap intersects this edge then it also
			// intersects the edge on the opposite side of the cell, because the center is
			// not contained with the cell.
			continue
		}

		// The Norm2() factor is necessary because "edge" is not normalized.
		if dot*dot > sin2Angle*edge.Norm2() {
			return false
		}

		// Otherwise, the great circle containing this edge intersects the interior of the cap. We just
		// need to check whether the point of closest approach occurs between the two edge endpoints.
		dir := edge.Cross(c.center.Vector)
		if dir.Dot(vertices[k].Vector) < 0 && dir.Dot(vertices[(k+1)&3].Vector) > 0 {
			return true
		}
	}
	return false
}
439212
func (f *Fpdf) Cell(w, h float64, txtStr string) {
	f.CellFormat(w, h, txtStr, "", 0, "L", false, 0, "")
}
552920
func (a *CellView) Size() (int, int) {
	// We always return a minimum of two rows, and two columns.
	w, h := a.model.GetBounds()
	// Clip to a 2x2 minimum square; we can scroll within that.
	if w > 2 {
		w = 2
	}
	if h > 2 {
		h = 2
	}
	return w, h
}
124699
func topsort(g Iterator, output bool) (order []int, acyclic bool) {
	indegree := make([]int, g.Order())
	for v := range indegree {
		g.Visit(v, func(w int, _ int64) (skip bool) {
			indegree[w]++
			return
		})
	}

	// Invariant: this queue holds all vertices with indegree 0.
	var queue []int
	for v, degree := range indegree {
		if degree == 0 {
			queue = append(queue, v)
		}
	}

	order = []int{}
	vertexCount := 0
	for len(queue) > 0 {
		v := queue[0]
		queue = queue[1:]
		if output {
			order = append(order, v)
		}
		vertexCount++
		g.Visit(v, func(w int, _ int64) (skip bool) {
			indegree[w]--
			if indegree[w] == 0 {
				queue = append(queue, w)
			}
			return
		})
	}
	if vertexCount != g.Order() {
		return
	}
	acyclic = true
	return
}
1029202
func Edge(v, w int) EdgeSet {
	if v < 0 || w < 0 || v == w {
		return NoEdges()
	}
	return EdgeSet{
		From: Vertex(v),
		To:   Vertex(w),
	}
}
286177
func (s *Spritesheet) Cell(index int) Texture {
	if r, ok := s.cache[index]; ok {
		return r
	}

	cell := s.cells[index]
	s.cache[index] = Texture{
		id:     s.texture,
		width:  float32(cell.Width),
		height: float32(cell.Height),
		viewport: engo.AABB{
			Min: engo.Point{
				X: cell.Position.X / s.width,
				Y: cell.Position.Y / s.height,
			},
			Max: engo.Point{
				X: (cell.Position.X + float32(cell.Width)) / s.width,
				Y: (cell.Position.Y + float32(cell.Height)) / s.height,
			},
		},
	}

	return s.cache[index]
}
172878
func (ac *AnimationComponent) Cell() Drawable {
	if len(ac.CurrentAnimation.Frames) == 0 {
		log.Println("No frame data for this animation. Selecting zeroth drawable. If this is incorrect, add an action to the animation.")
		return ac.Drawables[0]
	}
	idx := ac.CurrentAnimation.Frames[ac.index]

	return ac.Drawables[idx]
}
470341
func (vertices vertices) String() string {
	result := ``
	for i, v := range vertices {
		result += fmt.Sprintf(`VERTEX INDEX: %+v, VERTEX: %+v`, i, v)
		result += fmt.Sprintln(``)
	}

	return result
}
320763
func (r *Row) HTML(tag string, style *renderStyle) string {
	attrs := make([]string, len(r.cells))
	elems := make([]string, len(r.cells))
	for i := range r.cells {
		if r.cells[i].alignment != nil {
			switch *r.cells[i].alignment {
			case AlignLeft:
				attrs[i] = " align='left'"
			case AlignCenter:
				attrs[i] = " align='center'"
			case AlignRight:
				attrs[i] = " align='right'"
			}
		}
		elems[i] = html.EscapeString(strings.TrimSpace(r.cells[i].Render(style)))
	}
	// WAG as to max capacity, plus a bit
	buf := bytes.NewBuffer(make([]byte, 0, 8192))
	buf.WriteString("<tr>")
	for i := range elems {
		fmt.Fprintf(buf, "<%s%s>%s</%s>", tag, attrs[i], elems[i], tag)
	}
	buf.WriteString("</tr>\n")
	return buf.String()
}
635709
func (m *matrix3x3) col(col int) Point {
	return Point{r3.Vector{m[0][col], m[1][col], m[2][col]}}
}
888501
func ConvexHull(geometry geom.T) geom.T {
	// copy coords because the algorithm reorders them
	calc := convexHullCalculator{
		layout:   geometry.Layout(),
		stride:   geometry.Layout().Stride(),
		inputPts: geometry.FlatCoords(),
	}

	return calc.getConvexHull()
}
463166
func (m Mat3) Rows() (row0, row1, row2 Vec3) {
	return m.Row(0), m.Row(1), m.Row(2)
}
156749
func (col Color) Hsv() (h, s, v float64) {
	min := math.Min(math.Min(col.R, col.G), col.B)
	v = math.Max(math.Max(col.R, col.G), col.B)
	C := v - min

	s = 0.0
	if v != 0.0 {
		s = C / v
	}

	h = 0.0 // We use 0 instead of undefined as in wp.
	if min != v {
		if v == col.R {
			h = math.Mod((col.G-col.B)/C, 6.0)
		}
		if v == col.G {
			h = (col.B-col.R)/C + 2.0
		}
		if v == col.B {
			h = (col.R-col.G)/C + 4.0
		}
		h *= 60.0
		if h < 0.0 {
			h += 360.0
		}
	}
	return
}