id
int32
0
167k
repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
listlengths
21
1.41k
docstring
stringlengths
6
2.61k
docstring_tokens
listlengths
3
215
sha
stringlengths
40
40
url
stringlengths
85
252
150,200
golang/geo
s2/shapeindex.go
End
func (s *ShapeIndexIterator) End() { s.position = len(s.index.cells) s.refresh() }
go
func (s *ShapeIndexIterator) End() { s.position = len(s.index.cells) s.refresh() }
[ "func", "(", "s", "*", "ShapeIndexIterator", ")", "End", "(", ")", "{", "s", ".", "position", "=", "len", "(", "s", ".", "index", ".", "cells", ")", "\n", "s", ".", "refresh", "(", ")", "\n", "}" ]
// End positions the iterator at the end of the index.
[ "End", "positions", "the", "iterator", "at", "the", "end", "of", "the", "index", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/shapeindex.go#L282-L285
150,201
golang/geo
s2/shapeindex.go
refresh
func (s *ShapeIndexIterator) refresh() { if s.position < len(s.index.cells) { s.id = s.index.cells[s.position] s.cell = s.index.cellMap[s.CellID()] } else { s.id = SentinelCellID s.cell = nil } }
go
func (s *ShapeIndexIterator) refresh() { if s.position < len(s.index.cells) { s.id = s.index.cells[s.position] s.cell = s.index.cellMap[s.CellID()] } else { s.id = SentinelCellID s.cell = nil } }
[ "func", "(", "s", "*", "ShapeIndexIterator", ")", "refresh", "(", ")", "{", "if", "s", ".", "position", "<", "len", "(", "s", ".", "index", ".", "cells", ")", "{", "s", ".", "id", "=", "s", ".", "index", ".", "cells", "[", "s", ".", "position", "]", "\n", "s", ".", "cell", "=", "s", ".", "index", ".", "cellMap", "[", "s", ".", "CellID", "(", ")", "]", "\n", "}", "else", "{", "s", ".", "id", "=", "SentinelCellID", "\n", "s", ".", "cell", "=", "nil", "\n", "}", "\n", "}" ]
// refresh updates the stored internal iterator values.
[ "refresh", "updates", "the", "stored", "internal", "iterator", "values", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/shapeindex.go#L293-L301
150,202
golang/geo
s2/shapeindex.go
seek
func (s *ShapeIndexIterator) seek(target CellID) { s.position = 0 // In C++, this relies on the lower_bound method of the underlying btree_map. // TODO(roberts): Convert this to a binary search since the list of cells is ordered. for k, v := range s.index.cells { // We've passed the cell that is after us, so we are done. if v >= target { s.position = k break } // Otherwise, advance the position. s.position++ } s.refresh() }
go
func (s *ShapeIndexIterator) seek(target CellID) { s.position = 0 // In C++, this relies on the lower_bound method of the underlying btree_map. // TODO(roberts): Convert this to a binary search since the list of cells is ordered. for k, v := range s.index.cells { // We've passed the cell that is after us, so we are done. if v >= target { s.position = k break } // Otherwise, advance the position. s.position++ } s.refresh() }
[ "func", "(", "s", "*", "ShapeIndexIterator", ")", "seek", "(", "target", "CellID", ")", "{", "s", ".", "position", "=", "0", "\n", "// In C++, this relies on the lower_bound method of the underlying btree_map.", "// TODO(roberts): Convert this to a binary search since the list of cells is ordered.", "for", "k", ",", "v", ":=", "range", "s", ".", "index", ".", "cells", "{", "// We've passed the cell that is after us, so we are done.", "if", "v", ">=", "target", "{", "s", ".", "position", "=", "k", "\n", "break", "\n", "}", "\n", "// Otherwise, advance the position.", "s", ".", "position", "++", "\n", "}", "\n", "s", ".", "refresh", "(", ")", "\n", "}" ]
// seek positions the iterator at the first cell whose ID >= target, or at the // end of the index if no such cell exists.
[ "seek", "positions", "the", "iterator", "at", "the", "first", "cell", "whose", "ID", ">", "=", "target", "or", "at", "the", "end", "of", "the", "index", "if", "no", "such", "cell", "exists", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/shapeindex.go#L305-L319
150,203
golang/geo
s2/shapeindex.go
LocatePoint
func (s *ShapeIndexIterator) LocatePoint(p Point) bool { // Let I = cellMap.LowerBound(T), where T is the leaf cell containing // point P. Then if T is contained by an index cell, then the // containing cell is either I or I'. We test for containment by comparing // the ranges of leaf cells spanned by T, I, and I'. target := cellIDFromPoint(p) s.seek(target) if !s.Done() && s.CellID().RangeMin() <= target { return true } if s.Prev() && s.CellID().RangeMax() >= target { return true } return false }
go
func (s *ShapeIndexIterator) LocatePoint(p Point) bool { // Let I = cellMap.LowerBound(T), where T is the leaf cell containing // point P. Then if T is contained by an index cell, then the // containing cell is either I or I'. We test for containment by comparing // the ranges of leaf cells spanned by T, I, and I'. target := cellIDFromPoint(p) s.seek(target) if !s.Done() && s.CellID().RangeMin() <= target { return true } if s.Prev() && s.CellID().RangeMax() >= target { return true } return false }
[ "func", "(", "s", "*", "ShapeIndexIterator", ")", "LocatePoint", "(", "p", "Point", ")", "bool", "{", "// Let I = cellMap.LowerBound(T), where T is the leaf cell containing", "// point P. Then if T is contained by an index cell, then the", "// containing cell is either I or I'. We test for containment by comparing", "// the ranges of leaf cells spanned by T, I, and I'.", "target", ":=", "cellIDFromPoint", "(", "p", ")", "\n", "s", ".", "seek", "(", "target", ")", "\n", "if", "!", "s", ".", "Done", "(", ")", "&&", "s", ".", "CellID", "(", ")", ".", "RangeMin", "(", ")", "<=", "target", "{", "return", "true", "\n", "}", "\n\n", "if", "s", ".", "Prev", "(", ")", "&&", "s", ".", "CellID", "(", ")", ".", "RangeMax", "(", ")", ">=", "target", "{", "return", "true", "\n", "}", "\n", "return", "false", "\n", "}" ]
// LocatePoint positions the iterator at the cell that contains the given Point. // If no such cell exists, the iterator position is unspecified, and false is returned. // The cell at the matched position is guaranteed to contain all edges that might // intersect the line segment between target and the cell's center.
[ "LocatePoint", "positions", "the", "iterator", "at", "the", "cell", "that", "contains", "the", "given", "Point", ".", "If", "no", "such", "cell", "exists", "the", "iterator", "position", "is", "unspecified", "and", "false", "is", "returned", ".", "The", "cell", "at", "the", "matched", "position", "is", "guaranteed", "to", "contain", "all", "edges", "that", "might", "intersect", "the", "line", "segment", "between", "target", "and", "the", "cell", "s", "center", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/shapeindex.go#L325-L340
150,204
golang/geo
s2/shapeindex.go
newTracker
func newTracker() *tracker { // As shapes are added, we compute which ones contain the start of the // CellID space-filling curve by drawing an edge from OriginPoint to this // point and counting how many shape edges cross this edge. t := &tracker{ isActive: false, b: trackerOrigin(), nextCellID: CellIDFromFace(0).ChildBeginAtLevel(maxLevel), } t.drawTo(Point{faceUVToXYZ(0, -1, -1).Normalize()}) // CellID curve start return t }
go
func newTracker() *tracker { // As shapes are added, we compute which ones contain the start of the // CellID space-filling curve by drawing an edge from OriginPoint to this // point and counting how many shape edges cross this edge. t := &tracker{ isActive: false, b: trackerOrigin(), nextCellID: CellIDFromFace(0).ChildBeginAtLevel(maxLevel), } t.drawTo(Point{faceUVToXYZ(0, -1, -1).Normalize()}) // CellID curve start return t }
[ "func", "newTracker", "(", ")", "*", "tracker", "{", "// As shapes are added, we compute which ones contain the start of the", "// CellID space-filling curve by drawing an edge from OriginPoint to this", "// point and counting how many shape edges cross this edge.", "t", ":=", "&", "tracker", "{", "isActive", ":", "false", ",", "b", ":", "trackerOrigin", "(", ")", ",", "nextCellID", ":", "CellIDFromFace", "(", "0", ")", ".", "ChildBeginAtLevel", "(", "maxLevel", ")", ",", "}", "\n", "t", ".", "drawTo", "(", "Point", "{", "faceUVToXYZ", "(", "0", ",", "-", "1", ",", "-", "1", ")", ".", "Normalize", "(", ")", "}", ")", "// CellID curve start", "\n\n", "return", "t", "\n", "}" ]
// newTracker returns a new tracker with the appropriate defaults.
[ "newTracker", "returns", "a", "new", "tracker", "with", "the", "appropriate", "defaults", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/shapeindex.go#L402-L414
150,205
golang/geo
s2/shapeindex.go
drawTo
func (t *tracker) drawTo(b Point) { t.a = t.b t.b = b // TODO: the edge crosser may need an in-place Init method if this gets expensive t.crosser = NewEdgeCrosser(t.a, t.b) }
go
func (t *tracker) drawTo(b Point) { t.a = t.b t.b = b // TODO: the edge crosser may need an in-place Init method if this gets expensive t.crosser = NewEdgeCrosser(t.a, t.b) }
[ "func", "(", "t", "*", "tracker", ")", "drawTo", "(", "b", "Point", ")", "{", "t", ".", "a", "=", "t", ".", "b", "\n", "t", ".", "b", "=", "b", "\n", "// TODO: the edge crosser may need an in-place Init method if this gets expensive", "t", ".", "crosser", "=", "NewEdgeCrosser", "(", "t", ".", "a", ",", "t", ".", "b", ")", "\n", "}" ]
// drawTo moves the focus of the tracker to the given point. After this method is // called, testEdge should be called with all edges that may cross the line // segment between the old and new focus locations.
[ "drawTo", "moves", "the", "focus", "of", "the", "tracker", "to", "the", "given", "point", ".", "After", "this", "method", "is", "called", "testEdge", "should", "be", "called", "with", "all", "edges", "that", "may", "cross", "the", "line", "segment", "between", "the", "old", "and", "new", "focus", "locations", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/shapeindex.go#L449-L454
150,206
golang/geo
s2/shapeindex.go
toggleShape
func (t *tracker) toggleShape(shapeID int32) { // Most shapeIDs slices are small, so special case the common steps. // If there is nothing here, add it. if len(t.shapeIDs) == 0 { t.shapeIDs = append(t.shapeIDs, shapeID) return } // If it's the first element, drop it from the slice. if t.shapeIDs[0] == shapeID { t.shapeIDs = t.shapeIDs[1:] return } for i, s := range t.shapeIDs { if s < shapeID { continue } // If it's in the set, cut it out. if s == shapeID { copy(t.shapeIDs[i:], t.shapeIDs[i+1:]) // overwrite the ith element t.shapeIDs = t.shapeIDs[:len(t.shapeIDs)-1] return } // We've got to a point in the slice where we should be inserted. // (the given shapeID is now less than the current positions id.) t.shapeIDs = append(t.shapeIDs[0:i], append([]int32{shapeID}, t.shapeIDs[i:len(t.shapeIDs)]...)...) return } // We got to the end and didn't find it, so add it to the list. t.shapeIDs = append(t.shapeIDs, shapeID) }
go
func (t *tracker) toggleShape(shapeID int32) { // Most shapeIDs slices are small, so special case the common steps. // If there is nothing here, add it. if len(t.shapeIDs) == 0 { t.shapeIDs = append(t.shapeIDs, shapeID) return } // If it's the first element, drop it from the slice. if t.shapeIDs[0] == shapeID { t.shapeIDs = t.shapeIDs[1:] return } for i, s := range t.shapeIDs { if s < shapeID { continue } // If it's in the set, cut it out. if s == shapeID { copy(t.shapeIDs[i:], t.shapeIDs[i+1:]) // overwrite the ith element t.shapeIDs = t.shapeIDs[:len(t.shapeIDs)-1] return } // We've got to a point in the slice where we should be inserted. // (the given shapeID is now less than the current positions id.) t.shapeIDs = append(t.shapeIDs[0:i], append([]int32{shapeID}, t.shapeIDs[i:len(t.shapeIDs)]...)...) return } // We got to the end and didn't find it, so add it to the list. t.shapeIDs = append(t.shapeIDs, shapeID) }
[ "func", "(", "t", "*", "tracker", ")", "toggleShape", "(", "shapeID", "int32", ")", "{", "// Most shapeIDs slices are small, so special case the common steps.", "// If there is nothing here, add it.", "if", "len", "(", "t", ".", "shapeIDs", ")", "==", "0", "{", "t", ".", "shapeIDs", "=", "append", "(", "t", ".", "shapeIDs", ",", "shapeID", ")", "\n", "return", "\n", "}", "\n\n", "// If it's the first element, drop it from the slice.", "if", "t", ".", "shapeIDs", "[", "0", "]", "==", "shapeID", "{", "t", ".", "shapeIDs", "=", "t", ".", "shapeIDs", "[", "1", ":", "]", "\n", "return", "\n", "}", "\n\n", "for", "i", ",", "s", ":=", "range", "t", ".", "shapeIDs", "{", "if", "s", "<", "shapeID", "{", "continue", "\n", "}", "\n\n", "// If it's in the set, cut it out.", "if", "s", "==", "shapeID", "{", "copy", "(", "t", ".", "shapeIDs", "[", "i", ":", "]", ",", "t", ".", "shapeIDs", "[", "i", "+", "1", ":", "]", ")", "// overwrite the ith element", "\n", "t", ".", "shapeIDs", "=", "t", ".", "shapeIDs", "[", ":", "len", "(", "t", ".", "shapeIDs", ")", "-", "1", "]", "\n", "return", "\n", "}", "\n\n", "// We've got to a point in the slice where we should be inserted.", "// (the given shapeID is now less than the current positions id.)", "t", ".", "shapeIDs", "=", "append", "(", "t", ".", "shapeIDs", "[", "0", ":", "i", "]", ",", "append", "(", "[", "]", "int32", "{", "shapeID", "}", ",", "t", ".", "shapeIDs", "[", "i", ":", "len", "(", "t", ".", "shapeIDs", ")", "]", "...", ")", "...", ")", "\n", "return", "\n", "}", "\n\n", "// We got to the end and didn't find it, so add it to the list.", "t", ".", "shapeIDs", "=", "append", "(", "t", ".", "shapeIDs", ",", "shapeID", ")", "\n", "}" ]
// toggleShape adds or removes the given shapeID from the set of IDs it is tracking.
[ "toggleShape", "adds", "or", "removes", "the", "given", "shapeID", "from", "the", "set", "of", "IDs", "it", "is", "tracking", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/shapeindex.go#L481-L517
150,207
golang/geo
s2/shapeindex.go
restoreStateBefore
func (t *tracker) restoreStateBefore(limitShapeID int32) { limit := t.lowerBound(limitShapeID) t.shapeIDs = append(append([]int32(nil), t.savedIDs...), t.shapeIDs[limit:]...) t.savedIDs = nil }
go
func (t *tracker) restoreStateBefore(limitShapeID int32) { limit := t.lowerBound(limitShapeID) t.shapeIDs = append(append([]int32(nil), t.savedIDs...), t.shapeIDs[limit:]...) t.savedIDs = nil }
[ "func", "(", "t", "*", "tracker", ")", "restoreStateBefore", "(", "limitShapeID", "int32", ")", "{", "limit", ":=", "t", ".", "lowerBound", "(", "limitShapeID", ")", "\n", "t", ".", "shapeIDs", "=", "append", "(", "append", "(", "[", "]", "int32", "(", "nil", ")", ",", "t", ".", "savedIDs", "...", ")", ",", "t", ".", "shapeIDs", "[", "limit", ":", "]", "...", ")", "\n", "t", ".", "savedIDs", "=", "nil", "\n", "}" ]
// restoreStateBefore restores the state previously saved by saveAndClearStateBefore. // This only affects the state for shapeIDs below "limitShapeID".
[ "restoreStateBefore", "restores", "the", "state", "previously", "saved", "by", "saveAndClearStateBefore", ".", "This", "only", "affects", "the", "state", "for", "shapeIDs", "below", "limitShapeID", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/shapeindex.go#L530-L534
150,208
golang/geo
s2/shapeindex.go
NewShapeIndex
func NewShapeIndex() *ShapeIndex { return &ShapeIndex{ maxEdgesPerCell: 10, shapes: make(map[int32]Shape), cellMap: make(map[CellID]*ShapeIndexCell), cells: nil, status: fresh, } }
go
func NewShapeIndex() *ShapeIndex { return &ShapeIndex{ maxEdgesPerCell: 10, shapes: make(map[int32]Shape), cellMap: make(map[CellID]*ShapeIndexCell), cells: nil, status: fresh, } }
[ "func", "NewShapeIndex", "(", ")", "*", "ShapeIndex", "{", "return", "&", "ShapeIndex", "{", "maxEdgesPerCell", ":", "10", ",", "shapes", ":", "make", "(", "map", "[", "int32", "]", "Shape", ")", ",", "cellMap", ":", "make", "(", "map", "[", "CellID", "]", "*", "ShapeIndexCell", ")", ",", "cells", ":", "nil", ",", "status", ":", "fresh", ",", "}", "\n", "}" ]
// NewShapeIndex creates a new ShapeIndex.
[ "NewShapeIndex", "creates", "a", "new", "ShapeIndex", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/shapeindex.go#L631-L639
150,209
golang/geo
s2/shapeindex.go
Reset
func (s *ShapeIndex) Reset() { s.shapes = make(map[int32]Shape) s.nextID = 0 s.cellMap = make(map[CellID]*ShapeIndexCell) s.cells = nil atomic.StoreInt32(&s.status, fresh) }
go
func (s *ShapeIndex) Reset() { s.shapes = make(map[int32]Shape) s.nextID = 0 s.cellMap = make(map[CellID]*ShapeIndexCell) s.cells = nil atomic.StoreInt32(&s.status, fresh) }
[ "func", "(", "s", "*", "ShapeIndex", ")", "Reset", "(", ")", "{", "s", ".", "shapes", "=", "make", "(", "map", "[", "int32", "]", "Shape", ")", "\n", "s", ".", "nextID", "=", "0", "\n", "s", ".", "cellMap", "=", "make", "(", "map", "[", "CellID", "]", "*", "ShapeIndexCell", ")", "\n", "s", ".", "cells", "=", "nil", "\n", "atomic", ".", "StoreInt32", "(", "&", "s", ".", "status", ",", "fresh", ")", "\n", "}" ]
// Reset resets the index to its original state.
[ "Reset", "resets", "the", "index", "to", "its", "original", "state", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/shapeindex.go#L669-L675
150,210
golang/geo
s2/shapeindex.go
NumEdges
func (s *ShapeIndex) NumEdges() int { numEdges := 0 for _, shape := range s.shapes { numEdges += shape.NumEdges() } return numEdges }
go
func (s *ShapeIndex) NumEdges() int { numEdges := 0 for _, shape := range s.shapes { numEdges += shape.NumEdges() } return numEdges }
[ "func", "(", "s", "*", "ShapeIndex", ")", "NumEdges", "(", ")", "int", "{", "numEdges", ":=", "0", "\n", "for", "_", ",", "shape", ":=", "range", "s", ".", "shapes", "{", "numEdges", "+=", "shape", ".", "NumEdges", "(", ")", "\n", "}", "\n", "return", "numEdges", "\n", "}" ]
// NumEdges returns the number of edges in this index.
[ "NumEdges", "returns", "the", "number", "of", "edges", "in", "this", "index", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/shapeindex.go#L678-L684
150,211
golang/geo
s2/shapeindex.go
NumEdgesUpTo
func (s *ShapeIndex) NumEdgesUpTo(limit int) int { var numEdges int // We choose to iterate over the shapes in order to match the counting // up behavior in C++ and for test compatibility instead of using a // more idiomatic range over the shape map. for i := int32(0); i <= s.nextID; i++ { s := s.Shape(i) if s == nil { continue } numEdges += s.NumEdges() if numEdges >= limit { break } } return numEdges }
go
func (s *ShapeIndex) NumEdgesUpTo(limit int) int { var numEdges int // We choose to iterate over the shapes in order to match the counting // up behavior in C++ and for test compatibility instead of using a // more idiomatic range over the shape map. for i := int32(0); i <= s.nextID; i++ { s := s.Shape(i) if s == nil { continue } numEdges += s.NumEdges() if numEdges >= limit { break } } return numEdges }
[ "func", "(", "s", "*", "ShapeIndex", ")", "NumEdgesUpTo", "(", "limit", "int", ")", "int", "{", "var", "numEdges", "int", "\n", "// We choose to iterate over the shapes in order to match the counting", "// up behavior in C++ and for test compatibility instead of using a", "// more idiomatic range over the shape map.", "for", "i", ":=", "int32", "(", "0", ")", ";", "i", "<=", "s", ".", "nextID", ";", "i", "++", "{", "s", ":=", "s", ".", "Shape", "(", "i", ")", "\n", "if", "s", "==", "nil", "{", "continue", "\n", "}", "\n", "numEdges", "+=", "s", ".", "NumEdges", "(", ")", "\n", "if", "numEdges", ">=", "limit", "{", "break", "\n", "}", "\n", "}", "\n\n", "return", "numEdges", "\n", "}" ]
// NumEdgesUpTo returns the number of edges in the given index, up to the given // limit. If the limit is encountered, the current running total is returned, // which may be more than the limit.
[ "NumEdgesUpTo", "returns", "the", "number", "of", "edges", "in", "the", "given", "index", "up", "to", "the", "given", "limit", ".", "If", "the", "limit", "is", "encountered", "the", "current", "running", "total", "is", "returned", "which", "may", "be", "more", "than", "the", "limit", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/shapeindex.go#L689-L706
150,212
golang/geo
s2/shapeindex.go
Add
func (s *ShapeIndex) Add(shape Shape) int32 { s.shapes[s.nextID] = shape s.nextID++ atomic.StoreInt32(&s.status, stale) return s.nextID - 1 }
go
func (s *ShapeIndex) Add(shape Shape) int32 { s.shapes[s.nextID] = shape s.nextID++ atomic.StoreInt32(&s.status, stale) return s.nextID - 1 }
[ "func", "(", "s", "*", "ShapeIndex", ")", "Add", "(", "shape", "Shape", ")", "int32", "{", "s", ".", "shapes", "[", "s", ".", "nextID", "]", "=", "shape", "\n", "s", ".", "nextID", "++", "\n", "atomic", ".", "StoreInt32", "(", "&", "s", ".", "status", ",", "stale", ")", "\n", "return", "s", ".", "nextID", "-", "1", "\n", "}" ]
// Add adds the given shape to the index and returns the assigned ID..
[ "Add", "adds", "the", "given", "shape", "to", "the", "index", "and", "returns", "the", "assigned", "ID", ".." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/shapeindex.go#L728-L733
150,213
golang/geo
s2/shapeindex.go
Remove
func (s *ShapeIndex) Remove(shape Shape) { // The index updates itself lazily because it is much more efficient to // process additions and removals in batches. id := s.idForShape(shape) // If the shape wasn't found, it's already been removed or was not in the index. if s.shapes[id] == nil { return } // Remove the shape from the shapes map. delete(s.shapes, id) // We are removing a shape that has not yet been added to the index, // so there is nothing else to do. if id >= s.pendingAdditionsPos { return } numEdges := shape.NumEdges() removed := &removedShape{ shapeID: id, hasInterior: shape.Dimension() == 2, containsTrackerOrigin: shape.ReferencePoint().Contained, edges: make([]Edge, numEdges), } for e := 0; e < numEdges; e++ { removed.edges[e] = shape.Edge(e) } s.pendingRemovals = append(s.pendingRemovals, removed) atomic.StoreInt32(&s.status, stale) }
go
func (s *ShapeIndex) Remove(shape Shape) { // The index updates itself lazily because it is much more efficient to // process additions and removals in batches. id := s.idForShape(shape) // If the shape wasn't found, it's already been removed or was not in the index. if s.shapes[id] == nil { return } // Remove the shape from the shapes map. delete(s.shapes, id) // We are removing a shape that has not yet been added to the index, // so there is nothing else to do. if id >= s.pendingAdditionsPos { return } numEdges := shape.NumEdges() removed := &removedShape{ shapeID: id, hasInterior: shape.Dimension() == 2, containsTrackerOrigin: shape.ReferencePoint().Contained, edges: make([]Edge, numEdges), } for e := 0; e < numEdges; e++ { removed.edges[e] = shape.Edge(e) } s.pendingRemovals = append(s.pendingRemovals, removed) atomic.StoreInt32(&s.status, stale) }
[ "func", "(", "s", "*", "ShapeIndex", ")", "Remove", "(", "shape", "Shape", ")", "{", "// The index updates itself lazily because it is much more efficient to", "// process additions and removals in batches.", "id", ":=", "s", ".", "idForShape", "(", "shape", ")", "\n\n", "// If the shape wasn't found, it's already been removed or was not in the index.", "if", "s", ".", "shapes", "[", "id", "]", "==", "nil", "{", "return", "\n", "}", "\n\n", "// Remove the shape from the shapes map.", "delete", "(", "s", ".", "shapes", ",", "id", ")", "\n\n", "// We are removing a shape that has not yet been added to the index,", "// so there is nothing else to do.", "if", "id", ">=", "s", ".", "pendingAdditionsPos", "{", "return", "\n", "}", "\n\n", "numEdges", ":=", "shape", ".", "NumEdges", "(", ")", "\n", "removed", ":=", "&", "removedShape", "{", "shapeID", ":", "id", ",", "hasInterior", ":", "shape", ".", "Dimension", "(", ")", "==", "2", ",", "containsTrackerOrigin", ":", "shape", ".", "ReferencePoint", "(", ")", ".", "Contained", ",", "edges", ":", "make", "(", "[", "]", "Edge", ",", "numEdges", ")", ",", "}", "\n\n", "for", "e", ":=", "0", ";", "e", "<", "numEdges", ";", "e", "++", "{", "removed", ".", "edges", "[", "e", "]", "=", "shape", ".", "Edge", "(", "e", ")", "\n", "}", "\n\n", "s", ".", "pendingRemovals", "=", "append", "(", "s", ".", "pendingRemovals", ",", "removed", ")", "\n", "atomic", ".", "StoreInt32", "(", "&", "s", ".", "status", ",", "stale", ")", "\n", "}" ]
// Remove removes the given shape from the index.
[ "Remove", "removes", "the", "given", "shape", "from", "the", "index", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/shapeindex.go#L736-L769
150,214
golang/geo
s2/shapeindex.go
maybeApplyUpdates
func (s *ShapeIndex) maybeApplyUpdates() { // TODO(roberts): To avoid acquiring and releasing the mutex on every // query, we should use atomic operations when testing whether the status // is fresh and when updating the status to be fresh. This guarantees // that any thread that sees a status of fresh will also see the // corresponding index updates. if atomic.LoadInt32(&s.status) != fresh { s.mu.Lock() s.applyUpdatesInternal() atomic.StoreInt32(&s.status, fresh) s.mu.Unlock() } }
go
func (s *ShapeIndex) maybeApplyUpdates() { // TODO(roberts): To avoid acquiring and releasing the mutex on every // query, we should use atomic operations when testing whether the status // is fresh and when updating the status to be fresh. This guarantees // that any thread that sees a status of fresh will also see the // corresponding index updates. if atomic.LoadInt32(&s.status) != fresh { s.mu.Lock() s.applyUpdatesInternal() atomic.StoreInt32(&s.status, fresh) s.mu.Unlock() } }
[ "func", "(", "s", "*", "ShapeIndex", ")", "maybeApplyUpdates", "(", ")", "{", "// TODO(roberts): To avoid acquiring and releasing the mutex on every", "// query, we should use atomic operations when testing whether the status", "// is fresh and when updating the status to be fresh. This guarantees", "// that any thread that sees a status of fresh will also see the", "// corresponding index updates.", "if", "atomic", ".", "LoadInt32", "(", "&", "s", ".", "status", ")", "!=", "fresh", "{", "s", ".", "mu", ".", "Lock", "(", ")", "\n", "s", ".", "applyUpdatesInternal", "(", ")", "\n", "atomic", ".", "StoreInt32", "(", "&", "s", ".", "status", ",", "fresh", ")", "\n", "s", ".", "mu", ".", "Unlock", "(", ")", "\n", "}", "\n", "}" ]
// maybeApplyUpdates checks if the index pieces have changed, and if so, applies pending updates.
[ "maybeApplyUpdates", "checks", "if", "the", "index", "pieces", "have", "changed", "and", "if", "so", "applies", "pending", "updates", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/shapeindex.go#L797-L809
150,215
golang/geo
s2/shapeindex.go
addShapeInternal
func (s *ShapeIndex) addShapeInternal(shapeID int32, allEdges [][]faceEdge, t *tracker) { shape, ok := s.shapes[shapeID] if !ok { // This shape has already been removed. return } faceEdge := faceEdge{ shapeID: shapeID, hasInterior: shape.Dimension() == 2, } if faceEdge.hasInterior { t.addShape(shapeID, containsBruteForce(shape, t.focus())) } numEdges := shape.NumEdges() for e := 0; e < numEdges; e++ { edge := shape.Edge(e) faceEdge.edgeID = e faceEdge.edge = edge faceEdge.maxLevel = maxLevelForEdge(edge) s.addFaceEdge(faceEdge, allEdges) } }
go
func (s *ShapeIndex) addShapeInternal(shapeID int32, allEdges [][]faceEdge, t *tracker) { shape, ok := s.shapes[shapeID] if !ok { // This shape has already been removed. return } faceEdge := faceEdge{ shapeID: shapeID, hasInterior: shape.Dimension() == 2, } if faceEdge.hasInterior { t.addShape(shapeID, containsBruteForce(shape, t.focus())) } numEdges := shape.NumEdges() for e := 0; e < numEdges; e++ { edge := shape.Edge(e) faceEdge.edgeID = e faceEdge.edge = edge faceEdge.maxLevel = maxLevelForEdge(edge) s.addFaceEdge(faceEdge, allEdges) } }
[ "func", "(", "s", "*", "ShapeIndex", ")", "addShapeInternal", "(", "shapeID", "int32", ",", "allEdges", "[", "]", "[", "]", "faceEdge", ",", "t", "*", "tracker", ")", "{", "shape", ",", "ok", ":=", "s", ".", "shapes", "[", "shapeID", "]", "\n", "if", "!", "ok", "{", "// This shape has already been removed.", "return", "\n", "}", "\n\n", "faceEdge", ":=", "faceEdge", "{", "shapeID", ":", "shapeID", ",", "hasInterior", ":", "shape", ".", "Dimension", "(", ")", "==", "2", ",", "}", "\n\n", "if", "faceEdge", ".", "hasInterior", "{", "t", ".", "addShape", "(", "shapeID", ",", "containsBruteForce", "(", "shape", ",", "t", ".", "focus", "(", ")", ")", ")", "\n", "}", "\n\n", "numEdges", ":=", "shape", ".", "NumEdges", "(", ")", "\n", "for", "e", ":=", "0", ";", "e", "<", "numEdges", ";", "e", "++", "{", "edge", ":=", "shape", ".", "Edge", "(", "e", ")", "\n\n", "faceEdge", ".", "edgeID", "=", "e", "\n", "faceEdge", ".", "edge", "=", "edge", "\n", "faceEdge", ".", "maxLevel", "=", "maxLevelForEdge", "(", "edge", ")", "\n", "s", ".", "addFaceEdge", "(", "faceEdge", ",", "allEdges", ")", "\n", "}", "\n", "}" ]
// addShapeInternal clips all edges of the given shape to the six cube faces, // adds the clipped edges to the set of allEdges, and starts tracking its // interior if necessary.
[ "addShapeInternal", "clips", "all", "edges", "of", "the", "given", "shape", "to", "the", "six", "cube", "faces", "adds", "the", "clipped", "edges", "to", "the", "set", "of", "allEdges", "and", "starts", "tracking", "its", "interior", "if", "necessary", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/shapeindex.go#L843-L868
150,216
golang/geo
s2/shapeindex.go
addFaceEdge
func (s *ShapeIndex) addFaceEdge(fe faceEdge, allEdges [][]faceEdge) { aFace := face(fe.edge.V0.Vector) // See if both endpoints are on the same face, and are far enough from // the edge of the face that they don't intersect any (padded) adjacent face. if aFace == face(fe.edge.V1.Vector) { x, y := validFaceXYZToUV(aFace, fe.edge.V0.Vector) fe.a = r2.Point{x, y} x, y = validFaceXYZToUV(aFace, fe.edge.V1.Vector) fe.b = r2.Point{x, y} maxUV := 1 - cellPadding if math.Abs(fe.a.X) <= maxUV && math.Abs(fe.a.Y) <= maxUV && math.Abs(fe.b.X) <= maxUV && math.Abs(fe.b.Y) <= maxUV { allEdges[aFace] = append(allEdges[aFace], fe) return } } // Otherwise, we simply clip the edge to all six faces. for face := 0; face < 6; face++ { if aClip, bClip, intersects := ClipToPaddedFace(fe.edge.V0, fe.edge.V1, face, cellPadding); intersects { fe.a = aClip fe.b = bClip allEdges[face] = append(allEdges[face], fe) } } return }
go
func (s *ShapeIndex) addFaceEdge(fe faceEdge, allEdges [][]faceEdge) { aFace := face(fe.edge.V0.Vector) // See if both endpoints are on the same face, and are far enough from // the edge of the face that they don't intersect any (padded) adjacent face. if aFace == face(fe.edge.V1.Vector) { x, y := validFaceXYZToUV(aFace, fe.edge.V0.Vector) fe.a = r2.Point{x, y} x, y = validFaceXYZToUV(aFace, fe.edge.V1.Vector) fe.b = r2.Point{x, y} maxUV := 1 - cellPadding if math.Abs(fe.a.X) <= maxUV && math.Abs(fe.a.Y) <= maxUV && math.Abs(fe.b.X) <= maxUV && math.Abs(fe.b.Y) <= maxUV { allEdges[aFace] = append(allEdges[aFace], fe) return } } // Otherwise, we simply clip the edge to all six faces. for face := 0; face < 6; face++ { if aClip, bClip, intersects := ClipToPaddedFace(fe.edge.V0, fe.edge.V1, face, cellPadding); intersects { fe.a = aClip fe.b = bClip allEdges[face] = append(allEdges[face], fe) } } return }
[ "func", "(", "s", "*", "ShapeIndex", ")", "addFaceEdge", "(", "fe", "faceEdge", ",", "allEdges", "[", "]", "[", "]", "faceEdge", ")", "{", "aFace", ":=", "face", "(", "fe", ".", "edge", ".", "V0", ".", "Vector", ")", "\n", "// See if both endpoints are on the same face, and are far enough from", "// the edge of the face that they don't intersect any (padded) adjacent face.", "if", "aFace", "==", "face", "(", "fe", ".", "edge", ".", "V1", ".", "Vector", ")", "{", "x", ",", "y", ":=", "validFaceXYZToUV", "(", "aFace", ",", "fe", ".", "edge", ".", "V0", ".", "Vector", ")", "\n", "fe", ".", "a", "=", "r2", ".", "Point", "{", "x", ",", "y", "}", "\n", "x", ",", "y", "=", "validFaceXYZToUV", "(", "aFace", ",", "fe", ".", "edge", ".", "V1", ".", "Vector", ")", "\n", "fe", ".", "b", "=", "r2", ".", "Point", "{", "x", ",", "y", "}", "\n\n", "maxUV", ":=", "1", "-", "cellPadding", "\n", "if", "math", ".", "Abs", "(", "fe", ".", "a", ".", "X", ")", "<=", "maxUV", "&&", "math", ".", "Abs", "(", "fe", ".", "a", ".", "Y", ")", "<=", "maxUV", "&&", "math", ".", "Abs", "(", "fe", ".", "b", ".", "X", ")", "<=", "maxUV", "&&", "math", ".", "Abs", "(", "fe", ".", "b", ".", "Y", ")", "<=", "maxUV", "{", "allEdges", "[", "aFace", "]", "=", "append", "(", "allEdges", "[", "aFace", "]", ",", "fe", ")", "\n", "return", "\n", "}", "\n", "}", "\n\n", "// Otherwise, we simply clip the edge to all six faces.", "for", "face", ":=", "0", ";", "face", "<", "6", ";", "face", "++", "{", "if", "aClip", ",", "bClip", ",", "intersects", ":=", "ClipToPaddedFace", "(", "fe", ".", "edge", ".", "V0", ",", "fe", ".", "edge", ".", "V1", ",", "face", ",", "cellPadding", ")", ";", "intersects", "{", "fe", ".", "a", "=", "aClip", "\n", "fe", ".", "b", "=", "bClip", "\n", "allEdges", "[", "face", "]", "=", "append", "(", "allEdges", "[", "face", "]", ",", "fe", ")", "\n", "}", "\n", "}", "\n", "return", "\n", "}" ]
// addFaceEdge adds the given faceEdge into the collection of all edges.
[ "addFaceEdge", "adds", "the", "given", "faceEdge", "into", "the", "collection", "of", "all", "edges", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/shapeindex.go#L871-L898
150,217
golang/geo
s2/shapeindex.go
shrinkToFit
func (s *ShapeIndex) shrinkToFit(pcell *PaddedCell, bound r2.Rect) CellID { shrunkID := pcell.ShrinkToFit(bound) if !s.isFirstUpdate() && shrunkID != pcell.CellID() { // Don't shrink any smaller than the existing index cells, since we need // to combine the new edges with those cells. iter := s.Iterator() if iter.LocateCellID(shrunkID) == Indexed { shrunkID = iter.CellID() } } return shrunkID }
go
func (s *ShapeIndex) shrinkToFit(pcell *PaddedCell, bound r2.Rect) CellID { shrunkID := pcell.ShrinkToFit(bound) if !s.isFirstUpdate() && shrunkID != pcell.CellID() { // Don't shrink any smaller than the existing index cells, since we need // to combine the new edges with those cells. iter := s.Iterator() if iter.LocateCellID(shrunkID) == Indexed { shrunkID = iter.CellID() } } return shrunkID }
[ "func", "(", "s", "*", "ShapeIndex", ")", "shrinkToFit", "(", "pcell", "*", "PaddedCell", ",", "bound", "r2", ".", "Rect", ")", "CellID", "{", "shrunkID", ":=", "pcell", ".", "ShrinkToFit", "(", "bound", ")", "\n\n", "if", "!", "s", ".", "isFirstUpdate", "(", ")", "&&", "shrunkID", "!=", "pcell", ".", "CellID", "(", ")", "{", "// Don't shrink any smaller than the existing index cells, since we need", "// to combine the new edges with those cells.", "iter", ":=", "s", ".", "Iterator", "(", ")", "\n", "if", "iter", ".", "LocateCellID", "(", "shrunkID", ")", "==", "Indexed", "{", "shrunkID", "=", "iter", ".", "CellID", "(", ")", "\n", "}", "\n", "}", "\n", "return", "shrunkID", "\n", "}" ]
// shrinkToFit shrinks the PaddedCell to fit within the given bounds.
[ "shrinkToFit", "shrinks", "the", "PaddedCell", "to", "fit", "within", "the", "given", "bounds", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/shapeindex.go#L950-L962
150,218
golang/geo
s2/shapeindex.go
skipCellRange
func (s *ShapeIndex) skipCellRange(begin, end CellID, t *tracker, disjointFromIndex bool) { // If we aren't in the interior of a shape, then skipping over cells is easy. if len(t.shapeIDs) == 0 { return } // Otherwise generate the list of cell ids that we need to visit, and create // an index entry for each one. skipped := CellUnionFromRange(begin, end) for _, cell := range skipped { var clippedEdges []*clippedEdge s.updateEdges(PaddedCellFromCellID(cell, cellPadding), clippedEdges, t, disjointFromIndex) } }
go
func (s *ShapeIndex) skipCellRange(begin, end CellID, t *tracker, disjointFromIndex bool) { // If we aren't in the interior of a shape, then skipping over cells is easy. if len(t.shapeIDs) == 0 { return } // Otherwise generate the list of cell ids that we need to visit, and create // an index entry for each one. skipped := CellUnionFromRange(begin, end) for _, cell := range skipped { var clippedEdges []*clippedEdge s.updateEdges(PaddedCellFromCellID(cell, cellPadding), clippedEdges, t, disjointFromIndex) } }
[ "func", "(", "s", "*", "ShapeIndex", ")", "skipCellRange", "(", "begin", ",", "end", "CellID", ",", "t", "*", "tracker", ",", "disjointFromIndex", "bool", ")", "{", "// If we aren't in the interior of a shape, then skipping over cells is easy.", "if", "len", "(", "t", ".", "shapeIDs", ")", "==", "0", "{", "return", "\n", "}", "\n\n", "// Otherwise generate the list of cell ids that we need to visit, and create", "// an index entry for each one.", "skipped", ":=", "CellUnionFromRange", "(", "begin", ",", "end", ")", "\n", "for", "_", ",", "cell", ":=", "range", "skipped", "{", "var", "clippedEdges", "[", "]", "*", "clippedEdge", "\n", "s", ".", "updateEdges", "(", "PaddedCellFromCellID", "(", "cell", ",", "cellPadding", ")", ",", "clippedEdges", ",", "t", ",", "disjointFromIndex", ")", "\n", "}", "\n", "}" ]
// skipCellRange skips over the cells in the given range, creating index cells if we are // currently in the interior of at least one shape.
[ "skipCellRange", "skips", "over", "the", "cells", "in", "the", "given", "range", "creating", "index", "cells", "if", "we", "are", "currently", "in", "the", "interior", "of", "at", "least", "one", "shape", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/shapeindex.go#L966-L979
150,219
golang/geo
s2/shapeindex.go
makeIndexCell
func (s *ShapeIndex) makeIndexCell(p *PaddedCell, edges []*clippedEdge, t *tracker) bool { // If the cell is empty, no index cell is needed. (In most cases this // situation is detected before we get to this point, but this can happen // when all shapes in a cell are removed.) if len(edges) == 0 && len(t.shapeIDs) == 0 { return true } // Count the number of edges that have not reached their maximum level yet. // Return false if there are too many such edges. count := 0 for _, ce := range edges { if p.Level() < ce.faceEdge.maxLevel { count++ } if count > s.maxEdgesPerCell { return false } } // Possible optimization: Continue subdividing as long as exactly one child // of the padded cell intersects the given edges. This can be done by finding // the bounding box of all the edges and calling ShrinkToFit: // // cellID = p.ShrinkToFit(RectBound(edges)); // // Currently this is not beneficial; it slows down construction by 4-25% // (mainly computing the union of the bounding rectangles) and also slows // down queries (since more recursive clipping is required to get down to // the level of a spatial index cell). But it may be worth trying again // once containsCenter is computed and all algorithms are modified to // take advantage of it. // We update the InteriorTracker as follows. For every Cell in the index // we construct two edges: one edge from entry vertex of the cell to its // center, and one from the cell center to its exit vertex. Here entry // and exit refer the CellID ordering, i.e. the order in which points // are encountered along the 2 space-filling curve. The exit vertex then // becomes the entry vertex for the next cell in the index, unless there are // one or more empty intervening cells, in which case the InteriorTracker // state is unchanged because the intervening cells have no edges. // Shift the InteriorTracker focus point to the center of the current cell. if t.isActive && len(edges) != 0 { if !t.atCellID(p.id) { t.moveTo(p.EntryVertex()) } t.drawTo(p.Center()) s.testAllEdges(edges, t) } // Allocate and fill a new index cell. To get the total number of shapes we // need to merge the shapes associated with the intersecting edges together // with the shapes that happen to contain the cell center. cshapeIDs := t.shapeIDs numShapes := s.countShapes(edges, cshapeIDs) cell := NewShapeIndexCell(numShapes) // To fill the index cell we merge the two sources of shapes: edge shapes // (those that have at least one edge that intersects this cell), and // containing shapes (those that contain the cell center). We keep track // of the index of the next intersecting edge and the next containing shape // as we go along. Both sets of shape ids are already sorted. eNext := 0 cNextIdx := 0 for i := 0; i < numShapes; i++ { var clipped *clippedShape // advance to next value base + i eshapeID := int32(s.Len()) cshapeID := int32(eshapeID) // Sentinels if eNext != len(edges) { eshapeID = edges[eNext].faceEdge.shapeID } if cNextIdx < len(cshapeIDs) { cshapeID = cshapeIDs[cNextIdx] } eBegin := eNext if cshapeID < eshapeID { // The entire cell is in the shape interior. clipped = newClippedShape(cshapeID, 0) clipped.containsCenter = true cNextIdx++ } else { // Count the number of edges for this shape and allocate space for them. for eNext < len(edges) && edges[eNext].faceEdge.shapeID == eshapeID { eNext++ } clipped = newClippedShape(eshapeID, eNext-eBegin) for e := eBegin; e < eNext; e++ { clipped.edges[e-eBegin] = edges[e].faceEdge.edgeID } if cshapeID == eshapeID { clipped.containsCenter = true cNextIdx++ } } cell.shapes[i] = clipped } // Add this cell to the map. s.cellMap[p.id] = cell s.cells = append(s.cells, p.id) // Shift the tracker focus point to the exit vertex of this cell. if t.isActive && len(edges) != 0 { t.drawTo(p.ExitVertex()) s.testAllEdges(edges, t) t.setNextCellID(p.id.Next()) } return true }
go
func (s *ShapeIndex) makeIndexCell(p *PaddedCell, edges []*clippedEdge, t *tracker) bool { // If the cell is empty, no index cell is needed. (In most cases this // situation is detected before we get to this point, but this can happen // when all shapes in a cell are removed.) if len(edges) == 0 && len(t.shapeIDs) == 0 { return true } // Count the number of edges that have not reached their maximum level yet. // Return false if there are too many such edges. count := 0 for _, ce := range edges { if p.Level() < ce.faceEdge.maxLevel { count++ } if count > s.maxEdgesPerCell { return false } } // Possible optimization: Continue subdividing as long as exactly one child // of the padded cell intersects the given edges. This can be done by finding // the bounding box of all the edges and calling ShrinkToFit: // // cellID = p.ShrinkToFit(RectBound(edges)); // // Currently this is not beneficial; it slows down construction by 4-25% // (mainly computing the union of the bounding rectangles) and also slows // down queries (since more recursive clipping is required to get down to // the level of a spatial index cell). But it may be worth trying again // once containsCenter is computed and all algorithms are modified to // take advantage of it. // We update the InteriorTracker as follows. For every Cell in the index // we construct two edges: one edge from entry vertex of the cell to its // center, and one from the cell center to its exit vertex. Here entry // and exit refer the CellID ordering, i.e. the order in which points // are encountered along the 2 space-filling curve. The exit vertex then // becomes the entry vertex for the next cell in the index, unless there are // one or more empty intervening cells, in which case the InteriorTracker // state is unchanged because the intervening cells have no edges. // Shift the InteriorTracker focus point to the center of the current cell. if t.isActive && len(edges) != 0 { if !t.atCellID(p.id) { t.moveTo(p.EntryVertex()) } t.drawTo(p.Center()) s.testAllEdges(edges, t) } // Allocate and fill a new index cell. To get the total number of shapes we // need to merge the shapes associated with the intersecting edges together // with the shapes that happen to contain the cell center. cshapeIDs := t.shapeIDs numShapes := s.countShapes(edges, cshapeIDs) cell := NewShapeIndexCell(numShapes) // To fill the index cell we merge the two sources of shapes: edge shapes // (those that have at least one edge that intersects this cell), and // containing shapes (those that contain the cell center). We keep track // of the index of the next intersecting edge and the next containing shape // as we go along. Both sets of shape ids are already sorted. eNext := 0 cNextIdx := 0 for i := 0; i < numShapes; i++ { var clipped *clippedShape // advance to next value base + i eshapeID := int32(s.Len()) cshapeID := int32(eshapeID) // Sentinels if eNext != len(edges) { eshapeID = edges[eNext].faceEdge.shapeID } if cNextIdx < len(cshapeIDs) { cshapeID = cshapeIDs[cNextIdx] } eBegin := eNext if cshapeID < eshapeID { // The entire cell is in the shape interior. clipped = newClippedShape(cshapeID, 0) clipped.containsCenter = true cNextIdx++ } else { // Count the number of edges for this shape and allocate space for them. for eNext < len(edges) && edges[eNext].faceEdge.shapeID == eshapeID { eNext++ } clipped = newClippedShape(eshapeID, eNext-eBegin) for e := eBegin; e < eNext; e++ { clipped.edges[e-eBegin] = edges[e].faceEdge.edgeID } if cshapeID == eshapeID { clipped.containsCenter = true cNextIdx++ } } cell.shapes[i] = clipped } // Add this cell to the map. s.cellMap[p.id] = cell s.cells = append(s.cells, p.id) // Shift the tracker focus point to the exit vertex of this cell. if t.isActive && len(edges) != 0 { t.drawTo(p.ExitVertex()) s.testAllEdges(edges, t) t.setNextCellID(p.id.Next()) } return true }
[ "func", "(", "s", "*", "ShapeIndex", ")", "makeIndexCell", "(", "p", "*", "PaddedCell", ",", "edges", "[", "]", "*", "clippedEdge", ",", "t", "*", "tracker", ")", "bool", "{", "// If the cell is empty, no index cell is needed. (In most cases this", "// situation is detected before we get to this point, but this can happen", "// when all shapes in a cell are removed.)", "if", "len", "(", "edges", ")", "==", "0", "&&", "len", "(", "t", ".", "shapeIDs", ")", "==", "0", "{", "return", "true", "\n", "}", "\n\n", "// Count the number of edges that have not reached their maximum level yet.", "// Return false if there are too many such edges.", "count", ":=", "0", "\n", "for", "_", ",", "ce", ":=", "range", "edges", "{", "if", "p", ".", "Level", "(", ")", "<", "ce", ".", "faceEdge", ".", "maxLevel", "{", "count", "++", "\n", "}", "\n\n", "if", "count", ">", "s", ".", "maxEdgesPerCell", "{", "return", "false", "\n", "}", "\n", "}", "\n\n", "// Possible optimization: Continue subdividing as long as exactly one child", "// of the padded cell intersects the given edges. This can be done by finding", "// the bounding box of all the edges and calling ShrinkToFit:", "//", "// cellID = p.ShrinkToFit(RectBound(edges));", "//", "// Currently this is not beneficial; it slows down construction by 4-25%", "// (mainly computing the union of the bounding rectangles) and also slows", "// down queries (since more recursive clipping is required to get down to", "// the level of a spatial index cell). But it may be worth trying again", "// once containsCenter is computed and all algorithms are modified to", "// take advantage of it.", "// We update the InteriorTracker as follows. For every Cell in the index", "// we construct two edges: one edge from entry vertex of the cell to its", "// center, and one from the cell center to its exit vertex. Here entry", "// and exit refer the CellID ordering, i.e. the order in which points", "// are encountered along the 2 space-filling curve. The exit vertex then", "// becomes the entry vertex for the next cell in the index, unless there are", "// one or more empty intervening cells, in which case the InteriorTracker", "// state is unchanged because the intervening cells have no edges.", "// Shift the InteriorTracker focus point to the center of the current cell.", "if", "t", ".", "isActive", "&&", "len", "(", "edges", ")", "!=", "0", "{", "if", "!", "t", ".", "atCellID", "(", "p", ".", "id", ")", "{", "t", ".", "moveTo", "(", "p", ".", "EntryVertex", "(", ")", ")", "\n", "}", "\n", "t", ".", "drawTo", "(", "p", ".", "Center", "(", ")", ")", "\n", "s", ".", "testAllEdges", "(", "edges", ",", "t", ")", "\n", "}", "\n\n", "// Allocate and fill a new index cell. To get the total number of shapes we", "// need to merge the shapes associated with the intersecting edges together", "// with the shapes that happen to contain the cell center.", "cshapeIDs", ":=", "t", ".", "shapeIDs", "\n", "numShapes", ":=", "s", ".", "countShapes", "(", "edges", ",", "cshapeIDs", ")", "\n", "cell", ":=", "NewShapeIndexCell", "(", "numShapes", ")", "\n\n", "// To fill the index cell we merge the two sources of shapes: edge shapes", "// (those that have at least one edge that intersects this cell), and", "// containing shapes (those that contain the cell center). We keep track", "// of the index of the next intersecting edge and the next containing shape", "// as we go along. Both sets of shape ids are already sorted.", "eNext", ":=", "0", "\n", "cNextIdx", ":=", "0", "\n", "for", "i", ":=", "0", ";", "i", "<", "numShapes", ";", "i", "++", "{", "var", "clipped", "*", "clippedShape", "\n", "// advance to next value base + i", "eshapeID", ":=", "int32", "(", "s", ".", "Len", "(", ")", ")", "\n", "cshapeID", ":=", "int32", "(", "eshapeID", ")", "// Sentinels", "\n\n", "if", "eNext", "!=", "len", "(", "edges", ")", "{", "eshapeID", "=", "edges", "[", "eNext", "]", ".", "faceEdge", ".", "shapeID", "\n", "}", "\n", "if", "cNextIdx", "<", "len", "(", "cshapeIDs", ")", "{", "cshapeID", "=", "cshapeIDs", "[", "cNextIdx", "]", "\n", "}", "\n", "eBegin", ":=", "eNext", "\n", "if", "cshapeID", "<", "eshapeID", "{", "// The entire cell is in the shape interior.", "clipped", "=", "newClippedShape", "(", "cshapeID", ",", "0", ")", "\n", "clipped", ".", "containsCenter", "=", "true", "\n", "cNextIdx", "++", "\n", "}", "else", "{", "// Count the number of edges for this shape and allocate space for them.", "for", "eNext", "<", "len", "(", "edges", ")", "&&", "edges", "[", "eNext", "]", ".", "faceEdge", ".", "shapeID", "==", "eshapeID", "{", "eNext", "++", "\n", "}", "\n", "clipped", "=", "newClippedShape", "(", "eshapeID", ",", "eNext", "-", "eBegin", ")", "\n", "for", "e", ":=", "eBegin", ";", "e", "<", "eNext", ";", "e", "++", "{", "clipped", ".", "edges", "[", "e", "-", "eBegin", "]", "=", "edges", "[", "e", "]", ".", "faceEdge", ".", "edgeID", "\n", "}", "\n", "if", "cshapeID", "==", "eshapeID", "{", "clipped", ".", "containsCenter", "=", "true", "\n", "cNextIdx", "++", "\n", "}", "\n", "}", "\n", "cell", ".", "shapes", "[", "i", "]", "=", "clipped", "\n", "}", "\n\n", "// Add this cell to the map.", "s", ".", "cellMap", "[", "p", ".", "id", "]", "=", "cell", "\n", "s", ".", "cells", "=", "append", "(", "s", ".", "cells", ",", "p", ".", "id", ")", "\n\n", "// Shift the tracker focus point to the exit vertex of this cell.", "if", "t", ".", "isActive", "&&", "len", "(", "edges", ")", "!=", "0", "{", "t", ".", "drawTo", "(", "p", ".", "ExitVertex", "(", ")", ")", "\n", "s", ".", "testAllEdges", "(", "edges", ",", "t", ")", "\n", "t", ".", "setNextCellID", "(", "p", ".", "id", ".", "Next", "(", ")", ")", "\n", "}", "\n", "return", "true", "\n", "}" ]
// makeIndexCell builds an indexCell from the given padded cell and set of edges and adds // it to the index. If the cell or edges are empty, no cell is added.
[ "makeIndexCell", "builds", "an", "indexCell", "from", "the", "given", "padded", "cell", "and", "set", "of", "edges", "and", "adds", "it", "to", "the", "index", ".", "If", "the", "cell", "or", "edges", "are", "empty", "no", "cell", "is", "added", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/shapeindex.go#L1121-L1233
150,220
golang/geo
s2/shapeindex.go
updateBound
func (s *ShapeIndex) updateBound(edge *clippedEdge, uEnd int, u float64, vEnd int, v float64) *clippedEdge { c := &clippedEdge{faceEdge: edge.faceEdge} if uEnd == 0 { c.bound.X.Lo = u c.bound.X.Hi = edge.bound.X.Hi } else { c.bound.X.Lo = edge.bound.X.Lo c.bound.X.Hi = u } if vEnd == 0 { c.bound.Y.Lo = v c.bound.Y.Hi = edge.bound.Y.Hi } else { c.bound.Y.Lo = edge.bound.Y.Lo c.bound.Y.Hi = v } return c }
go
func (s *ShapeIndex) updateBound(edge *clippedEdge, uEnd int, u float64, vEnd int, v float64) *clippedEdge { c := &clippedEdge{faceEdge: edge.faceEdge} if uEnd == 0 { c.bound.X.Lo = u c.bound.X.Hi = edge.bound.X.Hi } else { c.bound.X.Lo = edge.bound.X.Lo c.bound.X.Hi = u } if vEnd == 0 { c.bound.Y.Lo = v c.bound.Y.Hi = edge.bound.Y.Hi } else { c.bound.Y.Lo = edge.bound.Y.Lo c.bound.Y.Hi = v } return c }
[ "func", "(", "s", "*", "ShapeIndex", ")", "updateBound", "(", "edge", "*", "clippedEdge", ",", "uEnd", "int", ",", "u", "float64", ",", "vEnd", "int", ",", "v", "float64", ")", "*", "clippedEdge", "{", "c", ":=", "&", "clippedEdge", "{", "faceEdge", ":", "edge", ".", "faceEdge", "}", "\n", "if", "uEnd", "==", "0", "{", "c", ".", "bound", ".", "X", ".", "Lo", "=", "u", "\n", "c", ".", "bound", ".", "X", ".", "Hi", "=", "edge", ".", "bound", ".", "X", ".", "Hi", "\n", "}", "else", "{", "c", ".", "bound", ".", "X", ".", "Lo", "=", "edge", ".", "bound", ".", "X", ".", "Lo", "\n", "c", ".", "bound", ".", "X", ".", "Hi", "=", "u", "\n", "}", "\n\n", "if", "vEnd", "==", "0", "{", "c", ".", "bound", ".", "Y", ".", "Lo", "=", "v", "\n", "c", ".", "bound", ".", "Y", ".", "Hi", "=", "edge", ".", "bound", ".", "Y", ".", "Hi", "\n", "}", "else", "{", "c", ".", "bound", ".", "Y", ".", "Lo", "=", "edge", ".", "bound", ".", "Y", ".", "Lo", "\n", "c", ".", "bound", ".", "Y", ".", "Hi", "=", "v", "\n", "}", "\n\n", "return", "c", "\n", "}" ]
// updateBound updates the specified endpoint of the given clipped edge and returns the // resulting clipped edge.
[ "updateBound", "updates", "the", "specified", "endpoint", "of", "the", "given", "clipped", "edge", "and", "returns", "the", "resulting", "clipped", "edge", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/shapeindex.go#L1237-L1256
150,221
golang/geo
s2/shapeindex.go
clipVAxis
func (s *ShapeIndex) clipVAxis(edge *clippedEdge, middle r1.Interval) (a, b *clippedEdge) { if edge.bound.Y.Hi <= middle.Lo { // Edge is entirely contained in the lower child. return edge, nil } else if edge.bound.Y.Lo >= middle.Hi { // Edge is entirely contained in the upper child. return nil, edge } // The edge bound spans both children. return s.clipVBound(edge, 1, middle.Hi), s.clipVBound(edge, 0, middle.Lo) }
go
func (s *ShapeIndex) clipVAxis(edge *clippedEdge, middle r1.Interval) (a, b *clippedEdge) { if edge.bound.Y.Hi <= middle.Lo { // Edge is entirely contained in the lower child. return edge, nil } else if edge.bound.Y.Lo >= middle.Hi { // Edge is entirely contained in the upper child. return nil, edge } // The edge bound spans both children. return s.clipVBound(edge, 1, middle.Hi), s.clipVBound(edge, 0, middle.Lo) }
[ "func", "(", "s", "*", "ShapeIndex", ")", "clipVAxis", "(", "edge", "*", "clippedEdge", ",", "middle", "r1", ".", "Interval", ")", "(", "a", ",", "b", "*", "clippedEdge", ")", "{", "if", "edge", ".", "bound", ".", "Y", ".", "Hi", "<=", "middle", ".", "Lo", "{", "// Edge is entirely contained in the lower child.", "return", "edge", ",", "nil", "\n", "}", "else", "if", "edge", ".", "bound", ".", "Y", ".", "Lo", ">=", "middle", ".", "Hi", "{", "// Edge is entirely contained in the upper child.", "return", "nil", ",", "edge", "\n", "}", "\n", "// The edge bound spans both children.", "return", "s", ".", "clipVBound", "(", "edge", ",", "1", ",", "middle", ".", "Hi", ")", ",", "s", ".", "clipVBound", "(", "edge", ",", "0", ",", "middle", ".", "Lo", ")", "\n", "}" ]
// cliupVAxis returns the given edge clipped to within the boundaries of the middle // interval along the v-axis, and adds the result to its children.
[ "cliupVAxis", "returns", "the", "given", "edge", "clipped", "to", "within", "the", "boundaries", "of", "the", "middle", "interval", "along", "the", "v", "-", "axis", "and", "adds", "the", "result", "to", "its", "children", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/shapeindex.go#L1326-L1336
150,222
golang/geo
s2/shapeindex.go
countShapes
func (s *ShapeIndex) countShapes(edges []*clippedEdge, shapeIDs []int32) int { count := 0 lastShapeID := int32(-1) // next clipped shape id in the shapeIDs list. clippedNext := int32(0) // index of the current element in the shapeIDs list. shapeIDidx := 0 for _, edge := range edges { if edge.faceEdge.shapeID == lastShapeID { continue } count++ lastShapeID = edge.faceEdge.shapeID // Skip over any containing shapes up to and including this one, // updating count as appropriate. for ; shapeIDidx < len(shapeIDs); shapeIDidx++ { clippedNext = shapeIDs[shapeIDidx] if clippedNext > lastShapeID { break } if clippedNext < lastShapeID { count++ } } } // Count any remaining containing shapes. count += int(len(shapeIDs)) - int(shapeIDidx) return count }
go
func (s *ShapeIndex) countShapes(edges []*clippedEdge, shapeIDs []int32) int { count := 0 lastShapeID := int32(-1) // next clipped shape id in the shapeIDs list. clippedNext := int32(0) // index of the current element in the shapeIDs list. shapeIDidx := 0 for _, edge := range edges { if edge.faceEdge.shapeID == lastShapeID { continue } count++ lastShapeID = edge.faceEdge.shapeID // Skip over any containing shapes up to and including this one, // updating count as appropriate. for ; shapeIDidx < len(shapeIDs); shapeIDidx++ { clippedNext = shapeIDs[shapeIDidx] if clippedNext > lastShapeID { break } if clippedNext < lastShapeID { count++ } } } // Count any remaining containing shapes. count += int(len(shapeIDs)) - int(shapeIDidx) return count }
[ "func", "(", "s", "*", "ShapeIndex", ")", "countShapes", "(", "edges", "[", "]", "*", "clippedEdge", ",", "shapeIDs", "[", "]", "int32", ")", "int", "{", "count", ":=", "0", "\n", "lastShapeID", ":=", "int32", "(", "-", "1", ")", "\n\n", "// next clipped shape id in the shapeIDs list.", "clippedNext", ":=", "int32", "(", "0", ")", "\n", "// index of the current element in the shapeIDs list.", "shapeIDidx", ":=", "0", "\n", "for", "_", ",", "edge", ":=", "range", "edges", "{", "if", "edge", ".", "faceEdge", ".", "shapeID", "==", "lastShapeID", "{", "continue", "\n", "}", "\n\n", "count", "++", "\n", "lastShapeID", "=", "edge", ".", "faceEdge", ".", "shapeID", "\n\n", "// Skip over any containing shapes up to and including this one,", "// updating count as appropriate.", "for", ";", "shapeIDidx", "<", "len", "(", "shapeIDs", ")", ";", "shapeIDidx", "++", "{", "clippedNext", "=", "shapeIDs", "[", "shapeIDidx", "]", "\n", "if", "clippedNext", ">", "lastShapeID", "{", "break", "\n", "}", "\n", "if", "clippedNext", "<", "lastShapeID", "{", "count", "++", "\n", "}", "\n", "}", "\n", "}", "\n\n", "// Count any remaining containing shapes.", "count", "+=", "int", "(", "len", "(", "shapeIDs", ")", ")", "-", "int", "(", "shapeIDidx", ")", "\n", "return", "count", "\n", "}" ]
// countShapes reports the number of distinct shapes that are either associated with the // given edges, or that are currently stored in the InteriorTracker.
[ "countShapes", "reports", "the", "number", "of", "distinct", "shapes", "that", "are", "either", "associated", "with", "the", "given", "edges", "or", "that", "are", "currently", "stored", "in", "the", "InteriorTracker", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/shapeindex.go#L1468-L1500
150,223
golang/geo
s2/shapeindex.go
maxLevelForEdge
func maxLevelForEdge(edge Edge) int { // Compute the maximum cell size for which this edge is considered long. // The calculation does not need to be perfectly accurate, so we use Norm // rather than Angle for speed. cellSize := edge.V0.Sub(edge.V1.Vector).Norm() * cellSizeToLongEdgeRatio // Now return the first level encountered during subdivision where the // average cell size is at most cellSize. return AvgEdgeMetric.MinLevel(cellSize) }
go
func maxLevelForEdge(edge Edge) int { // Compute the maximum cell size for which this edge is considered long. // The calculation does not need to be perfectly accurate, so we use Norm // rather than Angle for speed. cellSize := edge.V0.Sub(edge.V1.Vector).Norm() * cellSizeToLongEdgeRatio // Now return the first level encountered during subdivision where the // average cell size is at most cellSize. return AvgEdgeMetric.MinLevel(cellSize) }
[ "func", "maxLevelForEdge", "(", "edge", "Edge", ")", "int", "{", "// Compute the maximum cell size for which this edge is considered long.", "// The calculation does not need to be perfectly accurate, so we use Norm", "// rather than Angle for speed.", "cellSize", ":=", "edge", ".", "V0", ".", "Sub", "(", "edge", ".", "V1", ".", "Vector", ")", ".", "Norm", "(", ")", "*", "cellSizeToLongEdgeRatio", "\n", "// Now return the first level encountered during subdivision where the", "// average cell size is at most cellSize.", "return", "AvgEdgeMetric", ".", "MinLevel", "(", "cellSize", ")", "\n", "}" ]
// maxLevelForEdge reports the maximum level for a given edge.
[ "maxLevelForEdge", "reports", "the", "maximum", "level", "for", "a", "given", "edge", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/shapeindex.go#L1503-L1511
150,224
golang/geo
s2/edge_crosser.go
NewEdgeCrosser
func NewEdgeCrosser(a, b Point) *EdgeCrosser { norm := a.PointCross(b) return &EdgeCrosser{ a: a, b: b, aXb: Point{a.Cross(b.Vector)}, aTangent: Point{a.Cross(norm.Vector)}, bTangent: Point{norm.Cross(b.Vector)}, } }
go
func NewEdgeCrosser(a, b Point) *EdgeCrosser { norm := a.PointCross(b) return &EdgeCrosser{ a: a, b: b, aXb: Point{a.Cross(b.Vector)}, aTangent: Point{a.Cross(norm.Vector)}, bTangent: Point{norm.Cross(b.Vector)}, } }
[ "func", "NewEdgeCrosser", "(", "a", ",", "b", "Point", ")", "*", "EdgeCrosser", "{", "norm", ":=", "a", ".", "PointCross", "(", "b", ")", "\n", "return", "&", "EdgeCrosser", "{", "a", ":", "a", ",", "b", ":", "b", ",", "aXb", ":", "Point", "{", "a", ".", "Cross", "(", "b", ".", "Vector", ")", "}", ",", "aTangent", ":", "Point", "{", "a", ".", "Cross", "(", "norm", ".", "Vector", ")", "}", ",", "bTangent", ":", "Point", "{", "norm", ".", "Cross", "(", "b", ".", "Vector", ")", "}", ",", "}", "\n", "}" ]
// NewEdgeCrosser returns an EdgeCrosser with the fixed edge AB.
[ "NewEdgeCrosser", "returns", "an", "EdgeCrosser", "with", "the", "fixed", "edge", "AB", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/edge_crosser.go#L56-L65
150,225
golang/geo
s2/edge_crosser.go
RestartAt
func (e *EdgeCrosser) RestartAt(c Point) { e.c = c e.acb = -triageSign(e.a, e.b, e.c) }
go
func (e *EdgeCrosser) RestartAt(c Point) { e.c = c e.acb = -triageSign(e.a, e.b, e.c) }
[ "func", "(", "e", "*", "EdgeCrosser", ")", "RestartAt", "(", "c", "Point", ")", "{", "e", ".", "c", "=", "c", "\n", "e", ".", "acb", "=", "-", "triageSign", "(", "e", ".", "a", ",", "e", ".", "b", ",", "e", ".", "c", ")", "\n", "}" ]
// RestartAt sets the current point of the edge crosser to be c. // Call this method when your chain 'jumps' to a new place. // The argument must point to a value that persists until the next call.
[ "RestartAt", "sets", "the", "current", "point", "of", "the", "edge", "crosser", "to", "be", "c", ".", "Call", "this", "method", "when", "your", "chain", "jumps", "to", "a", "new", "place", ".", "The", "argument", "must", "point", "to", "a", "value", "that", "persists", "until", "the", "next", "call", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/edge_crosser.go#L120-L123
150,226
golang/geo
s2/edge_crosser.go
crossingSign
func (e *EdgeCrosser) crossingSign(d Point, bda Direction) Crossing { // Compute the actual result, and then save the current vertex D as the next // vertex C, and save the orientation of the next triangle ACB (which is // opposite to the current triangle BDA). defer func() { e.c = d e.acb = -bda }() // At this point, a very common situation is that A,B,C,D are four points on // a line such that AB does not overlap CD. (For example, this happens when // a line or curve is sampled finely, or when geometry is constructed by // computing the union of S2CellIds.) Most of the time, we can determine // that AB and CD do not intersect using the two outward-facing // tangents at A and B (parallel to AB) and testing whether AB and CD are on // opposite sides of the plane perpendicular to one of these tangents. This // is moderately expensive but still much cheaper than expensiveSign. // The error in RobustCrossProd is insignificant. The maximum error in // the call to CrossProd (i.e., the maximum norm of the error vector) is // (0.5 + 1/sqrt(3)) * dblEpsilon. The maximum error in each call to // DotProd below is dblEpsilon. (There is also a small relative error // term that is insignificant because we are comparing the result against a // constant that is very close to zero.) maxError := (1.5 + 1/math.Sqrt(3)) * dblEpsilon if (e.c.Dot(e.aTangent.Vector) > maxError && d.Dot(e.aTangent.Vector) > maxError) || (e.c.Dot(e.bTangent.Vector) > maxError && d.Dot(e.bTangent.Vector) > maxError) { return DoNotCross } // Otherwise, eliminate the cases where two vertices from different edges are // equal. (These cases could be handled in the code below, but we would rather // avoid calling ExpensiveSign if possible.) if e.a == e.c || e.a == d || e.b == e.c || e.b == d { return MaybeCross } // Eliminate the cases where an input edge is degenerate. (Note that in // most cases, if CD is degenerate then this method is not even called // because acb and bda have different signs.) if e.a == e.b || e.c == d { return DoNotCross } // Otherwise it's time to break out the big guns. if e.acb == Indeterminate { e.acb = -expensiveSign(e.a, e.b, e.c) } if bda == Indeterminate { bda = expensiveSign(e.a, e.b, d) } if bda != e.acb { return DoNotCross } cbd := -RobustSign(e.c, d, e.b) if cbd != e.acb { return DoNotCross } dac := RobustSign(e.c, d, e.a) if dac != e.acb { return DoNotCross } return Cross }
go
func (e *EdgeCrosser) crossingSign(d Point, bda Direction) Crossing { // Compute the actual result, and then save the current vertex D as the next // vertex C, and save the orientation of the next triangle ACB (which is // opposite to the current triangle BDA). defer func() { e.c = d e.acb = -bda }() // At this point, a very common situation is that A,B,C,D are four points on // a line such that AB does not overlap CD. (For example, this happens when // a line or curve is sampled finely, or when geometry is constructed by // computing the union of S2CellIds.) Most of the time, we can determine // that AB and CD do not intersect using the two outward-facing // tangents at A and B (parallel to AB) and testing whether AB and CD are on // opposite sides of the plane perpendicular to one of these tangents. This // is moderately expensive but still much cheaper than expensiveSign. // The error in RobustCrossProd is insignificant. The maximum error in // the call to CrossProd (i.e., the maximum norm of the error vector) is // (0.5 + 1/sqrt(3)) * dblEpsilon. The maximum error in each call to // DotProd below is dblEpsilon. (There is also a small relative error // term that is insignificant because we are comparing the result against a // constant that is very close to zero.) maxError := (1.5 + 1/math.Sqrt(3)) * dblEpsilon if (e.c.Dot(e.aTangent.Vector) > maxError && d.Dot(e.aTangent.Vector) > maxError) || (e.c.Dot(e.bTangent.Vector) > maxError && d.Dot(e.bTangent.Vector) > maxError) { return DoNotCross } // Otherwise, eliminate the cases where two vertices from different edges are // equal. (These cases could be handled in the code below, but we would rather // avoid calling ExpensiveSign if possible.) if e.a == e.c || e.a == d || e.b == e.c || e.b == d { return MaybeCross } // Eliminate the cases where an input edge is degenerate. (Note that in // most cases, if CD is degenerate then this method is not even called // because acb and bda have different signs.) if e.a == e.b || e.c == d { return DoNotCross } // Otherwise it's time to break out the big guns. if e.acb == Indeterminate { e.acb = -expensiveSign(e.a, e.b, e.c) } if bda == Indeterminate { bda = expensiveSign(e.a, e.b, d) } if bda != e.acb { return DoNotCross } cbd := -RobustSign(e.c, d, e.b) if cbd != e.acb { return DoNotCross } dac := RobustSign(e.c, d, e.a) if dac != e.acb { return DoNotCross } return Cross }
[ "func", "(", "e", "*", "EdgeCrosser", ")", "crossingSign", "(", "d", "Point", ",", "bda", "Direction", ")", "Crossing", "{", "// Compute the actual result, and then save the current vertex D as the next", "// vertex C, and save the orientation of the next triangle ACB (which is", "// opposite to the current triangle BDA).", "defer", "func", "(", ")", "{", "e", ".", "c", "=", "d", "\n", "e", ".", "acb", "=", "-", "bda", "\n", "}", "(", ")", "\n\n", "// At this point, a very common situation is that A,B,C,D are four points on", "// a line such that AB does not overlap CD. (For example, this happens when", "// a line or curve is sampled finely, or when geometry is constructed by", "// computing the union of S2CellIds.) Most of the time, we can determine", "// that AB and CD do not intersect using the two outward-facing", "// tangents at A and B (parallel to AB) and testing whether AB and CD are on", "// opposite sides of the plane perpendicular to one of these tangents. This", "// is moderately expensive but still much cheaper than expensiveSign.", "// The error in RobustCrossProd is insignificant. The maximum error in", "// the call to CrossProd (i.e., the maximum norm of the error vector) is", "// (0.5 + 1/sqrt(3)) * dblEpsilon. The maximum error in each call to", "// DotProd below is dblEpsilon. (There is also a small relative error", "// term that is insignificant because we are comparing the result against a", "// constant that is very close to zero.)", "maxError", ":=", "(", "1.5", "+", "1", "/", "math", ".", "Sqrt", "(", "3", ")", ")", "*", "dblEpsilon", "\n", "if", "(", "e", ".", "c", ".", "Dot", "(", "e", ".", "aTangent", ".", "Vector", ")", ">", "maxError", "&&", "d", ".", "Dot", "(", "e", ".", "aTangent", ".", "Vector", ")", ">", "maxError", ")", "||", "(", "e", ".", "c", ".", "Dot", "(", "e", ".", "bTangent", ".", "Vector", ")", ">", "maxError", "&&", "d", ".", "Dot", "(", "e", ".", "bTangent", ".", "Vector", ")", ">", "maxError", ")", "{", "return", "DoNotCross", "\n", "}", "\n\n", "// Otherwise, eliminate the cases where two vertices from different edges are", "// equal. (These cases could be handled in the code below, but we would rather", "// avoid calling ExpensiveSign if possible.)", "if", "e", ".", "a", "==", "e", ".", "c", "||", "e", ".", "a", "==", "d", "||", "e", ".", "b", "==", "e", ".", "c", "||", "e", ".", "b", "==", "d", "{", "return", "MaybeCross", "\n", "}", "\n\n", "// Eliminate the cases where an input edge is degenerate. (Note that in", "// most cases, if CD is degenerate then this method is not even called", "// because acb and bda have different signs.)", "if", "e", ".", "a", "==", "e", ".", "b", "||", "e", ".", "c", "==", "d", "{", "return", "DoNotCross", "\n", "}", "\n\n", "// Otherwise it's time to break out the big guns.", "if", "e", ".", "acb", "==", "Indeterminate", "{", "e", ".", "acb", "=", "-", "expensiveSign", "(", "e", ".", "a", ",", "e", ".", "b", ",", "e", ".", "c", ")", "\n", "}", "\n", "if", "bda", "==", "Indeterminate", "{", "bda", "=", "expensiveSign", "(", "e", ".", "a", ",", "e", ".", "b", ",", "d", ")", "\n", "}", "\n\n", "if", "bda", "!=", "e", ".", "acb", "{", "return", "DoNotCross", "\n", "}", "\n\n", "cbd", ":=", "-", "RobustSign", "(", "e", ".", "c", ",", "d", ",", "e", ".", "b", ")", "\n", "if", "cbd", "!=", "e", ".", "acb", "{", "return", "DoNotCross", "\n", "}", "\n", "dac", ":=", "RobustSign", "(", "e", ".", "c", ",", "d", ",", "e", ".", "a", ")", "\n", "if", "dac", "!=", "e", ".", "acb", "{", "return", "DoNotCross", "\n", "}", "\n", "return", "Cross", "\n", "}" ]
// crossingSign handle the slow path of CrossingSign.
[ "crossingSign", "handle", "the", "slow", "path", "of", "CrossingSign", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/edge_crosser.go#L163-L227
150,227
golang/geo
s2/interleave.go
deinterleaveUint32
func deinterleaveUint32(code uint64) (uint32, uint32) { x := (deinterleaveLookup[code&0x55]) | (deinterleaveLookup[(code>>8)&0x55] << 4) | (deinterleaveLookup[(code>>16)&0x55] << 8) | (deinterleaveLookup[(code>>24)&0x55] << 12) | (deinterleaveLookup[(code>>32)&0x55] << 16) | (deinterleaveLookup[(code>>40)&0x55] << 20) | (deinterleaveLookup[(code>>48)&0x55] << 24) | (deinterleaveLookup[(code>>56)&0x55] << 28) y := (deinterleaveLookup[code&0xaa]) | (deinterleaveLookup[(code>>8)&0xaa] << 4) | (deinterleaveLookup[(code>>16)&0xaa] << 8) | (deinterleaveLookup[(code>>24)&0xaa] << 12) | (deinterleaveLookup[(code>>32)&0xaa] << 16) | (deinterleaveLookup[(code>>40)&0xaa] << 20) | (deinterleaveLookup[(code>>48)&0xaa] << 24) | (deinterleaveLookup[(code>>56)&0xaa] << 28) return x, y }
go
func deinterleaveUint32(code uint64) (uint32, uint32) { x := (deinterleaveLookup[code&0x55]) | (deinterleaveLookup[(code>>8)&0x55] << 4) | (deinterleaveLookup[(code>>16)&0x55] << 8) | (deinterleaveLookup[(code>>24)&0x55] << 12) | (deinterleaveLookup[(code>>32)&0x55] << 16) | (deinterleaveLookup[(code>>40)&0x55] << 20) | (deinterleaveLookup[(code>>48)&0x55] << 24) | (deinterleaveLookup[(code>>56)&0x55] << 28) y := (deinterleaveLookup[code&0xaa]) | (deinterleaveLookup[(code>>8)&0xaa] << 4) | (deinterleaveLookup[(code>>16)&0xaa] << 8) | (deinterleaveLookup[(code>>24)&0xaa] << 12) | (deinterleaveLookup[(code>>32)&0xaa] << 16) | (deinterleaveLookup[(code>>40)&0xaa] << 20) | (deinterleaveLookup[(code>>48)&0xaa] << 24) | (deinterleaveLookup[(code>>56)&0xaa] << 28) return x, y }
[ "func", "deinterleaveUint32", "(", "code", "uint64", ")", "(", "uint32", ",", "uint32", ")", "{", "x", ":=", "(", "deinterleaveLookup", "[", "code", "&", "0x55", "]", ")", "|", "(", "deinterleaveLookup", "[", "(", "code", ">>", "8", ")", "&", "0x55", "]", "<<", "4", ")", "|", "(", "deinterleaveLookup", "[", "(", "code", ">>", "16", ")", "&", "0x55", "]", "<<", "8", ")", "|", "(", "deinterleaveLookup", "[", "(", "code", ">>", "24", ")", "&", "0x55", "]", "<<", "12", ")", "|", "(", "deinterleaveLookup", "[", "(", "code", ">>", "32", ")", "&", "0x55", "]", "<<", "16", ")", "|", "(", "deinterleaveLookup", "[", "(", "code", ">>", "40", ")", "&", "0x55", "]", "<<", "20", ")", "|", "(", "deinterleaveLookup", "[", "(", "code", ">>", "48", ")", "&", "0x55", "]", "<<", "24", ")", "|", "(", "deinterleaveLookup", "[", "(", "code", ">>", "56", ")", "&", "0x55", "]", "<<", "28", ")", "\n", "y", ":=", "(", "deinterleaveLookup", "[", "code", "&", "0xaa", "]", ")", "|", "(", "deinterleaveLookup", "[", "(", "code", ">>", "8", ")", "&", "0xaa", "]", "<<", "4", ")", "|", "(", "deinterleaveLookup", "[", "(", "code", ">>", "16", ")", "&", "0xaa", "]", "<<", "8", ")", "|", "(", "deinterleaveLookup", "[", "(", "code", ">>", "24", ")", "&", "0xaa", "]", "<<", "12", ")", "|", "(", "deinterleaveLookup", "[", "(", "code", ">>", "32", ")", "&", "0xaa", "]", "<<", "16", ")", "|", "(", "deinterleaveLookup", "[", "(", "code", ">>", "40", ")", "&", "0xaa", "]", "<<", "20", ")", "|", "(", "deinterleaveLookup", "[", "(", "code", ">>", "48", ")", "&", "0xaa", "]", "<<", "24", ")", "|", "(", "deinterleaveLookup", "[", "(", "code", ">>", "56", ")", "&", "0xaa", "]", "<<", "28", ")", "\n", "return", "x", ",", "y", "\n", "}" ]
// deinterleaveUint32 decodes the interleaved values.
[ "deinterleaveUint32", "decodes", "the", "interleaved", "values", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/interleave.go#L71-L89
150,228
golang/geo
s2/interleave.go
interleaveUint32
func interleaveUint32(x, y uint32) uint64 { return (interleaveLookup[x&0xff]) | (interleaveLookup[(x>>8)&0xff] << 16) | (interleaveLookup[(x>>16)&0xff] << 32) | (interleaveLookup[x>>24] << 48) | (interleaveLookup[y&0xff] << 1) | (interleaveLookup[(y>>8)&0xff] << 17) | (interleaveLookup[(y>>16)&0xff] << 33) | (interleaveLookup[y>>24] << 49) }
go
func interleaveUint32(x, y uint32) uint64 { return (interleaveLookup[x&0xff]) | (interleaveLookup[(x>>8)&0xff] << 16) | (interleaveLookup[(x>>16)&0xff] << 32) | (interleaveLookup[x>>24] << 48) | (interleaveLookup[y&0xff] << 1) | (interleaveLookup[(y>>8)&0xff] << 17) | (interleaveLookup[(y>>16)&0xff] << 33) | (interleaveLookup[y>>24] << 49) }
[ "func", "interleaveUint32", "(", "x", ",", "y", "uint32", ")", "uint64", "{", "return", "(", "interleaveLookup", "[", "x", "&", "0xff", "]", ")", "|", "(", "interleaveLookup", "[", "(", "x", ">>", "8", ")", "&", "0xff", "]", "<<", "16", ")", "|", "(", "interleaveLookup", "[", "(", "x", ">>", "16", ")", "&", "0xff", "]", "<<", "32", ")", "|", "(", "interleaveLookup", "[", "x", ">>", "24", "]", "<<", "48", ")", "|", "(", "interleaveLookup", "[", "y", "&", "0xff", "]", "<<", "1", ")", "|", "(", "interleaveLookup", "[", "(", "y", ">>", "8", ")", "&", "0xff", "]", "<<", "17", ")", "|", "(", "interleaveLookup", "[", "(", "y", ">>", "16", ")", "&", "0xff", "]", "<<", "33", ")", "|", "(", "interleaveLookup", "[", "y", ">>", "24", "]", "<<", "49", ")", "\n", "}" ]
// interleaveUint32 interleaves the given arguments into the return value. // // The 0-bit in val0 will be the 0-bit in the return value. // The 0-bit in val1 will be the 1-bit in the return value. // The 1-bit of val0 will be the 2-bit in the return value, and so on.
[ "interleaveUint32", "interleaves", "the", "given", "arguments", "into", "the", "return", "value", ".", "The", "0", "-", "bit", "in", "val0", "will", "be", "the", "0", "-", "bit", "in", "the", "return", "value", ".", "The", "0", "-", "bit", "in", "val1", "will", "be", "the", "1", "-", "bit", "in", "the", "return", "value", ".", "The", "1", "-", "bit", "of", "val0", "will", "be", "the", "2", "-", "bit", "in", "the", "return", "value", "and", "so", "on", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/interleave.go#L134-L143
150,229
golang/geo
s2/paddedcell.go
PaddedCellFromCellID
func PaddedCellFromCellID(id CellID, padding float64) *PaddedCell { p := &PaddedCell{ id: id, padding: padding, middle: r2.EmptyRect(), } // Fast path for constructing a top-level face (the most common case). if id.isFace() { limit := padding + 1 p.bound = r2.Rect{r1.Interval{-limit, limit}, r1.Interval{-limit, limit}} p.middle = r2.Rect{r1.Interval{-padding, padding}, r1.Interval{-padding, padding}} p.orientation = id.Face() & 1 return p } _, p.iLo, p.jLo, p.orientation = id.faceIJOrientation() p.level = id.Level() p.bound = ijLevelToBoundUV(p.iLo, p.jLo, p.level).ExpandedByMargin(padding) ijSize := sizeIJ(p.level) p.iLo &= -ijSize p.jLo &= -ijSize return p }
go
func PaddedCellFromCellID(id CellID, padding float64) *PaddedCell { p := &PaddedCell{ id: id, padding: padding, middle: r2.EmptyRect(), } // Fast path for constructing a top-level face (the most common case). if id.isFace() { limit := padding + 1 p.bound = r2.Rect{r1.Interval{-limit, limit}, r1.Interval{-limit, limit}} p.middle = r2.Rect{r1.Interval{-padding, padding}, r1.Interval{-padding, padding}} p.orientation = id.Face() & 1 return p } _, p.iLo, p.jLo, p.orientation = id.faceIJOrientation() p.level = id.Level() p.bound = ijLevelToBoundUV(p.iLo, p.jLo, p.level).ExpandedByMargin(padding) ijSize := sizeIJ(p.level) p.iLo &= -ijSize p.jLo &= -ijSize return p }
[ "func", "PaddedCellFromCellID", "(", "id", "CellID", ",", "padding", "float64", ")", "*", "PaddedCell", "{", "p", ":=", "&", "PaddedCell", "{", "id", ":", "id", ",", "padding", ":", "padding", ",", "middle", ":", "r2", ".", "EmptyRect", "(", ")", ",", "}", "\n\n", "// Fast path for constructing a top-level face (the most common case).", "if", "id", ".", "isFace", "(", ")", "{", "limit", ":=", "padding", "+", "1", "\n", "p", ".", "bound", "=", "r2", ".", "Rect", "{", "r1", ".", "Interval", "{", "-", "limit", ",", "limit", "}", ",", "r1", ".", "Interval", "{", "-", "limit", ",", "limit", "}", "}", "\n", "p", ".", "middle", "=", "r2", ".", "Rect", "{", "r1", ".", "Interval", "{", "-", "padding", ",", "padding", "}", ",", "r1", ".", "Interval", "{", "-", "padding", ",", "padding", "}", "}", "\n", "p", ".", "orientation", "=", "id", ".", "Face", "(", ")", "&", "1", "\n", "return", "p", "\n", "}", "\n\n", "_", ",", "p", ".", "iLo", ",", "p", ".", "jLo", ",", "p", ".", "orientation", "=", "id", ".", "faceIJOrientation", "(", ")", "\n", "p", ".", "level", "=", "id", ".", "Level", "(", ")", "\n", "p", ".", "bound", "=", "ijLevelToBoundUV", "(", "p", ".", "iLo", ",", "p", ".", "jLo", ",", "p", ".", "level", ")", ".", "ExpandedByMargin", "(", "padding", ")", "\n", "ijSize", ":=", "sizeIJ", "(", "p", ".", "level", ")", "\n", "p", ".", "iLo", "&=", "-", "ijSize", "\n", "p", ".", "jLo", "&=", "-", "ijSize", "\n\n", "return", "p", "\n", "}" ]
// PaddedCellFromCellID constructs a padded cell with the given padding.
[ "PaddedCellFromCellID", "constructs", "a", "padded", "cell", "with", "the", "given", "padding", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/paddedcell.go#L37-L61
150,230
golang/geo
s2/paddedcell.go
Center
func (p PaddedCell) Center() Point { ijSize := sizeIJ(p.level) si := uint32(2*p.iLo + ijSize) ti := uint32(2*p.jLo + ijSize) return Point{faceSiTiToXYZ(p.id.Face(), si, ti).Normalize()} }
go
func (p PaddedCell) Center() Point { ijSize := sizeIJ(p.level) si := uint32(2*p.iLo + ijSize) ti := uint32(2*p.jLo + ijSize) return Point{faceSiTiToXYZ(p.id.Face(), si, ti).Normalize()} }
[ "func", "(", "p", "PaddedCell", ")", "Center", "(", ")", "Point", "{", "ijSize", ":=", "sizeIJ", "(", "p", ".", "level", ")", "\n", "si", ":=", "uint32", "(", "2", "*", "p", ".", "iLo", "+", "ijSize", ")", "\n", "ti", ":=", "uint32", "(", "2", "*", "p", ".", "jLo", "+", "ijSize", ")", "\n", "return", "Point", "{", "faceSiTiToXYZ", "(", "p", ".", "id", ".", "Face", "(", ")", ",", "si", ",", "ti", ")", ".", "Normalize", "(", ")", "}", "\n", "}" ]
// Center returns the center of this cell.
[ "Center", "returns", "the", "center", "of", "this", "cell", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/paddedcell.go#L117-L122
150,231
golang/geo
s2/paddedcell.go
EntryVertex
func (p PaddedCell) EntryVertex() Point { // The curve enters at the (0,0) vertex unless the axis directions are // reversed, in which case it enters at the (1,1) vertex. i := p.iLo j := p.jLo if p.orientation&invertMask != 0 { ijSize := sizeIJ(p.level) i += ijSize j += ijSize } return Point{faceSiTiToXYZ(p.id.Face(), uint32(2*i), uint32(2*j)).Normalize()} }
go
func (p PaddedCell) EntryVertex() Point { // The curve enters at the (0,0) vertex unless the axis directions are // reversed, in which case it enters at the (1,1) vertex. i := p.iLo j := p.jLo if p.orientation&invertMask != 0 { ijSize := sizeIJ(p.level) i += ijSize j += ijSize } return Point{faceSiTiToXYZ(p.id.Face(), uint32(2*i), uint32(2*j)).Normalize()} }
[ "func", "(", "p", "PaddedCell", ")", "EntryVertex", "(", ")", "Point", "{", "// The curve enters at the (0,0) vertex unless the axis directions are", "// reversed, in which case it enters at the (1,1) vertex.", "i", ":=", "p", ".", "iLo", "\n", "j", ":=", "p", ".", "jLo", "\n", "if", "p", ".", "orientation", "&", "invertMask", "!=", "0", "{", "ijSize", ":=", "sizeIJ", "(", "p", ".", "level", ")", "\n", "i", "+=", "ijSize", "\n", "j", "+=", "ijSize", "\n", "}", "\n", "return", "Point", "{", "faceSiTiToXYZ", "(", "p", ".", "id", ".", "Face", "(", ")", ",", "uint32", "(", "2", "*", "i", ")", ",", "uint32", "(", "2", "*", "j", ")", ")", ".", "Normalize", "(", ")", "}", "\n", "}" ]
// EntryVertex return the vertex where the space-filling curve enters this cell.
[ "EntryVertex", "return", "the", "vertex", "where", "the", "space", "-", "filling", "curve", "enters", "this", "cell", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/paddedcell.go#L155-L166
150,232
golang/geo
s2/paddedcell.go
ShrinkToFit
func (p *PaddedCell) ShrinkToFit(rect r2.Rect) CellID { // Quick rejection test: if rect contains the center of this cell along // either axis, then no further shrinking is possible. if p.level == 0 { // Fast path (most calls to this function start with a face cell). if rect.X.Contains(0) || rect.Y.Contains(0) { return p.id } } ijSize := sizeIJ(p.level) if rect.X.Contains(stToUV(siTiToST(uint32(2*p.iLo+ijSize)))) || rect.Y.Contains(stToUV(siTiToST(uint32(2*p.jLo+ijSize)))) { return p.id } // Otherwise we expand rect by the given padding on all sides and find // the range of coordinates that it spans along the i- and j-axes. We then // compute the highest bit position at which the min and max coordinates // differ. This corresponds to the first cell level at which at least two // children intersect rect. // Increase the padding to compensate for the error in uvToST. // (The constant below is a provable upper bound on the additional error.) padded := rect.ExpandedByMargin(p.padding + 1.5*dblEpsilon) iMin, jMin := p.iLo, p.jLo // Min i- or j- coordinate spanned by padded var iXor, jXor int // XOR of the min and max i- or j-coordinates if iMin < stToIJ(uvToST(padded.X.Lo)) { iMin = stToIJ(uvToST(padded.X.Lo)) } if a, b := p.iLo+ijSize-1, stToIJ(uvToST(padded.X.Hi)); a <= b { iXor = iMin ^ a } else { iXor = iMin ^ b } if jMin < stToIJ(uvToST(padded.Y.Lo)) { jMin = stToIJ(uvToST(padded.Y.Lo)) } if a, b := p.jLo+ijSize-1, stToIJ(uvToST(padded.Y.Hi)); a <= b { jXor = jMin ^ a } else { jXor = jMin ^ b } // Compute the highest bit position where the two i- or j-endpoints differ, // and then choose the cell level that includes both of these endpoints. So // if both pairs of endpoints are equal we choose maxLevel; if they differ // only at bit 0, we choose (maxLevel - 1), and so on. levelMSB := uint64(((iXor | jXor) << 1) + 1) level := maxLevel - int(findMSBSetNonZero64(levelMSB)) if level <= p.level { return p.id } return cellIDFromFaceIJ(p.id.Face(), iMin, jMin).Parent(level) }
go
func (p *PaddedCell) ShrinkToFit(rect r2.Rect) CellID { // Quick rejection test: if rect contains the center of this cell along // either axis, then no further shrinking is possible. if p.level == 0 { // Fast path (most calls to this function start with a face cell). if rect.X.Contains(0) || rect.Y.Contains(0) { return p.id } } ijSize := sizeIJ(p.level) if rect.X.Contains(stToUV(siTiToST(uint32(2*p.iLo+ijSize)))) || rect.Y.Contains(stToUV(siTiToST(uint32(2*p.jLo+ijSize)))) { return p.id } // Otherwise we expand rect by the given padding on all sides and find // the range of coordinates that it spans along the i- and j-axes. We then // compute the highest bit position at which the min and max coordinates // differ. This corresponds to the first cell level at which at least two // children intersect rect. // Increase the padding to compensate for the error in uvToST. // (The constant below is a provable upper bound on the additional error.) padded := rect.ExpandedByMargin(p.padding + 1.5*dblEpsilon) iMin, jMin := p.iLo, p.jLo // Min i- or j- coordinate spanned by padded var iXor, jXor int // XOR of the min and max i- or j-coordinates if iMin < stToIJ(uvToST(padded.X.Lo)) { iMin = stToIJ(uvToST(padded.X.Lo)) } if a, b := p.iLo+ijSize-1, stToIJ(uvToST(padded.X.Hi)); a <= b { iXor = iMin ^ a } else { iXor = iMin ^ b } if jMin < stToIJ(uvToST(padded.Y.Lo)) { jMin = stToIJ(uvToST(padded.Y.Lo)) } if a, b := p.jLo+ijSize-1, stToIJ(uvToST(padded.Y.Hi)); a <= b { jXor = jMin ^ a } else { jXor = jMin ^ b } // Compute the highest bit position where the two i- or j-endpoints differ, // and then choose the cell level that includes both of these endpoints. So // if both pairs of endpoints are equal we choose maxLevel; if they differ // only at bit 0, we choose (maxLevel - 1), and so on. levelMSB := uint64(((iXor | jXor) << 1) + 1) level := maxLevel - int(findMSBSetNonZero64(levelMSB)) if level <= p.level { return p.id } return cellIDFromFaceIJ(p.id.Face(), iMin, jMin).Parent(level) }
[ "func", "(", "p", "*", "PaddedCell", ")", "ShrinkToFit", "(", "rect", "r2", ".", "Rect", ")", "CellID", "{", "// Quick rejection test: if rect contains the center of this cell along", "// either axis, then no further shrinking is possible.", "if", "p", ".", "level", "==", "0", "{", "// Fast path (most calls to this function start with a face cell).", "if", "rect", ".", "X", ".", "Contains", "(", "0", ")", "||", "rect", ".", "Y", ".", "Contains", "(", "0", ")", "{", "return", "p", ".", "id", "\n", "}", "\n", "}", "\n\n", "ijSize", ":=", "sizeIJ", "(", "p", ".", "level", ")", "\n", "if", "rect", ".", "X", ".", "Contains", "(", "stToUV", "(", "siTiToST", "(", "uint32", "(", "2", "*", "p", ".", "iLo", "+", "ijSize", ")", ")", ")", ")", "||", "rect", ".", "Y", ".", "Contains", "(", "stToUV", "(", "siTiToST", "(", "uint32", "(", "2", "*", "p", ".", "jLo", "+", "ijSize", ")", ")", ")", ")", "{", "return", "p", ".", "id", "\n", "}", "\n\n", "// Otherwise we expand rect by the given padding on all sides and find", "// the range of coordinates that it spans along the i- and j-axes. We then", "// compute the highest bit position at which the min and max coordinates", "// differ. This corresponds to the first cell level at which at least two", "// children intersect rect.", "// Increase the padding to compensate for the error in uvToST.", "// (The constant below is a provable upper bound on the additional error.)", "padded", ":=", "rect", ".", "ExpandedByMargin", "(", "p", ".", "padding", "+", "1.5", "*", "dblEpsilon", ")", "\n", "iMin", ",", "jMin", ":=", "p", ".", "iLo", ",", "p", ".", "jLo", "// Min i- or j- coordinate spanned by padded", "\n", "var", "iXor", ",", "jXor", "int", "// XOR of the min and max i- or j-coordinates", "\n\n", "if", "iMin", "<", "stToIJ", "(", "uvToST", "(", "padded", ".", "X", ".", "Lo", ")", ")", "{", "iMin", "=", "stToIJ", "(", "uvToST", "(", "padded", ".", "X", ".", "Lo", ")", ")", "\n", "}", "\n", "if", "a", ",", "b", ":=", "p", ".", "iLo", "+", "ijSize", "-", "1", ",", "stToIJ", "(", "uvToST", "(", "padded", ".", "X", ".", "Hi", ")", ")", ";", "a", "<=", "b", "{", "iXor", "=", "iMin", "^", "a", "\n", "}", "else", "{", "iXor", "=", "iMin", "^", "b", "\n", "}", "\n\n", "if", "jMin", "<", "stToIJ", "(", "uvToST", "(", "padded", ".", "Y", ".", "Lo", ")", ")", "{", "jMin", "=", "stToIJ", "(", "uvToST", "(", "padded", ".", "Y", ".", "Lo", ")", ")", "\n", "}", "\n", "if", "a", ",", "b", ":=", "p", ".", "jLo", "+", "ijSize", "-", "1", ",", "stToIJ", "(", "uvToST", "(", "padded", ".", "Y", ".", "Hi", ")", ")", ";", "a", "<=", "b", "{", "jXor", "=", "jMin", "^", "a", "\n", "}", "else", "{", "jXor", "=", "jMin", "^", "b", "\n", "}", "\n\n", "// Compute the highest bit position where the two i- or j-endpoints differ,", "// and then choose the cell level that includes both of these endpoints. So", "// if both pairs of endpoints are equal we choose maxLevel; if they differ", "// only at bit 0, we choose (maxLevel - 1), and so on.", "levelMSB", ":=", "uint64", "(", "(", "(", "iXor", "|", "jXor", ")", "<<", "1", ")", "+", "1", ")", "\n", "level", ":=", "maxLevel", "-", "int", "(", "findMSBSetNonZero64", "(", "levelMSB", ")", ")", "\n", "if", "level", "<=", "p", ".", "level", "{", "return", "p", ".", "id", "\n", "}", "\n\n", "return", "cellIDFromFaceIJ", "(", "p", ".", "id", ".", "Face", "(", ")", ",", "iMin", ",", "jMin", ")", ".", "Parent", "(", "level", ")", "\n", "}" ]
// ShrinkToFit returns the smallest CellID that contains all descendants of this // padded cell whose bounds intersect the given rect. For algorithms that use // recursive subdivision to find the cells that intersect a particular object, this // method can be used to skip all of the initial subdivision steps where only // one child needs to be expanded. // // Note that this method is not the same as returning the smallest cell that contains // the intersection of this cell with rect. Because of the padding, even if one child // completely contains rect it is still possible that a neighboring child may also // intersect the given rect. // // The provided Rect must intersect the bounds of this cell.
[ "ShrinkToFit", "returns", "the", "smallest", "CellID", "that", "contains", "all", "descendants", "of", "this", "padded", "cell", "whose", "bounds", "intersect", "the", "given", "rect", ".", "For", "algorithms", "that", "use", "recursive", "subdivision", "to", "find", "the", "cells", "that", "intersect", "a", "particular", "object", "this", "method", "can", "be", "used", "to", "skip", "all", "of", "the", "initial", "subdivision", "steps", "where", "only", "one", "child", "needs", "to", "be", "expanded", ".", "Note", "that", "this", "method", "is", "not", "the", "same", "as", "returning", "the", "smallest", "cell", "that", "contains", "the", "intersection", "of", "this", "cell", "with", "rect", ".", "Because", "of", "the", "padding", "even", "if", "one", "child", "completely", "contains", "rect", "it", "is", "still", "possible", "that", "a", "neighboring", "child", "may", "also", "intersect", "the", "given", "rect", ".", "The", "provided", "Rect", "must", "intersect", "the", "bounds", "of", "this", "cell", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/paddedcell.go#L195-L252
150,233
golang/geo
r3/precisevector.go
precStr
func precStr(s string) *big.Float { // Explicitly ignoring the bool return for this usage. f, _ := new(big.Float).SetPrec(prec).SetString(s) return f }
go
func precStr(s string) *big.Float { // Explicitly ignoring the bool return for this usage. f, _ := new(big.Float).SetPrec(prec).SetString(s) return f }
[ "func", "precStr", "(", "s", "string", ")", "*", "big", ".", "Float", "{", "// Explicitly ignoring the bool return for this usage.", "f", ",", "_", ":=", "new", "(", "big", ".", "Float", ")", ".", "SetPrec", "(", "prec", ")", ".", "SetString", "(", "s", ")", "\n", "return", "f", "\n", "}" ]
// precStr wraps the conversion from a string into a big.Float. For results that // actually can be represented exactly, this should only be used on values that // are integer multiples of integer powers of 2.
[ "precStr", "wraps", "the", "conversion", "from", "a", "string", "into", "a", "big", ".", "Float", ".", "For", "results", "that", "actually", "can", "be", "represented", "exactly", "this", "should", "only", "be", "used", "on", "values", "that", "are", "integer", "multiples", "of", "integer", "powers", "of", "2", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/r3/precisevector.go#L38-L42
150,234
golang/geo
r3/precisevector.go
PreciseVectorFromVector
func PreciseVectorFromVector(v Vector) PreciseVector { return NewPreciseVector(v.X, v.Y, v.Z) }
go
func PreciseVectorFromVector(v Vector) PreciseVector { return NewPreciseVector(v.X, v.Y, v.Z) }
[ "func", "PreciseVectorFromVector", "(", "v", "Vector", ")", "PreciseVector", "{", "return", "NewPreciseVector", "(", "v", ".", "X", ",", "v", ".", "Y", ",", "v", ".", "Z", ")", "\n", "}" ]
// PreciseVectorFromVector creates a high precision vector from the given Vector.
[ "PreciseVectorFromVector", "creates", "a", "high", "precision", "vector", "from", "the", "given", "Vector", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/r3/precisevector.go#L74-L76
150,235
golang/geo
r3/precisevector.go
NewPreciseVector
func NewPreciseVector(x, y, z float64) PreciseVector { return PreciseVector{ X: precFloat(x), Y: precFloat(y), Z: precFloat(z), } }
go
func NewPreciseVector(x, y, z float64) PreciseVector { return PreciseVector{ X: precFloat(x), Y: precFloat(y), Z: precFloat(z), } }
[ "func", "NewPreciseVector", "(", "x", ",", "y", ",", "z", "float64", ")", "PreciseVector", "{", "return", "PreciseVector", "{", "X", ":", "precFloat", "(", "x", ")", ",", "Y", ":", "precFloat", "(", "y", ")", ",", "Z", ":", "precFloat", "(", "z", ")", ",", "}", "\n", "}" ]
// NewPreciseVector creates a high precision vector from the given floating point values.
[ "NewPreciseVector", "creates", "a", "high", "precision", "vector", "from", "the", "given", "floating", "point", "values", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/r3/precisevector.go#L79-L85
150,236
golang/geo
r3/precisevector.go
Vector
func (v PreciseVector) Vector() Vector { // The accuracy flag is ignored on these conversions back to float64. x, _ := v.X.Float64() y, _ := v.Y.Float64() z, _ := v.Z.Float64() return Vector{x, y, z}.Normalize() }
go
func (v PreciseVector) Vector() Vector { // The accuracy flag is ignored on these conversions back to float64. x, _ := v.X.Float64() y, _ := v.Y.Float64() z, _ := v.Z.Float64() return Vector{x, y, z}.Normalize() }
[ "func", "(", "v", "PreciseVector", ")", "Vector", "(", ")", "Vector", "{", "// The accuracy flag is ignored on these conversions back to float64.", "x", ",", "_", ":=", "v", ".", "X", ".", "Float64", "(", ")", "\n", "y", ",", "_", ":=", "v", ".", "Y", ".", "Float64", "(", ")", "\n", "z", ",", "_", ":=", "v", ".", "Z", ".", "Float64", "(", ")", "\n", "return", "Vector", "{", "x", ",", "y", ",", "z", "}", ".", "Normalize", "(", ")", "\n", "}" ]
// Vector returns this precise vector converted to a Vector.
[ "Vector", "returns", "this", "precise", "vector", "converted", "to", "a", "Vector", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/r3/precisevector.go#L88-L94
150,237
golang/geo
r3/precisevector.go
Equal
func (v PreciseVector) Equal(ov PreciseVector) bool { return v.X.Cmp(ov.X) == 0 && v.Y.Cmp(ov.Y) == 0 && v.Z.Cmp(ov.Z) == 0 }
go
func (v PreciseVector) Equal(ov PreciseVector) bool { return v.X.Cmp(ov.X) == 0 && v.Y.Cmp(ov.Y) == 0 && v.Z.Cmp(ov.Z) == 0 }
[ "func", "(", "v", "PreciseVector", ")", "Equal", "(", "ov", "PreciseVector", ")", "bool", "{", "return", "v", ".", "X", ".", "Cmp", "(", "ov", ".", "X", ")", "==", "0", "&&", "v", ".", "Y", ".", "Cmp", "(", "ov", ".", "Y", ")", "==", "0", "&&", "v", ".", "Z", ".", "Cmp", "(", "ov", ".", "Z", ")", "==", "0", "\n", "}" ]
// Equal reports whether v and ov are equal.
[ "Equal", "reports", "whether", "v", "and", "ov", "are", "equal", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/r3/precisevector.go#L97-L99
150,238
golang/geo
r3/precisevector.go
Abs
func (v PreciseVector) Abs() PreciseVector { return PreciseVector{ X: new(big.Float).Abs(v.X), Y: new(big.Float).Abs(v.Y), Z: new(big.Float).Abs(v.Z), } }
go
func (v PreciseVector) Abs() PreciseVector { return PreciseVector{ X: new(big.Float).Abs(v.X), Y: new(big.Float).Abs(v.Y), Z: new(big.Float).Abs(v.Z), } }
[ "func", "(", "v", "PreciseVector", ")", "Abs", "(", ")", "PreciseVector", "{", "return", "PreciseVector", "{", "X", ":", "new", "(", "big", ".", "Float", ")", ".", "Abs", "(", "v", ".", "X", ")", ",", "Y", ":", "new", "(", "big", ".", "Float", ")", ".", "Abs", "(", "v", ".", "Y", ")", ",", "Z", ":", "new", "(", "big", ".", "Float", ")", ".", "Abs", "(", "v", ".", "Z", ")", ",", "}", "\n", "}" ]
// Abs returns the vector with nonnegative components.
[ "Abs", "returns", "the", "vector", "with", "nonnegative", "components", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/r3/precisevector.go#L114-L120
150,239
golang/geo
r3/precisevector.go
Add
func (v PreciseVector) Add(ov PreciseVector) PreciseVector { return PreciseVector{ X: precAdd(v.X, ov.X), Y: precAdd(v.Y, ov.Y), Z: precAdd(v.Z, ov.Z), } }
go
func (v PreciseVector) Add(ov PreciseVector) PreciseVector { return PreciseVector{ X: precAdd(v.X, ov.X), Y: precAdd(v.Y, ov.Y), Z: precAdd(v.Z, ov.Z), } }
[ "func", "(", "v", "PreciseVector", ")", "Add", "(", "ov", "PreciseVector", ")", "PreciseVector", "{", "return", "PreciseVector", "{", "X", ":", "precAdd", "(", "v", ".", "X", ",", "ov", ".", "X", ")", ",", "Y", ":", "precAdd", "(", "v", ".", "Y", ",", "ov", ".", "Y", ")", ",", "Z", ":", "precAdd", "(", "v", ".", "Z", ",", "ov", ".", "Z", ")", ",", "}", "\n", "}" ]
// Add returns the standard vector sum of v and ov.
[ "Add", "returns", "the", "standard", "vector", "sum", "of", "v", "and", "ov", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/r3/precisevector.go#L123-L129
150,240
golang/geo
r3/precisevector.go
Sub
func (v PreciseVector) Sub(ov PreciseVector) PreciseVector { return PreciseVector{ X: precSub(v.X, ov.X), Y: precSub(v.Y, ov.Y), Z: precSub(v.Z, ov.Z), } }
go
func (v PreciseVector) Sub(ov PreciseVector) PreciseVector { return PreciseVector{ X: precSub(v.X, ov.X), Y: precSub(v.Y, ov.Y), Z: precSub(v.Z, ov.Z), } }
[ "func", "(", "v", "PreciseVector", ")", "Sub", "(", "ov", "PreciseVector", ")", "PreciseVector", "{", "return", "PreciseVector", "{", "X", ":", "precSub", "(", "v", ".", "X", ",", "ov", ".", "X", ")", ",", "Y", ":", "precSub", "(", "v", ".", "Y", ",", "ov", ".", "Y", ")", ",", "Z", ":", "precSub", "(", "v", ".", "Z", ",", "ov", ".", "Z", ")", ",", "}", "\n", "}" ]
// Sub returns the standard vector difference of v and ov.
[ "Sub", "returns", "the", "standard", "vector", "difference", "of", "v", "and", "ov", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/r3/precisevector.go#L132-L138
150,241
golang/geo
r3/precisevector.go
Mul
func (v PreciseVector) Mul(f *big.Float) PreciseVector { return PreciseVector{ X: precMul(v.X, f), Y: precMul(v.Y, f), Z: precMul(v.Z, f), } }
go
func (v PreciseVector) Mul(f *big.Float) PreciseVector { return PreciseVector{ X: precMul(v.X, f), Y: precMul(v.Y, f), Z: precMul(v.Z, f), } }
[ "func", "(", "v", "PreciseVector", ")", "Mul", "(", "f", "*", "big", ".", "Float", ")", "PreciseVector", "{", "return", "PreciseVector", "{", "X", ":", "precMul", "(", "v", ".", "X", ",", "f", ")", ",", "Y", ":", "precMul", "(", "v", ".", "Y", ",", "f", ")", ",", "Z", ":", "precMul", "(", "v", ".", "Z", ",", "f", ")", ",", "}", "\n", "}" ]
// Mul returns the standard scalar product of v and f.
[ "Mul", "returns", "the", "standard", "scalar", "product", "of", "v", "and", "f", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/r3/precisevector.go#L141-L147
150,242
golang/geo
r3/precisevector.go
MulByFloat64
func (v PreciseVector) MulByFloat64(f float64) PreciseVector { return v.Mul(precFloat(f)) }
go
func (v PreciseVector) MulByFloat64(f float64) PreciseVector { return v.Mul(precFloat(f)) }
[ "func", "(", "v", "PreciseVector", ")", "MulByFloat64", "(", "f", "float64", ")", "PreciseVector", "{", "return", "v", ".", "Mul", "(", "precFloat", "(", "f", ")", ")", "\n", "}" ]
// MulByFloat64 returns the standard scalar product of v and f.
[ "MulByFloat64", "returns", "the", "standard", "scalar", "product", "of", "v", "and", "f", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/r3/precisevector.go#L150-L152
150,243
golang/geo
r3/precisevector.go
Dot
func (v PreciseVector) Dot(ov PreciseVector) *big.Float { return precAdd(precMul(v.X, ov.X), precAdd(precMul(v.Y, ov.Y), precMul(v.Z, ov.Z))) }
go
func (v PreciseVector) Dot(ov PreciseVector) *big.Float { return precAdd(precMul(v.X, ov.X), precAdd(precMul(v.Y, ov.Y), precMul(v.Z, ov.Z))) }
[ "func", "(", "v", "PreciseVector", ")", "Dot", "(", "ov", "PreciseVector", ")", "*", "big", ".", "Float", "{", "return", "precAdd", "(", "precMul", "(", "v", ".", "X", ",", "ov", ".", "X", ")", ",", "precAdd", "(", "precMul", "(", "v", ".", "Y", ",", "ov", ".", "Y", ")", ",", "precMul", "(", "v", ".", "Z", ",", "ov", ".", "Z", ")", ")", ")", "\n", "}" ]
// Dot returns the standard dot product of v and ov.
[ "Dot", "returns", "the", "standard", "dot", "product", "of", "v", "and", "ov", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/r3/precisevector.go#L155-L157
150,244
golang/geo
s2/matrix3x3.go
col
func (m *matrix3x3) col(col int) Point { return Point{r3.Vector{m[0][col], m[1][col], m[2][col]}} }
go
func (m *matrix3x3) col(col int) Point { return Point{r3.Vector{m[0][col], m[1][col], m[2][col]}} }
[ "func", "(", "m", "*", "matrix3x3", ")", "col", "(", "col", "int", ")", "Point", "{", "return", "Point", "{", "r3", ".", "Vector", "{", "m", "[", "0", "]", "[", "col", "]", ",", "m", "[", "1", "]", "[", "col", "]", ",", "m", "[", "2", "]", "[", "col", "]", "}", "}", "\n", "}" ]
// col returns the given column as a Point.
[ "col", "returns", "the", "given", "column", "as", "a", "Point", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/matrix3x3.go#L29-L31
150,245
golang/geo
s2/matrix3x3.go
row
func (m *matrix3x3) row(row int) Point { return Point{r3.Vector{m[row][0], m[row][1], m[row][2]}} }
go
func (m *matrix3x3) row(row int) Point { return Point{r3.Vector{m[row][0], m[row][1], m[row][2]}} }
[ "func", "(", "m", "*", "matrix3x3", ")", "row", "(", "row", "int", ")", "Point", "{", "return", "Point", "{", "r3", ".", "Vector", "{", "m", "[", "row", "]", "[", "0", "]", ",", "m", "[", "row", "]", "[", "1", "]", ",", "m", "[", "row", "]", "[", "2", "]", "}", "}", "\n", "}" ]
// row returns the given row as a Point.
[ "row", "returns", "the", "given", "row", "as", "a", "Point", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/matrix3x3.go#L34-L36
150,246
golang/geo
s2/matrix3x3.go
setCol
func (m *matrix3x3) setCol(col int, p Point) *matrix3x3 { m[0][col] = p.X m[1][col] = p.Y m[2][col] = p.Z return m }
go
func (m *matrix3x3) setCol(col int, p Point) *matrix3x3 { m[0][col] = p.X m[1][col] = p.Y m[2][col] = p.Z return m }
[ "func", "(", "m", "*", "matrix3x3", ")", "setCol", "(", "col", "int", ",", "p", "Point", ")", "*", "matrix3x3", "{", "m", "[", "0", "]", "[", "col", "]", "=", "p", ".", "X", "\n", "m", "[", "1", "]", "[", "col", "]", "=", "p", ".", "Y", "\n", "m", "[", "2", "]", "[", "col", "]", "=", "p", ".", "Z", "\n\n", "return", "m", "\n", "}" ]
// setCol sets the specified column to the value in the given Point.
[ "setCol", "sets", "the", "specified", "column", "to", "the", "value", "in", "the", "given", "Point", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/matrix3x3.go#L39-L45
150,247
golang/geo
s2/matrix3x3.go
setRow
func (m *matrix3x3) setRow(row int, p Point) *matrix3x3 { m[row][0] = p.X m[row][1] = p.Y m[row][2] = p.Z return m }
go
func (m *matrix3x3) setRow(row int, p Point) *matrix3x3 { m[row][0] = p.X m[row][1] = p.Y m[row][2] = p.Z return m }
[ "func", "(", "m", "*", "matrix3x3", ")", "setRow", "(", "row", "int", ",", "p", "Point", ")", "*", "matrix3x3", "{", "m", "[", "row", "]", "[", "0", "]", "=", "p", ".", "X", "\n", "m", "[", "row", "]", "[", "1", "]", "=", "p", ".", "Y", "\n", "m", "[", "row", "]", "[", "2", "]", "=", "p", ".", "Z", "\n\n", "return", "m", "\n", "}" ]
// setRow sets the specified row to the value in the given Point.
[ "setRow", "sets", "the", "specified", "row", "to", "the", "value", "in", "the", "given", "Point", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/matrix3x3.go#L48-L54
150,248
golang/geo
s2/matrix3x3.go
scale
func (m *matrix3x3) scale(f float64) *matrix3x3 { return &matrix3x3{ [3]float64{f * m[0][0], f * m[0][1], f * m[0][2]}, [3]float64{f * m[1][0], f * m[1][1], f * m[1][2]}, [3]float64{f * m[2][0], f * m[2][1], f * m[2][2]}, } }
go
func (m *matrix3x3) scale(f float64) *matrix3x3 { return &matrix3x3{ [3]float64{f * m[0][0], f * m[0][1], f * m[0][2]}, [3]float64{f * m[1][0], f * m[1][1], f * m[1][2]}, [3]float64{f * m[2][0], f * m[2][1], f * m[2][2]}, } }
[ "func", "(", "m", "*", "matrix3x3", ")", "scale", "(", "f", "float64", ")", "*", "matrix3x3", "{", "return", "&", "matrix3x3", "{", "[", "3", "]", "float64", "{", "f", "*", "m", "[", "0", "]", "[", "0", "]", ",", "f", "*", "m", "[", "0", "]", "[", "1", "]", ",", "f", "*", "m", "[", "0", "]", "[", "2", "]", "}", ",", "[", "3", "]", "float64", "{", "f", "*", "m", "[", "1", "]", "[", "0", "]", ",", "f", "*", "m", "[", "1", "]", "[", "1", "]", ",", "f", "*", "m", "[", "1", "]", "[", "2", "]", "}", ",", "[", "3", "]", "float64", "{", "f", "*", "m", "[", "2", "]", "[", "0", "]", ",", "f", "*", "m", "[", "2", "]", "[", "1", "]", ",", "f", "*", "m", "[", "2", "]", "[", "2", "]", "}", ",", "}", "\n", "}" ]
// scale multiplies the matrix by the given value.
[ "scale", "multiplies", "the", "matrix", "by", "the", "given", "value", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/matrix3x3.go#L57-L63
150,249
golang/geo
s2/matrix3x3.go
mul
func (m *matrix3x3) mul(p Point) Point { return Point{r3.Vector{ m[0][0]*p.X + m[0][1]*p.Y + m[0][2]*p.Z, m[1][0]*p.X + m[1][1]*p.Y + m[1][2]*p.Z, m[2][0]*p.X + m[2][1]*p.Y + m[2][2]*p.Z, }} }
go
func (m *matrix3x3) mul(p Point) Point { return Point{r3.Vector{ m[0][0]*p.X + m[0][1]*p.Y + m[0][2]*p.Z, m[1][0]*p.X + m[1][1]*p.Y + m[1][2]*p.Z, m[2][0]*p.X + m[2][1]*p.Y + m[2][2]*p.Z, }} }
[ "func", "(", "m", "*", "matrix3x3", ")", "mul", "(", "p", "Point", ")", "Point", "{", "return", "Point", "{", "r3", ".", "Vector", "{", "m", "[", "0", "]", "[", "0", "]", "*", "p", ".", "X", "+", "m", "[", "0", "]", "[", "1", "]", "*", "p", ".", "Y", "+", "m", "[", "0", "]", "[", "2", "]", "*", "p", ".", "Z", ",", "m", "[", "1", "]", "[", "0", "]", "*", "p", ".", "X", "+", "m", "[", "1", "]", "[", "1", "]", "*", "p", ".", "Y", "+", "m", "[", "1", "]", "[", "2", "]", "*", "p", ".", "Z", ",", "m", "[", "2", "]", "[", "0", "]", "*", "p", ".", "X", "+", "m", "[", "2", "]", "[", "1", "]", "*", "p", ".", "Y", "+", "m", "[", "2", "]", "[", "2", "]", "*", "p", ".", "Z", ",", "}", "}", "\n", "}" ]
// mul returns the multiplication of m by the Point p and converts the // resulting 1x3 matrix into a Point.
[ "mul", "returns", "the", "multiplication", "of", "m", "by", "the", "Point", "p", "and", "converts", "the", "resulting", "1x3", "matrix", "into", "a", "Point", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/matrix3x3.go#L67-L73
150,250
golang/geo
s2/matrix3x3.go
det
func (m *matrix3x3) det() float64 { // | a b c | // det | d e f | = aei + bfg + cdh - ceg - bdi - afh // | g h i | return m[0][0]*m[1][1]*m[2][2] + m[0][1]*m[1][2]*m[2][0] + m[0][2]*m[1][0]*m[2][1] - m[0][2]*m[1][1]*m[2][0] - m[0][1]*m[1][0]*m[2][2] - m[0][0]*m[1][2]*m[2][1] }
go
func (m *matrix3x3) det() float64 { // | a b c | // det | d e f | = aei + bfg + cdh - ceg - bdi - afh // | g h i | return m[0][0]*m[1][1]*m[2][2] + m[0][1]*m[1][2]*m[2][0] + m[0][2]*m[1][0]*m[2][1] - m[0][2]*m[1][1]*m[2][0] - m[0][1]*m[1][0]*m[2][2] - m[0][0]*m[1][2]*m[2][1] }
[ "func", "(", "m", "*", "matrix3x3", ")", "det", "(", ")", "float64", "{", "// | a b c |", "// det | d e f | = aei + bfg + cdh - ceg - bdi - afh", "// | g h i |", "return", "m", "[", "0", "]", "[", "0", "]", "*", "m", "[", "1", "]", "[", "1", "]", "*", "m", "[", "2", "]", "[", "2", "]", "+", "m", "[", "0", "]", "[", "1", "]", "*", "m", "[", "1", "]", "[", "2", "]", "*", "m", "[", "2", "]", "[", "0", "]", "+", "m", "[", "0", "]", "[", "2", "]", "*", "m", "[", "1", "]", "[", "0", "]", "*", "m", "[", "2", "]", "[", "1", "]", "-", "m", "[", "0", "]", "[", "2", "]", "*", "m", "[", "1", "]", "[", "1", "]", "*", "m", "[", "2", "]", "[", "0", "]", "-", "m", "[", "0", "]", "[", "1", "]", "*", "m", "[", "1", "]", "[", "0", "]", "*", "m", "[", "2", "]", "[", "2", "]", "-", "m", "[", "0", "]", "[", "0", "]", "*", "m", "[", "1", "]", "[", "2", "]", "*", "m", "[", "2", "]", "[", "1", "]", "\n", "}" ]
// det returns the determinant of this matrix.
[ "det", "returns", "the", "determinant", "of", "this", "matrix", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/matrix3x3.go#L76-L82
150,251
golang/geo
s2/matrix3x3.go
transpose
func (m *matrix3x3) transpose() *matrix3x3 { m[0][1], m[1][0] = m[1][0], m[0][1] m[0][2], m[2][0] = m[2][0], m[0][2] m[1][2], m[2][1] = m[2][1], m[1][2] return m }
go
func (m *matrix3x3) transpose() *matrix3x3 { m[0][1], m[1][0] = m[1][0], m[0][1] m[0][2], m[2][0] = m[2][0], m[0][2] m[1][2], m[2][1] = m[2][1], m[1][2] return m }
[ "func", "(", "m", "*", "matrix3x3", ")", "transpose", "(", ")", "*", "matrix3x3", "{", "m", "[", "0", "]", "[", "1", "]", ",", "m", "[", "1", "]", "[", "0", "]", "=", "m", "[", "1", "]", "[", "0", "]", ",", "m", "[", "0", "]", "[", "1", "]", "\n", "m", "[", "0", "]", "[", "2", "]", ",", "m", "[", "2", "]", "[", "0", "]", "=", "m", "[", "2", "]", "[", "0", "]", ",", "m", "[", "0", "]", "[", "2", "]", "\n", "m", "[", "1", "]", "[", "2", "]", ",", "m", "[", "2", "]", "[", "1", "]", "=", "m", "[", "2", "]", "[", "1", "]", ",", "m", "[", "1", "]", "[", "2", "]", "\n\n", "return", "m", "\n", "}" ]
// transpose reflects the matrix along its diagonal and returns the result.
[ "transpose", "reflects", "the", "matrix", "along", "its", "diagonal", "and", "returns", "the", "result", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/matrix3x3.go#L85-L91
150,252
golang/geo
s2/matrix3x3.go
String
func (m *matrix3x3) String() string { return fmt.Sprintf("[ %0.4f %0.4f %0.4f ] [ %0.4f %0.4f %0.4f ] [ %0.4f %0.4f %0.4f ]", m[0][0], m[0][1], m[0][2], m[1][0], m[1][1], m[1][2], m[2][0], m[2][1], m[2][2], ) }
go
func (m *matrix3x3) String() string { return fmt.Sprintf("[ %0.4f %0.4f %0.4f ] [ %0.4f %0.4f %0.4f ] [ %0.4f %0.4f %0.4f ]", m[0][0], m[0][1], m[0][2], m[1][0], m[1][1], m[1][2], m[2][0], m[2][1], m[2][2], ) }
[ "func", "(", "m", "*", "matrix3x3", ")", "String", "(", ")", "string", "{", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "m", "[", "0", "]", "[", "0", "]", ",", "m", "[", "0", "]", "[", "1", "]", ",", "m", "[", "0", "]", "[", "2", "]", ",", "m", "[", "1", "]", "[", "0", "]", ",", "m", "[", "1", "]", "[", "1", "]", ",", "m", "[", "1", "]", "[", "2", "]", ",", "m", "[", "2", "]", "[", "0", "]", ",", "m", "[", "2", "]", "[", "1", "]", ",", "m", "[", "2", "]", "[", "2", "]", ",", ")", "\n", "}" ]
// String formats the matrix into an easier to read layout.
[ "String", "formats", "the", "matrix", "into", "an", "easier", "to", "read", "layout", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/matrix3x3.go#L94-L100
150,253
golang/geo
s2/matrix3x3.go
getFrame
func getFrame(p Point) matrix3x3 { // Given the point p on the unit sphere, extend this into a right-handed // coordinate frame of unit-length column vectors m = (x,y,z). Note that // the vectors (x,y) are an orthonormal frame for the tangent space at point p, // while p itself is an orthonormal frame for the normal space at p. m := matrix3x3{} m.setCol(2, p) m.setCol(1, Point{p.Ortho()}) m.setCol(0, Point{m.col(1).Cross(p.Vector)}) return m }
go
func getFrame(p Point) matrix3x3 { // Given the point p on the unit sphere, extend this into a right-handed // coordinate frame of unit-length column vectors m = (x,y,z). Note that // the vectors (x,y) are an orthonormal frame for the tangent space at point p, // while p itself is an orthonormal frame for the normal space at p. m := matrix3x3{} m.setCol(2, p) m.setCol(1, Point{p.Ortho()}) m.setCol(0, Point{m.col(1).Cross(p.Vector)}) return m }
[ "func", "getFrame", "(", "p", "Point", ")", "matrix3x3", "{", "// Given the point p on the unit sphere, extend this into a right-handed", "// coordinate frame of unit-length column vectors m = (x,y,z). Note that", "// the vectors (x,y) are an orthonormal frame for the tangent space at point p,", "// while p itself is an orthonormal frame for the normal space at p.", "m", ":=", "matrix3x3", "{", "}", "\n", "m", ".", "setCol", "(", "2", ",", "p", ")", "\n", "m", ".", "setCol", "(", "1", ",", "Point", "{", "p", ".", "Ortho", "(", ")", "}", ")", "\n", "m", ".", "setCol", "(", "0", ",", "Point", "{", "m", ".", "col", "(", "1", ")", ".", "Cross", "(", "p", ".", "Vector", ")", "}", ")", "\n", "return", "m", "\n", "}" ]
// getFrame returns the orthonormal frame for the given point on the unit sphere.
[ "getFrame", "returns", "the", "orthonormal", "frame", "for", "the", "given", "point", "on", "the", "unit", "sphere", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/matrix3x3.go#L103-L113
150,254
golang/geo
r2/rect.go
Normalize
func (p Point) Normalize() Point { if p.X == 0 && p.Y == 0 { return p } return p.Mul(1 / p.Norm()) }
go
func (p Point) Normalize() Point { if p.X == 0 && p.Y == 0 { return p } return p.Mul(1 / p.Norm()) }
[ "func", "(", "p", "Point", ")", "Normalize", "(", ")", "Point", "{", "if", "p", ".", "X", "==", "0", "&&", "p", ".", "Y", "==", "0", "{", "return", "p", "\n", "}", "\n", "return", "p", ".", "Mul", "(", "1", "/", "p", ".", "Norm", "(", ")", ")", "\n", "}" ]
// Normalize returns a unit point in the same direction as p.
[ "Normalize", "returns", "a", "unit", "point", "in", "the", "same", "direction", "as", "p", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/r2/rect.go#L51-L56
150,255
golang/geo
r2/rect.go
RectFromPoints
func RectFromPoints(pts ...Point) Rect { // Because the default value on interval is 0,0, we need to manually // define the interval from the first point passed in as our starting // interval, otherwise we end up with the case of passing in // Point{0.2, 0.3} and getting the starting Rect of {0, 0.2}, {0, 0.3} // instead of the Rect {0.2, 0.2}, {0.3, 0.3} which is not correct. if len(pts) == 0 { return Rect{} } r := Rect{ X: r1.Interval{Lo: pts[0].X, Hi: pts[0].X}, Y: r1.Interval{Lo: pts[0].Y, Hi: pts[0].Y}, } for _, p := range pts[1:] { r = r.AddPoint(p) } return r }
go
func RectFromPoints(pts ...Point) Rect { // Because the default value on interval is 0,0, we need to manually // define the interval from the first point passed in as our starting // interval, otherwise we end up with the case of passing in // Point{0.2, 0.3} and getting the starting Rect of {0, 0.2}, {0, 0.3} // instead of the Rect {0.2, 0.2}, {0.3, 0.3} which is not correct. if len(pts) == 0 { return Rect{} } r := Rect{ X: r1.Interval{Lo: pts[0].X, Hi: pts[0].X}, Y: r1.Interval{Lo: pts[0].Y, Hi: pts[0].Y}, } for _, p := range pts[1:] { r = r.AddPoint(p) } return r }
[ "func", "RectFromPoints", "(", "pts", "...", "Point", ")", "Rect", "{", "// Because the default value on interval is 0,0, we need to manually", "// define the interval from the first point passed in as our starting", "// interval, otherwise we end up with the case of passing in", "// Point{0.2, 0.3} and getting the starting Rect of {0, 0.2}, {0, 0.3}", "// instead of the Rect {0.2, 0.2}, {0.3, 0.3} which is not correct.", "if", "len", "(", "pts", ")", "==", "0", "{", "return", "Rect", "{", "}", "\n", "}", "\n\n", "r", ":=", "Rect", "{", "X", ":", "r1", ".", "Interval", "{", "Lo", ":", "pts", "[", "0", "]", ".", "X", ",", "Hi", ":", "pts", "[", "0", "]", ".", "X", "}", ",", "Y", ":", "r1", ".", "Interval", "{", "Lo", ":", "pts", "[", "0", "]", ".", "Y", ",", "Hi", ":", "pts", "[", "0", "]", ".", "Y", "}", ",", "}", "\n\n", "for", "_", ",", "p", ":=", "range", "pts", "[", "1", ":", "]", "{", "r", "=", "r", ".", "AddPoint", "(", "p", ")", "\n", "}", "\n", "return", "r", "\n", "}" ]
// RectFromPoints constructs a rect that contains the given points.
[ "RectFromPoints", "constructs", "a", "rect", "that", "contains", "the", "given", "points", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/r2/rect.go#L66-L85
150,256
golang/geo
r2/rect.go
RectFromCenterSize
func RectFromCenterSize(center, size Point) Rect { return Rect{ r1.Interval{Lo: center.X - size.X/2, Hi: center.X + size.X/2}, r1.Interval{Lo: center.Y - size.Y/2, Hi: center.Y + size.Y/2}, } }
go
func RectFromCenterSize(center, size Point) Rect { return Rect{ r1.Interval{Lo: center.X - size.X/2, Hi: center.X + size.X/2}, r1.Interval{Lo: center.Y - size.Y/2, Hi: center.Y + size.Y/2}, } }
[ "func", "RectFromCenterSize", "(", "center", ",", "size", "Point", ")", "Rect", "{", "return", "Rect", "{", "r1", ".", "Interval", "{", "Lo", ":", "center", ".", "X", "-", "size", ".", "X", "/", "2", ",", "Hi", ":", "center", ".", "X", "+", "size", ".", "X", "/", "2", "}", ",", "r1", ".", "Interval", "{", "Lo", ":", "center", ".", "Y", "-", "size", ".", "Y", "/", "2", ",", "Hi", ":", "center", ".", "Y", "+", "size", ".", "Y", "/", "2", "}", ",", "}", "\n", "}" ]
// RectFromCenterSize constructs a rectangle with the given center and size. // Both dimensions of size must be non-negative.
[ "RectFromCenterSize", "constructs", "a", "rectangle", "with", "the", "given", "center", "and", "size", ".", "Both", "dimensions", "of", "size", "must", "be", "non", "-", "negative", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/r2/rect.go#L89-L94
150,257
golang/geo
r2/rect.go
IsValid
func (r Rect) IsValid() bool { return r.X.IsEmpty() == r.Y.IsEmpty() }
go
func (r Rect) IsValid() bool { return r.X.IsEmpty() == r.Y.IsEmpty() }
[ "func", "(", "r", "Rect", ")", "IsValid", "(", ")", "bool", "{", "return", "r", ".", "X", ".", "IsEmpty", "(", ")", "==", "r", ".", "Y", ".", "IsEmpty", "(", ")", "\n", "}" ]
// IsValid reports whether the rectangle is valid. // This requires the width to be empty iff the height is empty.
[ "IsValid", "reports", "whether", "the", "rectangle", "is", "valid", ".", "This", "requires", "the", "width", "to", "be", "empty", "iff", "the", "height", "is", "empty", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/r2/rect.go#L105-L107
150,258
golang/geo
r2/rect.go
Vertices
func (r Rect) Vertices() [4]Point { return [4]Point{ {r.X.Lo, r.Y.Lo}, {r.X.Hi, r.Y.Lo}, {r.X.Hi, r.Y.Hi}, {r.X.Lo, r.Y.Hi}, } }
go
func (r Rect) Vertices() [4]Point { return [4]Point{ {r.X.Lo, r.Y.Lo}, {r.X.Hi, r.Y.Lo}, {r.X.Hi, r.Y.Hi}, {r.X.Lo, r.Y.Hi}, } }
[ "func", "(", "r", "Rect", ")", "Vertices", "(", ")", "[", "4", "]", "Point", "{", "return", "[", "4", "]", "Point", "{", "{", "r", ".", "X", ".", "Lo", ",", "r", ".", "Y", ".", "Lo", "}", ",", "{", "r", ".", "X", ".", "Hi", ",", "r", ".", "Y", ".", "Lo", "}", ",", "{", "r", ".", "X", ".", "Hi", ",", "r", ".", "Y", ".", "Hi", "}", ",", "{", "r", ".", "X", ".", "Lo", ",", "r", ".", "Y", ".", "Hi", "}", ",", "}", "\n", "}" ]
// Vertices returns all four vertices of the rectangle. Vertices are returned in // CCW direction starting with the lower left corner.
[ "Vertices", "returns", "all", "four", "vertices", "of", "the", "rectangle", ".", "Vertices", "are", "returned", "in", "CCW", "direction", "starting", "with", "the", "lower", "left", "corner", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/r2/rect.go#L116-L123
150,259
golang/geo
r2/rect.go
Lo
func (r Rect) Lo() Point { return Point{r.X.Lo, r.Y.Lo} }
go
func (r Rect) Lo() Point { return Point{r.X.Lo, r.Y.Lo} }
[ "func", "(", "r", "Rect", ")", "Lo", "(", ")", "Point", "{", "return", "Point", "{", "r", ".", "X", ".", "Lo", ",", "r", ".", "Y", ".", "Lo", "}", "\n", "}" ]
// Lo returns the low corner of the rect.
[ "Lo", "returns", "the", "low", "corner", "of", "the", "rect", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/r2/rect.go#L140-L142
150,260
golang/geo
r2/rect.go
Hi
func (r Rect) Hi() Point { return Point{r.X.Hi, r.Y.Hi} }
go
func (r Rect) Hi() Point { return Point{r.X.Hi, r.Y.Hi} }
[ "func", "(", "r", "Rect", ")", "Hi", "(", ")", "Point", "{", "return", "Point", "{", "r", ".", "X", ".", "Hi", ",", "r", ".", "Y", ".", "Hi", "}", "\n", "}" ]
// Hi returns the high corner of the rect.
[ "Hi", "returns", "the", "high", "corner", "of", "the", "rect", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/r2/rect.go#L145-L147
150,261
golang/geo
r2/rect.go
ContainsPoint
func (r Rect) ContainsPoint(p Point) bool { return r.X.Contains(p.X) && r.Y.Contains(p.Y) }
go
func (r Rect) ContainsPoint(p Point) bool { return r.X.Contains(p.X) && r.Y.Contains(p.Y) }
[ "func", "(", "r", "Rect", ")", "ContainsPoint", "(", "p", "Point", ")", "bool", "{", "return", "r", ".", "X", ".", "Contains", "(", "p", ".", "X", ")", "&&", "r", ".", "Y", ".", "Contains", "(", "p", ".", "Y", ")", "\n", "}" ]
// ContainsPoint reports whether the rectangle contains the given point. // Rectangles are closed regions, i.e. they contain their boundary.
[ "ContainsPoint", "reports", "whether", "the", "rectangle", "contains", "the", "given", "point", ".", "Rectangles", "are", "closed", "regions", "i", ".", "e", ".", "they", "contain", "their", "boundary", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/r2/rect.go#L162-L164
150,262
golang/geo
r2/rect.go
Contains
func (r Rect) Contains(other Rect) bool { return r.X.ContainsInterval(other.X) && r.Y.ContainsInterval(other.Y) }
go
func (r Rect) Contains(other Rect) bool { return r.X.ContainsInterval(other.X) && r.Y.ContainsInterval(other.Y) }
[ "func", "(", "r", "Rect", ")", "Contains", "(", "other", "Rect", ")", "bool", "{", "return", "r", ".", "X", ".", "ContainsInterval", "(", "other", ".", "X", ")", "&&", "r", ".", "Y", ".", "ContainsInterval", "(", "other", ".", "Y", ")", "\n", "}" ]
// Contains reports whether the rectangle contains the given rectangle.
[ "Contains", "reports", "whether", "the", "rectangle", "contains", "the", "given", "rectangle", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/r2/rect.go#L173-L175
150,263
golang/geo
r2/rect.go
Intersects
func (r Rect) Intersects(other Rect) bool { return r.X.Intersects(other.X) && r.Y.Intersects(other.Y) }
go
func (r Rect) Intersects(other Rect) bool { return r.X.Intersects(other.X) && r.Y.Intersects(other.Y) }
[ "func", "(", "r", "Rect", ")", "Intersects", "(", "other", "Rect", ")", "bool", "{", "return", "r", ".", "X", ".", "Intersects", "(", "other", ".", "X", ")", "&&", "r", ".", "Y", ".", "Intersects", "(", "other", ".", "Y", ")", "\n", "}" ]
// Intersects reports whether this rectangle and the other rectangle have any points in common.
[ "Intersects", "reports", "whether", "this", "rectangle", "and", "the", "other", "rectangle", "have", "any", "points", "in", "common", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/r2/rect.go#L184-L186
150,264
golang/geo
r2/rect.go
AddPoint
func (r Rect) AddPoint(p Point) Rect { return Rect{r.X.AddPoint(p.X), r.Y.AddPoint(p.Y)} }
go
func (r Rect) AddPoint(p Point) Rect { return Rect{r.X.AddPoint(p.X), r.Y.AddPoint(p.Y)} }
[ "func", "(", "r", "Rect", ")", "AddPoint", "(", "p", "Point", ")", "Rect", "{", "return", "Rect", "{", "r", ".", "X", ".", "AddPoint", "(", "p", ".", "X", ")", ",", "r", ".", "Y", ".", "AddPoint", "(", "p", ".", "Y", ")", "}", "\n", "}" ]
// AddPoint expands the rectangle to include the given point. The rectangle is // expanded by the minimum amount possible.
[ "AddPoint", "expands", "the", "rectangle", "to", "include", "the", "given", "point", ".", "The", "rectangle", "is", "expanded", "by", "the", "minimum", "amount", "possible", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/r2/rect.go#L196-L198
150,265
golang/geo
r2/rect.go
ClampPoint
func (r Rect) ClampPoint(p Point) Point { return Point{r.X.ClampPoint(p.X), r.Y.ClampPoint(p.Y)} }
go
func (r Rect) ClampPoint(p Point) Point { return Point{r.X.ClampPoint(p.X), r.Y.ClampPoint(p.Y)} }
[ "func", "(", "r", "Rect", ")", "ClampPoint", "(", "p", "Point", ")", "Point", "{", "return", "Point", "{", "r", ".", "X", ".", "ClampPoint", "(", "p", ".", "X", ")", ",", "r", ".", "Y", ".", "ClampPoint", "(", "p", ".", "Y", ")", "}", "\n", "}" ]
// ClampPoint returns the closest point in the rectangle to the given point. // The rectangle must be non-empty.
[ "ClampPoint", "returns", "the", "closest", "point", "in", "the", "rectangle", "to", "the", "given", "point", ".", "The", "rectangle", "must", "be", "non", "-", "empty", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/r2/rect.go#L209-L211
150,266
golang/geo
r2/rect.go
Expanded
func (r Rect) Expanded(margin Point) Rect { xx := r.X.Expanded(margin.X) yy := r.Y.Expanded(margin.Y) if xx.IsEmpty() || yy.IsEmpty() { return EmptyRect() } return Rect{xx, yy} }
go
func (r Rect) Expanded(margin Point) Rect { xx := r.X.Expanded(margin.X) yy := r.Y.Expanded(margin.Y) if xx.IsEmpty() || yy.IsEmpty() { return EmptyRect() } return Rect{xx, yy} }
[ "func", "(", "r", "Rect", ")", "Expanded", "(", "margin", "Point", ")", "Rect", "{", "xx", ":=", "r", ".", "X", ".", "Expanded", "(", "margin", ".", "X", ")", "\n", "yy", ":=", "r", ".", "Y", ".", "Expanded", "(", "margin", ".", "Y", ")", "\n", "if", "xx", ".", "IsEmpty", "(", ")", "||", "yy", ".", "IsEmpty", "(", ")", "{", "return", "EmptyRect", "(", ")", "\n", "}", "\n", "return", "Rect", "{", "xx", ",", "yy", "}", "\n", "}" ]
// Expanded returns a rectangle that has been expanded in the x-direction // by margin.X, and in y-direction by margin.Y. If either margin is empty, // then shrink the interval on the corresponding sides instead. The resulting // rectangle may be empty. Any expansion of an empty rectangle remains empty.
[ "Expanded", "returns", "a", "rectangle", "that", "has", "been", "expanded", "in", "the", "x", "-", "direction", "by", "margin", ".", "X", "and", "in", "y", "-", "direction", "by", "margin", ".", "Y", ".", "If", "either", "margin", "is", "empty", "then", "shrink", "the", "interval", "on", "the", "corresponding", "sides", "instead", ".", "The", "resulting", "rectangle", "may", "be", "empty", ".", "Any", "expansion", "of", "an", "empty", "rectangle", "remains", "empty", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/r2/rect.go#L217-L224
150,267
golang/geo
r2/rect.go
ExpandedByMargin
func (r Rect) ExpandedByMargin(margin float64) Rect { return r.Expanded(Point{margin, margin}) }
go
func (r Rect) ExpandedByMargin(margin float64) Rect { return r.Expanded(Point{margin, margin}) }
[ "func", "(", "r", "Rect", ")", "ExpandedByMargin", "(", "margin", "float64", ")", "Rect", "{", "return", "r", ".", "Expanded", "(", "Point", "{", "margin", ",", "margin", "}", ")", "\n", "}" ]
// ExpandedByMargin returns a Rect that has been expanded by the amount on all sides.
[ "ExpandedByMargin", "returns", "a", "Rect", "that", "has", "been", "expanded", "by", "the", "amount", "on", "all", "sides", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/r2/rect.go#L227-L229
150,268
golang/geo
r2/rect.go
Union
func (r Rect) Union(other Rect) Rect { return Rect{r.X.Union(other.X), r.Y.Union(other.Y)} }
go
func (r Rect) Union(other Rect) Rect { return Rect{r.X.Union(other.X), r.Y.Union(other.Y)} }
[ "func", "(", "r", "Rect", ")", "Union", "(", "other", "Rect", ")", "Rect", "{", "return", "Rect", "{", "r", ".", "X", ".", "Union", "(", "other", ".", "X", ")", ",", "r", ".", "Y", ".", "Union", "(", "other", ".", "Y", ")", "}", "\n", "}" ]
// Union returns the smallest rectangle containing the union of this rectangle and // the given rectangle.
[ "Union", "returns", "the", "smallest", "rectangle", "containing", "the", "union", "of", "this", "rectangle", "and", "the", "given", "rectangle", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/r2/rect.go#L233-L235
150,269
golang/geo
r2/rect.go
Intersection
func (r Rect) Intersection(other Rect) Rect { xx := r.X.Intersection(other.X) yy := r.Y.Intersection(other.Y) if xx.IsEmpty() || yy.IsEmpty() { return EmptyRect() } return Rect{xx, yy} }
go
func (r Rect) Intersection(other Rect) Rect { xx := r.X.Intersection(other.X) yy := r.Y.Intersection(other.Y) if xx.IsEmpty() || yy.IsEmpty() { return EmptyRect() } return Rect{xx, yy} }
[ "func", "(", "r", "Rect", ")", "Intersection", "(", "other", "Rect", ")", "Rect", "{", "xx", ":=", "r", ".", "X", ".", "Intersection", "(", "other", ".", "X", ")", "\n", "yy", ":=", "r", ".", "Y", ".", "Intersection", "(", "other", ".", "Y", ")", "\n", "if", "xx", ".", "IsEmpty", "(", ")", "||", "yy", ".", "IsEmpty", "(", ")", "{", "return", "EmptyRect", "(", ")", "\n", "}", "\n\n", "return", "Rect", "{", "xx", ",", "yy", "}", "\n", "}" ]
// Intersection returns the smallest rectangle containing the intersection of this // rectangle and the given rectangle.
[ "Intersection", "returns", "the", "smallest", "rectangle", "containing", "the", "intersection", "of", "this", "rectangle", "and", "the", "given", "rectangle", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/r2/rect.go#L239-L247
150,270
golang/geo
s2/edge_tessellator.go
NewEdgeTessellator
func NewEdgeTessellator(p Projection, tolerance s1.Angle) *EdgeTessellator { return &EdgeTessellator{ projection: p, tolerance: s1.ChordAngleFromAngle(maxAngle(tolerance, MinTessellationTolerance)), wrapDistance: p.WrapDistance(), } }
go
func NewEdgeTessellator(p Projection, tolerance s1.Angle) *EdgeTessellator { return &EdgeTessellator{ projection: p, tolerance: s1.ChordAngleFromAngle(maxAngle(tolerance, MinTessellationTolerance)), wrapDistance: p.WrapDistance(), } }
[ "func", "NewEdgeTessellator", "(", "p", "Projection", ",", "tolerance", "s1", ".", "Angle", ")", "*", "EdgeTessellator", "{", "return", "&", "EdgeTessellator", "{", "projection", ":", "p", ",", "tolerance", ":", "s1", ".", "ChordAngleFromAngle", "(", "maxAngle", "(", "tolerance", ",", "MinTessellationTolerance", ")", ")", ",", "wrapDistance", ":", "p", ".", "WrapDistance", "(", ")", ",", "}", "\n", "}" ]
// NewEdgeTessellator creates a new edge tessellator for the given projection and tolerance.
[ "NewEdgeTessellator", "creates", "a", "new", "edge", "tessellator", "for", "the", "given", "projection", "and", "tolerance", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/edge_tessellator.go#L50-L56
150,271
golang/geo
s2/edge_tessellator.go
appendUnprojected
func (e *EdgeTessellator) appendUnprojected(pa r2.Point, a Point, pb r2.Point, b Point, vertices []Point) []Point { pmid := e.projection.Interpolate(0.5, pa, pb) mid := e.projection.Unproject(pmid) testMid := Point{a.Add(b.Vector).Normalize()} if ChordAngleBetweenPoints(mid, testMid) < e.tolerance { return append(vertices, b) } vertices = e.appendUnprojected(pa, a, pmid, mid, vertices) return e.appendUnprojected(pmid, mid, pb, b, vertices) }
go
func (e *EdgeTessellator) appendUnprojected(pa r2.Point, a Point, pb r2.Point, b Point, vertices []Point) []Point { pmid := e.projection.Interpolate(0.5, pa, pb) mid := e.projection.Unproject(pmid) testMid := Point{a.Add(b.Vector).Normalize()} if ChordAngleBetweenPoints(mid, testMid) < e.tolerance { return append(vertices, b) } vertices = e.appendUnprojected(pa, a, pmid, mid, vertices) return e.appendUnprojected(pmid, mid, pb, b, vertices) }
[ "func", "(", "e", "*", "EdgeTessellator", ")", "appendUnprojected", "(", "pa", "r2", ".", "Point", ",", "a", "Point", ",", "pb", "r2", ".", "Point", ",", "b", "Point", ",", "vertices", "[", "]", "Point", ")", "[", "]", "Point", "{", "pmid", ":=", "e", ".", "projection", ".", "Interpolate", "(", "0.5", ",", "pa", ",", "pb", ")", "\n", "mid", ":=", "e", ".", "projection", ".", "Unproject", "(", "pmid", ")", "\n", "testMid", ":=", "Point", "{", "a", ".", "Add", "(", "b", ".", "Vector", ")", ".", "Normalize", "(", ")", "}", "\n\n", "if", "ChordAngleBetweenPoints", "(", "mid", ",", "testMid", ")", "<", "e", ".", "tolerance", "{", "return", "append", "(", "vertices", ",", "b", ")", "\n", "}", "\n\n", "vertices", "=", "e", ".", "appendUnprojected", "(", "pa", ",", "a", ",", "pmid", ",", "mid", ",", "vertices", ")", "\n", "return", "e", ".", "appendUnprojected", "(", "pmid", ",", "mid", ",", "pb", ",", "b", ",", "vertices", ")", "\n", "}" ]
// appendUnprojected interpolates a projected edge and appends the corresponding // points on the sphere.
[ "appendUnprojected", "interpolates", "a", "projected", "edge", "and", "appends", "the", "corresponding", "points", "on", "the", "sphere", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/edge_tessellator.go#L141-L152
150,272
golang/geo
s2/edge_tessellator.go
wrapDestination
func (e *EdgeTessellator) wrapDestination(pa, pb r2.Point) r2.Point { x := pb.X y := pb.Y // The code below ensures that pb is unmodified unless wrapping is required. if e.wrapDistance.X > 0 && math.Abs(x-pa.X) > 0.5*e.wrapDistance.X { x = pa.X + math.Remainder(x-pa.X, e.wrapDistance.X) } if e.wrapDistance.Y > 0 && math.Abs(y-pa.Y) > 0.5*e.wrapDistance.Y { y = pa.Y + math.Remainder(y-pa.Y, e.wrapDistance.Y) } return r2.Point{x, y} }
go
func (e *EdgeTessellator) wrapDestination(pa, pb r2.Point) r2.Point { x := pb.X y := pb.Y // The code below ensures that pb is unmodified unless wrapping is required. if e.wrapDistance.X > 0 && math.Abs(x-pa.X) > 0.5*e.wrapDistance.X { x = pa.X + math.Remainder(x-pa.X, e.wrapDistance.X) } if e.wrapDistance.Y > 0 && math.Abs(y-pa.Y) > 0.5*e.wrapDistance.Y { y = pa.Y + math.Remainder(y-pa.Y, e.wrapDistance.Y) } return r2.Point{x, y} }
[ "func", "(", "e", "*", "EdgeTessellator", ")", "wrapDestination", "(", "pa", ",", "pb", "r2", ".", "Point", ")", "r2", ".", "Point", "{", "x", ":=", "pb", ".", "X", "\n", "y", ":=", "pb", ".", "Y", "\n", "// The code below ensures that pb is unmodified unless wrapping is required.", "if", "e", ".", "wrapDistance", ".", "X", ">", "0", "&&", "math", ".", "Abs", "(", "x", "-", "pa", ".", "X", ")", ">", "0.5", "*", "e", ".", "wrapDistance", ".", "X", "{", "x", "=", "pa", ".", "X", "+", "math", ".", "Remainder", "(", "x", "-", "pa", ".", "X", ",", "e", ".", "wrapDistance", ".", "X", ")", "\n", "}", "\n", "if", "e", ".", "wrapDistance", ".", "Y", ">", "0", "&&", "math", ".", "Abs", "(", "y", "-", "pa", ".", "Y", ")", ">", "0.5", "*", "e", ".", "wrapDistance", ".", "Y", "{", "y", "=", "pa", ".", "Y", "+", "math", ".", "Remainder", "(", "y", "-", "pa", ".", "Y", ",", "e", ".", "wrapDistance", ".", "Y", ")", "\n", "}", "\n", "return", "r2", ".", "Point", "{", "x", ",", "y", "}", "\n", "}" ]
// wrapDestination returns the coordinates of the edge destination wrapped if // necessary to obtain the shortest edge.
[ "wrapDestination", "returns", "the", "coordinates", "of", "the", "edge", "destination", "wrapped", "if", "necessary", "to", "obtain", "the", "shortest", "edge", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/edge_tessellator.go#L156-L167
150,273
golang/geo
s2/shapeutil.go
newRangeIterator
func newRangeIterator(index *ShapeIndex) *rangeIterator { r := &rangeIterator{ it: index.Iterator(), } r.refresh() return r }
go
func newRangeIterator(index *ShapeIndex) *rangeIterator { r := &rangeIterator{ it: index.Iterator(), } r.refresh() return r }
[ "func", "newRangeIterator", "(", "index", "*", "ShapeIndex", ")", "*", "rangeIterator", "{", "r", ":=", "&", "rangeIterator", "{", "it", ":", "index", ".", "Iterator", "(", ")", ",", "}", "\n", "r", ".", "refresh", "(", ")", "\n", "return", "r", "\n", "}" ]
// newRangeIterator creates a new rangeIterator positioned at the first cell of the given index.
[ "newRangeIterator", "creates", "a", "new", "rangeIterator", "positioned", "at", "the", "first", "cell", "of", "the", "given", "index", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/shapeutil.go#L45-L51
150,274
golang/geo
s2/shapeutil.go
seekTo
func (r *rangeIterator) seekTo(target *rangeIterator) { r.it.seek(target.rangeMin) // If the current cell does not overlap target, it is possible that the // previous cell is the one we are looking for. This can only happen when // the previous cell contains target but has a smaller CellID. if r.it.Done() || r.it.CellID().RangeMin() > target.rangeMax { if r.it.Prev() && r.it.CellID().RangeMax() < target.cellID() { r.it.Next() } } r.refresh() }
go
func (r *rangeIterator) seekTo(target *rangeIterator) { r.it.seek(target.rangeMin) // If the current cell does not overlap target, it is possible that the // previous cell is the one we are looking for. This can only happen when // the previous cell contains target but has a smaller CellID. if r.it.Done() || r.it.CellID().RangeMin() > target.rangeMax { if r.it.Prev() && r.it.CellID().RangeMax() < target.cellID() { r.it.Next() } } r.refresh() }
[ "func", "(", "r", "*", "rangeIterator", ")", "seekTo", "(", "target", "*", "rangeIterator", ")", "{", "r", ".", "it", ".", "seek", "(", "target", ".", "rangeMin", ")", "\n", "// If the current cell does not overlap target, it is possible that the", "// previous cell is the one we are looking for. This can only happen when", "// the previous cell contains target but has a smaller CellID.", "if", "r", ".", "it", ".", "Done", "(", ")", "||", "r", ".", "it", ".", "CellID", "(", ")", ".", "RangeMin", "(", ")", ">", "target", ".", "rangeMax", "{", "if", "r", ".", "it", ".", "Prev", "(", ")", "&&", "r", ".", "it", ".", "CellID", "(", ")", ".", "RangeMax", "(", ")", "<", "target", ".", "cellID", "(", ")", "{", "r", ".", "it", ".", "Next", "(", ")", "\n", "}", "\n", "}", "\n", "r", ".", "refresh", "(", ")", "\n", "}" ]
// seekTo positions the iterator at the first cell that overlaps or follows // the current range minimum of the target iterator, i.e. such that its // rangeMax >= target.rangeMin.
[ "seekTo", "positions", "the", "iterator", "at", "the", "first", "cell", "that", "overlaps", "or", "follows", "the", "current", "range", "minimum", "of", "the", "target", "iterator", "i", ".", "e", ".", "such", "that", "its", "rangeMax", ">", "=", "target", ".", "rangeMin", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/shapeutil.go#L61-L72
150,275
golang/geo
s2/shapeutil.go
seekBeyond
func (r *rangeIterator) seekBeyond(target *rangeIterator) { r.it.seek(target.rangeMax.Next()) if !r.it.Done() && r.it.CellID().RangeMin() <= target.rangeMax { r.it.Next() } r.refresh() }
go
func (r *rangeIterator) seekBeyond(target *rangeIterator) { r.it.seek(target.rangeMax.Next()) if !r.it.Done() && r.it.CellID().RangeMin() <= target.rangeMax { r.it.Next() } r.refresh() }
[ "func", "(", "r", "*", "rangeIterator", ")", "seekBeyond", "(", "target", "*", "rangeIterator", ")", "{", "r", ".", "it", ".", "seek", "(", "target", ".", "rangeMax", ".", "Next", "(", ")", ")", "\n", "if", "!", "r", ".", "it", ".", "Done", "(", ")", "&&", "r", ".", "it", ".", "CellID", "(", ")", ".", "RangeMin", "(", ")", "<=", "target", ".", "rangeMax", "{", "r", ".", "it", ".", "Next", "(", ")", "\n", "}", "\n", "r", ".", "refresh", "(", ")", "\n", "}" ]
// seekBeyond positions the iterator at the first cell that follows the current // range minimum of the target iterator. i.e. the first cell such that its // rangeMin > target.rangeMax.
[ "seekBeyond", "positions", "the", "iterator", "at", "the", "first", "cell", "that", "follows", "the", "current", "range", "minimum", "of", "the", "target", "iterator", ".", "i", ".", "e", ".", "the", "first", "cell", "such", "that", "its", "rangeMin", ">", "target", ".", "rangeMax", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/shapeutil.go#L77-L83
150,276
golang/geo
s2/shapeutil.go
refresh
func (r *rangeIterator) refresh() { r.rangeMin = r.cellID().RangeMin() r.rangeMax = r.cellID().RangeMax() }
go
func (r *rangeIterator) refresh() { r.rangeMin = r.cellID().RangeMin() r.rangeMax = r.cellID().RangeMax() }
[ "func", "(", "r", "*", "rangeIterator", ")", "refresh", "(", ")", "{", "r", ".", "rangeMin", "=", "r", ".", "cellID", "(", ")", ".", "RangeMin", "(", ")", "\n", "r", ".", "rangeMax", "=", "r", ".", "cellID", "(", ")", ".", "RangeMax", "(", ")", "\n", "}" ]
// refresh updates the iterators min and max values.
[ "refresh", "updates", "the", "iterators", "min", "and", "max", "values", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/shapeutil.go#L86-L89
150,277
golang/geo
s2/shapeutil.go
referencePointAtVertex
func referencePointAtVertex(shape Shape, vTest Point) (ReferencePoint, bool) { var ref ReferencePoint // Let P be an unbalanced vertex. Vertex P is defined to be inside the // region if the region contains a particular direction vector starting from // P, namely the direction p.Ortho(). This can be calculated using // ContainsVertexQuery. containsQuery := NewContainsVertexQuery(vTest) n := shape.NumEdges() for e := 0; e < n; e++ { edge := shape.Edge(e) if edge.V0 == vTest { containsQuery.AddEdge(edge.V1, 1) } if edge.V1 == vTest { containsQuery.AddEdge(edge.V0, -1) } } containsSign := containsQuery.ContainsVertex() if containsSign == 0 { return ref, false // There are no unmatched edges incident to this vertex. } ref.Point = vTest ref.Contained = containsSign > 0 return ref, true }
go
func referencePointAtVertex(shape Shape, vTest Point) (ReferencePoint, bool) { var ref ReferencePoint // Let P be an unbalanced vertex. Vertex P is defined to be inside the // region if the region contains a particular direction vector starting from // P, namely the direction p.Ortho(). This can be calculated using // ContainsVertexQuery. containsQuery := NewContainsVertexQuery(vTest) n := shape.NumEdges() for e := 0; e < n; e++ { edge := shape.Edge(e) if edge.V0 == vTest { containsQuery.AddEdge(edge.V1, 1) } if edge.V1 == vTest { containsQuery.AddEdge(edge.V0, -1) } } containsSign := containsQuery.ContainsVertex() if containsSign == 0 { return ref, false // There are no unmatched edges incident to this vertex. } ref.Point = vTest ref.Contained = containsSign > 0 return ref, true }
[ "func", "referencePointAtVertex", "(", "shape", "Shape", ",", "vTest", "Point", ")", "(", "ReferencePoint", ",", "bool", ")", "{", "var", "ref", "ReferencePoint", "\n\n", "// Let P be an unbalanced vertex. Vertex P is defined to be inside the", "// region if the region contains a particular direction vector starting from", "// P, namely the direction p.Ortho(). This can be calculated using", "// ContainsVertexQuery.", "containsQuery", ":=", "NewContainsVertexQuery", "(", "vTest", ")", "\n", "n", ":=", "shape", ".", "NumEdges", "(", ")", "\n", "for", "e", ":=", "0", ";", "e", "<", "n", ";", "e", "++", "{", "edge", ":=", "shape", ".", "Edge", "(", "e", ")", "\n", "if", "edge", ".", "V0", "==", "vTest", "{", "containsQuery", ".", "AddEdge", "(", "edge", ".", "V1", ",", "1", ")", "\n", "}", "\n", "if", "edge", ".", "V1", "==", "vTest", "{", "containsQuery", ".", "AddEdge", "(", "edge", ".", "V0", ",", "-", "1", ")", "\n", "}", "\n", "}", "\n", "containsSign", ":=", "containsQuery", ".", "ContainsVertex", "(", ")", "\n", "if", "containsSign", "==", "0", "{", "return", "ref", ",", "false", "// There are no unmatched edges incident to this vertex.", "\n", "}", "\n", "ref", ".", "Point", "=", "vTest", "\n", "ref", ".", "Contained", "=", "containsSign", ">", "0", "\n\n", "return", "ref", ",", "true", "\n", "}" ]
// referencePointAtVertex reports whether the given vertex is unbalanced, and // returns a ReferencePoint indicating if the point is contained. // Otherwise returns false.
[ "referencePointAtVertex", "reports", "whether", "the", "given", "vertex", "is", "unbalanced", "and", "returns", "a", "ReferencePoint", "indicating", "if", "the", "point", "is", "contained", ".", "Otherwise", "returns", "false", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/shapeutil.go#L174-L201
150,278
golang/geo
s2/contains_vertex_query.go
NewContainsVertexQuery
func NewContainsVertexQuery(target Point) *ContainsVertexQuery { return &ContainsVertexQuery{ target: target, edgeMap: make(map[Point]int), } }
go
func NewContainsVertexQuery(target Point) *ContainsVertexQuery { return &ContainsVertexQuery{ target: target, edgeMap: make(map[Point]int), } }
[ "func", "NewContainsVertexQuery", "(", "target", "Point", ")", "*", "ContainsVertexQuery", "{", "return", "&", "ContainsVertexQuery", "{", "target", ":", "target", ",", "edgeMap", ":", "make", "(", "map", "[", "Point", "]", "int", ")", ",", "}", "\n", "}" ]
// NewContainsVertexQuery returns a new query for the given vertex whose // containment will be determined.
[ "NewContainsVertexQuery", "returns", "a", "new", "query", "for", "the", "given", "vertex", "whose", "containment", "will", "be", "determined", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/contains_vertex_query.go#L31-L36
150,279
golang/geo
s2/contains_vertex_query.go
ContainsVertex
func (q *ContainsVertexQuery) ContainsVertex() int { // Find the unmatched edge that is immediately clockwise from Ortho(P). referenceDir := Point{q.target.Ortho()} bestPoint := referenceDir bestDir := 0 for k, v := range q.edgeMap { if v == 0 { continue // This is a "matched" edge. } if OrderedCCW(referenceDir, bestPoint, k, q.target) { bestPoint = k bestDir = v } } return bestDir }
go
func (q *ContainsVertexQuery) ContainsVertex() int { // Find the unmatched edge that is immediately clockwise from Ortho(P). referenceDir := Point{q.target.Ortho()} bestPoint := referenceDir bestDir := 0 for k, v := range q.edgeMap { if v == 0 { continue // This is a "matched" edge. } if OrderedCCW(referenceDir, bestPoint, k, q.target) { bestPoint = k bestDir = v } } return bestDir }
[ "func", "(", "q", "*", "ContainsVertexQuery", ")", "ContainsVertex", "(", ")", "int", "{", "// Find the unmatched edge that is immediately clockwise from Ortho(P).", "referenceDir", ":=", "Point", "{", "q", ".", "target", ".", "Ortho", "(", ")", "}", "\n\n", "bestPoint", ":=", "referenceDir", "\n", "bestDir", ":=", "0", "\n\n", "for", "k", ",", "v", ":=", "range", "q", ".", "edgeMap", "{", "if", "v", "==", "0", "{", "continue", "// This is a \"matched\" edge.", "\n", "}", "\n", "if", "OrderedCCW", "(", "referenceDir", ",", "bestPoint", ",", "k", ",", "q", ".", "target", ")", "{", "bestPoint", "=", "k", "\n", "bestDir", "=", "v", "\n", "}", "\n", "}", "\n", "return", "bestDir", "\n", "}" ]
// ContainsVertex reports a +1 if the target vertex is contained, -1 if it is // not contained, and 0 if the incident edges consisted of matched sibling pairs.
[ "ContainsVertex", "reports", "a", "+", "1", "if", "the", "target", "vertex", "is", "contained", "-", "1", "if", "it", "is", "not", "contained", "and", "0", "if", "the", "incident", "edges", "consisted", "of", "matched", "sibling", "pairs", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/contains_vertex_query.go#L46-L63
150,280
docopt/docopt.go
examples/config_file/config_file.go
merge
func merge(mapA, mapB map[string]interface{}) map[string]interface{} { result := make(map[string]interface{}) for k, v := range mapA { result[k] = v } for k, v := range mapB { if _, ok := result[k]; !ok || result[k] == nil || result[k] == false { result[k] = v } } return result }
go
func merge(mapA, mapB map[string]interface{}) map[string]interface{} { result := make(map[string]interface{}) for k, v := range mapA { result[k] = v } for k, v := range mapB { if _, ok := result[k]; !ok || result[k] == nil || result[k] == false { result[k] = v } } return result }
[ "func", "merge", "(", "mapA", ",", "mapB", "map", "[", "string", "]", "interface", "{", "}", ")", "map", "[", "string", "]", "interface", "{", "}", "{", "result", ":=", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "for", "k", ",", "v", ":=", "range", "mapA", "{", "result", "[", "k", "]", "=", "v", "\n", "}", "\n", "for", "k", ",", "v", ":=", "range", "mapB", "{", "if", "_", ",", "ok", ":=", "result", "[", "k", "]", ";", "!", "ok", "||", "result", "[", "k", "]", "==", "nil", "||", "result", "[", "k", "]", "==", "false", "{", "result", "[", "k", "]", "=", "v", "\n", "}", "\n", "}", "\n", "return", "result", "\n", "}" ]
// merge combines two maps. // truthiness takes priority over falsiness // mapA takes priority over mapB
[ "merge", "combines", "two", "maps", ".", "truthiness", "takes", "priority", "over", "falsiness", "mapA", "takes", "priority", "over", "mapB" ]
ee0de3bc6815ee19d4a46c7eb90f829db0e014b1
https://github.com/docopt/docopt.go/blob/ee0de3bc6815ee19d4a46c7eb90f829db0e014b1/examples/config_file/config_file.go#L47-L58
150,281
docopt/docopt.go
opts.go
guessUntaggedField
func guessUntaggedField(key string) string { switch { case strings.HasPrefix(key, "--") && len(key[2:]) > 1: return titleCaseDashes(key[2:]) case strings.HasPrefix(key, "-") && len(key[1:]) == 1: return titleCaseDashes(key[1:]) case strings.HasPrefix(key, "<") && strings.HasSuffix(key, ">"): key = key[1 : len(key)-1] } return strings.Title(strings.ToLower(key)) }
go
func guessUntaggedField(key string) string { switch { case strings.HasPrefix(key, "--") && len(key[2:]) > 1: return titleCaseDashes(key[2:]) case strings.HasPrefix(key, "-") && len(key[1:]) == 1: return titleCaseDashes(key[1:]) case strings.HasPrefix(key, "<") && strings.HasSuffix(key, ">"): key = key[1 : len(key)-1] } return strings.Title(strings.ToLower(key)) }
[ "func", "guessUntaggedField", "(", "key", "string", ")", "string", "{", "switch", "{", "case", "strings", ".", "HasPrefix", "(", "key", ",", "\"", "\"", ")", "&&", "len", "(", "key", "[", "2", ":", "]", ")", ">", "1", ":", "return", "titleCaseDashes", "(", "key", "[", "2", ":", "]", ")", "\n", "case", "strings", ".", "HasPrefix", "(", "key", ",", "\"", "\"", ")", "&&", "len", "(", "key", "[", "1", ":", "]", ")", "==", "1", ":", "return", "titleCaseDashes", "(", "key", "[", "1", ":", "]", ")", "\n", "case", "strings", ".", "HasPrefix", "(", "key", ",", "\"", "\"", ")", "&&", "strings", ".", "HasSuffix", "(", "key", ",", "\"", "\"", ")", ":", "key", "=", "key", "[", "1", ":", "len", "(", "key", ")", "-", "1", "]", "\n", "}", "\n", "return", "strings", ".", "Title", "(", "strings", ".", "ToLower", "(", "key", ")", ")", "\n", "}" ]
// Best guess which field.Name in a struct to assign for an option key.
[ "Best", "guess", "which", "field", ".", "Name", "in", "a", "struct", "to", "assign", "for", "an", "option", "key", "." ]
ee0de3bc6815ee19d4a46c7eb90f829db0e014b1
https://github.com/docopt/docopt.go/blob/ee0de3bc6815ee19d4a46c7eb90f829db0e014b1/opts.go#L254-L264
150,282
docopt/docopt.go
token.go
isStringUppercase
func isStringUppercase(s string) bool { if strings.ToUpper(s) != s { return false } for _, c := range []rune(s) { if unicode.IsUpper(c) { return true } } return false }
go
func isStringUppercase(s string) bool { if strings.ToUpper(s) != s { return false } for _, c := range []rune(s) { if unicode.IsUpper(c) { return true } } return false }
[ "func", "isStringUppercase", "(", "s", "string", ")", "bool", "{", "if", "strings", ".", "ToUpper", "(", "s", ")", "!=", "s", "{", "return", "false", "\n", "}", "\n", "for", "_", ",", "c", ":=", "range", "[", "]", "rune", "(", "s", ")", "{", "if", "unicode", ".", "IsUpper", "(", "c", ")", "{", "return", "true", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}" ]
// returns true if all cased characters in the string are uppercase // and there are there is at least one cased charcter
[ "returns", "true", "if", "all", "cased", "characters", "in", "the", "string", "are", "uppercase", "and", "there", "are", "there", "is", "at", "least", "one", "cased", "charcter" ]
ee0de3bc6815ee19d4a46c7eb90f829db0e014b1
https://github.com/docopt/docopt.go/blob/ee0de3bc6815ee19d4a46c7eb90f829db0e014b1/token.go#L116-L126
150,283
rubenv/sql-migrate
sqlparse/sqlparse.go
endsWithSemicolon
func endsWithSemicolon(line string) bool { prev := "" scanner := bufio.NewScanner(strings.NewReader(line)) scanner.Split(bufio.ScanWords) for scanner.Scan() { word := scanner.Text() if strings.HasPrefix(word, "--") { break } prev = word } return strings.HasSuffix(prev, ";") }
go
func endsWithSemicolon(line string) bool { prev := "" scanner := bufio.NewScanner(strings.NewReader(line)) scanner.Split(bufio.ScanWords) for scanner.Scan() { word := scanner.Text() if strings.HasPrefix(word, "--") { break } prev = word } return strings.HasSuffix(prev, ";") }
[ "func", "endsWithSemicolon", "(", "line", "string", ")", "bool", "{", "prev", ":=", "\"", "\"", "\n", "scanner", ":=", "bufio", ".", "NewScanner", "(", "strings", ".", "NewReader", "(", "line", ")", ")", "\n", "scanner", ".", "Split", "(", "bufio", ".", "ScanWords", ")", "\n\n", "for", "scanner", ".", "Scan", "(", ")", "{", "word", ":=", "scanner", ".", "Text", "(", ")", "\n", "if", "strings", ".", "HasPrefix", "(", "word", ",", "\"", "\"", ")", "{", "break", "\n", "}", "\n", "prev", "=", "word", "\n", "}", "\n\n", "return", "strings", ".", "HasSuffix", "(", "prev", ",", "\"", "\"", ")", "\n", "}" ]
// Checks the line to see if the line has a statement-ending semicolon // or if the line contains a double-dash comment.
[ "Checks", "the", "line", "to", "see", "if", "the", "line", "has", "a", "statement", "-", "ending", "semicolon", "or", "if", "the", "line", "contains", "a", "double", "-", "dash", "comment", "." ]
54bad0a9b051368ffec9cd2b869789c2b8eaea35
https://github.com/rubenv/sql-migrate/blob/54bad0a9b051368ffec9cd2b869789c2b8eaea35/sqlparse/sqlparse.go#L47-L62
150,284
rubenv/sql-migrate
migrate.go
Exec
func Exec(db *sql.DB, dialect string, m MigrationSource, dir MigrationDirection) (int, error) { return ExecMax(db, dialect, m, dir, 0) }
go
func Exec(db *sql.DB, dialect string, m MigrationSource, dir MigrationDirection) (int, error) { return ExecMax(db, dialect, m, dir, 0) }
[ "func", "Exec", "(", "db", "*", "sql", ".", "DB", ",", "dialect", "string", ",", "m", "MigrationSource", ",", "dir", "MigrationDirection", ")", "(", "int", ",", "error", ")", "{", "return", "ExecMax", "(", "db", ",", "dialect", ",", "m", ",", "dir", ",", "0", ")", "\n", "}" ]
// Execute a set of migrations // // Returns the number of applied migrations.
[ "Execute", "a", "set", "of", "migrations", "Returns", "the", "number", "of", "applied", "migrations", "." ]
54bad0a9b051368ffec9cd2b869789c2b8eaea35
https://github.com/rubenv/sql-migrate/blob/54bad0a9b051368ffec9cd2b869789c2b8eaea35/migrate.go#L365-L367
150,285
rubenv/sql-migrate
migrate.go
PlanMigration
func PlanMigration(db *sql.DB, dialect string, m MigrationSource, dir MigrationDirection, max int) ([]*PlannedMigration, *gorp.DbMap, error) { dbMap, err := getMigrationDbMap(db, dialect) if err != nil { return nil, nil, err } migrations, err := m.FindMigrations() if err != nil { return nil, nil, err } var migrationRecords []MigrationRecord _, err = dbMap.Select(&migrationRecords, fmt.Sprintf("SELECT * FROM %s", dbMap.Dialect.QuotedTableForQuery(schemaName, tableName))) if err != nil { return nil, nil, err } // Sort migrations that have been run by Id. var existingMigrations []*Migration for _, migrationRecord := range migrationRecords { existingMigrations = append(existingMigrations, &Migration{ Id: migrationRecord.Id, }) } sort.Sort(byId(existingMigrations)) // Make sure all migrations in the database are among the found migrations which // are to be applied. migrationsSearch := make(map[string]struct{}) for _, migration := range migrations { migrationsSearch[migration.Id] = struct{}{} } for _, existingMigration := range existingMigrations { if _, ok := migrationsSearch[existingMigration.Id]; !ok { return nil, nil, newPlanError(existingMigration, "unknown migration in database") } } // Get last migration that was run record := &Migration{} if len(existingMigrations) > 0 { record = existingMigrations[len(existingMigrations)-1] } result := make([]*PlannedMigration, 0) // Add missing migrations up to the last run migration. // This can happen for example when merges happened. if len(existingMigrations) > 0 { result = append(result, ToCatchup(migrations, existingMigrations, record)...) } // Figure out which migrations to apply toApply := ToApply(migrations, record.Id, dir) toApplyCount := len(toApply) if max > 0 && max < toApplyCount { toApplyCount = max } for _, v := range toApply[0:toApplyCount] { if dir == Up { result = append(result, &PlannedMigration{ Migration: v, Queries: v.Up, DisableTransaction: v.DisableTransactionUp, }) } else if dir == Down { result = append(result, &PlannedMigration{ Migration: v, Queries: v.Down, DisableTransaction: v.DisableTransactionDown, }) } } return result, dbMap, nil }
go
func PlanMigration(db *sql.DB, dialect string, m MigrationSource, dir MigrationDirection, max int) ([]*PlannedMigration, *gorp.DbMap, error) { dbMap, err := getMigrationDbMap(db, dialect) if err != nil { return nil, nil, err } migrations, err := m.FindMigrations() if err != nil { return nil, nil, err } var migrationRecords []MigrationRecord _, err = dbMap.Select(&migrationRecords, fmt.Sprintf("SELECT * FROM %s", dbMap.Dialect.QuotedTableForQuery(schemaName, tableName))) if err != nil { return nil, nil, err } // Sort migrations that have been run by Id. var existingMigrations []*Migration for _, migrationRecord := range migrationRecords { existingMigrations = append(existingMigrations, &Migration{ Id: migrationRecord.Id, }) } sort.Sort(byId(existingMigrations)) // Make sure all migrations in the database are among the found migrations which // are to be applied. migrationsSearch := make(map[string]struct{}) for _, migration := range migrations { migrationsSearch[migration.Id] = struct{}{} } for _, existingMigration := range existingMigrations { if _, ok := migrationsSearch[existingMigration.Id]; !ok { return nil, nil, newPlanError(existingMigration, "unknown migration in database") } } // Get last migration that was run record := &Migration{} if len(existingMigrations) > 0 { record = existingMigrations[len(existingMigrations)-1] } result := make([]*PlannedMigration, 0) // Add missing migrations up to the last run migration. // This can happen for example when merges happened. if len(existingMigrations) > 0 { result = append(result, ToCatchup(migrations, existingMigrations, record)...) } // Figure out which migrations to apply toApply := ToApply(migrations, record.Id, dir) toApplyCount := len(toApply) if max > 0 && max < toApplyCount { toApplyCount = max } for _, v := range toApply[0:toApplyCount] { if dir == Up { result = append(result, &PlannedMigration{ Migration: v, Queries: v.Up, DisableTransaction: v.DisableTransactionUp, }) } else if dir == Down { result = append(result, &PlannedMigration{ Migration: v, Queries: v.Down, DisableTransaction: v.DisableTransactionDown, }) } } return result, dbMap, nil }
[ "func", "PlanMigration", "(", "db", "*", "sql", ".", "DB", ",", "dialect", "string", ",", "m", "MigrationSource", ",", "dir", "MigrationDirection", ",", "max", "int", ")", "(", "[", "]", "*", "PlannedMigration", ",", "*", "gorp", ".", "DbMap", ",", "error", ")", "{", "dbMap", ",", "err", ":=", "getMigrationDbMap", "(", "db", ",", "dialect", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "nil", ",", "err", "\n", "}", "\n\n", "migrations", ",", "err", ":=", "m", ".", "FindMigrations", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "nil", ",", "err", "\n", "}", "\n\n", "var", "migrationRecords", "[", "]", "MigrationRecord", "\n", "_", ",", "err", "=", "dbMap", ".", "Select", "(", "&", "migrationRecords", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "dbMap", ".", "Dialect", ".", "QuotedTableForQuery", "(", "schemaName", ",", "tableName", ")", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "nil", ",", "err", "\n", "}", "\n\n", "// Sort migrations that have been run by Id.", "var", "existingMigrations", "[", "]", "*", "Migration", "\n", "for", "_", ",", "migrationRecord", ":=", "range", "migrationRecords", "{", "existingMigrations", "=", "append", "(", "existingMigrations", ",", "&", "Migration", "{", "Id", ":", "migrationRecord", ".", "Id", ",", "}", ")", "\n", "}", "\n", "sort", ".", "Sort", "(", "byId", "(", "existingMigrations", ")", ")", "\n\n", "// Make sure all migrations in the database are among the found migrations which", "// are to be applied.", "migrationsSearch", ":=", "make", "(", "map", "[", "string", "]", "struct", "{", "}", ")", "\n", "for", "_", ",", "migration", ":=", "range", "migrations", "{", "migrationsSearch", "[", "migration", ".", "Id", "]", "=", "struct", "{", "}", "{", "}", "\n", "}", "\n", "for", "_", ",", "existingMigration", ":=", "range", "existingMigrations", "{", "if", "_", ",", "ok", ":=", "migrationsSearch", "[", "existingMigration", ".", "Id", "]", ";", "!", "ok", "{", "return", "nil", ",", "nil", ",", "newPlanError", "(", "existingMigration", ",", "\"", "\"", ")", "\n", "}", "\n", "}", "\n\n", "// Get last migration that was run", "record", ":=", "&", "Migration", "{", "}", "\n", "if", "len", "(", "existingMigrations", ")", ">", "0", "{", "record", "=", "existingMigrations", "[", "len", "(", "existingMigrations", ")", "-", "1", "]", "\n", "}", "\n\n", "result", ":=", "make", "(", "[", "]", "*", "PlannedMigration", ",", "0", ")", "\n\n", "// Add missing migrations up to the last run migration.", "// This can happen for example when merges happened.", "if", "len", "(", "existingMigrations", ")", ">", "0", "{", "result", "=", "append", "(", "result", ",", "ToCatchup", "(", "migrations", ",", "existingMigrations", ",", "record", ")", "...", ")", "\n", "}", "\n\n", "// Figure out which migrations to apply", "toApply", ":=", "ToApply", "(", "migrations", ",", "record", ".", "Id", ",", "dir", ")", "\n", "toApplyCount", ":=", "len", "(", "toApply", ")", "\n", "if", "max", ">", "0", "&&", "max", "<", "toApplyCount", "{", "toApplyCount", "=", "max", "\n", "}", "\n", "for", "_", ",", "v", ":=", "range", "toApply", "[", "0", ":", "toApplyCount", "]", "{", "if", "dir", "==", "Up", "{", "result", "=", "append", "(", "result", ",", "&", "PlannedMigration", "{", "Migration", ":", "v", ",", "Queries", ":", "v", ".", "Up", ",", "DisableTransaction", ":", "v", ".", "DisableTransactionUp", ",", "}", ")", "\n", "}", "else", "if", "dir", "==", "Down", "{", "result", "=", "append", "(", "result", ",", "&", "PlannedMigration", "{", "Migration", ":", "v", ",", "Queries", ":", "v", ".", "Down", ",", "DisableTransaction", ":", "v", ".", "DisableTransactionDown", ",", "}", ")", "\n", "}", "\n", "}", "\n\n", "return", "result", ",", "dbMap", ",", "nil", "\n", "}" ]
// Plan a migration.
[ "Plan", "a", "migration", "." ]
54bad0a9b051368ffec9cd2b869789c2b8eaea35
https://github.com/rubenv/sql-migrate/blob/54bad0a9b051368ffec9cd2b869789c2b8eaea35/migrate.go#L445-L521
150,286
rubenv/sql-migrate
migrate.go
SkipMax
func SkipMax(db *sql.DB, dialect string, m MigrationSource, dir MigrationDirection, max int) (int, error) { migrations, dbMap, err := PlanMigration(db, dialect, m, dir, max) if err != nil { return 0, err } // Skip migrations applied := 0 for _, migration := range migrations { var executor SqlExecutor if migration.DisableTransaction { executor = dbMap } else { executor, err = dbMap.Begin() if err != nil { return applied, newTxError(migration, err) } } err = executor.Insert(&MigrationRecord{ Id: migration.Id, AppliedAt: time.Now(), }) if err != nil { if trans, ok := executor.(*gorp.Transaction); ok { _ = trans.Rollback() } return applied, newTxError(migration, err) } if trans, ok := executor.(*gorp.Transaction); ok { if err := trans.Commit(); err != nil { return applied, newTxError(migration, err) } } applied++ } return applied, nil }
go
func SkipMax(db *sql.DB, dialect string, m MigrationSource, dir MigrationDirection, max int) (int, error) { migrations, dbMap, err := PlanMigration(db, dialect, m, dir, max) if err != nil { return 0, err } // Skip migrations applied := 0 for _, migration := range migrations { var executor SqlExecutor if migration.DisableTransaction { executor = dbMap } else { executor, err = dbMap.Begin() if err != nil { return applied, newTxError(migration, err) } } err = executor.Insert(&MigrationRecord{ Id: migration.Id, AppliedAt: time.Now(), }) if err != nil { if trans, ok := executor.(*gorp.Transaction); ok { _ = trans.Rollback() } return applied, newTxError(migration, err) } if trans, ok := executor.(*gorp.Transaction); ok { if err := trans.Commit(); err != nil { return applied, newTxError(migration, err) } } applied++ } return applied, nil }
[ "func", "SkipMax", "(", "db", "*", "sql", ".", "DB", ",", "dialect", "string", ",", "m", "MigrationSource", ",", "dir", "MigrationDirection", ",", "max", "int", ")", "(", "int", ",", "error", ")", "{", "migrations", ",", "dbMap", ",", "err", ":=", "PlanMigration", "(", "db", ",", "dialect", ",", "m", ",", "dir", ",", "max", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n\n", "// Skip migrations", "applied", ":=", "0", "\n", "for", "_", ",", "migration", ":=", "range", "migrations", "{", "var", "executor", "SqlExecutor", "\n\n", "if", "migration", ".", "DisableTransaction", "{", "executor", "=", "dbMap", "\n", "}", "else", "{", "executor", ",", "err", "=", "dbMap", ".", "Begin", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "applied", ",", "newTxError", "(", "migration", ",", "err", ")", "\n", "}", "\n", "}", "\n\n", "err", "=", "executor", ".", "Insert", "(", "&", "MigrationRecord", "{", "Id", ":", "migration", ".", "Id", ",", "AppliedAt", ":", "time", ".", "Now", "(", ")", ",", "}", ")", "\n", "if", "err", "!=", "nil", "{", "if", "trans", ",", "ok", ":=", "executor", ".", "(", "*", "gorp", ".", "Transaction", ")", ";", "ok", "{", "_", "=", "trans", ".", "Rollback", "(", ")", "\n", "}", "\n\n", "return", "applied", ",", "newTxError", "(", "migration", ",", "err", ")", "\n", "}", "\n\n", "if", "trans", ",", "ok", ":=", "executor", ".", "(", "*", "gorp", ".", "Transaction", ")", ";", "ok", "{", "if", "err", ":=", "trans", ".", "Commit", "(", ")", ";", "err", "!=", "nil", "{", "return", "applied", ",", "newTxError", "(", "migration", ",", "err", ")", "\n", "}", "\n", "}", "\n\n", "applied", "++", "\n", "}", "\n\n", "return", "applied", ",", "nil", "\n", "}" ]
// Skip a set of migrations // // Will skip at most `max` migrations. Pass 0 for no limit. // // Returns the number of skipped migrations.
[ "Skip", "a", "set", "of", "migrations", "Will", "skip", "at", "most", "max", "migrations", ".", "Pass", "0", "for", "no", "limit", ".", "Returns", "the", "number", "of", "skipped", "migrations", "." ]
54bad0a9b051368ffec9cd2b869789c2b8eaea35
https://github.com/rubenv/sql-migrate/blob/54bad0a9b051368ffec9cd2b869789c2b8eaea35/migrate.go#L528-L570
150,287
rubenv/sql-migrate
migrate.go
ToApply
func ToApply(migrations []*Migration, current string, direction MigrationDirection) []*Migration { var index = -1 if current != "" { for index < len(migrations)-1 { index++ if migrations[index].Id == current { break } } } if direction == Up { return migrations[index+1:] } else if direction == Down { if index == -1 { return []*Migration{} } // Add in reverse order toApply := make([]*Migration, index+1) for i := 0; i < index+1; i++ { toApply[index-i] = migrations[i] } return toApply } panic("Not possible") }
go
func ToApply(migrations []*Migration, current string, direction MigrationDirection) []*Migration { var index = -1 if current != "" { for index < len(migrations)-1 { index++ if migrations[index].Id == current { break } } } if direction == Up { return migrations[index+1:] } else if direction == Down { if index == -1 { return []*Migration{} } // Add in reverse order toApply := make([]*Migration, index+1) for i := 0; i < index+1; i++ { toApply[index-i] = migrations[i] } return toApply } panic("Not possible") }
[ "func", "ToApply", "(", "migrations", "[", "]", "*", "Migration", ",", "current", "string", ",", "direction", "MigrationDirection", ")", "[", "]", "*", "Migration", "{", "var", "index", "=", "-", "1", "\n", "if", "current", "!=", "\"", "\"", "{", "for", "index", "<", "len", "(", "migrations", ")", "-", "1", "{", "index", "++", "\n", "if", "migrations", "[", "index", "]", ".", "Id", "==", "current", "{", "break", "\n", "}", "\n", "}", "\n", "}", "\n\n", "if", "direction", "==", "Up", "{", "return", "migrations", "[", "index", "+", "1", ":", "]", "\n", "}", "else", "if", "direction", "==", "Down", "{", "if", "index", "==", "-", "1", "{", "return", "[", "]", "*", "Migration", "{", "}", "\n", "}", "\n\n", "// Add in reverse order", "toApply", ":=", "make", "(", "[", "]", "*", "Migration", ",", "index", "+", "1", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "index", "+", "1", ";", "i", "++", "{", "toApply", "[", "index", "-", "i", "]", "=", "migrations", "[", "i", "]", "\n", "}", "\n", "return", "toApply", "\n", "}", "\n\n", "panic", "(", "\"", "\"", ")", "\n", "}" ]
// Filter a slice of migrations into ones that should be applied.
[ "Filter", "a", "slice", "of", "migrations", "into", "ones", "that", "should", "be", "applied", "." ]
54bad0a9b051368ffec9cd2b869789c2b8eaea35
https://github.com/rubenv/sql-migrate/blob/54bad0a9b051368ffec9cd2b869789c2b8eaea35/migrate.go#L573-L600
150,288
cheekybits/genny
examples/queue/queue_generic.go
Enq
func (q *GenericQueue) Enq(obj Generic) *GenericQueue { q.items = append(q.items, obj) return q }
go
func (q *GenericQueue) Enq(obj Generic) *GenericQueue { q.items = append(q.items, obj) return q }
[ "func", "(", "q", "*", "GenericQueue", ")", "Enq", "(", "obj", "Generic", ")", "*", "GenericQueue", "{", "q", ".", "items", "=", "append", "(", "q", ".", "items", ",", "obj", ")", "\n", "return", "q", "\n", "}" ]
// Enq adds an item to the queue.
[ "Enq", "adds", "an", "item", "to", "the", "queue", "." ]
d2cf3cdd35ce0d789056c4bc02a4d6349c947caf
https://github.com/cheekybits/genny/blob/d2cf3cdd35ce0d789056c4bc02a4d6349c947caf/examples/queue/queue_generic.go#L18-L21
150,289
cheekybits/genny
examples/queue/queue_generic.go
Deq
func (q *GenericQueue) Deq() Generic { obj := q.items[0] q.items = q.items[1:] return obj }
go
func (q *GenericQueue) Deq() Generic { obj := q.items[0] q.items = q.items[1:] return obj }
[ "func", "(", "q", "*", "GenericQueue", ")", "Deq", "(", ")", "Generic", "{", "obj", ":=", "q", ".", "items", "[", "0", "]", "\n", "q", ".", "items", "=", "q", ".", "items", "[", "1", ":", "]", "\n", "return", "obj", "\n", "}" ]
// Deq removes and returns the next item in the queue.
[ "Deq", "removes", "and", "returns", "the", "next", "item", "in", "the", "queue", "." ]
d2cf3cdd35ce0d789056c4bc02a4d6349c947caf
https://github.com/cheekybits/genny/blob/d2cf3cdd35ce0d789056c4bc02a4d6349c947caf/examples/queue/queue_generic.go#L24-L28
150,290
cheekybits/genny
parse/parse.go
subTypeIntoLine
func subTypeIntoLine(line, typeTemplate, specificType string) string { src := []byte(line) var s scanner.Scanner fset := token.NewFileSet() file := fset.AddFile("", fset.Base(), len(src)) s.Init(file, src, nil, scanner.ScanComments) output := "" for { _, tok, lit := s.Scan() if tok == token.EOF { break } else if tok == token.COMMENT { subbed := subTypeIntoComment(lit, typeTemplate, specificType) output = output + subbed + " " } else if tok.IsLiteral() { subbed := subIntoLiteral(lit, typeTemplate, specificType) output = output + subbed + " " } else { output = output + tok.String() + " " } } return output }
go
func subTypeIntoLine(line, typeTemplate, specificType string) string { src := []byte(line) var s scanner.Scanner fset := token.NewFileSet() file := fset.AddFile("", fset.Base(), len(src)) s.Init(file, src, nil, scanner.ScanComments) output := "" for { _, tok, lit := s.Scan() if tok == token.EOF { break } else if tok == token.COMMENT { subbed := subTypeIntoComment(lit, typeTemplate, specificType) output = output + subbed + " " } else if tok.IsLiteral() { subbed := subIntoLiteral(lit, typeTemplate, specificType) output = output + subbed + " " } else { output = output + tok.String() + " " } } return output }
[ "func", "subTypeIntoLine", "(", "line", ",", "typeTemplate", ",", "specificType", "string", ")", "string", "{", "src", ":=", "[", "]", "byte", "(", "line", ")", "\n", "var", "s", "scanner", ".", "Scanner", "\n", "fset", ":=", "token", ".", "NewFileSet", "(", ")", "\n", "file", ":=", "fset", ".", "AddFile", "(", "\"", "\"", ",", "fset", ".", "Base", "(", ")", ",", "len", "(", "src", ")", ")", "\n", "s", ".", "Init", "(", "file", ",", "src", ",", "nil", ",", "scanner", ".", "ScanComments", ")", "\n", "output", ":=", "\"", "\"", "\n", "for", "{", "_", ",", "tok", ",", "lit", ":=", "s", ".", "Scan", "(", ")", "\n", "if", "tok", "==", "token", ".", "EOF", "{", "break", "\n", "}", "else", "if", "tok", "==", "token", ".", "COMMENT", "{", "subbed", ":=", "subTypeIntoComment", "(", "lit", ",", "typeTemplate", ",", "specificType", ")", "\n", "output", "=", "output", "+", "subbed", "+", "\"", "\"", "\n", "}", "else", "if", "tok", ".", "IsLiteral", "(", ")", "{", "subbed", ":=", "subIntoLiteral", "(", "lit", ",", "typeTemplate", ",", "specificType", ")", "\n", "output", "=", "output", "+", "subbed", "+", "\"", "\"", "\n", "}", "else", "{", "output", "=", "output", "+", "tok", ".", "String", "(", ")", "+", "\"", "\"", "\n", "}", "\n", "}", "\n", "return", "output", "\n", "}" ]
// Does the heavy lifting of taking a line of our code and // sbustituting a type into there for our generic type
[ "Does", "the", "heavy", "lifting", "of", "taking", "a", "line", "of", "our", "code", "and", "sbustituting", "a", "type", "into", "there", "for", "our", "generic", "type" ]
d2cf3cdd35ce0d789056c4bc02a4d6349c947caf
https://github.com/cheekybits/genny/blob/d2cf3cdd35ce0d789056c4bc02a4d6349c947caf/parse/parse.go#L67-L89
150,291
cheekybits/genny
parse/parse.go
wordify
func wordify(s string, exported bool) string { s = strings.TrimRight(s, "{}") s = strings.TrimLeft(s, "*&") s = strings.Replace(s, ".", "", -1) if !exported { return s } return strings.ToUpper(string(s[0])) + s[1:] }
go
func wordify(s string, exported bool) string { s = strings.TrimRight(s, "{}") s = strings.TrimLeft(s, "*&") s = strings.Replace(s, ".", "", -1) if !exported { return s } return strings.ToUpper(string(s[0])) + s[1:] }
[ "func", "wordify", "(", "s", "string", ",", "exported", "bool", ")", "string", "{", "s", "=", "strings", ".", "TrimRight", "(", "s", ",", "\"", "\"", ")", "\n", "s", "=", "strings", ".", "TrimLeft", "(", "s", ",", "\"", "\"", ")", "\n", "s", "=", "strings", ".", "Replace", "(", "s", ",", "\"", "\"", ",", "\"", "\"", ",", "-", "1", ")", "\n", "if", "!", "exported", "{", "return", "s", "\n", "}", "\n", "return", "strings", ".", "ToUpper", "(", "string", "(", "s", "[", "0", "]", ")", ")", "+", "s", "[", "1", ":", "]", "\n", "}" ]
// wordify turns a type into a nice word for function and type // names etc.
[ "wordify", "turns", "a", "type", "into", "a", "nice", "word", "for", "function", "and", "type", "names", "etc", "." ]
d2cf3cdd35ce0d789056c4bc02a4d6349c947caf
https://github.com/cheekybits/genny/blob/d2cf3cdd35ce0d789056c4bc02a4d6349c947caf/parse/parse.go#L263-L271
150,292
cheekybits/genny
out/lazy_file.go
Close
func (lw *LazyFile) Close() error { if lw.file != nil { return lw.file.Close() } return nil }
go
func (lw *LazyFile) Close() error { if lw.file != nil { return lw.file.Close() } return nil }
[ "func", "(", "lw", "*", "LazyFile", ")", "Close", "(", ")", "error", "{", "if", "lw", ".", "file", "!=", "nil", "{", "return", "lw", ".", "file", ".", "Close", "(", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Close closes the file if it is created. Returns nil if no file is created.
[ "Close", "closes", "the", "file", "if", "it", "is", "created", ".", "Returns", "nil", "if", "no", "file", "is", "created", "." ]
d2cf3cdd35ce0d789056c4bc02a4d6349c947caf
https://github.com/cheekybits/genny/blob/d2cf3cdd35ce0d789056c4bc02a4d6349c947caf/out/lazy_file.go#L18-L23
150,293
cheekybits/genny
out/lazy_file.go
Write
func (lw *LazyFile) Write(p []byte) (int, error) { if lw.file == nil { err := os.MkdirAll(path.Dir(lw.FileName), 0755) if err != nil { return 0, err } lw.file, err = os.Create(lw.FileName) if err != nil { return 0, err } } return lw.file.Write(p) }
go
func (lw *LazyFile) Write(p []byte) (int, error) { if lw.file == nil { err := os.MkdirAll(path.Dir(lw.FileName), 0755) if err != nil { return 0, err } lw.file, err = os.Create(lw.FileName) if err != nil { return 0, err } } return lw.file.Write(p) }
[ "func", "(", "lw", "*", "LazyFile", ")", "Write", "(", "p", "[", "]", "byte", ")", "(", "int", ",", "error", ")", "{", "if", "lw", ".", "file", "==", "nil", "{", "err", ":=", "os", ".", "MkdirAll", "(", "path", ".", "Dir", "(", "lw", ".", "FileName", ")", ",", "0755", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "lw", ".", "file", ",", "err", "=", "os", ".", "Create", "(", "lw", ".", "FileName", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "}", "\n", "return", "lw", ".", "file", ".", "Write", "(", "p", ")", "\n", "}" ]
// Write writes to the specified file and creates the file first time it is called.
[ "Write", "writes", "to", "the", "specified", "file", "and", "creates", "the", "file", "first", "time", "it", "is", "called", "." ]
d2cf3cdd35ce0d789056c4bc02a4d6349c947caf
https://github.com/cheekybits/genny/blob/d2cf3cdd35ce0d789056c4bc02a4d6349c947caf/out/lazy_file.go#L26-L38
150,294
cheekybits/genny
main.go
gen
func gen(filename, pkgName string, in io.ReadSeeker, typesets []map[string]string, out io.Writer) error { var output []byte var err error output, err = parse.Generics(filename, pkgName, in, typesets) if err != nil { return err } out.Write(output) return nil }
go
func gen(filename, pkgName string, in io.ReadSeeker, typesets []map[string]string, out io.Writer) error { var output []byte var err error output, err = parse.Generics(filename, pkgName, in, typesets) if err != nil { return err } out.Write(output) return nil }
[ "func", "gen", "(", "filename", ",", "pkgName", "string", ",", "in", "io", ".", "ReadSeeker", ",", "typesets", "[", "]", "map", "[", "string", "]", "string", ",", "out", "io", ".", "Writer", ")", "error", "{", "var", "output", "[", "]", "byte", "\n", "var", "err", "error", "\n\n", "output", ",", "err", "=", "parse", ".", "Generics", "(", "filename", ",", "pkgName", ",", "in", ",", "typesets", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "out", ".", "Write", "(", "output", ")", "\n", "return", "nil", "\n", "}" ]
// gen performs the generic generation.
[ "gen", "performs", "the", "generic", "generation", "." ]
d2cf3cdd35ce0d789056c4bc02a4d6349c947caf
https://github.com/cheekybits/genny/blob/d2cf3cdd35ce0d789056c4bc02a4d6349c947caf/main.go#L142-L154
150,295
machinebox/graphql
graphql.go
NewClient
func NewClient(endpoint string, opts ...ClientOption) *Client { c := &Client{ endpoint: endpoint, Log: func(string) {}, } for _, optionFunc := range opts { optionFunc(c) } if c.httpClient == nil { c.httpClient = http.DefaultClient } return c }
go
func NewClient(endpoint string, opts ...ClientOption) *Client { c := &Client{ endpoint: endpoint, Log: func(string) {}, } for _, optionFunc := range opts { optionFunc(c) } if c.httpClient == nil { c.httpClient = http.DefaultClient } return c }
[ "func", "NewClient", "(", "endpoint", "string", ",", "opts", "...", "ClientOption", ")", "*", "Client", "{", "c", ":=", "&", "Client", "{", "endpoint", ":", "endpoint", ",", "Log", ":", "func", "(", "string", ")", "{", "}", ",", "}", "\n", "for", "_", ",", "optionFunc", ":=", "range", "opts", "{", "optionFunc", "(", "c", ")", "\n", "}", "\n", "if", "c", ".", "httpClient", "==", "nil", "{", "c", ".", "httpClient", "=", "http", ".", "DefaultClient", "\n", "}", "\n", "return", "c", "\n", "}" ]
// NewClient makes a new Client capable of making GraphQL requests.
[ "NewClient", "makes", "a", "new", "Client", "capable", "of", "making", "GraphQL", "requests", "." ]
3a92531802258604bd12793465c2e28bc4b2fc85
https://github.com/machinebox/graphql/blob/3a92531802258604bd12793465c2e28bc4b2fc85/graphql.go#L61-L73
150,296
machinebox/graphql
graphql.go
Run
func (c *Client) Run(ctx context.Context, req *Request, resp interface{}) error { select { case <-ctx.Done(): return ctx.Err() default: } if len(req.files) > 0 && !c.useMultipartForm { return errors.New("cannot send files with PostFields option") } if c.useMultipartForm { return c.runWithPostFields(ctx, req, resp) } return c.runWithJSON(ctx, req, resp) }
go
func (c *Client) Run(ctx context.Context, req *Request, resp interface{}) error { select { case <-ctx.Done(): return ctx.Err() default: } if len(req.files) > 0 && !c.useMultipartForm { return errors.New("cannot send files with PostFields option") } if c.useMultipartForm { return c.runWithPostFields(ctx, req, resp) } return c.runWithJSON(ctx, req, resp) }
[ "func", "(", "c", "*", "Client", ")", "Run", "(", "ctx", "context", ".", "Context", ",", "req", "*", "Request", ",", "resp", "interface", "{", "}", ")", "error", "{", "select", "{", "case", "<-", "ctx", ".", "Done", "(", ")", ":", "return", "ctx", ".", "Err", "(", ")", "\n", "default", ":", "}", "\n", "if", "len", "(", "req", ".", "files", ")", ">", "0", "&&", "!", "c", ".", "useMultipartForm", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "if", "c", ".", "useMultipartForm", "{", "return", "c", ".", "runWithPostFields", "(", "ctx", ",", "req", ",", "resp", ")", "\n", "}", "\n", "return", "c", ".", "runWithJSON", "(", "ctx", ",", "req", ",", "resp", ")", "\n", "}" ]
// Run executes the query and unmarshals the response from the data field // into the response object. // Pass in a nil response object to skip response parsing. // If the request fails or the server returns an error, the first error // will be returned.
[ "Run", "executes", "the", "query", "and", "unmarshals", "the", "response", "from", "the", "data", "field", "into", "the", "response", "object", ".", "Pass", "in", "a", "nil", "response", "object", "to", "skip", "response", "parsing", ".", "If", "the", "request", "fails", "or", "the", "server", "returns", "an", "error", "the", "first", "error", "will", "be", "returned", "." ]
3a92531802258604bd12793465c2e28bc4b2fc85
https://github.com/machinebox/graphql/blob/3a92531802258604bd12793465c2e28bc4b2fc85/graphql.go#L84-L97
150,297
machinebox/graphql
graphql.go
NewRequest
func NewRequest(q string) *Request { req := &Request{ q: q, Header: make(map[string][]string), } return req }
go
func NewRequest(q string) *Request { req := &Request{ q: q, Header: make(map[string][]string), } return req }
[ "func", "NewRequest", "(", "q", "string", ")", "*", "Request", "{", "req", ":=", "&", "Request", "{", "q", ":", "q", ",", "Header", ":", "make", "(", "map", "[", "string", "]", "[", "]", "string", ")", ",", "}", "\n", "return", "req", "\n", "}" ]
// NewRequest makes a new Request with the specified string.
[ "NewRequest", "makes", "a", "new", "Request", "with", "the", "specified", "string", "." ]
3a92531802258604bd12793465c2e28bc4b2fc85
https://github.com/machinebox/graphql/blob/3a92531802258604bd12793465c2e28bc4b2fc85/graphql.go#L277-L283
150,298
machinebox/graphql
graphql.go
Var
func (req *Request) Var(key string, value interface{}) { if req.vars == nil { req.vars = make(map[string]interface{}) } req.vars[key] = value }
go
func (req *Request) Var(key string, value interface{}) { if req.vars == nil { req.vars = make(map[string]interface{}) } req.vars[key] = value }
[ "func", "(", "req", "*", "Request", ")", "Var", "(", "key", "string", ",", "value", "interface", "{", "}", ")", "{", "if", "req", ".", "vars", "==", "nil", "{", "req", ".", "vars", "=", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "}", "\n", "req", ".", "vars", "[", "key", "]", "=", "value", "\n", "}" ]
// Var sets a variable.
[ "Var", "sets", "a", "variable", "." ]
3a92531802258604bd12793465c2e28bc4b2fc85
https://github.com/machinebox/graphql/blob/3a92531802258604bd12793465c2e28bc4b2fc85/graphql.go#L286-L291
150,299
machinebox/graphql
graphql.go
File
func (req *Request) File(fieldname, filename string, r io.Reader) { req.files = append(req.files, File{ Field: fieldname, Name: filename, R: r, }) }
go
func (req *Request) File(fieldname, filename string, r io.Reader) { req.files = append(req.files, File{ Field: fieldname, Name: filename, R: r, }) }
[ "func", "(", "req", "*", "Request", ")", "File", "(", "fieldname", ",", "filename", "string", ",", "r", "io", ".", "Reader", ")", "{", "req", ".", "files", "=", "append", "(", "req", ".", "files", ",", "File", "{", "Field", ":", "fieldname", ",", "Name", ":", "filename", ",", "R", ":", "r", ",", "}", ")", "\n", "}" ]
// File sets a file to upload. // Files are only supported with a Client that was created with // the UseMultipartForm option.
[ "File", "sets", "a", "file", "to", "upload", ".", "Files", "are", "only", "supported", "with", "a", "Client", "that", "was", "created", "with", "the", "UseMultipartForm", "option", "." ]
3a92531802258604bd12793465c2e28bc4b2fc85
https://github.com/machinebox/graphql/blob/3a92531802258604bd12793465c2e28bc4b2fc85/graphql.go#L311-L317