repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1 value | code stringlengths 52 85.5k | code_tokens list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 | partition stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|
golang/geo | s2/loop.go | ChainEdge | func (l *Loop) ChainEdge(chainID, offset int) Edge {
return Edge{l.Vertex(offset), l.Vertex(offset + 1)}
} | go | func (l *Loop) ChainEdge(chainID, offset int) Edge {
return Edge{l.Vertex(offset), l.Vertex(offset + 1)}
} | [
"func",
"(",
"l",
"*",
"Loop",
")",
"ChainEdge",
"(",
"chainID",
",",
"offset",
"int",
")",
"Edge",
"{",
"return",
"Edge",
"{",
"l",
".",
"Vertex",
"(",
"offset",
")",
",",
"l",
".",
"Vertex",
"(",
"offset",
"+",
"1",
")",
"}",
"\n",
"}"
] | // ChainEdge returns the j-th edge of the i-th edge chain. | [
"ChainEdge",
"returns",
"the",
"j",
"-",
"th",
"edge",
"of",
"the",
"i",
"-",
"th",
"edge",
"chain",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/loop.go#L496-L498 | train |
golang/geo | s2/loop.go | bruteForceContainsPoint | func (l *Loop) bruteForceContainsPoint(p Point) bool {
origin := OriginPoint()
inside := l.originInside
crosser := NewChainEdgeCrosser(origin, p, l.Vertex(0))
for i := 1; i <= len(l.vertices); i++ { // add vertex 0 twice
inside = inside != crosser.EdgeOrVertexChainCrossing(l.Vertex(i))
}
return inside
} | go | func (l *Loop) bruteForceContainsPoint(p Point) bool {
origin := OriginPoint()
inside := l.originInside
crosser := NewChainEdgeCrosser(origin, p, l.Vertex(0))
for i := 1; i <= len(l.vertices); i++ { // add vertex 0 twice
inside = inside != crosser.EdgeOrVertexChainCrossing(l.Vertex(i))
}
return inside
} | [
"func",
"(",
"l",
"*",
"Loop",
")",
"bruteForceContainsPoint",
"(",
"p",
"Point",
")",
"bool",
"{",
"origin",
":=",
"OriginPoint",
"(",
")",
"\n",
"inside",
":=",
"l",
".",
"originInside",
"\n",
"crosser",
":=",
"NewChainEdgeCrosser",
"(",
"origin",
",",
... | // bruteForceContainsPoint reports if the given point is contained by this loop.
// This method does not use the ShapeIndex, so it is only preferable below a certain
// size of loop. | [
"bruteForceContainsPoint",
"reports",
"if",
"the",
"given",
"point",
"is",
"contained",
"by",
"this",
"loop",
".",
"This",
"method",
"does",
"not",
"use",
"the",
"ShapeIndex",
"so",
"it",
"is",
"only",
"preferable",
"below",
"a",
"certain",
"size",
"of",
"lo... | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/loop.go#L576-L584 | train |
golang/geo | s2/loop.go | ContainsPoint | func (l *Loop) ContainsPoint(p Point) bool {
// Empty and full loops don't need a special case, but invalid loops with
// zero vertices do, so we might as well handle them all at once.
if len(l.vertices) < 3 {
return l.originInside
}
// For small loops, and during initial construction, it is faster to just
// check all the crossing.
const maxBruteForceVertices = 32
if len(l.vertices) < maxBruteForceVertices || l.index == nil {
return l.bruteForceContainsPoint(p)
}
// Otherwise, look up the point in the index.
it := l.index.Iterator()
if !it.LocatePoint(p) {
return false
}
return l.iteratorContainsPoint(it, p)
} | go | func (l *Loop) ContainsPoint(p Point) bool {
// Empty and full loops don't need a special case, but invalid loops with
// zero vertices do, so we might as well handle them all at once.
if len(l.vertices) < 3 {
return l.originInside
}
// For small loops, and during initial construction, it is faster to just
// check all the crossing.
const maxBruteForceVertices = 32
if len(l.vertices) < maxBruteForceVertices || l.index == nil {
return l.bruteForceContainsPoint(p)
}
// Otherwise, look up the point in the index.
it := l.index.Iterator()
if !it.LocatePoint(p) {
return false
}
return l.iteratorContainsPoint(it, p)
} | [
"func",
"(",
"l",
"*",
"Loop",
")",
"ContainsPoint",
"(",
"p",
"Point",
")",
"bool",
"{",
"// Empty and full loops don't need a special case, but invalid loops with",
"// zero vertices do, so we might as well handle them all at once.",
"if",
"len",
"(",
"l",
".",
"vertices",
... | // ContainsPoint returns true if the loop contains the point. | [
"ContainsPoint",
"returns",
"true",
"if",
"the",
"loop",
"contains",
"the",
"point",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/loop.go#L587-L607 | train |
golang/geo | s2/loop.go | ContainsCell | func (l *Loop) ContainsCell(target Cell) bool {
it := l.index.Iterator()
relation := it.LocateCellID(target.ID())
// If "target" is disjoint from all index cells, it is not contained.
// Similarly, if "target" is subdivided into one or more index cells then it
// is not contained, since index cells are subdivided only if they (nearly)
// intersect a sufficient number of edges. (But note that if "target" itself
// is an index cell then it may be contained, since it could be a cell with
// no edges in the loop interior.)
if relation != Indexed {
return false
}
// Otherwise check if any edges intersect "target".
if l.boundaryApproxIntersects(it, target) {
return false
}
// Otherwise check if the loop contains the center of "target".
return l.iteratorContainsPoint(it, target.Center())
} | go | func (l *Loop) ContainsCell(target Cell) bool {
it := l.index.Iterator()
relation := it.LocateCellID(target.ID())
// If "target" is disjoint from all index cells, it is not contained.
// Similarly, if "target" is subdivided into one or more index cells then it
// is not contained, since index cells are subdivided only if they (nearly)
// intersect a sufficient number of edges. (But note that if "target" itself
// is an index cell then it may be contained, since it could be a cell with
// no edges in the loop interior.)
if relation != Indexed {
return false
}
// Otherwise check if any edges intersect "target".
if l.boundaryApproxIntersects(it, target) {
return false
}
// Otherwise check if the loop contains the center of "target".
return l.iteratorContainsPoint(it, target.Center())
} | [
"func",
"(",
"l",
"*",
"Loop",
")",
"ContainsCell",
"(",
"target",
"Cell",
")",
"bool",
"{",
"it",
":=",
"l",
".",
"index",
".",
"Iterator",
"(",
")",
"\n",
"relation",
":=",
"it",
".",
"LocateCellID",
"(",
"target",
".",
"ID",
"(",
")",
")",
"\n... | // ContainsCell reports whether the given Cell is contained by this Loop. | [
"ContainsCell",
"reports",
"whether",
"the",
"given",
"Cell",
"is",
"contained",
"by",
"this",
"Loop",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/loop.go#L610-L631 | train |
golang/geo | s2/loop.go | IntersectsCell | func (l *Loop) IntersectsCell(target Cell) bool {
it := l.index.Iterator()
relation := it.LocateCellID(target.ID())
// If target does not overlap any index cell, there is no intersection.
if relation == Disjoint {
return false
}
// If target is subdivided into one or more index cells, there is an
// intersection to within the ShapeIndex error bound (see Contains).
if relation == Subdivided {
return true
}
// If target is an index cell, there is an intersection because index cells
// are created only if they have at least one edge or they are entirely
// contained by the loop.
if it.CellID() == target.id {
return true
}
// Otherwise check if any edges intersect target.
if l.boundaryApproxIntersects(it, target) {
return true
}
// Otherwise check if the loop contains the center of target.
return l.iteratorContainsPoint(it, target.Center())
} | go | func (l *Loop) IntersectsCell(target Cell) bool {
it := l.index.Iterator()
relation := it.LocateCellID(target.ID())
// If target does not overlap any index cell, there is no intersection.
if relation == Disjoint {
return false
}
// If target is subdivided into one or more index cells, there is an
// intersection to within the ShapeIndex error bound (see Contains).
if relation == Subdivided {
return true
}
// If target is an index cell, there is an intersection because index cells
// are created only if they have at least one edge or they are entirely
// contained by the loop.
if it.CellID() == target.id {
return true
}
// Otherwise check if any edges intersect target.
if l.boundaryApproxIntersects(it, target) {
return true
}
// Otherwise check if the loop contains the center of target.
return l.iteratorContainsPoint(it, target.Center())
} | [
"func",
"(",
"l",
"*",
"Loop",
")",
"IntersectsCell",
"(",
"target",
"Cell",
")",
"bool",
"{",
"it",
":=",
"l",
".",
"index",
".",
"Iterator",
"(",
")",
"\n",
"relation",
":=",
"it",
".",
"LocateCellID",
"(",
"target",
".",
"ID",
"(",
")",
")",
"... | // IntersectsCell reports whether this Loop intersects the given cell. | [
"IntersectsCell",
"reports",
"whether",
"this",
"Loop",
"intersects",
"the",
"given",
"cell",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/loop.go#L634-L659 | train |
golang/geo | s2/loop.go | iteratorContainsPoint | func (l *Loop) iteratorContainsPoint(it *ShapeIndexIterator, p Point) bool {
// Test containment by drawing a line segment from the cell center to the
// given point and counting edge crossings.
aClipped := it.IndexCell().findByShapeID(0)
inside := aClipped.containsCenter
if len(aClipped.edges) > 0 {
center := it.Center()
crosser := NewEdgeCrosser(center, p)
aiPrev := -2
for _, ai := range aClipped.edges {
if ai != aiPrev+1 {
crosser.RestartAt(l.Vertex(ai))
}
aiPrev = ai
inside = inside != crosser.EdgeOrVertexChainCrossing(l.Vertex(ai+1))
}
}
return inside
} | go | func (l *Loop) iteratorContainsPoint(it *ShapeIndexIterator, p Point) bool {
// Test containment by drawing a line segment from the cell center to the
// given point and counting edge crossings.
aClipped := it.IndexCell().findByShapeID(0)
inside := aClipped.containsCenter
if len(aClipped.edges) > 0 {
center := it.Center()
crosser := NewEdgeCrosser(center, p)
aiPrev := -2
for _, ai := range aClipped.edges {
if ai != aiPrev+1 {
crosser.RestartAt(l.Vertex(ai))
}
aiPrev = ai
inside = inside != crosser.EdgeOrVertexChainCrossing(l.Vertex(ai+1))
}
}
return inside
} | [
"func",
"(",
"l",
"*",
"Loop",
")",
"iteratorContainsPoint",
"(",
"it",
"*",
"ShapeIndexIterator",
",",
"p",
"Point",
")",
"bool",
"{",
"// Test containment by drawing a line segment from the cell center to the",
"// given point and counting edge crossings.",
"aClipped",
":="... | // iteratorContainsPoint reports if the iterator that is positioned at the ShapeIndexCell
// that may contain p, contains the point p. | [
"iteratorContainsPoint",
"reports",
"if",
"the",
"iterator",
"that",
"is",
"positioned",
"at",
"the",
"ShapeIndexCell",
"that",
"may",
"contain",
"p",
"contains",
"the",
"point",
"p",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/loop.go#L698-L716 | train |
golang/geo | s2/loop.go | RegularLoop | func RegularLoop(center Point, radius s1.Angle, numVertices int) *Loop {
return RegularLoopForFrame(getFrame(center), radius, numVertices)
} | go | func RegularLoop(center Point, radius s1.Angle, numVertices int) *Loop {
return RegularLoopForFrame(getFrame(center), radius, numVertices)
} | [
"func",
"RegularLoop",
"(",
"center",
"Point",
",",
"radius",
"s1",
".",
"Angle",
",",
"numVertices",
"int",
")",
"*",
"Loop",
"{",
"return",
"RegularLoopForFrame",
"(",
"getFrame",
"(",
"center",
")",
",",
"radius",
",",
"numVertices",
")",
"\n",
"}"
] | // RegularLoop creates a loop with the given number of vertices, all
// located on a circle of the specified radius around the given center. | [
"RegularLoop",
"creates",
"a",
"loop",
"with",
"the",
"given",
"number",
"of",
"vertices",
"all",
"located",
"on",
"a",
"circle",
"of",
"the",
"specified",
"radius",
"around",
"the",
"given",
"center",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/loop.go#L720-L722 | train |
golang/geo | s2/loop.go | RegularLoopForFrame | func RegularLoopForFrame(frame matrix3x3, radius s1.Angle, numVertices int) *Loop {
return LoopFromPoints(regularPointsForFrame(frame, radius, numVertices))
} | go | func RegularLoopForFrame(frame matrix3x3, radius s1.Angle, numVertices int) *Loop {
return LoopFromPoints(regularPointsForFrame(frame, radius, numVertices))
} | [
"func",
"RegularLoopForFrame",
"(",
"frame",
"matrix3x3",
",",
"radius",
"s1",
".",
"Angle",
",",
"numVertices",
"int",
")",
"*",
"Loop",
"{",
"return",
"LoopFromPoints",
"(",
"regularPointsForFrame",
"(",
"frame",
",",
"radius",
",",
"numVertices",
")",
")",
... | // RegularLoopForFrame creates a loop centered around the z-axis of the given
// coordinate frame, with the first vertex in the direction of the positive x-axis. | [
"RegularLoopForFrame",
"creates",
"a",
"loop",
"centered",
"around",
"the",
"z",
"-",
"axis",
"of",
"the",
"given",
"coordinate",
"frame",
"with",
"the",
"first",
"vertex",
"in",
"the",
"direction",
"of",
"the",
"positive",
"x",
"-",
"axis",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/loop.go#L726-L728 | train |
golang/geo | s2/loop.go | turningAngleMaxError | 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))
} | go | 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))
} | [
"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()",
... | // turningAngleMaxError return the maximum error in TurningAngle. The value is not
// constant; it depends on the loop. | [
"turningAngleMaxError",
"return",
"the",
"maximum",
"error",
"in",
"TurningAngle",
".",
"The",
"value",
"is",
"not",
"constant",
";",
"it",
"depends",
"on",
"the",
"loop",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/loop.go#L808-L818 | train |
golang/geo | s2/loop.go | findVertex | func (l *Loop) findVertex(p Point) (index int, ok bool) {
const notFound = 0
if len(l.vertices) < 10 {
// Exhaustive search for loops below a small threshold.
for i := 1; i <= len(l.vertices); i++ {
if l.Vertex(i) == p {
return i, true
}
}
return notFound, false
}
it := l.index.Iterator()
if !it.LocatePoint(p) {
return notFound, false
}
aClipped := it.IndexCell().findByShapeID(0)
for i := aClipped.numEdges() - 1; i >= 0; i-- {
ai := aClipped.edges[i]
if l.Vertex(ai) == p {
if ai == 0 {
return len(l.vertices), true
}
return ai, true
}
if l.Vertex(ai+1) == p {
return ai + 1, true
}
}
return notFound, false
} | go | func (l *Loop) findVertex(p Point) (index int, ok bool) {
const notFound = 0
if len(l.vertices) < 10 {
// Exhaustive search for loops below a small threshold.
for i := 1; i <= len(l.vertices); i++ {
if l.Vertex(i) == p {
return i, true
}
}
return notFound, false
}
it := l.index.Iterator()
if !it.LocatePoint(p) {
return notFound, false
}
aClipped := it.IndexCell().findByShapeID(0)
for i := aClipped.numEdges() - 1; i >= 0; i-- {
ai := aClipped.edges[i]
if l.Vertex(ai) == p {
if ai == 0 {
return len(l.vertices), true
}
return ai, true
}
if l.Vertex(ai+1) == p {
return ai + 1, true
}
}
return notFound, false
} | [
"func",
"(",
"l",
"*",
"Loop",
")",
"findVertex",
"(",
"p",
"Point",
")",
"(",
"index",
"int",
",",
"ok",
"bool",
")",
"{",
"const",
"notFound",
"=",
"0",
"\n",
"if",
"len",
"(",
"l",
".",
"vertices",
")",
"<",
"10",
"{",
"// Exhaustive search for ... | // findVertex returns the index of the vertex at the given Point in the range
// 1..numVertices, and a boolean indicating if a vertex was found. | [
"findVertex",
"returns",
"the",
"index",
"of",
"the",
"vertex",
"at",
"the",
"given",
"Point",
"in",
"the",
"range",
"1",
"..",
"numVertices",
"and",
"a",
"boolean",
"indicating",
"if",
"a",
"vertex",
"was",
"found",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/loop.go#L892-L924 | train |
golang/geo | s2/loop.go | Encode | func (l Loop) Encode(w io.Writer) error {
e := &encoder{w: w}
l.encode(e)
return e.err
} | go | func (l Loop) Encode(w io.Writer) error {
e := &encoder{w: w}
l.encode(e)
return e.err
} | [
"func",
"(",
"l",
"Loop",
")",
"Encode",
"(",
"w",
"io",
".",
"Writer",
")",
"error",
"{",
"e",
":=",
"&",
"encoder",
"{",
"w",
":",
"w",
"}",
"\n",
"l",
".",
"encode",
"(",
"e",
")",
"\n",
"return",
"e",
".",
"err",
"\n",
"}"
] | // Encode encodes the Loop. | [
"Encode",
"encodes",
"the",
"Loop",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/loop.go#L1220-L1224 | train |
golang/geo | s2/loop.go | Decode | func (l *Loop) Decode(r io.Reader) error {
*l = Loop{}
d := &decoder{r: asByteReader(r)}
l.decode(d)
return d.err
} | go | func (l *Loop) Decode(r io.Reader) error {
*l = Loop{}
d := &decoder{r: asByteReader(r)}
l.decode(d)
return d.err
} | [
"func",
"(",
"l",
"*",
"Loop",
")",
"Decode",
"(",
"r",
"io",
".",
"Reader",
")",
"error",
"{",
"*",
"l",
"=",
"Loop",
"{",
"}",
"\n",
"d",
":=",
"&",
"decoder",
"{",
"r",
":",
"asByteReader",
"(",
"r",
")",
"}",
"\n",
"l",
".",
"decode",
"... | // Decode decodes a loop. | [
"Decode",
"decodes",
"a",
"loop",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/loop.go#L1243-L1248 | train |
golang/geo | s2/loop.go | startEdge | func (l *loopCrosser) startEdge(aj int) {
l.crosser = NewEdgeCrosser(l.a.Vertex(aj), l.a.Vertex(aj+1))
l.aj = aj
l.bjPrev = -2
} | go | func (l *loopCrosser) startEdge(aj int) {
l.crosser = NewEdgeCrosser(l.a.Vertex(aj), l.a.Vertex(aj+1))
l.aj = aj
l.bjPrev = -2
} | [
"func",
"(",
"l",
"*",
"loopCrosser",
")",
"startEdge",
"(",
"aj",
"int",
")",
"{",
"l",
".",
"crosser",
"=",
"NewEdgeCrosser",
"(",
"l",
".",
"a",
".",
"Vertex",
"(",
"aj",
")",
",",
"l",
".",
"a",
".",
"Vertex",
"(",
"aj",
"+",
"1",
")",
")... | // startEdge sets the crossers state for checking the given edge of loop A. | [
"startEdge",
"sets",
"the",
"crossers",
"state",
"for",
"checking",
"the",
"given",
"edge",
"of",
"loop",
"A",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/loop.go#L1466-L1470 | train |
golang/geo | s2/loop.go | edgeCrossesCell | func (l *loopCrosser) edgeCrossesCell(bClipped *clippedShape) bool {
// Test the current edge of A against all edges of bClipped
bNumEdges := bClipped.numEdges()
for j := 0; j < bNumEdges; j++ {
bj := bClipped.edges[j]
if bj != l.bjPrev+1 {
l.crosser.RestartAt(l.b.Vertex(bj))
}
l.bjPrev = bj
if crossing := l.crosser.ChainCrossingSign(l.b.Vertex(bj + 1)); crossing == DoNotCross {
continue
} else if crossing == Cross {
return true
}
// We only need to check each shared vertex once, so we only
// consider the case where l.aVertex(l.aj+1) == l.b.Vertex(bj+1).
if l.a.Vertex(l.aj+1) == l.b.Vertex(bj+1) {
if l.swapped {
if l.relation.wedgesCross(l.b.Vertex(bj), l.b.Vertex(bj+1), l.b.Vertex(bj+2), l.a.Vertex(l.aj), l.a.Vertex(l.aj+2)) {
return true
}
} else {
if l.relation.wedgesCross(l.a.Vertex(l.aj), l.a.Vertex(l.aj+1), l.a.Vertex(l.aj+2), l.b.Vertex(bj), l.b.Vertex(bj+2)) {
return true
}
}
}
}
return false
} | go | func (l *loopCrosser) edgeCrossesCell(bClipped *clippedShape) bool {
// Test the current edge of A against all edges of bClipped
bNumEdges := bClipped.numEdges()
for j := 0; j < bNumEdges; j++ {
bj := bClipped.edges[j]
if bj != l.bjPrev+1 {
l.crosser.RestartAt(l.b.Vertex(bj))
}
l.bjPrev = bj
if crossing := l.crosser.ChainCrossingSign(l.b.Vertex(bj + 1)); crossing == DoNotCross {
continue
} else if crossing == Cross {
return true
}
// We only need to check each shared vertex once, so we only
// consider the case where l.aVertex(l.aj+1) == l.b.Vertex(bj+1).
if l.a.Vertex(l.aj+1) == l.b.Vertex(bj+1) {
if l.swapped {
if l.relation.wedgesCross(l.b.Vertex(bj), l.b.Vertex(bj+1), l.b.Vertex(bj+2), l.a.Vertex(l.aj), l.a.Vertex(l.aj+2)) {
return true
}
} else {
if l.relation.wedgesCross(l.a.Vertex(l.aj), l.a.Vertex(l.aj+1), l.a.Vertex(l.aj+2), l.b.Vertex(bj), l.b.Vertex(bj+2)) {
return true
}
}
}
}
return false
} | [
"func",
"(",
"l",
"*",
"loopCrosser",
")",
"edgeCrossesCell",
"(",
"bClipped",
"*",
"clippedShape",
")",
"bool",
"{",
"// Test the current edge of A against all edges of bClipped",
"bNumEdges",
":=",
"bClipped",
".",
"numEdges",
"(",
")",
"\n",
"for",
"j",
":=",
"... | // edgeCrossesCell reports whether the current edge of loop A has any crossings with
// edges of the index cell of loop B. | [
"edgeCrossesCell",
"reports",
"whether",
"the",
"current",
"edge",
"of",
"loop",
"A",
"has",
"any",
"crossings",
"with",
"edges",
"of",
"the",
"index",
"cell",
"of",
"loop",
"B",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/loop.go#L1474-L1505 | train |
golang/geo | s2/loop.go | cellCrossesCell | func (l *loopCrosser) cellCrossesCell(aClipped, bClipped *clippedShape) bool {
// Test all edges of aClipped against all edges of bClipped.
for _, edge := range aClipped.edges {
l.startEdge(edge)
if l.edgeCrossesCell(bClipped) {
return true
}
}
return false
} | go | func (l *loopCrosser) cellCrossesCell(aClipped, bClipped *clippedShape) bool {
// Test all edges of aClipped against all edges of bClipped.
for _, edge := range aClipped.edges {
l.startEdge(edge)
if l.edgeCrossesCell(bClipped) {
return true
}
}
return false
} | [
"func",
"(",
"l",
"*",
"loopCrosser",
")",
"cellCrossesCell",
"(",
"aClipped",
",",
"bClipped",
"*",
"clippedShape",
")",
"bool",
"{",
"// Test all edges of aClipped against all edges of bClipped.",
"for",
"_",
",",
"edge",
":=",
"range",
"aClipped",
".",
"edges",
... | // cellCrossesCell reports whether there are any edge crossings or wedge crossings
// within the two given cells. | [
"cellCrossesCell",
"reports",
"whether",
"there",
"are",
"any",
"edge",
"crossings",
"or",
"wedge",
"crossings",
"within",
"the",
"two",
"given",
"cells",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/loop.go#L1509-L1519 | train |
golang/geo | s2/loop.go | cellCrossesAnySubcell | func (l *loopCrosser) cellCrossesAnySubcell(aClipped *clippedShape, bID CellID) bool {
// Test all edges of aClipped against all edges of B. The relevant B
// edges are guaranteed to be children of bID, which lets us find the
// correct index cells more efficiently.
bRoot := PaddedCellFromCellID(bID, 0)
for _, aj := range aClipped.edges {
// Use an CrossingEdgeQuery starting at bRoot to find the index cells
// of B that might contain crossing edges.
l.bCells = l.bQuery.getCells(l.a.Vertex(aj), l.a.Vertex(aj+1), bRoot)
if len(l.bCells) == 0 {
continue
}
l.startEdge(aj)
for c := 0; c < len(l.bCells); c++ {
if l.edgeCrossesCell(l.bCells[c].shapes[0]) {
return true
}
}
}
return false
} | go | func (l *loopCrosser) cellCrossesAnySubcell(aClipped *clippedShape, bID CellID) bool {
// Test all edges of aClipped against all edges of B. The relevant B
// edges are guaranteed to be children of bID, which lets us find the
// correct index cells more efficiently.
bRoot := PaddedCellFromCellID(bID, 0)
for _, aj := range aClipped.edges {
// Use an CrossingEdgeQuery starting at bRoot to find the index cells
// of B that might contain crossing edges.
l.bCells = l.bQuery.getCells(l.a.Vertex(aj), l.a.Vertex(aj+1), bRoot)
if len(l.bCells) == 0 {
continue
}
l.startEdge(aj)
for c := 0; c < len(l.bCells); c++ {
if l.edgeCrossesCell(l.bCells[c].shapes[0]) {
return true
}
}
}
return false
} | [
"func",
"(",
"l",
"*",
"loopCrosser",
")",
"cellCrossesAnySubcell",
"(",
"aClipped",
"*",
"clippedShape",
",",
"bID",
"CellID",
")",
"bool",
"{",
"// Test all edges of aClipped against all edges of B. The relevant B",
"// edges are guaranteed to be children of bID, which lets us ... | // cellCrossesAnySubcell reports whether given an index cell of A, if there are any
// edge or wedge crossings with any index cell of B contained within bID. | [
"cellCrossesAnySubcell",
"reports",
"whether",
"given",
"an",
"index",
"cell",
"of",
"A",
"if",
"there",
"are",
"any",
"edge",
"or",
"wedge",
"crossings",
"with",
"any",
"index",
"cell",
"of",
"B",
"contained",
"within",
"bID",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/loop.go#L1523-L1544 | train |
golang/geo | s2/projections.go | Interpolate | func (p *MercatorProjection) Interpolate(f float64, a, b r2.Point) r2.Point {
return a.Mul(1 - f).Add(b.Mul(f))
} | go | func (p *MercatorProjection) Interpolate(f float64, a, b r2.Point) r2.Point {
return a.Mul(1 - f).Add(b.Mul(f))
} | [
"func",
"(",
"p",
"*",
"MercatorProjection",
")",
"Interpolate",
"(",
"f",
"float64",
",",
"a",
",",
"b",
"r2",
".",
"Point",
")",
"r2",
".",
"Point",
"{",
"return",
"a",
".",
"Mul",
"(",
"1",
"-",
"f",
")",
".",
"Add",
"(",
"b",
".",
"Mul",
... | // Interpolate returns the point obtained by interpolating the given
// fraction of the distance along the line from A to B. | [
"Interpolate",
"returns",
"the",
"point",
"obtained",
"by",
"interpolating",
"the",
"given",
"fraction",
"of",
"the",
"distance",
"along",
"the",
"line",
"from",
"A",
"to",
"B",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/projections.go#L196-L198 | train |
golang/geo | s2/shape.go | defaultShapeIsEmpty | func defaultShapeIsEmpty(s Shape) bool {
return s.NumEdges() == 0 && (s.Dimension() != 2 || s.NumChains() == 0)
} | go | func defaultShapeIsEmpty(s Shape) bool {
return s.NumEdges() == 0 && (s.Dimension() != 2 || s.NumChains() == 0)
} | [
"func",
"defaultShapeIsEmpty",
"(",
"s",
"Shape",
")",
"bool",
"{",
"return",
"s",
".",
"NumEdges",
"(",
")",
"==",
"0",
"&&",
"(",
"s",
".",
"Dimension",
"(",
")",
"!=",
"2",
"||",
"s",
".",
"NumChains",
"(",
")",
"==",
"0",
")",
"\n",
"}"
] | // defaultShapeIsEmpty reports whether this shape contains no points. | [
"defaultShapeIsEmpty",
"reports",
"whether",
"this",
"shape",
"contains",
"no",
"points",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/shape.go#L228-L230 | train |
golang/geo | s2/shape.go | defaultShapeIsFull | func defaultShapeIsFull(s Shape) bool {
return s.NumEdges() == 0 && s.Dimension() == 2 && s.NumChains() > 0
} | go | func defaultShapeIsFull(s Shape) bool {
return s.NumEdges() == 0 && s.Dimension() == 2 && s.NumChains() > 0
} | [
"func",
"defaultShapeIsFull",
"(",
"s",
"Shape",
")",
"bool",
"{",
"return",
"s",
".",
"NumEdges",
"(",
")",
"==",
"0",
"&&",
"s",
".",
"Dimension",
"(",
")",
"==",
"2",
"&&",
"s",
".",
"NumChains",
"(",
")",
">",
"0",
"\n",
"}"
] | // defaultShapeIsFull reports whether this shape contains all points on the sphere. | [
"defaultShapeIsFull",
"reports",
"whether",
"this",
"shape",
"contains",
"all",
"points",
"on",
"the",
"sphere",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/shape.go#L233-L235 | train |
golang/geo | s2/shapeindex.go | newClippedShape | func newClippedShape(id int32, numEdges int) *clippedShape {
return &clippedShape{
shapeID: id,
edges: make([]int, numEdges),
}
} | go | func newClippedShape(id int32, numEdges int) *clippedShape {
return &clippedShape{
shapeID: id,
edges: make([]int, numEdges),
}
} | [
"func",
"newClippedShape",
"(",
"id",
"int32",
",",
"numEdges",
"int",
")",
"*",
"clippedShape",
"{",
"return",
"&",
"clippedShape",
"{",
"shapeID",
":",
"id",
",",
"edges",
":",
"make",
"(",
"[",
"]",
"int",
",",
"numEdges",
")",
",",
"}",
"\n",
"}"... | // newClippedShape returns a new clipped shape for the given shapeID and number of expected edges. | [
"newClippedShape",
"returns",
"a",
"new",
"clipped",
"shape",
"for",
"the",
"given",
"shapeID",
"and",
"number",
"of",
"expected",
"edges",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/shapeindex.go#L86-L91 | train |
golang/geo | s2/shapeindex.go | containsEdge | func (c *clippedShape) containsEdge(id int) bool {
// Linear search is fast because the number of edges per shape is typically
// very small (less than 10).
for _, e := range c.edges {
if e == id {
return true
}
}
return false
} | go | func (c *clippedShape) containsEdge(id int) bool {
// Linear search is fast because the number of edges per shape is typically
// very small (less than 10).
for _, e := range c.edges {
if e == id {
return true
}
}
return false
} | [
"func",
"(",
"c",
"*",
"clippedShape",
")",
"containsEdge",
"(",
"id",
"int",
")",
"bool",
"{",
"// Linear search is fast because the number of edges per shape is typically",
"// very small (less than 10).",
"for",
"_",
",",
"e",
":=",
"range",
"c",
".",
"edges",
"{",... | // containsEdge reports if this clipped shape contains the given edge ID. | [
"containsEdge",
"reports",
"if",
"this",
"clipped",
"shape",
"contains",
"the",
"given",
"edge",
"ID",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/shapeindex.go#L99-L108 | train |
golang/geo | s2/shapeindex.go | numEdges | func (s *ShapeIndexCell) numEdges() int {
var e int
for _, cs := range s.shapes {
e += cs.numEdges()
}
return e
} | go | func (s *ShapeIndexCell) numEdges() int {
var e int
for _, cs := range s.shapes {
e += cs.numEdges()
}
return e
} | [
"func",
"(",
"s",
"*",
"ShapeIndexCell",
")",
"numEdges",
"(",
")",
"int",
"{",
"var",
"e",
"int",
"\n",
"for",
"_",
",",
"cs",
":=",
"range",
"s",
".",
"shapes",
"{",
"e",
"+=",
"cs",
".",
"numEdges",
"(",
")",
"\n",
"}",
"\n",
"return",
"e",
... | // numEdges reports the total number of edges in all clipped shapes in this cell. | [
"numEdges",
"reports",
"the",
"total",
"number",
"of",
"edges",
"in",
"all",
"clipped",
"shapes",
"in",
"this",
"cell",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/shapeindex.go#L123-L129 | train |
golang/geo | s2/shapeindex.go | add | func (s *ShapeIndexCell) add(c *clippedShape) {
// C++ uses a set, so it's ordered and unique. We don't currently catch
// the case when a duplicate value is added.
s.shapes = append(s.shapes, c)
} | go | func (s *ShapeIndexCell) add(c *clippedShape) {
// C++ uses a set, so it's ordered and unique. We don't currently catch
// the case when a duplicate value is added.
s.shapes = append(s.shapes, c)
} | [
"func",
"(",
"s",
"*",
"ShapeIndexCell",
")",
"add",
"(",
"c",
"*",
"clippedShape",
")",
"{",
"// C++ uses a set, so it's ordered and unique. We don't currently catch",
"// the case when a duplicate value is added.",
"s",
".",
"shapes",
"=",
"append",
"(",
"s",
".",
"sh... | // add adds the given clipped shape to this index cell. | [
"add",
"adds",
"the",
"given",
"clipped",
"shape",
"to",
"this",
"index",
"cell",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/shapeindex.go#L132-L136 | train |
golang/geo | s2/shapeindex.go | findByShapeID | func (s *ShapeIndexCell) findByShapeID(shapeID int32) *clippedShape {
// Linear search is fine because the number of shapes per cell is typically
// very small (most often 1), and is large only for pathological inputs
// (e.g. very deeply nested loops).
for _, clipped := range s.shapes {
if clipped.shapeID == shapeID {
return clipped
}
}
return nil
} | go | func (s *ShapeIndexCell) findByShapeID(shapeID int32) *clippedShape {
// Linear search is fine because the number of shapes per cell is typically
// very small (most often 1), and is large only for pathological inputs
// (e.g. very deeply nested loops).
for _, clipped := range s.shapes {
if clipped.shapeID == shapeID {
return clipped
}
}
return nil
} | [
"func",
"(",
"s",
"*",
"ShapeIndexCell",
")",
"findByShapeID",
"(",
"shapeID",
"int32",
")",
"*",
"clippedShape",
"{",
"// Linear search is fine because the number of shapes per cell is typically",
"// very small (most often 1), and is large only for pathological inputs",
"// (e.g. v... | // findByShapeID returns the clipped shape that contains the given shapeID,
// or nil if none of the clipped shapes contain it. | [
"findByShapeID",
"returns",
"the",
"clipped",
"shape",
"that",
"contains",
"the",
"given",
"shapeID",
"or",
"nil",
"if",
"none",
"of",
"the",
"clipped",
"shapes",
"contain",
"it",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/shapeindex.go#L140-L150 | train |
golang/geo | s2/shapeindex.go | NewShapeIndexIterator | func NewShapeIndexIterator(index *ShapeIndex, pos ...ShapeIndexIteratorPos) *ShapeIndexIterator {
s := &ShapeIndexIterator{
index: index,
}
if len(pos) > 0 {
if len(pos) > 1 {
panic("too many ShapeIndexIteratorPos arguments")
}
switch pos[0] {
case IteratorBegin:
s.Begin()
case IteratorEnd:
s.End()
default:
panic("unknown ShapeIndexIteratorPos value")
}
}
return s
} | go | func NewShapeIndexIterator(index *ShapeIndex, pos ...ShapeIndexIteratorPos) *ShapeIndexIterator {
s := &ShapeIndexIterator{
index: index,
}
if len(pos) > 0 {
if len(pos) > 1 {
panic("too many ShapeIndexIteratorPos arguments")
}
switch pos[0] {
case IteratorBegin:
s.Begin()
case IteratorEnd:
s.End()
default:
panic("unknown ShapeIndexIteratorPos value")
}
}
return s
} | [
"func",
"NewShapeIndexIterator",
"(",
"index",
"*",
"ShapeIndex",
",",
"pos",
"...",
"ShapeIndexIteratorPos",
")",
"*",
"ShapeIndexIterator",
"{",
"s",
":=",
"&",
"ShapeIndexIterator",
"{",
"index",
":",
"index",
",",
"}",
"\n\n",
"if",
"len",
"(",
"pos",
")... | // NewShapeIndexIterator creates a new iterator for the given index. If a starting
// position is specified, the iterator is positioned at the given spot. | [
"NewShapeIndexIterator",
"creates",
"a",
"new",
"iterator",
"for",
"the",
"given",
"index",
".",
"If",
"a",
"starting",
"position",
"is",
"specified",
"the",
"iterator",
"is",
"positioned",
"at",
"the",
"given",
"spot",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/shapeindex.go#L212-L232 | train |
golang/geo | s2/shapeindex.go | Begin | func (s *ShapeIndexIterator) Begin() {
if !s.index.IsFresh() {
s.index.maybeApplyUpdates()
}
s.position = 0
s.refresh()
} | go | func (s *ShapeIndexIterator) Begin() {
if !s.index.IsFresh() {
s.index.maybeApplyUpdates()
}
s.position = 0
s.refresh()
} | [
"func",
"(",
"s",
"*",
"ShapeIndexIterator",
")",
"Begin",
"(",
")",
"{",
"if",
"!",
"s",
".",
"index",
".",
"IsFresh",
"(",
")",
"{",
"s",
".",
"index",
".",
"maybeApplyUpdates",
"(",
")",
"\n",
"}",
"\n",
"s",
".",
"position",
"=",
"0",
"\n",
... | // Begin positions the iterator at the beginning of the index. | [
"Begin",
"positions",
"the",
"iterator",
"at",
"the",
"beginning",
"of",
"the",
"index",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/shapeindex.go#L254-L260 | train |
golang/geo | s2/shapeindex.go | Prev | func (s *ShapeIndexIterator) Prev() bool {
if s.position <= 0 {
return false
}
s.position--
s.refresh()
return true
} | go | func (s *ShapeIndexIterator) Prev() bool {
if s.position <= 0 {
return false
}
s.position--
s.refresh()
return true
} | [
"func",
"(",
"s",
"*",
"ShapeIndexIterator",
")",
"Prev",
"(",
")",
"bool",
"{",
"if",
"s",
".",
"position",
"<=",
"0",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"s",
".",
"position",
"--",
"\n",
"s",
".",
"refresh",
"(",
")",
"\n",
"return",
"t... | // Prev advances the iterator to the previous cell in the index and returns true to
// indicate it was not yet at the beginning of the index. If the iterator is at the
// first cell the call does nothing and returns false. | [
"Prev",
"advances",
"the",
"iterator",
"to",
"the",
"previous",
"cell",
"in",
"the",
"index",
"and",
"returns",
"true",
"to",
"indicate",
"it",
"was",
"not",
"yet",
"at",
"the",
"beginning",
"of",
"the",
"index",
".",
"If",
"the",
"iterator",
"is",
"at",... | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/shapeindex.go#L271-L279 | train |
golang/geo | s2/shapeindex.go | End | func (s *ShapeIndexIterator) End() {
s.position = len(s.index.cells)
s.refresh()
} | go | func (s *ShapeIndexIterator) End() {
s.position = len(s.index.cells)
s.refresh()
} | [
"func",
"(",
"s",
"*",
"ShapeIndexIterator",
")",
"End",
"(",
")",
"{",
"s",
".",
"position",
"=",
"len",
"(",
"s",
".",
"index",
".",
"cells",
")",
"\n",
"s",
".",
"refresh",
"(",
")",
"\n",
"}"
] | // End positions the iterator at the end of the index. | [
"End",
"positions",
"the",
"iterator",
"at",
"the",
"end",
"of",
"the",
"index",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/shapeindex.go#L282-L285 | train |
golang/geo | s2/shapeindex.go | refresh | func (s *ShapeIndexIterator) refresh() {
if s.position < len(s.index.cells) {
s.id = s.index.cells[s.position]
s.cell = s.index.cellMap[s.CellID()]
} else {
s.id = SentinelCellID
s.cell = nil
}
} | go | func (s *ShapeIndexIterator) refresh() {
if s.position < len(s.index.cells) {
s.id = s.index.cells[s.position]
s.cell = s.index.cellMap[s.CellID()]
} else {
s.id = SentinelCellID
s.cell = nil
}
} | [
"func",
"(",
"s",
"*",
"ShapeIndexIterator",
")",
"refresh",
"(",
")",
"{",
"if",
"s",
".",
"position",
"<",
"len",
"(",
"s",
".",
"index",
".",
"cells",
")",
"{",
"s",
".",
"id",
"=",
"s",
".",
"index",
".",
"cells",
"[",
"s",
".",
"position",... | // refresh updates the stored internal iterator values. | [
"refresh",
"updates",
"the",
"stored",
"internal",
"iterator",
"values",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/shapeindex.go#L293-L301 | train |
golang/geo | s2/shapeindex.go | seek | func (s *ShapeIndexIterator) seek(target CellID) {
s.position = 0
// In C++, this relies on the lower_bound method of the underlying btree_map.
// TODO(roberts): Convert this to a binary search since the list of cells is ordered.
for k, v := range s.index.cells {
// We've passed the cell that is after us, so we are done.
if v >= target {
s.position = k
break
}
// Otherwise, advance the position.
s.position++
}
s.refresh()
} | go | func (s *ShapeIndexIterator) seek(target CellID) {
s.position = 0
// In C++, this relies on the lower_bound method of the underlying btree_map.
// TODO(roberts): Convert this to a binary search since the list of cells is ordered.
for k, v := range s.index.cells {
// We've passed the cell that is after us, so we are done.
if v >= target {
s.position = k
break
}
// Otherwise, advance the position.
s.position++
}
s.refresh()
} | [
"func",
"(",
"s",
"*",
"ShapeIndexIterator",
")",
"seek",
"(",
"target",
"CellID",
")",
"{",
"s",
".",
"position",
"=",
"0",
"\n",
"// In C++, this relies on the lower_bound method of the underlying btree_map.",
"// TODO(roberts): Convert this to a binary search since the list ... | // seek positions the iterator at the first cell whose ID >= target, or at the
// end of the index if no such cell exists. | [
"seek",
"positions",
"the",
"iterator",
"at",
"the",
"first",
"cell",
"whose",
"ID",
">",
"=",
"target",
"or",
"at",
"the",
"end",
"of",
"the",
"index",
"if",
"no",
"such",
"cell",
"exists",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/shapeindex.go#L305-L319 | train |
golang/geo | s2/shapeindex.go | LocatePoint | func (s *ShapeIndexIterator) LocatePoint(p Point) bool {
// Let I = cellMap.LowerBound(T), where T is the leaf cell containing
// point P. Then if T is contained by an index cell, then the
// containing cell is either I or I'. We test for containment by comparing
// the ranges of leaf cells spanned by T, I, and I'.
target := cellIDFromPoint(p)
s.seek(target)
if !s.Done() && s.CellID().RangeMin() <= target {
return true
}
if s.Prev() && s.CellID().RangeMax() >= target {
return true
}
return false
} | go | func (s *ShapeIndexIterator) LocatePoint(p Point) bool {
// Let I = cellMap.LowerBound(T), where T is the leaf cell containing
// point P. Then if T is contained by an index cell, then the
// containing cell is either I or I'. We test for containment by comparing
// the ranges of leaf cells spanned by T, I, and I'.
target := cellIDFromPoint(p)
s.seek(target)
if !s.Done() && s.CellID().RangeMin() <= target {
return true
}
if s.Prev() && s.CellID().RangeMax() >= target {
return true
}
return false
} | [
"func",
"(",
"s",
"*",
"ShapeIndexIterator",
")",
"LocatePoint",
"(",
"p",
"Point",
")",
"bool",
"{",
"// Let I = cellMap.LowerBound(T), where T is the leaf cell containing",
"// point P. Then if T is contained by an index cell, then the",
"// containing cell is either I or I'. We test... | // LocatePoint positions the iterator at the cell that contains the given Point.
// If no such cell exists, the iterator position is unspecified, and false is returned.
// The cell at the matched position is guaranteed to contain all edges that might
// intersect the line segment between target and the cell's center. | [
"LocatePoint",
"positions",
"the",
"iterator",
"at",
"the",
"cell",
"that",
"contains",
"the",
"given",
"Point",
".",
"If",
"no",
"such",
"cell",
"exists",
"the",
"iterator",
"position",
"is",
"unspecified",
"and",
"false",
"is",
"returned",
".",
"The",
"cel... | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/shapeindex.go#L325-L340 | train |
golang/geo | s2/shapeindex.go | newTracker | func newTracker() *tracker {
// As shapes are added, we compute which ones contain the start of the
// CellID space-filling curve by drawing an edge from OriginPoint to this
// point and counting how many shape edges cross this edge.
t := &tracker{
isActive: false,
b: trackerOrigin(),
nextCellID: CellIDFromFace(0).ChildBeginAtLevel(maxLevel),
}
t.drawTo(Point{faceUVToXYZ(0, -1, -1).Normalize()}) // CellID curve start
return t
} | go | func newTracker() *tracker {
// As shapes are added, we compute which ones contain the start of the
// CellID space-filling curve by drawing an edge from OriginPoint to this
// point and counting how many shape edges cross this edge.
t := &tracker{
isActive: false,
b: trackerOrigin(),
nextCellID: CellIDFromFace(0).ChildBeginAtLevel(maxLevel),
}
t.drawTo(Point{faceUVToXYZ(0, -1, -1).Normalize()}) // CellID curve start
return t
} | [
"func",
"newTracker",
"(",
")",
"*",
"tracker",
"{",
"// As shapes are added, we compute which ones contain the start of the",
"// CellID space-filling curve by drawing an edge from OriginPoint to this",
"// point and counting how many shape edges cross this edge.",
"t",
":=",
"&",
"tracke... | // newTracker returns a new tracker with the appropriate defaults. | [
"newTracker",
"returns",
"a",
"new",
"tracker",
"with",
"the",
"appropriate",
"defaults",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/shapeindex.go#L402-L414 | train |
golang/geo | s2/shapeindex.go | drawTo | func (t *tracker) drawTo(b Point) {
t.a = t.b
t.b = b
// TODO: the edge crosser may need an in-place Init method if this gets expensive
t.crosser = NewEdgeCrosser(t.a, t.b)
} | go | func (t *tracker) drawTo(b Point) {
t.a = t.b
t.b = b
// TODO: the edge crosser may need an in-place Init method if this gets expensive
t.crosser = NewEdgeCrosser(t.a, t.b)
} | [
"func",
"(",
"t",
"*",
"tracker",
")",
"drawTo",
"(",
"b",
"Point",
")",
"{",
"t",
".",
"a",
"=",
"t",
".",
"b",
"\n",
"t",
".",
"b",
"=",
"b",
"\n",
"// TODO: the edge crosser may need an in-place Init method if this gets expensive",
"t",
".",
"crosser",
... | // drawTo moves the focus of the tracker to the given point. After this method is
// called, testEdge should be called with all edges that may cross the line
// segment between the old and new focus locations. | [
"drawTo",
"moves",
"the",
"focus",
"of",
"the",
"tracker",
"to",
"the",
"given",
"point",
".",
"After",
"this",
"method",
"is",
"called",
"testEdge",
"should",
"be",
"called",
"with",
"all",
"edges",
"that",
"may",
"cross",
"the",
"line",
"segment",
"betwe... | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/shapeindex.go#L449-L454 | train |
golang/geo | s2/shapeindex.go | toggleShape | func (t *tracker) toggleShape(shapeID int32) {
// Most shapeIDs slices are small, so special case the common steps.
// If there is nothing here, add it.
if len(t.shapeIDs) == 0 {
t.shapeIDs = append(t.shapeIDs, shapeID)
return
}
// If it's the first element, drop it from the slice.
if t.shapeIDs[0] == shapeID {
t.shapeIDs = t.shapeIDs[1:]
return
}
for i, s := range t.shapeIDs {
if s < shapeID {
continue
}
// If it's in the set, cut it out.
if s == shapeID {
copy(t.shapeIDs[i:], t.shapeIDs[i+1:]) // overwrite the ith element
t.shapeIDs = t.shapeIDs[:len(t.shapeIDs)-1]
return
}
// We've got to a point in the slice where we should be inserted.
// (the given shapeID is now less than the current positions id.)
t.shapeIDs = append(t.shapeIDs[0:i],
append([]int32{shapeID}, t.shapeIDs[i:len(t.shapeIDs)]...)...)
return
}
// We got to the end and didn't find it, so add it to the list.
t.shapeIDs = append(t.shapeIDs, shapeID)
} | go | func (t *tracker) toggleShape(shapeID int32) {
// Most shapeIDs slices are small, so special case the common steps.
// If there is nothing here, add it.
if len(t.shapeIDs) == 0 {
t.shapeIDs = append(t.shapeIDs, shapeID)
return
}
// If it's the first element, drop it from the slice.
if t.shapeIDs[0] == shapeID {
t.shapeIDs = t.shapeIDs[1:]
return
}
for i, s := range t.shapeIDs {
if s < shapeID {
continue
}
// If it's in the set, cut it out.
if s == shapeID {
copy(t.shapeIDs[i:], t.shapeIDs[i+1:]) // overwrite the ith element
t.shapeIDs = t.shapeIDs[:len(t.shapeIDs)-1]
return
}
// We've got to a point in the slice where we should be inserted.
// (the given shapeID is now less than the current positions id.)
t.shapeIDs = append(t.shapeIDs[0:i],
append([]int32{shapeID}, t.shapeIDs[i:len(t.shapeIDs)]...)...)
return
}
// We got to the end and didn't find it, so add it to the list.
t.shapeIDs = append(t.shapeIDs, shapeID)
} | [
"func",
"(",
"t",
"*",
"tracker",
")",
"toggleShape",
"(",
"shapeID",
"int32",
")",
"{",
"// Most shapeIDs slices are small, so special case the common steps.",
"// If there is nothing here, add it.",
"if",
"len",
"(",
"t",
".",
"shapeIDs",
")",
"==",
"0",
"{",
"t",
... | // toggleShape adds or removes the given shapeID from the set of IDs it is tracking. | [
"toggleShape",
"adds",
"or",
"removes",
"the",
"given",
"shapeID",
"from",
"the",
"set",
"of",
"IDs",
"it",
"is",
"tracking",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/shapeindex.go#L481-L517 | train |
golang/geo | s2/shapeindex.go | restoreStateBefore | func (t *tracker) restoreStateBefore(limitShapeID int32) {
limit := t.lowerBound(limitShapeID)
t.shapeIDs = append(append([]int32(nil), t.savedIDs...), t.shapeIDs[limit:]...)
t.savedIDs = nil
} | go | func (t *tracker) restoreStateBefore(limitShapeID int32) {
limit := t.lowerBound(limitShapeID)
t.shapeIDs = append(append([]int32(nil), t.savedIDs...), t.shapeIDs[limit:]...)
t.savedIDs = nil
} | [
"func",
"(",
"t",
"*",
"tracker",
")",
"restoreStateBefore",
"(",
"limitShapeID",
"int32",
")",
"{",
"limit",
":=",
"t",
".",
"lowerBound",
"(",
"limitShapeID",
")",
"\n",
"t",
".",
"shapeIDs",
"=",
"append",
"(",
"append",
"(",
"[",
"]",
"int32",
"(",... | // restoreStateBefore restores the state previously saved by saveAndClearStateBefore.
// This only affects the state for shapeIDs below "limitShapeID". | [
"restoreStateBefore",
"restores",
"the",
"state",
"previously",
"saved",
"by",
"saveAndClearStateBefore",
".",
"This",
"only",
"affects",
"the",
"state",
"for",
"shapeIDs",
"below",
"limitShapeID",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/shapeindex.go#L530-L534 | train |
golang/geo | s2/shapeindex.go | NewShapeIndex | func NewShapeIndex() *ShapeIndex {
return &ShapeIndex{
maxEdgesPerCell: 10,
shapes: make(map[int32]Shape),
cellMap: make(map[CellID]*ShapeIndexCell),
cells: nil,
status: fresh,
}
} | go | func NewShapeIndex() *ShapeIndex {
return &ShapeIndex{
maxEdgesPerCell: 10,
shapes: make(map[int32]Shape),
cellMap: make(map[CellID]*ShapeIndexCell),
cells: nil,
status: fresh,
}
} | [
"func",
"NewShapeIndex",
"(",
")",
"*",
"ShapeIndex",
"{",
"return",
"&",
"ShapeIndex",
"{",
"maxEdgesPerCell",
":",
"10",
",",
"shapes",
":",
"make",
"(",
"map",
"[",
"int32",
"]",
"Shape",
")",
",",
"cellMap",
":",
"make",
"(",
"map",
"[",
"CellID",
... | // NewShapeIndex creates a new ShapeIndex. | [
"NewShapeIndex",
"creates",
"a",
"new",
"ShapeIndex",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/shapeindex.go#L631-L639 | train |
golang/geo | s2/shapeindex.go | Reset | func (s *ShapeIndex) Reset() {
s.shapes = make(map[int32]Shape)
s.nextID = 0
s.cellMap = make(map[CellID]*ShapeIndexCell)
s.cells = nil
atomic.StoreInt32(&s.status, fresh)
} | go | func (s *ShapeIndex) Reset() {
s.shapes = make(map[int32]Shape)
s.nextID = 0
s.cellMap = make(map[CellID]*ShapeIndexCell)
s.cells = nil
atomic.StoreInt32(&s.status, fresh)
} | [
"func",
"(",
"s",
"*",
"ShapeIndex",
")",
"Reset",
"(",
")",
"{",
"s",
".",
"shapes",
"=",
"make",
"(",
"map",
"[",
"int32",
"]",
"Shape",
")",
"\n",
"s",
".",
"nextID",
"=",
"0",
"\n",
"s",
".",
"cellMap",
"=",
"make",
"(",
"map",
"[",
"Cell... | // Reset resets the index to its original state. | [
"Reset",
"resets",
"the",
"index",
"to",
"its",
"original",
"state",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/shapeindex.go#L669-L675 | train |
golang/geo | s2/shapeindex.go | NumEdges | func (s *ShapeIndex) NumEdges() int {
numEdges := 0
for _, shape := range s.shapes {
numEdges += shape.NumEdges()
}
return numEdges
} | go | func (s *ShapeIndex) NumEdges() int {
numEdges := 0
for _, shape := range s.shapes {
numEdges += shape.NumEdges()
}
return numEdges
} | [
"func",
"(",
"s",
"*",
"ShapeIndex",
")",
"NumEdges",
"(",
")",
"int",
"{",
"numEdges",
":=",
"0",
"\n",
"for",
"_",
",",
"shape",
":=",
"range",
"s",
".",
"shapes",
"{",
"numEdges",
"+=",
"shape",
".",
"NumEdges",
"(",
")",
"\n",
"}",
"\n",
"ret... | // NumEdges returns the number of edges in this index. | [
"NumEdges",
"returns",
"the",
"number",
"of",
"edges",
"in",
"this",
"index",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/shapeindex.go#L678-L684 | train |
golang/geo | s2/shapeindex.go | NumEdgesUpTo | func (s *ShapeIndex) NumEdgesUpTo(limit int) int {
var numEdges int
// We choose to iterate over the shapes in order to match the counting
// up behavior in C++ and for test compatibility instead of using a
// more idiomatic range over the shape map.
for i := int32(0); i <= s.nextID; i++ {
s := s.Shape(i)
if s == nil {
continue
}
numEdges += s.NumEdges()
if numEdges >= limit {
break
}
}
return numEdges
} | go | func (s *ShapeIndex) NumEdgesUpTo(limit int) int {
var numEdges int
// We choose to iterate over the shapes in order to match the counting
// up behavior in C++ and for test compatibility instead of using a
// more idiomatic range over the shape map.
for i := int32(0); i <= s.nextID; i++ {
s := s.Shape(i)
if s == nil {
continue
}
numEdges += s.NumEdges()
if numEdges >= limit {
break
}
}
return numEdges
} | [
"func",
"(",
"s",
"*",
"ShapeIndex",
")",
"NumEdgesUpTo",
"(",
"limit",
"int",
")",
"int",
"{",
"var",
"numEdges",
"int",
"\n",
"// We choose to iterate over the shapes in order to match the counting",
"// up behavior in C++ and for test compatibility instead of using a",
"// m... | // NumEdgesUpTo returns the number of edges in the given index, up to the given
// limit. If the limit is encountered, the current running total is returned,
// which may be more than the limit. | [
"NumEdgesUpTo",
"returns",
"the",
"number",
"of",
"edges",
"in",
"the",
"given",
"index",
"up",
"to",
"the",
"given",
"limit",
".",
"If",
"the",
"limit",
"is",
"encountered",
"the",
"current",
"running",
"total",
"is",
"returned",
"which",
"may",
"be",
"mo... | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/shapeindex.go#L689-L706 | train |
golang/geo | s2/shapeindex.go | Add | func (s *ShapeIndex) Add(shape Shape) int32 {
s.shapes[s.nextID] = shape
s.nextID++
atomic.StoreInt32(&s.status, stale)
return s.nextID - 1
} | go | func (s *ShapeIndex) Add(shape Shape) int32 {
s.shapes[s.nextID] = shape
s.nextID++
atomic.StoreInt32(&s.status, stale)
return s.nextID - 1
} | [
"func",
"(",
"s",
"*",
"ShapeIndex",
")",
"Add",
"(",
"shape",
"Shape",
")",
"int32",
"{",
"s",
".",
"shapes",
"[",
"s",
".",
"nextID",
"]",
"=",
"shape",
"\n",
"s",
".",
"nextID",
"++",
"\n",
"atomic",
".",
"StoreInt32",
"(",
"&",
"s",
".",
"s... | // Add adds the given shape to the index and returns the assigned ID.. | [
"Add",
"adds",
"the",
"given",
"shape",
"to",
"the",
"index",
"and",
"returns",
"the",
"assigned",
"ID",
".."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/shapeindex.go#L728-L733 | train |
golang/geo | s2/shapeindex.go | Remove | func (s *ShapeIndex) Remove(shape Shape) {
// The index updates itself lazily because it is much more efficient to
// process additions and removals in batches.
id := s.idForShape(shape)
// If the shape wasn't found, it's already been removed or was not in the index.
if s.shapes[id] == nil {
return
}
// Remove the shape from the shapes map.
delete(s.shapes, id)
// We are removing a shape that has not yet been added to the index,
// so there is nothing else to do.
if id >= s.pendingAdditionsPos {
return
}
numEdges := shape.NumEdges()
removed := &removedShape{
shapeID: id,
hasInterior: shape.Dimension() == 2,
containsTrackerOrigin: shape.ReferencePoint().Contained,
edges: make([]Edge, numEdges),
}
for e := 0; e < numEdges; e++ {
removed.edges[e] = shape.Edge(e)
}
s.pendingRemovals = append(s.pendingRemovals, removed)
atomic.StoreInt32(&s.status, stale)
} | go | func (s *ShapeIndex) Remove(shape Shape) {
// The index updates itself lazily because it is much more efficient to
// process additions and removals in batches.
id := s.idForShape(shape)
// If the shape wasn't found, it's already been removed or was not in the index.
if s.shapes[id] == nil {
return
}
// Remove the shape from the shapes map.
delete(s.shapes, id)
// We are removing a shape that has not yet been added to the index,
// so there is nothing else to do.
if id >= s.pendingAdditionsPos {
return
}
numEdges := shape.NumEdges()
removed := &removedShape{
shapeID: id,
hasInterior: shape.Dimension() == 2,
containsTrackerOrigin: shape.ReferencePoint().Contained,
edges: make([]Edge, numEdges),
}
for e := 0; e < numEdges; e++ {
removed.edges[e] = shape.Edge(e)
}
s.pendingRemovals = append(s.pendingRemovals, removed)
atomic.StoreInt32(&s.status, stale)
} | [
"func",
"(",
"s",
"*",
"ShapeIndex",
")",
"Remove",
"(",
"shape",
"Shape",
")",
"{",
"// The index updates itself lazily because it is much more efficient to",
"// process additions and removals in batches.",
"id",
":=",
"s",
".",
"idForShape",
"(",
"shape",
")",
"\n\n",
... | // Remove removes the given shape from the index. | [
"Remove",
"removes",
"the",
"given",
"shape",
"from",
"the",
"index",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/shapeindex.go#L736-L769 | train |
golang/geo | s2/shapeindex.go | maybeApplyUpdates | func (s *ShapeIndex) maybeApplyUpdates() {
// TODO(roberts): To avoid acquiring and releasing the mutex on every
// query, we should use atomic operations when testing whether the status
// is fresh and when updating the status to be fresh. This guarantees
// that any thread that sees a status of fresh will also see the
// corresponding index updates.
if atomic.LoadInt32(&s.status) != fresh {
s.mu.Lock()
s.applyUpdatesInternal()
atomic.StoreInt32(&s.status, fresh)
s.mu.Unlock()
}
} | go | func (s *ShapeIndex) maybeApplyUpdates() {
// TODO(roberts): To avoid acquiring and releasing the mutex on every
// query, we should use atomic operations when testing whether the status
// is fresh and when updating the status to be fresh. This guarantees
// that any thread that sees a status of fresh will also see the
// corresponding index updates.
if atomic.LoadInt32(&s.status) != fresh {
s.mu.Lock()
s.applyUpdatesInternal()
atomic.StoreInt32(&s.status, fresh)
s.mu.Unlock()
}
} | [
"func",
"(",
"s",
"*",
"ShapeIndex",
")",
"maybeApplyUpdates",
"(",
")",
"{",
"// TODO(roberts): To avoid acquiring and releasing the mutex on every",
"// query, we should use atomic operations when testing whether the status",
"// is fresh and when updating the status to be fresh. This guar... | // maybeApplyUpdates checks if the index pieces have changed, and if so, applies pending updates. | [
"maybeApplyUpdates",
"checks",
"if",
"the",
"index",
"pieces",
"have",
"changed",
"and",
"if",
"so",
"applies",
"pending",
"updates",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/shapeindex.go#L797-L809 | train |
golang/geo | s2/shapeindex.go | addShapeInternal | func (s *ShapeIndex) addShapeInternal(shapeID int32, allEdges [][]faceEdge, t *tracker) {
shape, ok := s.shapes[shapeID]
if !ok {
// This shape has already been removed.
return
}
faceEdge := faceEdge{
shapeID: shapeID,
hasInterior: shape.Dimension() == 2,
}
if faceEdge.hasInterior {
t.addShape(shapeID, containsBruteForce(shape, t.focus()))
}
numEdges := shape.NumEdges()
for e := 0; e < numEdges; e++ {
edge := shape.Edge(e)
faceEdge.edgeID = e
faceEdge.edge = edge
faceEdge.maxLevel = maxLevelForEdge(edge)
s.addFaceEdge(faceEdge, allEdges)
}
} | go | func (s *ShapeIndex) addShapeInternal(shapeID int32, allEdges [][]faceEdge, t *tracker) {
shape, ok := s.shapes[shapeID]
if !ok {
// This shape has already been removed.
return
}
faceEdge := faceEdge{
shapeID: shapeID,
hasInterior: shape.Dimension() == 2,
}
if faceEdge.hasInterior {
t.addShape(shapeID, containsBruteForce(shape, t.focus()))
}
numEdges := shape.NumEdges()
for e := 0; e < numEdges; e++ {
edge := shape.Edge(e)
faceEdge.edgeID = e
faceEdge.edge = edge
faceEdge.maxLevel = maxLevelForEdge(edge)
s.addFaceEdge(faceEdge, allEdges)
}
} | [
"func",
"(",
"s",
"*",
"ShapeIndex",
")",
"addShapeInternal",
"(",
"shapeID",
"int32",
",",
"allEdges",
"[",
"]",
"[",
"]",
"faceEdge",
",",
"t",
"*",
"tracker",
")",
"{",
"shape",
",",
"ok",
":=",
"s",
".",
"shapes",
"[",
"shapeID",
"]",
"\n",
"if... | // addShapeInternal clips all edges of the given shape to the six cube faces,
// adds the clipped edges to the set of allEdges, and starts tracking its
// interior if necessary. | [
"addShapeInternal",
"clips",
"all",
"edges",
"of",
"the",
"given",
"shape",
"to",
"the",
"six",
"cube",
"faces",
"adds",
"the",
"clipped",
"edges",
"to",
"the",
"set",
"of",
"allEdges",
"and",
"starts",
"tracking",
"its",
"interior",
"if",
"necessary",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/shapeindex.go#L843-L868 | train |
golang/geo | s2/shapeindex.go | addFaceEdge | func (s *ShapeIndex) addFaceEdge(fe faceEdge, allEdges [][]faceEdge) {
aFace := face(fe.edge.V0.Vector)
// See if both endpoints are on the same face, and are far enough from
// the edge of the face that they don't intersect any (padded) adjacent face.
if aFace == face(fe.edge.V1.Vector) {
x, y := validFaceXYZToUV(aFace, fe.edge.V0.Vector)
fe.a = r2.Point{x, y}
x, y = validFaceXYZToUV(aFace, fe.edge.V1.Vector)
fe.b = r2.Point{x, y}
maxUV := 1 - cellPadding
if math.Abs(fe.a.X) <= maxUV && math.Abs(fe.a.Y) <= maxUV &&
math.Abs(fe.b.X) <= maxUV && math.Abs(fe.b.Y) <= maxUV {
allEdges[aFace] = append(allEdges[aFace], fe)
return
}
}
// Otherwise, we simply clip the edge to all six faces.
for face := 0; face < 6; face++ {
if aClip, bClip, intersects := ClipToPaddedFace(fe.edge.V0, fe.edge.V1, face, cellPadding); intersects {
fe.a = aClip
fe.b = bClip
allEdges[face] = append(allEdges[face], fe)
}
}
return
} | go | func (s *ShapeIndex) addFaceEdge(fe faceEdge, allEdges [][]faceEdge) {
aFace := face(fe.edge.V0.Vector)
// See if both endpoints are on the same face, and are far enough from
// the edge of the face that they don't intersect any (padded) adjacent face.
if aFace == face(fe.edge.V1.Vector) {
x, y := validFaceXYZToUV(aFace, fe.edge.V0.Vector)
fe.a = r2.Point{x, y}
x, y = validFaceXYZToUV(aFace, fe.edge.V1.Vector)
fe.b = r2.Point{x, y}
maxUV := 1 - cellPadding
if math.Abs(fe.a.X) <= maxUV && math.Abs(fe.a.Y) <= maxUV &&
math.Abs(fe.b.X) <= maxUV && math.Abs(fe.b.Y) <= maxUV {
allEdges[aFace] = append(allEdges[aFace], fe)
return
}
}
// Otherwise, we simply clip the edge to all six faces.
for face := 0; face < 6; face++ {
if aClip, bClip, intersects := ClipToPaddedFace(fe.edge.V0, fe.edge.V1, face, cellPadding); intersects {
fe.a = aClip
fe.b = bClip
allEdges[face] = append(allEdges[face], fe)
}
}
return
} | [
"func",
"(",
"s",
"*",
"ShapeIndex",
")",
"addFaceEdge",
"(",
"fe",
"faceEdge",
",",
"allEdges",
"[",
"]",
"[",
"]",
"faceEdge",
")",
"{",
"aFace",
":=",
"face",
"(",
"fe",
".",
"edge",
".",
"V0",
".",
"Vector",
")",
"\n",
"// See if both endpoints are... | // addFaceEdge adds the given faceEdge into the collection of all edges. | [
"addFaceEdge",
"adds",
"the",
"given",
"faceEdge",
"into",
"the",
"collection",
"of",
"all",
"edges",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/shapeindex.go#L871-L898 | train |
golang/geo | s2/shapeindex.go | shrinkToFit | func (s *ShapeIndex) shrinkToFit(pcell *PaddedCell, bound r2.Rect) CellID {
shrunkID := pcell.ShrinkToFit(bound)
if !s.isFirstUpdate() && shrunkID != pcell.CellID() {
// Don't shrink any smaller than the existing index cells, since we need
// to combine the new edges with those cells.
iter := s.Iterator()
if iter.LocateCellID(shrunkID) == Indexed {
shrunkID = iter.CellID()
}
}
return shrunkID
} | go | func (s *ShapeIndex) shrinkToFit(pcell *PaddedCell, bound r2.Rect) CellID {
shrunkID := pcell.ShrinkToFit(bound)
if !s.isFirstUpdate() && shrunkID != pcell.CellID() {
// Don't shrink any smaller than the existing index cells, since we need
// to combine the new edges with those cells.
iter := s.Iterator()
if iter.LocateCellID(shrunkID) == Indexed {
shrunkID = iter.CellID()
}
}
return shrunkID
} | [
"func",
"(",
"s",
"*",
"ShapeIndex",
")",
"shrinkToFit",
"(",
"pcell",
"*",
"PaddedCell",
",",
"bound",
"r2",
".",
"Rect",
")",
"CellID",
"{",
"shrunkID",
":=",
"pcell",
".",
"ShrinkToFit",
"(",
"bound",
")",
"\n\n",
"if",
"!",
"s",
".",
"isFirstUpdate... | // shrinkToFit shrinks the PaddedCell to fit within the given bounds. | [
"shrinkToFit",
"shrinks",
"the",
"PaddedCell",
"to",
"fit",
"within",
"the",
"given",
"bounds",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/shapeindex.go#L950-L962 | train |
golang/geo | s2/shapeindex.go | skipCellRange | func (s *ShapeIndex) skipCellRange(begin, end CellID, t *tracker, disjointFromIndex bool) {
// If we aren't in the interior of a shape, then skipping over cells is easy.
if len(t.shapeIDs) == 0 {
return
}
// Otherwise generate the list of cell ids that we need to visit, and create
// an index entry for each one.
skipped := CellUnionFromRange(begin, end)
for _, cell := range skipped {
var clippedEdges []*clippedEdge
s.updateEdges(PaddedCellFromCellID(cell, cellPadding), clippedEdges, t, disjointFromIndex)
}
} | go | func (s *ShapeIndex) skipCellRange(begin, end CellID, t *tracker, disjointFromIndex bool) {
// If we aren't in the interior of a shape, then skipping over cells is easy.
if len(t.shapeIDs) == 0 {
return
}
// Otherwise generate the list of cell ids that we need to visit, and create
// an index entry for each one.
skipped := CellUnionFromRange(begin, end)
for _, cell := range skipped {
var clippedEdges []*clippedEdge
s.updateEdges(PaddedCellFromCellID(cell, cellPadding), clippedEdges, t, disjointFromIndex)
}
} | [
"func",
"(",
"s",
"*",
"ShapeIndex",
")",
"skipCellRange",
"(",
"begin",
",",
"end",
"CellID",
",",
"t",
"*",
"tracker",
",",
"disjointFromIndex",
"bool",
")",
"{",
"// If we aren't in the interior of a shape, then skipping over cells is easy.",
"if",
"len",
"(",
"t... | // skipCellRange skips over the cells in the given range, creating index cells if we are
// currently in the interior of at least one shape. | [
"skipCellRange",
"skips",
"over",
"the",
"cells",
"in",
"the",
"given",
"range",
"creating",
"index",
"cells",
"if",
"we",
"are",
"currently",
"in",
"the",
"interior",
"of",
"at",
"least",
"one",
"shape",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/shapeindex.go#L966-L979 | train |
golang/geo | s2/shapeindex.go | makeIndexCell | func (s *ShapeIndex) makeIndexCell(p *PaddedCell, edges []*clippedEdge, t *tracker) bool {
// If the cell is empty, no index cell is needed. (In most cases this
// situation is detected before we get to this point, but this can happen
// when all shapes in a cell are removed.)
if len(edges) == 0 && len(t.shapeIDs) == 0 {
return true
}
// Count the number of edges that have not reached their maximum level yet.
// Return false if there are too many such edges.
count := 0
for _, ce := range edges {
if p.Level() < ce.faceEdge.maxLevel {
count++
}
if count > s.maxEdgesPerCell {
return false
}
}
// Possible optimization: Continue subdividing as long as exactly one child
// of the padded cell intersects the given edges. This can be done by finding
// the bounding box of all the edges and calling ShrinkToFit:
//
// cellID = p.ShrinkToFit(RectBound(edges));
//
// Currently this is not beneficial; it slows down construction by 4-25%
// (mainly computing the union of the bounding rectangles) and also slows
// down queries (since more recursive clipping is required to get down to
// the level of a spatial index cell). But it may be worth trying again
// once containsCenter is computed and all algorithms are modified to
// take advantage of it.
// We update the InteriorTracker as follows. For every Cell in the index
// we construct two edges: one edge from entry vertex of the cell to its
// center, and one from the cell center to its exit vertex. Here entry
// and exit refer the CellID ordering, i.e. the order in which points
// are encountered along the 2 space-filling curve. The exit vertex then
// becomes the entry vertex for the next cell in the index, unless there are
// one or more empty intervening cells, in which case the InteriorTracker
// state is unchanged because the intervening cells have no edges.
// Shift the InteriorTracker focus point to the center of the current cell.
if t.isActive && len(edges) != 0 {
if !t.atCellID(p.id) {
t.moveTo(p.EntryVertex())
}
t.drawTo(p.Center())
s.testAllEdges(edges, t)
}
// Allocate and fill a new index cell. To get the total number of shapes we
// need to merge the shapes associated with the intersecting edges together
// with the shapes that happen to contain the cell center.
cshapeIDs := t.shapeIDs
numShapes := s.countShapes(edges, cshapeIDs)
cell := NewShapeIndexCell(numShapes)
// To fill the index cell we merge the two sources of shapes: edge shapes
// (those that have at least one edge that intersects this cell), and
// containing shapes (those that contain the cell center). We keep track
// of the index of the next intersecting edge and the next containing shape
// as we go along. Both sets of shape ids are already sorted.
eNext := 0
cNextIdx := 0
for i := 0; i < numShapes; i++ {
var clipped *clippedShape
// advance to next value base + i
eshapeID := int32(s.Len())
cshapeID := int32(eshapeID) // Sentinels
if eNext != len(edges) {
eshapeID = edges[eNext].faceEdge.shapeID
}
if cNextIdx < len(cshapeIDs) {
cshapeID = cshapeIDs[cNextIdx]
}
eBegin := eNext
if cshapeID < eshapeID {
// The entire cell is in the shape interior.
clipped = newClippedShape(cshapeID, 0)
clipped.containsCenter = true
cNextIdx++
} else {
// Count the number of edges for this shape and allocate space for them.
for eNext < len(edges) && edges[eNext].faceEdge.shapeID == eshapeID {
eNext++
}
clipped = newClippedShape(eshapeID, eNext-eBegin)
for e := eBegin; e < eNext; e++ {
clipped.edges[e-eBegin] = edges[e].faceEdge.edgeID
}
if cshapeID == eshapeID {
clipped.containsCenter = true
cNextIdx++
}
}
cell.shapes[i] = clipped
}
// Add this cell to the map.
s.cellMap[p.id] = cell
s.cells = append(s.cells, p.id)
// Shift the tracker focus point to the exit vertex of this cell.
if t.isActive && len(edges) != 0 {
t.drawTo(p.ExitVertex())
s.testAllEdges(edges, t)
t.setNextCellID(p.id.Next())
}
return true
} | go | func (s *ShapeIndex) makeIndexCell(p *PaddedCell, edges []*clippedEdge, t *tracker) bool {
// If the cell is empty, no index cell is needed. (In most cases this
// situation is detected before we get to this point, but this can happen
// when all shapes in a cell are removed.)
if len(edges) == 0 && len(t.shapeIDs) == 0 {
return true
}
// Count the number of edges that have not reached their maximum level yet.
// Return false if there are too many such edges.
count := 0
for _, ce := range edges {
if p.Level() < ce.faceEdge.maxLevel {
count++
}
if count > s.maxEdgesPerCell {
return false
}
}
// Possible optimization: Continue subdividing as long as exactly one child
// of the padded cell intersects the given edges. This can be done by finding
// the bounding box of all the edges and calling ShrinkToFit:
//
// cellID = p.ShrinkToFit(RectBound(edges));
//
// Currently this is not beneficial; it slows down construction by 4-25%
// (mainly computing the union of the bounding rectangles) and also slows
// down queries (since more recursive clipping is required to get down to
// the level of a spatial index cell). But it may be worth trying again
// once containsCenter is computed and all algorithms are modified to
// take advantage of it.
// We update the InteriorTracker as follows. For every Cell in the index
// we construct two edges: one edge from entry vertex of the cell to its
// center, and one from the cell center to its exit vertex. Here entry
// and exit refer the CellID ordering, i.e. the order in which points
// are encountered along the 2 space-filling curve. The exit vertex then
// becomes the entry vertex for the next cell in the index, unless there are
// one or more empty intervening cells, in which case the InteriorTracker
// state is unchanged because the intervening cells have no edges.
// Shift the InteriorTracker focus point to the center of the current cell.
if t.isActive && len(edges) != 0 {
if !t.atCellID(p.id) {
t.moveTo(p.EntryVertex())
}
t.drawTo(p.Center())
s.testAllEdges(edges, t)
}
// Allocate and fill a new index cell. To get the total number of shapes we
// need to merge the shapes associated with the intersecting edges together
// with the shapes that happen to contain the cell center.
cshapeIDs := t.shapeIDs
numShapes := s.countShapes(edges, cshapeIDs)
cell := NewShapeIndexCell(numShapes)
// To fill the index cell we merge the two sources of shapes: edge shapes
// (those that have at least one edge that intersects this cell), and
// containing shapes (those that contain the cell center). We keep track
// of the index of the next intersecting edge and the next containing shape
// as we go along. Both sets of shape ids are already sorted.
eNext := 0
cNextIdx := 0
for i := 0; i < numShapes; i++ {
var clipped *clippedShape
// advance to next value base + i
eshapeID := int32(s.Len())
cshapeID := int32(eshapeID) // Sentinels
if eNext != len(edges) {
eshapeID = edges[eNext].faceEdge.shapeID
}
if cNextIdx < len(cshapeIDs) {
cshapeID = cshapeIDs[cNextIdx]
}
eBegin := eNext
if cshapeID < eshapeID {
// The entire cell is in the shape interior.
clipped = newClippedShape(cshapeID, 0)
clipped.containsCenter = true
cNextIdx++
} else {
// Count the number of edges for this shape and allocate space for them.
for eNext < len(edges) && edges[eNext].faceEdge.shapeID == eshapeID {
eNext++
}
clipped = newClippedShape(eshapeID, eNext-eBegin)
for e := eBegin; e < eNext; e++ {
clipped.edges[e-eBegin] = edges[e].faceEdge.edgeID
}
if cshapeID == eshapeID {
clipped.containsCenter = true
cNextIdx++
}
}
cell.shapes[i] = clipped
}
// Add this cell to the map.
s.cellMap[p.id] = cell
s.cells = append(s.cells, p.id)
// Shift the tracker focus point to the exit vertex of this cell.
if t.isActive && len(edges) != 0 {
t.drawTo(p.ExitVertex())
s.testAllEdges(edges, t)
t.setNextCellID(p.id.Next())
}
return true
} | [
"func",
"(",
"s",
"*",
"ShapeIndex",
")",
"makeIndexCell",
"(",
"p",
"*",
"PaddedCell",
",",
"edges",
"[",
"]",
"*",
"clippedEdge",
",",
"t",
"*",
"tracker",
")",
"bool",
"{",
"// If the cell is empty, no index cell is needed. (In most cases this",
"// situation is ... | // makeIndexCell builds an indexCell from the given padded cell and set of edges and adds
// it to the index. If the cell or edges are empty, no cell is added. | [
"makeIndexCell",
"builds",
"an",
"indexCell",
"from",
"the",
"given",
"padded",
"cell",
"and",
"set",
"of",
"edges",
"and",
"adds",
"it",
"to",
"the",
"index",
".",
"If",
"the",
"cell",
"or",
"edges",
"are",
"empty",
"no",
"cell",
"is",
"added",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/shapeindex.go#L1121-L1233 | train |
golang/geo | s2/shapeindex.go | updateBound | func (s *ShapeIndex) updateBound(edge *clippedEdge, uEnd int, u float64, vEnd int, v float64) *clippedEdge {
c := &clippedEdge{faceEdge: edge.faceEdge}
if uEnd == 0 {
c.bound.X.Lo = u
c.bound.X.Hi = edge.bound.X.Hi
} else {
c.bound.X.Lo = edge.bound.X.Lo
c.bound.X.Hi = u
}
if vEnd == 0 {
c.bound.Y.Lo = v
c.bound.Y.Hi = edge.bound.Y.Hi
} else {
c.bound.Y.Lo = edge.bound.Y.Lo
c.bound.Y.Hi = v
}
return c
} | go | func (s *ShapeIndex) updateBound(edge *clippedEdge, uEnd int, u float64, vEnd int, v float64) *clippedEdge {
c := &clippedEdge{faceEdge: edge.faceEdge}
if uEnd == 0 {
c.bound.X.Lo = u
c.bound.X.Hi = edge.bound.X.Hi
} else {
c.bound.X.Lo = edge.bound.X.Lo
c.bound.X.Hi = u
}
if vEnd == 0 {
c.bound.Y.Lo = v
c.bound.Y.Hi = edge.bound.Y.Hi
} else {
c.bound.Y.Lo = edge.bound.Y.Lo
c.bound.Y.Hi = v
}
return c
} | [
"func",
"(",
"s",
"*",
"ShapeIndex",
")",
"updateBound",
"(",
"edge",
"*",
"clippedEdge",
",",
"uEnd",
"int",
",",
"u",
"float64",
",",
"vEnd",
"int",
",",
"v",
"float64",
")",
"*",
"clippedEdge",
"{",
"c",
":=",
"&",
"clippedEdge",
"{",
"faceEdge",
... | // updateBound updates the specified endpoint of the given clipped edge and returns the
// resulting clipped edge. | [
"updateBound",
"updates",
"the",
"specified",
"endpoint",
"of",
"the",
"given",
"clipped",
"edge",
"and",
"returns",
"the",
"resulting",
"clipped",
"edge",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/shapeindex.go#L1237-L1256 | train |
golang/geo | s2/shapeindex.go | clipVAxis | func (s *ShapeIndex) clipVAxis(edge *clippedEdge, middle r1.Interval) (a, b *clippedEdge) {
if edge.bound.Y.Hi <= middle.Lo {
// Edge is entirely contained in the lower child.
return edge, nil
} else if edge.bound.Y.Lo >= middle.Hi {
// Edge is entirely contained in the upper child.
return nil, edge
}
// The edge bound spans both children.
return s.clipVBound(edge, 1, middle.Hi), s.clipVBound(edge, 0, middle.Lo)
} | go | func (s *ShapeIndex) clipVAxis(edge *clippedEdge, middle r1.Interval) (a, b *clippedEdge) {
if edge.bound.Y.Hi <= middle.Lo {
// Edge is entirely contained in the lower child.
return edge, nil
} else if edge.bound.Y.Lo >= middle.Hi {
// Edge is entirely contained in the upper child.
return nil, edge
}
// The edge bound spans both children.
return s.clipVBound(edge, 1, middle.Hi), s.clipVBound(edge, 0, middle.Lo)
} | [
"func",
"(",
"s",
"*",
"ShapeIndex",
")",
"clipVAxis",
"(",
"edge",
"*",
"clippedEdge",
",",
"middle",
"r1",
".",
"Interval",
")",
"(",
"a",
",",
"b",
"*",
"clippedEdge",
")",
"{",
"if",
"edge",
".",
"bound",
".",
"Y",
".",
"Hi",
"<=",
"middle",
... | // cliupVAxis returns the given edge clipped to within the boundaries of the middle
// interval along the v-axis, and adds the result to its children. | [
"cliupVAxis",
"returns",
"the",
"given",
"edge",
"clipped",
"to",
"within",
"the",
"boundaries",
"of",
"the",
"middle",
"interval",
"along",
"the",
"v",
"-",
"axis",
"and",
"adds",
"the",
"result",
"to",
"its",
"children",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/shapeindex.go#L1326-L1336 | train |
golang/geo | s2/shapeindex.go | countShapes | func (s *ShapeIndex) countShapes(edges []*clippedEdge, shapeIDs []int32) int {
count := 0
lastShapeID := int32(-1)
// next clipped shape id in the shapeIDs list.
clippedNext := int32(0)
// index of the current element in the shapeIDs list.
shapeIDidx := 0
for _, edge := range edges {
if edge.faceEdge.shapeID == lastShapeID {
continue
}
count++
lastShapeID = edge.faceEdge.shapeID
// Skip over any containing shapes up to and including this one,
// updating count as appropriate.
for ; shapeIDidx < len(shapeIDs); shapeIDidx++ {
clippedNext = shapeIDs[shapeIDidx]
if clippedNext > lastShapeID {
break
}
if clippedNext < lastShapeID {
count++
}
}
}
// Count any remaining containing shapes.
count += int(len(shapeIDs)) - int(shapeIDidx)
return count
} | go | func (s *ShapeIndex) countShapes(edges []*clippedEdge, shapeIDs []int32) int {
count := 0
lastShapeID := int32(-1)
// next clipped shape id in the shapeIDs list.
clippedNext := int32(0)
// index of the current element in the shapeIDs list.
shapeIDidx := 0
for _, edge := range edges {
if edge.faceEdge.shapeID == lastShapeID {
continue
}
count++
lastShapeID = edge.faceEdge.shapeID
// Skip over any containing shapes up to and including this one,
// updating count as appropriate.
for ; shapeIDidx < len(shapeIDs); shapeIDidx++ {
clippedNext = shapeIDs[shapeIDidx]
if clippedNext > lastShapeID {
break
}
if clippedNext < lastShapeID {
count++
}
}
}
// Count any remaining containing shapes.
count += int(len(shapeIDs)) - int(shapeIDidx)
return count
} | [
"func",
"(",
"s",
"*",
"ShapeIndex",
")",
"countShapes",
"(",
"edges",
"[",
"]",
"*",
"clippedEdge",
",",
"shapeIDs",
"[",
"]",
"int32",
")",
"int",
"{",
"count",
":=",
"0",
"\n",
"lastShapeID",
":=",
"int32",
"(",
"-",
"1",
")",
"\n\n",
"// next cli... | // countShapes reports the number of distinct shapes that are either associated with the
// given edges, or that are currently stored in the InteriorTracker. | [
"countShapes",
"reports",
"the",
"number",
"of",
"distinct",
"shapes",
"that",
"are",
"either",
"associated",
"with",
"the",
"given",
"edges",
"or",
"that",
"are",
"currently",
"stored",
"in",
"the",
"InteriorTracker",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/shapeindex.go#L1468-L1500 | train |
golang/geo | s2/shapeindex.go | maxLevelForEdge | func maxLevelForEdge(edge Edge) int {
// Compute the maximum cell size for which this edge is considered long.
// The calculation does not need to be perfectly accurate, so we use Norm
// rather than Angle for speed.
cellSize := edge.V0.Sub(edge.V1.Vector).Norm() * cellSizeToLongEdgeRatio
// Now return the first level encountered during subdivision where the
// average cell size is at most cellSize.
return AvgEdgeMetric.MinLevel(cellSize)
} | go | func maxLevelForEdge(edge Edge) int {
// Compute the maximum cell size for which this edge is considered long.
// The calculation does not need to be perfectly accurate, so we use Norm
// rather than Angle for speed.
cellSize := edge.V0.Sub(edge.V1.Vector).Norm() * cellSizeToLongEdgeRatio
// Now return the first level encountered during subdivision where the
// average cell size is at most cellSize.
return AvgEdgeMetric.MinLevel(cellSize)
} | [
"func",
"maxLevelForEdge",
"(",
"edge",
"Edge",
")",
"int",
"{",
"// Compute the maximum cell size for which this edge is considered long.",
"// The calculation does not need to be perfectly accurate, so we use Norm",
"// rather than Angle for speed.",
"cellSize",
":=",
"edge",
".",
"V... | // maxLevelForEdge reports the maximum level for a given edge. | [
"maxLevelForEdge",
"reports",
"the",
"maximum",
"level",
"for",
"a",
"given",
"edge",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/shapeindex.go#L1503-L1511 | train |
golang/geo | s2/edge_crosser.go | NewEdgeCrosser | func NewEdgeCrosser(a, b Point) *EdgeCrosser {
norm := a.PointCross(b)
return &EdgeCrosser{
a: a,
b: b,
aXb: Point{a.Cross(b.Vector)},
aTangent: Point{a.Cross(norm.Vector)},
bTangent: Point{norm.Cross(b.Vector)},
}
} | go | func NewEdgeCrosser(a, b Point) *EdgeCrosser {
norm := a.PointCross(b)
return &EdgeCrosser{
a: a,
b: b,
aXb: Point{a.Cross(b.Vector)},
aTangent: Point{a.Cross(norm.Vector)},
bTangent: Point{norm.Cross(b.Vector)},
}
} | [
"func",
"NewEdgeCrosser",
"(",
"a",
",",
"b",
"Point",
")",
"*",
"EdgeCrosser",
"{",
"norm",
":=",
"a",
".",
"PointCross",
"(",
"b",
")",
"\n",
"return",
"&",
"EdgeCrosser",
"{",
"a",
":",
"a",
",",
"b",
":",
"b",
",",
"aXb",
":",
"Point",
"{",
... | // NewEdgeCrosser returns an EdgeCrosser with the fixed edge AB. | [
"NewEdgeCrosser",
"returns",
"an",
"EdgeCrosser",
"with",
"the",
"fixed",
"edge",
"AB",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/edge_crosser.go#L56-L65 | train |
golang/geo | s2/edge_crosser.go | RestartAt | func (e *EdgeCrosser) RestartAt(c Point) {
e.c = c
e.acb = -triageSign(e.a, e.b, e.c)
} | go | func (e *EdgeCrosser) RestartAt(c Point) {
e.c = c
e.acb = -triageSign(e.a, e.b, e.c)
} | [
"func",
"(",
"e",
"*",
"EdgeCrosser",
")",
"RestartAt",
"(",
"c",
"Point",
")",
"{",
"e",
".",
"c",
"=",
"c",
"\n",
"e",
".",
"acb",
"=",
"-",
"triageSign",
"(",
"e",
".",
"a",
",",
"e",
".",
"b",
",",
"e",
".",
"c",
")",
"\n",
"}"
] | // RestartAt sets the current point of the edge crosser to be c.
// Call this method when your chain 'jumps' to a new place.
// The argument must point to a value that persists until the next call. | [
"RestartAt",
"sets",
"the",
"current",
"point",
"of",
"the",
"edge",
"crosser",
"to",
"be",
"c",
".",
"Call",
"this",
"method",
"when",
"your",
"chain",
"jumps",
"to",
"a",
"new",
"place",
".",
"The",
"argument",
"must",
"point",
"to",
"a",
"value",
"t... | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/edge_crosser.go#L120-L123 | train |
golang/geo | s2/edge_crosser.go | crossingSign | func (e *EdgeCrosser) crossingSign(d Point, bda Direction) Crossing {
// Compute the actual result, and then save the current vertex D as the next
// vertex C, and save the orientation of the next triangle ACB (which is
// opposite to the current triangle BDA).
defer func() {
e.c = d
e.acb = -bda
}()
// At this point, a very common situation is that A,B,C,D are four points on
// a line such that AB does not overlap CD. (For example, this happens when
// a line or curve is sampled finely, or when geometry is constructed by
// computing the union of S2CellIds.) Most of the time, we can determine
// that AB and CD do not intersect using the two outward-facing
// tangents at A and B (parallel to AB) and testing whether AB and CD are on
// opposite sides of the plane perpendicular to one of these tangents. This
// is moderately expensive but still much cheaper than expensiveSign.
// The error in RobustCrossProd is insignificant. The maximum error in
// the call to CrossProd (i.e., the maximum norm of the error vector) is
// (0.5 + 1/sqrt(3)) * dblEpsilon. The maximum error in each call to
// DotProd below is dblEpsilon. (There is also a small relative error
// term that is insignificant because we are comparing the result against a
// constant that is very close to zero.)
maxError := (1.5 + 1/math.Sqrt(3)) * dblEpsilon
if (e.c.Dot(e.aTangent.Vector) > maxError && d.Dot(e.aTangent.Vector) > maxError) || (e.c.Dot(e.bTangent.Vector) > maxError && d.Dot(e.bTangent.Vector) > maxError) {
return DoNotCross
}
// Otherwise, eliminate the cases where two vertices from different edges are
// equal. (These cases could be handled in the code below, but we would rather
// avoid calling ExpensiveSign if possible.)
if e.a == e.c || e.a == d || e.b == e.c || e.b == d {
return MaybeCross
}
// Eliminate the cases where an input edge is degenerate. (Note that in
// most cases, if CD is degenerate then this method is not even called
// because acb and bda have different signs.)
if e.a == e.b || e.c == d {
return DoNotCross
}
// Otherwise it's time to break out the big guns.
if e.acb == Indeterminate {
e.acb = -expensiveSign(e.a, e.b, e.c)
}
if bda == Indeterminate {
bda = expensiveSign(e.a, e.b, d)
}
if bda != e.acb {
return DoNotCross
}
cbd := -RobustSign(e.c, d, e.b)
if cbd != e.acb {
return DoNotCross
}
dac := RobustSign(e.c, d, e.a)
if dac != e.acb {
return DoNotCross
}
return Cross
} | go | func (e *EdgeCrosser) crossingSign(d Point, bda Direction) Crossing {
// Compute the actual result, and then save the current vertex D as the next
// vertex C, and save the orientation of the next triangle ACB (which is
// opposite to the current triangle BDA).
defer func() {
e.c = d
e.acb = -bda
}()
// At this point, a very common situation is that A,B,C,D are four points on
// a line such that AB does not overlap CD. (For example, this happens when
// a line or curve is sampled finely, or when geometry is constructed by
// computing the union of S2CellIds.) Most of the time, we can determine
// that AB and CD do not intersect using the two outward-facing
// tangents at A and B (parallel to AB) and testing whether AB and CD are on
// opposite sides of the plane perpendicular to one of these tangents. This
// is moderately expensive but still much cheaper than expensiveSign.
// The error in RobustCrossProd is insignificant. The maximum error in
// the call to CrossProd (i.e., the maximum norm of the error vector) is
// (0.5 + 1/sqrt(3)) * dblEpsilon. The maximum error in each call to
// DotProd below is dblEpsilon. (There is also a small relative error
// term that is insignificant because we are comparing the result against a
// constant that is very close to zero.)
maxError := (1.5 + 1/math.Sqrt(3)) * dblEpsilon
if (e.c.Dot(e.aTangent.Vector) > maxError && d.Dot(e.aTangent.Vector) > maxError) || (e.c.Dot(e.bTangent.Vector) > maxError && d.Dot(e.bTangent.Vector) > maxError) {
return DoNotCross
}
// Otherwise, eliminate the cases where two vertices from different edges are
// equal. (These cases could be handled in the code below, but we would rather
// avoid calling ExpensiveSign if possible.)
if e.a == e.c || e.a == d || e.b == e.c || e.b == d {
return MaybeCross
}
// Eliminate the cases where an input edge is degenerate. (Note that in
// most cases, if CD is degenerate then this method is not even called
// because acb and bda have different signs.)
if e.a == e.b || e.c == d {
return DoNotCross
}
// Otherwise it's time to break out the big guns.
if e.acb == Indeterminate {
e.acb = -expensiveSign(e.a, e.b, e.c)
}
if bda == Indeterminate {
bda = expensiveSign(e.a, e.b, d)
}
if bda != e.acb {
return DoNotCross
}
cbd := -RobustSign(e.c, d, e.b)
if cbd != e.acb {
return DoNotCross
}
dac := RobustSign(e.c, d, e.a)
if dac != e.acb {
return DoNotCross
}
return Cross
} | [
"func",
"(",
"e",
"*",
"EdgeCrosser",
")",
"crossingSign",
"(",
"d",
"Point",
",",
"bda",
"Direction",
")",
"Crossing",
"{",
"// Compute the actual result, and then save the current vertex D as the next",
"// vertex C, and save the orientation of the next triangle ACB (which is",
... | // crossingSign handle the slow path of CrossingSign. | [
"crossingSign",
"handle",
"the",
"slow",
"path",
"of",
"CrossingSign",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/edge_crosser.go#L163-L227 | train |
golang/geo | s2/interleave.go | deinterleaveUint32 | func deinterleaveUint32(code uint64) (uint32, uint32) {
x := (deinterleaveLookup[code&0x55]) |
(deinterleaveLookup[(code>>8)&0x55] << 4) |
(deinterleaveLookup[(code>>16)&0x55] << 8) |
(deinterleaveLookup[(code>>24)&0x55] << 12) |
(deinterleaveLookup[(code>>32)&0x55] << 16) |
(deinterleaveLookup[(code>>40)&0x55] << 20) |
(deinterleaveLookup[(code>>48)&0x55] << 24) |
(deinterleaveLookup[(code>>56)&0x55] << 28)
y := (deinterleaveLookup[code&0xaa]) |
(deinterleaveLookup[(code>>8)&0xaa] << 4) |
(deinterleaveLookup[(code>>16)&0xaa] << 8) |
(deinterleaveLookup[(code>>24)&0xaa] << 12) |
(deinterleaveLookup[(code>>32)&0xaa] << 16) |
(deinterleaveLookup[(code>>40)&0xaa] << 20) |
(deinterleaveLookup[(code>>48)&0xaa] << 24) |
(deinterleaveLookup[(code>>56)&0xaa] << 28)
return x, y
} | go | func deinterleaveUint32(code uint64) (uint32, uint32) {
x := (deinterleaveLookup[code&0x55]) |
(deinterleaveLookup[(code>>8)&0x55] << 4) |
(deinterleaveLookup[(code>>16)&0x55] << 8) |
(deinterleaveLookup[(code>>24)&0x55] << 12) |
(deinterleaveLookup[(code>>32)&0x55] << 16) |
(deinterleaveLookup[(code>>40)&0x55] << 20) |
(deinterleaveLookup[(code>>48)&0x55] << 24) |
(deinterleaveLookup[(code>>56)&0x55] << 28)
y := (deinterleaveLookup[code&0xaa]) |
(deinterleaveLookup[(code>>8)&0xaa] << 4) |
(deinterleaveLookup[(code>>16)&0xaa] << 8) |
(deinterleaveLookup[(code>>24)&0xaa] << 12) |
(deinterleaveLookup[(code>>32)&0xaa] << 16) |
(deinterleaveLookup[(code>>40)&0xaa] << 20) |
(deinterleaveLookup[(code>>48)&0xaa] << 24) |
(deinterleaveLookup[(code>>56)&0xaa] << 28)
return x, y
} | [
"func",
"deinterleaveUint32",
"(",
"code",
"uint64",
")",
"(",
"uint32",
",",
"uint32",
")",
"{",
"x",
":=",
"(",
"deinterleaveLookup",
"[",
"code",
"&",
"0x55",
"]",
")",
"|",
"(",
"deinterleaveLookup",
"[",
"(",
"code",
">>",
"8",
")",
"&",
"0x55",
... | // deinterleaveUint32 decodes the interleaved values. | [
"deinterleaveUint32",
"decodes",
"the",
"interleaved",
"values",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/interleave.go#L71-L89 | train |
golang/geo | s2/interleave.go | interleaveUint32 | func interleaveUint32(x, y uint32) uint64 {
return (interleaveLookup[x&0xff]) |
(interleaveLookup[(x>>8)&0xff] << 16) |
(interleaveLookup[(x>>16)&0xff] << 32) |
(interleaveLookup[x>>24] << 48) |
(interleaveLookup[y&0xff] << 1) |
(interleaveLookup[(y>>8)&0xff] << 17) |
(interleaveLookup[(y>>16)&0xff] << 33) |
(interleaveLookup[y>>24] << 49)
} | go | func interleaveUint32(x, y uint32) uint64 {
return (interleaveLookup[x&0xff]) |
(interleaveLookup[(x>>8)&0xff] << 16) |
(interleaveLookup[(x>>16)&0xff] << 32) |
(interleaveLookup[x>>24] << 48) |
(interleaveLookup[y&0xff] << 1) |
(interleaveLookup[(y>>8)&0xff] << 17) |
(interleaveLookup[(y>>16)&0xff] << 33) |
(interleaveLookup[y>>24] << 49)
} | [
"func",
"interleaveUint32",
"(",
"x",
",",
"y",
"uint32",
")",
"uint64",
"{",
"return",
"(",
"interleaveLookup",
"[",
"x",
"&",
"0xff",
"]",
")",
"|",
"(",
"interleaveLookup",
"[",
"(",
"x",
">>",
"8",
")",
"&",
"0xff",
"]",
"<<",
"16",
")",
"|",
... | // interleaveUint32 interleaves the given arguments into the return value.
//
// The 0-bit in val0 will be the 0-bit in the return value.
// The 0-bit in val1 will be the 1-bit in the return value.
// The 1-bit of val0 will be the 2-bit in the return value, and so on. | [
"interleaveUint32",
"interleaves",
"the",
"given",
"arguments",
"into",
"the",
"return",
"value",
".",
"The",
"0",
"-",
"bit",
"in",
"val0",
"will",
"be",
"the",
"0",
"-",
"bit",
"in",
"the",
"return",
"value",
".",
"The",
"0",
"-",
"bit",
"in",
"val1"... | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/interleave.go#L134-L143 | train |
golang/geo | s2/paddedcell.go | PaddedCellFromCellID | func PaddedCellFromCellID(id CellID, padding float64) *PaddedCell {
p := &PaddedCell{
id: id,
padding: padding,
middle: r2.EmptyRect(),
}
// Fast path for constructing a top-level face (the most common case).
if id.isFace() {
limit := padding + 1
p.bound = r2.Rect{r1.Interval{-limit, limit}, r1.Interval{-limit, limit}}
p.middle = r2.Rect{r1.Interval{-padding, padding}, r1.Interval{-padding, padding}}
p.orientation = id.Face() & 1
return p
}
_, p.iLo, p.jLo, p.orientation = id.faceIJOrientation()
p.level = id.Level()
p.bound = ijLevelToBoundUV(p.iLo, p.jLo, p.level).ExpandedByMargin(padding)
ijSize := sizeIJ(p.level)
p.iLo &= -ijSize
p.jLo &= -ijSize
return p
} | go | func PaddedCellFromCellID(id CellID, padding float64) *PaddedCell {
p := &PaddedCell{
id: id,
padding: padding,
middle: r2.EmptyRect(),
}
// Fast path for constructing a top-level face (the most common case).
if id.isFace() {
limit := padding + 1
p.bound = r2.Rect{r1.Interval{-limit, limit}, r1.Interval{-limit, limit}}
p.middle = r2.Rect{r1.Interval{-padding, padding}, r1.Interval{-padding, padding}}
p.orientation = id.Face() & 1
return p
}
_, p.iLo, p.jLo, p.orientation = id.faceIJOrientation()
p.level = id.Level()
p.bound = ijLevelToBoundUV(p.iLo, p.jLo, p.level).ExpandedByMargin(padding)
ijSize := sizeIJ(p.level)
p.iLo &= -ijSize
p.jLo &= -ijSize
return p
} | [
"func",
"PaddedCellFromCellID",
"(",
"id",
"CellID",
",",
"padding",
"float64",
")",
"*",
"PaddedCell",
"{",
"p",
":=",
"&",
"PaddedCell",
"{",
"id",
":",
"id",
",",
"padding",
":",
"padding",
",",
"middle",
":",
"r2",
".",
"EmptyRect",
"(",
")",
",",
... | // PaddedCellFromCellID constructs a padded cell with the given padding. | [
"PaddedCellFromCellID",
"constructs",
"a",
"padded",
"cell",
"with",
"the",
"given",
"padding",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/paddedcell.go#L37-L61 | train |
golang/geo | s2/paddedcell.go | Center | func (p PaddedCell) Center() Point {
ijSize := sizeIJ(p.level)
si := uint32(2*p.iLo + ijSize)
ti := uint32(2*p.jLo + ijSize)
return Point{faceSiTiToXYZ(p.id.Face(), si, ti).Normalize()}
} | go | func (p PaddedCell) Center() Point {
ijSize := sizeIJ(p.level)
si := uint32(2*p.iLo + ijSize)
ti := uint32(2*p.jLo + ijSize)
return Point{faceSiTiToXYZ(p.id.Face(), si, ti).Normalize()}
} | [
"func",
"(",
"p",
"PaddedCell",
")",
"Center",
"(",
")",
"Point",
"{",
"ijSize",
":=",
"sizeIJ",
"(",
"p",
".",
"level",
")",
"\n",
"si",
":=",
"uint32",
"(",
"2",
"*",
"p",
".",
"iLo",
"+",
"ijSize",
")",
"\n",
"ti",
":=",
"uint32",
"(",
"2",
... | // Center returns the center of this cell. | [
"Center",
"returns",
"the",
"center",
"of",
"this",
"cell",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/paddedcell.go#L117-L122 | train |
golang/geo | s2/paddedcell.go | EntryVertex | func (p PaddedCell) EntryVertex() Point {
// The curve enters at the (0,0) vertex unless the axis directions are
// reversed, in which case it enters at the (1,1) vertex.
i := p.iLo
j := p.jLo
if p.orientation&invertMask != 0 {
ijSize := sizeIJ(p.level)
i += ijSize
j += ijSize
}
return Point{faceSiTiToXYZ(p.id.Face(), uint32(2*i), uint32(2*j)).Normalize()}
} | go | func (p PaddedCell) EntryVertex() Point {
// The curve enters at the (0,0) vertex unless the axis directions are
// reversed, in which case it enters at the (1,1) vertex.
i := p.iLo
j := p.jLo
if p.orientation&invertMask != 0 {
ijSize := sizeIJ(p.level)
i += ijSize
j += ijSize
}
return Point{faceSiTiToXYZ(p.id.Face(), uint32(2*i), uint32(2*j)).Normalize()}
} | [
"func",
"(",
"p",
"PaddedCell",
")",
"EntryVertex",
"(",
")",
"Point",
"{",
"// The curve enters at the (0,0) vertex unless the axis directions are",
"// reversed, in which case it enters at the (1,1) vertex.",
"i",
":=",
"p",
".",
"iLo",
"\n",
"j",
":=",
"p",
".",
"jLo",... | // EntryVertex return the vertex where the space-filling curve enters this cell. | [
"EntryVertex",
"return",
"the",
"vertex",
"where",
"the",
"space",
"-",
"filling",
"curve",
"enters",
"this",
"cell",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/paddedcell.go#L155-L166 | train |
golang/geo | s2/paddedcell.go | ShrinkToFit | func (p *PaddedCell) ShrinkToFit(rect r2.Rect) CellID {
// Quick rejection test: if rect contains the center of this cell along
// either axis, then no further shrinking is possible.
if p.level == 0 {
// Fast path (most calls to this function start with a face cell).
if rect.X.Contains(0) || rect.Y.Contains(0) {
return p.id
}
}
ijSize := sizeIJ(p.level)
if rect.X.Contains(stToUV(siTiToST(uint32(2*p.iLo+ijSize)))) ||
rect.Y.Contains(stToUV(siTiToST(uint32(2*p.jLo+ijSize)))) {
return p.id
}
// Otherwise we expand rect by the given padding on all sides and find
// the range of coordinates that it spans along the i- and j-axes. We then
// compute the highest bit position at which the min and max coordinates
// differ. This corresponds to the first cell level at which at least two
// children intersect rect.
// Increase the padding to compensate for the error in uvToST.
// (The constant below is a provable upper bound on the additional error.)
padded := rect.ExpandedByMargin(p.padding + 1.5*dblEpsilon)
iMin, jMin := p.iLo, p.jLo // Min i- or j- coordinate spanned by padded
var iXor, jXor int // XOR of the min and max i- or j-coordinates
if iMin < stToIJ(uvToST(padded.X.Lo)) {
iMin = stToIJ(uvToST(padded.X.Lo))
}
if a, b := p.iLo+ijSize-1, stToIJ(uvToST(padded.X.Hi)); a <= b {
iXor = iMin ^ a
} else {
iXor = iMin ^ b
}
if jMin < stToIJ(uvToST(padded.Y.Lo)) {
jMin = stToIJ(uvToST(padded.Y.Lo))
}
if a, b := p.jLo+ijSize-1, stToIJ(uvToST(padded.Y.Hi)); a <= b {
jXor = jMin ^ a
} else {
jXor = jMin ^ b
}
// Compute the highest bit position where the two i- or j-endpoints differ,
// and then choose the cell level that includes both of these endpoints. So
// if both pairs of endpoints are equal we choose maxLevel; if they differ
// only at bit 0, we choose (maxLevel - 1), and so on.
levelMSB := uint64(((iXor | jXor) << 1) + 1)
level := maxLevel - int(findMSBSetNonZero64(levelMSB))
if level <= p.level {
return p.id
}
return cellIDFromFaceIJ(p.id.Face(), iMin, jMin).Parent(level)
} | go | func (p *PaddedCell) ShrinkToFit(rect r2.Rect) CellID {
// Quick rejection test: if rect contains the center of this cell along
// either axis, then no further shrinking is possible.
if p.level == 0 {
// Fast path (most calls to this function start with a face cell).
if rect.X.Contains(0) || rect.Y.Contains(0) {
return p.id
}
}
ijSize := sizeIJ(p.level)
if rect.X.Contains(stToUV(siTiToST(uint32(2*p.iLo+ijSize)))) ||
rect.Y.Contains(stToUV(siTiToST(uint32(2*p.jLo+ijSize)))) {
return p.id
}
// Otherwise we expand rect by the given padding on all sides and find
// the range of coordinates that it spans along the i- and j-axes. We then
// compute the highest bit position at which the min and max coordinates
// differ. This corresponds to the first cell level at which at least two
// children intersect rect.
// Increase the padding to compensate for the error in uvToST.
// (The constant below is a provable upper bound on the additional error.)
padded := rect.ExpandedByMargin(p.padding + 1.5*dblEpsilon)
iMin, jMin := p.iLo, p.jLo // Min i- or j- coordinate spanned by padded
var iXor, jXor int // XOR of the min and max i- or j-coordinates
if iMin < stToIJ(uvToST(padded.X.Lo)) {
iMin = stToIJ(uvToST(padded.X.Lo))
}
if a, b := p.iLo+ijSize-1, stToIJ(uvToST(padded.X.Hi)); a <= b {
iXor = iMin ^ a
} else {
iXor = iMin ^ b
}
if jMin < stToIJ(uvToST(padded.Y.Lo)) {
jMin = stToIJ(uvToST(padded.Y.Lo))
}
if a, b := p.jLo+ijSize-1, stToIJ(uvToST(padded.Y.Hi)); a <= b {
jXor = jMin ^ a
} else {
jXor = jMin ^ b
}
// Compute the highest bit position where the two i- or j-endpoints differ,
// and then choose the cell level that includes both of these endpoints. So
// if both pairs of endpoints are equal we choose maxLevel; if they differ
// only at bit 0, we choose (maxLevel - 1), and so on.
levelMSB := uint64(((iXor | jXor) << 1) + 1)
level := maxLevel - int(findMSBSetNonZero64(levelMSB))
if level <= p.level {
return p.id
}
return cellIDFromFaceIJ(p.id.Face(), iMin, jMin).Parent(level)
} | [
"func",
"(",
"p",
"*",
"PaddedCell",
")",
"ShrinkToFit",
"(",
"rect",
"r2",
".",
"Rect",
")",
"CellID",
"{",
"// Quick rejection test: if rect contains the center of this cell along",
"// either axis, then no further shrinking is possible.",
"if",
"p",
".",
"level",
"==",
... | // ShrinkToFit returns the smallest CellID that contains all descendants of this
// padded cell whose bounds intersect the given rect. For algorithms that use
// recursive subdivision to find the cells that intersect a particular object, this
// method can be used to skip all of the initial subdivision steps where only
// one child needs to be expanded.
//
// Note that this method is not the same as returning the smallest cell that contains
// the intersection of this cell with rect. Because of the padding, even if one child
// completely contains rect it is still possible that a neighboring child may also
// intersect the given rect.
//
// The provided Rect must intersect the bounds of this cell. | [
"ShrinkToFit",
"returns",
"the",
"smallest",
"CellID",
"that",
"contains",
"all",
"descendants",
"of",
"this",
"padded",
"cell",
"whose",
"bounds",
"intersect",
"the",
"given",
"rect",
".",
"For",
"algorithms",
"that",
"use",
"recursive",
"subdivision",
"to",
"f... | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/paddedcell.go#L195-L252 | train |
golang/geo | r3/precisevector.go | precStr | func precStr(s string) *big.Float {
// Explicitly ignoring the bool return for this usage.
f, _ := new(big.Float).SetPrec(prec).SetString(s)
return f
} | go | func precStr(s string) *big.Float {
// Explicitly ignoring the bool return for this usage.
f, _ := new(big.Float).SetPrec(prec).SetString(s)
return f
} | [
"func",
"precStr",
"(",
"s",
"string",
")",
"*",
"big",
".",
"Float",
"{",
"// Explicitly ignoring the bool return for this usage.",
"f",
",",
"_",
":=",
"new",
"(",
"big",
".",
"Float",
")",
".",
"SetPrec",
"(",
"prec",
")",
".",
"SetString",
"(",
"s",
... | // precStr wraps the conversion from a string into a big.Float. For results that
// actually can be represented exactly, this should only be used on values that
// are integer multiples of integer powers of 2. | [
"precStr",
"wraps",
"the",
"conversion",
"from",
"a",
"string",
"into",
"a",
"big",
".",
"Float",
".",
"For",
"results",
"that",
"actually",
"can",
"be",
"represented",
"exactly",
"this",
"should",
"only",
"be",
"used",
"on",
"values",
"that",
"are",
"inte... | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/r3/precisevector.go#L38-L42 | train |
golang/geo | r3/precisevector.go | PreciseVectorFromVector | func PreciseVectorFromVector(v Vector) PreciseVector {
return NewPreciseVector(v.X, v.Y, v.Z)
} | go | func PreciseVectorFromVector(v Vector) PreciseVector {
return NewPreciseVector(v.X, v.Y, v.Z)
} | [
"func",
"PreciseVectorFromVector",
"(",
"v",
"Vector",
")",
"PreciseVector",
"{",
"return",
"NewPreciseVector",
"(",
"v",
".",
"X",
",",
"v",
".",
"Y",
",",
"v",
".",
"Z",
")",
"\n",
"}"
] | // PreciseVectorFromVector creates a high precision vector from the given Vector. | [
"PreciseVectorFromVector",
"creates",
"a",
"high",
"precision",
"vector",
"from",
"the",
"given",
"Vector",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/r3/precisevector.go#L74-L76 | train |
golang/geo | r3/precisevector.go | NewPreciseVector | func NewPreciseVector(x, y, z float64) PreciseVector {
return PreciseVector{
X: precFloat(x),
Y: precFloat(y),
Z: precFloat(z),
}
} | go | func NewPreciseVector(x, y, z float64) PreciseVector {
return PreciseVector{
X: precFloat(x),
Y: precFloat(y),
Z: precFloat(z),
}
} | [
"func",
"NewPreciseVector",
"(",
"x",
",",
"y",
",",
"z",
"float64",
")",
"PreciseVector",
"{",
"return",
"PreciseVector",
"{",
"X",
":",
"precFloat",
"(",
"x",
")",
",",
"Y",
":",
"precFloat",
"(",
"y",
")",
",",
"Z",
":",
"precFloat",
"(",
"z",
"... | // NewPreciseVector creates a high precision vector from the given floating point values. | [
"NewPreciseVector",
"creates",
"a",
"high",
"precision",
"vector",
"from",
"the",
"given",
"floating",
"point",
"values",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/r3/precisevector.go#L79-L85 | train |
golang/geo | r3/precisevector.go | Vector | func (v PreciseVector) Vector() Vector {
// The accuracy flag is ignored on these conversions back to float64.
x, _ := v.X.Float64()
y, _ := v.Y.Float64()
z, _ := v.Z.Float64()
return Vector{x, y, z}.Normalize()
} | go | func (v PreciseVector) Vector() Vector {
// The accuracy flag is ignored on these conversions back to float64.
x, _ := v.X.Float64()
y, _ := v.Y.Float64()
z, _ := v.Z.Float64()
return Vector{x, y, z}.Normalize()
} | [
"func",
"(",
"v",
"PreciseVector",
")",
"Vector",
"(",
")",
"Vector",
"{",
"// The accuracy flag is ignored on these conversions back to float64.",
"x",
",",
"_",
":=",
"v",
".",
"X",
".",
"Float64",
"(",
")",
"\n",
"y",
",",
"_",
":=",
"v",
".",
"Y",
".",... | // Vector returns this precise vector converted to a Vector. | [
"Vector",
"returns",
"this",
"precise",
"vector",
"converted",
"to",
"a",
"Vector",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/r3/precisevector.go#L88-L94 | train |
golang/geo | r3/precisevector.go | Equal | func (v PreciseVector) Equal(ov PreciseVector) bool {
return v.X.Cmp(ov.X) == 0 && v.Y.Cmp(ov.Y) == 0 && v.Z.Cmp(ov.Z) == 0
} | go | func (v PreciseVector) Equal(ov PreciseVector) bool {
return v.X.Cmp(ov.X) == 0 && v.Y.Cmp(ov.Y) == 0 && v.Z.Cmp(ov.Z) == 0
} | [
"func",
"(",
"v",
"PreciseVector",
")",
"Equal",
"(",
"ov",
"PreciseVector",
")",
"bool",
"{",
"return",
"v",
".",
"X",
".",
"Cmp",
"(",
"ov",
".",
"X",
")",
"==",
"0",
"&&",
"v",
".",
"Y",
".",
"Cmp",
"(",
"ov",
".",
"Y",
")",
"==",
"0",
"... | // Equal reports whether v and ov are equal. | [
"Equal",
"reports",
"whether",
"v",
"and",
"ov",
"are",
"equal",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/r3/precisevector.go#L97-L99 | train |
golang/geo | r3/precisevector.go | Abs | func (v PreciseVector) Abs() PreciseVector {
return PreciseVector{
X: new(big.Float).Abs(v.X),
Y: new(big.Float).Abs(v.Y),
Z: new(big.Float).Abs(v.Z),
}
} | go | func (v PreciseVector) Abs() PreciseVector {
return PreciseVector{
X: new(big.Float).Abs(v.X),
Y: new(big.Float).Abs(v.Y),
Z: new(big.Float).Abs(v.Z),
}
} | [
"func",
"(",
"v",
"PreciseVector",
")",
"Abs",
"(",
")",
"PreciseVector",
"{",
"return",
"PreciseVector",
"{",
"X",
":",
"new",
"(",
"big",
".",
"Float",
")",
".",
"Abs",
"(",
"v",
".",
"X",
")",
",",
"Y",
":",
"new",
"(",
"big",
".",
"Float",
... | // Abs returns the vector with nonnegative components. | [
"Abs",
"returns",
"the",
"vector",
"with",
"nonnegative",
"components",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/r3/precisevector.go#L114-L120 | train |
golang/geo | r3/precisevector.go | Add | func (v PreciseVector) Add(ov PreciseVector) PreciseVector {
return PreciseVector{
X: precAdd(v.X, ov.X),
Y: precAdd(v.Y, ov.Y),
Z: precAdd(v.Z, ov.Z),
}
} | go | func (v PreciseVector) Add(ov PreciseVector) PreciseVector {
return PreciseVector{
X: precAdd(v.X, ov.X),
Y: precAdd(v.Y, ov.Y),
Z: precAdd(v.Z, ov.Z),
}
} | [
"func",
"(",
"v",
"PreciseVector",
")",
"Add",
"(",
"ov",
"PreciseVector",
")",
"PreciseVector",
"{",
"return",
"PreciseVector",
"{",
"X",
":",
"precAdd",
"(",
"v",
".",
"X",
",",
"ov",
".",
"X",
")",
",",
"Y",
":",
"precAdd",
"(",
"v",
".",
"Y",
... | // Add returns the standard vector sum of v and ov. | [
"Add",
"returns",
"the",
"standard",
"vector",
"sum",
"of",
"v",
"and",
"ov",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/r3/precisevector.go#L123-L129 | train |
golang/geo | r3/precisevector.go | Sub | func (v PreciseVector) Sub(ov PreciseVector) PreciseVector {
return PreciseVector{
X: precSub(v.X, ov.X),
Y: precSub(v.Y, ov.Y),
Z: precSub(v.Z, ov.Z),
}
} | go | func (v PreciseVector) Sub(ov PreciseVector) PreciseVector {
return PreciseVector{
X: precSub(v.X, ov.X),
Y: precSub(v.Y, ov.Y),
Z: precSub(v.Z, ov.Z),
}
} | [
"func",
"(",
"v",
"PreciseVector",
")",
"Sub",
"(",
"ov",
"PreciseVector",
")",
"PreciseVector",
"{",
"return",
"PreciseVector",
"{",
"X",
":",
"precSub",
"(",
"v",
".",
"X",
",",
"ov",
".",
"X",
")",
",",
"Y",
":",
"precSub",
"(",
"v",
".",
"Y",
... | // Sub returns the standard vector difference of v and ov. | [
"Sub",
"returns",
"the",
"standard",
"vector",
"difference",
"of",
"v",
"and",
"ov",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/r3/precisevector.go#L132-L138 | train |
golang/geo | r3/precisevector.go | Mul | func (v PreciseVector) Mul(f *big.Float) PreciseVector {
return PreciseVector{
X: precMul(v.X, f),
Y: precMul(v.Y, f),
Z: precMul(v.Z, f),
}
} | go | func (v PreciseVector) Mul(f *big.Float) PreciseVector {
return PreciseVector{
X: precMul(v.X, f),
Y: precMul(v.Y, f),
Z: precMul(v.Z, f),
}
} | [
"func",
"(",
"v",
"PreciseVector",
")",
"Mul",
"(",
"f",
"*",
"big",
".",
"Float",
")",
"PreciseVector",
"{",
"return",
"PreciseVector",
"{",
"X",
":",
"precMul",
"(",
"v",
".",
"X",
",",
"f",
")",
",",
"Y",
":",
"precMul",
"(",
"v",
".",
"Y",
... | // Mul returns the standard scalar product of v and f. | [
"Mul",
"returns",
"the",
"standard",
"scalar",
"product",
"of",
"v",
"and",
"f",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/r3/precisevector.go#L141-L147 | train |
golang/geo | r3/precisevector.go | MulByFloat64 | func (v PreciseVector) MulByFloat64(f float64) PreciseVector {
return v.Mul(precFloat(f))
} | go | func (v PreciseVector) MulByFloat64(f float64) PreciseVector {
return v.Mul(precFloat(f))
} | [
"func",
"(",
"v",
"PreciseVector",
")",
"MulByFloat64",
"(",
"f",
"float64",
")",
"PreciseVector",
"{",
"return",
"v",
".",
"Mul",
"(",
"precFloat",
"(",
"f",
")",
")",
"\n",
"}"
] | // MulByFloat64 returns the standard scalar product of v and f. | [
"MulByFloat64",
"returns",
"the",
"standard",
"scalar",
"product",
"of",
"v",
"and",
"f",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/r3/precisevector.go#L150-L152 | train |
golang/geo | r3/precisevector.go | Dot | func (v PreciseVector) Dot(ov PreciseVector) *big.Float {
return precAdd(precMul(v.X, ov.X), precAdd(precMul(v.Y, ov.Y), precMul(v.Z, ov.Z)))
} | go | func (v PreciseVector) Dot(ov PreciseVector) *big.Float {
return precAdd(precMul(v.X, ov.X), precAdd(precMul(v.Y, ov.Y), precMul(v.Z, ov.Z)))
} | [
"func",
"(",
"v",
"PreciseVector",
")",
"Dot",
"(",
"ov",
"PreciseVector",
")",
"*",
"big",
".",
"Float",
"{",
"return",
"precAdd",
"(",
"precMul",
"(",
"v",
".",
"X",
",",
"ov",
".",
"X",
")",
",",
"precAdd",
"(",
"precMul",
"(",
"v",
".",
"Y",
... | // Dot returns the standard dot product of v and ov. | [
"Dot",
"returns",
"the",
"standard",
"dot",
"product",
"of",
"v",
"and",
"ov",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/r3/precisevector.go#L155-L157 | train |
golang/geo | s2/matrix3x3.go | col | func (m *matrix3x3) col(col int) Point {
return Point{r3.Vector{m[0][col], m[1][col], m[2][col]}}
} | go | func (m *matrix3x3) col(col int) Point {
return Point{r3.Vector{m[0][col], m[1][col], m[2][col]}}
} | [
"func",
"(",
"m",
"*",
"matrix3x3",
")",
"col",
"(",
"col",
"int",
")",
"Point",
"{",
"return",
"Point",
"{",
"r3",
".",
"Vector",
"{",
"m",
"[",
"0",
"]",
"[",
"col",
"]",
",",
"m",
"[",
"1",
"]",
"[",
"col",
"]",
",",
"m",
"[",
"2",
"]"... | // col returns the given column as a Point. | [
"col",
"returns",
"the",
"given",
"column",
"as",
"a",
"Point",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/matrix3x3.go#L29-L31 | train |
golang/geo | s2/matrix3x3.go | row | func (m *matrix3x3) row(row int) Point {
return Point{r3.Vector{m[row][0], m[row][1], m[row][2]}}
} | go | func (m *matrix3x3) row(row int) Point {
return Point{r3.Vector{m[row][0], m[row][1], m[row][2]}}
} | [
"func",
"(",
"m",
"*",
"matrix3x3",
")",
"row",
"(",
"row",
"int",
")",
"Point",
"{",
"return",
"Point",
"{",
"r3",
".",
"Vector",
"{",
"m",
"[",
"row",
"]",
"[",
"0",
"]",
",",
"m",
"[",
"row",
"]",
"[",
"1",
"]",
",",
"m",
"[",
"row",
"... | // row returns the given row as a Point. | [
"row",
"returns",
"the",
"given",
"row",
"as",
"a",
"Point",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/matrix3x3.go#L34-L36 | train |
golang/geo | s2/matrix3x3.go | setCol | func (m *matrix3x3) setCol(col int, p Point) *matrix3x3 {
m[0][col] = p.X
m[1][col] = p.Y
m[2][col] = p.Z
return m
} | go | func (m *matrix3x3) setCol(col int, p Point) *matrix3x3 {
m[0][col] = p.X
m[1][col] = p.Y
m[2][col] = p.Z
return m
} | [
"func",
"(",
"m",
"*",
"matrix3x3",
")",
"setCol",
"(",
"col",
"int",
",",
"p",
"Point",
")",
"*",
"matrix3x3",
"{",
"m",
"[",
"0",
"]",
"[",
"col",
"]",
"=",
"p",
".",
"X",
"\n",
"m",
"[",
"1",
"]",
"[",
"col",
"]",
"=",
"p",
".",
"Y",
... | // setCol sets the specified column to the value in the given Point. | [
"setCol",
"sets",
"the",
"specified",
"column",
"to",
"the",
"value",
"in",
"the",
"given",
"Point",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/matrix3x3.go#L39-L45 | train |
golang/geo | s2/matrix3x3.go | setRow | func (m *matrix3x3) setRow(row int, p Point) *matrix3x3 {
m[row][0] = p.X
m[row][1] = p.Y
m[row][2] = p.Z
return m
} | go | func (m *matrix3x3) setRow(row int, p Point) *matrix3x3 {
m[row][0] = p.X
m[row][1] = p.Y
m[row][2] = p.Z
return m
} | [
"func",
"(",
"m",
"*",
"matrix3x3",
")",
"setRow",
"(",
"row",
"int",
",",
"p",
"Point",
")",
"*",
"matrix3x3",
"{",
"m",
"[",
"row",
"]",
"[",
"0",
"]",
"=",
"p",
".",
"X",
"\n",
"m",
"[",
"row",
"]",
"[",
"1",
"]",
"=",
"p",
".",
"Y",
... | // setRow sets the specified row to the value in the given Point. | [
"setRow",
"sets",
"the",
"specified",
"row",
"to",
"the",
"value",
"in",
"the",
"given",
"Point",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/matrix3x3.go#L48-L54 | train |
golang/geo | s2/matrix3x3.go | scale | func (m *matrix3x3) scale(f float64) *matrix3x3 {
return &matrix3x3{
[3]float64{f * m[0][0], f * m[0][1], f * m[0][2]},
[3]float64{f * m[1][0], f * m[1][1], f * m[1][2]},
[3]float64{f * m[2][0], f * m[2][1], f * m[2][2]},
}
} | go | func (m *matrix3x3) scale(f float64) *matrix3x3 {
return &matrix3x3{
[3]float64{f * m[0][0], f * m[0][1], f * m[0][2]},
[3]float64{f * m[1][0], f * m[1][1], f * m[1][2]},
[3]float64{f * m[2][0], f * m[2][1], f * m[2][2]},
}
} | [
"func",
"(",
"m",
"*",
"matrix3x3",
")",
"scale",
"(",
"f",
"float64",
")",
"*",
"matrix3x3",
"{",
"return",
"&",
"matrix3x3",
"{",
"[",
"3",
"]",
"float64",
"{",
"f",
"*",
"m",
"[",
"0",
"]",
"[",
"0",
"]",
",",
"f",
"*",
"m",
"[",
"0",
"]... | // scale multiplies the matrix by the given value. | [
"scale",
"multiplies",
"the",
"matrix",
"by",
"the",
"given",
"value",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/matrix3x3.go#L57-L63 | train |
golang/geo | s2/matrix3x3.go | mul | func (m *matrix3x3) mul(p Point) Point {
return Point{r3.Vector{
m[0][0]*p.X + m[0][1]*p.Y + m[0][2]*p.Z,
m[1][0]*p.X + m[1][1]*p.Y + m[1][2]*p.Z,
m[2][0]*p.X + m[2][1]*p.Y + m[2][2]*p.Z,
}}
} | go | func (m *matrix3x3) mul(p Point) Point {
return Point{r3.Vector{
m[0][0]*p.X + m[0][1]*p.Y + m[0][2]*p.Z,
m[1][0]*p.X + m[1][1]*p.Y + m[1][2]*p.Z,
m[2][0]*p.X + m[2][1]*p.Y + m[2][2]*p.Z,
}}
} | [
"func",
"(",
"m",
"*",
"matrix3x3",
")",
"mul",
"(",
"p",
"Point",
")",
"Point",
"{",
"return",
"Point",
"{",
"r3",
".",
"Vector",
"{",
"m",
"[",
"0",
"]",
"[",
"0",
"]",
"*",
"p",
".",
"X",
"+",
"m",
"[",
"0",
"]",
"[",
"1",
"]",
"*",
... | // mul returns the multiplication of m by the Point p and converts the
// resulting 1x3 matrix into a Point. | [
"mul",
"returns",
"the",
"multiplication",
"of",
"m",
"by",
"the",
"Point",
"p",
"and",
"converts",
"the",
"resulting",
"1x3",
"matrix",
"into",
"a",
"Point",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/matrix3x3.go#L67-L73 | train |
golang/geo | s2/matrix3x3.go | det | func (m *matrix3x3) det() float64 {
// | a b c |
// det | d e f | = aei + bfg + cdh - ceg - bdi - afh
// | g h i |
return m[0][0]*m[1][1]*m[2][2] + m[0][1]*m[1][2]*m[2][0] + m[0][2]*m[1][0]*m[2][1] -
m[0][2]*m[1][1]*m[2][0] - m[0][1]*m[1][0]*m[2][2] - m[0][0]*m[1][2]*m[2][1]
} | go | func (m *matrix3x3) det() float64 {
// | a b c |
// det | d e f | = aei + bfg + cdh - ceg - bdi - afh
// | g h i |
return m[0][0]*m[1][1]*m[2][2] + m[0][1]*m[1][2]*m[2][0] + m[0][2]*m[1][0]*m[2][1] -
m[0][2]*m[1][1]*m[2][0] - m[0][1]*m[1][0]*m[2][2] - m[0][0]*m[1][2]*m[2][1]
} | [
"func",
"(",
"m",
"*",
"matrix3x3",
")",
"det",
"(",
")",
"float64",
"{",
"// | a b c |",
"// det | d e f | = aei + bfg + cdh - ceg - bdi - afh",
"// | g h i |",
"return",
"m",
"[",
"0",
"]",
"[",
"0",
"]",
"*",
"m",
"[",
"1",
"]",
"[",
"1",
... | // det returns the determinant of this matrix. | [
"det",
"returns",
"the",
"determinant",
"of",
"this",
"matrix",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/matrix3x3.go#L76-L82 | train |
golang/geo | s2/matrix3x3.go | transpose | func (m *matrix3x3) transpose() *matrix3x3 {
m[0][1], m[1][0] = m[1][0], m[0][1]
m[0][2], m[2][0] = m[2][0], m[0][2]
m[1][2], m[2][1] = m[2][1], m[1][2]
return m
} | go | func (m *matrix3x3) transpose() *matrix3x3 {
m[0][1], m[1][0] = m[1][0], m[0][1]
m[0][2], m[2][0] = m[2][0], m[0][2]
m[1][2], m[2][1] = m[2][1], m[1][2]
return m
} | [
"func",
"(",
"m",
"*",
"matrix3x3",
")",
"transpose",
"(",
")",
"*",
"matrix3x3",
"{",
"m",
"[",
"0",
"]",
"[",
"1",
"]",
",",
"m",
"[",
"1",
"]",
"[",
"0",
"]",
"=",
"m",
"[",
"1",
"]",
"[",
"0",
"]",
",",
"m",
"[",
"0",
"]",
"[",
"1... | // transpose reflects the matrix along its diagonal and returns the result. | [
"transpose",
"reflects",
"the",
"matrix",
"along",
"its",
"diagonal",
"and",
"returns",
"the",
"result",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/matrix3x3.go#L85-L91 | train |
golang/geo | s2/matrix3x3.go | String | func (m *matrix3x3) String() string {
return fmt.Sprintf("[ %0.4f %0.4f %0.4f ] [ %0.4f %0.4f %0.4f ] [ %0.4f %0.4f %0.4f ]",
m[0][0], m[0][1], m[0][2],
m[1][0], m[1][1], m[1][2],
m[2][0], m[2][1], m[2][2],
)
} | go | func (m *matrix3x3) String() string {
return fmt.Sprintf("[ %0.4f %0.4f %0.4f ] [ %0.4f %0.4f %0.4f ] [ %0.4f %0.4f %0.4f ]",
m[0][0], m[0][1], m[0][2],
m[1][0], m[1][1], m[1][2],
m[2][0], m[2][1], m[2][2],
)
} | [
"func",
"(",
"m",
"*",
"matrix3x3",
")",
"String",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"m",
"[",
"0",
"]",
"[",
"0",
"]",
",",
"m",
"[",
"0",
"]",
"[",
"1",
"]",
",",
"m",
"[",
"0",
"]",
"[",
... | // String formats the matrix into an easier to read layout. | [
"String",
"formats",
"the",
"matrix",
"into",
"an",
"easier",
"to",
"read",
"layout",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/matrix3x3.go#L94-L100 | train |
golang/geo | s2/matrix3x3.go | getFrame | func getFrame(p Point) matrix3x3 {
// Given the point p on the unit sphere, extend this into a right-handed
// coordinate frame of unit-length column vectors m = (x,y,z). Note that
// the vectors (x,y) are an orthonormal frame for the tangent space at point p,
// while p itself is an orthonormal frame for the normal space at p.
m := matrix3x3{}
m.setCol(2, p)
m.setCol(1, Point{p.Ortho()})
m.setCol(0, Point{m.col(1).Cross(p.Vector)})
return m
} | go | func getFrame(p Point) matrix3x3 {
// Given the point p on the unit sphere, extend this into a right-handed
// coordinate frame of unit-length column vectors m = (x,y,z). Note that
// the vectors (x,y) are an orthonormal frame for the tangent space at point p,
// while p itself is an orthonormal frame for the normal space at p.
m := matrix3x3{}
m.setCol(2, p)
m.setCol(1, Point{p.Ortho()})
m.setCol(0, Point{m.col(1).Cross(p.Vector)})
return m
} | [
"func",
"getFrame",
"(",
"p",
"Point",
")",
"matrix3x3",
"{",
"// Given the point p on the unit sphere, extend this into a right-handed",
"// coordinate frame of unit-length column vectors m = (x,y,z). Note that",
"// the vectors (x,y) are an orthonormal frame for the tangent space at point p,"... | // getFrame returns the orthonormal frame for the given point on the unit sphere. | [
"getFrame",
"returns",
"the",
"orthonormal",
"frame",
"for",
"the",
"given",
"point",
"on",
"the",
"unit",
"sphere",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/matrix3x3.go#L103-L113 | train |
golang/geo | r2/rect.go | Normalize | func (p Point) Normalize() Point {
if p.X == 0 && p.Y == 0 {
return p
}
return p.Mul(1 / p.Norm())
} | go | func (p Point) Normalize() Point {
if p.X == 0 && p.Y == 0 {
return p
}
return p.Mul(1 / p.Norm())
} | [
"func",
"(",
"p",
"Point",
")",
"Normalize",
"(",
")",
"Point",
"{",
"if",
"p",
".",
"X",
"==",
"0",
"&&",
"p",
".",
"Y",
"==",
"0",
"{",
"return",
"p",
"\n",
"}",
"\n",
"return",
"p",
".",
"Mul",
"(",
"1",
"/",
"p",
".",
"Norm",
"(",
")"... | // Normalize returns a unit point in the same direction as p. | [
"Normalize",
"returns",
"a",
"unit",
"point",
"in",
"the",
"same",
"direction",
"as",
"p",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/r2/rect.go#L51-L56 | train |
golang/geo | r2/rect.go | RectFromPoints | func RectFromPoints(pts ...Point) Rect {
// Because the default value on interval is 0,0, we need to manually
// define the interval from the first point passed in as our starting
// interval, otherwise we end up with the case of passing in
// Point{0.2, 0.3} and getting the starting Rect of {0, 0.2}, {0, 0.3}
// instead of the Rect {0.2, 0.2}, {0.3, 0.3} which is not correct.
if len(pts) == 0 {
return Rect{}
}
r := Rect{
X: r1.Interval{Lo: pts[0].X, Hi: pts[0].X},
Y: r1.Interval{Lo: pts[0].Y, Hi: pts[0].Y},
}
for _, p := range pts[1:] {
r = r.AddPoint(p)
}
return r
} | go | func RectFromPoints(pts ...Point) Rect {
// Because the default value on interval is 0,0, we need to manually
// define the interval from the first point passed in as our starting
// interval, otherwise we end up with the case of passing in
// Point{0.2, 0.3} and getting the starting Rect of {0, 0.2}, {0, 0.3}
// instead of the Rect {0.2, 0.2}, {0.3, 0.3} which is not correct.
if len(pts) == 0 {
return Rect{}
}
r := Rect{
X: r1.Interval{Lo: pts[0].X, Hi: pts[0].X},
Y: r1.Interval{Lo: pts[0].Y, Hi: pts[0].Y},
}
for _, p := range pts[1:] {
r = r.AddPoint(p)
}
return r
} | [
"func",
"RectFromPoints",
"(",
"pts",
"...",
"Point",
")",
"Rect",
"{",
"// Because the default value on interval is 0,0, we need to manually",
"// define the interval from the first point passed in as our starting",
"// interval, otherwise we end up with the case of passing in",
"// Point{0... | // RectFromPoints constructs a rect that contains the given points. | [
"RectFromPoints",
"constructs",
"a",
"rect",
"that",
"contains",
"the",
"given",
"points",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/r2/rect.go#L66-L85 | train |
golang/geo | r2/rect.go | RectFromCenterSize | func RectFromCenterSize(center, size Point) Rect {
return Rect{
r1.Interval{Lo: center.X - size.X/2, Hi: center.X + size.X/2},
r1.Interval{Lo: center.Y - size.Y/2, Hi: center.Y + size.Y/2},
}
} | go | func RectFromCenterSize(center, size Point) Rect {
return Rect{
r1.Interval{Lo: center.X - size.X/2, Hi: center.X + size.X/2},
r1.Interval{Lo: center.Y - size.Y/2, Hi: center.Y + size.Y/2},
}
} | [
"func",
"RectFromCenterSize",
"(",
"center",
",",
"size",
"Point",
")",
"Rect",
"{",
"return",
"Rect",
"{",
"r1",
".",
"Interval",
"{",
"Lo",
":",
"center",
".",
"X",
"-",
"size",
".",
"X",
"/",
"2",
",",
"Hi",
":",
"center",
".",
"X",
"+",
"size... | // RectFromCenterSize constructs a rectangle with the given center and size.
// Both dimensions of size must be non-negative. | [
"RectFromCenterSize",
"constructs",
"a",
"rectangle",
"with",
"the",
"given",
"center",
"and",
"size",
".",
"Both",
"dimensions",
"of",
"size",
"must",
"be",
"non",
"-",
"negative",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/r2/rect.go#L89-L94 | train |
golang/geo | r2/rect.go | IsValid | func (r Rect) IsValid() bool {
return r.X.IsEmpty() == r.Y.IsEmpty()
} | go | func (r Rect) IsValid() bool {
return r.X.IsEmpty() == r.Y.IsEmpty()
} | [
"func",
"(",
"r",
"Rect",
")",
"IsValid",
"(",
")",
"bool",
"{",
"return",
"r",
".",
"X",
".",
"IsEmpty",
"(",
")",
"==",
"r",
".",
"Y",
".",
"IsEmpty",
"(",
")",
"\n",
"}"
] | // IsValid reports whether the rectangle is valid.
// This requires the width to be empty iff the height is empty. | [
"IsValid",
"reports",
"whether",
"the",
"rectangle",
"is",
"valid",
".",
"This",
"requires",
"the",
"width",
"to",
"be",
"empty",
"iff",
"the",
"height",
"is",
"empty",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/r2/rect.go#L105-L107 | train |
golang/geo | r2/rect.go | Vertices | func (r Rect) Vertices() [4]Point {
return [4]Point{
{r.X.Lo, r.Y.Lo},
{r.X.Hi, r.Y.Lo},
{r.X.Hi, r.Y.Hi},
{r.X.Lo, r.Y.Hi},
}
} | go | func (r Rect) Vertices() [4]Point {
return [4]Point{
{r.X.Lo, r.Y.Lo},
{r.X.Hi, r.Y.Lo},
{r.X.Hi, r.Y.Hi},
{r.X.Lo, r.Y.Hi},
}
} | [
"func",
"(",
"r",
"Rect",
")",
"Vertices",
"(",
")",
"[",
"4",
"]",
"Point",
"{",
"return",
"[",
"4",
"]",
"Point",
"{",
"{",
"r",
".",
"X",
".",
"Lo",
",",
"r",
".",
"Y",
".",
"Lo",
"}",
",",
"{",
"r",
".",
"X",
".",
"Hi",
",",
"r",
... | // Vertices returns all four vertices of the rectangle. Vertices are returned in
// CCW direction starting with the lower left corner. | [
"Vertices",
"returns",
"all",
"four",
"vertices",
"of",
"the",
"rectangle",
".",
"Vertices",
"are",
"returned",
"in",
"CCW",
"direction",
"starting",
"with",
"the",
"lower",
"left",
"corner",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/r2/rect.go#L116-L123 | train |
golang/geo | r2/rect.go | Lo | func (r Rect) Lo() Point {
return Point{r.X.Lo, r.Y.Lo}
} | go | func (r Rect) Lo() Point {
return Point{r.X.Lo, r.Y.Lo}
} | [
"func",
"(",
"r",
"Rect",
")",
"Lo",
"(",
")",
"Point",
"{",
"return",
"Point",
"{",
"r",
".",
"X",
".",
"Lo",
",",
"r",
".",
"Y",
".",
"Lo",
"}",
"\n",
"}"
] | // Lo returns the low corner of the rect. | [
"Lo",
"returns",
"the",
"low",
"corner",
"of",
"the",
"rect",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/r2/rect.go#L140-L142 | train |
golang/geo | r2/rect.go | Hi | func (r Rect) Hi() Point {
return Point{r.X.Hi, r.Y.Hi}
} | go | func (r Rect) Hi() Point {
return Point{r.X.Hi, r.Y.Hi}
} | [
"func",
"(",
"r",
"Rect",
")",
"Hi",
"(",
")",
"Point",
"{",
"return",
"Point",
"{",
"r",
".",
"X",
".",
"Hi",
",",
"r",
".",
"Y",
".",
"Hi",
"}",
"\n",
"}"
] | // Hi returns the high corner of the rect. | [
"Hi",
"returns",
"the",
"high",
"corner",
"of",
"the",
"rect",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/r2/rect.go#L145-L147 | train |
golang/geo | r2/rect.go | ContainsPoint | func (r Rect) ContainsPoint(p Point) bool {
return r.X.Contains(p.X) && r.Y.Contains(p.Y)
} | go | func (r Rect) ContainsPoint(p Point) bool {
return r.X.Contains(p.X) && r.Y.Contains(p.Y)
} | [
"func",
"(",
"r",
"Rect",
")",
"ContainsPoint",
"(",
"p",
"Point",
")",
"bool",
"{",
"return",
"r",
".",
"X",
".",
"Contains",
"(",
"p",
".",
"X",
")",
"&&",
"r",
".",
"Y",
".",
"Contains",
"(",
"p",
".",
"Y",
")",
"\n",
"}"
] | // ContainsPoint reports whether the rectangle contains the given point.
// Rectangles are closed regions, i.e. they contain their boundary. | [
"ContainsPoint",
"reports",
"whether",
"the",
"rectangle",
"contains",
"the",
"given",
"point",
".",
"Rectangles",
"are",
"closed",
"regions",
"i",
".",
"e",
".",
"they",
"contain",
"their",
"boundary",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/r2/rect.go#L162-L164 | train |
golang/geo | r2/rect.go | Contains | func (r Rect) Contains(other Rect) bool {
return r.X.ContainsInterval(other.X) && r.Y.ContainsInterval(other.Y)
} | go | func (r Rect) Contains(other Rect) bool {
return r.X.ContainsInterval(other.X) && r.Y.ContainsInterval(other.Y)
} | [
"func",
"(",
"r",
"Rect",
")",
"Contains",
"(",
"other",
"Rect",
")",
"bool",
"{",
"return",
"r",
".",
"X",
".",
"ContainsInterval",
"(",
"other",
".",
"X",
")",
"&&",
"r",
".",
"Y",
".",
"ContainsInterval",
"(",
"other",
".",
"Y",
")",
"\n",
"}"... | // Contains reports whether the rectangle contains the given rectangle. | [
"Contains",
"reports",
"whether",
"the",
"rectangle",
"contains",
"the",
"given",
"rectangle",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/r2/rect.go#L173-L175 | train |
golang/geo | r2/rect.go | Intersects | func (r Rect) Intersects(other Rect) bool {
return r.X.Intersects(other.X) && r.Y.Intersects(other.Y)
} | go | func (r Rect) Intersects(other Rect) bool {
return r.X.Intersects(other.X) && r.Y.Intersects(other.Y)
} | [
"func",
"(",
"r",
"Rect",
")",
"Intersects",
"(",
"other",
"Rect",
")",
"bool",
"{",
"return",
"r",
".",
"X",
".",
"Intersects",
"(",
"other",
".",
"X",
")",
"&&",
"r",
".",
"Y",
".",
"Intersects",
"(",
"other",
".",
"Y",
")",
"\n",
"}"
] | // Intersects reports whether this rectangle and the other rectangle have any points in common. | [
"Intersects",
"reports",
"whether",
"this",
"rectangle",
"and",
"the",
"other",
"rectangle",
"have",
"any",
"points",
"in",
"common",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/r2/rect.go#L184-L186 | train |
golang/geo | r2/rect.go | AddPoint | func (r Rect) AddPoint(p Point) Rect {
return Rect{r.X.AddPoint(p.X), r.Y.AddPoint(p.Y)}
} | go | func (r Rect) AddPoint(p Point) Rect {
return Rect{r.X.AddPoint(p.X), r.Y.AddPoint(p.Y)}
} | [
"func",
"(",
"r",
"Rect",
")",
"AddPoint",
"(",
"p",
"Point",
")",
"Rect",
"{",
"return",
"Rect",
"{",
"r",
".",
"X",
".",
"AddPoint",
"(",
"p",
".",
"X",
")",
",",
"r",
".",
"Y",
".",
"AddPoint",
"(",
"p",
".",
"Y",
")",
"}",
"\n",
"}"
] | // AddPoint expands the rectangle to include the given point. The rectangle is
// expanded by the minimum amount possible. | [
"AddPoint",
"expands",
"the",
"rectangle",
"to",
"include",
"the",
"given",
"point",
".",
"The",
"rectangle",
"is",
"expanded",
"by",
"the",
"minimum",
"amount",
"possible",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/r2/rect.go#L196-L198 | train |
golang/geo | r2/rect.go | ClampPoint | func (r Rect) ClampPoint(p Point) Point {
return Point{r.X.ClampPoint(p.X), r.Y.ClampPoint(p.Y)}
} | go | func (r Rect) ClampPoint(p Point) Point {
return Point{r.X.ClampPoint(p.X), r.Y.ClampPoint(p.Y)}
} | [
"func",
"(",
"r",
"Rect",
")",
"ClampPoint",
"(",
"p",
"Point",
")",
"Point",
"{",
"return",
"Point",
"{",
"r",
".",
"X",
".",
"ClampPoint",
"(",
"p",
".",
"X",
")",
",",
"r",
".",
"Y",
".",
"ClampPoint",
"(",
"p",
".",
"Y",
")",
"}",
"\n",
... | // ClampPoint returns the closest point in the rectangle to the given point.
// The rectangle must be non-empty. | [
"ClampPoint",
"returns",
"the",
"closest",
"point",
"in",
"the",
"rectangle",
"to",
"the",
"given",
"point",
".",
"The",
"rectangle",
"must",
"be",
"non",
"-",
"empty",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/r2/rect.go#L209-L211 | train |
golang/geo | r2/rect.go | Expanded | func (r Rect) Expanded(margin Point) Rect {
xx := r.X.Expanded(margin.X)
yy := r.Y.Expanded(margin.Y)
if xx.IsEmpty() || yy.IsEmpty() {
return EmptyRect()
}
return Rect{xx, yy}
} | go | func (r Rect) Expanded(margin Point) Rect {
xx := r.X.Expanded(margin.X)
yy := r.Y.Expanded(margin.Y)
if xx.IsEmpty() || yy.IsEmpty() {
return EmptyRect()
}
return Rect{xx, yy}
} | [
"func",
"(",
"r",
"Rect",
")",
"Expanded",
"(",
"margin",
"Point",
")",
"Rect",
"{",
"xx",
":=",
"r",
".",
"X",
".",
"Expanded",
"(",
"margin",
".",
"X",
")",
"\n",
"yy",
":=",
"r",
".",
"Y",
".",
"Expanded",
"(",
"margin",
".",
"Y",
")",
"\n... | // Expanded returns a rectangle that has been expanded in the x-direction
// by margin.X, and in y-direction by margin.Y. If either margin is empty,
// then shrink the interval on the corresponding sides instead. The resulting
// rectangle may be empty. Any expansion of an empty rectangle remains empty. | [
"Expanded",
"returns",
"a",
"rectangle",
"that",
"has",
"been",
"expanded",
"in",
"the",
"x",
"-",
"direction",
"by",
"margin",
".",
"X",
"and",
"in",
"y",
"-",
"direction",
"by",
"margin",
".",
"Y",
".",
"If",
"either",
"margin",
"is",
"empty",
"then"... | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/r2/rect.go#L217-L224 | train |
golang/geo | r2/rect.go | ExpandedByMargin | func (r Rect) ExpandedByMargin(margin float64) Rect {
return r.Expanded(Point{margin, margin})
} | go | func (r Rect) ExpandedByMargin(margin float64) Rect {
return r.Expanded(Point{margin, margin})
} | [
"func",
"(",
"r",
"Rect",
")",
"ExpandedByMargin",
"(",
"margin",
"float64",
")",
"Rect",
"{",
"return",
"r",
".",
"Expanded",
"(",
"Point",
"{",
"margin",
",",
"margin",
"}",
")",
"\n",
"}"
] | // ExpandedByMargin returns a Rect that has been expanded by the amount on all sides. | [
"ExpandedByMargin",
"returns",
"a",
"Rect",
"that",
"has",
"been",
"expanded",
"by",
"the",
"amount",
"on",
"all",
"sides",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/r2/rect.go#L227-L229 | train |
golang/geo | r2/rect.go | Union | func (r Rect) Union(other Rect) Rect {
return Rect{r.X.Union(other.X), r.Y.Union(other.Y)}
} | go | func (r Rect) Union(other Rect) Rect {
return Rect{r.X.Union(other.X), r.Y.Union(other.Y)}
} | [
"func",
"(",
"r",
"Rect",
")",
"Union",
"(",
"other",
"Rect",
")",
"Rect",
"{",
"return",
"Rect",
"{",
"r",
".",
"X",
".",
"Union",
"(",
"other",
".",
"X",
")",
",",
"r",
".",
"Y",
".",
"Union",
"(",
"other",
".",
"Y",
")",
"}",
"\n",
"}"
] | // Union returns the smallest rectangle containing the union of this rectangle and
// the given rectangle. | [
"Union",
"returns",
"the",
"smallest",
"rectangle",
"containing",
"the",
"union",
"of",
"this",
"rectangle",
"and",
"the",
"given",
"rectangle",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/r2/rect.go#L233-L235 | train |
golang/geo | r2/rect.go | Intersection | func (r Rect) Intersection(other Rect) Rect {
xx := r.X.Intersection(other.X)
yy := r.Y.Intersection(other.Y)
if xx.IsEmpty() || yy.IsEmpty() {
return EmptyRect()
}
return Rect{xx, yy}
} | go | func (r Rect) Intersection(other Rect) Rect {
xx := r.X.Intersection(other.X)
yy := r.Y.Intersection(other.Y)
if xx.IsEmpty() || yy.IsEmpty() {
return EmptyRect()
}
return Rect{xx, yy}
} | [
"func",
"(",
"r",
"Rect",
")",
"Intersection",
"(",
"other",
"Rect",
")",
"Rect",
"{",
"xx",
":=",
"r",
".",
"X",
".",
"Intersection",
"(",
"other",
".",
"X",
")",
"\n",
"yy",
":=",
"r",
".",
"Y",
".",
"Intersection",
"(",
"other",
".",
"Y",
")... | // Intersection returns the smallest rectangle containing the intersection of this
// rectangle and the given rectangle. | [
"Intersection",
"returns",
"the",
"smallest",
"rectangle",
"containing",
"the",
"intersection",
"of",
"this",
"rectangle",
"and",
"the",
"given",
"rectangle",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/r2/rect.go#L239-L247 | train |
golang/geo | s2/edge_tessellator.go | NewEdgeTessellator | func NewEdgeTessellator(p Projection, tolerance s1.Angle) *EdgeTessellator {
return &EdgeTessellator{
projection: p,
tolerance: s1.ChordAngleFromAngle(maxAngle(tolerance, MinTessellationTolerance)),
wrapDistance: p.WrapDistance(),
}
} | go | func NewEdgeTessellator(p Projection, tolerance s1.Angle) *EdgeTessellator {
return &EdgeTessellator{
projection: p,
tolerance: s1.ChordAngleFromAngle(maxAngle(tolerance, MinTessellationTolerance)),
wrapDistance: p.WrapDistance(),
}
} | [
"func",
"NewEdgeTessellator",
"(",
"p",
"Projection",
",",
"tolerance",
"s1",
".",
"Angle",
")",
"*",
"EdgeTessellator",
"{",
"return",
"&",
"EdgeTessellator",
"{",
"projection",
":",
"p",
",",
"tolerance",
":",
"s1",
".",
"ChordAngleFromAngle",
"(",
"maxAngle... | // NewEdgeTessellator creates a new edge tessellator for the given projection and tolerance. | [
"NewEdgeTessellator",
"creates",
"a",
"new",
"edge",
"tessellator",
"for",
"the",
"given",
"projection",
"and",
"tolerance",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/edge_tessellator.go#L50-L56 | train |
golang/geo | s2/edge_tessellator.go | appendUnprojected | func (e *EdgeTessellator) appendUnprojected(pa r2.Point, a Point, pb r2.Point, b Point, vertices []Point) []Point {
pmid := e.projection.Interpolate(0.5, pa, pb)
mid := e.projection.Unproject(pmid)
testMid := Point{a.Add(b.Vector).Normalize()}
if ChordAngleBetweenPoints(mid, testMid) < e.tolerance {
return append(vertices, b)
}
vertices = e.appendUnprojected(pa, a, pmid, mid, vertices)
return e.appendUnprojected(pmid, mid, pb, b, vertices)
} | go | func (e *EdgeTessellator) appendUnprojected(pa r2.Point, a Point, pb r2.Point, b Point, vertices []Point) []Point {
pmid := e.projection.Interpolate(0.5, pa, pb)
mid := e.projection.Unproject(pmid)
testMid := Point{a.Add(b.Vector).Normalize()}
if ChordAngleBetweenPoints(mid, testMid) < e.tolerance {
return append(vertices, b)
}
vertices = e.appendUnprojected(pa, a, pmid, mid, vertices)
return e.appendUnprojected(pmid, mid, pb, b, vertices)
} | [
"func",
"(",
"e",
"*",
"EdgeTessellator",
")",
"appendUnprojected",
"(",
"pa",
"r2",
".",
"Point",
",",
"a",
"Point",
",",
"pb",
"r2",
".",
"Point",
",",
"b",
"Point",
",",
"vertices",
"[",
"]",
"Point",
")",
"[",
"]",
"Point",
"{",
"pmid",
":=",
... | // appendUnprojected interpolates a projected edge and appends the corresponding
// points on the sphere. | [
"appendUnprojected",
"interpolates",
"a",
"projected",
"edge",
"and",
"appends",
"the",
"corresponding",
"points",
"on",
"the",
"sphere",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/edge_tessellator.go#L141-L152 | train |
golang/geo | s2/edge_tessellator.go | wrapDestination | func (e *EdgeTessellator) wrapDestination(pa, pb r2.Point) r2.Point {
x := pb.X
y := pb.Y
// The code below ensures that pb is unmodified unless wrapping is required.
if e.wrapDistance.X > 0 && math.Abs(x-pa.X) > 0.5*e.wrapDistance.X {
x = pa.X + math.Remainder(x-pa.X, e.wrapDistance.X)
}
if e.wrapDistance.Y > 0 && math.Abs(y-pa.Y) > 0.5*e.wrapDistance.Y {
y = pa.Y + math.Remainder(y-pa.Y, e.wrapDistance.Y)
}
return r2.Point{x, y}
} | go | func (e *EdgeTessellator) wrapDestination(pa, pb r2.Point) r2.Point {
x := pb.X
y := pb.Y
// The code below ensures that pb is unmodified unless wrapping is required.
if e.wrapDistance.X > 0 && math.Abs(x-pa.X) > 0.5*e.wrapDistance.X {
x = pa.X + math.Remainder(x-pa.X, e.wrapDistance.X)
}
if e.wrapDistance.Y > 0 && math.Abs(y-pa.Y) > 0.5*e.wrapDistance.Y {
y = pa.Y + math.Remainder(y-pa.Y, e.wrapDistance.Y)
}
return r2.Point{x, y}
} | [
"func",
"(",
"e",
"*",
"EdgeTessellator",
")",
"wrapDestination",
"(",
"pa",
",",
"pb",
"r2",
".",
"Point",
")",
"r2",
".",
"Point",
"{",
"x",
":=",
"pb",
".",
"X",
"\n",
"y",
":=",
"pb",
".",
"Y",
"\n",
"// The code below ensures that pb is unmodified u... | // wrapDestination returns the coordinates of the edge destination wrapped if
// necessary to obtain the shortest edge. | [
"wrapDestination",
"returns",
"the",
"coordinates",
"of",
"the",
"edge",
"destination",
"wrapped",
"if",
"necessary",
"to",
"obtain",
"the",
"shortest",
"edge",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/edge_tessellator.go#L156-L167 | train |
Subsets and Splits
SQL Console for semeru/code-text-go
Retrieves a limited set of code samples with their languages, with a specific case adjustment for 'Go' language.