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/polygon.go
initEdgesAndIndex
func (p *Polygon) initEdgesAndIndex() { if p.IsFull() { return } const maxLinearSearchLoops = 12 // Based on benchmarks. if len(p.loops) > maxLinearSearchLoops { p.cumulativeEdges = make([]int, 0, len(p.loops)) } for _, l := range p.loops { if p.cumulativeEdges != nil { p.cumulativeEdges = append(p.cumulativeEdges, p.numEdges) } p.numEdges += len(l.vertices) } p.index = NewShapeIndex() p.index.Add(p) }
go
func (p *Polygon) initEdgesAndIndex() { if p.IsFull() { return } const maxLinearSearchLoops = 12 // Based on benchmarks. if len(p.loops) > maxLinearSearchLoops { p.cumulativeEdges = make([]int, 0, len(p.loops)) } for _, l := range p.loops { if p.cumulativeEdges != nil { p.cumulativeEdges = append(p.cumulativeEdges, p.numEdges) } p.numEdges += len(l.vertices) } p.index = NewShapeIndex() p.index.Add(p) }
[ "func", "(", "p", "*", "Polygon", ")", "initEdgesAndIndex", "(", ")", "{", "if", "p", ".", "IsFull", "(", ")", "{", "return", "\n", "}", "\n", "const", "maxLinearSearchLoops", "=", "12", "// Based on benchmarks.", "\n", "if", "len", "(", "p", ".", "loo...
// initEdgesAndIndex performs the shape related initializations and adds the final // polygon to the index.
[ "initEdgesAndIndex", "performs", "the", "shape", "related", "initializations", "and", "adds", "the", "final", "polygon", "to", "the", "index", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/polygon.go#L404-L422
train
golang/geo
s2/polygon.go
FullPolygon
func FullPolygon() *Polygon { ret := &Polygon{ loops: []*Loop{ FullLoop(), }, numVertices: len(FullLoop().Vertices()), bound: FullRect(), subregionBound: FullRect(), } ret.initEdgesAndIndex() return ret }
go
func FullPolygon() *Polygon { ret := &Polygon{ loops: []*Loop{ FullLoop(), }, numVertices: len(FullLoop().Vertices()), bound: FullRect(), subregionBound: FullRect(), } ret.initEdgesAndIndex() return ret }
[ "func", "FullPolygon", "(", ")", "*", "Polygon", "{", "ret", ":=", "&", "Polygon", "{", "loops", ":", "[", "]", "*", "Loop", "{", "FullLoop", "(", ")", ",", "}", ",", "numVertices", ":", "len", "(", "FullLoop", "(", ")", ".", "Vertices", "(", ")"...
// FullPolygon returns a special "full" polygon.
[ "FullPolygon", "returns", "a", "special", "full", "polygon", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/polygon.go#L425-L436
train
golang/geo
s2/polygon.go
Validate
func (p *Polygon) Validate() error { for i, l := range p.loops { // Check for loop errors that don't require building a ShapeIndex. if err := l.findValidationErrorNoIndex(); err != nil { return fmt.Errorf("loop %d: %v", i, err) } // Check that no loop is empty, and that the full loop only appears in the // full polygon. if l.IsEmpty() { return fmt.Errorf("loop %d: empty loops are not allowed", i) } if l.IsFull() && len(p.loops) > 1 { return fmt.Errorf("loop %d: full loop appears in non-full polygon", i) } } // TODO(roberts): Uncomment the remaining checks when they are completed. // Check for loop self-intersections and loop pairs that cross // (including duplicate edges and vertices). // if findSelfIntersection(p.index) { // return fmt.Errorf("polygon has loop pairs that cross") // } // Check whether initOriented detected inconsistent loop orientations. // if p.hasInconsistentLoopOrientations { // return fmt.Errorf("inconsistent loop orientations detected") // } // Finally, verify the loop nesting hierarchy. return p.findLoopNestingError() }
go
func (p *Polygon) Validate() error { for i, l := range p.loops { // Check for loop errors that don't require building a ShapeIndex. if err := l.findValidationErrorNoIndex(); err != nil { return fmt.Errorf("loop %d: %v", i, err) } // Check that no loop is empty, and that the full loop only appears in the // full polygon. if l.IsEmpty() { return fmt.Errorf("loop %d: empty loops are not allowed", i) } if l.IsFull() && len(p.loops) > 1 { return fmt.Errorf("loop %d: full loop appears in non-full polygon", i) } } // TODO(roberts): Uncomment the remaining checks when they are completed. // Check for loop self-intersections and loop pairs that cross // (including duplicate edges and vertices). // if findSelfIntersection(p.index) { // return fmt.Errorf("polygon has loop pairs that cross") // } // Check whether initOriented detected inconsistent loop orientations. // if p.hasInconsistentLoopOrientations { // return fmt.Errorf("inconsistent loop orientations detected") // } // Finally, verify the loop nesting hierarchy. return p.findLoopNestingError() }
[ "func", "(", "p", "*", "Polygon", ")", "Validate", "(", ")", "error", "{", "for", "i", ",", "l", ":=", "range", "p", ".", "loops", "{", "// Check for loop errors that don't require building a ShapeIndex.", "if", "err", ":=", "l", ".", "findValidationErrorNoIndex...
// Validate checks whether this is a valid polygon, // including checking whether all the loops are themselves valid.
[ "Validate", "checks", "whether", "this", "is", "a", "valid", "polygon", "including", "checking", "whether", "all", "the", "loops", "are", "themselves", "valid", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/polygon.go#L440-L471
train
golang/geo
s2/polygon.go
findLoopNestingError
func (p *Polygon) findLoopNestingError() error { // First check that the loop depths make sense. lastDepth := -1 for i, l := range p.loops { depth := l.depth if depth < 0 || depth > lastDepth+1 { return fmt.Errorf("loop %d: invalid loop depth (%d)", i, depth) } lastDepth = depth } // Then check that they correspond to the actual loop nesting. This test // is quadratic in the number of loops but the cost per iteration is small. for i, l := range p.loops { last := p.LastDescendant(i) for j, l2 := range p.loops { if i == j { continue } nested := (j >= i+1) && (j <= last) const reverseB = false if l.containsNonCrossingBoundary(l2, reverseB) != nested { nestedStr := "" if !nested { nestedStr = "not " } return fmt.Errorf("invalid nesting: loop %d should %scontain loop %d", i, nestedStr, j) } } } return nil }
go
func (p *Polygon) findLoopNestingError() error { // First check that the loop depths make sense. lastDepth := -1 for i, l := range p.loops { depth := l.depth if depth < 0 || depth > lastDepth+1 { return fmt.Errorf("loop %d: invalid loop depth (%d)", i, depth) } lastDepth = depth } // Then check that they correspond to the actual loop nesting. This test // is quadratic in the number of loops but the cost per iteration is small. for i, l := range p.loops { last := p.LastDescendant(i) for j, l2 := range p.loops { if i == j { continue } nested := (j >= i+1) && (j <= last) const reverseB = false if l.containsNonCrossingBoundary(l2, reverseB) != nested { nestedStr := "" if !nested { nestedStr = "not " } return fmt.Errorf("invalid nesting: loop %d should %scontain loop %d", i, nestedStr, j) } } } return nil }
[ "func", "(", "p", "*", "Polygon", ")", "findLoopNestingError", "(", ")", "error", "{", "// First check that the loop depths make sense.", "lastDepth", ":=", "-", "1", "\n", "for", "i", ",", "l", ":=", "range", "p", ".", "loops", "{", "depth", ":=", "l", "....
// findLoopNestingError reports if there is an error in the loop nesting hierarchy.
[ "findLoopNestingError", "reports", "if", "there", "is", "an", "error", "in", "the", "loop", "nesting", "hierarchy", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/polygon.go#L474-L505
train
golang/geo
s2/polygon.go
Parent
func (p *Polygon) Parent(k int) (index int, ok bool) { // See where we are on the depth hierarchy. depth := p.loops[k].depth if depth == 0 { return -1, false } // There may be several loops at the same nesting level as us that share a // parent loop with us. (Imagine a slice of swiss cheese, of which we are one loop. // we don't know how many may be next to us before we get back to our parent loop.) // Move up one position from us, and then begin traversing back through the set of loops // until we find the one that is our parent or we get to the top of the polygon. for k--; k >= 0 && p.loops[k].depth <= depth; k-- { } return k, true }
go
func (p *Polygon) Parent(k int) (index int, ok bool) { // See where we are on the depth hierarchy. depth := p.loops[k].depth if depth == 0 { return -1, false } // There may be several loops at the same nesting level as us that share a // parent loop with us. (Imagine a slice of swiss cheese, of which we are one loop. // we don't know how many may be next to us before we get back to our parent loop.) // Move up one position from us, and then begin traversing back through the set of loops // until we find the one that is our parent or we get to the top of the polygon. for k--; k >= 0 && p.loops[k].depth <= depth; k-- { } return k, true }
[ "func", "(", "p", "*", "Polygon", ")", "Parent", "(", "k", "int", ")", "(", "index", "int", ",", "ok", "bool", ")", "{", "// See where we are on the depth hierarchy.", "depth", ":=", "p", ".", "loops", "[", "k", "]", ".", "depth", "\n", "if", "depth", ...
// Parent returns the index of the parent of loop k. // If the loop does not have a parent, ok=false is returned.
[ "Parent", "returns", "the", "index", "of", "the", "parent", "of", "loop", "k", ".", "If", "the", "loop", "does", "not", "have", "a", "parent", "ok", "=", "false", "is", "returned", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/polygon.go#L539-L554
train
golang/geo
s2/polygon.go
ContainsPoint
func (p *Polygon) ContainsPoint(point Point) bool { // NOTE: A bounds check slows down this function by about 50%. It is // worthwhile only when it might allow us to delay building the index. if !p.index.IsFresh() && !p.bound.ContainsPoint(point) { return false } // For small polygons, and during initial construction, it is faster to just // check all the crossing. const maxBruteForceVertices = 32 if p.numVertices < maxBruteForceVertices || p.index == nil { inside := false for _, l := range p.loops { // use loops bruteforce to avoid building the index on each loop. inside = inside != l.bruteForceContainsPoint(point) } return inside } // Otherwise, look up the ShapeIndex cell containing this point. it := p.index.Iterator() if !it.LocatePoint(point) { return false } return p.iteratorContainsPoint(it, point) }
go
func (p *Polygon) ContainsPoint(point Point) bool { // NOTE: A bounds check slows down this function by about 50%. It is // worthwhile only when it might allow us to delay building the index. if !p.index.IsFresh() && !p.bound.ContainsPoint(point) { return false } // For small polygons, and during initial construction, it is faster to just // check all the crossing. const maxBruteForceVertices = 32 if p.numVertices < maxBruteForceVertices || p.index == nil { inside := false for _, l := range p.loops { // use loops bruteforce to avoid building the index on each loop. inside = inside != l.bruteForceContainsPoint(point) } return inside } // Otherwise, look up the ShapeIndex cell containing this point. it := p.index.Iterator() if !it.LocatePoint(point) { return false } return p.iteratorContainsPoint(it, point) }
[ "func", "(", "p", "*", "Polygon", ")", "ContainsPoint", "(", "point", "Point", ")", "bool", "{", "// NOTE: A bounds check slows down this function by about 50%. It is", "// worthwhile only when it might allow us to delay building the index.", "if", "!", "p", ".", "index", "."...
// ContainsPoint reports whether the polygon contains the point.
[ "ContainsPoint", "reports", "whether", "the", "polygon", "contains", "the", "point", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/polygon.go#L584-L610
train
golang/geo
s2/polygon.go
ContainsCell
func (p *Polygon) ContainsCell(cell Cell) bool { it := p.index.Iterator() relation := it.LocateCellID(cell.ID()) // If "cell" is disjoint from all index cells, it is not contained. // Similarly, if "cell" is subdivided into one or more index cells then it // is not contained, since index cells are subdivided only if they (nearly) // intersect a sufficient number of edges. (But note that if "cell" itself // is an index cell then it may be contained, since it could be a cell with // no edges in the loop interior.) if relation != Indexed { return false } // Otherwise check if any edges intersect "cell". if p.boundaryApproxIntersects(it, cell) { return false } // Otherwise check if the loop contains the center of "cell". return p.iteratorContainsPoint(it, cell.Center()) }
go
func (p *Polygon) ContainsCell(cell Cell) bool { it := p.index.Iterator() relation := it.LocateCellID(cell.ID()) // If "cell" is disjoint from all index cells, it is not contained. // Similarly, if "cell" is subdivided into one or more index cells then it // is not contained, since index cells are subdivided only if they (nearly) // intersect a sufficient number of edges. (But note that if "cell" itself // is an index cell then it may be contained, since it could be a cell with // no edges in the loop interior.) if relation != Indexed { return false } // Otherwise check if any edges intersect "cell". if p.boundaryApproxIntersects(it, cell) { return false } // Otherwise check if the loop contains the center of "cell". return p.iteratorContainsPoint(it, cell.Center()) }
[ "func", "(", "p", "*", "Polygon", ")", "ContainsCell", "(", "cell", "Cell", ")", "bool", "{", "it", ":=", "p", ".", "index", ".", "Iterator", "(", ")", "\n", "relation", ":=", "it", ".", "LocateCellID", "(", "cell", ".", "ID", "(", ")", ")", "\n\...
// ContainsCell reports whether the polygon contains the given cell.
[ "ContainsCell", "reports", "whether", "the", "polygon", "contains", "the", "given", "cell", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/polygon.go#L613-L634
train
golang/geo
s2/polygon.go
IntersectsCell
func (p *Polygon) IntersectsCell(cell Cell) bool { it := p.index.Iterator() relation := it.LocateCellID(cell.ID()) // If cell does not overlap any index cell, there is no intersection. if relation == Disjoint { return false } // If cell is subdivided into one or more index cells, there is an // intersection to within the S2ShapeIndex error bound (see Contains). if relation == Subdivided { return true } // If cell is an index cell, there is an intersection because index cells // are created only if they have at least one edge or they are entirely // contained by the loop. if it.CellID() == cell.id { return true } // Otherwise check if any edges intersect cell. if p.boundaryApproxIntersects(it, cell) { return true } // Otherwise check if the loop contains the center of cell. return p.iteratorContainsPoint(it, cell.Center()) }
go
func (p *Polygon) IntersectsCell(cell Cell) bool { it := p.index.Iterator() relation := it.LocateCellID(cell.ID()) // If cell does not overlap any index cell, there is no intersection. if relation == Disjoint { return false } // If cell is subdivided into one or more index cells, there is an // intersection to within the S2ShapeIndex error bound (see Contains). if relation == Subdivided { return true } // If cell is an index cell, there is an intersection because index cells // are created only if they have at least one edge or they are entirely // contained by the loop. if it.CellID() == cell.id { return true } // Otherwise check if any edges intersect cell. if p.boundaryApproxIntersects(it, cell) { return true } // Otherwise check if the loop contains the center of cell. return p.iteratorContainsPoint(it, cell.Center()) }
[ "func", "(", "p", "*", "Polygon", ")", "IntersectsCell", "(", "cell", "Cell", ")", "bool", "{", "it", ":=", "p", ".", "index", ".", "Iterator", "(", ")", "\n", "relation", ":=", "it", ".", "LocateCellID", "(", "cell", ".", "ID", "(", ")", ")", "\...
// IntersectsCell reports whether the polygon intersects the given cell.
[ "IntersectsCell", "reports", "whether", "the", "polygon", "intersects", "the", "given", "cell", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/polygon.go#L637-L662
train
golang/geo
s2/polygon.go
iteratorContainsPoint
func (p *Polygon) iteratorContainsPoint(it *ShapeIndexIterator, point Point) bool { // Test containment by drawing a line segment from the cell center to the // given point and counting edge crossings. aClipped := it.IndexCell().findByShapeID(0) inside := aClipped.containsCenter if len(aClipped.edges) == 0 { return inside } // This block requires ShapeIndex. crosser := NewEdgeCrosser(it.Center(), point) shape := p.index.Shape(0) for _, e := range aClipped.edges { edge := shape.Edge(e) inside = inside != crosser.EdgeOrVertexCrossing(edge.V0, edge.V1) } return inside }
go
func (p *Polygon) iteratorContainsPoint(it *ShapeIndexIterator, point Point) bool { // Test containment by drawing a line segment from the cell center to the // given point and counting edge crossings. aClipped := it.IndexCell().findByShapeID(0) inside := aClipped.containsCenter if len(aClipped.edges) == 0 { return inside } // This block requires ShapeIndex. crosser := NewEdgeCrosser(it.Center(), point) shape := p.index.Shape(0) for _, e := range aClipped.edges { edge := shape.Edge(e) inside = inside != crosser.EdgeOrVertexCrossing(edge.V0, edge.V1) } return inside }
[ "func", "(", "p", "*", "Polygon", ")", "iteratorContainsPoint", "(", "it", "*", "ShapeIndexIterator", ",", "point", "Point", ")", "bool", "{", "// Test containment by drawing a line segment from the cell center to the", "// given point and counting edge crossings.", "aClipped",...
// iteratorContainsPoint reports whether the iterator that is positioned at the // ShapeIndexCell that may contain p, contains the point p.
[ "iteratorContainsPoint", "reports", "whether", "the", "iterator", "that", "is", "positioned", "at", "the", "ShapeIndexCell", "that", "may", "contain", "p", "contains", "the", "point", "p", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/polygon.go#L704-L723
train
golang/geo
s2/polygon.go
ReferencePoint
func (p *Polygon) ReferencePoint() ReferencePoint { containsOrigin := false for _, l := range p.loops { containsOrigin = containsOrigin != l.ContainsOrigin() } return OriginReferencePoint(containsOrigin) }
go
func (p *Polygon) ReferencePoint() ReferencePoint { containsOrigin := false for _, l := range p.loops { containsOrigin = containsOrigin != l.ContainsOrigin() } return OriginReferencePoint(containsOrigin) }
[ "func", "(", "p", "*", "Polygon", ")", "ReferencePoint", "(", ")", "ReferencePoint", "{", "containsOrigin", ":=", "false", "\n", "for", "_", ",", "l", ":=", "range", "p", ".", "loops", "{", "containsOrigin", "=", "containsOrigin", "!=", "l", ".", "Contai...
// ReferencePoint returns the reference point for this polygon.
[ "ReferencePoint", "returns", "the", "reference", "point", "for", "this", "polygon", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/polygon.go#L755-L761
train
golang/geo
s2/polygon.go
Contains
func (p *Polygon) Contains(o *Polygon) bool { // If both polygons have one loop, use the more efficient Loop method. // Note that Loop's Contains does its own bounding rectangle check. if len(p.loops) == 1 && len(o.loops) == 1 { return p.loops[0].Contains(o.loops[0]) } // Otherwise if neither polygon has holes, we can still use the more // efficient Loop's Contains method (rather than compareBoundary), // but it's worthwhile to do our own bounds check first. if !p.subregionBound.Contains(o.bound) { // Even though Bound(A) does not contain Bound(B), it is still possible // that A contains B. This can only happen when union of the two bounds // spans all longitudes. For example, suppose that B consists of two // shells with a longitude gap between them, while A consists of one shell // that surrounds both shells of B but goes the other way around the // sphere (so that it does not intersect the longitude gap). if !p.bound.Lng.Union(o.bound.Lng).IsFull() { return false } } if !p.hasHoles && !o.hasHoles { for _, l := range o.loops { if !p.anyLoopContains(l) { return false } } return true } // Polygon A contains B iff B does not intersect the complement of A. From // the intersection algorithm below, this means that the complement of A // must exclude the entire boundary of B, and B must exclude all shell // boundaries of the complement of A. (It can be shown that B must then // exclude the entire boundary of the complement of A.) The first call // below returns false if the boundaries cross, therefore the second call // does not need to check for any crossing edges (which makes it cheaper). return p.containsBoundary(o) && o.excludesNonCrossingComplementShells(p) }
go
func (p *Polygon) Contains(o *Polygon) bool { // If both polygons have one loop, use the more efficient Loop method. // Note that Loop's Contains does its own bounding rectangle check. if len(p.loops) == 1 && len(o.loops) == 1 { return p.loops[0].Contains(o.loops[0]) } // Otherwise if neither polygon has holes, we can still use the more // efficient Loop's Contains method (rather than compareBoundary), // but it's worthwhile to do our own bounds check first. if !p.subregionBound.Contains(o.bound) { // Even though Bound(A) does not contain Bound(B), it is still possible // that A contains B. This can only happen when union of the two bounds // spans all longitudes. For example, suppose that B consists of two // shells with a longitude gap between them, while A consists of one shell // that surrounds both shells of B but goes the other way around the // sphere (so that it does not intersect the longitude gap). if !p.bound.Lng.Union(o.bound.Lng).IsFull() { return false } } if !p.hasHoles && !o.hasHoles { for _, l := range o.loops { if !p.anyLoopContains(l) { return false } } return true } // Polygon A contains B iff B does not intersect the complement of A. From // the intersection algorithm below, this means that the complement of A // must exclude the entire boundary of B, and B must exclude all shell // boundaries of the complement of A. (It can be shown that B must then // exclude the entire boundary of the complement of A.) The first call // below returns false if the boundaries cross, therefore the second call // does not need to check for any crossing edges (which makes it cheaper). return p.containsBoundary(o) && o.excludesNonCrossingComplementShells(p) }
[ "func", "(", "p", "*", "Polygon", ")", "Contains", "(", "o", "*", "Polygon", ")", "bool", "{", "// If both polygons have one loop, use the more efficient Loop method.", "// Note that Loop's Contains does its own bounding rectangle check.", "if", "len", "(", "p", ".", "loops...
// Contains reports whether this polygon contains the other polygon. // Specifically, it reports whether all the points in the other polygon // are also in this polygon.
[ "Contains", "reports", "whether", "this", "polygon", "contains", "the", "other", "polygon", ".", "Specifically", "it", "reports", "whether", "all", "the", "points", "in", "the", "other", "polygon", "are", "also", "in", "this", "polygon", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/polygon.go#L822-L861
train
golang/geo
s2/polygon.go
Intersects
func (p *Polygon) Intersects(o *Polygon) bool { // If both polygons have one loop, use the more efficient Loop method. // Note that Loop Intersects does its own bounding rectangle check. if len(p.loops) == 1 && len(o.loops) == 1 { return p.loops[0].Intersects(o.loops[0]) } // Otherwise if neither polygon has holes, we can still use the more // efficient Loop.Intersects method. The polygons intersect if and // only if some pair of loop regions intersect. if !p.bound.Intersects(o.bound) { return false } if !p.hasHoles && !o.hasHoles { for _, l := range o.loops { if p.anyLoopIntersects(l) { return true } } return false } // Polygon A is disjoint from B if A excludes the entire boundary of B and B // excludes all shell boundaries of A. (It can be shown that B must then // exclude the entire boundary of A.) The first call below returns false if // the boundaries cross, therefore the second call does not need to check // for crossing edges. return !p.excludesBoundary(o) || !o.excludesNonCrossingShells(p) }
go
func (p *Polygon) Intersects(o *Polygon) bool { // If both polygons have one loop, use the more efficient Loop method. // Note that Loop Intersects does its own bounding rectangle check. if len(p.loops) == 1 && len(o.loops) == 1 { return p.loops[0].Intersects(o.loops[0]) } // Otherwise if neither polygon has holes, we can still use the more // efficient Loop.Intersects method. The polygons intersect if and // only if some pair of loop regions intersect. if !p.bound.Intersects(o.bound) { return false } if !p.hasHoles && !o.hasHoles { for _, l := range o.loops { if p.anyLoopIntersects(l) { return true } } return false } // Polygon A is disjoint from B if A excludes the entire boundary of B and B // excludes all shell boundaries of A. (It can be shown that B must then // exclude the entire boundary of A.) The first call below returns false if // the boundaries cross, therefore the second call does not need to check // for crossing edges. return !p.excludesBoundary(o) || !o.excludesNonCrossingShells(p) }
[ "func", "(", "p", "*", "Polygon", ")", "Intersects", "(", "o", "*", "Polygon", ")", "bool", "{", "// If both polygons have one loop, use the more efficient Loop method.", "// Note that Loop Intersects does its own bounding rectangle check.", "if", "len", "(", "p", ".", "loo...
// Intersects reports whether this polygon intersects the other polygon, i.e. // if there is a point that is contained by both polygons.
[ "Intersects", "reports", "whether", "this", "polygon", "intersects", "the", "other", "polygon", "i", ".", "e", ".", "if", "there", "is", "a", "point", "that", "is", "contained", "by", "both", "polygons", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/polygon.go#L865-L894
train
golang/geo
s2/polygon.go
compareBoundary
func (p *Polygon) compareBoundary(o *Loop) int { result := -1 for i := 0; i < len(p.loops) && result != 0; i++ { // If B crosses any loop of A, the result is 0. Otherwise the result // changes sign each time B is contained by a loop of A. result *= -p.loops[i].compareBoundary(o) } return result }
go
func (p *Polygon) compareBoundary(o *Loop) int { result := -1 for i := 0; i < len(p.loops) && result != 0; i++ { // If B crosses any loop of A, the result is 0. Otherwise the result // changes sign each time B is contained by a loop of A. result *= -p.loops[i].compareBoundary(o) } return result }
[ "func", "(", "p", "*", "Polygon", ")", "compareBoundary", "(", "o", "*", "Loop", ")", "int", "{", "result", ":=", "-", "1", "\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "p", ".", "loops", ")", "&&", "result", "!=", "0", ";", "i", ...
// compareBoundary returns +1 if this polygon contains the boundary of B, -1 if A // excludes the boundary of B, and 0 if the boundaries of A and B cross.
[ "compareBoundary", "returns", "+", "1", "if", "this", "polygon", "contains", "the", "boundary", "of", "B", "-", "1", "if", "A", "excludes", "the", "boundary", "of", "B", "and", "0", "if", "the", "boundaries", "of", "A", "and", "B", "cross", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/polygon.go#L898-L906
train
golang/geo
s2/polygon.go
containsBoundary
func (p *Polygon) containsBoundary(o *Polygon) bool { for _, l := range o.loops { if p.compareBoundary(l) <= 0 { return false } } return true }
go
func (p *Polygon) containsBoundary(o *Polygon) bool { for _, l := range o.loops { if p.compareBoundary(l) <= 0 { return false } } return true }
[ "func", "(", "p", "*", "Polygon", ")", "containsBoundary", "(", "o", "*", "Polygon", ")", "bool", "{", "for", "_", ",", "l", ":=", "range", "o", ".", "loops", "{", "if", "p", ".", "compareBoundary", "(", "l", ")", "<=", "0", "{", "return", "false...
// containsBoundary reports whether this polygon contains the entire boundary of B.
[ "containsBoundary", "reports", "whether", "this", "polygon", "contains", "the", "entire", "boundary", "of", "B", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/polygon.go#L909-L916
train
golang/geo
s2/polygon.go
containsNonCrossingBoundary
func (p *Polygon) containsNonCrossingBoundary(o *Loop, reverse bool) bool { var inside bool for _, l := range p.loops { x := l.containsNonCrossingBoundary(o, reverse) inside = (inside != x) } return inside }
go
func (p *Polygon) containsNonCrossingBoundary(o *Loop, reverse bool) bool { var inside bool for _, l := range p.loops { x := l.containsNonCrossingBoundary(o, reverse) inside = (inside != x) } return inside }
[ "func", "(", "p", "*", "Polygon", ")", "containsNonCrossingBoundary", "(", "o", "*", "Loop", ",", "reverse", "bool", ")", "bool", "{", "var", "inside", "bool", "\n", "for", "_", ",", "l", ":=", "range", "p", ".", "loops", "{", "x", ":=", "l", ".", ...
// containsNonCrossingBoundary reports whether polygon A contains the boundary of // loop B. Shared edges are handled according to the rule described in loops // containsNonCrossingBoundary.
[ "containsNonCrossingBoundary", "reports", "whether", "polygon", "A", "contains", "the", "boundary", "of", "loop", "B", ".", "Shared", "edges", "are", "handled", "according", "to", "the", "rule", "described", "in", "loops", "containsNonCrossingBoundary", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/polygon.go#L931-L938
train
golang/geo
s2/polygon.go
excludesNonCrossingShells
func (p *Polygon) excludesNonCrossingShells(o *Polygon) bool { for _, l := range o.loops { if l.IsHole() { continue } if p.containsNonCrossingBoundary(l, false) { return false } } return true }
go
func (p *Polygon) excludesNonCrossingShells(o *Polygon) bool { for _, l := range o.loops { if l.IsHole() { continue } if p.containsNonCrossingBoundary(l, false) { return false } } return true }
[ "func", "(", "p", "*", "Polygon", ")", "excludesNonCrossingShells", "(", "o", "*", "Polygon", ")", "bool", "{", "for", "_", ",", "l", ":=", "range", "o", ".", "loops", "{", "if", "l", ".", "IsHole", "(", ")", "{", "continue", "\n", "}", "\n", "if...
// excludesNonCrossingShells reports wheterh given two polygons A and B such that the // boundary of A does not cross any loop of B, if A excludes all shell boundaries of B.
[ "excludesNonCrossingShells", "reports", "wheterh", "given", "two", "polygons", "A", "and", "B", "such", "that", "the", "boundary", "of", "A", "does", "not", "cross", "any", "loop", "of", "B", "if", "A", "excludes", "all", "shell", "boundaries", "of", "B", ...
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/polygon.go#L942-L952
train
golang/geo
s2/polygon.go
excludesNonCrossingComplementShells
func (p *Polygon) excludesNonCrossingComplementShells(o *Polygon) bool { // Special case to handle the complement of the empty or full polygons. if o.IsEmpty() { return !p.IsFull() } if o.IsFull() { return true } // Otherwise the complement of B may be obtained by inverting loop(0) and // then swapping the shell/hole status of all other loops. This implies // that the shells of the complement consist of loop 0 plus all the holes of // the original polygon. for j, l := range o.loops { if j > 0 && !l.IsHole() { continue } // The interior of the complement is to the right of loop 0, and to the // left of the loops that were originally holes. if p.containsNonCrossingBoundary(l, j == 0) { return false } } return true }
go
func (p *Polygon) excludesNonCrossingComplementShells(o *Polygon) bool { // Special case to handle the complement of the empty or full polygons. if o.IsEmpty() { return !p.IsFull() } if o.IsFull() { return true } // Otherwise the complement of B may be obtained by inverting loop(0) and // then swapping the shell/hole status of all other loops. This implies // that the shells of the complement consist of loop 0 plus all the holes of // the original polygon. for j, l := range o.loops { if j > 0 && !l.IsHole() { continue } // The interior of the complement is to the right of loop 0, and to the // left of the loops that were originally holes. if p.containsNonCrossingBoundary(l, j == 0) { return false } } return true }
[ "func", "(", "p", "*", "Polygon", ")", "excludesNonCrossingComplementShells", "(", "o", "*", "Polygon", ")", "bool", "{", "// Special case to handle the complement of the empty or full polygons.", "if", "o", ".", "IsEmpty", "(", ")", "{", "return", "!", "p", ".", ...
// excludesNonCrossingComplementShells reports whether given two polygons A and B // such that the boundary of A does not cross any loop of B, if A excludes all // shell boundaries of the complement of B.
[ "excludesNonCrossingComplementShells", "reports", "whether", "given", "two", "polygons", "A", "and", "B", "such", "that", "the", "boundary", "of", "A", "does", "not", "cross", "any", "loop", "of", "B", "if", "A", "excludes", "all", "shell", "boundaries", "of",...
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/polygon.go#L957-L982
train
golang/geo
s2/polygon.go
anyLoopContains
func (p *Polygon) anyLoopContains(o *Loop) bool { for _, l := range p.loops { if l.Contains(o) { return true } } return false }
go
func (p *Polygon) anyLoopContains(o *Loop) bool { for _, l := range p.loops { if l.Contains(o) { return true } } return false }
[ "func", "(", "p", "*", "Polygon", ")", "anyLoopContains", "(", "o", "*", "Loop", ")", "bool", "{", "for", "_", ",", "l", ":=", "range", "p", ".", "loops", "{", "if", "l", ".", "Contains", "(", "o", ")", "{", "return", "true", "\n", "}", "\n", ...
// anyLoopContains reports whether any loop in this polygon contains the given loop.
[ "anyLoopContains", "reports", "whether", "any", "loop", "in", "this", "polygon", "contains", "the", "given", "loop", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/polygon.go#L985-L992
train
golang/geo
s2/polygon.go
anyLoopIntersects
func (p *Polygon) anyLoopIntersects(o *Loop) bool { for _, l := range p.loops { if l.Intersects(o) { return true } } return false }
go
func (p *Polygon) anyLoopIntersects(o *Loop) bool { for _, l := range p.loops { if l.Intersects(o) { return true } } return false }
[ "func", "(", "p", "*", "Polygon", ")", "anyLoopIntersects", "(", "o", "*", "Loop", ")", "bool", "{", "for", "_", ",", "l", ":=", "range", "p", ".", "loops", "{", "if", "l", ".", "Intersects", "(", "o", ")", "{", "return", "true", "\n", "}", "\n...
// anyLoopIntersects reports whether any loop in this polygon intersects the given loop.
[ "anyLoopIntersects", "reports", "whether", "any", "loop", "in", "this", "polygon", "intersects", "the", "given", "loop", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/polygon.go#L995-L1002
train
golang/geo
s2/polygon.go
encode
func (p *Polygon) encode(e *encoder) { if p.numVertices == 0 { p.encodeCompressed(e, maxLevel, nil) return } // Convert all the polygon vertices to XYZFaceSiTi format. vs := make([]xyzFaceSiTi, 0, p.numVertices) for _, l := range p.loops { vs = append(vs, l.xyzFaceSiTiVertices()...) } // Computes a histogram of the cell levels at which the vertices are snapped. // (histogram[0] is the number of unsnapped vertices, histogram[i] the number // of vertices snapped at level i-1). histogram := make([]int, maxLevel+2) for _, v := range vs { histogram[v.level+1]++ } // Compute the level at which most of the vertices are snapped. // If multiple levels have the same maximum number of vertices // snapped to it, the first one (lowest level number / largest // area / smallest encoding length) will be chosen, so this // is desired. var snapLevel, numSnapped int for level, h := range histogram[1:] { if h > numSnapped { snapLevel, numSnapped = level, h } } // Choose an encoding format based on the number of unsnapped vertices and a // rough estimate of the encoded sizes. numUnsnapped := p.numVertices - numSnapped // Number of vertices that won't be snapped at snapLevel. const pointSize = 3 * 8 // s2.Point is an r3.Vector, which is 3 float64s. That's 3*8 = 24 bytes. compressedSize := 4*p.numVertices + (pointSize+2)*numUnsnapped losslessSize := pointSize * p.numVertices if compressedSize < losslessSize { p.encodeCompressed(e, snapLevel, vs) } else { p.encodeLossless(e) } }
go
func (p *Polygon) encode(e *encoder) { if p.numVertices == 0 { p.encodeCompressed(e, maxLevel, nil) return } // Convert all the polygon vertices to XYZFaceSiTi format. vs := make([]xyzFaceSiTi, 0, p.numVertices) for _, l := range p.loops { vs = append(vs, l.xyzFaceSiTiVertices()...) } // Computes a histogram of the cell levels at which the vertices are snapped. // (histogram[0] is the number of unsnapped vertices, histogram[i] the number // of vertices snapped at level i-1). histogram := make([]int, maxLevel+2) for _, v := range vs { histogram[v.level+1]++ } // Compute the level at which most of the vertices are snapped. // If multiple levels have the same maximum number of vertices // snapped to it, the first one (lowest level number / largest // area / smallest encoding length) will be chosen, so this // is desired. var snapLevel, numSnapped int for level, h := range histogram[1:] { if h > numSnapped { snapLevel, numSnapped = level, h } } // Choose an encoding format based on the number of unsnapped vertices and a // rough estimate of the encoded sizes. numUnsnapped := p.numVertices - numSnapped // Number of vertices that won't be snapped at snapLevel. const pointSize = 3 * 8 // s2.Point is an r3.Vector, which is 3 float64s. That's 3*8 = 24 bytes. compressedSize := 4*p.numVertices + (pointSize+2)*numUnsnapped losslessSize := pointSize * p.numVertices if compressedSize < losslessSize { p.encodeCompressed(e, snapLevel, vs) } else { p.encodeLossless(e) } }
[ "func", "(", "p", "*", "Polygon", ")", "encode", "(", "e", "*", "encoder", ")", "{", "if", "p", ".", "numVertices", "==", "0", "{", "p", ".", "encodeCompressed", "(", "e", ",", "maxLevel", ",", "nil", ")", "\n", "return", "\n", "}", "\n\n", "// C...
// encode only supports lossless encoding and not compressed format.
[ "encode", "only", "supports", "lossless", "encoding", "and", "not", "compressed", "format", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/polygon.go#L1022-L1065
train
golang/geo
s2/polygon.go
encodeLossless
func (p *Polygon) encodeLossless(e *encoder) { e.writeInt8(encodingVersion) e.writeBool(true) // a legacy c++ value. must be true. e.writeBool(p.hasHoles) e.writeUint32(uint32(len(p.loops))) if e.err != nil { return } if len(p.loops) > maxEncodedLoops { e.err = fmt.Errorf("too many loops (%d; max is %d)", len(p.loops), maxEncodedLoops) return } for _, l := range p.loops { l.encode(e) } // Encode the bound. p.bound.encode(e) }
go
func (p *Polygon) encodeLossless(e *encoder) { e.writeInt8(encodingVersion) e.writeBool(true) // a legacy c++ value. must be true. e.writeBool(p.hasHoles) e.writeUint32(uint32(len(p.loops))) if e.err != nil { return } if len(p.loops) > maxEncodedLoops { e.err = fmt.Errorf("too many loops (%d; max is %d)", len(p.loops), maxEncodedLoops) return } for _, l := range p.loops { l.encode(e) } // Encode the bound. p.bound.encode(e) }
[ "func", "(", "p", "*", "Polygon", ")", "encodeLossless", "(", "e", "*", "encoder", ")", "{", "e", ".", "writeInt8", "(", "encodingVersion", ")", "\n", "e", ".", "writeBool", "(", "true", ")", "// a legacy c++ value. must be true.", "\n", "e", ".", "writeBo...
// encodeLossless encodes the polygon's Points as float64s.
[ "encodeLossless", "encodes", "the", "polygon", "s", "Points", "as", "float64s", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/polygon.go#L1068-L1087
train
golang/geo
s2/polygon.go
Decode
func (p *Polygon) Decode(r io.Reader) error { d := &decoder{r: asByteReader(r)} version := int8(d.readUint8()) var dec func(*decoder) switch version { case encodingVersion: dec = p.decode case encodingCompressedVersion: dec = p.decodeCompressed default: return fmt.Errorf("unsupported version %d", version) } dec(d) return d.err }
go
func (p *Polygon) Decode(r io.Reader) error { d := &decoder{r: asByteReader(r)} version := int8(d.readUint8()) var dec func(*decoder) switch version { case encodingVersion: dec = p.decode case encodingCompressedVersion: dec = p.decodeCompressed default: return fmt.Errorf("unsupported version %d", version) } dec(d) return d.err }
[ "func", "(", "p", "*", "Polygon", ")", "Decode", "(", "r", "io", ".", "Reader", ")", "error", "{", "d", ":=", "&", "decoder", "{", "r", ":", "asByteReader", "(", "r", ")", "}", "\n", "version", ":=", "int8", "(", "d", ".", "readUint8", "(", ")"...
// Decode decodes the Polygon.
[ "Decode", "decodes", "the", "Polygon", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/polygon.go#L1112-L1126
train
golang/geo
s2/rect.go
RectFromLatLng
func RectFromLatLng(p LatLng) Rect { return Rect{ Lat: r1.Interval{p.Lat.Radians(), p.Lat.Radians()}, Lng: s1.Interval{p.Lng.Radians(), p.Lng.Radians()}, } }
go
func RectFromLatLng(p LatLng) Rect { return Rect{ Lat: r1.Interval{p.Lat.Radians(), p.Lat.Radians()}, Lng: s1.Interval{p.Lng.Radians(), p.Lng.Radians()}, } }
[ "func", "RectFromLatLng", "(", "p", "LatLng", ")", "Rect", "{", "return", "Rect", "{", "Lat", ":", "r1", ".", "Interval", "{", "p", ".", "Lat", ".", "Radians", "(", ")", ",", "p", ".", "Lat", ".", "Radians", "(", ")", "}", ",", "Lng", ":", "s1"...
// RectFromLatLng constructs a rectangle containing a single point p.
[ "RectFromLatLng", "constructs", "a", "rectangle", "containing", "a", "single", "point", "p", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/rect.go#L45-L50
train
golang/geo
s2/rect.go
Lo
func (r Rect) Lo() LatLng { return LatLng{s1.Angle(r.Lat.Lo) * s1.Radian, s1.Angle(r.Lng.Lo) * s1.Radian} }
go
func (r Rect) Lo() LatLng { return LatLng{s1.Angle(r.Lat.Lo) * s1.Radian, s1.Angle(r.Lng.Lo) * s1.Radian} }
[ "func", "(", "r", "Rect", ")", "Lo", "(", ")", "LatLng", "{", "return", "LatLng", "{", "s1", ".", "Angle", "(", "r", ".", "Lat", ".", "Lo", ")", "*", "s1", ".", "Radian", ",", "s1", ".", "Angle", "(", "r", ".", "Lng", ".", "Lo", ")", "*", ...
// Lo returns one corner of the rectangle.
[ "Lo", "returns", "one", "corner", "of", "the", "rectangle", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/rect.go#L108-L110
train
golang/geo
s2/rect.go
Size
func (r Rect) Size() LatLng { return LatLng{s1.Angle(r.Lat.Length()) * s1.Radian, s1.Angle(r.Lng.Length()) * s1.Radian} }
go
func (r Rect) Size() LatLng { return LatLng{s1.Angle(r.Lat.Length()) * s1.Radian, s1.Angle(r.Lng.Length()) * s1.Radian} }
[ "func", "(", "r", "Rect", ")", "Size", "(", ")", "LatLng", "{", "return", "LatLng", "{", "s1", ".", "Angle", "(", "r", ".", "Lat", ".", "Length", "(", ")", ")", "*", "s1", ".", "Radian", ",", "s1", ".", "Angle", "(", "r", ".", "Lng", ".", "...
// Size returns the size of the Rect.
[ "Size", "returns", "the", "size", "of", "the", "Rect", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/rect.go#L123-L125
train
golang/geo
s2/rect.go
Area
func (r Rect) Area() float64 { if r.IsEmpty() { return 0 } capDiff := math.Abs(math.Sin(r.Lat.Hi) - math.Sin(r.Lat.Lo)) return r.Lng.Length() * capDiff }
go
func (r Rect) Area() float64 { if r.IsEmpty() { return 0 } capDiff := math.Abs(math.Sin(r.Lat.Hi) - math.Sin(r.Lat.Lo)) return r.Lng.Length() * capDiff }
[ "func", "(", "r", "Rect", ")", "Area", "(", ")", "float64", "{", "if", "r", ".", "IsEmpty", "(", ")", "{", "return", "0", "\n", "}", "\n", "capDiff", ":=", "math", ".", "Abs", "(", "math", ".", "Sin", "(", "r", ".", "Lat", ".", "Hi", ")", "...
// Area returns the surface area of the Rect.
[ "Area", "returns", "the", "surface", "area", "of", "the", "Rect", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/rect.go#L128-L134
train
golang/geo
s2/rect.go
AddPoint
func (r Rect) AddPoint(ll LatLng) Rect { if !ll.IsValid() { return r } return Rect{ Lat: r.Lat.AddPoint(ll.Lat.Radians()), Lng: r.Lng.AddPoint(ll.Lng.Radians()), } }
go
func (r Rect) AddPoint(ll LatLng) Rect { if !ll.IsValid() { return r } return Rect{ Lat: r.Lat.AddPoint(ll.Lat.Radians()), Lng: r.Lng.AddPoint(ll.Lng.Radians()), } }
[ "func", "(", "r", "Rect", ")", "AddPoint", "(", "ll", "LatLng", ")", "Rect", "{", "if", "!", "ll", ".", "IsValid", "(", ")", "{", "return", "r", "\n", "}", "\n", "return", "Rect", "{", "Lat", ":", "r", ".", "Lat", ".", "AddPoint", "(", "ll", ...
// AddPoint increases the size of the rectangle to include the given point.
[ "AddPoint", "increases", "the", "size", "of", "the", "rectangle", "to", "include", "the", "given", "point", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/rect.go#L137-L145
train
golang/geo
s2/rect.go
PolarClosure
func (r Rect) PolarClosure() Rect { if r.Lat.Lo == -math.Pi/2 || r.Lat.Hi == math.Pi/2 { return Rect{r.Lat, s1.FullInterval()} } return r }
go
func (r Rect) PolarClosure() Rect { if r.Lat.Lo == -math.Pi/2 || r.Lat.Hi == math.Pi/2 { return Rect{r.Lat, s1.FullInterval()} } return r }
[ "func", "(", "r", "Rect", ")", "PolarClosure", "(", ")", "Rect", "{", "if", "r", ".", "Lat", ".", "Lo", "==", "-", "math", ".", "Pi", "/", "2", "||", "r", ".", "Lat", ".", "Hi", "==", "math", ".", "Pi", "/", "2", "{", "return", "Rect", "{",...
// PolarClosure returns the rectangle unmodified if it does not include either pole. // If it includes either pole, PolarClosure returns an expansion of the rectangle along // the longitudinal range to include all possible representations of the contained poles.
[ "PolarClosure", "returns", "the", "rectangle", "unmodified", "if", "it", "does", "not", "include", "either", "pole", ".", "If", "it", "includes", "either", "pole", "PolarClosure", "returns", "an", "expansion", "of", "the", "rectangle", "along", "the", "longitudi...
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/rect.go#L189-L194
train
golang/geo
s2/rect.go
Union
func (r Rect) Union(other Rect) Rect { return Rect{ Lat: r.Lat.Union(other.Lat), Lng: r.Lng.Union(other.Lng), } }
go
func (r Rect) Union(other Rect) Rect { return Rect{ Lat: r.Lat.Union(other.Lat), Lng: r.Lng.Union(other.Lng), } }
[ "func", "(", "r", "Rect", ")", "Union", "(", "other", "Rect", ")", "Rect", "{", "return", "Rect", "{", "Lat", ":", "r", ".", "Lat", ".", "Union", "(", "other", ".", "Lat", ")", ",", "Lng", ":", "r", ".", "Lng", ".", "Union", "(", "other", "."...
// Union returns the smallest Rect containing the union of this rectangle and the given rectangle.
[ "Union", "returns", "the", "smallest", "Rect", "containing", "the", "union", "of", "this", "rectangle", "and", "the", "given", "rectangle", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/rect.go#L197-L202
train
golang/geo
s2/rect.go
Intersection
func (r Rect) Intersection(other Rect) Rect { lat := r.Lat.Intersection(other.Lat) lng := r.Lng.Intersection(other.Lng) if lat.IsEmpty() || lng.IsEmpty() { return EmptyRect() } return Rect{lat, lng} }
go
func (r Rect) Intersection(other Rect) Rect { lat := r.Lat.Intersection(other.Lat) lng := r.Lng.Intersection(other.Lng) if lat.IsEmpty() || lng.IsEmpty() { return EmptyRect() } return Rect{lat, lng} }
[ "func", "(", "r", "Rect", ")", "Intersection", "(", "other", "Rect", ")", "Rect", "{", "lat", ":=", "r", ".", "Lat", ".", "Intersection", "(", "other", ".", "Lat", ")", "\n", "lng", ":=", "r", ".", "Lng", ".", "Intersection", "(", "other", ".", "...
// Intersection returns the smallest rectangle containing the intersection of // this rectangle and the given rectangle. Note that the region of intersection // may consist of two disjoint rectangles, in which case a single rectangle // spanning both of them is returned.
[ "Intersection", "returns", "the", "smallest", "rectangle", "containing", "the", "intersection", "of", "this", "rectangle", "and", "the", "given", "rectangle", ".", "Note", "that", "the", "region", "of", "intersection", "may", "consist", "of", "two", "disjoint", ...
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/rect.go#L208-L216
train
golang/geo
s2/rect.go
Intersects
func (r Rect) Intersects(other Rect) bool { return r.Lat.Intersects(other.Lat) && r.Lng.Intersects(other.Lng) }
go
func (r Rect) Intersects(other Rect) bool { return r.Lat.Intersects(other.Lat) && r.Lng.Intersects(other.Lng) }
[ "func", "(", "r", "Rect", ")", "Intersects", "(", "other", "Rect", ")", "bool", "{", "return", "r", ".", "Lat", ".", "Intersects", "(", "other", ".", "Lat", ")", "&&", "r", ".", "Lng", ".", "Intersects", "(", "other", ".", "Lng", ")", "\n", "}" ]
// Intersects reports whether this rectangle and the other have any points in common.
[ "Intersects", "reports", "whether", "this", "rectangle", "and", "the", "other", "have", "any", "points", "in", "common", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/rect.go#L219-L221
train
golang/geo
s2/rect.go
CapBound
func (r Rect) CapBound() Cap { // We consider two possible bounding caps, one whose axis passes // through the center of the lat-long rectangle and one whose axis // is the north or south pole. We return the smaller of the two caps. if r.IsEmpty() { return EmptyCap() } var poleZ, poleAngle float64 if r.Lat.Hi+r.Lat.Lo < 0 { // South pole axis yields smaller cap. poleZ = -1 poleAngle = math.Pi/2 + r.Lat.Hi } else { poleZ = 1 poleAngle = math.Pi/2 - r.Lat.Lo } poleCap := CapFromCenterAngle(Point{r3.Vector{0, 0, poleZ}}, s1.Angle(poleAngle)*s1.Radian) // For bounding rectangles that span 180 degrees or less in longitude, the // maximum cap size is achieved at one of the rectangle vertices. For // rectangles that are larger than 180 degrees, we punt and always return a // bounding cap centered at one of the two poles. if math.Remainder(r.Lng.Hi-r.Lng.Lo, 2*math.Pi) >= 0 && r.Lng.Hi-r.Lng.Lo < 2*math.Pi { midCap := CapFromPoint(PointFromLatLng(r.Center())).AddPoint(PointFromLatLng(r.Lo())).AddPoint(PointFromLatLng(r.Hi())) if midCap.Height() < poleCap.Height() { return midCap } } return poleCap }
go
func (r Rect) CapBound() Cap { // We consider two possible bounding caps, one whose axis passes // through the center of the lat-long rectangle and one whose axis // is the north or south pole. We return the smaller of the two caps. if r.IsEmpty() { return EmptyCap() } var poleZ, poleAngle float64 if r.Lat.Hi+r.Lat.Lo < 0 { // South pole axis yields smaller cap. poleZ = -1 poleAngle = math.Pi/2 + r.Lat.Hi } else { poleZ = 1 poleAngle = math.Pi/2 - r.Lat.Lo } poleCap := CapFromCenterAngle(Point{r3.Vector{0, 0, poleZ}}, s1.Angle(poleAngle)*s1.Radian) // For bounding rectangles that span 180 degrees or less in longitude, the // maximum cap size is achieved at one of the rectangle vertices. For // rectangles that are larger than 180 degrees, we punt and always return a // bounding cap centered at one of the two poles. if math.Remainder(r.Lng.Hi-r.Lng.Lo, 2*math.Pi) >= 0 && r.Lng.Hi-r.Lng.Lo < 2*math.Pi { midCap := CapFromPoint(PointFromLatLng(r.Center())).AddPoint(PointFromLatLng(r.Lo())).AddPoint(PointFromLatLng(r.Hi())) if midCap.Height() < poleCap.Height() { return midCap } } return poleCap }
[ "func", "(", "r", "Rect", ")", "CapBound", "(", ")", "Cap", "{", "// We consider two possible bounding caps, one whose axis passes", "// through the center of the lat-long rectangle and one whose axis", "// is the north or south pole. We return the smaller of the two caps.", "if", "r", ...
// CapBound returns a cap that countains Rect.
[ "CapBound", "returns", "a", "cap", "that", "countains", "Rect", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/rect.go#L224-L255
train
golang/geo
s2/rect.go
Contains
func (r Rect) Contains(other Rect) bool { return r.Lat.ContainsInterval(other.Lat) && r.Lng.ContainsInterval(other.Lng) }
go
func (r Rect) Contains(other Rect) bool { return r.Lat.ContainsInterval(other.Lat) && r.Lng.ContainsInterval(other.Lng) }
[ "func", "(", "r", "Rect", ")", "Contains", "(", "other", "Rect", ")", "bool", "{", "return", "r", ".", "Lat", ".", "ContainsInterval", "(", "other", ".", "Lat", ")", "&&", "r", ".", "Lng", ".", "ContainsInterval", "(", "other", ".", "Lng", ")", "\n...
// Contains reports whether this Rect contains the other Rect.
[ "Contains", "reports", "whether", "this", "Rect", "contains", "the", "other", "Rect", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/rect.go#L263-L265
train
golang/geo
s2/rect.go
ContainsCell
func (r Rect) ContainsCell(c Cell) bool { // A latitude-longitude rectangle contains a cell if and only if it contains // the cell's bounding rectangle. This test is exact from a mathematical // point of view, assuming that the bounds returned by Cell.RectBound() // are tight. However, note that there can be a loss of precision when // converting between representations -- for example, if an s2.Cell is // converted to a polygon, the polygon's bounding rectangle may not contain // the cell's bounding rectangle. This has some slightly unexpected side // effects; for instance, if one creates an s2.Polygon from an s2.Cell, the // polygon will contain the cell, but the polygon's bounding box will not. return r.Contains(c.RectBound()) }
go
func (r Rect) ContainsCell(c Cell) bool { // A latitude-longitude rectangle contains a cell if and only if it contains // the cell's bounding rectangle. This test is exact from a mathematical // point of view, assuming that the bounds returned by Cell.RectBound() // are tight. However, note that there can be a loss of precision when // converting between representations -- for example, if an s2.Cell is // converted to a polygon, the polygon's bounding rectangle may not contain // the cell's bounding rectangle. This has some slightly unexpected side // effects; for instance, if one creates an s2.Polygon from an s2.Cell, the // polygon will contain the cell, but the polygon's bounding box will not. return r.Contains(c.RectBound()) }
[ "func", "(", "r", "Rect", ")", "ContainsCell", "(", "c", "Cell", ")", "bool", "{", "// A latitude-longitude rectangle contains a cell if and only if it contains", "// the cell's bounding rectangle. This test is exact from a mathematical", "// point of view, assuming that the bounds retur...
// ContainsCell reports whether the given Cell is contained by this Rect.
[ "ContainsCell", "reports", "whether", "the", "given", "Cell", "is", "contained", "by", "this", "Rect", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/rect.go#L268-L279
train
golang/geo
s2/rect.go
ContainsLatLng
func (r Rect) ContainsLatLng(ll LatLng) bool { if !ll.IsValid() { return false } return r.Lat.Contains(ll.Lat.Radians()) && r.Lng.Contains(ll.Lng.Radians()) }
go
func (r Rect) ContainsLatLng(ll LatLng) bool { if !ll.IsValid() { return false } return r.Lat.Contains(ll.Lat.Radians()) && r.Lng.Contains(ll.Lng.Radians()) }
[ "func", "(", "r", "Rect", ")", "ContainsLatLng", "(", "ll", "LatLng", ")", "bool", "{", "if", "!", "ll", ".", "IsValid", "(", ")", "{", "return", "false", "\n", "}", "\n", "return", "r", ".", "Lat", ".", "Contains", "(", "ll", ".", "Lat", ".", ...
// ContainsLatLng reports whether the given LatLng is within the Rect.
[ "ContainsLatLng", "reports", "whether", "the", "given", "LatLng", "is", "within", "the", "Rect", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/rect.go#L282-L287
train
golang/geo
s2/rect.go
ContainsPoint
func (r Rect) ContainsPoint(p Point) bool { return r.ContainsLatLng(LatLngFromPoint(p)) }
go
func (r Rect) ContainsPoint(p Point) bool { return r.ContainsLatLng(LatLngFromPoint(p)) }
[ "func", "(", "r", "Rect", ")", "ContainsPoint", "(", "p", "Point", ")", "bool", "{", "return", "r", ".", "ContainsLatLng", "(", "LatLngFromPoint", "(", "p", ")", ")", "\n", "}" ]
// ContainsPoint reports whether the given Point is within the Rect.
[ "ContainsPoint", "reports", "whether", "the", "given", "Point", "is", "within", "the", "Rect", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/rect.go#L290-L292
train
golang/geo
s2/rect.go
intersectsLatEdge
func intersectsLatEdge(a, b Point, lat s1.Angle, lng s1.Interval) bool { // Unfortunately, lines of constant latitude are curves on // the sphere. They can intersect a straight edge in 0, 1, or 2 points. // First, compute the normal to the plane AB that points vaguely north. z := Point{a.PointCross(b).Normalize()} if z.Z < 0 { z = Point{z.Mul(-1)} } // Extend this to an orthonormal frame (x,y,z) where x is the direction // where the great circle through AB achieves its maximium latitude. y := Point{z.PointCross(PointFromCoords(0, 0, 1)).Normalize()} x := y.Cross(z.Vector) // Compute the angle "theta" from the x-axis (in the x-y plane defined // above) where the great circle intersects the given line of latitude. sinLat := math.Sin(float64(lat)) if math.Abs(sinLat) >= x.Z { // The great circle does not reach the given latitude. return false } cosTheta := sinLat / x.Z sinTheta := math.Sqrt(1 - cosTheta*cosTheta) theta := math.Atan2(sinTheta, cosTheta) // The candidate intersection points are located +/- theta in the x-y // plane. For an intersection to be valid, we need to check that the // intersection point is contained in the interior of the edge AB and // also that it is contained within the given longitude interval "lng". // Compute the range of theta values spanned by the edge AB. abTheta := s1.IntervalFromPointPair( math.Atan2(a.Dot(y.Vector), a.Dot(x)), math.Atan2(b.Dot(y.Vector), b.Dot(x))) if abTheta.Contains(theta) { // Check if the intersection point is also in the given lng interval. isect := x.Mul(cosTheta).Add(y.Mul(sinTheta)) if lng.Contains(math.Atan2(isect.Y, isect.X)) { return true } } if abTheta.Contains(-theta) { // Check if the other intersection point is also in the given lng interval. isect := x.Mul(cosTheta).Sub(y.Mul(sinTheta)) if lng.Contains(math.Atan2(isect.Y, isect.X)) { return true } } return false }
go
func intersectsLatEdge(a, b Point, lat s1.Angle, lng s1.Interval) bool { // Unfortunately, lines of constant latitude are curves on // the sphere. They can intersect a straight edge in 0, 1, or 2 points. // First, compute the normal to the plane AB that points vaguely north. z := Point{a.PointCross(b).Normalize()} if z.Z < 0 { z = Point{z.Mul(-1)} } // Extend this to an orthonormal frame (x,y,z) where x is the direction // where the great circle through AB achieves its maximium latitude. y := Point{z.PointCross(PointFromCoords(0, 0, 1)).Normalize()} x := y.Cross(z.Vector) // Compute the angle "theta" from the x-axis (in the x-y plane defined // above) where the great circle intersects the given line of latitude. sinLat := math.Sin(float64(lat)) if math.Abs(sinLat) >= x.Z { // The great circle does not reach the given latitude. return false } cosTheta := sinLat / x.Z sinTheta := math.Sqrt(1 - cosTheta*cosTheta) theta := math.Atan2(sinTheta, cosTheta) // The candidate intersection points are located +/- theta in the x-y // plane. For an intersection to be valid, we need to check that the // intersection point is contained in the interior of the edge AB and // also that it is contained within the given longitude interval "lng". // Compute the range of theta values spanned by the edge AB. abTheta := s1.IntervalFromPointPair( math.Atan2(a.Dot(y.Vector), a.Dot(x)), math.Atan2(b.Dot(y.Vector), b.Dot(x))) if abTheta.Contains(theta) { // Check if the intersection point is also in the given lng interval. isect := x.Mul(cosTheta).Add(y.Mul(sinTheta)) if lng.Contains(math.Atan2(isect.Y, isect.X)) { return true } } if abTheta.Contains(-theta) { // Check if the other intersection point is also in the given lng interval. isect := x.Mul(cosTheta).Sub(y.Mul(sinTheta)) if lng.Contains(math.Atan2(isect.Y, isect.X)) { return true } } return false }
[ "func", "intersectsLatEdge", "(", "a", ",", "b", "Point", ",", "lat", "s1", ".", "Angle", ",", "lng", "s1", ".", "Interval", ")", "bool", "{", "// Unfortunately, lines of constant latitude are curves on", "// the sphere. They can intersect a straight edge in 0, 1, or 2 poin...
// intersectsLatEdge reports whether the edge AB intersects the given edge of constant // latitude. Requires the points to have unit length.
[ "intersectsLatEdge", "reports", "whether", "the", "edge", "AB", "intersects", "the", "given", "edge", "of", "constant", "latitude", ".", "Requires", "the", "points", "to", "have", "unit", "length", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/rect.go#L301-L354
train
golang/geo
s2/rect.go
intersectsLngEdge
func intersectsLngEdge(a, b Point, lat r1.Interval, lng s1.Angle) bool { // The nice thing about edges of constant longitude is that // they are straight lines on the sphere (geodesics). return CrossingSign(a, b, PointFromLatLng(LatLng{s1.Angle(lat.Lo), lng}), PointFromLatLng(LatLng{s1.Angle(lat.Hi), lng})) == Cross }
go
func intersectsLngEdge(a, b Point, lat r1.Interval, lng s1.Angle) bool { // The nice thing about edges of constant longitude is that // they are straight lines on the sphere (geodesics). return CrossingSign(a, b, PointFromLatLng(LatLng{s1.Angle(lat.Lo), lng}), PointFromLatLng(LatLng{s1.Angle(lat.Hi), lng})) == Cross }
[ "func", "intersectsLngEdge", "(", "a", ",", "b", "Point", ",", "lat", "r1", ".", "Interval", ",", "lng", "s1", ".", "Angle", ")", "bool", "{", "// The nice thing about edges of constant longitude is that", "// they are straight lines on the sphere (geodesics).", "return",...
// intersectsLngEdge reports whether the edge AB intersects the given edge of constant // longitude. Requires the points to have unit length.
[ "intersectsLngEdge", "reports", "whether", "the", "edge", "AB", "intersects", "the", "given", "edge", "of", "constant", "longitude", ".", "Requires", "the", "points", "to", "have", "unit", "length", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/rect.go#L358-L363
train
golang/geo
s2/rect.go
IntersectsCell
func (r Rect) IntersectsCell(c Cell) bool { // First we eliminate the cases where one region completely contains the // other. Once these are disposed of, then the regions will intersect // if and only if their boundaries intersect. if r.IsEmpty() { return false } if r.ContainsPoint(Point{c.id.rawPoint()}) { return true } if c.ContainsPoint(PointFromLatLng(r.Center())) { return true } // Quick rejection test (not required for correctness). if !r.Intersects(c.RectBound()) { return false } // Precompute the cell vertices as points and latitude-longitudes. We also // check whether the Cell contains any corner of the rectangle, or // vice-versa, since the edge-crossing tests only check the edge interiors. vertices := [4]Point{} latlngs := [4]LatLng{} for i := range vertices { vertices[i] = c.Vertex(i) latlngs[i] = LatLngFromPoint(vertices[i]) if r.ContainsLatLng(latlngs[i]) { return true } if c.ContainsPoint(PointFromLatLng(r.Vertex(i))) { return true } } // Now check whether the boundaries intersect. Unfortunately, a // latitude-longitude rectangle does not have straight edges: two edges // are curved, and at least one of them is concave. for i := range vertices { edgeLng := s1.IntervalFromEndpoints(latlngs[i].Lng.Radians(), latlngs[(i+1)&3].Lng.Radians()) if !r.Lng.Intersects(edgeLng) { continue } a := vertices[i] b := vertices[(i+1)&3] if edgeLng.Contains(r.Lng.Lo) && intersectsLngEdge(a, b, r.Lat, s1.Angle(r.Lng.Lo)) { return true } if edgeLng.Contains(r.Lng.Hi) && intersectsLngEdge(a, b, r.Lat, s1.Angle(r.Lng.Hi)) { return true } if intersectsLatEdge(a, b, s1.Angle(r.Lat.Lo), r.Lng) { return true } if intersectsLatEdge(a, b, s1.Angle(r.Lat.Hi), r.Lng) { return true } } return false }
go
func (r Rect) IntersectsCell(c Cell) bool { // First we eliminate the cases where one region completely contains the // other. Once these are disposed of, then the regions will intersect // if and only if their boundaries intersect. if r.IsEmpty() { return false } if r.ContainsPoint(Point{c.id.rawPoint()}) { return true } if c.ContainsPoint(PointFromLatLng(r.Center())) { return true } // Quick rejection test (not required for correctness). if !r.Intersects(c.RectBound()) { return false } // Precompute the cell vertices as points and latitude-longitudes. We also // check whether the Cell contains any corner of the rectangle, or // vice-versa, since the edge-crossing tests only check the edge interiors. vertices := [4]Point{} latlngs := [4]LatLng{} for i := range vertices { vertices[i] = c.Vertex(i) latlngs[i] = LatLngFromPoint(vertices[i]) if r.ContainsLatLng(latlngs[i]) { return true } if c.ContainsPoint(PointFromLatLng(r.Vertex(i))) { return true } } // Now check whether the boundaries intersect. Unfortunately, a // latitude-longitude rectangle does not have straight edges: two edges // are curved, and at least one of them is concave. for i := range vertices { edgeLng := s1.IntervalFromEndpoints(latlngs[i].Lng.Radians(), latlngs[(i+1)&3].Lng.Radians()) if !r.Lng.Intersects(edgeLng) { continue } a := vertices[i] b := vertices[(i+1)&3] if edgeLng.Contains(r.Lng.Lo) && intersectsLngEdge(a, b, r.Lat, s1.Angle(r.Lng.Lo)) { return true } if edgeLng.Contains(r.Lng.Hi) && intersectsLngEdge(a, b, r.Lat, s1.Angle(r.Lng.Hi)) { return true } if intersectsLatEdge(a, b, s1.Angle(r.Lat.Lo), r.Lng) { return true } if intersectsLatEdge(a, b, s1.Angle(r.Lat.Hi), r.Lng) { return true } } return false }
[ "func", "(", "r", "Rect", ")", "IntersectsCell", "(", "c", "Cell", ")", "bool", "{", "// First we eliminate the cases where one region completely contains the", "// other. Once these are disposed of, then the regions will intersect", "// if and only if their boundaries intersect.", "if...
// IntersectsCell reports whether this rectangle intersects the given cell. This is an // exact test and may be fairly expensive.
[ "IntersectsCell", "reports", "whether", "this", "rectangle", "intersects", "the", "given", "cell", ".", "This", "is", "an", "exact", "test", "and", "may", "be", "fairly", "expensive", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/rect.go#L367-L428
train
golang/geo
s2/rect.go
Encode
func (r Rect) Encode(w io.Writer) error { e := &encoder{w: w} r.encode(e) return e.err }
go
func (r Rect) Encode(w io.Writer) error { e := &encoder{w: w} r.encode(e) return e.err }
[ "func", "(", "r", "Rect", ")", "Encode", "(", "w", "io", ".", "Writer", ")", "error", "{", "e", ":=", "&", "encoder", "{", "w", ":", "w", "}", "\n", "r", ".", "encode", "(", "e", ")", "\n", "return", "e", ".", "err", "\n", "}" ]
// Encode encodes the Rect.
[ "Encode", "encodes", "the", "Rect", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/rect.go#L431-L435
train
golang/geo
s2/rect.go
Decode
func (r *Rect) Decode(rd io.Reader) error { d := &decoder{r: asByteReader(rd)} r.decode(d) return d.err }
go
func (r *Rect) Decode(rd io.Reader) error { d := &decoder{r: asByteReader(rd)} r.decode(d) return d.err }
[ "func", "(", "r", "*", "Rect", ")", "Decode", "(", "rd", "io", ".", "Reader", ")", "error", "{", "d", ":=", "&", "decoder", "{", "r", ":", "asByteReader", "(", "rd", ")", "}", "\n", "r", ".", "decode", "(", "d", ")", "\n", "return", "d", ".",...
// Decode decodes a rectangle.
[ "Decode", "decodes", "a", "rectangle", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/rect.go#L446-L450
train
golang/geo
s2/cap.go
CapFromCenterChordAngle
func CapFromCenterChordAngle(center Point, radius s1.ChordAngle) Cap { return Cap{ center: center, radius: radius, } }
go
func CapFromCenterChordAngle(center Point, radius s1.ChordAngle) Cap { return Cap{ center: center, radius: radius, } }
[ "func", "CapFromCenterChordAngle", "(", "center", "Point", ",", "radius", "s1", ".", "ChordAngle", ")", "Cap", "{", "return", "Cap", "{", "center", ":", "center", ",", "radius", ":", "radius", ",", "}", "\n", "}" ]
// CapFromCenterChordAngle constructs a cap where the angle is expressed as an // s1.ChordAngle. This constructor is more efficient than using an s1.Angle.
[ "CapFromCenterChordAngle", "constructs", "a", "cap", "where", "the", "angle", "is", "expressed", "as", "an", "s1", ".", "ChordAngle", ".", "This", "constructor", "is", "more", "efficient", "than", "using", "an", "s1", ".", "Angle", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/cap.go#L78-L83
train
golang/geo
s2/cap.go
CapFromCenterHeight
func CapFromCenterHeight(center Point, height float64) Cap { return CapFromCenterChordAngle(center, s1.ChordAngleFromSquaredLength(2*height)) }
go
func CapFromCenterHeight(center Point, height float64) Cap { return CapFromCenterChordAngle(center, s1.ChordAngleFromSquaredLength(2*height)) }
[ "func", "CapFromCenterHeight", "(", "center", "Point", ",", "height", "float64", ")", "Cap", "{", "return", "CapFromCenterChordAngle", "(", "center", ",", "s1", ".", "ChordAngleFromSquaredLength", "(", "2", "*", "height", ")", ")", "\n", "}" ]
// CapFromCenterHeight constructs a cap with the given center and height. A // negative height yields an empty cap; a height of 2 or more yields a full cap. // The center should be unit length.
[ "CapFromCenterHeight", "constructs", "a", "cap", "with", "the", "given", "center", "and", "height", ".", "A", "negative", "height", "yields", "an", "empty", "cap", ";", "a", "height", "of", "2", "or", "more", "yields", "a", "full", "cap", ".", "The", "ce...
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/cap.go#L88-L90
train
golang/geo
s2/cap.go
IsValid
func (c Cap) IsValid() bool { return c.center.Vector.IsUnit() && c.radius <= s1.StraightChordAngle }
go
func (c Cap) IsValid() bool { return c.center.Vector.IsUnit() && c.radius <= s1.StraightChordAngle }
[ "func", "(", "c", "Cap", ")", "IsValid", "(", ")", "bool", "{", "return", "c", ".", "center", ".", "Vector", ".", "IsUnit", "(", ")", "&&", "c", ".", "radius", "<=", "s1", ".", "StraightChordAngle", "\n", "}" ]
// IsValid reports whether the Cap is considered valid.
[ "IsValid", "reports", "whether", "the", "Cap", "is", "considered", "valid", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/cap.go#L111-L113
train
golang/geo
s2/cap.go
Equal
func (c Cap) Equal(other Cap) bool { return (c.radius == other.radius && c.center == other.center) || (c.IsEmpty() && other.IsEmpty()) || (c.IsFull() && other.IsFull()) }
go
func (c Cap) Equal(other Cap) bool { return (c.radius == other.radius && c.center == other.center) || (c.IsEmpty() && other.IsEmpty()) || (c.IsFull() && other.IsFull()) }
[ "func", "(", "c", "Cap", ")", "Equal", "(", "other", "Cap", ")", "bool", "{", "return", "(", "c", ".", "radius", "==", "other", ".", "radius", "&&", "c", ".", "center", "==", "other", ".", "center", ")", "||", "(", "c", ".", "IsEmpty", "(", ")"...
// Equal reports whether this cap is equal to the other cap.
[ "Equal", "reports", "whether", "this", "cap", "is", "equal", "to", "the", "other", "cap", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/cap.go#L259-L263
train
golang/geo
s2/cap.go
ApproxEqual
func (c Cap) ApproxEqual(other Cap) bool { const epsilon = 1e-14 r2 := float64(c.radius) otherR2 := float64(other.radius) return c.center.ApproxEqual(other.center) && math.Abs(r2-otherR2) <= epsilon || c.IsEmpty() && otherR2 <= epsilon || other.IsEmpty() && r2 <= epsilon || c.IsFull() && otherR2 >= 2-epsilon || other.IsFull() && r2 >= 2-epsilon }
go
func (c Cap) ApproxEqual(other Cap) bool { const epsilon = 1e-14 r2 := float64(c.radius) otherR2 := float64(other.radius) return c.center.ApproxEqual(other.center) && math.Abs(r2-otherR2) <= epsilon || c.IsEmpty() && otherR2 <= epsilon || other.IsEmpty() && r2 <= epsilon || c.IsFull() && otherR2 >= 2-epsilon || other.IsFull() && r2 >= 2-epsilon }
[ "func", "(", "c", "Cap", ")", "ApproxEqual", "(", "other", "Cap", ")", "bool", "{", "const", "epsilon", "=", "1e-14", "\n", "r2", ":=", "float64", "(", "c", ".", "radius", ")", "\n", "otherR2", ":=", "float64", "(", "other", ".", "radius", ")", "\n...
// ApproxEqual reports whether this cap is equal to the other cap within the given tolerance.
[ "ApproxEqual", "reports", "whether", "this", "cap", "is", "equal", "to", "the", "other", "cap", "within", "the", "given", "tolerance", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/cap.go#L266-L276
train
golang/geo
s2/cap.go
AddPoint
func (c Cap) AddPoint(p Point) Cap { if c.IsEmpty() { c.center = p c.radius = 0 return c } // After calling cap.AddPoint(p), cap.Contains(p) must be true. However // we don't need to do anything special to achieve this because Contains() // does exactly the same distance calculation that we do here. if newRad := ChordAngleBetweenPoints(c.center, p); newRad > c.radius { c.radius = newRad } return c }
go
func (c Cap) AddPoint(p Point) Cap { if c.IsEmpty() { c.center = p c.radius = 0 return c } // After calling cap.AddPoint(p), cap.Contains(p) must be true. However // we don't need to do anything special to achieve this because Contains() // does exactly the same distance calculation that we do here. if newRad := ChordAngleBetweenPoints(c.center, p); newRad > c.radius { c.radius = newRad } return c }
[ "func", "(", "c", "Cap", ")", "AddPoint", "(", "p", "Point", ")", "Cap", "{", "if", "c", ".", "IsEmpty", "(", ")", "{", "c", ".", "center", "=", "p", "\n", "c", ".", "radius", "=", "0", "\n", "return", "c", "\n", "}", "\n\n", "// After calling ...
// AddPoint increases the cap if necessary to include the given point. If this cap is empty, // then the center is set to the point with a zero height. p must be unit-length.
[ "AddPoint", "increases", "the", "cap", "if", "necessary", "to", "include", "the", "given", "point", ".", "If", "this", "cap", "is", "empty", "then", "the", "center", "is", "set", "to", "the", "point", "with", "a", "zero", "height", ".", "p", "must", "b...
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/cap.go#L280-L294
train
golang/geo
s2/cap.go
AddCap
func (c Cap) AddCap(other Cap) Cap { if c.IsEmpty() { return other } if other.IsEmpty() { return c } // We round up the distance to ensure that the cap is actually contained. // TODO(roberts): Do some error analysis in order to guarantee this. dist := ChordAngleBetweenPoints(c.center, other.center).Add(other.radius) if newRad := dist.Expanded(dblEpsilon * float64(dist)); newRad > c.radius { c.radius = newRad } return c }
go
func (c Cap) AddCap(other Cap) Cap { if c.IsEmpty() { return other } if other.IsEmpty() { return c } // We round up the distance to ensure that the cap is actually contained. // TODO(roberts): Do some error analysis in order to guarantee this. dist := ChordAngleBetweenPoints(c.center, other.center).Add(other.radius) if newRad := dist.Expanded(dblEpsilon * float64(dist)); newRad > c.radius { c.radius = newRad } return c }
[ "func", "(", "c", "Cap", ")", "AddCap", "(", "other", "Cap", ")", "Cap", "{", "if", "c", ".", "IsEmpty", "(", ")", "{", "return", "other", "\n", "}", "\n", "if", "other", ".", "IsEmpty", "(", ")", "{", "return", "c", "\n", "}", "\n\n", "// We r...
// AddCap increases the cap height if necessary to include the other cap. If this cap is empty, // it is set to the other cap.
[ "AddCap", "increases", "the", "cap", "height", "if", "necessary", "to", "include", "the", "other", "cap", ".", "If", "this", "cap", "is", "empty", "it", "is", "set", "to", "the", "other", "cap", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/cap.go#L298-L313
train
golang/geo
s2/cap.go
ContainsCell
func (c Cap) ContainsCell(cell Cell) bool { // If the cap does not contain all cell vertices, return false. var vertices [4]Point for k := 0; k < 4; k++ { vertices[k] = cell.Vertex(k) if !c.ContainsPoint(vertices[k]) { return false } } // Otherwise, return true if the complement of the cap does not intersect the cell. return !c.Complement().intersects(cell, vertices) }
go
func (c Cap) ContainsCell(cell Cell) bool { // If the cap does not contain all cell vertices, return false. var vertices [4]Point for k := 0; k < 4; k++ { vertices[k] = cell.Vertex(k) if !c.ContainsPoint(vertices[k]) { return false } } // Otherwise, return true if the complement of the cap does not intersect the cell. return !c.Complement().intersects(cell, vertices) }
[ "func", "(", "c", "Cap", ")", "ContainsCell", "(", "cell", "Cell", ")", "bool", "{", "// If the cap does not contain all cell vertices, return false.", "var", "vertices", "[", "4", "]", "Point", "\n", "for", "k", ":=", "0", ";", "k", "<", "4", ";", "k", "+...
// ContainsCell reports whether the cap contains the given cell.
[ "ContainsCell", "reports", "whether", "the", "cap", "contains", "the", "given", "cell", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/cap.go#L341-L352
train
golang/geo
s2/cap.go
IntersectsCell
func (c Cap) IntersectsCell(cell Cell) bool { // If the cap contains any cell vertex, return true. var vertices [4]Point for k := 0; k < 4; k++ { vertices[k] = cell.Vertex(k) if c.ContainsPoint(vertices[k]) { return true } } return c.intersects(cell, vertices) }
go
func (c Cap) IntersectsCell(cell Cell) bool { // If the cap contains any cell vertex, return true. var vertices [4]Point for k := 0; k < 4; k++ { vertices[k] = cell.Vertex(k) if c.ContainsPoint(vertices[k]) { return true } } return c.intersects(cell, vertices) }
[ "func", "(", "c", "Cap", ")", "IntersectsCell", "(", "cell", "Cell", ")", "bool", "{", "// If the cap contains any cell vertex, return true.", "var", "vertices", "[", "4", "]", "Point", "\n", "for", "k", ":=", "0", ";", "k", "<", "4", ";", "k", "++", "{"...
// IntersectsCell reports whether the cap intersects the cell.
[ "IntersectsCell", "reports", "whether", "the", "cap", "intersects", "the", "cell", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/cap.go#L355-L365
train
golang/geo
s2/cap.go
CellUnionBound
func (c Cap) CellUnionBound() []CellID { // TODO(roberts): The covering could be made quite a bit tighter by mapping // the cap to a rectangle in (i,j)-space and finding a covering for that. // Find the maximum level such that the cap contains at most one cell vertex // and such that CellID.AppendVertexNeighbors() can be called. level := MinWidthMetric.MaxLevel(c.Radius().Radians()) - 1 // If level < 0, more than three face cells are required. if level < 0 { cellIDs := make([]CellID, 6) for face := 0; face < 6; face++ { cellIDs[face] = CellIDFromFace(face) } return cellIDs } // The covering consists of the 4 cells at the given level that share the // cell vertex that is closest to the cap center. return cellIDFromPoint(c.center).VertexNeighbors(level) }
go
func (c Cap) CellUnionBound() []CellID { // TODO(roberts): The covering could be made quite a bit tighter by mapping // the cap to a rectangle in (i,j)-space and finding a covering for that. // Find the maximum level such that the cap contains at most one cell vertex // and such that CellID.AppendVertexNeighbors() can be called. level := MinWidthMetric.MaxLevel(c.Radius().Radians()) - 1 // If level < 0, more than three face cells are required. if level < 0 { cellIDs := make([]CellID, 6) for face := 0; face < 6; face++ { cellIDs[face] = CellIDFromFace(face) } return cellIDs } // The covering consists of the 4 cells at the given level that share the // cell vertex that is closest to the cap center. return cellIDFromPoint(c.center).VertexNeighbors(level) }
[ "func", "(", "c", "Cap", ")", "CellUnionBound", "(", ")", "[", "]", "CellID", "{", "// TODO(roberts): The covering could be made quite a bit tighter by mapping", "// the cap to a rectangle in (i,j)-space and finding a covering for that.", "// Find the maximum level such that the cap cont...
// CellUnionBound computes a covering of the Cap. In general the covering // consists of at most 4 cells except for very large caps, which may need // up to 6 cells. The output is not sorted.
[ "CellUnionBound", "computes", "a", "covering", "of", "the", "Cap", ".", "In", "general", "the", "covering", "consists", "of", "at", "most", "4", "cells", "except", "for", "very", "large", "caps", "which", "may", "need", "up", "to", "6", "cells", ".", "Th...
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/cap.go#L421-L440
train
golang/geo
s2/cap.go
Union
func (c Cap) Union(other Cap) Cap { // If the other cap is larger, swap c and other for the rest of the computations. if c.radius < other.radius { c, other = other, c } if c.IsFull() || other.IsEmpty() { return c } // TODO: This calculation would be more efficient using s1.ChordAngles. cRadius := c.Radius() otherRadius := other.Radius() distance := c.center.Distance(other.center) if cRadius >= distance+otherRadius { return c } resRadius := 0.5 * (distance + cRadius + otherRadius) resCenter := InterpolateAtDistance(0.5*(distance-cRadius+otherRadius), c.center, other.center) return CapFromCenterAngle(resCenter, resRadius) }
go
func (c Cap) Union(other Cap) Cap { // If the other cap is larger, swap c and other for the rest of the computations. if c.radius < other.radius { c, other = other, c } if c.IsFull() || other.IsEmpty() { return c } // TODO: This calculation would be more efficient using s1.ChordAngles. cRadius := c.Radius() otherRadius := other.Radius() distance := c.center.Distance(other.center) if cRadius >= distance+otherRadius { return c } resRadius := 0.5 * (distance + cRadius + otherRadius) resCenter := InterpolateAtDistance(0.5*(distance-cRadius+otherRadius), c.center, other.center) return CapFromCenterAngle(resCenter, resRadius) }
[ "func", "(", "c", "Cap", ")", "Union", "(", "other", "Cap", ")", "Cap", "{", "// If the other cap is larger, swap c and other for the rest of the computations.", "if", "c", ".", "radius", "<", "other", ".", "radius", "{", "c", ",", "other", "=", "other", ",", ...
// Union returns the smallest cap which encloses this cap and other.
[ "Union", "returns", "the", "smallest", "cap", "which", "encloses", "this", "cap", "and", "other", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/cap.go#L470-L491
train
golang/geo
s2/cap.go
Encode
func (c Cap) Encode(w io.Writer) error { e := &encoder{w: w} c.encode(e) return e.err }
go
func (c Cap) Encode(w io.Writer) error { e := &encoder{w: w} c.encode(e) return e.err }
[ "func", "(", "c", "Cap", ")", "Encode", "(", "w", "io", ".", "Writer", ")", "error", "{", "e", ":=", "&", "encoder", "{", "w", ":", "w", "}", "\n", "c", ".", "encode", "(", "e", ")", "\n", "return", "e", ".", "err", "\n", "}" ]
// Encode encodes the Cap.
[ "Encode", "encodes", "the", "Cap", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/cap.go#L494-L498
train
golang/geo
s2/cap.go
Decode
func (c *Cap) Decode(r io.Reader) error { d := &decoder{r: asByteReader(r)} c.decode(d) return d.err }
go
func (c *Cap) Decode(r io.Reader) error { d := &decoder{r: asByteReader(r)} c.decode(d) return d.err }
[ "func", "(", "c", "*", "Cap", ")", "Decode", "(", "r", "io", ".", "Reader", ")", "error", "{", "d", ":=", "&", "decoder", "{", "r", ":", "asByteReader", "(", "r", ")", "}", "\n", "c", ".", "decode", "(", "d", ")", "\n", "return", "d", ".", ...
// Decode decodes the Cap.
[ "Decode", "decodes", "the", "Cap", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/cap.go#L508-L512
train
golang/geo
r1/interval.go
Equal
func (i Interval) Equal(oi Interval) bool { return i == oi || i.IsEmpty() && oi.IsEmpty() }
go
func (i Interval) Equal(oi Interval) bool { return i == oi || i.IsEmpty() && oi.IsEmpty() }
[ "func", "(", "i", "Interval", ")", "Equal", "(", "oi", "Interval", ")", "bool", "{", "return", "i", "==", "oi", "||", "i", ".", "IsEmpty", "(", ")", "&&", "oi", ".", "IsEmpty", "(", ")", "\n", "}" ]
// Equal returns true iff the interval contains the same points as oi.
[ "Equal", "returns", "true", "iff", "the", "interval", "contains", "the", "same", "points", "as", "oi", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/r1/interval.go#L39-L41
train
golang/geo
r1/interval.go
InteriorContains
func (i Interval) InteriorContains(p float64) bool { return i.Lo < p && p < i.Hi }
go
func (i Interval) InteriorContains(p float64) bool { return i.Lo < p && p < i.Hi }
[ "func", "(", "i", "Interval", ")", "InteriorContains", "(", "p", "float64", ")", "bool", "{", "return", "i", ".", "Lo", "<", "p", "&&", "p", "<", "i", ".", "Hi", "\n", "}" ]
// InteriorContains returns true iff the interval strictly contains p.
[ "InteriorContains", "returns", "true", "iff", "the", "interval", "strictly", "contains", "p", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/r1/interval.go#L63-L65
train
golang/geo
r1/interval.go
Intersection
func (i Interval) Intersection(j Interval) Interval { // Empty intervals do not need to be special-cased. return Interval{ Lo: math.Max(i.Lo, j.Lo), Hi: math.Min(i.Hi, j.Hi), } }
go
func (i Interval) Intersection(j Interval) Interval { // Empty intervals do not need to be special-cased. return Interval{ Lo: math.Max(i.Lo, j.Lo), Hi: math.Min(i.Hi, j.Hi), } }
[ "func", "(", "i", "Interval", ")", "Intersection", "(", "j", "Interval", ")", "Interval", "{", "// Empty intervals do not need to be special-cased.", "return", "Interval", "{", "Lo", ":", "math", ".", "Max", "(", "i", ".", "Lo", ",", "j", ".", "Lo", ")", "...
// Intersection returns the interval containing all points common to i and j.
[ "Intersection", "returns", "the", "interval", "containing", "all", "points", "common", "to", "i", "and", "j", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/r1/interval.go#L89-L95
train
golang/geo
r1/interval.go
AddPoint
func (i Interval) AddPoint(p float64) Interval { if i.IsEmpty() { return Interval{p, p} } if p < i.Lo { return Interval{p, i.Hi} } if p > i.Hi { return Interval{i.Lo, p} } return i }
go
func (i Interval) AddPoint(p float64) Interval { if i.IsEmpty() { return Interval{p, p} } if p < i.Lo { return Interval{p, i.Hi} } if p > i.Hi { return Interval{i.Lo, p} } return i }
[ "func", "(", "i", "Interval", ")", "AddPoint", "(", "p", "float64", ")", "Interval", "{", "if", "i", ".", "IsEmpty", "(", ")", "{", "return", "Interval", "{", "p", ",", "p", "}", "\n", "}", "\n", "if", "p", "<", "i", ".", "Lo", "{", "return", ...
// AddPoint returns the interval expanded so that it contains the given point.
[ "AddPoint", "returns", "the", "interval", "expanded", "so", "that", "it", "contains", "the", "given", "point", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/r1/interval.go#L98-L109
train
golang/geo
r1/interval.go
ClampPoint
func (i Interval) ClampPoint(p float64) float64 { return math.Max(i.Lo, math.Min(i.Hi, p)) }
go
func (i Interval) ClampPoint(p float64) float64 { return math.Max(i.Lo, math.Min(i.Hi, p)) }
[ "func", "(", "i", "Interval", ")", "ClampPoint", "(", "p", "float64", ")", "float64", "{", "return", "math", ".", "Max", "(", "i", ".", "Lo", ",", "math", ".", "Min", "(", "i", ".", "Hi", ",", "p", ")", ")", "\n", "}" ]
// ClampPoint returns the closest point in the interval to the given point "p". // The interval must be non-empty.
[ "ClampPoint", "returns", "the", "closest", "point", "in", "the", "interval", "to", "the", "given", "point", "p", ".", "The", "interval", "must", "be", "non", "-", "empty", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/r1/interval.go#L113-L115
train
golang/geo
r1/interval.go
Expanded
func (i Interval) Expanded(margin float64) Interval { if i.IsEmpty() { return i } return Interval{i.Lo - margin, i.Hi + margin} }
go
func (i Interval) Expanded(margin float64) Interval { if i.IsEmpty() { return i } return Interval{i.Lo - margin, i.Hi + margin} }
[ "func", "(", "i", "Interval", ")", "Expanded", "(", "margin", "float64", ")", "Interval", "{", "if", "i", ".", "IsEmpty", "(", ")", "{", "return", "i", "\n", "}", "\n", "return", "Interval", "{", "i", ".", "Lo", "-", "margin", ",", "i", ".", "Hi"...
// Expanded returns an interval that has been expanded on each side by margin. // If margin is negative, then the function shrinks the interval on // each side by margin instead. The resulting interval may be empty. Any // expansion of an empty interval remains empty.
[ "Expanded", "returns", "an", "interval", "that", "has", "been", "expanded", "on", "each", "side", "by", "margin", ".", "If", "margin", "is", "negative", "then", "the", "function", "shrinks", "the", "interval", "on", "each", "side", "by", "margin", "instead",...
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/r1/interval.go#L121-L126
train
golang/geo
r1/interval.go
Union
func (i Interval) Union(other Interval) Interval { if i.IsEmpty() { return other } if other.IsEmpty() { return i } return Interval{math.Min(i.Lo, other.Lo), math.Max(i.Hi, other.Hi)} }
go
func (i Interval) Union(other Interval) Interval { if i.IsEmpty() { return other } if other.IsEmpty() { return i } return Interval{math.Min(i.Lo, other.Lo), math.Max(i.Hi, other.Hi)} }
[ "func", "(", "i", "Interval", ")", "Union", "(", "other", "Interval", ")", "Interval", "{", "if", "i", ".", "IsEmpty", "(", ")", "{", "return", "other", "\n", "}", "\n", "if", "other", ".", "IsEmpty", "(", ")", "{", "return", "i", "\n", "}", "\n"...
// Union returns the smallest interval that contains this interval and the given interval.
[ "Union", "returns", "the", "smallest", "interval", "that", "contains", "this", "interval", "and", "the", "given", "interval", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/r1/interval.go#L129-L137
train
golang/geo
r1/interval.go
ApproxEqual
func (i Interval) ApproxEqual(other Interval) bool { if i.IsEmpty() { return other.Length() <= 2*epsilon } if other.IsEmpty() { return i.Length() <= 2*epsilon } return math.Abs(other.Lo-i.Lo) <= epsilon && math.Abs(other.Hi-i.Hi) <= epsilon }
go
func (i Interval) ApproxEqual(other Interval) bool { if i.IsEmpty() { return other.Length() <= 2*epsilon } if other.IsEmpty() { return i.Length() <= 2*epsilon } return math.Abs(other.Lo-i.Lo) <= epsilon && math.Abs(other.Hi-i.Hi) <= epsilon }
[ "func", "(", "i", "Interval", ")", "ApproxEqual", "(", "other", "Interval", ")", "bool", "{", "if", "i", ".", "IsEmpty", "(", ")", "{", "return", "other", ".", "Length", "(", ")", "<=", "2", "*", "epsilon", "\n", "}", "\n", "if", "other", ".", "I...
// ApproxEqual reports whether the interval can be transformed into the // given interval by moving each endpoint a small distance. // The empty interval is considered to be positioned arbitrarily on the // real line, so any interval with a small enough length will match // the empty interval.
[ "ApproxEqual", "reports", "whether", "the", "interval", "can", "be", "transformed", "into", "the", "given", "interval", "by", "moving", "each", "endpoint", "a", "small", "distance", ".", "The", "empty", "interval", "is", "considered", "to", "be", "positioned", ...
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/r1/interval.go#L155-L164
train
golang/geo
s2/convex_hull_query.go
AddPoint
func (q *ConvexHullQuery) AddPoint(p Point) { q.bound = q.bound.AddPoint(LatLngFromPoint(p)) q.points = append(q.points, p) }
go
func (q *ConvexHullQuery) AddPoint(p Point) { q.bound = q.bound.AddPoint(LatLngFromPoint(p)) q.points = append(q.points, p) }
[ "func", "(", "q", "*", "ConvexHullQuery", ")", "AddPoint", "(", "p", "Point", ")", "{", "q", ".", "bound", "=", "q", ".", "bound", ".", "AddPoint", "(", "LatLngFromPoint", "(", "p", ")", ")", "\n", "q", ".", "points", "=", "append", "(", "q", "."...
// AddPoint adds the given point to the input geometry.
[ "AddPoint", "adds", "the", "given", "point", "to", "the", "input", "geometry", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/convex_hull_query.go#L71-L74
train
golang/geo
s2/convex_hull_query.go
AddPolyline
func (q *ConvexHullQuery) AddPolyline(p *Polyline) { q.bound = q.bound.Union(p.RectBound()) q.points = append(q.points, (*p)...) }
go
func (q *ConvexHullQuery) AddPolyline(p *Polyline) { q.bound = q.bound.Union(p.RectBound()) q.points = append(q.points, (*p)...) }
[ "func", "(", "q", "*", "ConvexHullQuery", ")", "AddPolyline", "(", "p", "*", "Polyline", ")", "{", "q", ".", "bound", "=", "q", ".", "bound", ".", "Union", "(", "p", ".", "RectBound", "(", ")", ")", "\n", "q", ".", "points", "=", "append", "(", ...
// AddPolyline adds the given polyline to the input geometry.
[ "AddPolyline", "adds", "the", "given", "polyline", "to", "the", "input", "geometry", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/convex_hull_query.go#L77-L80
train
golang/geo
s2/convex_hull_query.go
AddLoop
func (q *ConvexHullQuery) AddLoop(l *Loop) { q.bound = q.bound.Union(l.RectBound()) if l.isEmptyOrFull() { return } q.points = append(q.points, l.vertices...) }
go
func (q *ConvexHullQuery) AddLoop(l *Loop) { q.bound = q.bound.Union(l.RectBound()) if l.isEmptyOrFull() { return } q.points = append(q.points, l.vertices...) }
[ "func", "(", "q", "*", "ConvexHullQuery", ")", "AddLoop", "(", "l", "*", "Loop", ")", "{", "q", ".", "bound", "=", "q", ".", "bound", ".", "Union", "(", "l", ".", "RectBound", "(", ")", ")", "\n", "if", "l", ".", "isEmptyOrFull", "(", ")", "{",...
// AddLoop adds the given loop to the input geometry.
[ "AddLoop", "adds", "the", "given", "loop", "to", "the", "input", "geometry", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/convex_hull_query.go#L83-L89
train
golang/geo
s2/convex_hull_query.go
AddPolygon
func (q *ConvexHullQuery) AddPolygon(p *Polygon) { q.bound = q.bound.Union(p.RectBound()) for _, l := range p.loops { // Only loops at depth 0 can contribute to the convex hull. if l.depth == 0 { q.AddLoop(l) } } }
go
func (q *ConvexHullQuery) AddPolygon(p *Polygon) { q.bound = q.bound.Union(p.RectBound()) for _, l := range p.loops { // Only loops at depth 0 can contribute to the convex hull. if l.depth == 0 { q.AddLoop(l) } } }
[ "func", "(", "q", "*", "ConvexHullQuery", ")", "AddPolygon", "(", "p", "*", "Polygon", ")", "{", "q", ".", "bound", "=", "q", ".", "bound", ".", "Union", "(", "p", ".", "RectBound", "(", ")", ")", "\n", "for", "_", ",", "l", ":=", "range", "p",...
// AddPolygon adds the given polygon to the input geometry.
[ "AddPolygon", "adds", "the", "given", "polygon", "to", "the", "input", "geometry", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/convex_hull_query.go#L92-L100
train
golang/geo
s2/convex_hull_query.go
singleEdgeLoop
func singleEdgeLoop(a, b Point) *Loop { vertices := []Point{a, b, Point{a.Add(b.Vector).Normalize()}} loop := LoopFromPoints(vertices) // The resulting loop may be clockwise, so invert it if necessary. loop.Normalize() return loop }
go
func singleEdgeLoop(a, b Point) *Loop { vertices := []Point{a, b, Point{a.Add(b.Vector).Normalize()}} loop := LoopFromPoints(vertices) // The resulting loop may be clockwise, so invert it if necessary. loop.Normalize() return loop }
[ "func", "singleEdgeLoop", "(", "a", ",", "b", "Point", ")", "*", "Loop", "{", "vertices", ":=", "[", "]", "Point", "{", "a", ",", "b", ",", "Point", "{", "a", ".", "Add", "(", "b", ".", "Vector", ")", ".", "Normalize", "(", ")", "}", "}", "\n...
// singleEdgeLoop constructs a loop consisting of the two vertices and their midpoint.
[ "singleEdgeLoop", "constructs", "a", "loop", "consisting", "of", "the", "two", "vertices", "and", "their", "midpoint", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/convex_hull_query.go#L233-L239
train
golang/geo
s1/chordangle.go
ChordAngleFromAngle
func ChordAngleFromAngle(a Angle) ChordAngle { if a < 0 { return NegativeChordAngle } if a.isInf() { return InfChordAngle() } l := 2 * math.Sin(0.5*math.Min(math.Pi, a.Radians())) return ChordAngle(l * l) }
go
func ChordAngleFromAngle(a Angle) ChordAngle { if a < 0 { return NegativeChordAngle } if a.isInf() { return InfChordAngle() } l := 2 * math.Sin(0.5*math.Min(math.Pi, a.Radians())) return ChordAngle(l * l) }
[ "func", "ChordAngleFromAngle", "(", "a", "Angle", ")", "ChordAngle", "{", "if", "a", "<", "0", "{", "return", "NegativeChordAngle", "\n", "}", "\n", "if", "a", ".", "isInf", "(", ")", "{", "return", "InfChordAngle", "(", ")", "\n", "}", "\n", "l", ":...
// ChordAngleFromAngle returns a ChordAngle from the given Angle.
[ "ChordAngleFromAngle", "returns", "a", "ChordAngle", "from", "the", "given", "Angle", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s1/chordangle.go#L57-L66
train
golang/geo
s1/chordangle.go
Angle
func (c ChordAngle) Angle() Angle { if c < 0 { return -1 * Radian } if c.isInf() { return InfAngle() } return Angle(2 * math.Asin(0.5*math.Sqrt(float64(c)))) }
go
func (c ChordAngle) Angle() Angle { if c < 0 { return -1 * Radian } if c.isInf() { return InfAngle() } return Angle(2 * math.Asin(0.5*math.Sqrt(float64(c)))) }
[ "func", "(", "c", "ChordAngle", ")", "Angle", "(", ")", "Angle", "{", "if", "c", "<", "0", "{", "return", "-", "1", "*", "Radian", "\n", "}", "\n", "if", "c", ".", "isInf", "(", ")", "{", "return", "InfAngle", "(", ")", "\n", "}", "\n", "retu...
// Angle converts this ChordAngle to an Angle.
[ "Angle", "converts", "this", "ChordAngle", "to", "an", "Angle", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s1/chordangle.go#L92-L100
train
golang/geo
s1/chordangle.go
Add
func (c ChordAngle) Add(other ChordAngle) ChordAngle { // Note that this method (and Sub) is much more efficient than converting // the ChordAngle to an Angle and adding those and converting back. It // requires only one square root plus a few additions and multiplications. // Optimization for the common case where b is an error tolerance // parameter that happens to be set to zero. if other == 0 { return c } // Clamp the angle sum to at most 180 degrees. if c+other >= maxLength2 { return StraightChordAngle } // Let a and b be the (non-squared) chord lengths, and let c = a+b. // Let A, B, and C be the corresponding half-angles (a = 2*sin(A), etc). // Then the formula below can be derived from c = 2 * sin(A+B) and the // relationships sin(A+B) = sin(A)*cos(B) + sin(B)*cos(A) // cos(X) = sqrt(1 - sin^2(X)) x := float64(c * (1 - 0.25*other)) y := float64(other * (1 - 0.25*c)) return ChordAngle(math.Min(maxLength2, x+y+2*math.Sqrt(x*y))) }
go
func (c ChordAngle) Add(other ChordAngle) ChordAngle { // Note that this method (and Sub) is much more efficient than converting // the ChordAngle to an Angle and adding those and converting back. It // requires only one square root plus a few additions and multiplications. // Optimization for the common case where b is an error tolerance // parameter that happens to be set to zero. if other == 0 { return c } // Clamp the angle sum to at most 180 degrees. if c+other >= maxLength2 { return StraightChordAngle } // Let a and b be the (non-squared) chord lengths, and let c = a+b. // Let A, B, and C be the corresponding half-angles (a = 2*sin(A), etc). // Then the formula below can be derived from c = 2 * sin(A+B) and the // relationships sin(A+B) = sin(A)*cos(B) + sin(B)*cos(A) // cos(X) = sqrt(1 - sin^2(X)) x := float64(c * (1 - 0.25*other)) y := float64(other * (1 - 0.25*c)) return ChordAngle(math.Min(maxLength2, x+y+2*math.Sqrt(x*y))) }
[ "func", "(", "c", "ChordAngle", ")", "Add", "(", "other", "ChordAngle", ")", "ChordAngle", "{", "// Note that this method (and Sub) is much more efficient than converting", "// the ChordAngle to an Angle and adding those and converting back. It", "// requires only one square root plus a ...
// Add adds the other ChordAngle to this one and returns the resulting value. // This method assumes the ChordAngles are not special.
[ "Add", "adds", "the", "other", "ChordAngle", "to", "this", "one", "and", "returns", "the", "resulting", "value", ".", "This", "method", "assumes", "the", "ChordAngles", "are", "not", "special", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s1/chordangle.go#L178-L202
train
golang/geo
s1/chordangle.go
Sub
func (c ChordAngle) Sub(other ChordAngle) ChordAngle { if other == 0 { return c } if c <= other { return 0 } x := float64(c * (1 - 0.25*other)) y := float64(other * (1 - 0.25*c)) return ChordAngle(math.Max(0.0, x+y-2*math.Sqrt(x*y))) }
go
func (c ChordAngle) Sub(other ChordAngle) ChordAngle { if other == 0 { return c } if c <= other { return 0 } x := float64(c * (1 - 0.25*other)) y := float64(other * (1 - 0.25*c)) return ChordAngle(math.Max(0.0, x+y-2*math.Sqrt(x*y))) }
[ "func", "(", "c", "ChordAngle", ")", "Sub", "(", "other", "ChordAngle", ")", "ChordAngle", "{", "if", "other", "==", "0", "{", "return", "c", "\n", "}", "\n", "if", "c", "<=", "other", "{", "return", "0", "\n", "}", "\n", "x", ":=", "float64", "(...
// Sub subtracts the other ChordAngle from this one and returns the resulting // value. This method assumes the ChordAngles are not special.
[ "Sub", "subtracts", "the", "other", "ChordAngle", "from", "this", "one", "and", "returns", "the", "resulting", "value", ".", "This", "method", "assumes", "the", "ChordAngles", "are", "not", "special", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s1/chordangle.go#L206-L216
train
golang/geo
s2/edge_clipping.go
ClipEdge
func ClipEdge(a, b r2.Point, clip r2.Rect) (aClip, bClip r2.Point, intersects bool) { // Compute the bounding rectangle of AB, clip it, and then extract the new // endpoints from the clipped bound. bound := r2.RectFromPoints(a, b) if bound, intersects = clipEdgeBound(a, b, clip, bound); !intersects { return aClip, bClip, false } ai := 0 if a.X > b.X { ai = 1 } aj := 0 if a.Y > b.Y { aj = 1 } return bound.VertexIJ(ai, aj), bound.VertexIJ(1-ai, 1-aj), true }
go
func ClipEdge(a, b r2.Point, clip r2.Rect) (aClip, bClip r2.Point, intersects bool) { // Compute the bounding rectangle of AB, clip it, and then extract the new // endpoints from the clipped bound. bound := r2.RectFromPoints(a, b) if bound, intersects = clipEdgeBound(a, b, clip, bound); !intersects { return aClip, bClip, false } ai := 0 if a.X > b.X { ai = 1 } aj := 0 if a.Y > b.Y { aj = 1 } return bound.VertexIJ(ai, aj), bound.VertexIJ(1-ai, 1-aj), true }
[ "func", "ClipEdge", "(", "a", ",", "b", "r2", ".", "Point", ",", "clip", "r2", ".", "Rect", ")", "(", "aClip", ",", "bClip", "r2", ".", "Point", ",", "intersects", "bool", ")", "{", "// Compute the bounding rectangle of AB, clip it, and then extract the new", ...
// ClipEdge returns the portion of the edge defined by AB that is contained by the // given rectangle. If there is no intersection, false is returned and aClip and bClip // are undefined.
[ "ClipEdge", "returns", "the", "portion", "of", "the", "edge", "defined", "by", "AB", "that", "is", "contained", "by", "the", "given", "rectangle", ".", "If", "there", "is", "no", "intersection", "false", "is", "returned", "and", "aClip", "and", "bClip", "a...
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/edge_clipping.go#L140-L157
train
golang/geo
s2/edge_clipping.go
updateEndpoint
func updateEndpoint(bound r1.Interval, highEndpoint bool, value float64) (r1.Interval, bool) { if !highEndpoint { if bound.Hi < value { return bound, false } if bound.Lo < value { bound.Lo = value } return bound, true } if bound.Lo > value { return bound, false } if bound.Hi > value { bound.Hi = value } return bound, true }
go
func updateEndpoint(bound r1.Interval, highEndpoint bool, value float64) (r1.Interval, bool) { if !highEndpoint { if bound.Hi < value { return bound, false } if bound.Lo < value { bound.Lo = value } return bound, true } if bound.Lo > value { return bound, false } if bound.Hi > value { bound.Hi = value } return bound, true }
[ "func", "updateEndpoint", "(", "bound", "r1", ".", "Interval", ",", "highEndpoint", "bool", ",", "value", "float64", ")", "(", "r1", ".", "Interval", ",", "bool", ")", "{", "if", "!", "highEndpoint", "{", "if", "bound", ".", "Hi", "<", "value", "{", ...
// updateEndpoint returns the interval with the specified endpoint updated to // the given value. If the value lies beyond the opposite endpoint, nothing is // changed and false is returned.
[ "updateEndpoint", "returns", "the", "interval", "with", "the", "specified", "endpoint", "updated", "to", "the", "given", "value", ".", "If", "the", "value", "lies", "beyond", "the", "opposite", "endpoint", "nothing", "is", "changed", "and", "false", "is", "ret...
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/edge_clipping.go#L364-L382
train
golang/geo
s2/edge_clipping.go
edgeIntersectsRect
func edgeIntersectsRect(a, b r2.Point, r r2.Rect) bool { // First check whether the bounds of a Rect around AB intersects the given rect. if !r.Intersects(r2.RectFromPoints(a, b)) { return false } // Otherwise AB intersects the rect if and only if all four vertices of rect // do not lie on the same side of the extended line AB. We test this by finding // the two vertices of rect with minimum and maximum projections onto the normal // of AB, and computing their dot products with the edge normal. n := b.Sub(a).Ortho() i := 0 if n.X >= 0 { i = 1 } j := 0 if n.Y >= 0 { j = 1 } max := n.Dot(r.VertexIJ(i, j).Sub(a)) min := n.Dot(r.VertexIJ(1-i, 1-j).Sub(a)) return (max >= 0) && (min <= 0) }
go
func edgeIntersectsRect(a, b r2.Point, r r2.Rect) bool { // First check whether the bounds of a Rect around AB intersects the given rect. if !r.Intersects(r2.RectFromPoints(a, b)) { return false } // Otherwise AB intersects the rect if and only if all four vertices of rect // do not lie on the same side of the extended line AB. We test this by finding // the two vertices of rect with minimum and maximum projections onto the normal // of AB, and computing their dot products with the edge normal. n := b.Sub(a).Ortho() i := 0 if n.X >= 0 { i = 1 } j := 0 if n.Y >= 0 { j = 1 } max := n.Dot(r.VertexIJ(i, j).Sub(a)) min := n.Dot(r.VertexIJ(1-i, 1-j).Sub(a)) return (max >= 0) && (min <= 0) }
[ "func", "edgeIntersectsRect", "(", "a", ",", "b", "r2", ".", "Point", ",", "r", "r2", ".", "Rect", ")", "bool", "{", "// First check whether the bounds of a Rect around AB intersects the given rect.", "if", "!", "r", ".", "Intersects", "(", "r2", ".", "RectFromPoi...
// edgeIntersectsRect reports whether the edge defined by AB intersects the // given closed rectangle to within the error bound.
[ "edgeIntersectsRect", "reports", "whether", "the", "edge", "defined", "by", "AB", "intersects", "the", "given", "closed", "rectangle", "to", "within", "the", "error", "bound", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/edge_clipping.go#L421-L446
train
golang/geo
s2/edge_clipping.go
clippedEdgeBound
func clippedEdgeBound(a, b r2.Point, clip r2.Rect) r2.Rect { bound := r2.RectFromPoints(a, b) if b1, intersects := clipEdgeBound(a, b, clip, bound); intersects { return b1 } return r2.EmptyRect() }
go
func clippedEdgeBound(a, b r2.Point, clip r2.Rect) r2.Rect { bound := r2.RectFromPoints(a, b) if b1, intersects := clipEdgeBound(a, b, clip, bound); intersects { return b1 } return r2.EmptyRect() }
[ "func", "clippedEdgeBound", "(", "a", ",", "b", "r2", ".", "Point", ",", "clip", "r2", ".", "Rect", ")", "r2", ".", "Rect", "{", "bound", ":=", "r2", ".", "RectFromPoints", "(", "a", ",", "b", ")", "\n", "if", "b1", ",", "intersects", ":=", "clip...
// clippedEdgeBound returns the bounding rectangle of the portion of the edge defined // by AB intersected by clip. The resulting bound may be empty. This is a convenience // function built on top of clipEdgeBound.
[ "clippedEdgeBound", "returns", "the", "bounding", "rectangle", "of", "the", "portion", "of", "the", "edge", "defined", "by", "AB", "intersected", "by", "clip", ".", "The", "resulting", "bound", "may", "be", "empty", ".", "This", "is", "a", "convenience", "fu...
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/edge_clipping.go#L451-L457
train
golang/geo
s2/edge_clipping.go
clipEdgeBound
func clipEdgeBound(a, b r2.Point, clip, bound r2.Rect) (r2.Rect, bool) { // negSlope indicates which diagonal of the bounding box is spanned by AB: it // is false if AB has positive slope, and true if AB has negative slope. This is // used to determine which interval endpoints need to be updated each time // the edge is clipped. negSlope := (a.X > b.X) != (a.Y > b.Y) b0x, b0y, up1 := clipBoundAxis(a.X, b.X, bound.X, a.Y, b.Y, bound.Y, negSlope, clip.X) if !up1 { return bound, false } b1y, b1x, up2 := clipBoundAxis(a.Y, b.Y, b0y, a.X, b.X, b0x, negSlope, clip.Y) if !up2 { return r2.Rect{b0x, b0y}, false } return r2.Rect{X: b1x, Y: b1y}, true }
go
func clipEdgeBound(a, b r2.Point, clip, bound r2.Rect) (r2.Rect, bool) { // negSlope indicates which diagonal of the bounding box is spanned by AB: it // is false if AB has positive slope, and true if AB has negative slope. This is // used to determine which interval endpoints need to be updated each time // the edge is clipped. negSlope := (a.X > b.X) != (a.Y > b.Y) b0x, b0y, up1 := clipBoundAxis(a.X, b.X, bound.X, a.Y, b.Y, bound.Y, negSlope, clip.X) if !up1 { return bound, false } b1y, b1x, up2 := clipBoundAxis(a.Y, b.Y, b0y, a.X, b.X, b0x, negSlope, clip.Y) if !up2 { return r2.Rect{b0x, b0y}, false } return r2.Rect{X: b1x, Y: b1y}, true }
[ "func", "clipEdgeBound", "(", "a", ",", "b", "r2", ".", "Point", ",", "clip", ",", "bound", "r2", ".", "Rect", ")", "(", "r2", ".", "Rect", ",", "bool", ")", "{", "// negSlope indicates which diagonal of the bounding box is spanned by AB: it", "// is false if AB h...
// clipEdgeBound clips an edge AB to sequence of rectangles efficiently. // It represents the clipped edges by their bounding boxes rather than as a pair of // endpoints. Specifically, let A'B' be some portion of an edge AB, and let bound be // a tight bound of A'B'. This function returns the bound that is a tight bound // of A'B' intersected with a given rectangle. If A'B' does not intersect clip, // it returns false and the original bound.
[ "clipEdgeBound", "clips", "an", "edge", "AB", "to", "sequence", "of", "rectangles", "efficiently", ".", "It", "represents", "the", "clipped", "edges", "by", "their", "bounding", "boxes", "rather", "than", "as", "a", "pair", "of", "endpoints", ".", "Specificall...
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/edge_clipping.go#L465-L481
train
golang/geo
s2/predicates.go
stableSign
func stableSign(a, b, c Point) Direction { ab := b.Sub(a.Vector) ab2 := ab.Norm2() bc := c.Sub(b.Vector) bc2 := bc.Norm2() ca := a.Sub(c.Vector) ca2 := ca.Norm2() // Now compute the determinant ((A-C)x(B-C)).C, where the vertices have been // cyclically permuted if necessary so that AB is the longest edge. (This // minimizes the magnitude of cross product.) At the same time we also // compute the maximum error in the determinant. // The two shortest edges, pointing away from their common point. var e1, e2, op r3.Vector if ab2 >= bc2 && ab2 >= ca2 { // AB is the longest edge. e1, e2, op = ca, bc, c.Vector } else if bc2 >= ca2 { // BC is the longest edge. e1, e2, op = ab, ca, a.Vector } else { // CA is the longest edge. e1, e2, op = bc, ab, b.Vector } det := -e1.Cross(e2).Dot(op) maxErr := detErrorMultiplier * math.Sqrt(e1.Norm2()*e2.Norm2()) // If the determinant isn't zero, within maxErr, we know definitively the point ordering. if det > maxErr { return CounterClockwise } if det < -maxErr { return Clockwise } return Indeterminate }
go
func stableSign(a, b, c Point) Direction { ab := b.Sub(a.Vector) ab2 := ab.Norm2() bc := c.Sub(b.Vector) bc2 := bc.Norm2() ca := a.Sub(c.Vector) ca2 := ca.Norm2() // Now compute the determinant ((A-C)x(B-C)).C, where the vertices have been // cyclically permuted if necessary so that AB is the longest edge. (This // minimizes the magnitude of cross product.) At the same time we also // compute the maximum error in the determinant. // The two shortest edges, pointing away from their common point. var e1, e2, op r3.Vector if ab2 >= bc2 && ab2 >= ca2 { // AB is the longest edge. e1, e2, op = ca, bc, c.Vector } else if bc2 >= ca2 { // BC is the longest edge. e1, e2, op = ab, ca, a.Vector } else { // CA is the longest edge. e1, e2, op = bc, ab, b.Vector } det := -e1.Cross(e2).Dot(op) maxErr := detErrorMultiplier * math.Sqrt(e1.Norm2()*e2.Norm2()) // If the determinant isn't zero, within maxErr, we know definitively the point ordering. if det > maxErr { return CounterClockwise } if det < -maxErr { return Clockwise } return Indeterminate }
[ "func", "stableSign", "(", "a", ",", "b", ",", "c", "Point", ")", "Direction", "{", "ab", ":=", "b", ".", "Sub", "(", "a", ".", "Vector", ")", "\n", "ab2", ":=", "ab", ".", "Norm2", "(", ")", "\n", "bc", ":=", "c", ".", "Sub", "(", "b", "."...
// stableSign reports the direction sign of the points in a numerically stable way. // Unlike triageSign, this method can usually compute the correct determinant sign // even when all three points are as collinear as possible. For example if three // points are spaced 1km apart along a random line on the Earth's surface using // the nearest representable points, there is only a 0.4% chance that this method // will not be able to find the determinant sign. The probability of failure // decreases as the points get closer together; if the collinear points are 1 meter // apart, the failure rate drops to 0.0004%. // // This method could be extended to also handle nearly-antipodal points, but antipodal // points are rare in practice so it seems better to simply fall back to // exact arithmetic in that case.
[ "stableSign", "reports", "the", "direction", "sign", "of", "the", "points", "in", "a", "numerically", "stable", "way", ".", "Unlike", "triageSign", "this", "method", "can", "usually", "compute", "the", "correct", "determinant", "sign", "even", "when", "all", "...
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/predicates.go#L156-L193
train
golang/geo
s2/predicates.go
triageSign
func triageSign(a, b, c Point) Direction { det := a.Cross(b.Vector).Dot(c.Vector) if det > maxDeterminantError { return CounterClockwise } if det < -maxDeterminantError { return Clockwise } return Indeterminate }
go
func triageSign(a, b, c Point) Direction { det := a.Cross(b.Vector).Dot(c.Vector) if det > maxDeterminantError { return CounterClockwise } if det < -maxDeterminantError { return Clockwise } return Indeterminate }
[ "func", "triageSign", "(", "a", ",", "b", ",", "c", "Point", ")", "Direction", "{", "det", ":=", "a", ".", "Cross", "(", "b", ".", "Vector", ")", ".", "Dot", "(", "c", ".", "Vector", ")", "\n", "if", "det", ">", "maxDeterminantError", "{", "retur...
// triageSign returns the direction sign of the points. It returns Indeterminate if two // points are identical or the result is uncertain. Uncertain cases can be resolved, if // desired, by calling expensiveSign. // // The purpose of this method is to allow additional cheap tests to be done without // calling expensiveSign.
[ "triageSign", "returns", "the", "direction", "sign", "of", "the", "points", ".", "It", "returns", "Indeterminate", "if", "two", "points", "are", "identical", "or", "the", "result", "is", "uncertain", ".", "Uncertain", "cases", "can", "be", "resolved", "if", ...
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/predicates.go#L201-L210
train
golang/geo
s2/predicates.go
expensiveSign
func expensiveSign(a, b, c Point) Direction { // Return Indeterminate if and only if two points are the same. // This ensures RobustSign(a,b,c) == Indeterminate if and only if a == b, b == c, or c == a. // ie. Property 1 of RobustSign. if a == b || b == c || c == a { return Indeterminate } // Next we try recomputing the determinant still using floating-point // arithmetic but in a more precise way. This is more expensive than the // simple calculation done by triageSign, but it is still *much* cheaper // than using arbitrary-precision arithmetic. This optimization is able to // compute the correct determinant sign in virtually all cases except when // the three points are truly collinear (e.g., three points on the equator). detSign := stableSign(a, b, c) if detSign != Indeterminate { return Direction(detSign) } // Otherwise fall back to exact arithmetic and symbolic permutations. return exactSign(a, b, c, true) }
go
func expensiveSign(a, b, c Point) Direction { // Return Indeterminate if and only if two points are the same. // This ensures RobustSign(a,b,c) == Indeterminate if and only if a == b, b == c, or c == a. // ie. Property 1 of RobustSign. if a == b || b == c || c == a { return Indeterminate } // Next we try recomputing the determinant still using floating-point // arithmetic but in a more precise way. This is more expensive than the // simple calculation done by triageSign, but it is still *much* cheaper // than using arbitrary-precision arithmetic. This optimization is able to // compute the correct determinant sign in virtually all cases except when // the three points are truly collinear (e.g., three points on the equator). detSign := stableSign(a, b, c) if detSign != Indeterminate { return Direction(detSign) } // Otherwise fall back to exact arithmetic and symbolic permutations. return exactSign(a, b, c, true) }
[ "func", "expensiveSign", "(", "a", ",", "b", ",", "c", "Point", ")", "Direction", "{", "// Return Indeterminate if and only if two points are the same.", "// This ensures RobustSign(a,b,c) == Indeterminate if and only if a == b, b == c, or c == a.", "// ie. Property 1 of RobustSign.", ...
// expensiveSign reports the direction sign of the points. It returns Indeterminate // if two of the input points are the same. It uses multiple-precision arithmetic // to ensure that its results are always self-consistent.
[ "expensiveSign", "reports", "the", "direction", "sign", "of", "the", "points", ".", "It", "returns", "Indeterminate", "if", "two", "of", "the", "input", "points", "are", "the", "same", ".", "It", "uses", "multiple", "-", "precision", "arithmetic", "to", "ens...
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/predicates.go#L215-L236
train
golang/geo
s2/predicates.go
exactCompareDistances
func exactCompareDistances(x, a, b r3.PreciseVector) int { // This code produces the same result as though all points were reprojected // to lie exactly on the surface of the unit sphere. It is based on testing // whether x.Dot(a.Normalize()) < x.Dot(b.Normalize()), reformulated // so that it can be evaluated using exact arithmetic. cosAX := x.Dot(a) cosBX := x.Dot(b) // If the two values have different signs, we need to handle that case now // before squaring them below. aSign := cosAX.Sign() bSign := cosBX.Sign() if aSign != bSign { // If cos(AX) > cos(BX), then AX < BX. if aSign > bSign { return -1 } return 1 } cosAX2 := newBigFloat().Mul(cosAX, cosAX) cosBX2 := newBigFloat().Mul(cosBX, cosBX) cmp := newBigFloat().Sub(cosBX2.Mul(cosBX2, a.Norm2()), cosAX2.Mul(cosAX2, b.Norm2())) return aSign * cmp.Sign() }
go
func exactCompareDistances(x, a, b r3.PreciseVector) int { // This code produces the same result as though all points were reprojected // to lie exactly on the surface of the unit sphere. It is based on testing // whether x.Dot(a.Normalize()) < x.Dot(b.Normalize()), reformulated // so that it can be evaluated using exact arithmetic. cosAX := x.Dot(a) cosBX := x.Dot(b) // If the two values have different signs, we need to handle that case now // before squaring them below. aSign := cosAX.Sign() bSign := cosBX.Sign() if aSign != bSign { // If cos(AX) > cos(BX), then AX < BX. if aSign > bSign { return -1 } return 1 } cosAX2 := newBigFloat().Mul(cosAX, cosAX) cosBX2 := newBigFloat().Mul(cosBX, cosBX) cmp := newBigFloat().Sub(cosBX2.Mul(cosBX2, a.Norm2()), cosAX2.Mul(cosAX2, b.Norm2())) return aSign * cmp.Sign() }
[ "func", "exactCompareDistances", "(", "x", ",", "a", ",", "b", "r3", ".", "PreciseVector", ")", "int", "{", "// This code produces the same result as though all points were reprojected", "// to lie exactly on the surface of the unit sphere. It is based on testing", "// whether x.Dot(...
// exactCompareDistances returns -1, 0, or 1 after comparing using the values as // PreciseVectors.
[ "exactCompareDistances", "returns", "-", "1", "0", "or", "1", "after", "comparing", "using", "the", "values", "as", "PreciseVectors", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/predicates.go#L527-L550
train
golang/geo
s2/predicates.go
CompareDistance
func CompareDistance(x, y Point, r s1.ChordAngle) int { // As with CompareDistances, we start by comparing dot products because // the sin^2 method is only valid when the distance XY and the limit "r" are // both less than 90 degrees. sign := triageCompareCosDistance(x, y, float64(r)) if sign != 0 { return sign } // Unlike with CompareDistances, it's not worth using the sin^2 method // when the distance limit is near 180 degrees because the ChordAngle // representation itself has has a rounding error of up to 2e-8 radians for // distances near 180 degrees. if r < ca45Degrees { sign = triageCompareSin2Distance(x, y, float64(r)) if sign != 0 { return sign } } return exactCompareDistance(r3.PreciseVectorFromVector(x.Vector), r3.PreciseVectorFromVector(y.Vector), big.NewFloat(float64(r)).SetPrec(big.MaxPrec)) }
go
func CompareDistance(x, y Point, r s1.ChordAngle) int { // As with CompareDistances, we start by comparing dot products because // the sin^2 method is only valid when the distance XY and the limit "r" are // both less than 90 degrees. sign := triageCompareCosDistance(x, y, float64(r)) if sign != 0 { return sign } // Unlike with CompareDistances, it's not worth using the sin^2 method // when the distance limit is near 180 degrees because the ChordAngle // representation itself has has a rounding error of up to 2e-8 radians for // distances near 180 degrees. if r < ca45Degrees { sign = triageCompareSin2Distance(x, y, float64(r)) if sign != 0 { return sign } } return exactCompareDistance(r3.PreciseVectorFromVector(x.Vector), r3.PreciseVectorFromVector(y.Vector), big.NewFloat(float64(r)).SetPrec(big.MaxPrec)) }
[ "func", "CompareDistance", "(", "x", ",", "y", "Point", ",", "r", "s1", ".", "ChordAngle", ")", "int", "{", "// As with CompareDistances, we start by comparing dot products because", "// the sin^2 method is only valid when the distance XY and the limit \"r\" are", "// both less tha...
// CompareDistance returns -1, 0, or +1 according to whether the distance XY is // respectively less than, equal to, or greater than the provided chord angle. Distances are measured // with respect to the positions of all points as though they are projected to lie // exactly on the surface of the unit sphere.
[ "CompareDistance", "returns", "-", "1", "0", "or", "+", "1", "according", "to", "whether", "the", "distance", "XY", "is", "respectively", "less", "than", "equal", "to", "or", "greater", "than", "the", "provided", "chord", "angle", ".", "Distances", "are", ...
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/predicates.go#L592-L612
train
golang/geo
s2/predicates.go
triageCompareCosDistance
func triageCompareCosDistance(x, y Point, r2 float64) int { cosXY, cosXYError := cosDistance(x, y) cosR := 1.0 - 0.5*r2 cosRError := 2.0 * dblError * cosR diff := cosXY - cosR err := cosXYError + cosRError if diff > err { return -1 } if diff < -err { return 1 } return 0 }
go
func triageCompareCosDistance(x, y Point, r2 float64) int { cosXY, cosXYError := cosDistance(x, y) cosR := 1.0 - 0.5*r2 cosRError := 2.0 * dblError * cosR diff := cosXY - cosR err := cosXYError + cosRError if diff > err { return -1 } if diff < -err { return 1 } return 0 }
[ "func", "triageCompareCosDistance", "(", "x", ",", "y", "Point", ",", "r2", "float64", ")", "int", "{", "cosXY", ",", "cosXYError", ":=", "cosDistance", "(", "x", ",", "y", ")", "\n", "cosR", ":=", "1.0", "-", "0.5", "*", "r2", "\n", "cosRError", ":=...
// triageCompareCosDistance returns -1, 0, or +1 according to whether the distance XY is // less than, equal to, or greater than r2 respectively using cos distance.
[ "triageCompareCosDistance", "returns", "-", "1", "0", "or", "+", "1", "according", "to", "whether", "the", "distance", "XY", "is", "less", "than", "equal", "to", "or", "greater", "than", "r2", "respectively", "using", "cos", "distance", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/predicates.go#L616-L629
train
golang/geo
s2/predicates.go
triageCompareSin2Distance
func triageCompareSin2Distance(x, y Point, r2 float64) int { // Only valid for distance limits < 90 degrees. sin2XY, sin2XYError := sin2Distance(x, y) sin2R := r2 * (1.0 - 0.25*r2) sin2RError := 3.0 * dblError * sin2R diff := sin2XY - sin2R err := sin2XYError + sin2RError if diff > err { return 1 } if diff < -err { return -1 } return 0 }
go
func triageCompareSin2Distance(x, y Point, r2 float64) int { // Only valid for distance limits < 90 degrees. sin2XY, sin2XYError := sin2Distance(x, y) sin2R := r2 * (1.0 - 0.25*r2) sin2RError := 3.0 * dblError * sin2R diff := sin2XY - sin2R err := sin2XYError + sin2RError if diff > err { return 1 } if diff < -err { return -1 } return 0 }
[ "func", "triageCompareSin2Distance", "(", "x", ",", "y", "Point", ",", "r2", "float64", ")", "int", "{", "// Only valid for distance limits < 90 degrees.", "sin2XY", ",", "sin2XYError", ":=", "sin2Distance", "(", "x", ",", "y", ")", "\n", "sin2R", ":=", "r2", ...
// triageCompareSin2Distance returns -1, 0, or +1 according to whether the distance XY is // less than, equal to, or greater than r2 respectively using sin^2 distance.
[ "triageCompareSin2Distance", "returns", "-", "1", "0", "or", "+", "1", "according", "to", "whether", "the", "distance", "XY", "is", "less", "than", "equal", "to", "or", "greater", "than", "r2", "respectively", "using", "sin^2", "distance", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/predicates.go#L633-L647
train
golang/geo
s2/predicates.go
exactCompareDistance
func exactCompareDistance(x, y r3.PreciseVector, r2 *big.Float) int { // This code produces the same result as though all points were reprojected // to lie exactly on the surface of the unit sphere. It is based on // comparing the cosine of the angle XY (when both points are projected to // lie exactly on the sphere) to the given threshold. cosXY := x.Dot(y) cosR := newBigFloat().Sub(bigOne, newBigFloat().Mul(bigHalf, r2)) // If the two values have different signs, we need to handle that case now // before squaring them below. xySign := cosXY.Sign() rSign := cosR.Sign() if xySign != rSign { if xySign > rSign { return -1 } return 1 // If cos(XY) > cos(r), then XY < r. } cmp := newBigFloat().Sub( newBigFloat().Mul( newBigFloat().Mul(cosR, cosR), newBigFloat().Mul(x.Norm2(), y.Norm2())), newBigFloat().Mul(cosXY, cosXY)) return xySign * cmp.Sign() }
go
func exactCompareDistance(x, y r3.PreciseVector, r2 *big.Float) int { // This code produces the same result as though all points were reprojected // to lie exactly on the surface of the unit sphere. It is based on // comparing the cosine of the angle XY (when both points are projected to // lie exactly on the sphere) to the given threshold. cosXY := x.Dot(y) cosR := newBigFloat().Sub(bigOne, newBigFloat().Mul(bigHalf, r2)) // If the two values have different signs, we need to handle that case now // before squaring them below. xySign := cosXY.Sign() rSign := cosR.Sign() if xySign != rSign { if xySign > rSign { return -1 } return 1 // If cos(XY) > cos(r), then XY < r. } cmp := newBigFloat().Sub( newBigFloat().Mul( newBigFloat().Mul(cosR, cosR), newBigFloat().Mul(x.Norm2(), y.Norm2())), newBigFloat().Mul(cosXY, cosXY)) return xySign * cmp.Sign() }
[ "func", "exactCompareDistance", "(", "x", ",", "y", "r3", ".", "PreciseVector", ",", "r2", "*", "big", ".", "Float", ")", "int", "{", "// This code produces the same result as though all points were reprojected", "// to lie exactly on the surface of the unit sphere. It is base...
// exactCompareDistance returns -1, 0, or +1 after comparing using PreciseVectors.
[ "exactCompareDistance", "returns", "-", "1", "0", "or", "+", "1", "after", "comparing", "using", "PreciseVectors", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/predicates.go#L655-L678
train
golang/geo
s2/rect_bounder.go
RectBound
func (r *RectBounder) RectBound() Rect { return r.bound.expanded(LatLng{s1.Angle(2 * dblEpsilon), 0}).PolarClosure() }
go
func (r *RectBounder) RectBound() Rect { return r.bound.expanded(LatLng{s1.Angle(2 * dblEpsilon), 0}).PolarClosure() }
[ "func", "(", "r", "*", "RectBounder", ")", "RectBound", "(", ")", "Rect", "{", "return", "r", ".", "bound", ".", "expanded", "(", "LatLng", "{", "s1", ".", "Angle", "(", "2", "*", "dblEpsilon", ")", ",", "0", "}", ")", ".", "PolarClosure", "(", "...
// RectBound returns the bounding rectangle of the edge chain that connects the // vertices defined so far. This bound satisfies the guarantee made // above, i.e. if the edge chain defines a Loop, then the bound contains // the LatLng coordinates of all Points contained by the loop.
[ "RectBound", "returns", "the", "bounding", "rectangle", "of", "the", "edge", "chain", "that", "connects", "the", "vertices", "defined", "so", "far", ".", "This", "bound", "satisfies", "the", "guarantee", "made", "above", "i", ".", "e", ".", "if", "the", "e...
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/rect_bounder.go#L202-L204
train
golang/geo
s2/edge_distances.go
UpdateMaxDistance
func UpdateMaxDistance(x, a, b Point, maxDist s1.ChordAngle) (s1.ChordAngle, bool) { dist := maxChordAngle(ChordAngleBetweenPoints(x, a), ChordAngleBetweenPoints(x, b)) if dist > s1.RightChordAngle { dist, _ = updateMinDistance(Point{x.Mul(-1)}, a, b, dist, true) dist = s1.StraightChordAngle - dist } if maxDist < dist { return dist, true } return maxDist, false }
go
func UpdateMaxDistance(x, a, b Point, maxDist s1.ChordAngle) (s1.ChordAngle, bool) { dist := maxChordAngle(ChordAngleBetweenPoints(x, a), ChordAngleBetweenPoints(x, b)) if dist > s1.RightChordAngle { dist, _ = updateMinDistance(Point{x.Mul(-1)}, a, b, dist, true) dist = s1.StraightChordAngle - dist } if maxDist < dist { return dist, true } return maxDist, false }
[ "func", "UpdateMaxDistance", "(", "x", ",", "a", ",", "b", "Point", ",", "maxDist", "s1", ".", "ChordAngle", ")", "(", "s1", ".", "ChordAngle", ",", "bool", ")", "{", "dist", ":=", "maxChordAngle", "(", "ChordAngleBetweenPoints", "(", "x", ",", "a", ")...
// UpdateMaxDistance checks if the distance from X to the edge AB is greater // than maxDist, and if so, returns the updated value and true. // Otherwise it returns false. The case A == B is handled correctly.
[ "UpdateMaxDistance", "checks", "if", "the", "distance", "from", "X", "to", "the", "edge", "AB", "is", "greater", "than", "maxDist", "and", "if", "so", "returns", "the", "updated", "value", "and", "true", ".", "Otherwise", "it", "returns", "false", ".", "Th...
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/edge_distances.go#L62-L73
train
golang/geo
s2/edge_distances.go
Project
func Project(x, a, b Point) Point { aXb := a.PointCross(b) // Find the closest point to X along the great circle through AB. p := x.Sub(aXb.Mul(x.Dot(aXb.Vector) / aXb.Vector.Norm2())) // If this point is on the edge AB, then it's the closest point. if Sign(aXb, a, Point{p}) && Sign(Point{p}, b, aXb) { return Point{p.Normalize()} } // Otherwise, the closest point is either A or B. if x.Sub(a.Vector).Norm2() <= x.Sub(b.Vector).Norm2() { return a } return b }
go
func Project(x, a, b Point) Point { aXb := a.PointCross(b) // Find the closest point to X along the great circle through AB. p := x.Sub(aXb.Mul(x.Dot(aXb.Vector) / aXb.Vector.Norm2())) // If this point is on the edge AB, then it's the closest point. if Sign(aXb, a, Point{p}) && Sign(Point{p}, b, aXb) { return Point{p.Normalize()} } // Otherwise, the closest point is either A or B. if x.Sub(a.Vector).Norm2() <= x.Sub(b.Vector).Norm2() { return a } return b }
[ "func", "Project", "(", "x", ",", "a", ",", "b", "Point", ")", "Point", "{", "aXb", ":=", "a", ".", "PointCross", "(", "b", ")", "\n", "// Find the closest point to X along the great circle through AB.", "p", ":=", "x", ".", "Sub", "(", "aXb", ".", "Mul", ...
// Project returns the point along the edge AB that is closest to the point X. // The fractional distance of this point along the edge AB can be obtained // using DistanceFraction. // // This requires that all points are unit length.
[ "Project", "returns", "the", "point", "along", "the", "edge", "AB", "that", "is", "closest", "to", "the", "point", "X", ".", "The", "fractional", "distance", "of", "this", "point", "along", "the", "edge", "AB", "can", "be", "obtained", "using", "DistanceFr...
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/edge_distances.go#L96-L111
train
golang/geo
s2/edge_distances.go
InterpolateAtDistance
func InterpolateAtDistance(ax s1.Angle, a, b Point) Point { aRad := ax.Radians() // Use PointCross to compute the tangent vector at A towards B. The // result is always perpendicular to A, even if A=B or A=-B, but it is not // necessarily unit length. (We effectively normalize it below.) normal := a.PointCross(b) tangent := normal.Vector.Cross(a.Vector) // Now compute the appropriate linear combination of A and "tangent". With // infinite precision the result would always be unit length, but we // normalize it anyway to ensure that the error is within acceptable bounds. // (Otherwise errors can build up when the result of one interpolation is // fed into another interpolation.) return Point{(a.Mul(math.Cos(aRad)).Add(tangent.Mul(math.Sin(aRad) / tangent.Norm()))).Normalize()} }
go
func InterpolateAtDistance(ax s1.Angle, a, b Point) Point { aRad := ax.Radians() // Use PointCross to compute the tangent vector at A towards B. The // result is always perpendicular to A, even if A=B or A=-B, but it is not // necessarily unit length. (We effectively normalize it below.) normal := a.PointCross(b) tangent := normal.Vector.Cross(a.Vector) // Now compute the appropriate linear combination of A and "tangent". With // infinite precision the result would always be unit length, but we // normalize it anyway to ensure that the error is within acceptable bounds. // (Otherwise errors can build up when the result of one interpolation is // fed into another interpolation.) return Point{(a.Mul(math.Cos(aRad)).Add(tangent.Mul(math.Sin(aRad) / tangent.Norm()))).Normalize()} }
[ "func", "InterpolateAtDistance", "(", "ax", "s1", ".", "Angle", ",", "a", ",", "b", "Point", ")", "Point", "{", "aRad", ":=", "ax", ".", "Radians", "(", ")", "\n\n", "// Use PointCross to compute the tangent vector at A towards B. The", "// result is always perpendicu...
// InterpolateAtDistance returns the point X along the line segment AB whose // distance from A is the angle ax.
[ "InterpolateAtDistance", "returns", "the", "point", "X", "along", "the", "line", "segment", "AB", "whose", "distance", "from", "A", "is", "the", "angle", "ax", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/edge_distances.go#L142-L157
train
golang/geo
s2/edge_distances.go
updateMinDistance
func updateMinDistance(x, a, b Point, minDist s1.ChordAngle, alwaysUpdate bool) (s1.ChordAngle, bool) { if d, ok := interiorDist(x, a, b, minDist, alwaysUpdate); ok { // Minimum distance is attained along the edge interior. return d, true } // Otherwise the minimum distance is to one of the endpoints. xa2, xb2 := (x.Sub(a.Vector)).Norm2(), x.Sub(b.Vector).Norm2() dist := s1.ChordAngle(math.Min(xa2, xb2)) if !alwaysUpdate && dist >= minDist { return minDist, false } return dist, true }
go
func updateMinDistance(x, a, b Point, minDist s1.ChordAngle, alwaysUpdate bool) (s1.ChordAngle, bool) { if d, ok := interiorDist(x, a, b, minDist, alwaysUpdate); ok { // Minimum distance is attained along the edge interior. return d, true } // Otherwise the minimum distance is to one of the endpoints. xa2, xb2 := (x.Sub(a.Vector)).Norm2(), x.Sub(b.Vector).Norm2() dist := s1.ChordAngle(math.Min(xa2, xb2)) if !alwaysUpdate && dist >= minDist { return minDist, false } return dist, true }
[ "func", "updateMinDistance", "(", "x", ",", "a", ",", "b", "Point", ",", "minDist", "s1", ".", "ChordAngle", ",", "alwaysUpdate", "bool", ")", "(", "s1", ".", "ChordAngle", ",", "bool", ")", "{", "if", "d", ",", "ok", ":=", "interiorDist", "(", "x", ...
// updateMinDistance computes the distance from a point X to a line segment AB, // and if either the distance was less than the given minDist, or alwaysUpdate is // true, the value and whether it was updated are returned.
[ "updateMinDistance", "computes", "the", "distance", "from", "a", "point", "X", "to", "a", "line", "segment", "AB", "and", "if", "either", "the", "distance", "was", "less", "than", "the", "given", "minDist", "or", "alwaysUpdate", "is", "true", "the", "value",...
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/edge_distances.go#L207-L220
train
golang/geo
s2/edge_distances.go
updateEdgePairMinDistance
func updateEdgePairMinDistance(a0, a1, b0, b1 Point, minDist s1.ChordAngle) (s1.ChordAngle, bool) { if minDist == 0 { return 0, false } if CrossingSign(a0, a1, b0, b1) == Cross { minDist = 0 return 0, true } // Otherwise, the minimum distance is achieved at an endpoint of at least // one of the two edges. We ensure that all four possibilities are always checked. // // The calculation below computes each of the six vertex-vertex distances // twice (this could be optimized). var ok1, ok2, ok3, ok4 bool minDist, ok1 = UpdateMinDistance(a0, b0, b1, minDist) minDist, ok2 = UpdateMinDistance(a1, b0, b1, minDist) minDist, ok3 = UpdateMinDistance(b0, a0, a1, minDist) minDist, ok4 = UpdateMinDistance(b1, a0, a1, minDist) return minDist, ok1 || ok2 || ok3 || ok4 }
go
func updateEdgePairMinDistance(a0, a1, b0, b1 Point, minDist s1.ChordAngle) (s1.ChordAngle, bool) { if minDist == 0 { return 0, false } if CrossingSign(a0, a1, b0, b1) == Cross { minDist = 0 return 0, true } // Otherwise, the minimum distance is achieved at an endpoint of at least // one of the two edges. We ensure that all four possibilities are always checked. // // The calculation below computes each of the six vertex-vertex distances // twice (this could be optimized). var ok1, ok2, ok3, ok4 bool minDist, ok1 = UpdateMinDistance(a0, b0, b1, minDist) minDist, ok2 = UpdateMinDistance(a1, b0, b1, minDist) minDist, ok3 = UpdateMinDistance(b0, a0, a1, minDist) minDist, ok4 = UpdateMinDistance(b1, a0, a1, minDist) return minDist, ok1 || ok2 || ok3 || ok4 }
[ "func", "updateEdgePairMinDistance", "(", "a0", ",", "a1", ",", "b0", ",", "b1", "Point", ",", "minDist", "s1", ".", "ChordAngle", ")", "(", "s1", ".", "ChordAngle", ",", "bool", ")", "{", "if", "minDist", "==", "0", "{", "return", "0", ",", "false",...
// updateEdgePairMinDistance computes the minimum distance between the given // pair of edges. If the two edges cross, the distance is zero. The cases // a0 == a1 and b0 == b1 are handled correctly.
[ "updateEdgePairMinDistance", "computes", "the", "minimum", "distance", "between", "the", "given", "pair", "of", "edges", ".", "If", "the", "two", "edges", "cross", "the", "distance", "is", "zero", ".", "The", "cases", "a0", "==", "a1", "and", "b0", "==", "...
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/edge_distances.go#L300-L320
train
golang/geo
s2/edge_distances.go
updateEdgePairMaxDistance
func updateEdgePairMaxDistance(a0, a1, b0, b1 Point, maxDist s1.ChordAngle) (s1.ChordAngle, bool) { if maxDist == s1.StraightChordAngle { return s1.StraightChordAngle, false } if CrossingSign(a0, a1, Point{b0.Mul(-1)}, Point{b1.Mul(-1)}) == Cross { return s1.StraightChordAngle, true } // Otherwise, the maximum distance is achieved at an endpoint of at least // one of the two edges. We ensure that all four possibilities are always checked. // // The calculation below computes each of the six vertex-vertex distances // twice (this could be optimized). var ok1, ok2, ok3, ok4 bool maxDist, ok1 = UpdateMaxDistance(a0, b0, b1, maxDist) maxDist, ok2 = UpdateMaxDistance(a1, b0, b1, maxDist) maxDist, ok3 = UpdateMaxDistance(b0, a0, a1, maxDist) maxDist, ok4 = UpdateMaxDistance(b1, a0, a1, maxDist) return maxDist, ok1 || ok2 || ok3 || ok4 }
go
func updateEdgePairMaxDistance(a0, a1, b0, b1 Point, maxDist s1.ChordAngle) (s1.ChordAngle, bool) { if maxDist == s1.StraightChordAngle { return s1.StraightChordAngle, false } if CrossingSign(a0, a1, Point{b0.Mul(-1)}, Point{b1.Mul(-1)}) == Cross { return s1.StraightChordAngle, true } // Otherwise, the maximum distance is achieved at an endpoint of at least // one of the two edges. We ensure that all four possibilities are always checked. // // The calculation below computes each of the six vertex-vertex distances // twice (this could be optimized). var ok1, ok2, ok3, ok4 bool maxDist, ok1 = UpdateMaxDistance(a0, b0, b1, maxDist) maxDist, ok2 = UpdateMaxDistance(a1, b0, b1, maxDist) maxDist, ok3 = UpdateMaxDistance(b0, a0, a1, maxDist) maxDist, ok4 = UpdateMaxDistance(b1, a0, a1, maxDist) return maxDist, ok1 || ok2 || ok3 || ok4 }
[ "func", "updateEdgePairMaxDistance", "(", "a0", ",", "a1", ",", "b0", ",", "b1", "Point", ",", "maxDist", "s1", ".", "ChordAngle", ")", "(", "s1", ".", "ChordAngle", ",", "bool", ")", "{", "if", "maxDist", "==", "s1", ".", "StraightChordAngle", "{", "r...
// updateEdgePairMaxDistance reports the minimum distance between the given pair of edges. // If one edge crosses the antipodal reflection of the other, the distance is pi.
[ "updateEdgePairMaxDistance", "reports", "the", "minimum", "distance", "between", "the", "given", "pair", "of", "edges", ".", "If", "one", "edge", "crosses", "the", "antipodal", "reflection", "of", "the", "other", "the", "distance", "is", "pi", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/edge_distances.go#L324-L343
train
golang/geo
s2/contains_point_query.go
NewContainsPointQuery
func NewContainsPointQuery(index *ShapeIndex, model VertexModel) *ContainsPointQuery { return &ContainsPointQuery{ index: index, model: model, iter: index.Iterator(), } }
go
func NewContainsPointQuery(index *ShapeIndex, model VertexModel) *ContainsPointQuery { return &ContainsPointQuery{ index: index, model: model, iter: index.Iterator(), } }
[ "func", "NewContainsPointQuery", "(", "index", "*", "ShapeIndex", ",", "model", "VertexModel", ")", "*", "ContainsPointQuery", "{", "return", "&", "ContainsPointQuery", "{", "index", ":", "index", ",", "model", ":", "model", ",", "iter", ":", "index", ".", "...
// NewContainsPointQuery creates a new instance of the ContainsPointQuery for the index // and given vertex model choice.
[ "NewContainsPointQuery", "creates", "a", "new", "instance", "of", "the", "ContainsPointQuery", "for", "the", "index", "and", "given", "vertex", "model", "choice", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/contains_point_query.go#L61-L67
train
golang/geo
s2/contains_point_query.go
shapeContains
func (q *ContainsPointQuery) shapeContains(clipped *clippedShape, center, p Point) bool { inside := clipped.containsCenter numEdges := clipped.numEdges() if numEdges <= 0 { return inside } shape := q.index.Shape(clipped.shapeID) if shape.Dimension() != 2 { // Points and polylines can be ignored unless the vertex model is Closed. if q.model != VertexModelClosed { return false } // Otherwise, the point is contained if and only if it matches a vertex. for _, edgeID := range clipped.edges { edge := shape.Edge(edgeID) if edge.V0 == p || edge.V1 == p { return true } } return false } // Test containment by drawing a line segment from the cell center to the // given point and counting edge crossings. crosser := NewEdgeCrosser(center, p) for _, edgeID := range clipped.edges { edge := shape.Edge(edgeID) sign := crosser.CrossingSign(edge.V0, edge.V1) if sign == DoNotCross { continue } if sign == MaybeCross { // For the Open and Closed models, check whether p is a vertex. if q.model != VertexModelSemiOpen && (edge.V0 == p || edge.V1 == p) { return (q.model == VertexModelClosed) } // C++ plays fast and loose with the int <-> bool conversions here. if VertexCrossing(crosser.a, crosser.b, edge.V0, edge.V1) { sign = Cross } else { sign = DoNotCross } } inside = inside != (sign == Cross) } return inside }
go
func (q *ContainsPointQuery) shapeContains(clipped *clippedShape, center, p Point) bool { inside := clipped.containsCenter numEdges := clipped.numEdges() if numEdges <= 0 { return inside } shape := q.index.Shape(clipped.shapeID) if shape.Dimension() != 2 { // Points and polylines can be ignored unless the vertex model is Closed. if q.model != VertexModelClosed { return false } // Otherwise, the point is contained if and only if it matches a vertex. for _, edgeID := range clipped.edges { edge := shape.Edge(edgeID) if edge.V0 == p || edge.V1 == p { return true } } return false } // Test containment by drawing a line segment from the cell center to the // given point and counting edge crossings. crosser := NewEdgeCrosser(center, p) for _, edgeID := range clipped.edges { edge := shape.Edge(edgeID) sign := crosser.CrossingSign(edge.V0, edge.V1) if sign == DoNotCross { continue } if sign == MaybeCross { // For the Open and Closed models, check whether p is a vertex. if q.model != VertexModelSemiOpen && (edge.V0 == p || edge.V1 == p) { return (q.model == VertexModelClosed) } // C++ plays fast and loose with the int <-> bool conversions here. if VertexCrossing(crosser.a, crosser.b, edge.V0, edge.V1) { sign = Cross } else { sign = DoNotCross } } inside = inside != (sign == Cross) } return inside }
[ "func", "(", "q", "*", "ContainsPointQuery", ")", "shapeContains", "(", "clipped", "*", "clippedShape", ",", "center", ",", "p", "Point", ")", "bool", "{", "inside", ":=", "clipped", ".", "containsCenter", "\n", "numEdges", ":=", "clipped", ".", "numEdges", ...
// shapeContains reports whether the clippedShape from the iterator's center position contains // the given point.
[ "shapeContains", "reports", "whether", "the", "clippedShape", "from", "the", "iterator", "s", "center", "position", "contains", "the", "given", "point", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/contains_point_query.go#L87-L136
train
golang/geo
s2/contains_point_query.go
visitContainingShapes
func (q *ContainsPointQuery) visitContainingShapes(p Point, f shapeVisitorFunc) bool { // This function returns false only if the algorithm terminates early // because the visitor function returned false. if !q.iter.LocatePoint(p) { return true } cell := q.iter.IndexCell() for _, clipped := range cell.shapes { if q.shapeContains(clipped, q.iter.Center(), p) && !f(q.index.Shape(clipped.shapeID)) { return false } } return true }
go
func (q *ContainsPointQuery) visitContainingShapes(p Point, f shapeVisitorFunc) bool { // This function returns false only if the algorithm terminates early // because the visitor function returned false. if !q.iter.LocatePoint(p) { return true } cell := q.iter.IndexCell() for _, clipped := range cell.shapes { if q.shapeContains(clipped, q.iter.Center(), p) && !f(q.index.Shape(clipped.shapeID)) { return false } } return true }
[ "func", "(", "q", "*", "ContainsPointQuery", ")", "visitContainingShapes", "(", "p", "Point", ",", "f", "shapeVisitorFunc", ")", "bool", "{", "// This function returns false only if the algorithm terminates early", "// because the visitor function returned false.", "if", "!", ...
// visitContainingShapes visits all shapes in the given index that contain the // given point p, terminating early if the given visitor function returns false, // in which case visitContainingShapes returns false. Each shape is // visited at most once.
[ "visitContainingShapes", "visits", "all", "shapes", "in", "the", "given", "index", "that", "contain", "the", "given", "point", "p", "terminating", "early", "if", "the", "given", "visitor", "function", "returns", "false", "in", "which", "case", "visitContainingShap...
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/contains_point_query.go#L161-L176
train
golang/geo
s2/contains_point_query.go
ContainingShapes
func (q *ContainsPointQuery) ContainingShapes(p Point) []Shape { var shapes []Shape q.visitContainingShapes(p, func(shape Shape) bool { shapes = append(shapes, shape) return true }) return shapes }
go
func (q *ContainsPointQuery) ContainingShapes(p Point) []Shape { var shapes []Shape q.visitContainingShapes(p, func(shape Shape) bool { shapes = append(shapes, shape) return true }) return shapes }
[ "func", "(", "q", "*", "ContainsPointQuery", ")", "ContainingShapes", "(", "p", "Point", ")", "[", "]", "Shape", "{", "var", "shapes", "[", "]", "Shape", "\n", "q", ".", "visitContainingShapes", "(", "p", ",", "func", "(", "shape", "Shape", ")", "bool"...
// ContainingShapes returns a slice of all shapes that contain the given point.
[ "ContainingShapes", "returns", "a", "slice", "of", "all", "shapes", "that", "contain", "the", "given", "point", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/contains_point_query.go#L179-L186
train
golang/geo
s2/cellid.go
CellIDFromToken
func CellIDFromToken(s string) CellID { if len(s) > 16 { return CellID(0) } n, err := strconv.ParseUint(s, 16, 64) if err != nil { return CellID(0) } // Equivalent to right-padding string with zeros to 16 characters. if len(s) < 16 { n = n << (4 * uint(16-len(s))) } return CellID(n) }
go
func CellIDFromToken(s string) CellID { if len(s) > 16 { return CellID(0) } n, err := strconv.ParseUint(s, 16, 64) if err != nil { return CellID(0) } // Equivalent to right-padding string with zeros to 16 characters. if len(s) < 16 { n = n << (4 * uint(16-len(s))) } return CellID(n) }
[ "func", "CellIDFromToken", "(", "s", "string", ")", "CellID", "{", "if", "len", "(", "s", ")", ">", "16", "{", "return", "CellID", "(", "0", ")", "\n", "}", "\n", "n", ",", "err", ":=", "strconv", ".", "ParseUint", "(", "s", ",", "16", ",", "64...
// CellIDFromToken returns a cell given a hex-encoded string of its uint64 ID.
[ "CellIDFromToken", "returns", "a", "cell", "given", "a", "hex", "-", "encoded", "string", "of", "its", "uint64", "ID", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/cellid.go#L116-L129
train
golang/geo
s2/cellid.go
ToToken
func (ci CellID) ToToken() string { s := strings.TrimRight(fmt.Sprintf("%016x", uint64(ci)), "0") if len(s) == 0 { return "X" } return s }
go
func (ci CellID) ToToken() string { s := strings.TrimRight(fmt.Sprintf("%016x", uint64(ci)), "0") if len(s) == 0 { return "X" } return s }
[ "func", "(", "ci", "CellID", ")", "ToToken", "(", ")", "string", "{", "s", ":=", "strings", ".", "TrimRight", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "uint64", "(", "ci", ")", ")", ",", "\"", "\"", ")", "\n", "if", "len", "(", "s", ...
// ToToken returns a hex-encoded string of the uint64 cell id, with leading // zeros included but trailing zeros stripped.
[ "ToToken", "returns", "a", "hex", "-", "encoded", "string", "of", "the", "uint64", "cell", "id", "with", "leading", "zeros", "included", "but", "trailing", "zeros", "stripped", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/cellid.go#L133-L139
train
golang/geo
s2/cellid.go
Parent
func (ci CellID) Parent(level int) CellID { lsb := lsbForLevel(level) return CellID((uint64(ci) & -lsb) | lsb) }
go
func (ci CellID) Parent(level int) CellID { lsb := lsbForLevel(level) return CellID((uint64(ci) & -lsb) | lsb) }
[ "func", "(", "ci", "CellID", ")", "Parent", "(", "level", "int", ")", "CellID", "{", "lsb", ":=", "lsbForLevel", "(", "level", ")", "\n", "return", "CellID", "(", "(", "uint64", "(", "ci", ")", "&", "-", "lsb", ")", "|", "lsb", ")", "\n", "}" ]
// Parent returns the cell at the given level, which must be no greater than the current level.
[ "Parent", "returns", "the", "cell", "at", "the", "given", "level", "which", "must", "be", "no", "greater", "than", "the", "current", "level", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/cellid.go#L174-L177
train
golang/geo
s2/cellid.go
Children
func (ci CellID) Children() [4]CellID { var ch [4]CellID lsb := CellID(ci.lsb()) ch[0] = ci - lsb + lsb>>2 lsb >>= 1 ch[1] = ch[0] + lsb ch[2] = ch[1] + lsb ch[3] = ch[2] + lsb return ch }
go
func (ci CellID) Children() [4]CellID { var ch [4]CellID lsb := CellID(ci.lsb()) ch[0] = ci - lsb + lsb>>2 lsb >>= 1 ch[1] = ch[0] + lsb ch[2] = ch[1] + lsb ch[3] = ch[2] + lsb return ch }
[ "func", "(", "ci", "CellID", ")", "Children", "(", ")", "[", "4", "]", "CellID", "{", "var", "ch", "[", "4", "]", "CellID", "\n", "lsb", ":=", "CellID", "(", "ci", ".", "lsb", "(", ")", ")", "\n", "ch", "[", "0", "]", "=", "ci", "-", "lsb",...
// Children returns the four immediate children of this cell. // If ci is a leaf cell, it returns four identical cells that are not the children.
[ "Children", "returns", "the", "four", "immediate", "children", "of", "this", "cell", ".", "If", "ci", "is", "a", "leaf", "cell", "it", "returns", "four", "identical", "cells", "that", "are", "not", "the", "children", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/cellid.go#L193-L202
train
golang/geo
s2/cellid.go
EdgeNeighbors
func (ci CellID) EdgeNeighbors() [4]CellID { level := ci.Level() size := sizeIJ(level) f, i, j, _ := ci.faceIJOrientation() return [4]CellID{ cellIDFromFaceIJWrap(f, i, j-size).Parent(level), cellIDFromFaceIJWrap(f, i+size, j).Parent(level), cellIDFromFaceIJWrap(f, i, j+size).Parent(level), cellIDFromFaceIJWrap(f, i-size, j).Parent(level), } }
go
func (ci CellID) EdgeNeighbors() [4]CellID { level := ci.Level() size := sizeIJ(level) f, i, j, _ := ci.faceIJOrientation() return [4]CellID{ cellIDFromFaceIJWrap(f, i, j-size).Parent(level), cellIDFromFaceIJWrap(f, i+size, j).Parent(level), cellIDFromFaceIJWrap(f, i, j+size).Parent(level), cellIDFromFaceIJWrap(f, i-size, j).Parent(level), } }
[ "func", "(", "ci", "CellID", ")", "EdgeNeighbors", "(", ")", "[", "4", "]", "CellID", "{", "level", ":=", "ci", ".", "Level", "(", ")", "\n", "size", ":=", "sizeIJ", "(", "level", ")", "\n", "f", ",", "i", ",", "j", ",", "_", ":=", "ci", ".",...
// EdgeNeighbors returns the four cells that are adjacent across the cell's four edges. // Edges 0, 1, 2, 3 are in the down, right, up, left directions in the face space. // All neighbors are guaranteed to be distinct.
[ "EdgeNeighbors", "returns", "the", "four", "cells", "that", "are", "adjacent", "across", "the", "cell", "s", "four", "edges", ".", "Edges", "0", "1", "2", "3", "are", "in", "the", "down", "right", "up", "left", "directions", "in", "the", "face", "space",...
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/cellid.go#L211-L221
train