repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
list
docstring
stringlengths
6
2.61k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
85
252
partition
stringclasses
1 value
golang/geo
s2/cellid.go
Contains
func (ci CellID) Contains(oci CellID) bool { return uint64(ci.RangeMin()) <= uint64(oci) && uint64(oci) <= uint64(ci.RangeMax()) }
go
func (ci CellID) Contains(oci CellID) bool { return uint64(ci.RangeMin()) <= uint64(oci) && uint64(oci) <= uint64(ci.RangeMax()) }
[ "func", "(", "ci", "CellID", ")", "Contains", "(", "oci", "CellID", ")", "bool", "{", "return", "uint64", "(", "ci", ".", "RangeMin", "(", ")", ")", "<=", "uint64", "(", "oci", ")", "&&", "uint64", "(", "oci", ")", "<=", "uint64", "(", "ci", ".",...
// Contains returns true iff the CellID contains oci.
[ "Contains", "returns", "true", "iff", "the", "CellID", "contains", "oci", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/cellid.go#L321-L323
train
golang/geo
s2/cellid.go
Intersects
func (ci CellID) Intersects(oci CellID) bool { return uint64(oci.RangeMin()) <= uint64(ci.RangeMax()) && uint64(oci.RangeMax()) >= uint64(ci.RangeMin()) }
go
func (ci CellID) Intersects(oci CellID) bool { return uint64(oci.RangeMin()) <= uint64(ci.RangeMax()) && uint64(oci.RangeMax()) >= uint64(ci.RangeMin()) }
[ "func", "(", "ci", "CellID", ")", "Intersects", "(", "oci", "CellID", ")", "bool", "{", "return", "uint64", "(", "oci", ".", "RangeMin", "(", ")", ")", "<=", "uint64", "(", "ci", ".", "RangeMax", "(", ")", ")", "&&", "uint64", "(", "oci", ".", "R...
// Intersects returns true iff the CellID intersects oci.
[ "Intersects", "returns", "true", "iff", "the", "CellID", "intersects", "oci", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/cellid.go#L326-L328
train
golang/geo
s2/cellid.go
ChildBeginAtLevel
func (ci CellID) ChildBeginAtLevel(level int) CellID { return CellID(uint64(ci) - ci.lsb() + lsbForLevel(level)) }
go
func (ci CellID) ChildBeginAtLevel(level int) CellID { return CellID(uint64(ci) - ci.lsb() + lsbForLevel(level)) }
[ "func", "(", "ci", "CellID", ")", "ChildBeginAtLevel", "(", "level", "int", ")", "CellID", "{", "return", "CellID", "(", "uint64", "(", "ci", ")", "-", "ci", ".", "lsb", "(", ")", "+", "lsbForLevel", "(", "level", ")", ")", "\n", "}" ]
// ChildBeginAtLevel returns the first cell in a traversal of children a given level deeper than this cell, in // Hilbert curve order. The given level must be no smaller than the cell's level. // See ChildBegin for example use.
[ "ChildBeginAtLevel", "returns", "the", "first", "cell", "in", "a", "traversal", "of", "children", "a", "given", "level", "deeper", "than", "this", "cell", "in", "Hilbert", "curve", "order", ".", "The", "given", "level", "must", "be", "no", "smaller", "than",...
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/cellid.go#L366-L368
train
golang/geo
s2/cellid.go
ChildEnd
func (ci CellID) ChildEnd() CellID { ol := ci.lsb() return CellID(uint64(ci) + ol + ol>>2) }
go
func (ci CellID) ChildEnd() CellID { ol := ci.lsb() return CellID(uint64(ci) + ol + ol>>2) }
[ "func", "(", "ci", "CellID", ")", "ChildEnd", "(", ")", "CellID", "{", "ol", ":=", "ci", ".", "lsb", "(", ")", "\n", "return", "CellID", "(", "uint64", "(", "ci", ")", "+", "ol", "+", "ol", ">>", "2", ")", "\n", "}" ]
// ChildEnd returns the first cell after a traversal of the children of this cell in Hilbert curve order. // The returned cell may be invalid.
[ "ChildEnd", "returns", "the", "first", "cell", "after", "a", "traversal", "of", "the", "children", "of", "this", "cell", "in", "Hilbert", "curve", "order", ".", "The", "returned", "cell", "may", "be", "invalid", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/cellid.go#L372-L375
train
golang/geo
s2/cellid.go
ChildEndAtLevel
func (ci CellID) ChildEndAtLevel(level int) CellID { return CellID(uint64(ci) + ci.lsb() + lsbForLevel(level)) }
go
func (ci CellID) ChildEndAtLevel(level int) CellID { return CellID(uint64(ci) + ci.lsb() + lsbForLevel(level)) }
[ "func", "(", "ci", "CellID", ")", "ChildEndAtLevel", "(", "level", "int", ")", "CellID", "{", "return", "CellID", "(", "uint64", "(", "ci", ")", "+", "ci", ".", "lsb", "(", ")", "+", "lsbForLevel", "(", "level", ")", ")", "\n", "}" ]
// ChildEndAtLevel returns the first cell after the last child in a traversal of children a given level deeper // than this cell, in Hilbert curve order. // The given level must be no smaller than the cell's level. // The returned cell may be invalid.
[ "ChildEndAtLevel", "returns", "the", "first", "cell", "after", "the", "last", "child", "in", "a", "traversal", "of", "children", "a", "given", "level", "deeper", "than", "this", "cell", "in", "Hilbert", "curve", "order", ".", "The", "given", "level", "must",...
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/cellid.go#L381-L383
train
golang/geo
s2/cellid.go
NextWrap
func (ci CellID) NextWrap() CellID { n := ci.Next() if uint64(n) < wrapOffset { return n } return CellID(uint64(n) - wrapOffset) }
go
func (ci CellID) NextWrap() CellID { n := ci.Next() if uint64(n) < wrapOffset { return n } return CellID(uint64(n) - wrapOffset) }
[ "func", "(", "ci", "CellID", ")", "NextWrap", "(", ")", "CellID", "{", "n", ":=", "ci", ".", "Next", "(", ")", "\n", "if", "uint64", "(", "n", ")", "<", "wrapOffset", "{", "return", "n", "\n", "}", "\n", "return", "CellID", "(", "uint64", "(", ...
// NextWrap returns the next cell along the Hilbert curve, wrapping from last to // first as necessary. This should not be used with ChildBegin and ChildEnd.
[ "NextWrap", "returns", "the", "next", "cell", "along", "the", "Hilbert", "curve", "wrapping", "from", "last", "to", "first", "as", "necessary", ".", "This", "should", "not", "be", "used", "with", "ChildBegin", "and", "ChildEnd", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/cellid.go#L399-L405
train
golang/geo
s2/cellid.go
PrevWrap
func (ci CellID) PrevWrap() CellID { p := ci.Prev() if uint64(p) < wrapOffset { return p } return CellID(uint64(p) + wrapOffset) }
go
func (ci CellID) PrevWrap() CellID { p := ci.Prev() if uint64(p) < wrapOffset { return p } return CellID(uint64(p) + wrapOffset) }
[ "func", "(", "ci", "CellID", ")", "PrevWrap", "(", ")", "CellID", "{", "p", ":=", "ci", ".", "Prev", "(", ")", "\n", "if", "uint64", "(", "p", ")", "<", "wrapOffset", "{", "return", "p", "\n", "}", "\n", "return", "CellID", "(", "uint64", "(", ...
// PrevWrap returns the previous cell along the Hilbert curve, wrapping around from // first to last as necessary. This should not be used with ChildBegin and ChildEnd.
[ "PrevWrap", "returns", "the", "previous", "cell", "along", "the", "Hilbert", "curve", "wrapping", "around", "from", "first", "to", "last", "as", "necessary", ".", "This", "should", "not", "be", "used", "with", "ChildBegin", "and", "ChildEnd", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/cellid.go#L409-L415
train
golang/geo
s2/cellid.go
AdvanceWrap
func (ci CellID) AdvanceWrap(steps int64) CellID { if steps == 0 { return ci } // We clamp the number of steps if necessary to ensure that we do not // advance past the End() or before the Begin() of this level. shift := uint(2*(maxLevel-ci.Level()) + 1) if steps < 0 { if min := -int64(uint64(ci) >> shift); steps < min { wrap := int64(wrapOffset >> shift) steps %= wrap if steps < min { steps += wrap } } } else { // Unlike Advance(), we don't want to return End(level). if max := int64((wrapOffset - uint64(ci)) >> shift); steps > max { wrap := int64(wrapOffset >> shift) steps %= wrap if steps > max { steps -= wrap } } } // If steps is negative, then shifting it left has undefined behavior. // Cast to uint64 for a 2's complement answer. return CellID(uint64(ci) + (uint64(steps) << shift)) }
go
func (ci CellID) AdvanceWrap(steps int64) CellID { if steps == 0 { return ci } // We clamp the number of steps if necessary to ensure that we do not // advance past the End() or before the Begin() of this level. shift := uint(2*(maxLevel-ci.Level()) + 1) if steps < 0 { if min := -int64(uint64(ci) >> shift); steps < min { wrap := int64(wrapOffset >> shift) steps %= wrap if steps < min { steps += wrap } } } else { // Unlike Advance(), we don't want to return End(level). if max := int64((wrapOffset - uint64(ci)) >> shift); steps > max { wrap := int64(wrapOffset >> shift) steps %= wrap if steps > max { steps -= wrap } } } // If steps is negative, then shifting it left has undefined behavior. // Cast to uint64 for a 2's complement answer. return CellID(uint64(ci) + (uint64(steps) << shift)) }
[ "func", "(", "ci", "CellID", ")", "AdvanceWrap", "(", "steps", "int64", ")", "CellID", "{", "if", "steps", "==", "0", "{", "return", "ci", "\n", "}", "\n\n", "// We clamp the number of steps if necessary to ensure that we do not", "// advance past the End() or before th...
// AdvanceWrap advances or retreats the indicated number of steps along the // Hilbert curve at the current level and returns the new position. The // position wraps between the first and last faces as necessary.
[ "AdvanceWrap", "advances", "or", "retreats", "the", "indicated", "number", "of", "steps", "along", "the", "Hilbert", "curve", "at", "the", "current", "level", "and", "returns", "the", "new", "position", ".", "The", "position", "wraps", "between", "the", "first...
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/cellid.go#L420-L450
train
golang/geo
s2/cellid.go
Encode
func (ci CellID) Encode(w io.Writer) error { e := &encoder{w: w} ci.encode(e) return e.err }
go
func (ci CellID) Encode(w io.Writer) error { e := &encoder{w: w} ci.encode(e) return e.err }
[ "func", "(", "ci", "CellID", ")", "Encode", "(", "w", "io", ".", "Writer", ")", "error", "{", "e", ":=", "&", "encoder", "{", "w", ":", "w", "}", "\n", "ci", ".", "encode", "(", "e", ")", "\n", "return", "e", ".", "err", "\n", "}" ]
// Encode encodes the CellID.
[ "Encode", "encodes", "the", "CellID", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/cellid.go#L453-L457
train
golang/geo
s2/cellid.go
Decode
func (ci *CellID) Decode(r io.Reader) error { d := &decoder{r: asByteReader(r)} ci.decode(d) return d.err }
go
func (ci *CellID) Decode(r io.Reader) error { d := &decoder{r: asByteReader(r)} ci.decode(d) return d.err }
[ "func", "(", "ci", "*", "CellID", ")", "Decode", "(", "r", "io", ".", "Reader", ")", "error", "{", "d", ":=", "&", "decoder", "{", "r", ":", "asByteReader", "(", "r", ")", "}", "\n", "ci", ".", "decode", "(", "d", ")", "\n", "return", "d", "....
// Decode encodes the CellID.
[ "Decode", "encodes", "the", "CellID", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/cellid.go#L464-L468
train
golang/geo
s2/cellid.go
rawPoint
func (ci CellID) rawPoint() r3.Vector { face, si, ti := ci.faceSiTi() return faceUVToXYZ(face, stToUV((0.5/maxSize)*float64(si)), stToUV((0.5/maxSize)*float64(ti))) }
go
func (ci CellID) rawPoint() r3.Vector { face, si, ti := ci.faceSiTi() return faceUVToXYZ(face, stToUV((0.5/maxSize)*float64(si)), stToUV((0.5/maxSize)*float64(ti))) }
[ "func", "(", "ci", "CellID", ")", "rawPoint", "(", ")", "r3", ".", "Vector", "{", "face", ",", "si", ",", "ti", ":=", "ci", ".", "faceSiTi", "(", ")", "\n", "return", "faceUVToXYZ", "(", "face", ",", "stToUV", "(", "(", "0.5", "/", "maxSize", ")"...
// rawPoint returns an unnormalized r3 vector from the origin through the center // of the s2 cell on the sphere.
[ "rawPoint", "returns", "an", "unnormalized", "r3", "vector", "from", "the", "origin", "through", "the", "center", "of", "the", "s2", "cell", "on", "the", "sphere", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/cellid.go#L486-L489
train
golang/geo
s2/cellid.go
faceIJOrientation
func (ci CellID) faceIJOrientation() (f, i, j, orientation int) { f = ci.Face() orientation = f & swapMask nbits := maxLevel - 7*lookupBits // first iteration // Each iteration maps 8 bits of the Hilbert curve position into // 4 bits of "i" and "j". The lookup table transforms a key of the // form "ppppppppoo" to a value of the form "iiiijjjjoo", where the // letters [ijpo] represents bits of "i", "j", the Hilbert curve // position, and the Hilbert curve orientation respectively. // // On the first iteration we need to be careful to clear out the bits // representing the cube face. for k := 7; k >= 0; k-- { orientation += (int(uint64(ci)>>uint64(k*2*lookupBits+1)) & ((1 << uint(2*nbits)) - 1)) << 2 orientation = lookupIJ[orientation] i += (orientation >> (lookupBits + 2)) << uint(k*lookupBits) j += ((orientation >> 2) & ((1 << lookupBits) - 1)) << uint(k*lookupBits) orientation &= (swapMask | invertMask) nbits = lookupBits // following iterations } // The position of a non-leaf cell at level "n" consists of a prefix of // 2*n bits that identifies the cell, followed by a suffix of // 2*(maxLevel-n)+1 bits of the form 10*. If n==maxLevel, the suffix is // just "1" and has no effect. Otherwise, it consists of "10", followed // by (maxLevel-n-1) repetitions of "00", followed by "0". The "10" has // no effect, while each occurrence of "00" has the effect of reversing // the swapMask bit. if ci.lsb()&0x1111111111111110 != 0 { orientation ^= swapMask } return }
go
func (ci CellID) faceIJOrientation() (f, i, j, orientation int) { f = ci.Face() orientation = f & swapMask nbits := maxLevel - 7*lookupBits // first iteration // Each iteration maps 8 bits of the Hilbert curve position into // 4 bits of "i" and "j". The lookup table transforms a key of the // form "ppppppppoo" to a value of the form "iiiijjjjoo", where the // letters [ijpo] represents bits of "i", "j", the Hilbert curve // position, and the Hilbert curve orientation respectively. // // On the first iteration we need to be careful to clear out the bits // representing the cube face. for k := 7; k >= 0; k-- { orientation += (int(uint64(ci)>>uint64(k*2*lookupBits+1)) & ((1 << uint(2*nbits)) - 1)) << 2 orientation = lookupIJ[orientation] i += (orientation >> (lookupBits + 2)) << uint(k*lookupBits) j += ((orientation >> 2) & ((1 << lookupBits) - 1)) << uint(k*lookupBits) orientation &= (swapMask | invertMask) nbits = lookupBits // following iterations } // The position of a non-leaf cell at level "n" consists of a prefix of // 2*n bits that identifies the cell, followed by a suffix of // 2*(maxLevel-n)+1 bits of the form 10*. If n==maxLevel, the suffix is // just "1" and has no effect. Otherwise, it consists of "10", followed // by (maxLevel-n-1) repetitions of "00", followed by "0". The "10" has // no effect, while each occurrence of "00" has the effect of reversing // the swapMask bit. if ci.lsb()&0x1111111111111110 != 0 { orientation ^= swapMask } return }
[ "func", "(", "ci", "CellID", ")", "faceIJOrientation", "(", ")", "(", "f", ",", "i", ",", "j", ",", "orientation", "int", ")", "{", "f", "=", "ci", ".", "Face", "(", ")", "\n", "orientation", "=", "f", "&", "swapMask", "\n", "nbits", ":=", "maxLe...
// faceIJOrientation uses the global lookupIJ table to unfiddle the bits of ci.
[ "faceIJOrientation", "uses", "the", "global", "lookupIJ", "table", "to", "unfiddle", "the", "bits", "of", "ci", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/cellid.go#L506-L540
train
golang/geo
s2/cellid.go
initLookupCell
func initLookupCell(level, i, j, origOrientation, pos, orientation int) { if level == lookupBits { ij := (i << lookupBits) + j lookupPos[(ij<<2)+origOrientation] = (pos << 2) + orientation lookupIJ[(pos<<2)+origOrientation] = (ij << 2) + orientation return } level++ i <<= 1 j <<= 1 pos <<= 2 r := posToIJ[orientation] initLookupCell(level, i+(r[0]>>1), j+(r[0]&1), origOrientation, pos, orientation^posToOrientation[0]) initLookupCell(level, i+(r[1]>>1), j+(r[1]&1), origOrientation, pos+1, orientation^posToOrientation[1]) initLookupCell(level, i+(r[2]>>1), j+(r[2]&1), origOrientation, pos+2, orientation^posToOrientation[2]) initLookupCell(level, i+(r[3]>>1), j+(r[3]&1), origOrientation, pos+3, orientation^posToOrientation[3]) }
go
func initLookupCell(level, i, j, origOrientation, pos, orientation int) { if level == lookupBits { ij := (i << lookupBits) + j lookupPos[(ij<<2)+origOrientation] = (pos << 2) + orientation lookupIJ[(pos<<2)+origOrientation] = (ij << 2) + orientation return } level++ i <<= 1 j <<= 1 pos <<= 2 r := posToIJ[orientation] initLookupCell(level, i+(r[0]>>1), j+(r[0]&1), origOrientation, pos, orientation^posToOrientation[0]) initLookupCell(level, i+(r[1]>>1), j+(r[1]&1), origOrientation, pos+1, orientation^posToOrientation[1]) initLookupCell(level, i+(r[2]>>1), j+(r[2]&1), origOrientation, pos+2, orientation^posToOrientation[2]) initLookupCell(level, i+(r[3]>>1), j+(r[3]&1), origOrientation, pos+3, orientation^posToOrientation[3]) }
[ "func", "initLookupCell", "(", "level", ",", "i", ",", "j", ",", "origOrientation", ",", "pos", ",", "orientation", "int", ")", "{", "if", "level", "==", "lookupBits", "{", "ij", ":=", "(", "i", "<<", "lookupBits", ")", "+", "j", "\n", "lookupPos", "...
// initLookupCell initializes the lookupIJ table at init time.
[ "initLookupCell", "initializes", "the", "lookupIJ", "table", "at", "init", "time", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/cellid.go#L701-L718
train
golang/geo
s2/cellid.go
CommonAncestorLevel
func (ci CellID) CommonAncestorLevel(other CellID) (level int, ok bool) { bits := uint64(ci ^ other) if bits < ci.lsb() { bits = ci.lsb() } if bits < other.lsb() { bits = other.lsb() } msbPos := findMSBSetNonZero64(bits) if msbPos > 60 { return 0, false } return (60 - msbPos) >> 1, true }
go
func (ci CellID) CommonAncestorLevel(other CellID) (level int, ok bool) { bits := uint64(ci ^ other) if bits < ci.lsb() { bits = ci.lsb() } if bits < other.lsb() { bits = other.lsb() } msbPos := findMSBSetNonZero64(bits) if msbPos > 60 { return 0, false } return (60 - msbPos) >> 1, true }
[ "func", "(", "ci", "CellID", ")", "CommonAncestorLevel", "(", "other", "CellID", ")", "(", "level", "int", ",", "ok", "bool", ")", "{", "bits", ":=", "uint64", "(", "ci", "^", "other", ")", "\n", "if", "bits", "<", "ci", ".", "lsb", "(", ")", "{"...
// CommonAncestorLevel returns the level of the common ancestor of the two S2 CellIDs.
[ "CommonAncestorLevel", "returns", "the", "level", "of", "the", "common", "ancestor", "of", "the", "two", "S2", "CellIDs", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/cellid.go#L721-L735
train
golang/geo
s2/metric.go
Value
func (m Metric) Value(level int) float64 { return math.Ldexp(m.Deriv, -m.Dim*level) }
go
func (m Metric) Value(level int) float64 { return math.Ldexp(m.Deriv, -m.Dim*level) }
[ "func", "(", "m", "Metric", ")", "Value", "(", "level", "int", ")", "float64", "{", "return", "math", ".", "Ldexp", "(", "m", ".", "Deriv", ",", "-", "m", ".", "Dim", "*", "level", ")", "\n", "}" ]
// Value returns the value of the metric at the given level.
[ "Value", "returns", "the", "value", "of", "the", "metric", "at", "the", "given", "level", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/metric.go#L106-L108
train
golang/geo
s2/util.go
roundAngle
func roundAngle(val s1.Angle) int32 { if val < 0 { return int32(val - 0.5) } return int32(val + 0.5) }
go
func roundAngle(val s1.Angle) int32 { if val < 0 { return int32(val - 0.5) } return int32(val + 0.5) }
[ "func", "roundAngle", "(", "val", "s1", ".", "Angle", ")", "int32", "{", "if", "val", "<", "0", "{", "return", "int32", "(", "val", "-", "0.5", ")", "\n", "}", "\n", "return", "int32", "(", "val", "+", "0.5", ")", "\n", "}" ]
// roundAngle returns the value rounded to nearest as an int32. // This does not match C++ exactly for the case of x.5.
[ "roundAngle", "returns", "the", "value", "rounded", "to", "nearest", "as", "an", "int32", ".", "This", "does", "not", "match", "C", "++", "exactly", "for", "the", "case", "of", "x", ".", "5", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/util.go#L21-L26
train
golang/geo
s2/util.go
minAngle
func minAngle(x s1.Angle, others ...s1.Angle) s1.Angle { min := x for _, y := range others { if y < min { min = y } } return min }
go
func minAngle(x s1.Angle, others ...s1.Angle) s1.Angle { min := x for _, y := range others { if y < min { min = y } } return min }
[ "func", "minAngle", "(", "x", "s1", ".", "Angle", ",", "others", "...", "s1", ".", "Angle", ")", "s1", ".", "Angle", "{", "min", ":=", "x", "\n", "for", "_", ",", "y", ":=", "range", "others", "{", "if", "y", "<", "min", "{", "min", "=", "y",...
// minAngle returns the smallest of the given values.
[ "minAngle", "returns", "the", "smallest", "of", "the", "given", "values", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/util.go#L29-L37
train
golang/geo
s2/util.go
maxAngle
func maxAngle(x s1.Angle, others ...s1.Angle) s1.Angle { max := x for _, y := range others { if y > max { max = y } } return max }
go
func maxAngle(x s1.Angle, others ...s1.Angle) s1.Angle { max := x for _, y := range others { if y > max { max = y } } return max }
[ "func", "maxAngle", "(", "x", "s1", ".", "Angle", ",", "others", "...", "s1", ".", "Angle", ")", "s1", ".", "Angle", "{", "max", ":=", "x", "\n", "for", "_", ",", "y", ":=", "range", "others", "{", "if", "y", ">", "max", "{", "max", "=", "y",...
// maxAngle returns the largest of the given values.
[ "maxAngle", "returns", "the", "largest", "of", "the", "given", "values", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/util.go#L40-L48
train
golang/geo
s2/util.go
minChordAngle
func minChordAngle(x s1.ChordAngle, others ...s1.ChordAngle) s1.ChordAngle { min := x for _, y := range others { if y < min { min = y } } return min }
go
func minChordAngle(x s1.ChordAngle, others ...s1.ChordAngle) s1.ChordAngle { min := x for _, y := range others { if y < min { min = y } } return min }
[ "func", "minChordAngle", "(", "x", "s1", ".", "ChordAngle", ",", "others", "...", "s1", ".", "ChordAngle", ")", "s1", ".", "ChordAngle", "{", "min", ":=", "x", "\n", "for", "_", ",", "y", ":=", "range", "others", "{", "if", "y", "<", "min", "{", ...
// minChordAngle returns the smallest of the given values.
[ "minChordAngle", "returns", "the", "smallest", "of", "the", "given", "values", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/util.go#L51-L59
train
golang/geo
s2/util.go
maxChordAngle
func maxChordAngle(x s1.ChordAngle, others ...s1.ChordAngle) s1.ChordAngle { max := x for _, y := range others { if y > max { max = y } } return max }
go
func maxChordAngle(x s1.ChordAngle, others ...s1.ChordAngle) s1.ChordAngle { max := x for _, y := range others { if y > max { max = y } } return max }
[ "func", "maxChordAngle", "(", "x", "s1", ".", "ChordAngle", ",", "others", "...", "s1", ".", "ChordAngle", ")", "s1", ".", "ChordAngle", "{", "max", ":=", "x", "\n", "for", "_", ",", "y", ":=", "range", "others", "{", "if", "y", ">", "max", "{", ...
// maxChordAngle returns the largest of the given values.
[ "maxChordAngle", "returns", "the", "largest", "of", "the", "given", "values", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/util.go#L62-L70
train
golang/geo
s2/util.go
minFloat64
func minFloat64(x float64, others ...float64) float64 { min := x for _, y := range others { if y < min { min = y } } return min }
go
func minFloat64(x float64, others ...float64) float64 { min := x for _, y := range others { if y < min { min = y } } return min }
[ "func", "minFloat64", "(", "x", "float64", ",", "others", "...", "float64", ")", "float64", "{", "min", ":=", "x", "\n", "for", "_", ",", "y", ":=", "range", "others", "{", "if", "y", "<", "min", "{", "min", "=", "y", "\n", "}", "\n", "}", "\n"...
// minFloat64 returns the smallest of the given values.
[ "minFloat64", "returns", "the", "smallest", "of", "the", "given", "values", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/util.go#L73-L81
train
golang/geo
s2/util.go
maxFloat64
func maxFloat64(x float64, others ...float64) float64 { max := x for _, y := range others { if y > max { max = y } } return max }
go
func maxFloat64(x float64, others ...float64) float64 { max := x for _, y := range others { if y > max { max = y } } return max }
[ "func", "maxFloat64", "(", "x", "float64", ",", "others", "...", "float64", ")", "float64", "{", "max", ":=", "x", "\n", "for", "_", ",", "y", ":=", "range", "others", "{", "if", "y", ">", "max", "{", "max", "=", "y", "\n", "}", "\n", "}", "\n"...
// maxFloat64 returns the largest of the given values.
[ "maxFloat64", "returns", "the", "largest", "of", "the", "given", "values", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/util.go#L84-L92
train
golang/geo
s2/util.go
minInt
func minInt(x int, others ...int) int { min := x for _, y := range others { if y < min { min = y } } return min }
go
func minInt(x int, others ...int) int { min := x for _, y := range others { if y < min { min = y } } return min }
[ "func", "minInt", "(", "x", "int", ",", "others", "...", "int", ")", "int", "{", "min", ":=", "x", "\n", "for", "_", ",", "y", ":=", "range", "others", "{", "if", "y", "<", "min", "{", "min", "=", "y", "\n", "}", "\n", "}", "\n", "return", ...
// minInt returns the smallest of the given values.
[ "minInt", "returns", "the", "smallest", "of", "the", "given", "values", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/util.go#L95-L103
train
golang/geo
s2/util.go
maxInt
func maxInt(x int, others ...int) int { max := x for _, y := range others { if y > max { max = y } } return max }
go
func maxInt(x int, others ...int) int { max := x for _, y := range others { if y > max { max = y } } return max }
[ "func", "maxInt", "(", "x", "int", ",", "others", "...", "int", ")", "int", "{", "max", ":=", "x", "\n", "for", "_", ",", "y", ":=", "range", "others", "{", "if", "y", ">", "max", "{", "max", "=", "y", "\n", "}", "\n", "}", "\n", "return", ...
// maxInt returns the largest of the given values.
[ "maxInt", "returns", "the", "largest", "of", "the", "given", "values", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/util.go#L106-L114
train
golang/geo
s2/util.go
clampInt
func clampInt(x, min, max int) int { if x < min { return min } if x > max { return max } return x }
go
func clampInt(x, min, max int) int { if x < min { return min } if x > max { return max } return x }
[ "func", "clampInt", "(", "x", ",", "min", ",", "max", "int", ")", "int", "{", "if", "x", "<", "min", "{", "return", "min", "\n", "}", "\n", "if", "x", ">", "max", "{", "return", "max", "\n", "}", "\n", "return", "x", "\n", "}" ]
// clampInt returns the number closest to x within the range min..max.
[ "clampInt", "returns", "the", "number", "closest", "to", "x", "within", "the", "range", "min", "..", "max", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/util.go#L117-L125
train
golang/geo
s2/regioncoverer.go
newCandidate
func (c *coverer) newCandidate(cell Cell) *candidate { if !c.region.IntersectsCell(cell) { return nil } cand := &candidate{cell: cell} level := int(cell.level) if level >= c.minLevel { if c.interiorCovering { if c.region.ContainsCell(cell) { cand.terminal = true } else if level+c.levelMod > c.maxLevel { return nil } } else if level+c.levelMod > c.maxLevel || c.region.ContainsCell(cell) { cand.terminal = true } } return cand }
go
func (c *coverer) newCandidate(cell Cell) *candidate { if !c.region.IntersectsCell(cell) { return nil } cand := &candidate{cell: cell} level := int(cell.level) if level >= c.minLevel { if c.interiorCovering { if c.region.ContainsCell(cell) { cand.terminal = true } else if level+c.levelMod > c.maxLevel { return nil } } else if level+c.levelMod > c.maxLevel || c.region.ContainsCell(cell) { cand.terminal = true } } return cand }
[ "func", "(", "c", "*", "coverer", ")", "newCandidate", "(", "cell", "Cell", ")", "*", "candidate", "{", "if", "!", "c", ".", "region", ".", "IntersectsCell", "(", "cell", ")", "{", "return", "nil", "\n", "}", "\n", "cand", ":=", "&", "candidate", "...
// newCandidate returns a new candidate with no children if the cell intersects the given region. // The candidate is marked as terminal if it should not be expanded further.
[ "newCandidate", "returns", "a", "new", "candidate", "with", "no", "children", "if", "the", "cell", "intersects", "the", "given", "region", ".", "The", "candidate", "is", "marked", "as", "terminal", "if", "it", "should", "not", "be", "expanded", "further", "....
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/regioncoverer.go#L132-L150
train
golang/geo
s2/regioncoverer.go
expandChildren
func (c *coverer) expandChildren(cand *candidate, cell Cell, numLevels int) int { numLevels-- var numTerminals int last := cell.id.ChildEnd() for ci := cell.id.ChildBegin(); ci != last; ci = ci.Next() { childCell := CellFromCellID(ci) if numLevels > 0 { if c.region.IntersectsCell(childCell) { numTerminals += c.expandChildren(cand, childCell, numLevels) } continue } if child := c.newCandidate(childCell); child != nil { cand.children = append(cand.children, child) cand.numChildren++ if child.terminal { numTerminals++ } } } return numTerminals }
go
func (c *coverer) expandChildren(cand *candidate, cell Cell, numLevels int) int { numLevels-- var numTerminals int last := cell.id.ChildEnd() for ci := cell.id.ChildBegin(); ci != last; ci = ci.Next() { childCell := CellFromCellID(ci) if numLevels > 0 { if c.region.IntersectsCell(childCell) { numTerminals += c.expandChildren(cand, childCell, numLevels) } continue } if child := c.newCandidate(childCell); child != nil { cand.children = append(cand.children, child) cand.numChildren++ if child.terminal { numTerminals++ } } } return numTerminals }
[ "func", "(", "c", "*", "coverer", ")", "expandChildren", "(", "cand", "*", "candidate", ",", "cell", "Cell", ",", "numLevels", "int", ")", "int", "{", "numLevels", "--", "\n", "var", "numTerminals", "int", "\n", "last", ":=", "cell", ".", "id", ".", ...
// expandChildren populates the children of the candidate by expanding the given number of // levels from the given cell. Returns the number of children that were marked "terminal".
[ "expandChildren", "populates", "the", "children", "of", "the", "candidate", "by", "expanding", "the", "given", "number", "of", "levels", "from", "the", "given", "cell", ".", "Returns", "the", "number", "of", "children", "that", "were", "marked", "terminal", "....
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/regioncoverer.go#L154-L175
train
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", ".", "re...
// 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", ...
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/regioncoverer.go#L180-L218
train
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", ":"...
// 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
train
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", ":",...
// 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
train
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", "(", "...
// 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
train
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", ",", ...
// 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
train
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", ")"...
// 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",...
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/regioncoverer.go#L442-L444
train
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", "f...
// 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
train
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", "=", "appendF...
// 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
train
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 + ...
// 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
train
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", ...
// 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
train
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", "//...
// 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
train
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",...
// 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
train
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", "{",...
// 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", "cast...
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/cellunion.go#L154-L167
train
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", ...
// 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", "Contain...
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/cellunion.go#L173-L192
train
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", "(", ...
// 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
train
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 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
train
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", "// bo...
// 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
train
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
train
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
train
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
train
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", ")", ...
// 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
train
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...
// 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
train
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", "}", ...
// 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
train
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", "(", "(", "*...
// 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", "c...
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/cellunion.go#L432-L443
train
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", ...
// 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
train
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
train
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...
// 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", "a...
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/cellunion.go#L529-L535
train
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",...
// 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
train
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
train
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", ...
// Decode decodes the CellUnion.
[ "Decode", "decodes", "the", "CellUnion", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/cellunion.go#L562-L566
train
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", ".", ...
// 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
train
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", ...
// 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", ...
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/cell.go#L133-L176
train
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"...
// 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
train
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
train
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
train
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 a...
// 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
train
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", "...
// 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
train
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...
// 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"...
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/cell.go#L469-L483
train
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", "(", ...
// 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
train
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
train
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
train
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.",...
// 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
train
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 consid...
// 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
train
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", "&&", "!...
// 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
train
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", ...
// 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
train
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...
// 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
train
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", ".", ...
// 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
train
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", "...
// 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
train
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", "]", "=...
// 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
train
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", ...
// 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
train
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", "+=", "(", "*"...
// 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
train
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", "*...
// 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
train
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 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
train
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,"...
// 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
train
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
train
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 angl...
// 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...
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/polyline.go#L206-L290
train
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
train
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", ".", "e...
// Decode decodes the polyline.
[ "Decode", "decodes", "the", "polyline", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/polyline.go#L353-L357
train
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...
// 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", ...
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/polyline.go#L420-L438
train
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", "(...
// 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
train
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", ":",...
// 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...
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/edge_crossings.go#L149-L158
train
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...
// 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",...
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/edge_crossings.go#L211-L221
train
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
train
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"...
// 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
train
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", ")", "}", ...
// 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", ...
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/centroids.go#L131-L133
train
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
train
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", "(", ")",...
// 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
train
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", "(", ...
// 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
train
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 ed...
// 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
train
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...
// 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", "...
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/loop.go#L223-L258
train
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 v...
// 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
train
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 en...
// 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
train
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
train