id
int32 0
167k
| 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
sequencelengths 21
1.41k
| docstring
stringlengths 6
2.61k
| docstring_tokens
sequencelengths 3
215
| sha
stringlengths 40
40
| url
stringlengths 85
252
|
---|---|---|---|---|---|---|---|---|---|---|---|
150,100 | golang/geo | s2/regioncoverer.go | addCandidate | func (c *coverer) addCandidate(cand *candidate) {
if cand == nil {
return
}
if cand.terminal {
c.result = append(c.result, cand.cell.id)
return
}
// Expand one level at a time until we hit minLevel to ensure that we don't skip over it.
numLevels := c.levelMod
level := int(cand.cell.level)
if level < c.minLevel {
numLevels = 1
}
numTerminals := c.expandChildren(cand, cand.cell, numLevels)
maxChildrenShift := uint(2 * c.levelMod)
if cand.numChildren == 0 {
return
} else if !c.interiorCovering && numTerminals == 1<<maxChildrenShift && level >= c.minLevel {
// Optimization: add the parent cell rather than all of its children.
// We can't do this for interior coverings, since the children just
// intersect the region, but may not be contained by it - we need to
// subdivide them further.
cand.terminal = true
c.addCandidate(cand)
} else {
// We negate the priority so that smaller absolute priorities are returned
// first. The heuristic is designed to refine the largest cells first,
// since those are where we have the largest potential gain. Among cells
// of the same size, we prefer the cells with the fewest children.
// Finally, among cells with equal numbers of children we prefer those
// with the smallest number of children that cannot be refined further.
cand.priority = -(((level<<maxChildrenShift)+cand.numChildren)<<maxChildrenShift + numTerminals)
heap.Push(&c.pq, cand)
}
} | go | func (c *coverer) addCandidate(cand *candidate) {
if cand == nil {
return
}
if cand.terminal {
c.result = append(c.result, cand.cell.id)
return
}
// Expand one level at a time until we hit minLevel to ensure that we don't skip over it.
numLevels := c.levelMod
level := int(cand.cell.level)
if level < c.minLevel {
numLevels = 1
}
numTerminals := c.expandChildren(cand, cand.cell, numLevels)
maxChildrenShift := uint(2 * c.levelMod)
if cand.numChildren == 0 {
return
} else if !c.interiorCovering && numTerminals == 1<<maxChildrenShift && level >= c.minLevel {
// Optimization: add the parent cell rather than all of its children.
// We can't do this for interior coverings, since the children just
// intersect the region, but may not be contained by it - we need to
// subdivide them further.
cand.terminal = true
c.addCandidate(cand)
} else {
// We negate the priority so that smaller absolute priorities are returned
// first. The heuristic is designed to refine the largest cells first,
// since those are where we have the largest potential gain. Among cells
// of the same size, we prefer the cells with the fewest children.
// Finally, among cells with equal numbers of children we prefer those
// with the smallest number of children that cannot be refined further.
cand.priority = -(((level<<maxChildrenShift)+cand.numChildren)<<maxChildrenShift + numTerminals)
heap.Push(&c.pq, cand)
}
} | [
"func",
"(",
"c",
"*",
"coverer",
")",
"addCandidate",
"(",
"cand",
"*",
"candidate",
")",
"{",
"if",
"cand",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"if",
"cand",
".",
"terminal",
"{",
"c",
".",
"result",
"=",
"append",
"(",
"c",
".",
"result",
",",
"cand",
".",
"cell",
".",
"id",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"// Expand one level at a time until we hit minLevel to ensure that we don't skip over it.",
"numLevels",
":=",
"c",
".",
"levelMod",
"\n",
"level",
":=",
"int",
"(",
"cand",
".",
"cell",
".",
"level",
")",
"\n",
"if",
"level",
"<",
"c",
".",
"minLevel",
"{",
"numLevels",
"=",
"1",
"\n",
"}",
"\n\n",
"numTerminals",
":=",
"c",
".",
"expandChildren",
"(",
"cand",
",",
"cand",
".",
"cell",
",",
"numLevels",
")",
"\n",
"maxChildrenShift",
":=",
"uint",
"(",
"2",
"*",
"c",
".",
"levelMod",
")",
"\n",
"if",
"cand",
".",
"numChildren",
"==",
"0",
"{",
"return",
"\n",
"}",
"else",
"if",
"!",
"c",
".",
"interiorCovering",
"&&",
"numTerminals",
"==",
"1",
"<<",
"maxChildrenShift",
"&&",
"level",
">=",
"c",
".",
"minLevel",
"{",
"// Optimization: add the parent cell rather than all of its children.",
"// We can't do this for interior coverings, since the children just",
"// intersect the region, but may not be contained by it - we need to",
"// subdivide them further.",
"cand",
".",
"terminal",
"=",
"true",
"\n",
"c",
".",
"addCandidate",
"(",
"cand",
")",
"\n",
"}",
"else",
"{",
"// We negate the priority so that smaller absolute priorities are returned",
"// first. The heuristic is designed to refine the largest cells first,",
"// since those are where we have the largest potential gain. Among cells",
"// of the same size, we prefer the cells with the fewest children.",
"// Finally, among cells with equal numbers of children we prefer those",
"// with the smallest number of children that cannot be refined further.",
"cand",
".",
"priority",
"=",
"-",
"(",
"(",
"(",
"level",
"<<",
"maxChildrenShift",
")",
"+",
"cand",
".",
"numChildren",
")",
"<<",
"maxChildrenShift",
"+",
"numTerminals",
")",
"\n",
"heap",
".",
"Push",
"(",
"&",
"c",
".",
"pq",
",",
"cand",
")",
"\n",
"}",
"\n",
"}"
] | // addCandidate adds the given candidate to the result if it is marked as "terminal",
// otherwise expands its children and inserts it into the priority queue.
// Passing an argument of nil does nothing. | [
"addCandidate",
"adds",
"the",
"given",
"candidate",
"to",
"the",
"result",
"if",
"it",
"is",
"marked",
"as",
"terminal",
"otherwise",
"expands",
"its",
"children",
"and",
"inserts",
"it",
"into",
"the",
"priority",
"queue",
".",
"Passing",
"an",
"argument",
"of",
"nil",
"does",
"nothing",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/regioncoverer.go#L180-L218 |
150,101 | golang/geo | s2/regioncoverer.go | initialCandidates | func (c *coverer) initialCandidates() {
// Optimization: start with a small (usually 4 cell) covering of the region's bounding cap.
temp := &RegionCoverer{MaxLevel: c.maxLevel, LevelMod: 1, MaxCells: minInt(4, c.maxCells)}
cells := temp.FastCovering(c.region)
c.adjustCellLevels(&cells)
for _, ci := range cells {
c.addCandidate(c.newCandidate(CellFromCellID(ci)))
}
} | go | func (c *coverer) initialCandidates() {
// Optimization: start with a small (usually 4 cell) covering of the region's bounding cap.
temp := &RegionCoverer{MaxLevel: c.maxLevel, LevelMod: 1, MaxCells: minInt(4, c.maxCells)}
cells := temp.FastCovering(c.region)
c.adjustCellLevels(&cells)
for _, ci := range cells {
c.addCandidate(c.newCandidate(CellFromCellID(ci)))
}
} | [
"func",
"(",
"c",
"*",
"coverer",
")",
"initialCandidates",
"(",
")",
"{",
"// Optimization: start with a small (usually 4 cell) covering of the region's bounding cap.",
"temp",
":=",
"&",
"RegionCoverer",
"{",
"MaxLevel",
":",
"c",
".",
"maxLevel",
",",
"LevelMod",
":",
"1",
",",
"MaxCells",
":",
"minInt",
"(",
"4",
",",
"c",
".",
"maxCells",
")",
"}",
"\n\n",
"cells",
":=",
"temp",
".",
"FastCovering",
"(",
"c",
".",
"region",
")",
"\n",
"c",
".",
"adjustCellLevels",
"(",
"&",
"cells",
")",
"\n",
"for",
"_",
",",
"ci",
":=",
"range",
"cells",
"{",
"c",
".",
"addCandidate",
"(",
"c",
".",
"newCandidate",
"(",
"CellFromCellID",
"(",
"ci",
")",
")",
")",
"\n",
"}",
"\n",
"}"
] | // initialCandidates computes a set of initial candidates that cover the given region. | [
"initialCandidates",
"computes",
"a",
"set",
"of",
"initial",
"candidates",
"that",
"cover",
"the",
"given",
"region",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/regioncoverer.go#L258-L267 |
150,102 | golang/geo | s2/regioncoverer.go | newCoverer | func (rc *RegionCoverer) newCoverer() *coverer {
return &coverer{
minLevel: maxInt(0, minInt(maxLevel, rc.MinLevel)),
maxLevel: maxInt(0, minInt(maxLevel, rc.MaxLevel)),
levelMod: maxInt(1, minInt(3, rc.LevelMod)),
maxCells: rc.MaxCells,
}
} | go | func (rc *RegionCoverer) newCoverer() *coverer {
return &coverer{
minLevel: maxInt(0, minInt(maxLevel, rc.MinLevel)),
maxLevel: maxInt(0, minInt(maxLevel, rc.MaxLevel)),
levelMod: maxInt(1, minInt(3, rc.LevelMod)),
maxCells: rc.MaxCells,
}
} | [
"func",
"(",
"rc",
"*",
"RegionCoverer",
")",
"newCoverer",
"(",
")",
"*",
"coverer",
"{",
"return",
"&",
"coverer",
"{",
"minLevel",
":",
"maxInt",
"(",
"0",
",",
"minInt",
"(",
"maxLevel",
",",
"rc",
".",
"MinLevel",
")",
")",
",",
"maxLevel",
":",
"maxInt",
"(",
"0",
",",
"minInt",
"(",
"maxLevel",
",",
"rc",
".",
"MaxLevel",
")",
")",
",",
"levelMod",
":",
"maxInt",
"(",
"1",
",",
"minInt",
"(",
"3",
",",
"rc",
".",
"LevelMod",
")",
")",
",",
"maxCells",
":",
"rc",
".",
"MaxCells",
",",
"}",
"\n",
"}"
] | // newCoverer returns an instance of coverer. | [
"newCoverer",
"returns",
"an",
"instance",
"of",
"coverer",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/regioncoverer.go#L314-L321 |
150,103 | golang/geo | s2/regioncoverer.go | Covering | func (rc *RegionCoverer) Covering(region Region) CellUnion {
covering := rc.CellUnion(region)
covering.Denormalize(maxInt(0, minInt(maxLevel, rc.MinLevel)), maxInt(1, minInt(3, rc.LevelMod)))
return covering
} | go | func (rc *RegionCoverer) Covering(region Region) CellUnion {
covering := rc.CellUnion(region)
covering.Denormalize(maxInt(0, minInt(maxLevel, rc.MinLevel)), maxInt(1, minInt(3, rc.LevelMod)))
return covering
} | [
"func",
"(",
"rc",
"*",
"RegionCoverer",
")",
"Covering",
"(",
"region",
"Region",
")",
"CellUnion",
"{",
"covering",
":=",
"rc",
".",
"CellUnion",
"(",
"region",
")",
"\n",
"covering",
".",
"Denormalize",
"(",
"maxInt",
"(",
"0",
",",
"minInt",
"(",
"maxLevel",
",",
"rc",
".",
"MinLevel",
")",
")",
",",
"maxInt",
"(",
"1",
",",
"minInt",
"(",
"3",
",",
"rc",
".",
"LevelMod",
")",
")",
")",
"\n",
"return",
"covering",
"\n",
"}"
] | // Covering returns a CellUnion that covers the given region and satisfies the various restrictions. | [
"Covering",
"returns",
"a",
"CellUnion",
"that",
"covers",
"the",
"given",
"region",
"and",
"satisfies",
"the",
"various",
"restrictions",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/regioncoverer.go#L324-L328 |
150,104 | golang/geo | s2/regioncoverer.go | InteriorCovering | func (rc *RegionCoverer) InteriorCovering(region Region) CellUnion {
intCovering := rc.InteriorCellUnion(region)
intCovering.Denormalize(maxInt(0, minInt(maxLevel, rc.MinLevel)), maxInt(1, minInt(3, rc.LevelMod)))
return intCovering
} | go | func (rc *RegionCoverer) InteriorCovering(region Region) CellUnion {
intCovering := rc.InteriorCellUnion(region)
intCovering.Denormalize(maxInt(0, minInt(maxLevel, rc.MinLevel)), maxInt(1, minInt(3, rc.LevelMod)))
return intCovering
} | [
"func",
"(",
"rc",
"*",
"RegionCoverer",
")",
"InteriorCovering",
"(",
"region",
"Region",
")",
"CellUnion",
"{",
"intCovering",
":=",
"rc",
".",
"InteriorCellUnion",
"(",
"region",
")",
"\n",
"intCovering",
".",
"Denormalize",
"(",
"maxInt",
"(",
"0",
",",
"minInt",
"(",
"maxLevel",
",",
"rc",
".",
"MinLevel",
")",
")",
",",
"maxInt",
"(",
"1",
",",
"minInt",
"(",
"3",
",",
"rc",
".",
"LevelMod",
")",
")",
")",
"\n",
"return",
"intCovering",
"\n",
"}"
] | // InteriorCovering returns a CellUnion that is contained within the given region and satisfies the various restrictions. | [
"InteriorCovering",
"returns",
"a",
"CellUnion",
"that",
"is",
"contained",
"within",
"the",
"given",
"region",
"and",
"satisfies",
"the",
"various",
"restrictions",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/regioncoverer.go#L331-L335 |
150,105 | golang/geo | s2/regioncoverer.go | SimpleRegionCovering | func SimpleRegionCovering(region Region, start Point, level int) []CellID {
return FloodFillRegionCovering(region, cellIDFromPoint(start).Parent(level))
} | go | func SimpleRegionCovering(region Region, start Point, level int) []CellID {
return FloodFillRegionCovering(region, cellIDFromPoint(start).Parent(level))
} | [
"func",
"SimpleRegionCovering",
"(",
"region",
"Region",
",",
"start",
"Point",
",",
"level",
"int",
")",
"[",
"]",
"CellID",
"{",
"return",
"FloodFillRegionCovering",
"(",
"region",
",",
"cellIDFromPoint",
"(",
"start",
")",
".",
"Parent",
"(",
"level",
")",
")",
"\n",
"}"
] | // SimpleRegionCovering returns a set of cells at the given level that cover
// the connected region and a starting point on the boundary or inside the
// region. The cells are returned in arbitrary order.
//
// Note that this method is not faster than the regular Covering
// method for most region types, such as Cap or Polygon, and in fact it
// can be much slower when the output consists of a large number of cells.
// Currently it can be faster at generating coverings of long narrow regions
// such as polylines, but this may change in the future. | [
"SimpleRegionCovering",
"returns",
"a",
"set",
"of",
"cells",
"at",
"the",
"given",
"level",
"that",
"cover",
"the",
"connected",
"region",
"and",
"a",
"starting",
"point",
"on",
"the",
"boundary",
"or",
"inside",
"the",
"region",
".",
"The",
"cells",
"are",
"returned",
"in",
"arbitrary",
"order",
".",
"Note",
"that",
"this",
"method",
"is",
"not",
"faster",
"than",
"the",
"regular",
"Covering",
"method",
"for",
"most",
"region",
"types",
"such",
"as",
"Cap",
"or",
"Polygon",
"and",
"in",
"fact",
"it",
"can",
"be",
"much",
"slower",
"when",
"the",
"output",
"consists",
"of",
"a",
"large",
"number",
"of",
"cells",
".",
"Currently",
"it",
"can",
"be",
"faster",
"at",
"generating",
"coverings",
"of",
"long",
"narrow",
"regions",
"such",
"as",
"polylines",
"but",
"this",
"may",
"change",
"in",
"the",
"future",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/regioncoverer.go#L442-L444 |
150,106 | golang/geo | s2/regioncoverer.go | FloodFillRegionCovering | func FloodFillRegionCovering(region Region, start CellID) []CellID {
var output []CellID
all := map[CellID]bool{
start: true,
}
frontier := []CellID{start}
for len(frontier) > 0 {
id := frontier[len(frontier)-1]
frontier = frontier[:len(frontier)-1]
if !region.IntersectsCell(CellFromCellID(id)) {
continue
}
output = append(output, id)
for _, nbr := range id.EdgeNeighbors() {
if !all[nbr] {
all[nbr] = true
frontier = append(frontier, nbr)
}
}
}
return output
} | go | func FloodFillRegionCovering(region Region, start CellID) []CellID {
var output []CellID
all := map[CellID]bool{
start: true,
}
frontier := []CellID{start}
for len(frontier) > 0 {
id := frontier[len(frontier)-1]
frontier = frontier[:len(frontier)-1]
if !region.IntersectsCell(CellFromCellID(id)) {
continue
}
output = append(output, id)
for _, nbr := range id.EdgeNeighbors() {
if !all[nbr] {
all[nbr] = true
frontier = append(frontier, nbr)
}
}
}
return output
} | [
"func",
"FloodFillRegionCovering",
"(",
"region",
"Region",
",",
"start",
"CellID",
")",
"[",
"]",
"CellID",
"{",
"var",
"output",
"[",
"]",
"CellID",
"\n",
"all",
":=",
"map",
"[",
"CellID",
"]",
"bool",
"{",
"start",
":",
"true",
",",
"}",
"\n",
"frontier",
":=",
"[",
"]",
"CellID",
"{",
"start",
"}",
"\n",
"for",
"len",
"(",
"frontier",
")",
">",
"0",
"{",
"id",
":=",
"frontier",
"[",
"len",
"(",
"frontier",
")",
"-",
"1",
"]",
"\n",
"frontier",
"=",
"frontier",
"[",
":",
"len",
"(",
"frontier",
")",
"-",
"1",
"]",
"\n",
"if",
"!",
"region",
".",
"IntersectsCell",
"(",
"CellFromCellID",
"(",
"id",
")",
")",
"{",
"continue",
"\n",
"}",
"\n",
"output",
"=",
"append",
"(",
"output",
",",
"id",
")",
"\n",
"for",
"_",
",",
"nbr",
":=",
"range",
"id",
".",
"EdgeNeighbors",
"(",
")",
"{",
"if",
"!",
"all",
"[",
"nbr",
"]",
"{",
"all",
"[",
"nbr",
"]",
"=",
"true",
"\n",
"frontier",
"=",
"append",
"(",
"frontier",
",",
"nbr",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"output",
"\n",
"}"
] | // FloodFillRegionCovering returns all edge-connected cells at the same level as
// the given CellID that intersect the given region, in arbitrary order. | [
"FloodFillRegionCovering",
"returns",
"all",
"edge",
"-",
"connected",
"cells",
"at",
"the",
"same",
"level",
"as",
"the",
"given",
"CellID",
"that",
"intersect",
"the",
"given",
"region",
"in",
"arbitrary",
"order",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/regioncoverer.go#L448-L470 |
150,107 | golang/geo | s2/pointcompression.go | encodePointsCompressed | func encodePointsCompressed(e *encoder, vertices []xyzFaceSiTi, level int) {
var faces []faceRun
for _, v := range vertices {
faces = appendFace(faces, v.face)
}
encodeFaces(e, faces)
type piQi struct {
pi, qi uint32
}
verticesPiQi := make([]piQi, len(vertices))
for i, v := range vertices {
verticesPiQi[i] = piQi{siTitoPiQi(v.si, level), siTitoPiQi(v.ti, level)}
}
piCoder, qiCoder := newNthDerivativeCoder(derivativeEncodingOrder), newNthDerivativeCoder(derivativeEncodingOrder)
for i, v := range verticesPiQi {
f := encodePointCompressed
if i == 0 {
// The first point will be just the (pi, qi) coordinates
// of the Point. NthDerivativeCoder will not save anything
// in that case, so we encode in fixed format rather than varint
// to avoid the varint overhead.
f = encodeFirstPointFixedLength
}
f(e, v.pi, v.qi, level, piCoder, qiCoder)
}
var offCenter []int
for i, v := range vertices {
if v.level != level {
offCenter = append(offCenter, i)
}
}
e.writeUvarint(uint64(len(offCenter)))
for _, idx := range offCenter {
e.writeUvarint(uint64(idx))
e.writeFloat64(vertices[idx].xyz.X)
e.writeFloat64(vertices[idx].xyz.Y)
e.writeFloat64(vertices[idx].xyz.Z)
}
} | go | func encodePointsCompressed(e *encoder, vertices []xyzFaceSiTi, level int) {
var faces []faceRun
for _, v := range vertices {
faces = appendFace(faces, v.face)
}
encodeFaces(e, faces)
type piQi struct {
pi, qi uint32
}
verticesPiQi := make([]piQi, len(vertices))
for i, v := range vertices {
verticesPiQi[i] = piQi{siTitoPiQi(v.si, level), siTitoPiQi(v.ti, level)}
}
piCoder, qiCoder := newNthDerivativeCoder(derivativeEncodingOrder), newNthDerivativeCoder(derivativeEncodingOrder)
for i, v := range verticesPiQi {
f := encodePointCompressed
if i == 0 {
// The first point will be just the (pi, qi) coordinates
// of the Point. NthDerivativeCoder will not save anything
// in that case, so we encode in fixed format rather than varint
// to avoid the varint overhead.
f = encodeFirstPointFixedLength
}
f(e, v.pi, v.qi, level, piCoder, qiCoder)
}
var offCenter []int
for i, v := range vertices {
if v.level != level {
offCenter = append(offCenter, i)
}
}
e.writeUvarint(uint64(len(offCenter)))
for _, idx := range offCenter {
e.writeUvarint(uint64(idx))
e.writeFloat64(vertices[idx].xyz.X)
e.writeFloat64(vertices[idx].xyz.Y)
e.writeFloat64(vertices[idx].xyz.Z)
}
} | [
"func",
"encodePointsCompressed",
"(",
"e",
"*",
"encoder",
",",
"vertices",
"[",
"]",
"xyzFaceSiTi",
",",
"level",
"int",
")",
"{",
"var",
"faces",
"[",
"]",
"faceRun",
"\n",
"for",
"_",
",",
"v",
":=",
"range",
"vertices",
"{",
"faces",
"=",
"appendFace",
"(",
"faces",
",",
"v",
".",
"face",
")",
"\n",
"}",
"\n",
"encodeFaces",
"(",
"e",
",",
"faces",
")",
"\n\n",
"type",
"piQi",
"struct",
"{",
"pi",
",",
"qi",
"uint32",
"\n",
"}",
"\n",
"verticesPiQi",
":=",
"make",
"(",
"[",
"]",
"piQi",
",",
"len",
"(",
"vertices",
")",
")",
"\n",
"for",
"i",
",",
"v",
":=",
"range",
"vertices",
"{",
"verticesPiQi",
"[",
"i",
"]",
"=",
"piQi",
"{",
"siTitoPiQi",
"(",
"v",
".",
"si",
",",
"level",
")",
",",
"siTitoPiQi",
"(",
"v",
".",
"ti",
",",
"level",
")",
"}",
"\n",
"}",
"\n",
"piCoder",
",",
"qiCoder",
":=",
"newNthDerivativeCoder",
"(",
"derivativeEncodingOrder",
")",
",",
"newNthDerivativeCoder",
"(",
"derivativeEncodingOrder",
")",
"\n",
"for",
"i",
",",
"v",
":=",
"range",
"verticesPiQi",
"{",
"f",
":=",
"encodePointCompressed",
"\n",
"if",
"i",
"==",
"0",
"{",
"// The first point will be just the (pi, qi) coordinates",
"// of the Point. NthDerivativeCoder will not save anything",
"// in that case, so we encode in fixed format rather than varint",
"// to avoid the varint overhead.",
"f",
"=",
"encodeFirstPointFixedLength",
"\n",
"}",
"\n",
"f",
"(",
"e",
",",
"v",
".",
"pi",
",",
"v",
".",
"qi",
",",
"level",
",",
"piCoder",
",",
"qiCoder",
")",
"\n",
"}",
"\n\n",
"var",
"offCenter",
"[",
"]",
"int",
"\n",
"for",
"i",
",",
"v",
":=",
"range",
"vertices",
"{",
"if",
"v",
".",
"level",
"!=",
"level",
"{",
"offCenter",
"=",
"append",
"(",
"offCenter",
",",
"i",
")",
"\n",
"}",
"\n",
"}",
"\n",
"e",
".",
"writeUvarint",
"(",
"uint64",
"(",
"len",
"(",
"offCenter",
")",
")",
")",
"\n",
"for",
"_",
",",
"idx",
":=",
"range",
"offCenter",
"{",
"e",
".",
"writeUvarint",
"(",
"uint64",
"(",
"idx",
")",
")",
"\n",
"e",
".",
"writeFloat64",
"(",
"vertices",
"[",
"idx",
"]",
".",
"xyz",
".",
"X",
")",
"\n",
"e",
".",
"writeFloat64",
"(",
"vertices",
"[",
"idx",
"]",
".",
"xyz",
".",
"Y",
")",
"\n",
"e",
".",
"writeFloat64",
"(",
"vertices",
"[",
"idx",
"]",
".",
"xyz",
".",
"Z",
")",
"\n",
"}",
"\n",
"}"
] | // encodePointsCompressed uses an optimized compressed format to encode the given values. | [
"encodePointsCompressed",
"uses",
"an",
"optimized",
"compressed",
"format",
"to",
"encode",
"the",
"given",
"values",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/pointcompression.go#L50-L90 |
150,108 | golang/geo | s2/pointcompression.go | piQiToST | func piQiToST(pi uint32, level int) float64 {
// We want to recover the position at the center of the cell. If the point
// was snapped to the center of the cell, then math.Modf(s * 2^level) == 0.5.
// Inverting STtoPiQi gives:
// s = (pi + 0.5) / 2^level.
return (float64(pi) + 0.5) / float64(int(1)<<uint(level))
} | go | func piQiToST(pi uint32, level int) float64 {
// We want to recover the position at the center of the cell. If the point
// was snapped to the center of the cell, then math.Modf(s * 2^level) == 0.5.
// Inverting STtoPiQi gives:
// s = (pi + 0.5) / 2^level.
return (float64(pi) + 0.5) / float64(int(1)<<uint(level))
} | [
"func",
"piQiToST",
"(",
"pi",
"uint32",
",",
"level",
"int",
")",
"float64",
"{",
"// We want to recover the position at the center of the cell. If the point",
"// was snapped to the center of the cell, then math.Modf(s * 2^level) == 0.5.",
"// Inverting STtoPiQi gives:",
"// s = (pi + 0.5) / 2^level.",
"return",
"(",
"float64",
"(",
"pi",
")",
"+",
"0.5",
")",
"/",
"float64",
"(",
"int",
"(",
"1",
")",
"<<",
"uint",
"(",
"level",
")",
")",
"\n",
"}"
] | // piQiToST returns the value transformed to ST space. | [
"piQiToST",
"returns",
"the",
"value",
"transformed",
"to",
"ST",
"space",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/pointcompression.go#L309-L315 |
150,109 | golang/geo | s2/cellunion.go | CellUnionFromUnion | func CellUnionFromUnion(cellUnions ...CellUnion) CellUnion {
var cu CellUnion
for _, cellUnion := range cellUnions {
cu = append(cu, cellUnion...)
}
cu.Normalize()
return cu
} | go | func CellUnionFromUnion(cellUnions ...CellUnion) CellUnion {
var cu CellUnion
for _, cellUnion := range cellUnions {
cu = append(cu, cellUnion...)
}
cu.Normalize()
return cu
} | [
"func",
"CellUnionFromUnion",
"(",
"cellUnions",
"...",
"CellUnion",
")",
"CellUnion",
"{",
"var",
"cu",
"CellUnion",
"\n",
"for",
"_",
",",
"cellUnion",
":=",
"range",
"cellUnions",
"{",
"cu",
"=",
"append",
"(",
"cu",
",",
"cellUnion",
"...",
")",
"\n",
"}",
"\n",
"cu",
".",
"Normalize",
"(",
")",
"\n",
"return",
"cu",
"\n",
"}"
] | // CellUnionFromUnion creates a CellUnion from the union of the given CellUnions. | [
"CellUnionFromUnion",
"creates",
"a",
"CellUnion",
"from",
"the",
"union",
"of",
"the",
"given",
"CellUnions",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/cellunion.go#L51-L58 |
150,110 | golang/geo | s2/cellunion.go | CellUnionFromIntersection | func CellUnionFromIntersection(x, y CellUnion) CellUnion {
var cu CellUnion
// This is a fairly efficient calculation that uses binary search to skip
// over sections of both input vectors. It takes constant time if all the
// cells of x come before or after all the cells of y in CellID order.
var i, j int
for i < len(x) && j < len(y) {
iMin := x[i].RangeMin()
jMin := y[j].RangeMin()
if iMin > jMin {
// Either j.Contains(i) or the two cells are disjoint.
if x[i] <= y[j].RangeMax() {
cu = append(cu, x[i])
i++
} else {
// Advance j to the first cell possibly contained by x[i].
j = y.lowerBound(j+1, len(y), iMin)
// The previous cell y[j-1] may now contain x[i].
if x[i] <= y[j-1].RangeMax() {
j--
}
}
} else if jMin > iMin {
// Identical to the code above with i and j reversed.
if y[j] <= x[i].RangeMax() {
cu = append(cu, y[j])
j++
} else {
i = x.lowerBound(i+1, len(x), jMin)
if y[j] <= x[i-1].RangeMax() {
i--
}
}
} else {
// i and j have the same RangeMin(), so one contains the other.
if x[i] < y[j] {
cu = append(cu, x[i])
i++
} else {
cu = append(cu, y[j])
j++
}
}
}
// The output is generated in sorted order.
cu.Normalize()
return cu
} | go | func CellUnionFromIntersection(x, y CellUnion) CellUnion {
var cu CellUnion
// This is a fairly efficient calculation that uses binary search to skip
// over sections of both input vectors. It takes constant time if all the
// cells of x come before or after all the cells of y in CellID order.
var i, j int
for i < len(x) && j < len(y) {
iMin := x[i].RangeMin()
jMin := y[j].RangeMin()
if iMin > jMin {
// Either j.Contains(i) or the two cells are disjoint.
if x[i] <= y[j].RangeMax() {
cu = append(cu, x[i])
i++
} else {
// Advance j to the first cell possibly contained by x[i].
j = y.lowerBound(j+1, len(y), iMin)
// The previous cell y[j-1] may now contain x[i].
if x[i] <= y[j-1].RangeMax() {
j--
}
}
} else if jMin > iMin {
// Identical to the code above with i and j reversed.
if y[j] <= x[i].RangeMax() {
cu = append(cu, y[j])
j++
} else {
i = x.lowerBound(i+1, len(x), jMin)
if y[j] <= x[i-1].RangeMax() {
i--
}
}
} else {
// i and j have the same RangeMin(), so one contains the other.
if x[i] < y[j] {
cu = append(cu, x[i])
i++
} else {
cu = append(cu, y[j])
j++
}
}
}
// The output is generated in sorted order.
cu.Normalize()
return cu
} | [
"func",
"CellUnionFromIntersection",
"(",
"x",
",",
"y",
"CellUnion",
")",
"CellUnion",
"{",
"var",
"cu",
"CellUnion",
"\n\n",
"// This is a fairly efficient calculation that uses binary search to skip",
"// over sections of both input vectors. It takes constant time if all the",
"// cells of x come before or after all the cells of y in CellID order.",
"var",
"i",
",",
"j",
"int",
"\n",
"for",
"i",
"<",
"len",
"(",
"x",
")",
"&&",
"j",
"<",
"len",
"(",
"y",
")",
"{",
"iMin",
":=",
"x",
"[",
"i",
"]",
".",
"RangeMin",
"(",
")",
"\n",
"jMin",
":=",
"y",
"[",
"j",
"]",
".",
"RangeMin",
"(",
")",
"\n",
"if",
"iMin",
">",
"jMin",
"{",
"// Either j.Contains(i) or the two cells are disjoint.",
"if",
"x",
"[",
"i",
"]",
"<=",
"y",
"[",
"j",
"]",
".",
"RangeMax",
"(",
")",
"{",
"cu",
"=",
"append",
"(",
"cu",
",",
"x",
"[",
"i",
"]",
")",
"\n",
"i",
"++",
"\n",
"}",
"else",
"{",
"// Advance j to the first cell possibly contained by x[i].",
"j",
"=",
"y",
".",
"lowerBound",
"(",
"j",
"+",
"1",
",",
"len",
"(",
"y",
")",
",",
"iMin",
")",
"\n",
"// The previous cell y[j-1] may now contain x[i].",
"if",
"x",
"[",
"i",
"]",
"<=",
"y",
"[",
"j",
"-",
"1",
"]",
".",
"RangeMax",
"(",
")",
"{",
"j",
"--",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"else",
"if",
"jMin",
">",
"iMin",
"{",
"// Identical to the code above with i and j reversed.",
"if",
"y",
"[",
"j",
"]",
"<=",
"x",
"[",
"i",
"]",
".",
"RangeMax",
"(",
")",
"{",
"cu",
"=",
"append",
"(",
"cu",
",",
"y",
"[",
"j",
"]",
")",
"\n",
"j",
"++",
"\n",
"}",
"else",
"{",
"i",
"=",
"x",
".",
"lowerBound",
"(",
"i",
"+",
"1",
",",
"len",
"(",
"x",
")",
",",
"jMin",
")",
"\n",
"if",
"y",
"[",
"j",
"]",
"<=",
"x",
"[",
"i",
"-",
"1",
"]",
".",
"RangeMax",
"(",
")",
"{",
"i",
"--",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"else",
"{",
"// i and j have the same RangeMin(), so one contains the other.",
"if",
"x",
"[",
"i",
"]",
"<",
"y",
"[",
"j",
"]",
"{",
"cu",
"=",
"append",
"(",
"cu",
",",
"x",
"[",
"i",
"]",
")",
"\n",
"i",
"++",
"\n",
"}",
"else",
"{",
"cu",
"=",
"append",
"(",
"cu",
",",
"y",
"[",
"j",
"]",
")",
"\n",
"j",
"++",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"// The output is generated in sorted order.",
"cu",
".",
"Normalize",
"(",
")",
"\n",
"return",
"cu",
"\n",
"}"
] | // CellUnionFromIntersection creates a CellUnion from the intersection of the given CellUnions. | [
"CellUnionFromIntersection",
"creates",
"a",
"CellUnion",
"from",
"the",
"intersection",
"of",
"the",
"given",
"CellUnions",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/cellunion.go#L61-L110 |
150,111 | golang/geo | s2/cellunion.go | CellUnionFromIntersectionWithCellID | func CellUnionFromIntersectionWithCellID(x CellUnion, id CellID) CellUnion {
var cu CellUnion
if x.ContainsCellID(id) {
cu = append(cu, id)
cu.Normalize()
return cu
}
idmax := id.RangeMax()
for i := x.lowerBound(0, len(x), id.RangeMin()); i < len(x) && x[i] <= idmax; i++ {
cu = append(cu, x[i])
}
cu.Normalize()
return cu
} | go | func CellUnionFromIntersectionWithCellID(x CellUnion, id CellID) CellUnion {
var cu CellUnion
if x.ContainsCellID(id) {
cu = append(cu, id)
cu.Normalize()
return cu
}
idmax := id.RangeMax()
for i := x.lowerBound(0, len(x), id.RangeMin()); i < len(x) && x[i] <= idmax; i++ {
cu = append(cu, x[i])
}
cu.Normalize()
return cu
} | [
"func",
"CellUnionFromIntersectionWithCellID",
"(",
"x",
"CellUnion",
",",
"id",
"CellID",
")",
"CellUnion",
"{",
"var",
"cu",
"CellUnion",
"\n",
"if",
"x",
".",
"ContainsCellID",
"(",
"id",
")",
"{",
"cu",
"=",
"append",
"(",
"cu",
",",
"id",
")",
"\n",
"cu",
".",
"Normalize",
"(",
")",
"\n",
"return",
"cu",
"\n",
"}",
"\n\n",
"idmax",
":=",
"id",
".",
"RangeMax",
"(",
")",
"\n",
"for",
"i",
":=",
"x",
".",
"lowerBound",
"(",
"0",
",",
"len",
"(",
"x",
")",
",",
"id",
".",
"RangeMin",
"(",
")",
")",
";",
"i",
"<",
"len",
"(",
"x",
")",
"&&",
"x",
"[",
"i",
"]",
"<=",
"idmax",
";",
"i",
"++",
"{",
"cu",
"=",
"append",
"(",
"cu",
",",
"x",
"[",
"i",
"]",
")",
"\n",
"}",
"\n\n",
"cu",
".",
"Normalize",
"(",
")",
"\n",
"return",
"cu",
"\n",
"}"
] | // CellUnionFromIntersectionWithCellID creates a CellUnion from the intersection
// of a CellUnion with the given CellID. This can be useful for splitting a
// CellUnion into chunks. | [
"CellUnionFromIntersectionWithCellID",
"creates",
"a",
"CellUnion",
"from",
"the",
"intersection",
"of",
"a",
"CellUnion",
"with",
"the",
"given",
"CellID",
".",
"This",
"can",
"be",
"useful",
"for",
"splitting",
"a",
"CellUnion",
"into",
"chunks",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/cellunion.go#L115-L130 |
150,112 | golang/geo | s2/cellunion.go | IsValid | func (cu *CellUnion) IsValid() bool {
for i, cid := range *cu {
if !cid.IsValid() {
return false
}
if i == 0 {
continue
}
if (*cu)[i-1].RangeMax() >= cid.RangeMin() {
return false
}
}
return true
} | go | func (cu *CellUnion) IsValid() bool {
for i, cid := range *cu {
if !cid.IsValid() {
return false
}
if i == 0 {
continue
}
if (*cu)[i-1].RangeMax() >= cid.RangeMin() {
return false
}
}
return true
} | [
"func",
"(",
"cu",
"*",
"CellUnion",
")",
"IsValid",
"(",
")",
"bool",
"{",
"for",
"i",
",",
"cid",
":=",
"range",
"*",
"cu",
"{",
"if",
"!",
"cid",
".",
"IsValid",
"(",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"i",
"==",
"0",
"{",
"continue",
"\n",
"}",
"\n",
"if",
"(",
"*",
"cu",
")",
"[",
"i",
"-",
"1",
"]",
".",
"RangeMax",
"(",
")",
">=",
"cid",
".",
"RangeMin",
"(",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}"
] | // The C++ constructor methods FromNormalized and FromVerbatim are not necessary
// since they don't call Normalize, and just set the CellIDs directly on the object,
// so straight casting is sufficient in Go to replicate this behavior.
// IsValid reports whether the cell union is valid, meaning that the CellIDs are
// valid, non-overlapping, and sorted in increasing order. | [
"The",
"C",
"++",
"constructor",
"methods",
"FromNormalized",
"and",
"FromVerbatim",
"are",
"not",
"necessary",
"since",
"they",
"don",
"t",
"call",
"Normalize",
"and",
"just",
"set",
"the",
"CellIDs",
"directly",
"on",
"the",
"object",
"so",
"straight",
"casting",
"is",
"sufficient",
"in",
"Go",
"to",
"replicate",
"this",
"behavior",
".",
"IsValid",
"reports",
"whether",
"the",
"cell",
"union",
"is",
"valid",
"meaning",
"that",
"the",
"CellIDs",
"are",
"valid",
"non",
"-",
"overlapping",
"and",
"sorted",
"in",
"increasing",
"order",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/cellunion.go#L154-L167 |
150,113 | golang/geo | s2/cellunion.go | IsNormalized | func (cu *CellUnion) IsNormalized() bool {
for i, cid := range *cu {
if !cid.IsValid() {
return false
}
if i == 0 {
continue
}
if (*cu)[i-1].RangeMax() >= cid.RangeMin() {
return false
}
if i < 3 {
continue
}
if areSiblings((*cu)[i-3], (*cu)[i-2], (*cu)[i-1], cid) {
return false
}
}
return true
} | go | func (cu *CellUnion) IsNormalized() bool {
for i, cid := range *cu {
if !cid.IsValid() {
return false
}
if i == 0 {
continue
}
if (*cu)[i-1].RangeMax() >= cid.RangeMin() {
return false
}
if i < 3 {
continue
}
if areSiblings((*cu)[i-3], (*cu)[i-2], (*cu)[i-1], cid) {
return false
}
}
return true
} | [
"func",
"(",
"cu",
"*",
"CellUnion",
")",
"IsNormalized",
"(",
")",
"bool",
"{",
"for",
"i",
",",
"cid",
":=",
"range",
"*",
"cu",
"{",
"if",
"!",
"cid",
".",
"IsValid",
"(",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"i",
"==",
"0",
"{",
"continue",
"\n",
"}",
"\n",
"if",
"(",
"*",
"cu",
")",
"[",
"i",
"-",
"1",
"]",
".",
"RangeMax",
"(",
")",
">=",
"cid",
".",
"RangeMin",
"(",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"i",
"<",
"3",
"{",
"continue",
"\n",
"}",
"\n",
"if",
"areSiblings",
"(",
"(",
"*",
"cu",
")",
"[",
"i",
"-",
"3",
"]",
",",
"(",
"*",
"cu",
")",
"[",
"i",
"-",
"2",
"]",
",",
"(",
"*",
"cu",
")",
"[",
"i",
"-",
"1",
"]",
",",
"cid",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}"
] | // IsNormalized reports whether the cell union is normalized, meaning that it is
// satisfies IsValid and that no four cells have a common parent.
// Certain operations such as Contains will return a different
// result if the cell union is not normalized. | [
"IsNormalized",
"reports",
"whether",
"the",
"cell",
"union",
"is",
"normalized",
"meaning",
"that",
"it",
"is",
"satisfies",
"IsValid",
"and",
"that",
"no",
"four",
"cells",
"have",
"a",
"common",
"parent",
".",
"Certain",
"operations",
"such",
"as",
"Contains",
"will",
"return",
"a",
"different",
"result",
"if",
"the",
"cell",
"union",
"is",
"not",
"normalized",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/cellunion.go#L173-L192 |
150,114 | golang/geo | s2/cellunion.go | IntersectsCellID | func (cu *CellUnion) IntersectsCellID(id CellID) bool {
// Find index of array item that occurs directly after our probe cell:
i := sort.Search(len(*cu), func(i int) bool { return id < (*cu)[i] })
if i != len(*cu) && (*cu)[i].RangeMin() <= id.RangeMax() {
return true
}
return i != 0 && (*cu)[i-1].RangeMax() >= id.RangeMin()
} | go | func (cu *CellUnion) IntersectsCellID(id CellID) bool {
// Find index of array item that occurs directly after our probe cell:
i := sort.Search(len(*cu), func(i int) bool { return id < (*cu)[i] })
if i != len(*cu) && (*cu)[i].RangeMin() <= id.RangeMax() {
return true
}
return i != 0 && (*cu)[i-1].RangeMax() >= id.RangeMin()
} | [
"func",
"(",
"cu",
"*",
"CellUnion",
")",
"IntersectsCellID",
"(",
"id",
"CellID",
")",
"bool",
"{",
"// Find index of array item that occurs directly after our probe cell:",
"i",
":=",
"sort",
".",
"Search",
"(",
"len",
"(",
"*",
"cu",
")",
",",
"func",
"(",
"i",
"int",
")",
"bool",
"{",
"return",
"id",
"<",
"(",
"*",
"cu",
")",
"[",
"i",
"]",
"}",
")",
"\n\n",
"if",
"i",
"!=",
"len",
"(",
"*",
"cu",
")",
"&&",
"(",
"*",
"cu",
")",
"[",
"i",
"]",
".",
"RangeMin",
"(",
")",
"<=",
"id",
".",
"RangeMax",
"(",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"return",
"i",
"!=",
"0",
"&&",
"(",
"*",
"cu",
")",
"[",
"i",
"-",
"1",
"]",
".",
"RangeMax",
"(",
")",
">=",
"id",
".",
"RangeMin",
"(",
")",
"\n",
"}"
] | // IntersectsCellID reports whether this CellUnion intersects the given cell ID. | [
"IntersectsCellID",
"reports",
"whether",
"this",
"CellUnion",
"intersects",
"the",
"given",
"cell",
"ID",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/cellunion.go#L240-L248 |
150,115 | golang/geo | s2/cellunion.go | RectBound | func (cu *CellUnion) RectBound() Rect {
bound := EmptyRect()
for _, c := range *cu {
bound = bound.Union(CellFromCellID(c).RectBound())
}
return bound
} | go | func (cu *CellUnion) RectBound() Rect {
bound := EmptyRect()
for _, c := range *cu {
bound = bound.Union(CellFromCellID(c).RectBound())
}
return bound
} | [
"func",
"(",
"cu",
"*",
"CellUnion",
")",
"RectBound",
"(",
")",
"Rect",
"{",
"bound",
":=",
"EmptyRect",
"(",
")",
"\n",
"for",
"_",
",",
"c",
":=",
"range",
"*",
"cu",
"{",
"bound",
"=",
"bound",
".",
"Union",
"(",
"CellFromCellID",
"(",
"c",
")",
".",
"RectBound",
"(",
")",
")",
"\n",
"}",
"\n",
"return",
"bound",
"\n",
"}"
] | // RectBound returns a Rect that bounds this entity. | [
"RectBound",
"returns",
"a",
"Rect",
"that",
"bounds",
"this",
"entity",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/cellunion.go#L298-L304 |
150,116 | golang/geo | s2/cellunion.go | CapBound | func (cu *CellUnion) CapBound() Cap {
if len(*cu) == 0 {
return EmptyCap()
}
// Compute the approximate centroid of the region. This won't produce the
// bounding cap of minimal area, but it should be close enough.
var centroid Point
for _, ci := range *cu {
area := AvgAreaMetric.Value(ci.Level())
centroid = Point{centroid.Add(ci.Point().Mul(area))}
}
if zero := (Point{}); centroid == zero {
centroid = PointFromCoords(1, 0, 0)
} else {
centroid = Point{centroid.Normalize()}
}
// Use the centroid as the cap axis, and expand the cap angle so that it
// contains the bounding caps of all the individual cells. Note that it is
// *not* sufficient to just bound all the cell vertices because the bounding
// cap may be concave (i.e. cover more than one hemisphere).
c := CapFromPoint(centroid)
for _, ci := range *cu {
c = c.AddCap(CellFromCellID(ci).CapBound())
}
return c
} | go | func (cu *CellUnion) CapBound() Cap {
if len(*cu) == 0 {
return EmptyCap()
}
// Compute the approximate centroid of the region. This won't produce the
// bounding cap of minimal area, but it should be close enough.
var centroid Point
for _, ci := range *cu {
area := AvgAreaMetric.Value(ci.Level())
centroid = Point{centroid.Add(ci.Point().Mul(area))}
}
if zero := (Point{}); centroid == zero {
centroid = PointFromCoords(1, 0, 0)
} else {
centroid = Point{centroid.Normalize()}
}
// Use the centroid as the cap axis, and expand the cap angle so that it
// contains the bounding caps of all the individual cells. Note that it is
// *not* sufficient to just bound all the cell vertices because the bounding
// cap may be concave (i.e. cover more than one hemisphere).
c := CapFromPoint(centroid)
for _, ci := range *cu {
c = c.AddCap(CellFromCellID(ci).CapBound())
}
return c
} | [
"func",
"(",
"cu",
"*",
"CellUnion",
")",
"CapBound",
"(",
")",
"Cap",
"{",
"if",
"len",
"(",
"*",
"cu",
")",
"==",
"0",
"{",
"return",
"EmptyCap",
"(",
")",
"\n",
"}",
"\n\n",
"// Compute the approximate centroid of the region. This won't produce the",
"// bounding cap of minimal area, but it should be close enough.",
"var",
"centroid",
"Point",
"\n\n",
"for",
"_",
",",
"ci",
":=",
"range",
"*",
"cu",
"{",
"area",
":=",
"AvgAreaMetric",
".",
"Value",
"(",
"ci",
".",
"Level",
"(",
")",
")",
"\n",
"centroid",
"=",
"Point",
"{",
"centroid",
".",
"Add",
"(",
"ci",
".",
"Point",
"(",
")",
".",
"Mul",
"(",
"area",
")",
")",
"}",
"\n",
"}",
"\n\n",
"if",
"zero",
":=",
"(",
"Point",
"{",
"}",
")",
";",
"centroid",
"==",
"zero",
"{",
"centroid",
"=",
"PointFromCoords",
"(",
"1",
",",
"0",
",",
"0",
")",
"\n",
"}",
"else",
"{",
"centroid",
"=",
"Point",
"{",
"centroid",
".",
"Normalize",
"(",
")",
"}",
"\n",
"}",
"\n\n",
"// Use the centroid as the cap axis, and expand the cap angle so that it",
"// contains the bounding caps of all the individual cells. Note that it is",
"// *not* sufficient to just bound all the cell vertices because the bounding",
"// cap may be concave (i.e. cover more than one hemisphere).",
"c",
":=",
"CapFromPoint",
"(",
"centroid",
")",
"\n",
"for",
"_",
",",
"ci",
":=",
"range",
"*",
"cu",
"{",
"c",
"=",
"c",
".",
"AddCap",
"(",
"CellFromCellID",
"(",
"ci",
")",
".",
"CapBound",
"(",
")",
")",
"\n",
"}",
"\n\n",
"return",
"c",
"\n",
"}"
] | // CapBound returns a Cap that bounds this entity. | [
"CapBound",
"returns",
"a",
"Cap",
"that",
"bounds",
"this",
"entity",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/cellunion.go#L307-L337 |
150,117 | golang/geo | s2/cellunion.go | ContainsCell | func (cu *CellUnion) ContainsCell(c Cell) bool {
return cu.ContainsCellID(c.id)
} | go | func (cu *CellUnion) ContainsCell(c Cell) bool {
return cu.ContainsCellID(c.id)
} | [
"func",
"(",
"cu",
"*",
"CellUnion",
")",
"ContainsCell",
"(",
"c",
"Cell",
")",
"bool",
"{",
"return",
"cu",
".",
"ContainsCellID",
"(",
"c",
".",
"id",
")",
"\n",
"}"
] | // ContainsCell reports whether this cell union contains the given cell. | [
"ContainsCell",
"reports",
"whether",
"this",
"cell",
"union",
"contains",
"the",
"given",
"cell",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/cellunion.go#L340-L342 |
150,118 | golang/geo | s2/cellunion.go | IntersectsCell | func (cu *CellUnion) IntersectsCell(c Cell) bool {
return cu.IntersectsCellID(c.id)
} | go | func (cu *CellUnion) IntersectsCell(c Cell) bool {
return cu.IntersectsCellID(c.id)
} | [
"func",
"(",
"cu",
"*",
"CellUnion",
")",
"IntersectsCell",
"(",
"c",
"Cell",
")",
"bool",
"{",
"return",
"cu",
".",
"IntersectsCellID",
"(",
"c",
".",
"id",
")",
"\n",
"}"
] | // IntersectsCell reports whether this cell union intersects the given cell. | [
"IntersectsCell",
"reports",
"whether",
"this",
"cell",
"union",
"intersects",
"the",
"given",
"cell",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/cellunion.go#L345-L347 |
150,119 | golang/geo | s2/cellunion.go | ContainsPoint | func (cu *CellUnion) ContainsPoint(p Point) bool {
return cu.ContainsCell(CellFromPoint(p))
} | go | func (cu *CellUnion) ContainsPoint(p Point) bool {
return cu.ContainsCell(CellFromPoint(p))
} | [
"func",
"(",
"cu",
"*",
"CellUnion",
")",
"ContainsPoint",
"(",
"p",
"Point",
")",
"bool",
"{",
"return",
"cu",
".",
"ContainsCell",
"(",
"CellFromPoint",
"(",
"p",
")",
")",
"\n",
"}"
] | // ContainsPoint reports whether this cell union contains the given point. | [
"ContainsPoint",
"reports",
"whether",
"this",
"cell",
"union",
"contains",
"the",
"given",
"point",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/cellunion.go#L350-L352 |
150,120 | golang/geo | s2/cellunion.go | areSiblings | func areSiblings(a, b, c, d CellID) bool {
// A necessary (but not sufficient) condition is that the XOR of the
// four cell IDs must be zero. This is also very fast to test.
if (a ^ b ^ c) != d {
return false
}
// Now we do a slightly more expensive but exact test. First, compute a
// mask that blocks out the two bits that encode the child position of
// "id" with respect to its parent, then check that the other three
// children all agree with "mask".
mask := uint64(d.lsb() << 1)
mask = ^(mask + (mask << 1))
idMasked := (uint64(d) & mask)
return ((uint64(a)&mask) == idMasked &&
(uint64(b)&mask) == idMasked &&
(uint64(c)&mask) == idMasked &&
!d.isFace())
} | go | func areSiblings(a, b, c, d CellID) bool {
// A necessary (but not sufficient) condition is that the XOR of the
// four cell IDs must be zero. This is also very fast to test.
if (a ^ b ^ c) != d {
return false
}
// Now we do a slightly more expensive but exact test. First, compute a
// mask that blocks out the two bits that encode the child position of
// "id" with respect to its parent, then check that the other three
// children all agree with "mask".
mask := uint64(d.lsb() << 1)
mask = ^(mask + (mask << 1))
idMasked := (uint64(d) & mask)
return ((uint64(a)&mask) == idMasked &&
(uint64(b)&mask) == idMasked &&
(uint64(c)&mask) == idMasked &&
!d.isFace())
} | [
"func",
"areSiblings",
"(",
"a",
",",
"b",
",",
"c",
",",
"d",
"CellID",
")",
"bool",
"{",
"// A necessary (but not sufficient) condition is that the XOR of the",
"// four cell IDs must be zero. This is also very fast to test.",
"if",
"(",
"a",
"^",
"b",
"^",
"c",
")",
"!=",
"d",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"// Now we do a slightly more expensive but exact test. First, compute a",
"// mask that blocks out the two bits that encode the child position of",
"// \"id\" with respect to its parent, then check that the other three",
"// children all agree with \"mask\".",
"mask",
":=",
"uint64",
"(",
"d",
".",
"lsb",
"(",
")",
"<<",
"1",
")",
"\n",
"mask",
"=",
"^",
"(",
"mask",
"+",
"(",
"mask",
"<<",
"1",
")",
")",
"\n",
"idMasked",
":=",
"(",
"uint64",
"(",
"d",
")",
"&",
"mask",
")",
"\n",
"return",
"(",
"(",
"uint64",
"(",
"a",
")",
"&",
"mask",
")",
"==",
"idMasked",
"&&",
"(",
"uint64",
"(",
"b",
")",
"&",
"mask",
")",
"==",
"idMasked",
"&&",
"(",
"uint64",
"(",
"c",
")",
"&",
"mask",
")",
"==",
"idMasked",
"&&",
"!",
"d",
".",
"isFace",
"(",
")",
")",
"\n",
"}"
] | // Returns true if the given four cells have a common parent.
// This requires that the four CellIDs are distinct. | [
"Returns",
"true",
"if",
"the",
"given",
"four",
"cells",
"have",
"a",
"common",
"parent",
".",
"This",
"requires",
"that",
"the",
"four",
"CellIDs",
"are",
"distinct",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/cellunion.go#L371-L389 |
150,121 | golang/geo | s2/cellunion.go | Contains | func (cu *CellUnion) Contains(o CellUnion) bool {
// TODO(roberts): Investigate alternatives such as divide-and-conquer
// or alternating-skip-search that may be significantly faster in both
// the average and worst case. This applies to Intersects as well.
for _, id := range o {
if !cu.ContainsCellID(id) {
return false
}
}
return true
} | go | func (cu *CellUnion) Contains(o CellUnion) bool {
// TODO(roberts): Investigate alternatives such as divide-and-conquer
// or alternating-skip-search that may be significantly faster in both
// the average and worst case. This applies to Intersects as well.
for _, id := range o {
if !cu.ContainsCellID(id) {
return false
}
}
return true
} | [
"func",
"(",
"cu",
"*",
"CellUnion",
")",
"Contains",
"(",
"o",
"CellUnion",
")",
"bool",
"{",
"// TODO(roberts): Investigate alternatives such as divide-and-conquer",
"// or alternating-skip-search that may be significantly faster in both",
"// the average and worst case. This applies to Intersects as well.",
"for",
"_",
",",
"id",
":=",
"range",
"o",
"{",
"if",
"!",
"cu",
".",
"ContainsCellID",
"(",
"id",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"true",
"\n",
"}"
] | // Contains reports whether this CellUnion contains all of the CellIDs of the given CellUnion. | [
"Contains",
"reports",
"whether",
"this",
"CellUnion",
"contains",
"all",
"of",
"the",
"CellIDs",
"of",
"the",
"given",
"CellUnion",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/cellunion.go#L392-L403 |
150,122 | golang/geo | s2/cellunion.go | Intersects | func (cu *CellUnion) Intersects(o CellUnion) bool {
for _, c := range *cu {
if o.IntersectsCellID(c) {
return true
}
}
return false
} | go | func (cu *CellUnion) Intersects(o CellUnion) bool {
for _, c := range *cu {
if o.IntersectsCellID(c) {
return true
}
}
return false
} | [
"func",
"(",
"cu",
"*",
"CellUnion",
")",
"Intersects",
"(",
"o",
"CellUnion",
")",
"bool",
"{",
"for",
"_",
",",
"c",
":=",
"range",
"*",
"cu",
"{",
"if",
"o",
".",
"IntersectsCellID",
"(",
"c",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"false",
"\n",
"}"
] | // Intersects reports whether this CellUnion intersects any of the CellIDs of the given CellUnion. | [
"Intersects",
"reports",
"whether",
"this",
"CellUnion",
"intersects",
"any",
"of",
"the",
"CellIDs",
"of",
"the",
"given",
"CellUnion",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/cellunion.go#L406-L414 |
150,123 | golang/geo | s2/cellunion.go | cellUnionDifferenceInternal | func (cu *CellUnion) cellUnionDifferenceInternal(id CellID, other *CellUnion) {
if !other.IntersectsCellID(id) {
(*cu) = append((*cu), id)
return
}
if !other.ContainsCellID(id) {
for _, child := range id.Children() {
cu.cellUnionDifferenceInternal(child, other)
}
}
} | go | func (cu *CellUnion) cellUnionDifferenceInternal(id CellID, other *CellUnion) {
if !other.IntersectsCellID(id) {
(*cu) = append((*cu), id)
return
}
if !other.ContainsCellID(id) {
for _, child := range id.Children() {
cu.cellUnionDifferenceInternal(child, other)
}
}
} | [
"func",
"(",
"cu",
"*",
"CellUnion",
")",
"cellUnionDifferenceInternal",
"(",
"id",
"CellID",
",",
"other",
"*",
"CellUnion",
")",
"{",
"if",
"!",
"other",
".",
"IntersectsCellID",
"(",
"id",
")",
"{",
"(",
"*",
"cu",
")",
"=",
"append",
"(",
"(",
"*",
"cu",
")",
",",
"id",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"if",
"!",
"other",
".",
"ContainsCellID",
"(",
"id",
")",
"{",
"for",
"_",
",",
"child",
":=",
"range",
"id",
".",
"Children",
"(",
")",
"{",
"cu",
".",
"cellUnionDifferenceInternal",
"(",
"child",
",",
"other",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // cellUnionDifferenceInternal adds the difference between the CellID and the union to
// the result CellUnion. If they intersect but the difference is non-empty, it divides
// and conquers. | [
"cellUnionDifferenceInternal",
"adds",
"the",
"difference",
"between",
"the",
"CellID",
"and",
"the",
"union",
"to",
"the",
"result",
"CellUnion",
".",
"If",
"they",
"intersect",
"but",
"the",
"difference",
"is",
"non",
"-",
"empty",
"it",
"divides",
"and",
"conquers",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/cellunion.go#L432-L443 |
150,124 | golang/geo | s2/cellunion.go | Equal | func (cu CellUnion) Equal(o CellUnion) bool {
if len(cu) != len(o) {
return false
}
for i := 0; i < len(cu); i++ {
if cu[i] != o[i] {
return false
}
}
return true
} | go | func (cu CellUnion) Equal(o CellUnion) bool {
if len(cu) != len(o) {
return false
}
for i := 0; i < len(cu); i++ {
if cu[i] != o[i] {
return false
}
}
return true
} | [
"func",
"(",
"cu",
"CellUnion",
")",
"Equal",
"(",
"o",
"CellUnion",
")",
"bool",
"{",
"if",
"len",
"(",
"cu",
")",
"!=",
"len",
"(",
"o",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"len",
"(",
"cu",
")",
";",
"i",
"++",
"{",
"if",
"cu",
"[",
"i",
"]",
"!=",
"o",
"[",
"i",
"]",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}"
] | // Equal reports whether the two CellUnions are equal. | [
"Equal",
"reports",
"whether",
"the",
"two",
"CellUnions",
"are",
"equal",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/cellunion.go#L508-L518 |
150,125 | golang/geo | s2/cellunion.go | AverageArea | func (cu *CellUnion) AverageArea() float64 {
return AvgAreaMetric.Value(maxLevel) * float64(cu.LeafCellsCovered())
} | go | func (cu *CellUnion) AverageArea() float64 {
return AvgAreaMetric.Value(maxLevel) * float64(cu.LeafCellsCovered())
} | [
"func",
"(",
"cu",
"*",
"CellUnion",
")",
"AverageArea",
"(",
")",
"float64",
"{",
"return",
"AvgAreaMetric",
".",
"Value",
"(",
"maxLevel",
")",
"*",
"float64",
"(",
"cu",
".",
"LeafCellsCovered",
"(",
")",
")",
"\n",
"}"
] | // AverageArea returns the average area of this CellUnion.
// This is accurate to within a factor of 1.7. | [
"AverageArea",
"returns",
"the",
"average",
"area",
"of",
"this",
"CellUnion",
".",
"This",
"is",
"accurate",
"to",
"within",
"a",
"factor",
"of",
"1",
".",
"7",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/cellunion.go#L522-L524 |
150,126 | golang/geo | s2/cellunion.go | ApproxArea | func (cu *CellUnion) ApproxArea() float64 {
var area float64
for _, id := range *cu {
area += CellFromCellID(id).ApproxArea()
}
return area
} | go | func (cu *CellUnion) ApproxArea() float64 {
var area float64
for _, id := range *cu {
area += CellFromCellID(id).ApproxArea()
}
return area
} | [
"func",
"(",
"cu",
"*",
"CellUnion",
")",
"ApproxArea",
"(",
")",
"float64",
"{",
"var",
"area",
"float64",
"\n",
"for",
"_",
",",
"id",
":=",
"range",
"*",
"cu",
"{",
"area",
"+=",
"CellFromCellID",
"(",
"id",
")",
".",
"ApproxArea",
"(",
")",
"\n",
"}",
"\n",
"return",
"area",
"\n",
"}"
] | // ApproxArea returns the approximate area of this CellUnion. This method is accurate
// to within 3% percent for all cell sizes and accurate to within 0.1% for cells
// at level 5 or higher within the union. | [
"ApproxArea",
"returns",
"the",
"approximate",
"area",
"of",
"this",
"CellUnion",
".",
"This",
"method",
"is",
"accurate",
"to",
"within",
"3%",
"percent",
"for",
"all",
"cell",
"sizes",
"and",
"accurate",
"to",
"within",
"0",
".",
"1%",
"for",
"cells",
"at",
"level",
"5",
"or",
"higher",
"within",
"the",
"union",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/cellunion.go#L529-L535 |
150,127 | golang/geo | s2/cellunion.go | ExactArea | func (cu *CellUnion) ExactArea() float64 {
var area float64
for _, id := range *cu {
area += CellFromCellID(id).ExactArea()
}
return area
} | go | func (cu *CellUnion) ExactArea() float64 {
var area float64
for _, id := range *cu {
area += CellFromCellID(id).ExactArea()
}
return area
} | [
"func",
"(",
"cu",
"*",
"CellUnion",
")",
"ExactArea",
"(",
")",
"float64",
"{",
"var",
"area",
"float64",
"\n",
"for",
"_",
",",
"id",
":=",
"range",
"*",
"cu",
"{",
"area",
"+=",
"CellFromCellID",
"(",
"id",
")",
".",
"ExactArea",
"(",
")",
"\n",
"}",
"\n",
"return",
"area",
"\n",
"}"
] | // ExactArea returns the area of this CellUnion as accurately as possible. | [
"ExactArea",
"returns",
"the",
"area",
"of",
"this",
"CellUnion",
"as",
"accurately",
"as",
"possible",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/cellunion.go#L538-L544 |
150,128 | golang/geo | s2/cellunion.go | Encode | func (cu *CellUnion) Encode(w io.Writer) error {
e := &encoder{w: w}
cu.encode(e)
return e.err
} | go | func (cu *CellUnion) Encode(w io.Writer) error {
e := &encoder{w: w}
cu.encode(e)
return e.err
} | [
"func",
"(",
"cu",
"*",
"CellUnion",
")",
"Encode",
"(",
"w",
"io",
".",
"Writer",
")",
"error",
"{",
"e",
":=",
"&",
"encoder",
"{",
"w",
":",
"w",
"}",
"\n",
"cu",
".",
"encode",
"(",
"e",
")",
"\n",
"return",
"e",
".",
"err",
"\n",
"}"
] | // Encode encodes the CellUnion. | [
"Encode",
"encodes",
"the",
"CellUnion",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/cellunion.go#L547-L551 |
150,129 | golang/geo | s2/cellunion.go | Decode | func (cu *CellUnion) Decode(r io.Reader) error {
d := &decoder{r: asByteReader(r)}
cu.decode(d)
return d.err
} | go | func (cu *CellUnion) Decode(r io.Reader) error {
d := &decoder{r: asByteReader(r)}
cu.decode(d)
return d.err
} | [
"func",
"(",
"cu",
"*",
"CellUnion",
")",
"Decode",
"(",
"r",
"io",
".",
"Reader",
")",
"error",
"{",
"d",
":=",
"&",
"decoder",
"{",
"r",
":",
"asByteReader",
"(",
"r",
")",
"}",
"\n",
"cu",
".",
"decode",
"(",
"d",
")",
"\n",
"return",
"d",
".",
"err",
"\n",
"}"
] | // Decode decodes the CellUnion. | [
"Decode",
"decodes",
"the",
"CellUnion",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/cellunion.go#L562-L566 |
150,130 | golang/geo | s2/cell.go | CellFromCellID | func CellFromCellID(id CellID) Cell {
c := Cell{}
c.id = id
f, i, j, o := c.id.faceIJOrientation()
c.face = int8(f)
c.level = int8(c.id.Level())
c.orientation = int8(o)
c.uv = ijLevelToBoundUV(i, j, int(c.level))
return c
} | go | func CellFromCellID(id CellID) Cell {
c := Cell{}
c.id = id
f, i, j, o := c.id.faceIJOrientation()
c.face = int8(f)
c.level = int8(c.id.Level())
c.orientation = int8(o)
c.uv = ijLevelToBoundUV(i, j, int(c.level))
return c
} | [
"func",
"CellFromCellID",
"(",
"id",
"CellID",
")",
"Cell",
"{",
"c",
":=",
"Cell",
"{",
"}",
"\n",
"c",
".",
"id",
"=",
"id",
"\n",
"f",
",",
"i",
",",
"j",
",",
"o",
":=",
"c",
".",
"id",
".",
"faceIJOrientation",
"(",
")",
"\n",
"c",
".",
"face",
"=",
"int8",
"(",
"f",
")",
"\n",
"c",
".",
"level",
"=",
"int8",
"(",
"c",
".",
"id",
".",
"Level",
"(",
")",
")",
"\n",
"c",
".",
"orientation",
"=",
"int8",
"(",
"o",
")",
"\n",
"c",
".",
"uv",
"=",
"ijLevelToBoundUV",
"(",
"i",
",",
"j",
",",
"int",
"(",
"c",
".",
"level",
")",
")",
"\n",
"return",
"c",
"\n",
"}"
] | // CellFromCellID constructs a Cell corresponding to the given CellID. | [
"CellFromCellID",
"constructs",
"a",
"Cell",
"corresponding",
"to",
"the",
"given",
"CellID",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/cell.go#L39-L48 |
150,131 | golang/geo | s2/cell.go | Children | func (c Cell) Children() ([4]Cell, bool) {
var children [4]Cell
if c.id.IsLeaf() {
return children, false
}
// Compute the cell midpoint in uv-space.
uvMid := c.id.centerUV()
// Create four children with the appropriate bounds.
cid := c.id.ChildBegin()
for pos := 0; pos < 4; pos++ {
children[pos] = Cell{
face: c.face,
level: c.level + 1,
orientation: c.orientation ^ int8(posToOrientation[pos]),
id: cid,
}
// We want to split the cell in half in u and v. To decide which
// side to set equal to the midpoint value, we look at cell's (i,j)
// position within its parent. The index for i is in bit 1 of ij.
ij := posToIJ[c.orientation][pos]
i := ij >> 1
j := ij & 1
if i == 1 {
children[pos].uv.X.Hi = c.uv.X.Hi
children[pos].uv.X.Lo = uvMid.X
} else {
children[pos].uv.X.Lo = c.uv.X.Lo
children[pos].uv.X.Hi = uvMid.X
}
if j == 1 {
children[pos].uv.Y.Hi = c.uv.Y.Hi
children[pos].uv.Y.Lo = uvMid.Y
} else {
children[pos].uv.Y.Lo = c.uv.Y.Lo
children[pos].uv.Y.Hi = uvMid.Y
}
cid = cid.Next()
}
return children, true
} | go | func (c Cell) Children() ([4]Cell, bool) {
var children [4]Cell
if c.id.IsLeaf() {
return children, false
}
// Compute the cell midpoint in uv-space.
uvMid := c.id.centerUV()
// Create four children with the appropriate bounds.
cid := c.id.ChildBegin()
for pos := 0; pos < 4; pos++ {
children[pos] = Cell{
face: c.face,
level: c.level + 1,
orientation: c.orientation ^ int8(posToOrientation[pos]),
id: cid,
}
// We want to split the cell in half in u and v. To decide which
// side to set equal to the midpoint value, we look at cell's (i,j)
// position within its parent. The index for i is in bit 1 of ij.
ij := posToIJ[c.orientation][pos]
i := ij >> 1
j := ij & 1
if i == 1 {
children[pos].uv.X.Hi = c.uv.X.Hi
children[pos].uv.X.Lo = uvMid.X
} else {
children[pos].uv.X.Lo = c.uv.X.Lo
children[pos].uv.X.Hi = uvMid.X
}
if j == 1 {
children[pos].uv.Y.Hi = c.uv.Y.Hi
children[pos].uv.Y.Lo = uvMid.Y
} else {
children[pos].uv.Y.Lo = c.uv.Y.Lo
children[pos].uv.Y.Hi = uvMid.Y
}
cid = cid.Next()
}
return children, true
} | [
"func",
"(",
"c",
"Cell",
")",
"Children",
"(",
")",
"(",
"[",
"4",
"]",
"Cell",
",",
"bool",
")",
"{",
"var",
"children",
"[",
"4",
"]",
"Cell",
"\n\n",
"if",
"c",
".",
"id",
".",
"IsLeaf",
"(",
")",
"{",
"return",
"children",
",",
"false",
"\n",
"}",
"\n\n",
"// Compute the cell midpoint in uv-space.",
"uvMid",
":=",
"c",
".",
"id",
".",
"centerUV",
"(",
")",
"\n\n",
"// Create four children with the appropriate bounds.",
"cid",
":=",
"c",
".",
"id",
".",
"ChildBegin",
"(",
")",
"\n",
"for",
"pos",
":=",
"0",
";",
"pos",
"<",
"4",
";",
"pos",
"++",
"{",
"children",
"[",
"pos",
"]",
"=",
"Cell",
"{",
"face",
":",
"c",
".",
"face",
",",
"level",
":",
"c",
".",
"level",
"+",
"1",
",",
"orientation",
":",
"c",
".",
"orientation",
"^",
"int8",
"(",
"posToOrientation",
"[",
"pos",
"]",
")",
",",
"id",
":",
"cid",
",",
"}",
"\n\n",
"// We want to split the cell in half in u and v. To decide which",
"// side to set equal to the midpoint value, we look at cell's (i,j)",
"// position within its parent. The index for i is in bit 1 of ij.",
"ij",
":=",
"posToIJ",
"[",
"c",
".",
"orientation",
"]",
"[",
"pos",
"]",
"\n",
"i",
":=",
"ij",
">>",
"1",
"\n",
"j",
":=",
"ij",
"&",
"1",
"\n",
"if",
"i",
"==",
"1",
"{",
"children",
"[",
"pos",
"]",
".",
"uv",
".",
"X",
".",
"Hi",
"=",
"c",
".",
"uv",
".",
"X",
".",
"Hi",
"\n",
"children",
"[",
"pos",
"]",
".",
"uv",
".",
"X",
".",
"Lo",
"=",
"uvMid",
".",
"X",
"\n",
"}",
"else",
"{",
"children",
"[",
"pos",
"]",
".",
"uv",
".",
"X",
".",
"Lo",
"=",
"c",
".",
"uv",
".",
"X",
".",
"Lo",
"\n",
"children",
"[",
"pos",
"]",
".",
"uv",
".",
"X",
".",
"Hi",
"=",
"uvMid",
".",
"X",
"\n",
"}",
"\n",
"if",
"j",
"==",
"1",
"{",
"children",
"[",
"pos",
"]",
".",
"uv",
".",
"Y",
".",
"Hi",
"=",
"c",
".",
"uv",
".",
"Y",
".",
"Hi",
"\n",
"children",
"[",
"pos",
"]",
".",
"uv",
".",
"Y",
".",
"Lo",
"=",
"uvMid",
".",
"Y",
"\n",
"}",
"else",
"{",
"children",
"[",
"pos",
"]",
".",
"uv",
".",
"Y",
".",
"Lo",
"=",
"c",
".",
"uv",
".",
"Y",
".",
"Lo",
"\n",
"children",
"[",
"pos",
"]",
".",
"uv",
".",
"Y",
".",
"Hi",
"=",
"uvMid",
".",
"Y",
"\n",
"}",
"\n",
"cid",
"=",
"cid",
".",
"Next",
"(",
")",
"\n",
"}",
"\n",
"return",
"children",
",",
"true",
"\n",
"}"
] | // Children returns the four direct children of this cell in traversal order
// and returns true. If this is a leaf cell, or the children could not be created,
// false is returned.
// The C++ method is called Subdivide. | [
"Children",
"returns",
"the",
"four",
"direct",
"children",
"of",
"this",
"cell",
"in",
"traversal",
"order",
"and",
"returns",
"true",
".",
"If",
"this",
"is",
"a",
"leaf",
"cell",
"or",
"the",
"children",
"could",
"not",
"be",
"created",
"false",
"is",
"returned",
".",
"The",
"C",
"++",
"method",
"is",
"called",
"Subdivide",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/cell.go#L133-L176 |
150,132 | golang/geo | s2/cell.go | ExactArea | func (c Cell) ExactArea() float64 {
v0, v1, v2, v3 := c.Vertex(0), c.Vertex(1), c.Vertex(2), c.Vertex(3)
return PointArea(v0, v1, v2) + PointArea(v0, v2, v3)
} | go | func (c Cell) ExactArea() float64 {
v0, v1, v2, v3 := c.Vertex(0), c.Vertex(1), c.Vertex(2), c.Vertex(3)
return PointArea(v0, v1, v2) + PointArea(v0, v2, v3)
} | [
"func",
"(",
"c",
"Cell",
")",
"ExactArea",
"(",
")",
"float64",
"{",
"v0",
",",
"v1",
",",
"v2",
",",
"v3",
":=",
"c",
".",
"Vertex",
"(",
"0",
")",
",",
"c",
".",
"Vertex",
"(",
"1",
")",
",",
"c",
".",
"Vertex",
"(",
"2",
")",
",",
"c",
".",
"Vertex",
"(",
"3",
")",
"\n",
"return",
"PointArea",
"(",
"v0",
",",
"v1",
",",
"v2",
")",
"+",
"PointArea",
"(",
"v0",
",",
"v2",
",",
"v3",
")",
"\n",
"}"
] | // ExactArea returns the area of this cell as accurately as possible. | [
"ExactArea",
"returns",
"the",
"area",
"of",
"this",
"cell",
"as",
"accurately",
"as",
"possible",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/cell.go#L179-L182 |
150,133 | golang/geo | s2/cell.go | IntersectsCell | func (c Cell) IntersectsCell(oc Cell) bool {
return c.id.Intersects(oc.id)
} | go | func (c Cell) IntersectsCell(oc Cell) bool {
return c.id.Intersects(oc.id)
} | [
"func",
"(",
"c",
"Cell",
")",
"IntersectsCell",
"(",
"oc",
"Cell",
")",
"bool",
"{",
"return",
"c",
".",
"id",
".",
"Intersects",
"(",
"oc",
".",
"id",
")",
"\n",
"}"
] | // IntersectsCell reports whether the intersection of this cell and the other cell is not nil. | [
"IntersectsCell",
"reports",
"whether",
"the",
"intersection",
"of",
"this",
"cell",
"and",
"the",
"other",
"cell",
"is",
"not",
"nil",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/cell.go#L216-L218 |
150,134 | golang/geo | s2/cell.go | ContainsCell | func (c Cell) ContainsCell(oc Cell) bool {
return c.id.Contains(oc.id)
} | go | func (c Cell) ContainsCell(oc Cell) bool {
return c.id.Contains(oc.id)
} | [
"func",
"(",
"c",
"Cell",
")",
"ContainsCell",
"(",
"oc",
"Cell",
")",
"bool",
"{",
"return",
"c",
".",
"id",
".",
"Contains",
"(",
"oc",
".",
"id",
")",
"\n",
"}"
] | // ContainsCell reports whether this cell contains the other cell. | [
"ContainsCell",
"reports",
"whether",
"this",
"cell",
"contains",
"the",
"other",
"cell",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/cell.go#L221-L223 |
150,135 | golang/geo | s2/cell.go | CapBound | func (c Cell) CapBound() Cap {
// We use the cell center in (u,v)-space as the cap axis. This vector is very close
// to GetCenter() and faster to compute. Neither one of these vectors yields the
// bounding cap with minimal surface area, but they are both pretty close.
cap := CapFromPoint(Point{faceUVToXYZ(int(c.face), c.uv.Center().X, c.uv.Center().Y).Normalize()})
for k := 0; k < 4; k++ {
cap = cap.AddPoint(c.Vertex(k))
}
return cap
} | go | func (c Cell) CapBound() Cap {
// We use the cell center in (u,v)-space as the cap axis. This vector is very close
// to GetCenter() and faster to compute. Neither one of these vectors yields the
// bounding cap with minimal surface area, but they are both pretty close.
cap := CapFromPoint(Point{faceUVToXYZ(int(c.face), c.uv.Center().X, c.uv.Center().Y).Normalize()})
for k := 0; k < 4; k++ {
cap = cap.AddPoint(c.Vertex(k))
}
return cap
} | [
"func",
"(",
"c",
"Cell",
")",
"CapBound",
"(",
")",
"Cap",
"{",
"// We use the cell center in (u,v)-space as the cap axis. This vector is very close",
"// to GetCenter() and faster to compute. Neither one of these vectors yields the",
"// bounding cap with minimal surface area, but they are both pretty close.",
"cap",
":=",
"CapFromPoint",
"(",
"Point",
"{",
"faceUVToXYZ",
"(",
"int",
"(",
"c",
".",
"face",
")",
",",
"c",
".",
"uv",
".",
"Center",
"(",
")",
".",
"X",
",",
"c",
".",
"uv",
".",
"Center",
"(",
")",
".",
"Y",
")",
".",
"Normalize",
"(",
")",
"}",
")",
"\n",
"for",
"k",
":=",
"0",
";",
"k",
"<",
"4",
";",
"k",
"++",
"{",
"cap",
"=",
"cap",
".",
"AddPoint",
"(",
"c",
".",
"Vertex",
"(",
"k",
")",
")",
"\n",
"}",
"\n",
"return",
"cap",
"\n",
"}"
] | // CapBound returns the bounding cap of this cell. | [
"CapBound",
"returns",
"the",
"bounding",
"cap",
"of",
"this",
"cell",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/cell.go#L363-L372 |
150,136 | golang/geo | s2/cell.go | vertexChordDist2 | func (c Cell) vertexChordDist2(p Point, xHi, yHi bool) s1.ChordAngle {
x := c.uv.X.Lo
y := c.uv.Y.Lo
if xHi {
x = c.uv.X.Hi
}
if yHi {
y = c.uv.Y.Hi
}
return ChordAngleBetweenPoints(p, PointFromCoords(x, y, 1))
} | go | func (c Cell) vertexChordDist2(p Point, xHi, yHi bool) s1.ChordAngle {
x := c.uv.X.Lo
y := c.uv.Y.Lo
if xHi {
x = c.uv.X.Hi
}
if yHi {
y = c.uv.Y.Hi
}
return ChordAngleBetweenPoints(p, PointFromCoords(x, y, 1))
} | [
"func",
"(",
"c",
"Cell",
")",
"vertexChordDist2",
"(",
"p",
"Point",
",",
"xHi",
",",
"yHi",
"bool",
")",
"s1",
".",
"ChordAngle",
"{",
"x",
":=",
"c",
".",
"uv",
".",
"X",
".",
"Lo",
"\n",
"y",
":=",
"c",
".",
"uv",
".",
"Y",
".",
"Lo",
"\n",
"if",
"xHi",
"{",
"x",
"=",
"c",
".",
"uv",
".",
"X",
".",
"Hi",
"\n",
"}",
"\n",
"if",
"yHi",
"{",
"y",
"=",
"c",
".",
"uv",
".",
"Y",
".",
"Hi",
"\n",
"}",
"\n\n",
"return",
"ChordAngleBetweenPoints",
"(",
"p",
",",
"PointFromCoords",
"(",
"x",
",",
"y",
",",
"1",
")",
")",
"\n",
"}"
] | // vertexChordDist2 returns the squared chord distance from point P to the
// given corner vertex specified by the Hi or Lo values of each. | [
"vertexChordDist2",
"returns",
"the",
"squared",
"chord",
"distance",
"from",
"point",
"P",
"to",
"the",
"given",
"corner",
"vertex",
"specified",
"by",
"the",
"Hi",
"or",
"Lo",
"values",
"of",
"each",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/cell.go#L423-L434 |
150,137 | golang/geo | s2/cell.go | edgeDistance | func edgeDistance(ij, uv float64) s1.ChordAngle {
// Let P by the target point and let R be the closest point on the given
// edge AB. The desired distance PR can be expressed as PR^2 = PQ^2 + QR^2
// where Q is the point P projected onto the plane through the great circle
// through AB. We can compute the distance PQ^2 perpendicular to the plane
// from "dirIJ" (the dot product of the target point P with the edge
// normal) and the squared length the edge normal (1 + uv**2).
pq2 := (ij * ij) / (1 + uv*uv)
// We can compute the distance QR as (1 - OQ) where O is the sphere origin,
// and we can compute OQ^2 = 1 - PQ^2 using the Pythagorean theorem.
// (This calculation loses accuracy as angle POQ approaches Pi/2.)
qr := 1 - math.Sqrt(1-pq2)
return s1.ChordAngleFromSquaredLength(pq2 + qr*qr)
} | go | func edgeDistance(ij, uv float64) s1.ChordAngle {
// Let P by the target point and let R be the closest point on the given
// edge AB. The desired distance PR can be expressed as PR^2 = PQ^2 + QR^2
// where Q is the point P projected onto the plane through the great circle
// through AB. We can compute the distance PQ^2 perpendicular to the plane
// from "dirIJ" (the dot product of the target point P with the edge
// normal) and the squared length the edge normal (1 + uv**2).
pq2 := (ij * ij) / (1 + uv*uv)
// We can compute the distance QR as (1 - OQ) where O is the sphere origin,
// and we can compute OQ^2 = 1 - PQ^2 using the Pythagorean theorem.
// (This calculation loses accuracy as angle POQ approaches Pi/2.)
qr := 1 - math.Sqrt(1-pq2)
return s1.ChordAngleFromSquaredLength(pq2 + qr*qr)
} | [
"func",
"edgeDistance",
"(",
"ij",
",",
"uv",
"float64",
")",
"s1",
".",
"ChordAngle",
"{",
"// Let P by the target point and let R be the closest point on the given",
"// edge AB. The desired distance PR can be expressed as PR^2 = PQ^2 + QR^2",
"// where Q is the point P projected onto the plane through the great circle",
"// through AB. We can compute the distance PQ^2 perpendicular to the plane",
"// from \"dirIJ\" (the dot product of the target point P with the edge",
"// normal) and the squared length the edge normal (1 + uv**2).",
"pq2",
":=",
"(",
"ij",
"*",
"ij",
")",
"/",
"(",
"1",
"+",
"uv",
"*",
"uv",
")",
"\n\n",
"// We can compute the distance QR as (1 - OQ) where O is the sphere origin,",
"// and we can compute OQ^2 = 1 - PQ^2 using the Pythagorean theorem.",
"// (This calculation loses accuracy as angle POQ approaches Pi/2.)",
"qr",
":=",
"1",
"-",
"math",
".",
"Sqrt",
"(",
"1",
"-",
"pq2",
")",
"\n",
"return",
"s1",
".",
"ChordAngleFromSquaredLength",
"(",
"pq2",
"+",
"qr",
"*",
"qr",
")",
"\n",
"}"
] | // edgeDistance reports the distance from a Point P to a given Cell edge. The point
// P is given by its dot product, and the uv edge by its normal in the
// given coordinate value. | [
"edgeDistance",
"reports",
"the",
"distance",
"from",
"a",
"Point",
"P",
"to",
"a",
"given",
"Cell",
"edge",
".",
"The",
"point",
"P",
"is",
"given",
"by",
"its",
"dot",
"product",
"and",
"the",
"uv",
"edge",
"by",
"its",
"normal",
"in",
"the",
"given",
"coordinate",
"value",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/cell.go#L469-L483 |
150,138 | golang/geo | s2/cell.go | distanceInternal | func (c Cell) distanceInternal(targetXYZ Point, toInterior bool) s1.ChordAngle {
// All calculations are done in the (u,v,w) coordinates of this cell's face.
target := faceXYZtoUVW(int(c.face), targetXYZ)
// Compute dot products with all four upward or rightward-facing edge
// normals. dirIJ is the dot product for the edge corresponding to axis
// I, endpoint J. For example, dir01 is the right edge of the Cell
// (corresponding to the upper endpoint of the u-axis).
dir00 := target.X - target.Z*c.uv.X.Lo
dir01 := target.X - target.Z*c.uv.X.Hi
dir10 := target.Y - target.Z*c.uv.Y.Lo
dir11 := target.Y - target.Z*c.uv.Y.Hi
inside := true
if dir00 < 0 {
inside = false // Target is to the left of the cell
if c.vEdgeIsClosest(target, false) {
return edgeDistance(-dir00, c.uv.X.Lo)
}
}
if dir01 > 0 {
inside = false // Target is to the right of the cell
if c.vEdgeIsClosest(target, true) {
return edgeDistance(dir01, c.uv.X.Hi)
}
}
if dir10 < 0 {
inside = false // Target is below the cell
if c.uEdgeIsClosest(target, false) {
return edgeDistance(-dir10, c.uv.Y.Lo)
}
}
if dir11 > 0 {
inside = false // Target is above the cell
if c.uEdgeIsClosest(target, true) {
return edgeDistance(dir11, c.uv.Y.Hi)
}
}
if inside {
if toInterior {
return s1.ChordAngle(0)
}
// Although you might think of Cells as rectangles, they are actually
// arbitrary quadrilaterals after they are projected onto the sphere.
// Therefore the simplest approach is just to find the minimum distance to
// any of the four edges.
return minChordAngle(edgeDistance(-dir00, c.uv.X.Lo),
edgeDistance(dir01, c.uv.X.Hi),
edgeDistance(-dir10, c.uv.Y.Lo),
edgeDistance(dir11, c.uv.Y.Hi))
}
// Otherwise, the closest point is one of the four cell vertices. Note that
// it is *not* trivial to narrow down the candidates based on the edge sign
// tests above, because (1) the edges don't meet at right angles and (2)
// there are points on the far side of the sphere that are both above *and*
// below the cell, etc.
return minChordAngle(c.vertexChordDist2(target, false, false),
c.vertexChordDist2(target, true, false),
c.vertexChordDist2(target, false, true),
c.vertexChordDist2(target, true, true))
} | go | func (c Cell) distanceInternal(targetXYZ Point, toInterior bool) s1.ChordAngle {
// All calculations are done in the (u,v,w) coordinates of this cell's face.
target := faceXYZtoUVW(int(c.face), targetXYZ)
// Compute dot products with all four upward or rightward-facing edge
// normals. dirIJ is the dot product for the edge corresponding to axis
// I, endpoint J. For example, dir01 is the right edge of the Cell
// (corresponding to the upper endpoint of the u-axis).
dir00 := target.X - target.Z*c.uv.X.Lo
dir01 := target.X - target.Z*c.uv.X.Hi
dir10 := target.Y - target.Z*c.uv.Y.Lo
dir11 := target.Y - target.Z*c.uv.Y.Hi
inside := true
if dir00 < 0 {
inside = false // Target is to the left of the cell
if c.vEdgeIsClosest(target, false) {
return edgeDistance(-dir00, c.uv.X.Lo)
}
}
if dir01 > 0 {
inside = false // Target is to the right of the cell
if c.vEdgeIsClosest(target, true) {
return edgeDistance(dir01, c.uv.X.Hi)
}
}
if dir10 < 0 {
inside = false // Target is below the cell
if c.uEdgeIsClosest(target, false) {
return edgeDistance(-dir10, c.uv.Y.Lo)
}
}
if dir11 > 0 {
inside = false // Target is above the cell
if c.uEdgeIsClosest(target, true) {
return edgeDistance(dir11, c.uv.Y.Hi)
}
}
if inside {
if toInterior {
return s1.ChordAngle(0)
}
// Although you might think of Cells as rectangles, they are actually
// arbitrary quadrilaterals after they are projected onto the sphere.
// Therefore the simplest approach is just to find the minimum distance to
// any of the four edges.
return minChordAngle(edgeDistance(-dir00, c.uv.X.Lo),
edgeDistance(dir01, c.uv.X.Hi),
edgeDistance(-dir10, c.uv.Y.Lo),
edgeDistance(dir11, c.uv.Y.Hi))
}
// Otherwise, the closest point is one of the four cell vertices. Note that
// it is *not* trivial to narrow down the candidates based on the edge sign
// tests above, because (1) the edges don't meet at right angles and (2)
// there are points on the far side of the sphere that are both above *and*
// below the cell, etc.
return minChordAngle(c.vertexChordDist2(target, false, false),
c.vertexChordDist2(target, true, false),
c.vertexChordDist2(target, false, true),
c.vertexChordDist2(target, true, true))
} | [
"func",
"(",
"c",
"Cell",
")",
"distanceInternal",
"(",
"targetXYZ",
"Point",
",",
"toInterior",
"bool",
")",
"s1",
".",
"ChordAngle",
"{",
"// All calculations are done in the (u,v,w) coordinates of this cell's face.",
"target",
":=",
"faceXYZtoUVW",
"(",
"int",
"(",
"c",
".",
"face",
")",
",",
"targetXYZ",
")",
"\n\n",
"// Compute dot products with all four upward or rightward-facing edge",
"// normals. dirIJ is the dot product for the edge corresponding to axis",
"// I, endpoint J. For example, dir01 is the right edge of the Cell",
"// (corresponding to the upper endpoint of the u-axis).",
"dir00",
":=",
"target",
".",
"X",
"-",
"target",
".",
"Z",
"*",
"c",
".",
"uv",
".",
"X",
".",
"Lo",
"\n",
"dir01",
":=",
"target",
".",
"X",
"-",
"target",
".",
"Z",
"*",
"c",
".",
"uv",
".",
"X",
".",
"Hi",
"\n",
"dir10",
":=",
"target",
".",
"Y",
"-",
"target",
".",
"Z",
"*",
"c",
".",
"uv",
".",
"Y",
".",
"Lo",
"\n",
"dir11",
":=",
"target",
".",
"Y",
"-",
"target",
".",
"Z",
"*",
"c",
".",
"uv",
".",
"Y",
".",
"Hi",
"\n",
"inside",
":=",
"true",
"\n",
"if",
"dir00",
"<",
"0",
"{",
"inside",
"=",
"false",
"// Target is to the left of the cell",
"\n",
"if",
"c",
".",
"vEdgeIsClosest",
"(",
"target",
",",
"false",
")",
"{",
"return",
"edgeDistance",
"(",
"-",
"dir00",
",",
"c",
".",
"uv",
".",
"X",
".",
"Lo",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"dir01",
">",
"0",
"{",
"inside",
"=",
"false",
"// Target is to the right of the cell",
"\n",
"if",
"c",
".",
"vEdgeIsClosest",
"(",
"target",
",",
"true",
")",
"{",
"return",
"edgeDistance",
"(",
"dir01",
",",
"c",
".",
"uv",
".",
"X",
".",
"Hi",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"dir10",
"<",
"0",
"{",
"inside",
"=",
"false",
"// Target is below the cell",
"\n",
"if",
"c",
".",
"uEdgeIsClosest",
"(",
"target",
",",
"false",
")",
"{",
"return",
"edgeDistance",
"(",
"-",
"dir10",
",",
"c",
".",
"uv",
".",
"Y",
".",
"Lo",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"dir11",
">",
"0",
"{",
"inside",
"=",
"false",
"// Target is above the cell",
"\n",
"if",
"c",
".",
"uEdgeIsClosest",
"(",
"target",
",",
"true",
")",
"{",
"return",
"edgeDistance",
"(",
"dir11",
",",
"c",
".",
"uv",
".",
"Y",
".",
"Hi",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"inside",
"{",
"if",
"toInterior",
"{",
"return",
"s1",
".",
"ChordAngle",
"(",
"0",
")",
"\n",
"}",
"\n",
"// Although you might think of Cells as rectangles, they are actually",
"// arbitrary quadrilaterals after they are projected onto the sphere.",
"// Therefore the simplest approach is just to find the minimum distance to",
"// any of the four edges.",
"return",
"minChordAngle",
"(",
"edgeDistance",
"(",
"-",
"dir00",
",",
"c",
".",
"uv",
".",
"X",
".",
"Lo",
")",
",",
"edgeDistance",
"(",
"dir01",
",",
"c",
".",
"uv",
".",
"X",
".",
"Hi",
")",
",",
"edgeDistance",
"(",
"-",
"dir10",
",",
"c",
".",
"uv",
".",
"Y",
".",
"Lo",
")",
",",
"edgeDistance",
"(",
"dir11",
",",
"c",
".",
"uv",
".",
"Y",
".",
"Hi",
")",
")",
"\n",
"}",
"\n\n",
"// Otherwise, the closest point is one of the four cell vertices. Note that",
"// it is *not* trivial to narrow down the candidates based on the edge sign",
"// tests above, because (1) the edges don't meet at right angles and (2)",
"// there are points on the far side of the sphere that are both above *and*",
"// below the cell, etc.",
"return",
"minChordAngle",
"(",
"c",
".",
"vertexChordDist2",
"(",
"target",
",",
"false",
",",
"false",
")",
",",
"c",
".",
"vertexChordDist2",
"(",
"target",
",",
"true",
",",
"false",
")",
",",
"c",
".",
"vertexChordDist2",
"(",
"target",
",",
"false",
",",
"true",
")",
",",
"c",
".",
"vertexChordDist2",
"(",
"target",
",",
"true",
",",
"true",
")",
")",
"\n",
"}"
] | // distanceInternal reports the distance from the given point to the interior of
// the cell if toInterior is true or to the boundary of the cell otherwise. | [
"distanceInternal",
"reports",
"the",
"distance",
"from",
"the",
"given",
"point",
"to",
"the",
"interior",
"of",
"the",
"cell",
"if",
"toInterior",
"is",
"true",
"or",
"to",
"the",
"boundary",
"of",
"the",
"cell",
"otherwise",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/cell.go#L487-L547 |
150,139 | golang/geo | s2/cell.go | Distance | func (c Cell) Distance(target Point) s1.ChordAngle {
return c.distanceInternal(target, true)
} | go | func (c Cell) Distance(target Point) s1.ChordAngle {
return c.distanceInternal(target, true)
} | [
"func",
"(",
"c",
"Cell",
")",
"Distance",
"(",
"target",
"Point",
")",
"s1",
".",
"ChordAngle",
"{",
"return",
"c",
".",
"distanceInternal",
"(",
"target",
",",
"true",
")",
"\n",
"}"
] | // Distance reports the distance from the cell to the given point. Returns zero if
// the point is inside the cell. | [
"Distance",
"reports",
"the",
"distance",
"from",
"the",
"cell",
"to",
"the",
"given",
"point",
".",
"Returns",
"zero",
"if",
"the",
"point",
"is",
"inside",
"the",
"cell",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/cell.go#L551-L553 |
150,140 | golang/geo | s2/cell.go | BoundaryDistance | func (c Cell) BoundaryDistance(target Point) s1.ChordAngle {
return c.distanceInternal(target, false)
} | go | func (c Cell) BoundaryDistance(target Point) s1.ChordAngle {
return c.distanceInternal(target, false)
} | [
"func",
"(",
"c",
"Cell",
")",
"BoundaryDistance",
"(",
"target",
"Point",
")",
"s1",
".",
"ChordAngle",
"{",
"return",
"c",
".",
"distanceInternal",
"(",
"target",
",",
"false",
")",
"\n",
"}"
] | // BoundaryDistance reports the distance from the cell boundary to the given point. | [
"BoundaryDistance",
"reports",
"the",
"distance",
"from",
"the",
"cell",
"boundary",
"to",
"the",
"given",
"point",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/cell.go#L576-L578 |
150,141 | golang/geo | s2/cell.go | DistanceToEdge | func (c Cell) DistanceToEdge(a, b Point) s1.ChordAngle {
// Possible optimizations:
// - Currently the (cell vertex, edge endpoint) distances are computed
// twice each, and the length of AB is computed 4 times.
// - To fix this, refactor GetDistance(target) so that it skips calculating
// the distance to each cell vertex. Instead, compute the cell vertices
// and distances in this function, and add a low-level UpdateMinDistance
// that allows the XA, XB, and AB distances to be passed in.
// - It might also be more efficient to do all calculations in UVW-space,
// since this would involve transforming 2 points rather than 4.
// First, check the minimum distance to the edge endpoints A and B.
// (This also detects whether either endpoint is inside the cell.)
minDist := minChordAngle(c.Distance(a), c.Distance(b))
if minDist == 0 {
return minDist
}
// Otherwise, check whether the edge crosses the cell boundary.
crosser := NewChainEdgeCrosser(a, b, c.Vertex(3))
for i := 0; i < 4; i++ {
if crosser.ChainCrossingSign(c.Vertex(i)) != DoNotCross {
return 0
}
}
// Finally, check whether the minimum distance occurs between a cell vertex
// and the interior of the edge AB. (Some of this work is redundant, since
// it also checks the distance to the endpoints A and B again.)
//
// Note that we don't need to check the distance from the interior of AB to
// the interior of a cell edge, because the only way that this distance can
// be minimal is if the two edges cross (already checked above).
for i := 0; i < 4; i++ {
minDist, _ = UpdateMinDistance(c.Vertex(i), a, b, minDist)
}
return minDist
} | go | func (c Cell) DistanceToEdge(a, b Point) s1.ChordAngle {
// Possible optimizations:
// - Currently the (cell vertex, edge endpoint) distances are computed
// twice each, and the length of AB is computed 4 times.
// - To fix this, refactor GetDistance(target) so that it skips calculating
// the distance to each cell vertex. Instead, compute the cell vertices
// and distances in this function, and add a low-level UpdateMinDistance
// that allows the XA, XB, and AB distances to be passed in.
// - It might also be more efficient to do all calculations in UVW-space,
// since this would involve transforming 2 points rather than 4.
// First, check the minimum distance to the edge endpoints A and B.
// (This also detects whether either endpoint is inside the cell.)
minDist := minChordAngle(c.Distance(a), c.Distance(b))
if minDist == 0 {
return minDist
}
// Otherwise, check whether the edge crosses the cell boundary.
crosser := NewChainEdgeCrosser(a, b, c.Vertex(3))
for i := 0; i < 4; i++ {
if crosser.ChainCrossingSign(c.Vertex(i)) != DoNotCross {
return 0
}
}
// Finally, check whether the minimum distance occurs between a cell vertex
// and the interior of the edge AB. (Some of this work is redundant, since
// it also checks the distance to the endpoints A and B again.)
//
// Note that we don't need to check the distance from the interior of AB to
// the interior of a cell edge, because the only way that this distance can
// be minimal is if the two edges cross (already checked above).
for i := 0; i < 4; i++ {
minDist, _ = UpdateMinDistance(c.Vertex(i), a, b, minDist)
}
return minDist
} | [
"func",
"(",
"c",
"Cell",
")",
"DistanceToEdge",
"(",
"a",
",",
"b",
"Point",
")",
"s1",
".",
"ChordAngle",
"{",
"// Possible optimizations:",
"// - Currently the (cell vertex, edge endpoint) distances are computed",
"// twice each, and the length of AB is computed 4 times.",
"// - To fix this, refactor GetDistance(target) so that it skips calculating",
"// the distance to each cell vertex. Instead, compute the cell vertices",
"// and distances in this function, and add a low-level UpdateMinDistance",
"// that allows the XA, XB, and AB distances to be passed in.",
"// - It might also be more efficient to do all calculations in UVW-space,",
"// since this would involve transforming 2 points rather than 4.",
"// First, check the minimum distance to the edge endpoints A and B.",
"// (This also detects whether either endpoint is inside the cell.)",
"minDist",
":=",
"minChordAngle",
"(",
"c",
".",
"Distance",
"(",
"a",
")",
",",
"c",
".",
"Distance",
"(",
"b",
")",
")",
"\n",
"if",
"minDist",
"==",
"0",
"{",
"return",
"minDist",
"\n",
"}",
"\n\n",
"// Otherwise, check whether the edge crosses the cell boundary.",
"crosser",
":=",
"NewChainEdgeCrosser",
"(",
"a",
",",
"b",
",",
"c",
".",
"Vertex",
"(",
"3",
")",
")",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"4",
";",
"i",
"++",
"{",
"if",
"crosser",
".",
"ChainCrossingSign",
"(",
"c",
".",
"Vertex",
"(",
"i",
")",
")",
"!=",
"DoNotCross",
"{",
"return",
"0",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Finally, check whether the minimum distance occurs between a cell vertex",
"// and the interior of the edge AB. (Some of this work is redundant, since",
"// it also checks the distance to the endpoints A and B again.)",
"//",
"// Note that we don't need to check the distance from the interior of AB to",
"// the interior of a cell edge, because the only way that this distance can",
"// be minimal is if the two edges cross (already checked above).",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"4",
";",
"i",
"++",
"{",
"minDist",
",",
"_",
"=",
"UpdateMinDistance",
"(",
"c",
".",
"Vertex",
"(",
"i",
")",
",",
"a",
",",
"b",
",",
"minDist",
")",
"\n",
"}",
"\n",
"return",
"minDist",
"\n",
"}"
] | // DistanceToEdge returns the minimum distance from the cell to the given edge AB. Returns
// zero if the edge intersects the cell interior. | [
"DistanceToEdge",
"returns",
"the",
"minimum",
"distance",
"from",
"the",
"cell",
"to",
"the",
"given",
"edge",
"AB",
".",
"Returns",
"zero",
"if",
"the",
"edge",
"intersects",
"the",
"cell",
"interior",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/cell.go#L582-L619 |
150,142 | golang/geo | s2/cell.go | DistanceToCell | func (c Cell) DistanceToCell(target Cell) s1.ChordAngle {
// If the cells intersect, the distance is zero. We use the (u,v) ranges
// rather than CellID intersects so that cells that share a partial edge or
// corner are considered to intersect.
if c.face == target.face && c.uv.Intersects(target.uv) {
return 0
}
// Otherwise, the minimum distance always occurs between a vertex of one
// cell and an edge of the other cell (including the edge endpoints). This
// represents a total of 32 possible (vertex, edge) pairs.
//
// TODO(roberts): This could be optimized to be at least 5x faster by pruning
// the set of possible closest vertex/edge pairs using the faces and (u,v)
// ranges of both cells.
var va, vb [4]Point
for i := 0; i < 4; i++ {
va[i] = c.Vertex(i)
vb[i] = target.Vertex(i)
}
minDist := s1.InfChordAngle()
for i := 0; i < 4; i++ {
for j := 0; j < 4; j++ {
minDist, _ = UpdateMinDistance(va[i], vb[j], vb[(j+1)&3], minDist)
minDist, _ = UpdateMinDistance(vb[i], va[j], va[(j+1)&3], minDist)
}
}
return minDist
} | go | func (c Cell) DistanceToCell(target Cell) s1.ChordAngle {
// If the cells intersect, the distance is zero. We use the (u,v) ranges
// rather than CellID intersects so that cells that share a partial edge or
// corner are considered to intersect.
if c.face == target.face && c.uv.Intersects(target.uv) {
return 0
}
// Otherwise, the minimum distance always occurs between a vertex of one
// cell and an edge of the other cell (including the edge endpoints). This
// represents a total of 32 possible (vertex, edge) pairs.
//
// TODO(roberts): This could be optimized to be at least 5x faster by pruning
// the set of possible closest vertex/edge pairs using the faces and (u,v)
// ranges of both cells.
var va, vb [4]Point
for i := 0; i < 4; i++ {
va[i] = c.Vertex(i)
vb[i] = target.Vertex(i)
}
minDist := s1.InfChordAngle()
for i := 0; i < 4; i++ {
for j := 0; j < 4; j++ {
minDist, _ = UpdateMinDistance(va[i], vb[j], vb[(j+1)&3], minDist)
minDist, _ = UpdateMinDistance(vb[i], va[j], va[(j+1)&3], minDist)
}
}
return minDist
} | [
"func",
"(",
"c",
"Cell",
")",
"DistanceToCell",
"(",
"target",
"Cell",
")",
"s1",
".",
"ChordAngle",
"{",
"// If the cells intersect, the distance is zero. We use the (u,v) ranges",
"// rather than CellID intersects so that cells that share a partial edge or",
"// corner are considered to intersect.",
"if",
"c",
".",
"face",
"==",
"target",
".",
"face",
"&&",
"c",
".",
"uv",
".",
"Intersects",
"(",
"target",
".",
"uv",
")",
"{",
"return",
"0",
"\n",
"}",
"\n\n",
"// Otherwise, the minimum distance always occurs between a vertex of one",
"// cell and an edge of the other cell (including the edge endpoints). This",
"// represents a total of 32 possible (vertex, edge) pairs.",
"//",
"// TODO(roberts): This could be optimized to be at least 5x faster by pruning",
"// the set of possible closest vertex/edge pairs using the faces and (u,v)",
"// ranges of both cells.",
"var",
"va",
",",
"vb",
"[",
"4",
"]",
"Point",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"4",
";",
"i",
"++",
"{",
"va",
"[",
"i",
"]",
"=",
"c",
".",
"Vertex",
"(",
"i",
")",
"\n",
"vb",
"[",
"i",
"]",
"=",
"target",
".",
"Vertex",
"(",
"i",
")",
"\n",
"}",
"\n",
"minDist",
":=",
"s1",
".",
"InfChordAngle",
"(",
")",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"4",
";",
"i",
"++",
"{",
"for",
"j",
":=",
"0",
";",
"j",
"<",
"4",
";",
"j",
"++",
"{",
"minDist",
",",
"_",
"=",
"UpdateMinDistance",
"(",
"va",
"[",
"i",
"]",
",",
"vb",
"[",
"j",
"]",
",",
"vb",
"[",
"(",
"j",
"+",
"1",
")",
"&",
"3",
"]",
",",
"minDist",
")",
"\n",
"minDist",
",",
"_",
"=",
"UpdateMinDistance",
"(",
"vb",
"[",
"i",
"]",
",",
"va",
"[",
"j",
"]",
",",
"va",
"[",
"(",
"j",
"+",
"1",
")",
"&",
"3",
"]",
",",
"minDist",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"minDist",
"\n",
"}"
] | // DistanceToCell returns the minimum distance from this cell to the given cell.
// It returns zero if one cell contains the other. | [
"DistanceToCell",
"returns",
"the",
"minimum",
"distance",
"from",
"this",
"cell",
"to",
"the",
"given",
"cell",
".",
"It",
"returns",
"zero",
"if",
"one",
"cell",
"contains",
"the",
"other",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/cell.go#L637-L665 |
150,143 | golang/geo | s1/interval.go | IsValid | func (i Interval) IsValid() bool {
return (math.Abs(i.Lo) <= math.Pi && math.Abs(i.Hi) <= math.Pi &&
!(i.Lo == -math.Pi && i.Hi != math.Pi) &&
!(i.Hi == -math.Pi && i.Lo != math.Pi))
} | go | func (i Interval) IsValid() bool {
return (math.Abs(i.Lo) <= math.Pi && math.Abs(i.Hi) <= math.Pi &&
!(i.Lo == -math.Pi && i.Hi != math.Pi) &&
!(i.Hi == -math.Pi && i.Lo != math.Pi))
} | [
"func",
"(",
"i",
"Interval",
")",
"IsValid",
"(",
")",
"bool",
"{",
"return",
"(",
"math",
".",
"Abs",
"(",
"i",
".",
"Lo",
")",
"<=",
"math",
".",
"Pi",
"&&",
"math",
".",
"Abs",
"(",
"i",
".",
"Hi",
")",
"<=",
"math",
".",
"Pi",
"&&",
"!",
"(",
"i",
".",
"Lo",
"==",
"-",
"math",
".",
"Pi",
"&&",
"i",
".",
"Hi",
"!=",
"math",
".",
"Pi",
")",
"&&",
"!",
"(",
"i",
".",
"Hi",
"==",
"-",
"math",
".",
"Pi",
"&&",
"i",
".",
"Lo",
"!=",
"math",
".",
"Pi",
")",
")",
"\n",
"}"
] | // IsValid reports whether the interval is valid. | [
"IsValid",
"reports",
"whether",
"the",
"interval",
"is",
"valid",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s1/interval.go#L71-L75 |
150,144 | golang/geo | s1/interval.go | Center | func (i Interval) Center() float64 {
c := 0.5 * (i.Lo + i.Hi)
if !i.IsInverted() {
return c
}
if c <= 0 {
return c + math.Pi
}
return c - math.Pi
} | go | func (i Interval) Center() float64 {
c := 0.5 * (i.Lo + i.Hi)
if !i.IsInverted() {
return c
}
if c <= 0 {
return c + math.Pi
}
return c - math.Pi
} | [
"func",
"(",
"i",
"Interval",
")",
"Center",
"(",
")",
"float64",
"{",
"c",
":=",
"0.5",
"*",
"(",
"i",
".",
"Lo",
"+",
"i",
".",
"Hi",
")",
"\n",
"if",
"!",
"i",
".",
"IsInverted",
"(",
")",
"{",
"return",
"c",
"\n",
"}",
"\n",
"if",
"c",
"<=",
"0",
"{",
"return",
"c",
"+",
"math",
".",
"Pi",
"\n",
"}",
"\n",
"return",
"c",
"-",
"math",
".",
"Pi",
"\n",
"}"
] | // Center returns the midpoint of the interval.
// It is undefined for full and empty intervals. | [
"Center",
"returns",
"the",
"midpoint",
"of",
"the",
"interval",
".",
"It",
"is",
"undefined",
"for",
"full",
"and",
"empty",
"intervals",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s1/interval.go#L93-L102 |
150,145 | golang/geo | s1/interval.go | Length | func (i Interval) Length() float64 {
l := i.Hi - i.Lo
if l >= 0 {
return l
}
l += 2 * math.Pi
if l > 0 {
return l
}
return -1
} | go | func (i Interval) Length() float64 {
l := i.Hi - i.Lo
if l >= 0 {
return l
}
l += 2 * math.Pi
if l > 0 {
return l
}
return -1
} | [
"func",
"(",
"i",
"Interval",
")",
"Length",
"(",
")",
"float64",
"{",
"l",
":=",
"i",
".",
"Hi",
"-",
"i",
".",
"Lo",
"\n",
"if",
"l",
">=",
"0",
"{",
"return",
"l",
"\n",
"}",
"\n",
"l",
"+=",
"2",
"*",
"math",
".",
"Pi",
"\n",
"if",
"l",
">",
"0",
"{",
"return",
"l",
"\n",
"}",
"\n",
"return",
"-",
"1",
"\n",
"}"
] | // Length returns the length of the interval.
// The length of an empty interval is negative. | [
"Length",
"returns",
"the",
"length",
"of",
"the",
"interval",
".",
"The",
"length",
"of",
"an",
"empty",
"interval",
"is",
"negative",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s1/interval.go#L106-L116 |
150,146 | golang/geo | s1/interval.go | Union | func (i Interval) Union(oi Interval) Interval {
if oi.IsEmpty() {
return i
}
if i.fastContains(oi.Lo) {
if i.fastContains(oi.Hi) {
// Either oi ⊂ i, or i ∪ oi is the full interval.
if i.ContainsInterval(oi) {
return i
}
return FullInterval()
}
return Interval{i.Lo, oi.Hi}
}
if i.fastContains(oi.Hi) {
return Interval{oi.Lo, i.Hi}
}
// Neither endpoint of oi is in i. Either i ⊂ oi, or i and oi are disjoint.
if i.IsEmpty() || oi.fastContains(i.Lo) {
return oi
}
// This is the only hard case where we need to find the closest pair of endpoints.
if positiveDistance(oi.Hi, i.Lo) < positiveDistance(i.Hi, oi.Lo) {
return Interval{oi.Lo, i.Hi}
}
return Interval{i.Lo, oi.Hi}
} | go | func (i Interval) Union(oi Interval) Interval {
if oi.IsEmpty() {
return i
}
if i.fastContains(oi.Lo) {
if i.fastContains(oi.Hi) {
// Either oi ⊂ i, or i ∪ oi is the full interval.
if i.ContainsInterval(oi) {
return i
}
return FullInterval()
}
return Interval{i.Lo, oi.Hi}
}
if i.fastContains(oi.Hi) {
return Interval{oi.Lo, i.Hi}
}
// Neither endpoint of oi is in i. Either i ⊂ oi, or i and oi are disjoint.
if i.IsEmpty() || oi.fastContains(i.Lo) {
return oi
}
// This is the only hard case where we need to find the closest pair of endpoints.
if positiveDistance(oi.Hi, i.Lo) < positiveDistance(i.Hi, oi.Lo) {
return Interval{oi.Lo, i.Hi}
}
return Interval{i.Lo, oi.Hi}
} | [
"func",
"(",
"i",
"Interval",
")",
"Union",
"(",
"oi",
"Interval",
")",
"Interval",
"{",
"if",
"oi",
".",
"IsEmpty",
"(",
")",
"{",
"return",
"i",
"\n",
"}",
"\n",
"if",
"i",
".",
"fastContains",
"(",
"oi",
".",
"Lo",
")",
"{",
"if",
"i",
".",
"fastContains",
"(",
"oi",
".",
"Hi",
")",
"{",
"// Either oi ⊂ i, or i ∪ oi is the full interval.",
"if",
"i",
".",
"ContainsInterval",
"(",
"oi",
")",
"{",
"return",
"i",
"\n",
"}",
"\n",
"return",
"FullInterval",
"(",
")",
"\n",
"}",
"\n",
"return",
"Interval",
"{",
"i",
".",
"Lo",
",",
"oi",
".",
"Hi",
"}",
"\n",
"}",
"\n",
"if",
"i",
".",
"fastContains",
"(",
"oi",
".",
"Hi",
")",
"{",
"return",
"Interval",
"{",
"oi",
".",
"Lo",
",",
"i",
".",
"Hi",
"}",
"\n",
"}",
"\n\n",
"// Neither endpoint of oi is in i. Either i ⊂ oi, or i and oi are disjoint.",
"if",
"i",
".",
"IsEmpty",
"(",
")",
"||",
"oi",
".",
"fastContains",
"(",
"i",
".",
"Lo",
")",
"{",
"return",
"oi",
"\n",
"}",
"\n\n",
"// This is the only hard case where we need to find the closest pair of endpoints.",
"if",
"positiveDistance",
"(",
"oi",
".",
"Hi",
",",
"i",
".",
"Lo",
")",
"<",
"positiveDistance",
"(",
"i",
".",
"Hi",
",",
"oi",
".",
"Lo",
")",
"{",
"return",
"Interval",
"{",
"oi",
".",
"Lo",
",",
"i",
".",
"Hi",
"}",
"\n",
"}",
"\n",
"return",
"Interval",
"{",
"i",
".",
"Lo",
",",
"oi",
".",
"Hi",
"}",
"\n",
"}"
] | // Union returns the smallest interval that contains both the interval and oi. | [
"Union",
"returns",
"the",
"smallest",
"interval",
"that",
"contains",
"both",
"the",
"interval",
"and",
"oi",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s1/interval.go#L213-L241 |
150,147 | golang/geo | s1/interval.go | Intersection | func (i Interval) Intersection(oi Interval) Interval {
if oi.IsEmpty() {
return EmptyInterval()
}
if i.fastContains(oi.Lo) {
if i.fastContains(oi.Hi) {
// Either oi ⊂ i, or i and oi intersect twice. Neither are empty.
// In the first case we want to return i (which is shorter than oi).
// In the second case one of them is inverted, and the smallest interval
// that covers the two disjoint pieces is the shorter of i and oi.
// We thus want to pick the shorter of i and oi in both cases.
if oi.Length() < i.Length() {
return oi
}
return i
}
return Interval{oi.Lo, i.Hi}
}
if i.fastContains(oi.Hi) {
return Interval{i.Lo, oi.Hi}
}
// Neither endpoint of oi is in i. Either i ⊂ oi, or i and oi are disjoint.
if oi.fastContains(i.Lo) {
return i
}
return EmptyInterval()
} | go | func (i Interval) Intersection(oi Interval) Interval {
if oi.IsEmpty() {
return EmptyInterval()
}
if i.fastContains(oi.Lo) {
if i.fastContains(oi.Hi) {
// Either oi ⊂ i, or i and oi intersect twice. Neither are empty.
// In the first case we want to return i (which is shorter than oi).
// In the second case one of them is inverted, and the smallest interval
// that covers the two disjoint pieces is the shorter of i and oi.
// We thus want to pick the shorter of i and oi in both cases.
if oi.Length() < i.Length() {
return oi
}
return i
}
return Interval{oi.Lo, i.Hi}
}
if i.fastContains(oi.Hi) {
return Interval{i.Lo, oi.Hi}
}
// Neither endpoint of oi is in i. Either i ⊂ oi, or i and oi are disjoint.
if oi.fastContains(i.Lo) {
return i
}
return EmptyInterval()
} | [
"func",
"(",
"i",
"Interval",
")",
"Intersection",
"(",
"oi",
"Interval",
")",
"Interval",
"{",
"if",
"oi",
".",
"IsEmpty",
"(",
")",
"{",
"return",
"EmptyInterval",
"(",
")",
"\n",
"}",
"\n",
"if",
"i",
".",
"fastContains",
"(",
"oi",
".",
"Lo",
")",
"{",
"if",
"i",
".",
"fastContains",
"(",
"oi",
".",
"Hi",
")",
"{",
"// Either oi ⊂ i, or i and oi intersect twice. Neither are empty.",
"// In the first case we want to return i (which is shorter than oi).",
"// In the second case one of them is inverted, and the smallest interval",
"// that covers the two disjoint pieces is the shorter of i and oi.",
"// We thus want to pick the shorter of i and oi in both cases.",
"if",
"oi",
".",
"Length",
"(",
")",
"<",
"i",
".",
"Length",
"(",
")",
"{",
"return",
"oi",
"\n",
"}",
"\n",
"return",
"i",
"\n",
"}",
"\n",
"return",
"Interval",
"{",
"oi",
".",
"Lo",
",",
"i",
".",
"Hi",
"}",
"\n",
"}",
"\n",
"if",
"i",
".",
"fastContains",
"(",
"oi",
".",
"Hi",
")",
"{",
"return",
"Interval",
"{",
"i",
".",
"Lo",
",",
"oi",
".",
"Hi",
"}",
"\n",
"}",
"\n\n",
"// Neither endpoint of oi is in i. Either i ⊂ oi, or i and oi are disjoint.",
"if",
"oi",
".",
"fastContains",
"(",
"i",
".",
"Lo",
")",
"{",
"return",
"i",
"\n",
"}",
"\n",
"return",
"EmptyInterval",
"(",
")",
"\n",
"}"
] | // Intersection returns the smallest interval that contains the intersection of the interval and oi. | [
"Intersection",
"returns",
"the",
"smallest",
"interval",
"that",
"contains",
"the",
"intersection",
"of",
"the",
"interval",
"and",
"oi",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s1/interval.go#L244-L271 |
150,148 | golang/geo | s2/polyline.go | PolylineFromLatLngs | func PolylineFromLatLngs(points []LatLng) *Polyline {
p := make(Polyline, len(points))
for k, v := range points {
p[k] = PointFromLatLng(v)
}
return &p
} | go | func PolylineFromLatLngs(points []LatLng) *Polyline {
p := make(Polyline, len(points))
for k, v := range points {
p[k] = PointFromLatLng(v)
}
return &p
} | [
"func",
"PolylineFromLatLngs",
"(",
"points",
"[",
"]",
"LatLng",
")",
"*",
"Polyline",
"{",
"p",
":=",
"make",
"(",
"Polyline",
",",
"len",
"(",
"points",
")",
")",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"points",
"{",
"p",
"[",
"k",
"]",
"=",
"PointFromLatLng",
"(",
"v",
")",
"\n",
"}",
"\n",
"return",
"&",
"p",
"\n",
"}"
] | // PolylineFromLatLngs creates a new Polyline from the given LatLngs. | [
"PolylineFromLatLngs",
"creates",
"a",
"new",
"Polyline",
"from",
"the",
"given",
"LatLngs",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/polyline.go#L31-L37 |
150,149 | golang/geo | s2/polyline.go | Reverse | func (p *Polyline) Reverse() {
for i := 0; i < len(*p)/2; i++ {
(*p)[i], (*p)[len(*p)-i-1] = (*p)[len(*p)-i-1], (*p)[i]
}
} | go | func (p *Polyline) Reverse() {
for i := 0; i < len(*p)/2; i++ {
(*p)[i], (*p)[len(*p)-i-1] = (*p)[len(*p)-i-1], (*p)[i]
}
} | [
"func",
"(",
"p",
"*",
"Polyline",
")",
"Reverse",
"(",
")",
"{",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"len",
"(",
"*",
"p",
")",
"/",
"2",
";",
"i",
"++",
"{",
"(",
"*",
"p",
")",
"[",
"i",
"]",
",",
"(",
"*",
"p",
")",
"[",
"len",
"(",
"*",
"p",
")",
"-",
"i",
"-",
"1",
"]",
"=",
"(",
"*",
"p",
")",
"[",
"len",
"(",
"*",
"p",
")",
"-",
"i",
"-",
"1",
"]",
",",
"(",
"*",
"p",
")",
"[",
"i",
"]",
"\n",
"}",
"\n",
"}"
] | // Reverse reverses the order of the Polyline vertices. | [
"Reverse",
"reverses",
"the",
"order",
"of",
"the",
"Polyline",
"vertices",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/polyline.go#L40-L44 |
150,150 | golang/geo | s2/polyline.go | Length | func (p *Polyline) Length() s1.Angle {
var length s1.Angle
for i := 1; i < len(*p); i++ {
length += (*p)[i-1].Distance((*p)[i])
}
return length
} | go | func (p *Polyline) Length() s1.Angle {
var length s1.Angle
for i := 1; i < len(*p); i++ {
length += (*p)[i-1].Distance((*p)[i])
}
return length
} | [
"func",
"(",
"p",
"*",
"Polyline",
")",
"Length",
"(",
")",
"s1",
".",
"Angle",
"{",
"var",
"length",
"s1",
".",
"Angle",
"\n\n",
"for",
"i",
":=",
"1",
";",
"i",
"<",
"len",
"(",
"*",
"p",
")",
";",
"i",
"++",
"{",
"length",
"+=",
"(",
"*",
"p",
")",
"[",
"i",
"-",
"1",
"]",
".",
"Distance",
"(",
"(",
"*",
"p",
")",
"[",
"i",
"]",
")",
"\n",
"}",
"\n",
"return",
"length",
"\n",
"}"
] | // Length returns the length of this Polyline. | [
"Length",
"returns",
"the",
"length",
"of",
"this",
"Polyline",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/polyline.go#L47-L54 |
150,151 | golang/geo | s2/polyline.go | Equal | func (p *Polyline) Equal(b *Polyline) bool {
if len(*p) != len(*b) {
return false
}
for i, v := range *p {
if v != (*b)[i] {
return false
}
}
return true
} | go | func (p *Polyline) Equal(b *Polyline) bool {
if len(*p) != len(*b) {
return false
}
for i, v := range *p {
if v != (*b)[i] {
return false
}
}
return true
} | [
"func",
"(",
"p",
"*",
"Polyline",
")",
"Equal",
"(",
"b",
"*",
"Polyline",
")",
"bool",
"{",
"if",
"len",
"(",
"*",
"p",
")",
"!=",
"len",
"(",
"*",
"b",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"for",
"i",
",",
"v",
":=",
"range",
"*",
"p",
"{",
"if",
"v",
"!=",
"(",
"*",
"b",
")",
"[",
"i",
"]",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"true",
"\n",
"}"
] | // Equal reports whether the given Polyline is exactly the same as this one. | [
"Equal",
"reports",
"whether",
"the",
"given",
"Polyline",
"is",
"exactly",
"the",
"same",
"as",
"this",
"one",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/polyline.go#L77-L88 |
150,152 | golang/geo | s2/polyline.go | RectBound | func (p *Polyline) RectBound() Rect {
rb := NewRectBounder()
for _, v := range *p {
rb.AddPoint(v)
}
return rb.RectBound()
} | go | func (p *Polyline) RectBound() Rect {
rb := NewRectBounder()
for _, v := range *p {
rb.AddPoint(v)
}
return rb.RectBound()
} | [
"func",
"(",
"p",
"*",
"Polyline",
")",
"RectBound",
"(",
")",
"Rect",
"{",
"rb",
":=",
"NewRectBounder",
"(",
")",
"\n",
"for",
"_",
",",
"v",
":=",
"range",
"*",
"p",
"{",
"rb",
".",
"AddPoint",
"(",
"v",
")",
"\n",
"}",
"\n",
"return",
"rb",
".",
"RectBound",
"(",
")",
"\n",
"}"
] | // RectBound returns the bounding Rect for this Polyline. | [
"RectBound",
"returns",
"the",
"bounding",
"Rect",
"for",
"this",
"Polyline",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/polyline.go#L96-L102 |
150,153 | golang/geo | s2/polyline.go | IntersectsCell | func (p *Polyline) IntersectsCell(cell Cell) bool {
if len(*p) == 0 {
return false
}
// We only need to check whether the cell contains vertex 0 for correctness,
// but these tests are cheap compared to edge crossings so we might as well
// check all the vertices.
for _, v := range *p {
if cell.ContainsPoint(v) {
return true
}
}
cellVertices := []Point{
cell.Vertex(0),
cell.Vertex(1),
cell.Vertex(2),
cell.Vertex(3),
}
for j := 0; j < 4; j++ {
crosser := NewChainEdgeCrosser(cellVertices[j], cellVertices[(j+1)&3], (*p)[0])
for i := 1; i < len(*p); i++ {
if crosser.ChainCrossingSign((*p)[i]) != DoNotCross {
// There is a proper crossing, or two vertices were the same.
return true
}
}
}
return false
} | go | func (p *Polyline) IntersectsCell(cell Cell) bool {
if len(*p) == 0 {
return false
}
// We only need to check whether the cell contains vertex 0 for correctness,
// but these tests are cheap compared to edge crossings so we might as well
// check all the vertices.
for _, v := range *p {
if cell.ContainsPoint(v) {
return true
}
}
cellVertices := []Point{
cell.Vertex(0),
cell.Vertex(1),
cell.Vertex(2),
cell.Vertex(3),
}
for j := 0; j < 4; j++ {
crosser := NewChainEdgeCrosser(cellVertices[j], cellVertices[(j+1)&3], (*p)[0])
for i := 1; i < len(*p); i++ {
if crosser.ChainCrossingSign((*p)[i]) != DoNotCross {
// There is a proper crossing, or two vertices were the same.
return true
}
}
}
return false
} | [
"func",
"(",
"p",
"*",
"Polyline",
")",
"IntersectsCell",
"(",
"cell",
"Cell",
")",
"bool",
"{",
"if",
"len",
"(",
"*",
"p",
")",
"==",
"0",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"// We only need to check whether the cell contains vertex 0 for correctness,",
"// but these tests are cheap compared to edge crossings so we might as well",
"// check all the vertices.",
"for",
"_",
",",
"v",
":=",
"range",
"*",
"p",
"{",
"if",
"cell",
".",
"ContainsPoint",
"(",
"v",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n\n",
"cellVertices",
":=",
"[",
"]",
"Point",
"{",
"cell",
".",
"Vertex",
"(",
"0",
")",
",",
"cell",
".",
"Vertex",
"(",
"1",
")",
",",
"cell",
".",
"Vertex",
"(",
"2",
")",
",",
"cell",
".",
"Vertex",
"(",
"3",
")",
",",
"}",
"\n\n",
"for",
"j",
":=",
"0",
";",
"j",
"<",
"4",
";",
"j",
"++",
"{",
"crosser",
":=",
"NewChainEdgeCrosser",
"(",
"cellVertices",
"[",
"j",
"]",
",",
"cellVertices",
"[",
"(",
"j",
"+",
"1",
")",
"&",
"3",
"]",
",",
"(",
"*",
"p",
")",
"[",
"0",
"]",
")",
"\n",
"for",
"i",
":=",
"1",
";",
"i",
"<",
"len",
"(",
"*",
"p",
")",
";",
"i",
"++",
"{",
"if",
"crosser",
".",
"ChainCrossingSign",
"(",
"(",
"*",
"p",
")",
"[",
"i",
"]",
")",
"!=",
"DoNotCross",
"{",
"// There is a proper crossing, or two vertices were the same.",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // IntersectsCell reports whether this Polyline intersects the given Cell. | [
"IntersectsCell",
"reports",
"whether",
"this",
"Polyline",
"intersects",
"the",
"given",
"Cell",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/polyline.go#L111-L142 |
150,154 | golang/geo | s2/polyline.go | ChainEdge | func (p *Polyline) ChainEdge(chainID, offset int) Edge {
return Edge{(*p)[offset], (*p)[offset+1]}
} | go | func (p *Polyline) ChainEdge(chainID, offset int) Edge {
return Edge{(*p)[offset], (*p)[offset+1]}
} | [
"func",
"(",
"p",
"*",
"Polyline",
")",
"ChainEdge",
"(",
"chainID",
",",
"offset",
"int",
")",
"Edge",
"{",
"return",
"Edge",
"{",
"(",
"*",
"p",
")",
"[",
"offset",
"]",
",",
"(",
"*",
"p",
")",
"[",
"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/polyline.go#L183-L185 |
150,155 | golang/geo | s2/polyline.go | findEndVertex | func findEndVertex(p Polyline, tolerance s1.Angle, index int) int {
// The basic idea is to keep track of the "pie wedge" of angles
// from the starting vertex such that a ray from the starting
// vertex at that angle will pass through the discs of radius
// tolerance centered around all vertices processed so far.
//
// First we define a coordinate frame for the tangent and normal
// spaces at the starting vertex. Essentially this means picking
// three orthonormal vectors X,Y,Z such that X and Y span the
// tangent plane at the starting vertex, and Z is up. We use
// the coordinate frame to define a mapping from 3D direction
// vectors to a one-dimensional ray angle in the range (-π,
// π]. The angle of a direction vector is computed by
// transforming it into the X,Y,Z basis, and then calculating
// atan2(y,x). This mapping allows us to represent a wedge of
// angles as a 1D interval. Since the interval wraps around, we
// represent it as an Interval, i.e. an interval on the unit
// circle.
origin := p[index]
frame := getFrame(origin)
// As we go along, we keep track of the current wedge of angles
// and the distance to the last vertex (which must be
// non-decreasing).
currentWedge := s1.FullInterval()
var lastDistance s1.Angle
for index++; index < len(p); index++ {
candidate := p[index]
distance := origin.Distance(candidate)
// We don't allow simplification to create edges longer than
// 90 degrees, to avoid numeric instability as lengths
// approach 180 degrees. We do need to allow for original
// edges longer than 90 degrees, though.
if distance > math.Pi/2 && lastDistance > 0 {
break
}
// Vertices must be in increasing order along the ray, except
// for the initial disc around the origin.
if distance < lastDistance && lastDistance > tolerance {
break
}
lastDistance = distance
// Points that are within the tolerance distance of the origin
// do not constrain the ray direction, so we can ignore them.
if distance <= tolerance {
continue
}
// If the current wedge of angles does not contain the angle
// to this vertex, then stop right now. Note that the wedge
// of possible ray angles is not necessarily empty yet, but we
// can't continue unless we are willing to backtrack to the
// last vertex that was contained within the wedge (since we
// don't create new vertices). This would be more complicated
// and also make the worst-case running time more than linear.
direction := toFrame(frame, candidate)
center := math.Atan2(direction.Y, direction.X)
if !currentWedge.Contains(center) {
break
}
// To determine how this vertex constrains the possible ray
// angles, consider the triangle ABC where A is the origin, B
// is the candidate vertex, and C is one of the two tangent
// points between A and the spherical cap of radius
// tolerance centered at B. Then from the spherical law of
// sines, sin(a)/sin(A) = sin(c)/sin(C), where a and c are
// the lengths of the edges opposite A and C. In our case C
// is a 90 degree angle, therefore A = asin(sin(a) / sin(c)).
// Angle A is the half-angle of the allowable wedge.
halfAngle := math.Asin(math.Sin(tolerance.Radians()) / math.Sin(distance.Radians()))
target := s1.IntervalFromPointPair(center, center).Expanded(halfAngle)
currentWedge = currentWedge.Intersection(target)
}
// We break out of the loop when we reach a vertex index that
// can't be included in the line segment, so back up by one
// vertex.
return index - 1
} | go | func findEndVertex(p Polyline, tolerance s1.Angle, index int) int {
// The basic idea is to keep track of the "pie wedge" of angles
// from the starting vertex such that a ray from the starting
// vertex at that angle will pass through the discs of radius
// tolerance centered around all vertices processed so far.
//
// First we define a coordinate frame for the tangent and normal
// spaces at the starting vertex. Essentially this means picking
// three orthonormal vectors X,Y,Z such that X and Y span the
// tangent plane at the starting vertex, and Z is up. We use
// the coordinate frame to define a mapping from 3D direction
// vectors to a one-dimensional ray angle in the range (-π,
// π]. The angle of a direction vector is computed by
// transforming it into the X,Y,Z basis, and then calculating
// atan2(y,x). This mapping allows us to represent a wedge of
// angles as a 1D interval. Since the interval wraps around, we
// represent it as an Interval, i.e. an interval on the unit
// circle.
origin := p[index]
frame := getFrame(origin)
// As we go along, we keep track of the current wedge of angles
// and the distance to the last vertex (which must be
// non-decreasing).
currentWedge := s1.FullInterval()
var lastDistance s1.Angle
for index++; index < len(p); index++ {
candidate := p[index]
distance := origin.Distance(candidate)
// We don't allow simplification to create edges longer than
// 90 degrees, to avoid numeric instability as lengths
// approach 180 degrees. We do need to allow for original
// edges longer than 90 degrees, though.
if distance > math.Pi/2 && lastDistance > 0 {
break
}
// Vertices must be in increasing order along the ray, except
// for the initial disc around the origin.
if distance < lastDistance && lastDistance > tolerance {
break
}
lastDistance = distance
// Points that are within the tolerance distance of the origin
// do not constrain the ray direction, so we can ignore them.
if distance <= tolerance {
continue
}
// If the current wedge of angles does not contain the angle
// to this vertex, then stop right now. Note that the wedge
// of possible ray angles is not necessarily empty yet, but we
// can't continue unless we are willing to backtrack to the
// last vertex that was contained within the wedge (since we
// don't create new vertices). This would be more complicated
// and also make the worst-case running time more than linear.
direction := toFrame(frame, candidate)
center := math.Atan2(direction.Y, direction.X)
if !currentWedge.Contains(center) {
break
}
// To determine how this vertex constrains the possible ray
// angles, consider the triangle ABC where A is the origin, B
// is the candidate vertex, and C is one of the two tangent
// points between A and the spherical cap of radius
// tolerance centered at B. Then from the spherical law of
// sines, sin(a)/sin(A) = sin(c)/sin(C), where a and c are
// the lengths of the edges opposite A and C. In our case C
// is a 90 degree angle, therefore A = asin(sin(a) / sin(c)).
// Angle A is the half-angle of the allowable wedge.
halfAngle := math.Asin(math.Sin(tolerance.Radians()) / math.Sin(distance.Radians()))
target := s1.IntervalFromPointPair(center, center).Expanded(halfAngle)
currentWedge = currentWedge.Intersection(target)
}
// We break out of the loop when we reach a vertex index that
// can't be included in the line segment, so back up by one
// vertex.
return index - 1
} | [
"func",
"findEndVertex",
"(",
"p",
"Polyline",
",",
"tolerance",
"s1",
".",
"Angle",
",",
"index",
"int",
")",
"int",
"{",
"// The basic idea is to keep track of the \"pie wedge\" of angles",
"// from the starting vertex such that a ray from the starting",
"// vertex at that angle will pass through the discs of radius",
"// tolerance centered around all vertices processed so far.",
"//",
"// First we define a coordinate frame for the tangent and normal",
"// spaces at the starting vertex. Essentially this means picking",
"// three orthonormal vectors X,Y,Z such that X and Y span the",
"// tangent plane at the starting vertex, and Z is up. We use",
"// the coordinate frame to define a mapping from 3D direction",
"// vectors to a one-dimensional ray angle in the range (-π,",
"// π]. The angle of a direction vector is computed by",
"// transforming it into the X,Y,Z basis, and then calculating",
"// atan2(y,x). This mapping allows us to represent a wedge of",
"// angles as a 1D interval. Since the interval wraps around, we",
"// represent it as an Interval, i.e. an interval on the unit",
"// circle.",
"origin",
":=",
"p",
"[",
"index",
"]",
"\n",
"frame",
":=",
"getFrame",
"(",
"origin",
")",
"\n\n",
"// As we go along, we keep track of the current wedge of angles",
"// and the distance to the last vertex (which must be",
"// non-decreasing).",
"currentWedge",
":=",
"s1",
".",
"FullInterval",
"(",
")",
"\n",
"var",
"lastDistance",
"s1",
".",
"Angle",
"\n\n",
"for",
"index",
"++",
";",
"index",
"<",
"len",
"(",
"p",
")",
";",
"index",
"++",
"{",
"candidate",
":=",
"p",
"[",
"index",
"]",
"\n",
"distance",
":=",
"origin",
".",
"Distance",
"(",
"candidate",
")",
"\n\n",
"// We don't allow simplification to create edges longer than",
"// 90 degrees, to avoid numeric instability as lengths",
"// approach 180 degrees. We do need to allow for original",
"// edges longer than 90 degrees, though.",
"if",
"distance",
">",
"math",
".",
"Pi",
"/",
"2",
"&&",
"lastDistance",
">",
"0",
"{",
"break",
"\n",
"}",
"\n\n",
"// Vertices must be in increasing order along the ray, except",
"// for the initial disc around the origin.",
"if",
"distance",
"<",
"lastDistance",
"&&",
"lastDistance",
">",
"tolerance",
"{",
"break",
"\n",
"}",
"\n\n",
"lastDistance",
"=",
"distance",
"\n\n",
"// Points that are within the tolerance distance of the origin",
"// do not constrain the ray direction, so we can ignore them.",
"if",
"distance",
"<=",
"tolerance",
"{",
"continue",
"\n",
"}",
"\n\n",
"// If the current wedge of angles does not contain the angle",
"// to this vertex, then stop right now. Note that the wedge",
"// of possible ray angles is not necessarily empty yet, but we",
"// can't continue unless we are willing to backtrack to the",
"// last vertex that was contained within the wedge (since we",
"// don't create new vertices). This would be more complicated",
"// and also make the worst-case running time more than linear.",
"direction",
":=",
"toFrame",
"(",
"frame",
",",
"candidate",
")",
"\n",
"center",
":=",
"math",
".",
"Atan2",
"(",
"direction",
".",
"Y",
",",
"direction",
".",
"X",
")",
"\n",
"if",
"!",
"currentWedge",
".",
"Contains",
"(",
"center",
")",
"{",
"break",
"\n",
"}",
"\n\n",
"// To determine how this vertex constrains the possible ray",
"// angles, consider the triangle ABC where A is the origin, B",
"// is the candidate vertex, and C is one of the two tangent",
"// points between A and the spherical cap of radius",
"// tolerance centered at B. Then from the spherical law of",
"// sines, sin(a)/sin(A) = sin(c)/sin(C), where a and c are",
"// the lengths of the edges opposite A and C. In our case C",
"// is a 90 degree angle, therefore A = asin(sin(a) / sin(c)).",
"// Angle A is the half-angle of the allowable wedge.",
"halfAngle",
":=",
"math",
".",
"Asin",
"(",
"math",
".",
"Sin",
"(",
"tolerance",
".",
"Radians",
"(",
")",
")",
"/",
"math",
".",
"Sin",
"(",
"distance",
".",
"Radians",
"(",
")",
")",
")",
"\n",
"target",
":=",
"s1",
".",
"IntervalFromPointPair",
"(",
"center",
",",
"center",
")",
".",
"Expanded",
"(",
"halfAngle",
")",
"\n",
"currentWedge",
"=",
"currentWedge",
".",
"Intersection",
"(",
"target",
")",
"\n",
"}",
"\n\n",
"// We break out of the loop when we reach a vertex index that",
"// can't be included in the line segment, so back up by one",
"// vertex.",
"return",
"index",
"-",
"1",
"\n",
"}"
] | // findEndVertex reports the maximal end index such that the line segment between
// the start index and this one such that the line segment between these two
// vertices passes within the given tolerance of all interior vertices, in order. | [
"findEndVertex",
"reports",
"the",
"maximal",
"end",
"index",
"such",
"that",
"the",
"line",
"segment",
"between",
"the",
"start",
"index",
"and",
"this",
"one",
"such",
"that",
"the",
"line",
"segment",
"between",
"these",
"two",
"vertices",
"passes",
"within",
"the",
"given",
"tolerance",
"of",
"all",
"interior",
"vertices",
"in",
"order",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/polyline.go#L206-L290 |
150,156 | golang/geo | s2/polyline.go | Encode | func (p Polyline) Encode(w io.Writer) error {
e := &encoder{w: w}
p.encode(e)
return e.err
} | go | func (p Polyline) Encode(w io.Writer) error {
e := &encoder{w: w}
p.encode(e)
return e.err
} | [
"func",
"(",
"p",
"Polyline",
")",
"Encode",
"(",
"w",
"io",
".",
"Writer",
")",
"error",
"{",
"e",
":=",
"&",
"encoder",
"{",
"w",
":",
"w",
"}",
"\n",
"p",
".",
"encode",
"(",
"e",
")",
"\n",
"return",
"e",
".",
"err",
"\n",
"}"
] | // Encode encodes the Polyline. | [
"Encode",
"encodes",
"the",
"Polyline",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/polyline.go#L336-L340 |
150,157 | golang/geo | s2/polyline.go | Decode | func (p *Polyline) Decode(r io.Reader) error {
d := decoder{r: asByteReader(r)}
p.decode(d)
return d.err
} | go | func (p *Polyline) Decode(r io.Reader) error {
d := decoder{r: asByteReader(r)}
p.decode(d)
return d.err
} | [
"func",
"(",
"p",
"*",
"Polyline",
")",
"Decode",
"(",
"r",
"io",
".",
"Reader",
")",
"error",
"{",
"d",
":=",
"decoder",
"{",
"r",
":",
"asByteReader",
"(",
"r",
")",
"}",
"\n",
"p",
".",
"decode",
"(",
"d",
")",
"\n",
"return",
"d",
".",
"err",
"\n",
"}"
] | // Decode decodes the polyline. | [
"Decode",
"decodes",
"the",
"polyline",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/polyline.go#L353-L357 |
150,158 | golang/geo | s2/polyline.go | IsOnRight | func (p *Polyline) IsOnRight(point Point) bool {
// If the closest point C is an interior vertex of the polyline, let B and D
// be the previous and next vertices. The given point P is on the right of
// the polyline (locally) if B, P, D are ordered CCW around vertex C.
closest, next := p.Project(point)
if closest == (*p)[next-1] && next > 1 && next < len(*p) {
if point == (*p)[next-1] {
// Polyline vertices are not on the RHS.
return false
}
return OrderedCCW((*p)[next-2], point, (*p)[next], (*p)[next-1])
}
// Otherwise, the closest point C is incident to exactly one polyline edge.
// We test the point P against that edge.
if next == len(*p) {
next--
}
return Sign(point, (*p)[next], (*p)[next-1])
} | go | func (p *Polyline) IsOnRight(point Point) bool {
// If the closest point C is an interior vertex of the polyline, let B and D
// be the previous and next vertices. The given point P is on the right of
// the polyline (locally) if B, P, D are ordered CCW around vertex C.
closest, next := p.Project(point)
if closest == (*p)[next-1] && next > 1 && next < len(*p) {
if point == (*p)[next-1] {
// Polyline vertices are not on the RHS.
return false
}
return OrderedCCW((*p)[next-2], point, (*p)[next], (*p)[next-1])
}
// Otherwise, the closest point C is incident to exactly one polyline edge.
// We test the point P against that edge.
if next == len(*p) {
next--
}
return Sign(point, (*p)[next], (*p)[next-1])
} | [
"func",
"(",
"p",
"*",
"Polyline",
")",
"IsOnRight",
"(",
"point",
"Point",
")",
"bool",
"{",
"// If the closest point C is an interior vertex of the polyline, let B and D",
"// be the previous and next vertices. The given point P is on the right of",
"// the polyline (locally) if B, P, D are ordered CCW around vertex C.",
"closest",
",",
"next",
":=",
"p",
".",
"Project",
"(",
"point",
")",
"\n",
"if",
"closest",
"==",
"(",
"*",
"p",
")",
"[",
"next",
"-",
"1",
"]",
"&&",
"next",
">",
"1",
"&&",
"next",
"<",
"len",
"(",
"*",
"p",
")",
"{",
"if",
"point",
"==",
"(",
"*",
"p",
")",
"[",
"next",
"-",
"1",
"]",
"{",
"// Polyline vertices are not on the RHS.",
"return",
"false",
"\n",
"}",
"\n",
"return",
"OrderedCCW",
"(",
"(",
"*",
"p",
")",
"[",
"next",
"-",
"2",
"]",
",",
"point",
",",
"(",
"*",
"p",
")",
"[",
"next",
"]",
",",
"(",
"*",
"p",
")",
"[",
"next",
"-",
"1",
"]",
")",
"\n",
"}",
"\n",
"// Otherwise, the closest point C is incident to exactly one polyline edge.",
"// We test the point P against that edge.",
"if",
"next",
"==",
"len",
"(",
"*",
"p",
")",
"{",
"next",
"--",
"\n",
"}",
"\n",
"return",
"Sign",
"(",
"point",
",",
"(",
"*",
"p",
")",
"[",
"next",
"]",
",",
"(",
"*",
"p",
")",
"[",
"next",
"-",
"1",
"]",
")",
"\n",
"}"
] | // IsOnRight reports whether the point given is on the right hand side of the
// polyline, using a naive definition of "right-hand-sideness" where the point
// is on the RHS of the polyline iff the point is on the RHS of the line segment
// in the polyline which it is closest to.
// The polyline must have at least 2 vertices. | [
"IsOnRight",
"reports",
"whether",
"the",
"point",
"given",
"is",
"on",
"the",
"right",
"hand",
"side",
"of",
"the",
"polyline",
"using",
"a",
"naive",
"definition",
"of",
"right",
"-",
"hand",
"-",
"sideness",
"where",
"the",
"point",
"is",
"on",
"the",
"RHS",
"of",
"the",
"polyline",
"iff",
"the",
"point",
"is",
"on",
"the",
"RHS",
"of",
"the",
"line",
"segment",
"in",
"the",
"polyline",
"which",
"it",
"is",
"closest",
"to",
".",
"The",
"polyline",
"must",
"have",
"at",
"least",
"2",
"vertices",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/polyline.go#L420-L438 |
150,159 | golang/geo | s2/polyline.go | Validate | func (p *Polyline) Validate() error {
// All vertices must be unit length.
for i, pt := range *p {
if !pt.IsUnit() {
return fmt.Errorf("vertex %d is not unit length", i)
}
}
// Adjacent vertices must not be identical or antipodal.
for i := 1; i < len(*p); i++ {
prev, cur := (*p)[i-1], (*p)[i]
if prev == cur {
return fmt.Errorf("vertices %d and %d are identical", i-1, i)
}
if prev == (Point{cur.Mul(-1)}) {
return fmt.Errorf("vertices %d and %d are antipodal", i-1, i)
}
}
return nil
} | go | func (p *Polyline) Validate() error {
// All vertices must be unit length.
for i, pt := range *p {
if !pt.IsUnit() {
return fmt.Errorf("vertex %d is not unit length", i)
}
}
// Adjacent vertices must not be identical or antipodal.
for i := 1; i < len(*p); i++ {
prev, cur := (*p)[i-1], (*p)[i]
if prev == cur {
return fmt.Errorf("vertices %d and %d are identical", i-1, i)
}
if prev == (Point{cur.Mul(-1)}) {
return fmt.Errorf("vertices %d and %d are antipodal", i-1, i)
}
}
return nil
} | [
"func",
"(",
"p",
"*",
"Polyline",
")",
"Validate",
"(",
")",
"error",
"{",
"// All vertices must be unit length.",
"for",
"i",
",",
"pt",
":=",
"range",
"*",
"p",
"{",
"if",
"!",
"pt",
".",
"IsUnit",
"(",
")",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"i",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Adjacent vertices must not be identical or antipodal.",
"for",
"i",
":=",
"1",
";",
"i",
"<",
"len",
"(",
"*",
"p",
")",
";",
"i",
"++",
"{",
"prev",
",",
"cur",
":=",
"(",
"*",
"p",
")",
"[",
"i",
"-",
"1",
"]",
",",
"(",
"*",
"p",
")",
"[",
"i",
"]",
"\n",
"if",
"prev",
"==",
"cur",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"i",
"-",
"1",
",",
"i",
")",
"\n",
"}",
"\n",
"if",
"prev",
"==",
"(",
"Point",
"{",
"cur",
".",
"Mul",
"(",
"-",
"1",
")",
"}",
")",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"i",
"-",
"1",
",",
"i",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Validate checks whether this is a valid polyline or not. | [
"Validate",
"checks",
"whether",
"this",
"is",
"a",
"valid",
"polyline",
"or",
"not",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/polyline.go#L441-L461 |
150,160 | golang/geo | s2/edge_crossings.go | EdgeOrVertexCrossing | func EdgeOrVertexCrossing(a, b, c, d Point) bool {
switch CrossingSign(a, b, c, d) {
case DoNotCross:
return false
case Cross:
return true
default:
return VertexCrossing(a, b, c, d)
}
} | go | func EdgeOrVertexCrossing(a, b, c, d Point) bool {
switch CrossingSign(a, b, c, d) {
case DoNotCross:
return false
case Cross:
return true
default:
return VertexCrossing(a, b, c, d)
}
} | [
"func",
"EdgeOrVertexCrossing",
"(",
"a",
",",
"b",
",",
"c",
",",
"d",
"Point",
")",
"bool",
"{",
"switch",
"CrossingSign",
"(",
"a",
",",
"b",
",",
"c",
",",
"d",
")",
"{",
"case",
"DoNotCross",
":",
"return",
"false",
"\n",
"case",
"Cross",
":",
"return",
"true",
"\n",
"default",
":",
"return",
"VertexCrossing",
"(",
"a",
",",
"b",
",",
"c",
",",
"d",
")",
"\n",
"}",
"\n",
"}"
] | // EdgeOrVertexCrossing is a convenience function that calls CrossingSign to
// handle cases where all four vertices are distinct, and VertexCrossing to
// handle cases where two or more vertices are the same. This defines a crossing
// function such that point-in-polygon containment tests can be implemented
// by simply counting edge crossings. | [
"EdgeOrVertexCrossing",
"is",
"a",
"convenience",
"function",
"that",
"calls",
"CrossingSign",
"to",
"handle",
"cases",
"where",
"all",
"four",
"vertices",
"are",
"distinct",
"and",
"VertexCrossing",
"to",
"handle",
"cases",
"where",
"two",
"or",
"more",
"vertices",
"are",
"the",
"same",
".",
"This",
"defines",
"a",
"crossing",
"function",
"such",
"that",
"point",
"-",
"in",
"-",
"polygon",
"containment",
"tests",
"can",
"be",
"implemented",
"by",
"simply",
"counting",
"edge",
"crossings",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/edge_crossings.go#L149-L158 |
150,161 | golang/geo | s2/edge_crossings.go | robustNormalWithLength | func robustNormalWithLength(x, y r3.Vector) (r3.Vector, float64) {
var pt r3.Vector
// This computes 2 * (x.Cross(y)), but has much better numerical
// stability when x and y are unit length.
tmp := x.Sub(y).Cross(x.Add(y))
length := tmp.Norm()
if length != 0 {
pt = tmp.Mul(1 / length)
}
return pt, 0.5 * length // Since tmp == 2 * (x.Cross(y))
} | go | func robustNormalWithLength(x, y r3.Vector) (r3.Vector, float64) {
var pt r3.Vector
// This computes 2 * (x.Cross(y)), but has much better numerical
// stability when x and y are unit length.
tmp := x.Sub(y).Cross(x.Add(y))
length := tmp.Norm()
if length != 0 {
pt = tmp.Mul(1 / length)
}
return pt, 0.5 * length // Since tmp == 2 * (x.Cross(y))
} | [
"func",
"robustNormalWithLength",
"(",
"x",
",",
"y",
"r3",
".",
"Vector",
")",
"(",
"r3",
".",
"Vector",
",",
"float64",
")",
"{",
"var",
"pt",
"r3",
".",
"Vector",
"\n",
"// This computes 2 * (x.Cross(y)), but has much better numerical",
"// stability when x and y are unit length.",
"tmp",
":=",
"x",
".",
"Sub",
"(",
"y",
")",
".",
"Cross",
"(",
"x",
".",
"Add",
"(",
"y",
")",
")",
"\n",
"length",
":=",
"tmp",
".",
"Norm",
"(",
")",
"\n",
"if",
"length",
"!=",
"0",
"{",
"pt",
"=",
"tmp",
".",
"Mul",
"(",
"1",
"/",
"length",
")",
"\n",
"}",
"\n",
"return",
"pt",
",",
"0.5",
"*",
"length",
"// Since tmp == 2 * (x.Cross(y))",
"\n",
"}"
] | // Computes the cross product of two vectors, normalized to be unit length.
// Also returns the length of the cross
// product before normalization, which is useful for estimating the amount of
// error in the result. For numerical stability, the vectors should both be
// approximately unit length. | [
"Computes",
"the",
"cross",
"product",
"of",
"two",
"vectors",
"normalized",
"to",
"be",
"unit",
"length",
".",
"Also",
"returns",
"the",
"length",
"of",
"the",
"cross",
"product",
"before",
"normalization",
"which",
"is",
"useful",
"for",
"estimating",
"the",
"amount",
"of",
"error",
"in",
"the",
"result",
".",
"For",
"numerical",
"stability",
"the",
"vectors",
"should",
"both",
"be",
"approximately",
"unit",
"length",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/edge_crossings.go#L211-L221 |
150,162 | golang/geo | s2/stuv.go | siTiToST | func siTiToST(si uint32) float64 {
if si > maxSiTi {
return 1.0
}
return float64(si) / float64(maxSiTi)
} | go | func siTiToST(si uint32) float64 {
if si > maxSiTi {
return 1.0
}
return float64(si) / float64(maxSiTi)
} | [
"func",
"siTiToST",
"(",
"si",
"uint32",
")",
"float64",
"{",
"if",
"si",
">",
"maxSiTi",
"{",
"return",
"1.0",
"\n",
"}",
"\n",
"return",
"float64",
"(",
"si",
")",
"/",
"float64",
"(",
"maxSiTi",
")",
"\n",
"}"
] | // siTiToST converts an si- or ti-value to the corresponding s- or t-value.
// Value is capped at 1.0 because there is no DCHECK in Go. | [
"siTiToST",
"converts",
"an",
"si",
"-",
"or",
"ti",
"-",
"value",
"to",
"the",
"corresponding",
"s",
"-",
"or",
"t",
"-",
"value",
".",
"Value",
"is",
"capped",
"at",
"1",
".",
"0",
"because",
"there",
"is",
"no",
"DCHECK",
"in",
"Go",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/stuv.go#L155-L160 |
150,163 | golang/geo | s2/stuv.go | faceUVToXYZ | func faceUVToXYZ(face int, u, v float64) r3.Vector {
switch face {
case 0:
return r3.Vector{1, u, v}
case 1:
return r3.Vector{-u, 1, v}
case 2:
return r3.Vector{-u, -v, 1}
case 3:
return r3.Vector{-1, -v, -u}
case 4:
return r3.Vector{v, -1, -u}
default:
return r3.Vector{v, u, -1}
}
} | go | func faceUVToXYZ(face int, u, v float64) r3.Vector {
switch face {
case 0:
return r3.Vector{1, u, v}
case 1:
return r3.Vector{-u, 1, v}
case 2:
return r3.Vector{-u, -v, 1}
case 3:
return r3.Vector{-1, -v, -u}
case 4:
return r3.Vector{v, -1, -u}
default:
return r3.Vector{v, u, -1}
}
} | [
"func",
"faceUVToXYZ",
"(",
"face",
"int",
",",
"u",
",",
"v",
"float64",
")",
"r3",
".",
"Vector",
"{",
"switch",
"face",
"{",
"case",
"0",
":",
"return",
"r3",
".",
"Vector",
"{",
"1",
",",
"u",
",",
"v",
"}",
"\n",
"case",
"1",
":",
"return",
"r3",
".",
"Vector",
"{",
"-",
"u",
",",
"1",
",",
"v",
"}",
"\n",
"case",
"2",
":",
"return",
"r3",
".",
"Vector",
"{",
"-",
"u",
",",
"-",
"v",
",",
"1",
"}",
"\n",
"case",
"3",
":",
"return",
"r3",
".",
"Vector",
"{",
"-",
"1",
",",
"-",
"v",
",",
"-",
"u",
"}",
"\n",
"case",
"4",
":",
"return",
"r3",
".",
"Vector",
"{",
"v",
",",
"-",
"1",
",",
"-",
"u",
"}",
"\n",
"default",
":",
"return",
"r3",
".",
"Vector",
"{",
"v",
",",
"u",
",",
"-",
"1",
"}",
"\n",
"}",
"\n",
"}"
] | // faceUVToXYZ turns face and UV coordinates into an unnormalized 3 vector. | [
"faceUVToXYZ",
"turns",
"face",
"and",
"UV",
"coordinates",
"into",
"an",
"unnormalized",
"3",
"vector",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/stuv.go#L236-L251 |
150,164 | golang/geo | s2/centroids.go | PlanarCentroid | func PlanarCentroid(a, b, c Point) Point {
return Point{a.Add(b.Vector).Add(c.Vector).Mul(1. / 3)}
} | go | func PlanarCentroid(a, b, c Point) Point {
return Point{a.Add(b.Vector).Add(c.Vector).Mul(1. / 3)}
} | [
"func",
"PlanarCentroid",
"(",
"a",
",",
"b",
",",
"c",
"Point",
")",
"Point",
"{",
"return",
"Point",
"{",
"a",
".",
"Add",
"(",
"b",
".",
"Vector",
")",
".",
"Add",
"(",
"c",
".",
"Vector",
")",
".",
"Mul",
"(",
"1.",
"/",
"3",
")",
"}",
"\n",
"}"
] | // PlanarCentroid returns the centroid of the planar triangle ABC. This can be
// normalized to unit length to obtain the "surface centroid" of the corresponding
// spherical triangle, i.e. the intersection of the three medians. However, note
// that for large spherical triangles the surface centroid may be nowhere near
// the intuitive "center". | [
"PlanarCentroid",
"returns",
"the",
"centroid",
"of",
"the",
"planar",
"triangle",
"ABC",
".",
"This",
"can",
"be",
"normalized",
"to",
"unit",
"length",
"to",
"obtain",
"the",
"surface",
"centroid",
"of",
"the",
"corresponding",
"spherical",
"triangle",
"i",
".",
"e",
".",
"the",
"intersection",
"of",
"the",
"three",
"medians",
".",
"However",
"note",
"that",
"for",
"large",
"spherical",
"triangles",
"the",
"surface",
"centroid",
"may",
"be",
"nowhere",
"near",
"the",
"intuitive",
"center",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/centroids.go#L131-L133 |
150,165 | golang/geo | s2/loop.go | LoopFromPoints | func LoopFromPoints(pts []Point) *Loop {
l := &Loop{
vertices: pts,
}
l.initOriginAndBound()
return l
} | go | func LoopFromPoints(pts []Point) *Loop {
l := &Loop{
vertices: pts,
}
l.initOriginAndBound()
return l
} | [
"func",
"LoopFromPoints",
"(",
"pts",
"[",
"]",
"Point",
")",
"*",
"Loop",
"{",
"l",
":=",
"&",
"Loop",
"{",
"vertices",
":",
"pts",
",",
"}",
"\n\n",
"l",
".",
"initOriginAndBound",
"(",
")",
"\n",
"return",
"l",
"\n",
"}"
] | // LoopFromPoints constructs a loop from the given points. | [
"LoopFromPoints",
"constructs",
"a",
"loop",
"from",
"the",
"given",
"points",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/loop.go#L72-L79 |
150,166 | golang/geo | s2/loop.go | initOriginAndBound | func (l *Loop) initOriginAndBound() {
if len(l.vertices) < 3 {
// Check for the special "empty" and "full" loops (which have one vertex).
if !l.isEmptyOrFull() {
l.originInside = false
return
}
// This is the special empty or full loop, so the origin depends on if
// the vertex is in the southern hemisphere or not.
l.originInside = l.vertices[0].Z < 0
} else {
// Point containment testing is done by counting edge crossings starting
// at a fixed point on the sphere (OriginPoint). We need to know whether
// the reference point (OriginPoint) is inside or outside the loop before
// we can construct the ShapeIndex. We do this by first guessing that
// it is outside, and then seeing whether we get the correct containment
// result for vertex 1. If the result is incorrect, the origin must be
// inside the loop.
//
// A loop with consecutive vertices A,B,C contains vertex B if and only if
// the fixed vector R = B.Ortho is contained by the wedge ABC. The
// wedge is closed at A and open at C, i.e. the point B is inside the loop
// if A = R but not if C = R. This convention is required for compatibility
// with VertexCrossing. (Note that we can't use OriginPoint
// as the fixed vector because of the possibility that B == OriginPoint.)
l.originInside = false
v1Inside := OrderedCCW(Point{l.vertices[1].Ortho()}, l.vertices[0], l.vertices[2], l.vertices[1])
if v1Inside != l.ContainsPoint(l.vertices[1]) {
l.originInside = true
}
}
// We *must* call initBound before initializing the index, because
// initBound calls ContainsPoint which does a bounds check before using
// the index.
l.initBound()
// Create a new index and add us to it.
l.index = NewShapeIndex()
l.index.Add(l)
} | go | func (l *Loop) initOriginAndBound() {
if len(l.vertices) < 3 {
// Check for the special "empty" and "full" loops (which have one vertex).
if !l.isEmptyOrFull() {
l.originInside = false
return
}
// This is the special empty or full loop, so the origin depends on if
// the vertex is in the southern hemisphere or not.
l.originInside = l.vertices[0].Z < 0
} else {
// Point containment testing is done by counting edge crossings starting
// at a fixed point on the sphere (OriginPoint). We need to know whether
// the reference point (OriginPoint) is inside or outside the loop before
// we can construct the ShapeIndex. We do this by first guessing that
// it is outside, and then seeing whether we get the correct containment
// result for vertex 1. If the result is incorrect, the origin must be
// inside the loop.
//
// A loop with consecutive vertices A,B,C contains vertex B if and only if
// the fixed vector R = B.Ortho is contained by the wedge ABC. The
// wedge is closed at A and open at C, i.e. the point B is inside the loop
// if A = R but not if C = R. This convention is required for compatibility
// with VertexCrossing. (Note that we can't use OriginPoint
// as the fixed vector because of the possibility that B == OriginPoint.)
l.originInside = false
v1Inside := OrderedCCW(Point{l.vertices[1].Ortho()}, l.vertices[0], l.vertices[2], l.vertices[1])
if v1Inside != l.ContainsPoint(l.vertices[1]) {
l.originInside = true
}
}
// We *must* call initBound before initializing the index, because
// initBound calls ContainsPoint which does a bounds check before using
// the index.
l.initBound()
// Create a new index and add us to it.
l.index = NewShapeIndex()
l.index.Add(l)
} | [
"func",
"(",
"l",
"*",
"Loop",
")",
"initOriginAndBound",
"(",
")",
"{",
"if",
"len",
"(",
"l",
".",
"vertices",
")",
"<",
"3",
"{",
"// Check for the special \"empty\" and \"full\" loops (which have one vertex).",
"if",
"!",
"l",
".",
"isEmptyOrFull",
"(",
")",
"{",
"l",
".",
"originInside",
"=",
"false",
"\n",
"return",
"\n",
"}",
"\n\n",
"// This is the special empty or full loop, so the origin depends on if",
"// the vertex is in the southern hemisphere or not.",
"l",
".",
"originInside",
"=",
"l",
".",
"vertices",
"[",
"0",
"]",
".",
"Z",
"<",
"0",
"\n",
"}",
"else",
"{",
"// Point containment testing is done by counting edge crossings starting",
"// at a fixed point on the sphere (OriginPoint). We need to know whether",
"// the reference point (OriginPoint) is inside or outside the loop before",
"// we can construct the ShapeIndex. We do this by first guessing that",
"// it is outside, and then seeing whether we get the correct containment",
"// result for vertex 1. If the result is incorrect, the origin must be",
"// inside the loop.",
"//",
"// A loop with consecutive vertices A,B,C contains vertex B if and only if",
"// the fixed vector R = B.Ortho is contained by the wedge ABC. The",
"// wedge is closed at A and open at C, i.e. the point B is inside the loop",
"// if A = R but not if C = R. This convention is required for compatibility",
"// with VertexCrossing. (Note that we can't use OriginPoint",
"// as the fixed vector because of the possibility that B == OriginPoint.)",
"l",
".",
"originInside",
"=",
"false",
"\n",
"v1Inside",
":=",
"OrderedCCW",
"(",
"Point",
"{",
"l",
".",
"vertices",
"[",
"1",
"]",
".",
"Ortho",
"(",
")",
"}",
",",
"l",
".",
"vertices",
"[",
"0",
"]",
",",
"l",
".",
"vertices",
"[",
"2",
"]",
",",
"l",
".",
"vertices",
"[",
"1",
"]",
")",
"\n",
"if",
"v1Inside",
"!=",
"l",
".",
"ContainsPoint",
"(",
"l",
".",
"vertices",
"[",
"1",
"]",
")",
"{",
"l",
".",
"originInside",
"=",
"true",
"\n",
"}",
"\n",
"}",
"\n\n",
"// We *must* call initBound before initializing the index, because",
"// initBound calls ContainsPoint which does a bounds check before using",
"// the index.",
"l",
".",
"initBound",
"(",
")",
"\n\n",
"// Create a new index and add us to it.",
"l",
".",
"index",
"=",
"NewShapeIndex",
"(",
")",
"\n",
"l",
".",
"index",
".",
"Add",
"(",
"l",
")",
"\n",
"}"
] | // initOriginAndBound sets the origin containment for the given point and then calls
// the initialization for the bounds objects and the internal index. | [
"initOriginAndBound",
"sets",
"the",
"origin",
"containment",
"for",
"the",
"given",
"point",
"and",
"then",
"calls",
"the",
"initialization",
"for",
"the",
"bounds",
"objects",
"and",
"the",
"internal",
"index",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/loop.go#L123-L164 |
150,167 | golang/geo | s2/loop.go | initBound | func (l *Loop) initBound() {
// Check for the special "empty" and "full" loops.
if l.isEmptyOrFull() {
if l.IsEmpty() {
l.bound = EmptyRect()
} else {
l.bound = FullRect()
}
l.subregionBound = l.bound
return
}
// The bounding rectangle of a loop is not necessarily the same as the
// bounding rectangle of its vertices. First, the maximal latitude may be
// attained along the interior of an edge. Second, the loop may wrap
// entirely around the sphere (e.g. a loop that defines two revolutions of a
// candy-cane stripe). Third, the loop may include one or both poles.
// Note that a small clockwise loop near the equator contains both poles.
bounder := NewRectBounder()
for i := 0; i <= len(l.vertices); i++ { // add vertex 0 twice
bounder.AddPoint(l.Vertex(i))
}
b := bounder.RectBound()
if l.ContainsPoint(Point{r3.Vector{0, 0, 1}}) {
b = Rect{r1.Interval{b.Lat.Lo, math.Pi / 2}, s1.FullInterval()}
}
// If a loop contains the south pole, then either it wraps entirely
// around the sphere (full longitude range), or it also contains the
// north pole in which case b.Lng.IsFull() due to the test above.
// Either way, we only need to do the south pole containment test if
// b.Lng.IsFull().
if b.Lng.IsFull() && l.ContainsPoint(Point{r3.Vector{0, 0, -1}}) {
b.Lat.Lo = -math.Pi / 2
}
l.bound = b
l.subregionBound = ExpandForSubregions(l.bound)
} | go | func (l *Loop) initBound() {
// Check for the special "empty" and "full" loops.
if l.isEmptyOrFull() {
if l.IsEmpty() {
l.bound = EmptyRect()
} else {
l.bound = FullRect()
}
l.subregionBound = l.bound
return
}
// The bounding rectangle of a loop is not necessarily the same as the
// bounding rectangle of its vertices. First, the maximal latitude may be
// attained along the interior of an edge. Second, the loop may wrap
// entirely around the sphere (e.g. a loop that defines two revolutions of a
// candy-cane stripe). Third, the loop may include one or both poles.
// Note that a small clockwise loop near the equator contains both poles.
bounder := NewRectBounder()
for i := 0; i <= len(l.vertices); i++ { // add vertex 0 twice
bounder.AddPoint(l.Vertex(i))
}
b := bounder.RectBound()
if l.ContainsPoint(Point{r3.Vector{0, 0, 1}}) {
b = Rect{r1.Interval{b.Lat.Lo, math.Pi / 2}, s1.FullInterval()}
}
// If a loop contains the south pole, then either it wraps entirely
// around the sphere (full longitude range), or it also contains the
// north pole in which case b.Lng.IsFull() due to the test above.
// Either way, we only need to do the south pole containment test if
// b.Lng.IsFull().
if b.Lng.IsFull() && l.ContainsPoint(Point{r3.Vector{0, 0, -1}}) {
b.Lat.Lo = -math.Pi / 2
}
l.bound = b
l.subregionBound = ExpandForSubregions(l.bound)
} | [
"func",
"(",
"l",
"*",
"Loop",
")",
"initBound",
"(",
")",
"{",
"// Check for the special \"empty\" and \"full\" loops.",
"if",
"l",
".",
"isEmptyOrFull",
"(",
")",
"{",
"if",
"l",
".",
"IsEmpty",
"(",
")",
"{",
"l",
".",
"bound",
"=",
"EmptyRect",
"(",
")",
"\n",
"}",
"else",
"{",
"l",
".",
"bound",
"=",
"FullRect",
"(",
")",
"\n",
"}",
"\n",
"l",
".",
"subregionBound",
"=",
"l",
".",
"bound",
"\n",
"return",
"\n",
"}",
"\n\n",
"// The bounding rectangle of a loop is not necessarily the same as the",
"// bounding rectangle of its vertices. First, the maximal latitude may be",
"// attained along the interior of an edge. Second, the loop may wrap",
"// entirely around the sphere (e.g. a loop that defines two revolutions of a",
"// candy-cane stripe). Third, the loop may include one or both poles.",
"// Note that a small clockwise loop near the equator contains both poles.",
"bounder",
":=",
"NewRectBounder",
"(",
")",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<=",
"len",
"(",
"l",
".",
"vertices",
")",
";",
"i",
"++",
"{",
"// add vertex 0 twice",
"bounder",
".",
"AddPoint",
"(",
"l",
".",
"Vertex",
"(",
"i",
")",
")",
"\n",
"}",
"\n",
"b",
":=",
"bounder",
".",
"RectBound",
"(",
")",
"\n\n",
"if",
"l",
".",
"ContainsPoint",
"(",
"Point",
"{",
"r3",
".",
"Vector",
"{",
"0",
",",
"0",
",",
"1",
"}",
"}",
")",
"{",
"b",
"=",
"Rect",
"{",
"r1",
".",
"Interval",
"{",
"b",
".",
"Lat",
".",
"Lo",
",",
"math",
".",
"Pi",
"/",
"2",
"}",
",",
"s1",
".",
"FullInterval",
"(",
")",
"}",
"\n",
"}",
"\n",
"// If a loop contains the south pole, then either it wraps entirely",
"// around the sphere (full longitude range), or it also contains the",
"// north pole in which case b.Lng.IsFull() due to the test above.",
"// Either way, we only need to do the south pole containment test if",
"// b.Lng.IsFull().",
"if",
"b",
".",
"Lng",
".",
"IsFull",
"(",
")",
"&&",
"l",
".",
"ContainsPoint",
"(",
"Point",
"{",
"r3",
".",
"Vector",
"{",
"0",
",",
"0",
",",
"-",
"1",
"}",
"}",
")",
"{",
"b",
".",
"Lat",
".",
"Lo",
"=",
"-",
"math",
".",
"Pi",
"/",
"2",
"\n",
"}",
"\n",
"l",
".",
"bound",
"=",
"b",
"\n",
"l",
".",
"subregionBound",
"=",
"ExpandForSubregions",
"(",
"l",
".",
"bound",
")",
"\n",
"}"
] | // initBound sets up the approximate bounding Rects for this loop. | [
"initBound",
"sets",
"up",
"the",
"approximate",
"bounding",
"Rects",
"for",
"this",
"loop",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/loop.go#L167-L204 |
150,168 | golang/geo | s2/loop.go | Validate | func (l *Loop) Validate() error {
if err := l.findValidationErrorNoIndex(); err != nil {
return err
}
// Check for intersections between non-adjacent edges (including at vertices)
// TODO(roberts): Once shapeutil gets findAnyCrossing uncomment this.
// return findAnyCrossing(l.index)
return nil
} | go | func (l *Loop) Validate() error {
if err := l.findValidationErrorNoIndex(); err != nil {
return err
}
// Check for intersections between non-adjacent edges (including at vertices)
// TODO(roberts): Once shapeutil gets findAnyCrossing uncomment this.
// return findAnyCrossing(l.index)
return nil
} | [
"func",
"(",
"l",
"*",
"Loop",
")",
"Validate",
"(",
")",
"error",
"{",
"if",
"err",
":=",
"l",
".",
"findValidationErrorNoIndex",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// Check for intersections between non-adjacent edges (including at vertices)",
"// TODO(roberts): Once shapeutil gets findAnyCrossing uncomment this.",
"// return findAnyCrossing(l.index)",
"return",
"nil",
"\n",
"}"
] | // Validate checks whether this is a valid loop. | [
"Validate",
"checks",
"whether",
"this",
"is",
"a",
"valid",
"loop",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/loop.go#L207-L217 |
150,169 | golang/geo | s2/loop.go | findValidationErrorNoIndex | func (l *Loop) findValidationErrorNoIndex() error {
// All vertices must be unit length.
for i, v := range l.vertices {
if !v.IsUnit() {
return fmt.Errorf("vertex %d is not unit length", i)
}
}
// Loops must have at least 3 vertices (except for empty and full).
if len(l.vertices) < 3 {
if l.isEmptyOrFull() {
return nil // Skip remaining tests.
}
return fmt.Errorf("non-empty, non-full loops must have at least 3 vertices")
}
// Loops are not allowed to have any duplicate vertices or edge crossings.
// We split this check into two parts. First we check that no edge is
// degenerate (identical endpoints). Then we check that there are no
// intersections between non-adjacent edges (including at vertices). The
// second check needs the ShapeIndex, so it does not fall within the scope
// of this method.
for i, v := range l.vertices {
if v == l.Vertex(i+1) {
return fmt.Errorf("edge %d is degenerate (duplicate vertex)", i)
}
// Antipodal vertices are not allowed.
if other := (Point{l.Vertex(i + 1).Mul(-1)}); v == other {
return fmt.Errorf("vertices %d and %d are antipodal", i,
(i+1)%len(l.vertices))
}
}
return nil
} | go | func (l *Loop) findValidationErrorNoIndex() error {
// All vertices must be unit length.
for i, v := range l.vertices {
if !v.IsUnit() {
return fmt.Errorf("vertex %d is not unit length", i)
}
}
// Loops must have at least 3 vertices (except for empty and full).
if len(l.vertices) < 3 {
if l.isEmptyOrFull() {
return nil // Skip remaining tests.
}
return fmt.Errorf("non-empty, non-full loops must have at least 3 vertices")
}
// Loops are not allowed to have any duplicate vertices or edge crossings.
// We split this check into two parts. First we check that no edge is
// degenerate (identical endpoints). Then we check that there are no
// intersections between non-adjacent edges (including at vertices). The
// second check needs the ShapeIndex, so it does not fall within the scope
// of this method.
for i, v := range l.vertices {
if v == l.Vertex(i+1) {
return fmt.Errorf("edge %d is degenerate (duplicate vertex)", i)
}
// Antipodal vertices are not allowed.
if other := (Point{l.Vertex(i + 1).Mul(-1)}); v == other {
return fmt.Errorf("vertices %d and %d are antipodal", i,
(i+1)%len(l.vertices))
}
}
return nil
} | [
"func",
"(",
"l",
"*",
"Loop",
")",
"findValidationErrorNoIndex",
"(",
")",
"error",
"{",
"// All vertices must be unit length.",
"for",
"i",
",",
"v",
":=",
"range",
"l",
".",
"vertices",
"{",
"if",
"!",
"v",
".",
"IsUnit",
"(",
")",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"i",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Loops must have at least 3 vertices (except for empty and full).",
"if",
"len",
"(",
"l",
".",
"vertices",
")",
"<",
"3",
"{",
"if",
"l",
".",
"isEmptyOrFull",
"(",
")",
"{",
"return",
"nil",
"// Skip remaining tests.",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Loops are not allowed to have any duplicate vertices or edge crossings.",
"// We split this check into two parts. First we check that no edge is",
"// degenerate (identical endpoints). Then we check that there are no",
"// intersections between non-adjacent edges (including at vertices). The",
"// second check needs the ShapeIndex, so it does not fall within the scope",
"// of this method.",
"for",
"i",
",",
"v",
":=",
"range",
"l",
".",
"vertices",
"{",
"if",
"v",
"==",
"l",
".",
"Vertex",
"(",
"i",
"+",
"1",
")",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"i",
")",
"\n",
"}",
"\n\n",
"// Antipodal vertices are not allowed.",
"if",
"other",
":=",
"(",
"Point",
"{",
"l",
".",
"Vertex",
"(",
"i",
"+",
"1",
")",
".",
"Mul",
"(",
"-",
"1",
")",
"}",
")",
";",
"v",
"==",
"other",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"i",
",",
"(",
"i",
"+",
"1",
")",
"%",
"len",
"(",
"l",
".",
"vertices",
")",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // findValidationErrorNoIndex reports whether this is not a valid loop, but
// skips checks that would require a ShapeIndex to be built for the loop. This
// is primarily used by Polygon to do validation so it doesn't trigger the
// creation of unneeded ShapeIndices. | [
"findValidationErrorNoIndex",
"reports",
"whether",
"this",
"is",
"not",
"a",
"valid",
"loop",
"but",
"skips",
"checks",
"that",
"would",
"require",
"a",
"ShapeIndex",
"to",
"be",
"built",
"for",
"the",
"loop",
".",
"This",
"is",
"primarily",
"used",
"by",
"Polygon",
"to",
"do",
"validation",
"so",
"it",
"doesn",
"t",
"trigger",
"the",
"creation",
"of",
"unneeded",
"ShapeIndices",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/loop.go#L223-L258 |
150,170 | golang/geo | s2/loop.go | Contains | func (l *Loop) Contains(o *Loop) bool {
// For a loop A to contain the loop B, all of the following must
// be true:
//
// (1) There are no edge crossings between A and B except at vertices.
//
// (2) At every vertex that is shared between A and B, the local edge
// ordering implies that A contains B.
//
// (3) If there are no shared vertices, then A must contain a vertex of B
// and B must not contain a vertex of A. (An arbitrary vertex may be
// chosen in each case.)
//
// The second part of (3) is necessary to detect the case of two loops whose
// union is the entire sphere, i.e. two loops that contains each other's
// boundaries but not each other's interiors.
if !l.subregionBound.Contains(o.bound) {
return false
}
// Special cases to handle either loop being empty or full.
if l.isEmptyOrFull() || o.isEmptyOrFull() {
return l.IsFull() || o.IsEmpty()
}
// Check whether there are any edge crossings, and also check the loop
// relationship at any shared vertices.
relation := &containsRelation{}
if hasCrossingRelation(l, o, relation) {
return false
}
// There are no crossings, and if there are any shared vertices then A
// contains B locally at each shared vertex.
if relation.foundSharedVertex {
return true
}
// Since there are no edge intersections or shared vertices, we just need to
// test condition (3) above. We can skip this test if we discovered that A
// contains at least one point of B while checking for edge crossings.
if !l.ContainsPoint(o.Vertex(0)) {
return false
}
// We still need to check whether (A union B) is the entire sphere.
// Normally this check is very cheap due to the bounding box precondition.
if (o.subregionBound.Contains(l.bound) || o.bound.Union(l.bound).IsFull()) &&
o.ContainsPoint(l.Vertex(0)) {
return false
}
return true
} | go | func (l *Loop) Contains(o *Loop) bool {
// For a loop A to contain the loop B, all of the following must
// be true:
//
// (1) There are no edge crossings between A and B except at vertices.
//
// (2) At every vertex that is shared between A and B, the local edge
// ordering implies that A contains B.
//
// (3) If there are no shared vertices, then A must contain a vertex of B
// and B must not contain a vertex of A. (An arbitrary vertex may be
// chosen in each case.)
//
// The second part of (3) is necessary to detect the case of two loops whose
// union is the entire sphere, i.e. two loops that contains each other's
// boundaries but not each other's interiors.
if !l.subregionBound.Contains(o.bound) {
return false
}
// Special cases to handle either loop being empty or full.
if l.isEmptyOrFull() || o.isEmptyOrFull() {
return l.IsFull() || o.IsEmpty()
}
// Check whether there are any edge crossings, and also check the loop
// relationship at any shared vertices.
relation := &containsRelation{}
if hasCrossingRelation(l, o, relation) {
return false
}
// There are no crossings, and if there are any shared vertices then A
// contains B locally at each shared vertex.
if relation.foundSharedVertex {
return true
}
// Since there are no edge intersections or shared vertices, we just need to
// test condition (3) above. We can skip this test if we discovered that A
// contains at least one point of B while checking for edge crossings.
if !l.ContainsPoint(o.Vertex(0)) {
return false
}
// We still need to check whether (A union B) is the entire sphere.
// Normally this check is very cheap due to the bounding box precondition.
if (o.subregionBound.Contains(l.bound) || o.bound.Union(l.bound).IsFull()) &&
o.ContainsPoint(l.Vertex(0)) {
return false
}
return true
} | [
"func",
"(",
"l",
"*",
"Loop",
")",
"Contains",
"(",
"o",
"*",
"Loop",
")",
"bool",
"{",
"// For a loop A to contain the loop B, all of the following must",
"// be true:",
"//",
"// (1) There are no edge crossings between A and B except at vertices.",
"//",
"// (2) At every vertex that is shared between A and B, the local edge",
"// ordering implies that A contains B.",
"//",
"// (3) If there are no shared vertices, then A must contain a vertex of B",
"// and B must not contain a vertex of A. (An arbitrary vertex may be",
"// chosen in each case.)",
"//",
"// The second part of (3) is necessary to detect the case of two loops whose",
"// union is the entire sphere, i.e. two loops that contains each other's",
"// boundaries but not each other's interiors.",
"if",
"!",
"l",
".",
"subregionBound",
".",
"Contains",
"(",
"o",
".",
"bound",
")",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"// Special cases to handle either loop being empty or full.",
"if",
"l",
".",
"isEmptyOrFull",
"(",
")",
"||",
"o",
".",
"isEmptyOrFull",
"(",
")",
"{",
"return",
"l",
".",
"IsFull",
"(",
")",
"||",
"o",
".",
"IsEmpty",
"(",
")",
"\n",
"}",
"\n\n",
"// Check whether there are any edge crossings, and also check the loop",
"// relationship at any shared vertices.",
"relation",
":=",
"&",
"containsRelation",
"{",
"}",
"\n",
"if",
"hasCrossingRelation",
"(",
"l",
",",
"o",
",",
"relation",
")",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"// There are no crossings, and if there are any shared vertices then A",
"// contains B locally at each shared vertex.",
"if",
"relation",
".",
"foundSharedVertex",
"{",
"return",
"true",
"\n",
"}",
"\n\n",
"// Since there are no edge intersections or shared vertices, we just need to",
"// test condition (3) above. We can skip this test if we discovered that A",
"// contains at least one point of B while checking for edge crossings.",
"if",
"!",
"l",
".",
"ContainsPoint",
"(",
"o",
".",
"Vertex",
"(",
"0",
")",
")",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"// We still need to check whether (A union B) is the entire sphere.",
"// Normally this check is very cheap due to the bounding box precondition.",
"if",
"(",
"o",
".",
"subregionBound",
".",
"Contains",
"(",
"l",
".",
"bound",
")",
"||",
"o",
".",
"bound",
".",
"Union",
"(",
"l",
".",
"bound",
")",
".",
"IsFull",
"(",
")",
")",
"&&",
"o",
".",
"ContainsPoint",
"(",
"l",
".",
"Vertex",
"(",
"0",
")",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}"
] | // Contains reports whether the region contained by this loop is a superset of the
// region contained by the given other loop. | [
"Contains",
"reports",
"whether",
"the",
"region",
"contained",
"by",
"this",
"loop",
"is",
"a",
"superset",
"of",
"the",
"region",
"contained",
"by",
"the",
"given",
"other",
"loop",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/loop.go#L262-L314 |
150,171 | golang/geo | s2/loop.go | Intersects | func (l *Loop) Intersects(o *Loop) bool {
// Given two loops, A and B, A.Intersects(B) if and only if !A.Complement().Contains(B).
//
// This code is similar to Contains, but is optimized for the case
// where both loops enclose less than half of the sphere.
if !l.bound.Intersects(o.bound) {
return false
}
// Check whether there are any edge crossings, and also check the loop
// relationship at any shared vertices.
relation := &intersectsRelation{}
if hasCrossingRelation(l, o, relation) {
return true
}
if relation.foundSharedVertex {
return false
}
// Since there are no edge intersections or shared vertices, the loops
// intersect only if A contains B, B contains A, or the two loops contain
// each other's boundaries. These checks are usually cheap because of the
// bounding box preconditions. Note that neither loop is empty (because of
// the bounding box check above), so it is safe to access vertex(0).
// Check whether A contains B, or A and B contain each other's boundaries.
// (Note that A contains all the vertices of B in either case.)
if l.subregionBound.Contains(o.bound) || l.bound.Union(o.bound).IsFull() {
if l.ContainsPoint(o.Vertex(0)) {
return true
}
}
// Check whether B contains A.
if o.subregionBound.Contains(l.bound) {
if o.ContainsPoint(l.Vertex(0)) {
return true
}
}
return false
} | go | func (l *Loop) Intersects(o *Loop) bool {
// Given two loops, A and B, A.Intersects(B) if and only if !A.Complement().Contains(B).
//
// This code is similar to Contains, but is optimized for the case
// where both loops enclose less than half of the sphere.
if !l.bound.Intersects(o.bound) {
return false
}
// Check whether there are any edge crossings, and also check the loop
// relationship at any shared vertices.
relation := &intersectsRelation{}
if hasCrossingRelation(l, o, relation) {
return true
}
if relation.foundSharedVertex {
return false
}
// Since there are no edge intersections or shared vertices, the loops
// intersect only if A contains B, B contains A, or the two loops contain
// each other's boundaries. These checks are usually cheap because of the
// bounding box preconditions. Note that neither loop is empty (because of
// the bounding box check above), so it is safe to access vertex(0).
// Check whether A contains B, or A and B contain each other's boundaries.
// (Note that A contains all the vertices of B in either case.)
if l.subregionBound.Contains(o.bound) || l.bound.Union(o.bound).IsFull() {
if l.ContainsPoint(o.Vertex(0)) {
return true
}
}
// Check whether B contains A.
if o.subregionBound.Contains(l.bound) {
if o.ContainsPoint(l.Vertex(0)) {
return true
}
}
return false
} | [
"func",
"(",
"l",
"*",
"Loop",
")",
"Intersects",
"(",
"o",
"*",
"Loop",
")",
"bool",
"{",
"// Given two loops, A and B, A.Intersects(B) if and only if !A.Complement().Contains(B).",
"//",
"// This code is similar to Contains, but is optimized for the case",
"// where both loops enclose less than half of the sphere.",
"if",
"!",
"l",
".",
"bound",
".",
"Intersects",
"(",
"o",
".",
"bound",
")",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"// Check whether there are any edge crossings, and also check the loop",
"// relationship at any shared vertices.",
"relation",
":=",
"&",
"intersectsRelation",
"{",
"}",
"\n",
"if",
"hasCrossingRelation",
"(",
"l",
",",
"o",
",",
"relation",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"if",
"relation",
".",
"foundSharedVertex",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"// Since there are no edge intersections or shared vertices, the loops",
"// intersect only if A contains B, B contains A, or the two loops contain",
"// each other's boundaries. These checks are usually cheap because of the",
"// bounding box preconditions. Note that neither loop is empty (because of",
"// the bounding box check above), so it is safe to access vertex(0).",
"// Check whether A contains B, or A and B contain each other's boundaries.",
"// (Note that A contains all the vertices of B in either case.)",
"if",
"l",
".",
"subregionBound",
".",
"Contains",
"(",
"o",
".",
"bound",
")",
"||",
"l",
".",
"bound",
".",
"Union",
"(",
"o",
".",
"bound",
")",
".",
"IsFull",
"(",
")",
"{",
"if",
"l",
".",
"ContainsPoint",
"(",
"o",
".",
"Vertex",
"(",
"0",
")",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"// Check whether B contains A.",
"if",
"o",
".",
"subregionBound",
".",
"Contains",
"(",
"l",
".",
"bound",
")",
"{",
"if",
"o",
".",
"ContainsPoint",
"(",
"l",
".",
"Vertex",
"(",
"0",
")",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // Intersects reports whether the region contained by this loop intersects the region
// contained by the other loop. | [
"Intersects",
"reports",
"whether",
"the",
"region",
"contained",
"by",
"this",
"loop",
"intersects",
"the",
"region",
"contained",
"by",
"the",
"other",
"loop",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/loop.go#L318-L357 |
150,172 | golang/geo | s2/loop.go | Edge | func (l *Loop) Edge(i int) Edge {
return Edge{l.Vertex(i), l.Vertex(i + 1)}
} | go | func (l *Loop) Edge(i int) Edge {
return Edge{l.Vertex(i), l.Vertex(i + 1)}
} | [
"func",
"(",
"l",
"*",
"Loop",
")",
"Edge",
"(",
"i",
"int",
")",
"Edge",
"{",
"return",
"Edge",
"{",
"l",
".",
"Vertex",
"(",
"i",
")",
",",
"l",
".",
"Vertex",
"(",
"i",
"+",
"1",
")",
"}",
"\n",
"}"
] | // Edge returns the endpoints for the given edge index. | [
"Edge",
"returns",
"the",
"endpoints",
"for",
"the",
"given",
"edge",
"index",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/loop.go#L478-L480 |
150,173 | 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 |
150,174 | 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",
",",
"p",
",",
"l",
".",
"Vertex",
"(",
"0",
")",
")",
"\n",
"for",
"i",
":=",
"1",
";",
"i",
"<=",
"len",
"(",
"l",
".",
"vertices",
")",
";",
"i",
"++",
"{",
"// add vertex 0 twice",
"inside",
"=",
"inside",
"!=",
"crosser",
".",
"EdgeOrVertexChainCrossing",
"(",
"l",
".",
"Vertex",
"(",
"i",
")",
")",
"\n",
"}",
"\n",
"return",
"inside",
"\n",
"}"
] | // 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",
"loop",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/loop.go#L576-L584 |
150,175 | 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",
")",
"<",
"3",
"{",
"return",
"l",
".",
"originInside",
"\n",
"}",
"\n\n",
"// For small loops, and during initial construction, it is faster to just",
"// check all the crossing.",
"const",
"maxBruteForceVertices",
"=",
"32",
"\n",
"if",
"len",
"(",
"l",
".",
"vertices",
")",
"<",
"maxBruteForceVertices",
"||",
"l",
".",
"index",
"==",
"nil",
"{",
"return",
"l",
".",
"bruteForceContainsPoint",
"(",
"p",
")",
"\n",
"}",
"\n\n",
"// Otherwise, look up the point in the index.",
"it",
":=",
"l",
".",
"index",
".",
"Iterator",
"(",
")",
"\n",
"if",
"!",
"it",
".",
"LocatePoint",
"(",
"p",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"l",
".",
"iteratorContainsPoint",
"(",
"it",
",",
"p",
")",
"\n",
"}"
] | // 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 |
150,176 | 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\n",
"// 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",
"\n",
"}",
"\n\n",
"// Otherwise check if any edges intersect \"target\".",
"if",
"l",
".",
"boundaryApproxIntersects",
"(",
"it",
",",
"target",
")",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"// Otherwise check if the loop contains the center of \"target\".",
"return",
"l",
".",
"iteratorContainsPoint",
"(",
"it",
",",
"target",
".",
"Center",
"(",
")",
")",
"\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 |
150,177 | 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",
"(",
")",
")",
"\n\n",
"// If target does not overlap any index cell, there is no intersection.",
"if",
"relation",
"==",
"Disjoint",
"{",
"return",
"false",
"\n",
"}",
"\n",
"// 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",
"\n",
"}",
"\n",
"// 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",
"\n",
"}",
"\n",
"// Otherwise check if any edges intersect target.",
"if",
"l",
".",
"boundaryApproxIntersects",
"(",
"it",
",",
"target",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"// Otherwise check if the loop contains the center of target.",
"return",
"l",
".",
"iteratorContainsPoint",
"(",
"it",
",",
"target",
".",
"Center",
"(",
")",
")",
"\n",
"}"
] | // 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 |
150,178 | 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",
":=",
"it",
".",
"IndexCell",
"(",
")",
".",
"findByShapeID",
"(",
"0",
")",
"\n",
"inside",
":=",
"aClipped",
".",
"containsCenter",
"\n",
"if",
"len",
"(",
"aClipped",
".",
"edges",
")",
">",
"0",
"{",
"center",
":=",
"it",
".",
"Center",
"(",
")",
"\n",
"crosser",
":=",
"NewEdgeCrosser",
"(",
"center",
",",
"p",
")",
"\n",
"aiPrev",
":=",
"-",
"2",
"\n",
"for",
"_",
",",
"ai",
":=",
"range",
"aClipped",
".",
"edges",
"{",
"if",
"ai",
"!=",
"aiPrev",
"+",
"1",
"{",
"crosser",
".",
"RestartAt",
"(",
"l",
".",
"Vertex",
"(",
"ai",
")",
")",
"\n",
"}",
"\n",
"aiPrev",
"=",
"ai",
"\n",
"inside",
"=",
"inside",
"!=",
"crosser",
".",
"EdgeOrVertexChainCrossing",
"(",
"l",
".",
"Vertex",
"(",
"ai",
"+",
"1",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"inside",
"\n",
"}"
] | // 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 |
150,179 | 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 |
150,180 | 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",
")",
")",
"\n",
"}"
] | // 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 |
150,181 | 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()",
"// 2.00 * dblEpsilon for each addition in the Kahan summation",
"// ------------------",
"// 9.73 * dblEpsilon",
"maxErrorPerVertex",
":=",
"9.73",
"*",
"dblEpsilon",
"\n",
"return",
"maxErrorPerVertex",
"*",
"float64",
"(",
"len",
"(",
"l",
".",
"vertices",
")",
")",
"\n",
"}"
] | // 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 |
150,182 | 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 loops below a small threshold.",
"for",
"i",
":=",
"1",
";",
"i",
"<=",
"len",
"(",
"l",
".",
"vertices",
")",
";",
"i",
"++",
"{",
"if",
"l",
".",
"Vertex",
"(",
"i",
")",
"==",
"p",
"{",
"return",
"i",
",",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"notFound",
",",
"false",
"\n",
"}",
"\n\n",
"it",
":=",
"l",
".",
"index",
".",
"Iterator",
"(",
")",
"\n",
"if",
"!",
"it",
".",
"LocatePoint",
"(",
"p",
")",
"{",
"return",
"notFound",
",",
"false",
"\n",
"}",
"\n\n",
"aClipped",
":=",
"it",
".",
"IndexCell",
"(",
")",
".",
"findByShapeID",
"(",
"0",
")",
"\n",
"for",
"i",
":=",
"aClipped",
".",
"numEdges",
"(",
")",
"-",
"1",
";",
"i",
">=",
"0",
";",
"i",
"--",
"{",
"ai",
":=",
"aClipped",
".",
"edges",
"[",
"i",
"]",
"\n",
"if",
"l",
".",
"Vertex",
"(",
"ai",
")",
"==",
"p",
"{",
"if",
"ai",
"==",
"0",
"{",
"return",
"len",
"(",
"l",
".",
"vertices",
")",
",",
"true",
"\n",
"}",
"\n",
"return",
"ai",
",",
"true",
"\n",
"}",
"\n\n",
"if",
"l",
".",
"Vertex",
"(",
"ai",
"+",
"1",
")",
"==",
"p",
"{",
"return",
"ai",
"+",
"1",
",",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"notFound",
",",
"false",
"\n",
"}"
] | // 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 |
150,183 | 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 |
150,184 | 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",
"(",
"d",
")",
"\n",
"return",
"d",
".",
"err",
"\n",
"}"
] | // Decode decodes a loop. | [
"Decode",
"decodes",
"a",
"loop",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/loop.go#L1243-L1248 |
150,185 | 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",
")",
")",
"\n",
"l",
".",
"aj",
"=",
"aj",
"\n",
"l",
".",
"bjPrev",
"=",
"-",
"2",
"\n",
"}"
] | // 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 |
150,186 | 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",
":=",
"0",
";",
"j",
"<",
"bNumEdges",
";",
"j",
"++",
"{",
"bj",
":=",
"bClipped",
".",
"edges",
"[",
"j",
"]",
"\n",
"if",
"bj",
"!=",
"l",
".",
"bjPrev",
"+",
"1",
"{",
"l",
".",
"crosser",
".",
"RestartAt",
"(",
"l",
".",
"b",
".",
"Vertex",
"(",
"bj",
")",
")",
"\n",
"}",
"\n",
"l",
".",
"bjPrev",
"=",
"bj",
"\n",
"if",
"crossing",
":=",
"l",
".",
"crosser",
".",
"ChainCrossingSign",
"(",
"l",
".",
"b",
".",
"Vertex",
"(",
"bj",
"+",
"1",
")",
")",
";",
"crossing",
"==",
"DoNotCross",
"{",
"continue",
"\n",
"}",
"else",
"if",
"crossing",
"==",
"Cross",
"{",
"return",
"true",
"\n",
"}",
"\n\n",
"// 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",
"\n",
"}",
"\n",
"}",
"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",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"false",
"\n",
"}"
] | // 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 |
150,187 | 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",
"{",
"l",
".",
"startEdge",
"(",
"edge",
")",
"\n",
"if",
"l",
".",
"edgeCrossesCell",
"(",
"bClipped",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"false",
"\n",
"}"
] | // 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 |
150,188 | 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 find the",
"// correct index cells more efficiently.",
"bRoot",
":=",
"PaddedCellFromCellID",
"(",
"bID",
",",
"0",
")",
"\n",
"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",
")",
"\n",
"if",
"len",
"(",
"l",
".",
"bCells",
")",
"==",
"0",
"{",
"continue",
"\n",
"}",
"\n",
"l",
".",
"startEdge",
"(",
"aj",
")",
"\n",
"for",
"c",
":=",
"0",
";",
"c",
"<",
"len",
"(",
"l",
".",
"bCells",
")",
";",
"c",
"++",
"{",
"if",
"l",
".",
"edgeCrossesCell",
"(",
"l",
".",
"bCells",
"[",
"c",
"]",
".",
"shapes",
"[",
"0",
"]",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"false",
"\n",
"}"
] | // 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 |
150,189 | 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",
"(",
"f",
")",
")",
"\n",
"}"
] | // 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 |
150,190 | 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 |
150,191 | 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 |
150,192 | 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 |
150,193 | 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",
"{",
"if",
"e",
"==",
"id",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // 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 |
150,194 | 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",
"\n",
"}"
] | // 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 |
150,195 | 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",
".",
"shapes",
",",
"c",
")",
"\n",
"}"
] | // 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 |
150,196 | 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. very deeply nested loops).",
"for",
"_",
",",
"clipped",
":=",
"range",
"s",
".",
"shapes",
"{",
"if",
"clipped",
".",
"shapeID",
"==",
"shapeID",
"{",
"return",
"clipped",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // 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 |
150,197 | 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",
")",
">",
"0",
"{",
"if",
"len",
"(",
"pos",
")",
">",
"1",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"switch",
"pos",
"[",
"0",
"]",
"{",
"case",
"IteratorBegin",
":",
"s",
".",
"Begin",
"(",
")",
"\n",
"case",
"IteratorEnd",
":",
"s",
".",
"End",
"(",
")",
"\n",
"default",
":",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"s",
"\n",
"}"
] | // 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 |
150,198 | 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",
"s",
".",
"refresh",
"(",
")",
"\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 |
150,199 | 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",
"true",
"\n",
"}"
] | // 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",
"the",
"first",
"cell",
"the",
"call",
"does",
"nothing",
"and",
"returns",
"false",
"."
] | 476085157cff9aaeef4d4f124649436542d4114a | https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/shapeindex.go#L271-L279 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.