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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
133,200 | paulmach/go.geo | quadtree/quadtree.go | NewFromPointers | func NewFromPointers(points []geo.Pointer) *Quadtree {
if len(points) == 0 {
// This is kind of meaningless but is what will happen
// if using an empty pointset above.
return New(geo.NewBound(0, 0, 0, 0))
}
b := geo.NewBoundFromPoints(points[0].Point(), points[0].Point())
for _, p := range points {
b.Exte... | go | func NewFromPointers(points []geo.Pointer) *Quadtree {
if len(points) == 0 {
// This is kind of meaningless but is what will happen
// if using an empty pointset above.
return New(geo.NewBound(0, 0, 0, 0))
}
b := geo.NewBoundFromPoints(points[0].Point(), points[0].Point())
for _, p := range points {
b.Exte... | [
"func",
"NewFromPointers",
"(",
"points",
"[",
"]",
"geo",
".",
"Pointer",
")",
"*",
"Quadtree",
"{",
"if",
"len",
"(",
"points",
")",
"==",
"0",
"{",
"// This is kind of meaningless but is what will happen",
"// if using an empty pointset above.",
"return",
"New",
... | // NewFromPointers creates a quadtree from a set of pointers. | [
"NewFromPointers",
"creates",
"a",
"quadtree",
"from",
"a",
"set",
"of",
"pointers",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/quadtree/quadtree.go#L80-L99 |
133,201 | paulmach/go.geo | quadtree/quadtree.go | Insert | func (q *Quadtree) Insert(p geo.Pointer) error {
if p == nil {
return nil
}
point := p.Point()
if point == nil {
return nil
}
if !q.bound.Contains(point) {
return ErrPointOutsideOfBounds
}
if q.root == nil {
q.root = &node{}
}
q.insert(q.root, p,
q.bound.Left(), q.bound.Right(),
q.bound.Bottom... | go | func (q *Quadtree) Insert(p geo.Pointer) error {
if p == nil {
return nil
}
point := p.Point()
if point == nil {
return nil
}
if !q.bound.Contains(point) {
return ErrPointOutsideOfBounds
}
if q.root == nil {
q.root = &node{}
}
q.insert(q.root, p,
q.bound.Left(), q.bound.Right(),
q.bound.Bottom... | [
"func",
"(",
"q",
"*",
"Quadtree",
")",
"Insert",
"(",
"p",
"geo",
".",
"Pointer",
")",
"error",
"{",
"if",
"p",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"point",
":=",
"p",
".",
"Point",
"(",
")",
"\n",
"if",
"point",
"==",
"nil",... | // Insert puts an object into the quad tree, must be within the quadtree bounds.
// If the pointer returns nil, the point will be ignored.
// This function is not thread-safe, ie. multiple goroutines cannot insert into
// a single quadtree. | [
"Insert",
"puts",
"an",
"object",
"into",
"the",
"quad",
"tree",
"must",
"be",
"within",
"the",
"quadtree",
"bounds",
".",
"If",
"the",
"pointer",
"returns",
"nil",
"the",
"point",
"will",
"be",
"ignored",
".",
"This",
"function",
"is",
"not",
"thread",
... | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/quadtree/quadtree.go#L110-L134 |
133,202 | paulmach/go.geo | quadtree/quadtree.go | nextNode | func (q *Quadtree) nextNode() *node {
if l := len(q.freeNodes); q.freeIndex >= l {
// Exponentially decrease the preallocation size.
// On a handful of tests, number of nodes was about 1.5 times pointers.
l /= 2
// min size of the preallocation. I think this could be bigger as it's
// not that much memory o... | go | func (q *Quadtree) nextNode() *node {
if l := len(q.freeNodes); q.freeIndex >= l {
// Exponentially decrease the preallocation size.
// On a handful of tests, number of nodes was about 1.5 times pointers.
l /= 2
// min size of the preallocation. I think this could be bigger as it's
// not that much memory o... | [
"func",
"(",
"q",
"*",
"Quadtree",
")",
"nextNode",
"(",
")",
"*",
"node",
"{",
"if",
"l",
":=",
"len",
"(",
"q",
".",
"freeNodes",
")",
";",
"q",
".",
"freeIndex",
">=",
"l",
"{",
"// Exponentially decrease the preallocation size.",
"// On a handful of test... | // nextNode returns the next node from a preallocated list.
// This resulted in about 15% improvement in quadtree creation. | [
"nextNode",
"returns",
"the",
"next",
"node",
"from",
"a",
"preallocated",
"list",
".",
"This",
"resulted",
"in",
"about",
"15%",
"improvement",
"in",
"quadtree",
"creation",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/quadtree/quadtree.go#L138-L158 |
133,203 | paulmach/go.geo | quadtree/quadtree.go | InBoundMatching | func (q *Quadtree) InBoundMatching(b *geo.Bound, f Filter, buf ...[]geo.Pointer) []geo.Pointer {
if q.root == nil {
return nil
}
var p []geo.Pointer
if len(buf) > 0 {
p = buf[0][:0]
}
v := &inBoundVisitor{
bound: b,
pointers: p,
filter: f,
}
newVisit(v).Visit(q.root,
q.bound.Left(), q.bound.R... | go | func (q *Quadtree) InBoundMatching(b *geo.Bound, f Filter, buf ...[]geo.Pointer) []geo.Pointer {
if q.root == nil {
return nil
}
var p []geo.Pointer
if len(buf) > 0 {
p = buf[0][:0]
}
v := &inBoundVisitor{
bound: b,
pointers: p,
filter: f,
}
newVisit(v).Visit(q.root,
q.bound.Left(), q.bound.R... | [
"func",
"(",
"q",
"*",
"Quadtree",
")",
"InBoundMatching",
"(",
"b",
"*",
"geo",
".",
"Bound",
",",
"f",
"Filter",
",",
"buf",
"...",
"[",
"]",
"geo",
".",
"Pointer",
")",
"[",
"]",
"geo",
".",
"Pointer",
"{",
"if",
"q",
".",
"root",
"==",
"nil... | // InBoundMatching returns a slice with all the pointers in the quadtree that are
// within the given bound and for which the given filter function returns true.
// An optional buffer parameter is provided to allow for the reuse of result slice memory.
// This function is thread safe. Multiple goroutines can read from ... | [
"InBoundMatching",
"returns",
"a",
"slice",
"with",
"all",
"the",
"pointers",
"in",
"the",
"quadtree",
"that",
"are",
"within",
"the",
"given",
"bound",
"and",
"for",
"which",
"the",
"given",
"filter",
"function",
"returns",
"true",
".",
"An",
"optional",
"b... | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/quadtree/quadtree.go#L310-L331 |
133,204 | paulmach/go.geo | bound.go | NewBound | func NewBound(west, east, south, north float64) *Bound {
return &Bound{
sw: &Point{math.Min(east, west), math.Min(north, south)},
ne: &Point{math.Max(east, west), math.Max(north, south)},
}
} | go | func NewBound(west, east, south, north float64) *Bound {
return &Bound{
sw: &Point{math.Min(east, west), math.Min(north, south)},
ne: &Point{math.Max(east, west), math.Max(north, south)},
}
} | [
"func",
"NewBound",
"(",
"west",
",",
"east",
",",
"south",
",",
"north",
"float64",
")",
"*",
"Bound",
"{",
"return",
"&",
"Bound",
"{",
"sw",
":",
"&",
"Point",
"{",
"math",
".",
"Min",
"(",
"east",
",",
"west",
")",
",",
"math",
".",
"Min",
... | // NewBound creates a new bound given the parameters. | [
"NewBound",
"creates",
"a",
"new",
"bound",
"given",
"the",
"parameters",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/bound.go#L16-L21 |
133,205 | paulmach/go.geo | bound.go | NewGeoBoundAroundPoint | func NewGeoBoundAroundPoint(center *Point, distance float64) *Bound {
if distance < 0 {
panic("invalid distance around center")
}
return geoBoundAroundPoint(center, distance)
} | go | func NewGeoBoundAroundPoint(center *Point, distance float64) *Bound {
if distance < 0 {
panic("invalid distance around center")
}
return geoBoundAroundPoint(center, distance)
} | [
"func",
"NewGeoBoundAroundPoint",
"(",
"center",
"*",
"Point",
",",
"distance",
"float64",
")",
"*",
"Bound",
"{",
"if",
"distance",
"<",
"0",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"geoBoundAroundPoint",
"(",
"center",
",",
"dist... | // NewGeoBoundAroundPoint creates a new bound given a center point,
// and a distance from the center point in meters | [
"NewGeoBoundAroundPoint",
"creates",
"a",
"new",
"bound",
"given",
"a",
"center",
"point",
"and",
"a",
"distance",
"from",
"the",
"center",
"point",
"in",
"meters"
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/bound.go#L37-L42 |
133,206 | paulmach/go.geo | bound.go | NewBoundFromMapTile | func NewBoundFromMapTile(x, y, z uint64) *Bound {
maxIndex := uint64(1) << z
if x < 0 || y < 0 || x >= maxIndex || y >= maxIndex {
panic("tile index out of range")
}
shift := 31 - z
if z > 31 {
shift = 0
}
lng1, lat1 := scalarMercatorInverse(x<<shift, y<<shift, 31)
lng2, lat2 := scalarMercatorInverse((x+1... | go | func NewBoundFromMapTile(x, y, z uint64) *Bound {
maxIndex := uint64(1) << z
if x < 0 || y < 0 || x >= maxIndex || y >= maxIndex {
panic("tile index out of range")
}
shift := 31 - z
if z > 31 {
shift = 0
}
lng1, lat1 := scalarMercatorInverse(x<<shift, y<<shift, 31)
lng2, lat2 := scalarMercatorInverse((x+1... | [
"func",
"NewBoundFromMapTile",
"(",
"x",
",",
"y",
",",
"z",
"uint64",
")",
"*",
"Bound",
"{",
"maxIndex",
":=",
"uint64",
"(",
"1",
")",
"<<",
"z",
"\n",
"if",
"x",
"<",
"0",
"||",
"y",
"<",
"0",
"||",
"x",
">=",
"maxIndex",
"||",
"y",
">=",
... | // NewBoundFromMapTile creates a bound given an online map tile index.
// Panics if x or y is out of range for zoom level. | [
"NewBoundFromMapTile",
"creates",
"a",
"bound",
"given",
"an",
"online",
"map",
"tile",
"index",
".",
"Panics",
"if",
"x",
"or",
"y",
"is",
"out",
"of",
"range",
"for",
"zoom",
"level",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/bound.go#L46-L64 |
133,207 | paulmach/go.geo | bound.go | NewBoundFromGeoHash | func NewBoundFromGeoHash(hash string) *Bound {
west, east, south, north := geoHash2ranges(hash)
return NewBound(west, east, south, north)
} | go | func NewBoundFromGeoHash(hash string) *Bound {
west, east, south, north := geoHash2ranges(hash)
return NewBound(west, east, south, north)
} | [
"func",
"NewBoundFromGeoHash",
"(",
"hash",
"string",
")",
"*",
"Bound",
"{",
"west",
",",
"east",
",",
"south",
",",
"north",
":=",
"geoHash2ranges",
"(",
"hash",
")",
"\n",
"return",
"NewBound",
"(",
"west",
",",
"east",
",",
"south",
",",
"north",
"... | // NewBoundFromGeoHash creates a new bound for the region defined by the GeoHash. | [
"NewBoundFromGeoHash",
"creates",
"a",
"new",
"bound",
"for",
"the",
"region",
"defined",
"by",
"the",
"GeoHash",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/bound.go#L67-L70 |
133,208 | paulmach/go.geo | bound.go | NewBoundFromGeoHashInt64 | func NewBoundFromGeoHashInt64(hash int64, bits int) *Bound {
west, east, south, north := geoHashInt2ranges(hash, bits)
return NewBound(west, east, south, north)
} | go | func NewBoundFromGeoHashInt64(hash int64, bits int) *Bound {
west, east, south, north := geoHashInt2ranges(hash, bits)
return NewBound(west, east, south, north)
} | [
"func",
"NewBoundFromGeoHashInt64",
"(",
"hash",
"int64",
",",
"bits",
"int",
")",
"*",
"Bound",
"{",
"west",
",",
"east",
",",
"south",
",",
"north",
":=",
"geoHashInt2ranges",
"(",
"hash",
",",
"bits",
")",
"\n",
"return",
"NewBound",
"(",
"west",
",",... | // NewBoundFromGeoHashInt64 creates a new bound from the region defined by the GeoHesh.
// bits indicates the precision of the hash. | [
"NewBoundFromGeoHashInt64",
"creates",
"a",
"new",
"bound",
"from",
"the",
"region",
"defined",
"by",
"the",
"GeoHesh",
".",
"bits",
"indicates",
"the",
"precision",
"of",
"the",
"hash",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/bound.go#L74-L77 |
133,209 | paulmach/go.geo | bound.go | Set | func (b *Bound) Set(west, east, south, north float64) {
b.sw[0] = west
b.sw[1] = south
b.ne[0] = east
b.ne[1] = north
} | go | func (b *Bound) Set(west, east, south, north float64) {
b.sw[0] = west
b.sw[1] = south
b.ne[0] = east
b.ne[1] = north
} | [
"func",
"(",
"b",
"*",
"Bound",
")",
"Set",
"(",
"west",
",",
"east",
",",
"south",
",",
"north",
"float64",
")",
"{",
"b",
".",
"sw",
"[",
"0",
"]",
"=",
"west",
"\n",
"b",
".",
"sw",
"[",
"1",
"]",
"=",
"south",
"\n\n",
"b",
".",
"ne",
... | // Set allows for the modification of the bound values in place. | [
"Set",
"allows",
"for",
"the",
"modification",
"of",
"the",
"bound",
"values",
"in",
"place",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/bound.go#L170-L176 |
133,210 | paulmach/go.geo | bound.go | Union | func (b *Bound) Union(other *Bound) *Bound {
b.Extend(other.SouthWest())
b.Extend(other.NorthWest())
b.Extend(other.SouthEast())
b.Extend(other.NorthEast())
return b
} | go | func (b *Bound) Union(other *Bound) *Bound {
b.Extend(other.SouthWest())
b.Extend(other.NorthWest())
b.Extend(other.SouthEast())
b.Extend(other.NorthEast())
return b
} | [
"func",
"(",
"b",
"*",
"Bound",
")",
"Union",
"(",
"other",
"*",
"Bound",
")",
"*",
"Bound",
"{",
"b",
".",
"Extend",
"(",
"other",
".",
"SouthWest",
"(",
")",
")",
"\n",
"b",
".",
"Extend",
"(",
"other",
".",
"NorthWest",
"(",
")",
")",
"\n",
... | // Union extends this bounds to contain the union of this and the given bounds. | [
"Union",
"extends",
"this",
"bounds",
"to",
"contain",
"the",
"union",
"of",
"this",
"and",
"the",
"given",
"bounds",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/bound.go#L196-L203 |
133,211 | paulmach/go.geo | bound.go | Center | func (b *Bound) Center() *Point {
p := &Point{}
p.SetX((b.ne.X() + b.sw.X()) / 2.0)
p.SetY((b.ne.Y() + b.sw.Y()) / 2.0)
return p
} | go | func (b *Bound) Center() *Point {
p := &Point{}
p.SetX((b.ne.X() + b.sw.X()) / 2.0)
p.SetY((b.ne.Y() + b.sw.Y()) / 2.0)
return p
} | [
"func",
"(",
"b",
"*",
"Bound",
")",
"Center",
"(",
")",
"*",
"Point",
"{",
"p",
":=",
"&",
"Point",
"{",
"}",
"\n",
"p",
".",
"SetX",
"(",
"(",
"b",
".",
"ne",
".",
"X",
"(",
")",
"+",
"b",
".",
"sw",
".",
"X",
"(",
")",
")",
"/",
"2... | // Center returns the center of the bound. | [
"Center",
"returns",
"the",
"center",
"of",
"the",
"bound",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/bound.go#L235-L241 |
133,212 | paulmach/go.geo | bound.go | Pad | func (b *Bound) Pad(amount float64) *Bound {
b.sw.SetX(b.sw.X() - amount)
b.sw.SetY(b.sw.Y() - amount)
b.ne.SetX(b.ne.X() + amount)
b.ne.SetY(b.ne.Y() + amount)
return b
} | go | func (b *Bound) Pad(amount float64) *Bound {
b.sw.SetX(b.sw.X() - amount)
b.sw.SetY(b.sw.Y() - amount)
b.ne.SetX(b.ne.X() + amount)
b.ne.SetY(b.ne.Y() + amount)
return b
} | [
"func",
"(",
"b",
"*",
"Bound",
")",
"Pad",
"(",
"amount",
"float64",
")",
"*",
"Bound",
"{",
"b",
".",
"sw",
".",
"SetX",
"(",
"b",
".",
"sw",
".",
"X",
"(",
")",
"-",
"amount",
")",
"\n",
"b",
".",
"sw",
".",
"SetY",
"(",
"b",
".",
"sw"... | // Pad expands the bound in all directions by the amount given. The amount must be
// in the units of the bounds. Technically one can pad with negative value,
// but no error checking is done. | [
"Pad",
"expands",
"the",
"bound",
"in",
"all",
"directions",
"by",
"the",
"amount",
"given",
".",
"The",
"amount",
"must",
"be",
"in",
"the",
"units",
"of",
"the",
"bounds",
".",
"Technically",
"one",
"can",
"pad",
"with",
"negative",
"value",
"but",
"no... | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/bound.go#L246-L254 |
133,213 | paulmach/go.geo | bound.go | SouthEast | func (b *Bound) SouthEast() *Point {
newP := &Point{}
newP.SetLat(b.sw.Lat()).SetLng(b.ne.Lng())
return newP
} | go | func (b *Bound) SouthEast() *Point {
newP := &Point{}
newP.SetLat(b.sw.Lat()).SetLng(b.ne.Lng())
return newP
} | [
"func",
"(",
"b",
"*",
"Bound",
")",
"SouthEast",
"(",
")",
"*",
"Point",
"{",
"newP",
":=",
"&",
"Point",
"{",
"}",
"\n",
"newP",
".",
"SetLat",
"(",
"b",
".",
"sw",
".",
"Lat",
"(",
")",
")",
".",
"SetLng",
"(",
"b",
".",
"ne",
".",
"Lng"... | // SouthEast returns the lower right corner of the bound. | [
"SouthEast",
"returns",
"the",
"lower",
"right",
"corner",
"of",
"the",
"bound",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/bound.go#L307-L311 |
133,214 | paulmach/go.geo | bound.go | Empty | func (b *Bound) Empty() bool {
return b.sw.X() >= b.ne.X() || b.sw.Y() >= b.ne.Y()
} | go | func (b *Bound) Empty() bool {
return b.sw.X() >= b.ne.X() || b.sw.Y() >= b.ne.Y()
} | [
"func",
"(",
"b",
"*",
"Bound",
")",
"Empty",
"(",
")",
"bool",
"{",
"return",
"b",
".",
"sw",
".",
"X",
"(",
")",
">=",
"b",
".",
"ne",
".",
"X",
"(",
")",
"||",
"b",
".",
"sw",
".",
"Y",
"(",
")",
">=",
"b",
".",
"ne",
".",
"Y",
"("... | // Empty returns true if it contains zero area or if
// it's in some malformed negative state where the left point is larger than the right.
// This can be caused by padding too much negative. | [
"Empty",
"returns",
"true",
"if",
"it",
"contains",
"zero",
"area",
"or",
"if",
"it",
"s",
"in",
"some",
"malformed",
"negative",
"state",
"where",
"the",
"left",
"point",
"is",
"larger",
"than",
"the",
"right",
".",
"This",
"can",
"be",
"caused",
"by",
... | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/bound.go#L363-L365 |
133,215 | paulmach/go.geo | bound.go | Equals | func (b *Bound) Equals(c *Bound) bool {
if b.sw.Equals(c.sw) && b.ne.Equals(c.ne) {
return true
}
return false
} | go | func (b *Bound) Equals(c *Bound) bool {
if b.sw.Equals(c.sw) && b.ne.Equals(c.ne) {
return true
}
return false
} | [
"func",
"(",
"b",
"*",
"Bound",
")",
"Equals",
"(",
"c",
"*",
"Bound",
")",
"bool",
"{",
"if",
"b",
".",
"sw",
".",
"Equals",
"(",
"c",
".",
"sw",
")",
"&&",
"b",
".",
"ne",
".",
"Equals",
"(",
"c",
".",
"ne",
")",
"{",
"return",
"true",
... | // Equals returns if two bounds are equal. | [
"Equals",
"returns",
"if",
"two",
"bounds",
"are",
"equal",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/bound.go#L368-L374 |
133,216 | paulmach/go.geo | bound.go | ToMysqlIntersectsCondition | func (b *Bound) ToMysqlIntersectsCondition(column string) string {
return fmt.Sprintf("INTERSECTS(%s, GEOMFROMTEXT('%s'))", column, b.String())
} | go | func (b *Bound) ToMysqlIntersectsCondition(column string) string {
return fmt.Sprintf("INTERSECTS(%s, GEOMFROMTEXT('%s'))", column, b.String())
} | [
"func",
"(",
"b",
"*",
"Bound",
")",
"ToMysqlIntersectsCondition",
"(",
"column",
"string",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"column",
",",
"b",
".",
"String",
"(",
")",
")",
"\n",
"}"
] | // ToMysqlIntersectsCondition returns a condition defining the intersection
// of the column and the bound. To be used in a MySQL query. | [
"ToMysqlIntersectsCondition",
"returns",
"a",
"condition",
"defining",
"the",
"intersection",
"of",
"the",
"column",
"and",
"the",
"bound",
".",
"To",
"be",
"used",
"in",
"a",
"MySQL",
"query",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/bound.go#L395-L397 |
133,217 | paulmach/go.geo | surface.go | GradientAt | func (s *Surface) GradientAt(point *Point) *Point {
if !s.bound.Contains(point) {
return NewPoint(0, 0)
}
xi, yi, deltaX, deltaY := s.gridCoordinate(point)
xi1 := xi + 1
if limit := s.Width - 1; xi1 > limit {
xi = limit - 1
xi1 = limit
deltaX = 1.0
}
yi1 := yi + 1
if limit := s.Height - 1; yi1 > limi... | go | func (s *Surface) GradientAt(point *Point) *Point {
if !s.bound.Contains(point) {
return NewPoint(0, 0)
}
xi, yi, deltaX, deltaY := s.gridCoordinate(point)
xi1 := xi + 1
if limit := s.Width - 1; xi1 > limit {
xi = limit - 1
xi1 = limit
deltaX = 1.0
}
yi1 := yi + 1
if limit := s.Height - 1; yi1 > limi... | [
"func",
"(",
"s",
"*",
"Surface",
")",
"GradientAt",
"(",
"point",
"*",
"Point",
")",
"*",
"Point",
"{",
"if",
"!",
"s",
".",
"bound",
".",
"Contains",
"(",
"point",
")",
"{",
"return",
"NewPoint",
"(",
"0",
",",
"0",
")",
"\n",
"}",
"\n\n",
"x... | // GradientAt returns the surface gradient at the given point.
// Bilinearlly interpolates the grid cell to find the gradient. | [
"GradientAt",
"returns",
"the",
"surface",
"gradient",
"at",
"the",
"given",
"point",
".",
"Bilinearlly",
"interpolates",
"the",
"grid",
"cell",
"to",
"find",
"the",
"gradient",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/surface.go#L89-L117 |
133,218 | paulmach/go.geo | surface.go | gridBoxWidth | func (s Surface) gridBoxWidth() float64 {
return s.bound.Width() / float64(s.Width-1)
} | go | func (s Surface) gridBoxWidth() float64 {
return s.bound.Width() / float64(s.Width-1)
} | [
"func",
"(",
"s",
"Surface",
")",
"gridBoxWidth",
"(",
")",
"float64",
"{",
"return",
"s",
".",
"bound",
".",
"Width",
"(",
")",
"/",
"float64",
"(",
"s",
".",
"Width",
"-",
"1",
")",
"\n",
"}"
] | // gridBoxWidth returns the width of a grid element in the units of s.Bound. | [
"gridBoxWidth",
"returns",
"the",
"width",
"of",
"a",
"grid",
"element",
"in",
"the",
"units",
"of",
"s",
".",
"Bound",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/surface.go#L154-L156 |
133,219 | paulmach/go.geo | surface.go | gridBoxHeight | func (s Surface) gridBoxHeight() float64 {
return s.bound.Height() / float64(s.Height-1)
} | go | func (s Surface) gridBoxHeight() float64 {
return s.bound.Height() / float64(s.Height-1)
} | [
"func",
"(",
"s",
"Surface",
")",
"gridBoxHeight",
"(",
")",
"float64",
"{",
"return",
"s",
".",
"bound",
".",
"Height",
"(",
")",
"/",
"float64",
"(",
"s",
".",
"Height",
"-",
"1",
")",
"\n",
"}"
] | // gridBoxHeight returns the height of a grid element in the units of s.Bound. | [
"gridBoxHeight",
"returns",
"the",
"height",
"of",
"a",
"grid",
"element",
"in",
"the",
"units",
"of",
"s",
".",
"Bound",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/surface.go#L159-L161 |
133,220 | paulmach/go.geo | clustering/combiner.go | ClusterCombiners | func ClusterCombiners(combiners []Combiner, threshold float64) []Combiner {
if len(combiners) < 2 {
return combiners
}
s := &state{
Distances: initializeCombinerDistances(combiners, threshold),
DistanceFunc: func(a, b int) float64 {
return combiners[a].DistanceFromCombiner(combiners[b])
},
}
// succes... | go | func ClusterCombiners(combiners []Combiner, threshold float64) []Combiner {
if len(combiners) < 2 {
return combiners
}
s := &state{
Distances: initializeCombinerDistances(combiners, threshold),
DistanceFunc: func(a, b int) float64 {
return combiners[a].DistanceFromCombiner(combiners[b])
},
}
// succes... | [
"func",
"ClusterCombiners",
"(",
"combiners",
"[",
"]",
"Combiner",
",",
"threshold",
"float64",
")",
"[",
"]",
"Combiner",
"{",
"if",
"len",
"(",
"combiners",
")",
"<",
"2",
"{",
"return",
"combiners",
"\n",
"}",
"\n\n",
"s",
":=",
"&",
"state",
"{",
... | // ClusterCombiners will do a simple hierarchical of the combiners.
// It will modify the input slice as things will be combined into each other. | [
"ClusterCombiners",
"will",
"do",
"a",
"simple",
"hierarchical",
"of",
"the",
"combiners",
".",
"It",
"will",
"modify",
"the",
"input",
"slice",
"as",
"things",
"will",
"be",
"combined",
"into",
"each",
"other",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/clustering/combiner.go#L13-L47 |
133,221 | paulmach/go.geo | clustering/distance_set.go | newDistanceSet | func newDistanceSet() *distanceSet {
return &distanceSet{
MinDistance: math.MaxFloat64,
Distances: make(map[int]float64, 500), // adding 500 was a 20% performance win
}
} | go | func newDistanceSet() *distanceSet {
return &distanceSet{
MinDistance: math.MaxFloat64,
Distances: make(map[int]float64, 500), // adding 500 was a 20% performance win
}
} | [
"func",
"newDistanceSet",
"(",
")",
"*",
"distanceSet",
"{",
"return",
"&",
"distanceSet",
"{",
"MinDistance",
":",
"math",
".",
"MaxFloat64",
",",
"Distances",
":",
"make",
"(",
"map",
"[",
"int",
"]",
"float64",
",",
"500",
")",
",",
"// adding 500 was a... | // newDistanceSet creates a new distance set. | [
"newDistanceSet",
"creates",
"a",
"new",
"distance",
"set",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/clustering/distance_set.go#L15-L20 |
133,222 | paulmach/go.geo | clustering/distance_set.go | Set | func (ds *distanceSet) Set(index int, distance float64) bool {
if d, ok := ds.Distances[index]; ok && index == ds.MinIndex && distance > d {
// minimum index is being made greater, need to reset
ds.Distances[index] = distance
ds.reset()
return true
}
ds.Distances[index] = distance
if distance < ds.MinDista... | go | func (ds *distanceSet) Set(index int, distance float64) bool {
if d, ok := ds.Distances[index]; ok && index == ds.MinIndex && distance > d {
// minimum index is being made greater, need to reset
ds.Distances[index] = distance
ds.reset()
return true
}
ds.Distances[index] = distance
if distance < ds.MinDista... | [
"func",
"(",
"ds",
"*",
"distanceSet",
")",
"Set",
"(",
"index",
"int",
",",
"distance",
"float64",
")",
"bool",
"{",
"if",
"d",
",",
"ok",
":=",
"ds",
".",
"Distances",
"[",
"index",
"]",
";",
"ok",
"&&",
"index",
"==",
"ds",
".",
"MinIndex",
"&... | // Set sets the distance for a given index
// and updates the denormalized min distance if necessary.
// Returns true if the minimum has been updated. | [
"Set",
"sets",
"the",
"distance",
"for",
"a",
"given",
"index",
"and",
"updates",
"the",
"denormalized",
"min",
"distance",
"if",
"necessary",
".",
"Returns",
"true",
"if",
"the",
"minimum",
"has",
"been",
"updated",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/clustering/distance_set.go#L25-L41 |
133,223 | paulmach/go.geo | clustering/distance_set.go | Delete | func (ds *distanceSet) Delete(index int) bool {
delete(ds.Distances, index)
if index == ds.MinIndex {
ds.reset()
return true
}
return false
} | go | func (ds *distanceSet) Delete(index int) bool {
delete(ds.Distances, index)
if index == ds.MinIndex {
ds.reset()
return true
}
return false
} | [
"func",
"(",
"ds",
"*",
"distanceSet",
")",
"Delete",
"(",
"index",
"int",
")",
"bool",
"{",
"delete",
"(",
"ds",
".",
"Distances",
",",
"index",
")",
"\n",
"if",
"index",
"==",
"ds",
".",
"MinIndex",
"{",
"ds",
".",
"reset",
"(",
")",
"\n",
"ret... | // Delete removes a values for an index and resets denormalized minimum.
// Returns true if the minimum has been updated. | [
"Delete",
"removes",
"a",
"values",
"for",
"an",
"index",
"and",
"resets",
"denormalized",
"minimum",
".",
"Returns",
"true",
"if",
"the",
"minimum",
"has",
"been",
"updated",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/clustering/distance_set.go#L45-L53 |
133,224 | paulmach/go.geo | clustering/distance_set.go | reset | func (ds *distanceSet) reset() {
minDist := math.MaxFloat64
minIndex := 0
for i, d := range ds.Distances {
if d < minDist {
minDist = d
minIndex = i
}
}
ds.MinIndex = minIndex
ds.MinDistance = minDist
} | go | func (ds *distanceSet) reset() {
minDist := math.MaxFloat64
minIndex := 0
for i, d := range ds.Distances {
if d < minDist {
minDist = d
minIndex = i
}
}
ds.MinIndex = minIndex
ds.MinDistance = minDist
} | [
"func",
"(",
"ds",
"*",
"distanceSet",
")",
"reset",
"(",
")",
"{",
"minDist",
":=",
"math",
".",
"MaxFloat64",
"\n",
"minIndex",
":=",
"0",
"\n",
"for",
"i",
",",
"d",
":=",
"range",
"ds",
".",
"Distances",
"{",
"if",
"d",
"<",
"minDist",
"{",
"... | // reset refinds the denormalized minimum. Can be used if manually updating values.
// not part of the official api. | [
"reset",
"refinds",
"the",
"denormalized",
"minimum",
".",
"Can",
"be",
"used",
"if",
"manually",
"updating",
"values",
".",
"not",
"part",
"of",
"the",
"official",
"api",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/clustering/distance_set.go#L57-L69 |
133,225 | paulmach/go.geo | line.go | NewLine | func NewLine(a, b *Point) *Line {
return &Line{*a.Clone(), *b.Clone()}
} | go | func NewLine(a, b *Point) *Line {
return &Line{*a.Clone(), *b.Clone()}
} | [
"func",
"NewLine",
"(",
"a",
",",
"b",
"*",
"Point",
")",
"*",
"Line",
"{",
"return",
"&",
"Line",
"{",
"*",
"a",
".",
"Clone",
"(",
")",
",",
"*",
"b",
".",
"Clone",
"(",
")",
"}",
"\n",
"}"
] | // NewLine creates a new line by cloning the provided points. | [
"NewLine",
"creates",
"a",
"new",
"line",
"by",
"cloning",
"the",
"provided",
"points",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/line.go#L16-L18 |
133,226 | paulmach/go.geo | line.go | Transform | func (l *Line) Transform(projector Projector) *Line {
projector(&l.a)
projector(&l.b)
return l
} | go | func (l *Line) Transform(projector Projector) *Line {
projector(&l.a)
projector(&l.b)
return l
} | [
"func",
"(",
"l",
"*",
"Line",
")",
"Transform",
"(",
"projector",
"Projector",
")",
"*",
"Line",
"{",
"projector",
"(",
"&",
"l",
".",
"a",
")",
"\n",
"projector",
"(",
"&",
"l",
".",
"b",
")",
"\n\n",
"return",
"l",
"\n",
"}"
] | // Transform applies a given projection or inverse projection to the current line.
// Modifies the line. | [
"Transform",
"applies",
"a",
"given",
"projection",
"or",
"inverse",
"projection",
"to",
"the",
"current",
"line",
".",
"Modifies",
"the",
"line",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/line.go#L22-L27 |
133,227 | paulmach/go.geo | line.go | DistanceFrom | func (l *Line) DistanceFrom(point *Point) float64 {
// yes duplicate code, but saw a 15% performance increase by removing the function call
// return math.Sqrt(l.SquaredDistanceFrom(point))
x := l.a[0]
y := l.a[1]
dx := l.b[0] - x
dy := l.b[1] - y
if dx != 0 || dy != 0 {
t := ((point[0]-x)*dx + (point[1]-y)*d... | go | func (l *Line) DistanceFrom(point *Point) float64 {
// yes duplicate code, but saw a 15% performance increase by removing the function call
// return math.Sqrt(l.SquaredDistanceFrom(point))
x := l.a[0]
y := l.a[1]
dx := l.b[0] - x
dy := l.b[1] - y
if dx != 0 || dy != 0 {
t := ((point[0]-x)*dx + (point[1]-y)*d... | [
"func",
"(",
"l",
"*",
"Line",
")",
"DistanceFrom",
"(",
"point",
"*",
"Point",
")",
"float64",
"{",
"// yes duplicate code, but saw a 15% performance increase by removing the function call",
"// return math.Sqrt(l.SquaredDistanceFrom(point))",
"x",
":=",
"l",
".",
"a",
"["... | // DistanceFrom does NOT use spherical geometry. It finds the distance from
// the line using standard Euclidean geometry, using the units the points are in. | [
"DistanceFrom",
"does",
"NOT",
"use",
"spherical",
"geometry",
".",
"It",
"finds",
"the",
"distance",
"from",
"the",
"line",
"using",
"standard",
"Euclidean",
"geometry",
"using",
"the",
"units",
"the",
"points",
"are",
"in",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/line.go#L31-L55 |
133,228 | paulmach/go.geo | line.go | SquaredDistanceFrom | func (l *Line) SquaredDistanceFrom(point *Point) float64 {
x := l.a[0]
y := l.a[1]
dx := l.b[0] - x
dy := l.b[1] - y
if dx != 0 || dy != 0 {
t := ((point[0]-x)*dx + (point[1]-y)*dy) / (dx*dx + dy*dy)
if t > 1 {
x = l.b[0]
y = l.b[1]
} else if t > 0 {
x += dx * t
y += dy * t
}
}
dx = point[... | go | func (l *Line) SquaredDistanceFrom(point *Point) float64 {
x := l.a[0]
y := l.a[1]
dx := l.b[0] - x
dy := l.b[1] - y
if dx != 0 || dy != 0 {
t := ((point[0]-x)*dx + (point[1]-y)*dy) / (dx*dx + dy*dy)
if t > 1 {
x = l.b[0]
y = l.b[1]
} else if t > 0 {
x += dx * t
y += dy * t
}
}
dx = point[... | [
"func",
"(",
"l",
"*",
"Line",
")",
"SquaredDistanceFrom",
"(",
"point",
"*",
"Point",
")",
"float64",
"{",
"x",
":=",
"l",
".",
"a",
"[",
"0",
"]",
"\n",
"y",
":=",
"l",
".",
"a",
"[",
"1",
"]",
"\n",
"dx",
":=",
"l",
".",
"b",
"[",
"0",
... | // SquaredDistanceFrom does NOT use spherical geometry. It finds the squared distance from
// the line using standard Euclidean geometry, using the units the points are in. | [
"SquaredDistanceFrom",
"does",
"NOT",
"use",
"spherical",
"geometry",
".",
"It",
"finds",
"the",
"squared",
"distance",
"from",
"the",
"line",
"using",
"standard",
"Euclidean",
"geometry",
"using",
"the",
"units",
"the",
"points",
"are",
"in",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/line.go#L59-L81 |
133,229 | paulmach/go.geo | line.go | GeoDistance | func (l *Line) GeoDistance(haversine ...bool) float64 {
return l.a.GeoDistanceFrom(&l.b, yesHaversine(haversine))
} | go | func (l *Line) GeoDistance(haversine ...bool) float64 {
return l.a.GeoDistanceFrom(&l.b, yesHaversine(haversine))
} | [
"func",
"(",
"l",
"*",
"Line",
")",
"GeoDistance",
"(",
"haversine",
"...",
"bool",
")",
"float64",
"{",
"return",
"l",
".",
"a",
".",
"GeoDistanceFrom",
"(",
"&",
"l",
".",
"b",
",",
"yesHaversine",
"(",
"haversine",
")",
")",
"\n",
"}"
] | // GeoDistance computes the distance of the line, ie. its length, using spherical geometry. | [
"GeoDistance",
"computes",
"the",
"distance",
"of",
"the",
"line",
"ie",
".",
"its",
"length",
"using",
"spherical",
"geometry",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/line.go#L95-L97 |
133,230 | paulmach/go.geo | line.go | Measure | func (l *Line) Measure(point *Point) float64 {
projFactor := l.Project(point)
if projFactor <= 0.0 {
return 0.0
}
if projFactor <= 1.0 {
return projFactor * l.Distance()
}
// projFactor is > 1
return l.Distance()
} | go | func (l *Line) Measure(point *Point) float64 {
projFactor := l.Project(point)
if projFactor <= 0.0 {
return 0.0
}
if projFactor <= 1.0 {
return projFactor * l.Distance()
}
// projFactor is > 1
return l.Distance()
} | [
"func",
"(",
"l",
"*",
"Line",
")",
"Measure",
"(",
"point",
"*",
"Point",
")",
"float64",
"{",
"projFactor",
":=",
"l",
".",
"Project",
"(",
"point",
")",
"\n",
"if",
"projFactor",
"<=",
"0.0",
"{",
"return",
"0.0",
"\n",
"}",
"\n",
"if",
"projFac... | // Measure returns the distance along the line to the point nearest the given point.
// Treats the line as a line segment such that if the nearest point is an endpoint of the line,
// the function will return 0 or 1 as appropriate. | [
"Measure",
"returns",
"the",
"distance",
"along",
"the",
"line",
"to",
"the",
"point",
"nearest",
"the",
"given",
"point",
".",
"Treats",
"the",
"line",
"as",
"a",
"line",
"segment",
"such",
"that",
"if",
"the",
"nearest",
"point",
"is",
"an",
"endpoint",
... | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/line.go#L130-L140 |
133,231 | paulmach/go.geo | line.go | Interpolate | func (l *Line) Interpolate(percent float64) *Point {
return &Point{
l.a[0] + percent*(l.b[0]-l.a[0]),
l.a[1] + percent*(l.b[1]-l.a[1]),
}
} | go | func (l *Line) Interpolate(percent float64) *Point {
return &Point{
l.a[0] + percent*(l.b[0]-l.a[0]),
l.a[1] + percent*(l.b[1]-l.a[1]),
}
} | [
"func",
"(",
"l",
"*",
"Line",
")",
"Interpolate",
"(",
"percent",
"float64",
")",
"*",
"Point",
"{",
"return",
"&",
"Point",
"{",
"l",
".",
"a",
"[",
"0",
"]",
"+",
"percent",
"*",
"(",
"l",
".",
"b",
"[",
"0",
"]",
"-",
"l",
".",
"a",
"["... | // Interpolate performs a simple linear interpolation, from A to B.
// This function is the opposite of Project. | [
"Interpolate",
"performs",
"a",
"simple",
"linear",
"interpolation",
"from",
"A",
"to",
"B",
".",
"This",
"function",
"is",
"the",
"opposite",
"of",
"Project",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/line.go#L144-L149 |
133,232 | paulmach/go.geo | line.go | Side | func (l *Line) Side(p *Point) int {
val := (l.b[0]-l.a[0])*(p[1]-l.b[1]) - (l.b[1]-l.a[1])*(p[0]-l.b[0])
if val < 0 {
return 1 // right
} else if val > 0 {
return -1 // left
}
return 0 // collinear
} | go | func (l *Line) Side(p *Point) int {
val := (l.b[0]-l.a[0])*(p[1]-l.b[1]) - (l.b[1]-l.a[1])*(p[0]-l.b[0])
if val < 0 {
return 1 // right
} else if val > 0 {
return -1 // left
}
return 0 // collinear
} | [
"func",
"(",
"l",
"*",
"Line",
")",
"Side",
"(",
"p",
"*",
"Point",
")",
"int",
"{",
"val",
":=",
"(",
"l",
".",
"b",
"[",
"0",
"]",
"-",
"l",
".",
"a",
"[",
"0",
"]",
")",
"*",
"(",
"p",
"[",
"1",
"]",
"-",
"l",
".",
"b",
"[",
"1",... | // Side returns 1 if the point is on the right side, -1 if on the left side, and 0 if collinear. | [
"Side",
"returns",
"1",
"if",
"the",
"point",
"is",
"on",
"the",
"right",
"side",
"-",
"1",
"if",
"on",
"the",
"left",
"side",
"and",
"0",
"if",
"collinear",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/line.go#L152-L162 |
133,233 | paulmach/go.geo | line.go | Midpoint | func (l *Line) Midpoint() *Point {
return &Point{(l.a[0] + l.b[0]) / 2, (l.a[1] + l.b[1]) / 2}
} | go | func (l *Line) Midpoint() *Point {
return &Point{(l.a[0] + l.b[0]) / 2, (l.a[1] + l.b[1]) / 2}
} | [
"func",
"(",
"l",
"*",
"Line",
")",
"Midpoint",
"(",
")",
"*",
"Point",
"{",
"return",
"&",
"Point",
"{",
"(",
"l",
".",
"a",
"[",
"0",
"]",
"+",
"l",
".",
"b",
"[",
"0",
"]",
")",
"/",
"2",
",",
"(",
"l",
".",
"a",
"[",
"1",
"]",
"+"... | // Midpoint returns the Euclidean midpoint of the line. | [
"Midpoint",
"returns",
"the",
"Euclidean",
"midpoint",
"of",
"the",
"line",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/line.go#L229-L231 |
133,234 | paulmach/go.geo | line.go | GeoMidpoint | func (l *Line) GeoMidpoint() *Point {
p := &Point{}
dLng := deg2rad(l.b.Lng() - l.a.Lng())
aLatRad := deg2rad(l.a.Lat())
bLatRad := deg2rad(l.b.Lat())
x := math.Cos(bLatRad) * math.Cos(dLng)
y := math.Cos(bLatRad) * math.Sin(dLng)
p.SetLat(math.Atan2(math.Sin(aLatRad)+math.Sin(bLatRad), math.Sqrt((math.Cos(a... | go | func (l *Line) GeoMidpoint() *Point {
p := &Point{}
dLng := deg2rad(l.b.Lng() - l.a.Lng())
aLatRad := deg2rad(l.a.Lat())
bLatRad := deg2rad(l.b.Lat())
x := math.Cos(bLatRad) * math.Cos(dLng)
y := math.Cos(bLatRad) * math.Sin(dLng)
p.SetLat(math.Atan2(math.Sin(aLatRad)+math.Sin(bLatRad), math.Sqrt((math.Cos(a... | [
"func",
"(",
"l",
"*",
"Line",
")",
"GeoMidpoint",
"(",
")",
"*",
"Point",
"{",
"p",
":=",
"&",
"Point",
"{",
"}",
"\n\n",
"dLng",
":=",
"deg2rad",
"(",
"l",
".",
"b",
".",
"Lng",
"(",
")",
"-",
"l",
".",
"a",
".",
"Lng",
"(",
")",
")",
"... | // GeoMidpoint returns the half-way point along a great circle path between the two points. | [
"GeoMidpoint",
"returns",
"the",
"half",
"-",
"way",
"point",
"along",
"a",
"great",
"circle",
"path",
"between",
"the",
"two",
"points",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/line.go#L234-L253 |
133,235 | paulmach/go.geo | line.go | Bound | func (l *Line) Bound() *Bound {
return NewBound(math.Max(l.a[0], l.b[0]), math.Min(l.a[0], l.b[0]),
math.Max(l.a[1], l.b[1]), math.Min(l.a[1], l.b[1]))
} | go | func (l *Line) Bound() *Bound {
return NewBound(math.Max(l.a[0], l.b[0]), math.Min(l.a[0], l.b[0]),
math.Max(l.a[1], l.b[1]), math.Min(l.a[1], l.b[1]))
} | [
"func",
"(",
"l",
"*",
"Line",
")",
"Bound",
"(",
")",
"*",
"Bound",
"{",
"return",
"NewBound",
"(",
"math",
".",
"Max",
"(",
"l",
".",
"a",
"[",
"0",
"]",
",",
"l",
".",
"b",
"[",
"0",
"]",
")",
",",
"math",
".",
"Min",
"(",
"l",
".",
... | // Bound returns a bound around the line. Simply uses rectangular coordinates. | [
"Bound",
"returns",
"a",
"bound",
"around",
"the",
"line",
".",
"Simply",
"uses",
"rectangular",
"coordinates",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/line.go#L256-L259 |
133,236 | paulmach/go.geo | line.go | Reverse | func (l *Line) Reverse() *Line {
l.a, l.b = l.b, l.a
return l
} | go | func (l *Line) Reverse() *Line {
l.a, l.b = l.b, l.a
return l
} | [
"func",
"(",
"l",
"*",
"Line",
")",
"Reverse",
"(",
")",
"*",
"Line",
"{",
"l",
".",
"a",
",",
"l",
".",
"b",
"=",
"l",
".",
"b",
",",
"l",
".",
"a",
"\n",
"return",
"l",
"\n",
"}"
] | // Reverse swaps the start and end of the line. | [
"Reverse",
"swaps",
"the",
"start",
"and",
"end",
"of",
"the",
"line",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/line.go#L262-L265 |
133,237 | paulmach/go.geo | line.go | Equals | func (l *Line) Equals(line *Line) bool {
return (l.a.Equals(&line.a) && l.b.Equals(&line.b)) || (l.a.Equals(&line.b) && l.b.Equals(&line.a))
} | go | func (l *Line) Equals(line *Line) bool {
return (l.a.Equals(&line.a) && l.b.Equals(&line.b)) || (l.a.Equals(&line.b) && l.b.Equals(&line.a))
} | [
"func",
"(",
"l",
"*",
"Line",
")",
"Equals",
"(",
"line",
"*",
"Line",
")",
"bool",
"{",
"return",
"(",
"l",
".",
"a",
".",
"Equals",
"(",
"&",
"line",
".",
"a",
")",
"&&",
"l",
".",
"b",
".",
"Equals",
"(",
"&",
"line",
".",
"b",
")",
"... | // Equals returns the line equality and is irrespective of direction,
// i.e. true if one is the reverse of the other. | [
"Equals",
"returns",
"the",
"line",
"equality",
"and",
"is",
"irrespective",
"of",
"direction",
"i",
".",
"e",
".",
"true",
"if",
"one",
"is",
"the",
"reverse",
"of",
"the",
"other",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/line.go#L269-L271 |
133,238 | paulmach/go.geo | line.go | ToGeoJSON | func (l *Line) ToGeoJSON() *geojson.Feature {
return geojson.NewLineStringFeature([][]float64{
{l.a[0], l.a[1]},
{l.b[0], l.b[1]},
})
} | go | func (l *Line) ToGeoJSON() *geojson.Feature {
return geojson.NewLineStringFeature([][]float64{
{l.a[0], l.a[1]},
{l.b[0], l.b[1]},
})
} | [
"func",
"(",
"l",
"*",
"Line",
")",
"ToGeoJSON",
"(",
")",
"*",
"geojson",
".",
"Feature",
"{",
"return",
"geojson",
".",
"NewLineStringFeature",
"(",
"[",
"]",
"[",
"]",
"float64",
"{",
"{",
"l",
".",
"a",
"[",
"0",
"]",
",",
"l",
".",
"a",
"[... | // ToGeoJSON creates a new geojson feature with a linestring geometry
// containing the two points. | [
"ToGeoJSON",
"creates",
"a",
"new",
"geojson",
"feature",
"with",
"a",
"linestring",
"geometry",
"containing",
"the",
"two",
"points",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/line.go#L290-L295 |
133,239 | paulmach/go.geo | reducers/douglas_peucker.go | Reduce | func (r DouglasPeuckerReducer) Reduce(path *geo.Path) *geo.Path {
return DouglasPeucker(path, r.Threshold)
} | go | func (r DouglasPeuckerReducer) Reduce(path *geo.Path) *geo.Path {
return DouglasPeucker(path, r.Threshold)
} | [
"func",
"(",
"r",
"DouglasPeuckerReducer",
")",
"Reduce",
"(",
"path",
"*",
"geo",
".",
"Path",
")",
"*",
"geo",
".",
"Path",
"{",
"return",
"DouglasPeucker",
"(",
"path",
",",
"r",
".",
"Threshold",
")",
"\n",
"}"
] | // Reduce runs the DouglasPeucker using the threshold of the DouglasPeuckerReducer. | [
"Reduce",
"runs",
"the",
"DouglasPeucker",
"using",
"the",
"threshold",
"of",
"the",
"DouglasPeuckerReducer",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/reducers/douglas_peucker.go#L21-L23 |
133,240 | paulmach/go.geo | reducers/douglas_peucker.go | DouglasPeucker | func DouglasPeucker(path *geo.Path, threshold float64) *geo.Path {
if path.Length() <= 2 {
return path.Clone()
}
mask := make([]byte, path.Length())
mask[0] = 1
mask[path.Length()-1] = 1
points := path.Points()
found := dpWorker(points, threshold, mask)
newPoints := make([]geo.Point, 0, found)
for i, v :... | go | func DouglasPeucker(path *geo.Path, threshold float64) *geo.Path {
if path.Length() <= 2 {
return path.Clone()
}
mask := make([]byte, path.Length())
mask[0] = 1
mask[path.Length()-1] = 1
points := path.Points()
found := dpWorker(points, threshold, mask)
newPoints := make([]geo.Point, 0, found)
for i, v :... | [
"func",
"DouglasPeucker",
"(",
"path",
"*",
"geo",
".",
"Path",
",",
"threshold",
"float64",
")",
"*",
"geo",
".",
"Path",
"{",
"if",
"path",
".",
"Length",
"(",
")",
"<=",
"2",
"{",
"return",
"path",
".",
"Clone",
"(",
")",
"\n",
"}",
"\n\n",
"m... | // DouglasPeucker simplifies the path using the Douglas Peucker method.
// Returns a new path and DOES NOT modify the original. | [
"DouglasPeucker",
"simplifies",
"the",
"path",
"using",
"the",
"Douglas",
"Peucker",
"method",
".",
"Returns",
"a",
"new",
"path",
"and",
"DOES",
"NOT",
"modify",
"the",
"original",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/reducers/douglas_peucker.go#L37-L58 |
133,241 | paulmach/go.geo | reducers/douglas_peucker.go | DouglasPeuckerIndexMap | func DouglasPeuckerIndexMap(path *geo.Path, threshold float64) (reduced *geo.Path, indexMap []int) {
if path.Length() == 0 {
return path.Clone(), []int{}
}
if path.Length() == 1 {
return path.Clone(), []int{0}
}
if path.Length() == 2 {
return path.Clone(), []int{0, 1}
}
mask := make([]byte, path.Length(... | go | func DouglasPeuckerIndexMap(path *geo.Path, threshold float64) (reduced *geo.Path, indexMap []int) {
if path.Length() == 0 {
return path.Clone(), []int{}
}
if path.Length() == 1 {
return path.Clone(), []int{0}
}
if path.Length() == 2 {
return path.Clone(), []int{0, 1}
}
mask := make([]byte, path.Length(... | [
"func",
"DouglasPeuckerIndexMap",
"(",
"path",
"*",
"geo",
".",
"Path",
",",
"threshold",
"float64",
")",
"(",
"reduced",
"*",
"geo",
".",
"Path",
",",
"indexMap",
"[",
"]",
"int",
")",
"{",
"if",
"path",
".",
"Length",
"(",
")",
"==",
"0",
"{",
"r... | // DouglasPeuckerIndexMap is similar to DouglasPeucker but returns an array that maps
// each new path index to its original path index.
// Returns a new path and DOES NOT modify the original. | [
"DouglasPeuckerIndexMap",
"is",
"similar",
"to",
"DouglasPeucker",
"but",
"returns",
"an",
"array",
"that",
"maps",
"each",
"new",
"path",
"index",
"to",
"its",
"original",
"path",
"index",
".",
"Returns",
"a",
"new",
"path",
"and",
"DOES",
"NOT",
"modify",
... | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/reducers/douglas_peucker.go#L63-L94 |
133,242 | paulmach/go.geo | reducers/douglas_peucker.go | DouglasPeuckerGeoIndexMap | func DouglasPeuckerGeoIndexMap(path *geo.Path, meters float64) (reduced *geo.Path, indexMap []int) {
if path.Length() == 0 {
return path.Clone(), []int{}
}
if path.Length() == 1 {
return path.Clone(), []int{0}
}
if path.Length() == 2 {
return path.Clone(), []int{0, 1}
}
mask := make([]byte, path.Length(... | go | func DouglasPeuckerGeoIndexMap(path *geo.Path, meters float64) (reduced *geo.Path, indexMap []int) {
if path.Length() == 0 {
return path.Clone(), []int{}
}
if path.Length() == 1 {
return path.Clone(), []int{0}
}
if path.Length() == 2 {
return path.Clone(), []int{0, 1}
}
mask := make([]byte, path.Length(... | [
"func",
"DouglasPeuckerGeoIndexMap",
"(",
"path",
"*",
"geo",
".",
"Path",
",",
"meters",
"float64",
")",
"(",
"reduced",
"*",
"geo",
".",
"Path",
",",
"indexMap",
"[",
"]",
"int",
")",
"{",
"if",
"path",
".",
"Length",
"(",
")",
"==",
"0",
"{",
"r... | // DouglasPeuckerGeoIndexMap is similar to GeoReduce but returns an array that maps
// each new path index to its original path index.
// Returns a new path and DOES NOT modify the original. | [
"DouglasPeuckerGeoIndexMap",
"is",
"similar",
"to",
"GeoReduce",
"but",
"returns",
"an",
"array",
"that",
"maps",
"each",
"new",
"path",
"index",
"to",
"its",
"original",
"path",
"index",
".",
"Returns",
"a",
"new",
"path",
"and",
"DOES",
"NOT",
"modify",
"t... | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/reducers/douglas_peucker.go#L99-L132 |
133,243 | paulmach/go.geo | path_resample.go | Resample | func (p *Path) Resample(totalPoints int) *Path {
if totalPoints <= 0 {
p.PointSet = make([]Point, 0)
return p
}
if p.resampleEdgeCases(totalPoints) {
return p
}
// precomputes the total distance and intermediate distances
total, dists := precomputeDistances(p.PointSet)
p.resample(dists, total, totalPoint... | go | func (p *Path) Resample(totalPoints int) *Path {
if totalPoints <= 0 {
p.PointSet = make([]Point, 0)
return p
}
if p.resampleEdgeCases(totalPoints) {
return p
}
// precomputes the total distance and intermediate distances
total, dists := precomputeDistances(p.PointSet)
p.resample(dists, total, totalPoint... | [
"func",
"(",
"p",
"*",
"Path",
")",
"Resample",
"(",
"totalPoints",
"int",
")",
"*",
"Path",
"{",
"if",
"totalPoints",
"<=",
"0",
"{",
"p",
".",
"PointSet",
"=",
"make",
"(",
"[",
"]",
"Point",
",",
"0",
")",
"\n",
"return",
"p",
"\n",
"}",
"\n... | // Resample converts the path into totalPoints-1 evenly spaced segments.
// Assumes euclidean geometry. | [
"Resample",
"converts",
"the",
"path",
"into",
"totalPoints",
"-",
"1",
"evenly",
"spaced",
"segments",
".",
"Assumes",
"euclidean",
"geometry",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/path_resample.go#L5-L19 |
133,244 | paulmach/go.geo | path_resample.go | ResampleWithInterval | func (p *Path) ResampleWithInterval(dist float64) *Path {
if dist <= 0 {
p.PointSet = make([]Point, 0)
return p
}
// precomputes the total distance and intermediate distances
total, dists := precomputeDistances(p.PointSet)
totalPoints := int(total/dist) + 1
if p.resampleEdgeCases(totalPoints) {
return p
... | go | func (p *Path) ResampleWithInterval(dist float64) *Path {
if dist <= 0 {
p.PointSet = make([]Point, 0)
return p
}
// precomputes the total distance and intermediate distances
total, dists := precomputeDistances(p.PointSet)
totalPoints := int(total/dist) + 1
if p.resampleEdgeCases(totalPoints) {
return p
... | [
"func",
"(",
"p",
"*",
"Path",
")",
"ResampleWithInterval",
"(",
"dist",
"float64",
")",
"*",
"Path",
"{",
"if",
"dist",
"<=",
"0",
"{",
"p",
".",
"PointSet",
"=",
"make",
"(",
"[",
"]",
"Point",
",",
"0",
")",
"\n",
"return",
"p",
"\n",
"}",
"... | // ResampleWithInterval coverts the path into evenly spaced points of
// about the given distance. The total distance is computed using euclidean
// geometry and then divided by the given distance to get the number of segments. | [
"ResampleWithInterval",
"coverts",
"the",
"path",
"into",
"evenly",
"spaced",
"points",
"of",
"about",
"the",
"given",
"distance",
".",
"The",
"total",
"distance",
"is",
"computed",
"using",
"euclidean",
"geometry",
"and",
"then",
"divided",
"by",
"the",
"given"... | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/path_resample.go#L24-L40 |
133,245 | paulmach/go.geo | path_resample.go | resampleEdgeCases | func (p *Path) resampleEdgeCases(totalPoints int) bool {
// degenerate case
if len(p.PointSet) <= 1 {
return true
}
// if all the points are the same, treat as special case.
equal := true
for _, point := range p.PointSet {
if !p.PointSet[0].Equals(&point) {
equal = false
break
}
}
if equal {
if ... | go | func (p *Path) resampleEdgeCases(totalPoints int) bool {
// degenerate case
if len(p.PointSet) <= 1 {
return true
}
// if all the points are the same, treat as special case.
equal := true
for _, point := range p.PointSet {
if !p.PointSet[0].Equals(&point) {
equal = false
break
}
}
if equal {
if ... | [
"func",
"(",
"p",
"*",
"Path",
")",
"resampleEdgeCases",
"(",
"totalPoints",
"int",
")",
"bool",
"{",
"// degenerate case",
"if",
"len",
"(",
"p",
".",
"PointSet",
")",
"<=",
"1",
"{",
"return",
"true",
"\n",
"}",
"\n\n",
"// if all the points are the same, ... | // resampleEdgeCases is used to handle edge case for
// resampling like not enough points and the path is all the same point.
// will return nil if there are no edge cases. If return true if
// one of these edge cases was found and handled. | [
"resampleEdgeCases",
"is",
"used",
"to",
"handle",
"edge",
"case",
"for",
"resampling",
"like",
"not",
"enough",
"points",
"and",
"the",
"path",
"is",
"all",
"the",
"same",
"point",
".",
"will",
"return",
"nil",
"if",
"there",
"are",
"no",
"edge",
"cases",... | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/path_resample.go#L119-L150 |
133,246 | paulmach/go.geo | clustering/sort.go | Less | func (s Sortable) Less(i, j int) bool {
return len(s[i].Pointers) > len(s[j].Pointers)
} | go | func (s Sortable) Less(i, j int) bool {
return len(s[i].Pointers) > len(s[j].Pointers)
} | [
"func",
"(",
"s",
"Sortable",
")",
"Less",
"(",
"i",
",",
"j",
"int",
")",
"bool",
"{",
"return",
"len",
"(",
"s",
"[",
"i",
"]",
".",
"Pointers",
")",
">",
"len",
"(",
"s",
"[",
"j",
"]",
".",
"Pointers",
")",
"\n\n",
"}"
] | // Less returns truee if i > j, so bigger will be first.
// This is to implement the sort interface. | [
"Less",
"returns",
"truee",
"if",
"i",
">",
"j",
"so",
"bigger",
"will",
"be",
"first",
".",
"This",
"is",
"to",
"implement",
"the",
"sort",
"interface",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/clustering/sort.go#L25-L28 |
133,247 | paulmach/go.geo | clustering/sort.go | Swap | func (s Sortable) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
} | go | func (s Sortable) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
} | [
"func",
"(",
"s",
"Sortable",
")",
"Swap",
"(",
"i",
",",
"j",
"int",
")",
"{",
"s",
"[",
"i",
"]",
",",
"s",
"[",
"j",
"]",
"=",
"s",
"[",
"j",
"]",
",",
"s",
"[",
"i",
"]",
"\n",
"}"
] | // Swap interchanges two elements.
// This is to implement the sort interface. | [
"Swap",
"interchanges",
"two",
"elements",
".",
"This",
"is",
"to",
"implement",
"the",
"sort",
"interface",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/clustering/sort.go#L32-L34 |
133,248 | paulmach/go.geo | reducers/radial.go | Reduce | func (r RadialReducer) Reduce(path *geo.Path) *geo.Path {
return Radial(path, r.Threshold)
} | go | func (r RadialReducer) Reduce(path *geo.Path) *geo.Path {
return Radial(path, r.Threshold)
} | [
"func",
"(",
"r",
"RadialReducer",
")",
"Reduce",
"(",
"path",
"*",
"geo",
".",
"Path",
")",
"*",
"geo",
".",
"Path",
"{",
"return",
"Radial",
"(",
"path",
",",
"r",
".",
"Threshold",
")",
"\n",
"}"
] | // Reduce runs the Radial reduction using the threshold of the RadialReducer. | [
"Reduce",
"runs",
"the",
"Radial",
"reduction",
"using",
"the",
"threshold",
"of",
"the",
"RadialReducer",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/reducers/radial.go#L23-L25 |
133,249 | paulmach/go.geo | reducers/radial.go | Reduce | func (r RadialGeoReducer) Reduce(path *geo.Path) *geo.Path {
return RadialGeo(path, r.Threshold)
} | go | func (r RadialGeoReducer) Reduce(path *geo.Path) *geo.Path {
return RadialGeo(path, r.Threshold)
} | [
"func",
"(",
"r",
"RadialGeoReducer",
")",
"Reduce",
"(",
"path",
"*",
"geo",
".",
"Path",
")",
"*",
"geo",
".",
"Path",
"{",
"return",
"RadialGeo",
"(",
"path",
",",
"r",
".",
"Threshold",
")",
"\n",
"}"
] | // Reduce runs the RadialGeo reduction using the threshold of the RadialGeoReducer.
// The threshold is expected to be in meters. | [
"Reduce",
"runs",
"the",
"RadialGeo",
"reduction",
"using",
"the",
"threshold",
"of",
"the",
"RadialGeoReducer",
".",
"The",
"threshold",
"is",
"expected",
"to",
"be",
"in",
"meters",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/reducers/radial.go#L49-L51 |
133,250 | paulmach/go.geo | reducers/radial.go | Radial | func Radial(path *geo.Path, meters float64) *geo.Path {
p, _ := radialCore(path, meters*meters, squaredDistance, false)
return p
} | go | func Radial(path *geo.Path, meters float64) *geo.Path {
p, _ := radialCore(path, meters*meters, squaredDistance, false)
return p
} | [
"func",
"Radial",
"(",
"path",
"*",
"geo",
".",
"Path",
",",
"meters",
"float64",
")",
"*",
"geo",
".",
"Path",
"{",
"p",
",",
"_",
":=",
"radialCore",
"(",
"path",
",",
"meters",
"*",
"meters",
",",
"squaredDistance",
",",
"false",
")",
"\n",
"ret... | // Radial peforms a radial distance polyline simplification using a standard euclidean distance.
// Returns a new path and DOES NOT modify the original. | [
"Radial",
"peforms",
"a",
"radial",
"distance",
"polyline",
"simplification",
"using",
"a",
"standard",
"euclidean",
"distance",
".",
"Returns",
"a",
"new",
"path",
"and",
"DOES",
"NOT",
"modify",
"the",
"original",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/reducers/radial.go#L61-L64 |
133,251 | paulmach/go.geo | reducers/radial.go | RadialIndexMap | func RadialIndexMap(path *geo.Path, meters float64) (*geo.Path, []int) {
return radialCore(path, meters*meters, squaredDistance, true)
} | go | func RadialIndexMap(path *geo.Path, meters float64) (*geo.Path, []int) {
return radialCore(path, meters*meters, squaredDistance, true)
} | [
"func",
"RadialIndexMap",
"(",
"path",
"*",
"geo",
".",
"Path",
",",
"meters",
"float64",
")",
"(",
"*",
"geo",
".",
"Path",
",",
"[",
"]",
"int",
")",
"{",
"return",
"radialCore",
"(",
"path",
",",
"meters",
"*",
"meters",
",",
"squaredDistance",
",... | // RadialIndexMap is similar to Radial but returns an array that maps
// each new path index to its original path index.
// Returns a new path and DOES NOT modify the original. | [
"RadialIndexMap",
"is",
"similar",
"to",
"Radial",
"but",
"returns",
"an",
"array",
"that",
"maps",
"each",
"new",
"path",
"index",
"to",
"its",
"original",
"path",
"index",
".",
"Returns",
"a",
"new",
"path",
"and",
"DOES",
"NOT",
"modify",
"the",
"origin... | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/reducers/radial.go#L69-L71 |
133,252 | paulmach/go.geo | reducers/radial.go | RadialGeoIndexMap | func RadialGeoIndexMap(path *geo.Path, meters float64) (*geo.Path, []int) {
return radialCore(path, meters, geoDistance, true)
} | go | func RadialGeoIndexMap(path *geo.Path, meters float64) (*geo.Path, []int) {
return radialCore(path, meters, geoDistance, true)
} | [
"func",
"RadialGeoIndexMap",
"(",
"path",
"*",
"geo",
".",
"Path",
",",
"meters",
"float64",
")",
"(",
"*",
"geo",
".",
"Path",
",",
"[",
"]",
"int",
")",
"{",
"return",
"radialCore",
"(",
"path",
",",
"meters",
",",
"geoDistance",
",",
"true",
")",
... | // RadialGeoIndexMap is similar to RadialGeo but returns an array that maps
// each new path index to its original path index.
// Returns a new path and DOES NOT modify the original. | [
"RadialGeoIndexMap",
"is",
"similar",
"to",
"RadialGeo",
"but",
"returns",
"an",
"array",
"that",
"maps",
"each",
"new",
"path",
"index",
"to",
"its",
"original",
"path",
"index",
".",
"Returns",
"a",
"new",
"path",
"and",
"DOES",
"NOT",
"modify",
"the",
"... | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/reducers/radial.go#L84-L86 |
133,253 | paulmach/go.geo | clustering/set.go | ResetDistances | func (s *state) ResetDistances(into, from int) {
// since the center of into changed, need to update the distance to anything linked to this one.
for k := range s.Distances[into].Distances {
if k == into {
continue
}
dist := s.DistanceFunc(into, k)
s.Distances[into].Set(k, dist)
s.Distances[k].Set(into... | go | func (s *state) ResetDistances(into, from int) {
// since the center of into changed, need to update the distance to anything linked to this one.
for k := range s.Distances[into].Distances {
if k == into {
continue
}
dist := s.DistanceFunc(into, k)
s.Distances[into].Set(k, dist)
s.Distances[k].Set(into... | [
"func",
"(",
"s",
"*",
"state",
")",
"ResetDistances",
"(",
"into",
",",
"from",
"int",
")",
"{",
"// since the center of into changed, need to update the distance to anything linked to this one.",
"for",
"k",
":=",
"range",
"s",
".",
"Distances",
"[",
"into",
"]",
... | // ResetDistances makes sure the distance map is up to date given the recent merge of clusters. | [
"ResetDistances",
"makes",
"sure",
"the",
"distance",
"map",
"is",
"up",
"to",
"date",
"given",
"the",
"recent",
"merge",
"of",
"clusters",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/clustering/set.go#L13-L45 |
133,254 | paulmach/go.geo | clustering/set.go | MinDistance | func (s *state) MinDistance() (a, b int, dist float64) {
dist = math.MaxFloat64
for i, ds := range s.Distances {
if ds == nil {
continue
}
if ds.MinDistance < dist {
dist = ds.MinDistance
a = i
b = ds.MinIndex
}
}
return
} | go | func (s *state) MinDistance() (a, b int, dist float64) {
dist = math.MaxFloat64
for i, ds := range s.Distances {
if ds == nil {
continue
}
if ds.MinDistance < dist {
dist = ds.MinDistance
a = i
b = ds.MinIndex
}
}
return
} | [
"func",
"(",
"s",
"*",
"state",
")",
"MinDistance",
"(",
")",
"(",
"a",
",",
"b",
"int",
",",
"dist",
"float64",
")",
"{",
"dist",
"=",
"math",
".",
"MaxFloat64",
"\n\n",
"for",
"i",
",",
"ds",
":=",
"range",
"s",
".",
"Distances",
"{",
"if",
"... | // MinDistance returns the link with minimum distance.
// a is the index stored on the DistanceSet, b is the index of the smallest values. | [
"MinDistance",
"returns",
"the",
"link",
"with",
"minimum",
"distance",
".",
"a",
"is",
"the",
"index",
"stored",
"on",
"the",
"DistanceSet",
"b",
"is",
"the",
"index",
"of",
"the",
"smallest",
"values",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/clustering/set.go#L49-L66 |
133,255 | paulmach/go.geo | reducers/merge.go | MergeIndexMaps | func MergeIndexMaps(map1, map2 []int) []int {
result := make([]int, len(map2))
for i, v := range map2 {
result[i] = map1[v]
}
return result
} | go | func MergeIndexMaps(map1, map2 []int) []int {
result := make([]int, len(map2))
for i, v := range map2 {
result[i] = map1[v]
}
return result
} | [
"func",
"MergeIndexMaps",
"(",
"map1",
",",
"map2",
"[",
"]",
"int",
")",
"[",
"]",
"int",
"{",
"result",
":=",
"make",
"(",
"[",
"]",
"int",
",",
"len",
"(",
"map2",
")",
")",
"\n",
"for",
"i",
",",
"v",
":=",
"range",
"map2",
"{",
"result",
... | // MergeIndexMaps merges two index maps for use when chaining reducers.
// For example, to radially reduce and then DP, merge the index maps with this function
// to get a map from the original to the final path. | [
"MergeIndexMaps",
"merges",
"two",
"index",
"maps",
"for",
"use",
"when",
"chaining",
"reducers",
".",
"For",
"example",
"to",
"radially",
"reduce",
"and",
"then",
"DP",
"merge",
"the",
"index",
"maps",
"with",
"this",
"function",
"to",
"get",
"a",
"map",
... | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/reducers/merge.go#L6-L13 |
133,256 | paulmach/go.geo | clustering/clustering.go | ClusterPointers | func ClusterPointers(pointers []geo.Pointer, distancer ClusterDistancer, threshold float64) []*Cluster {
clusters := make([]*Cluster, 0, len(pointers))
for _, p := range pointers {
clusters = append(clusters, NewCluster(p))
}
return cluster(clusters, distancer, threshold)
} | go | func ClusterPointers(pointers []geo.Pointer, distancer ClusterDistancer, threshold float64) []*Cluster {
clusters := make([]*Cluster, 0, len(pointers))
for _, p := range pointers {
clusters = append(clusters, NewCluster(p))
}
return cluster(clusters, distancer, threshold)
} | [
"func",
"ClusterPointers",
"(",
"pointers",
"[",
"]",
"geo",
".",
"Pointer",
",",
"distancer",
"ClusterDistancer",
",",
"threshold",
"float64",
")",
"[",
"]",
"*",
"Cluster",
"{",
"clusters",
":=",
"make",
"(",
"[",
"]",
"*",
"Cluster",
",",
"0",
",",
... | // ClusterPointers will take a set of Pointers and cluster them using
// the distancer and threshold. | [
"ClusterPointers",
"will",
"take",
"a",
"set",
"of",
"Pointers",
"and",
"cluster",
"them",
"using",
"the",
"distancer",
"and",
"threshold",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/clustering/clustering.go#L11-L18 |
133,257 | paulmach/go.geo | clustering/clustering.go | ClusterClusters | func ClusterClusters(clusters []*Cluster, distancer ClusterDistancer, threshold float64) []*Cluster {
copiedClusters := make([]*Cluster, len(clusters), len(clusters))
copy(copiedClusters, clusters)
return cluster(copiedClusters, distancer, threshold)
} | go | func ClusterClusters(clusters []*Cluster, distancer ClusterDistancer, threshold float64) []*Cluster {
copiedClusters := make([]*Cluster, len(clusters), len(clusters))
copy(copiedClusters, clusters)
return cluster(copiedClusters, distancer, threshold)
} | [
"func",
"ClusterClusters",
"(",
"clusters",
"[",
"]",
"*",
"Cluster",
",",
"distancer",
"ClusterDistancer",
",",
"threshold",
"float64",
")",
"[",
"]",
"*",
"Cluster",
"{",
"copiedClusters",
":=",
"make",
"(",
"[",
"]",
"*",
"Cluster",
",",
"len",
"(",
"... | // ClusterClusters can be used if you've already created cluster objects
// using a prefilterer of something else. Original clusters will be copied
// so the original set will be unchanged. | [
"ClusterClusters",
"can",
"be",
"used",
"if",
"you",
"ve",
"already",
"created",
"cluster",
"objects",
"using",
"a",
"prefilterer",
"of",
"something",
"else",
".",
"Original",
"clusters",
"will",
"be",
"copied",
"so",
"the",
"original",
"set",
"will",
"be",
... | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/clustering/clustering.go#L23-L28 |
133,258 | paulmach/go.geo | clustering/clustering.go | cluster | func cluster(clusters []*Cluster, distancer ClusterDistancer, threshold float64) []*Cluster {
if len(clusters) < 2 {
return clusters
}
count := 0
for _, cluster := range clusters {
count += len(cluster.Pointers)
}
clusters, found := clusterClusters(
clusters,
// Default initialization, TODO: better buck... | go | func cluster(clusters []*Cluster, distancer ClusterDistancer, threshold float64) []*Cluster {
if len(clusters) < 2 {
return clusters
}
count := 0
for _, cluster := range clusters {
count += len(cluster.Pointers)
}
clusters, found := clusterClusters(
clusters,
// Default initialization, TODO: better buck... | [
"func",
"cluster",
"(",
"clusters",
"[",
"]",
"*",
"Cluster",
",",
"distancer",
"ClusterDistancer",
",",
"threshold",
"float64",
")",
"[",
"]",
"*",
"Cluster",
"{",
"if",
"len",
"(",
"clusters",
")",
"<",
"2",
"{",
"return",
"clusters",
"\n",
"}",
"\n\... | // cluster will modify the passed in clusters, centroid and list of pointers,
// so a copy must have been made before reaching this function. | [
"cluster",
"will",
"modify",
"the",
"passed",
"in",
"clusters",
"centroid",
"and",
"list",
"of",
"pointers",
"so",
"a",
"copy",
"must",
"have",
"been",
"made",
"before",
"reaching",
"this",
"function",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/clustering/clustering.go#L32-L58 |
133,259 | paulmach/go.geo | clustering/clustering.go | ClusterGeoPointers | func ClusterGeoPointers(pointers []geo.Pointer, threshold float64) []*Cluster {
clusters := make([]*Cluster, 0, len(pointers))
for _, p := range pointers {
clusters = append(clusters, NewCluster(p))
}
if len(clusters) < 2 {
return clusters
}
// performs the actual clustering
return geocluster(clusters, thr... | go | func ClusterGeoPointers(pointers []geo.Pointer, threshold float64) []*Cluster {
clusters := make([]*Cluster, 0, len(pointers))
for _, p := range pointers {
clusters = append(clusters, NewCluster(p))
}
if len(clusters) < 2 {
return clusters
}
// performs the actual clustering
return geocluster(clusters, thr... | [
"func",
"ClusterGeoPointers",
"(",
"pointers",
"[",
"]",
"geo",
".",
"Pointer",
",",
"threshold",
"float64",
")",
"[",
"]",
"*",
"Cluster",
"{",
"clusters",
":=",
"make",
"(",
"[",
"]",
"*",
"Cluster",
",",
"0",
",",
"len",
"(",
"pointers",
")",
")",... | // ClusterGeoPointers will take a set of Pointers and cluster them.
// It will project the points using mercator, scale the threshold, cluster, and project back.
// Performace is about 40% than simply using a geo distancer.
// This may not make sense for all geo datasets. | [
"ClusterGeoPointers",
"will",
"take",
"a",
"set",
"of",
"Pointers",
"and",
"cluster",
"them",
".",
"It",
"will",
"project",
"the",
"points",
"using",
"mercator",
"scale",
"the",
"threshold",
"cluster",
"and",
"project",
"back",
".",
"Performace",
"is",
"about"... | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/clustering/clustering.go#L64-L76 |
133,260 | paulmach/go.geo | clustering/clustering.go | ClusterGeoClusters | func ClusterGeoClusters(clusters []*Cluster, threshold float64) []*Cluster {
if len(clusters) < 2 {
return clusters
}
copiedClusters := make([]*Cluster, len(clusters), len(clusters))
for i, cluster := range clusters {
copiedClusters[i] = NewClusterWithCentroid(cluster.Centroid, cluster.Pointers...)
}
return... | go | func ClusterGeoClusters(clusters []*Cluster, threshold float64) []*Cluster {
if len(clusters) < 2 {
return clusters
}
copiedClusters := make([]*Cluster, len(clusters), len(clusters))
for i, cluster := range clusters {
copiedClusters[i] = NewClusterWithCentroid(cluster.Centroid, cluster.Pointers...)
}
return... | [
"func",
"ClusterGeoClusters",
"(",
"clusters",
"[",
"]",
"*",
"Cluster",
",",
"threshold",
"float64",
")",
"[",
"]",
"*",
"Cluster",
"{",
"if",
"len",
"(",
"clusters",
")",
"<",
"2",
"{",
"return",
"clusters",
"\n",
"}",
"\n\n",
"copiedClusters",
":=",
... | // ClusterGeoClusters can be used if you've already created clusters objects
// using a prefilterer of something else. | [
"ClusterGeoClusters",
"can",
"be",
"used",
"if",
"you",
"ve",
"already",
"created",
"clusters",
"objects",
"using",
"a",
"prefilterer",
"of",
"something",
"else",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/clustering/clustering.go#L80-L91 |
133,261 | paulmach/go.geo | clustering/clustering.go | geocluster | func geocluster(clusters []*Cluster, threshold float64) []*Cluster {
if len(clusters) < 2 {
return clusters
}
bound := geo.NewBoundFromPoints(clusters[0].Centroid, clusters[0].Centroid)
for _, cluster := range clusters {
bound.Extend(cluster.Centroid)
geo.Mercator.Project(cluster.Centroid)
}
factor := geo... | go | func geocluster(clusters []*Cluster, threshold float64) []*Cluster {
if len(clusters) < 2 {
return clusters
}
bound := geo.NewBoundFromPoints(clusters[0].Centroid, clusters[0].Centroid)
for _, cluster := range clusters {
bound.Extend(cluster.Centroid)
geo.Mercator.Project(cluster.Centroid)
}
factor := geo... | [
"func",
"geocluster",
"(",
"clusters",
"[",
"]",
"*",
"Cluster",
",",
"threshold",
"float64",
")",
"[",
"]",
"*",
"Cluster",
"{",
"if",
"len",
"(",
"clusters",
")",
"<",
"2",
"{",
"return",
"clusters",
"\n",
"}",
"\n\n",
"bound",
":=",
"geo",
".",
... | // will modify the passed in clusters, centroid and list of pathers,
// so a copy must have been made before reaching this function. | [
"will",
"modify",
"the",
"passed",
"in",
"clusters",
"centroid",
"and",
"list",
"of",
"pathers",
"so",
"a",
"copy",
"must",
"have",
"been",
"made",
"before",
"reaching",
"this",
"function",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/clustering/clustering.go#L95-L127 |
133,262 | paulmach/go.geo | point.go | NewPointFromQuadkeyString | func NewPointFromQuadkeyString(key string) *Point {
i, _ := strconv.ParseInt(key, 4, 64)
return NewPointFromQuadkey(i, len(key))
} | go | func NewPointFromQuadkeyString(key string) *Point {
i, _ := strconv.ParseInt(key, 4, 64)
return NewPointFromQuadkey(i, len(key))
} | [
"func",
"NewPointFromQuadkeyString",
"(",
"key",
"string",
")",
"*",
"Point",
"{",
"i",
",",
"_",
":=",
"strconv",
".",
"ParseInt",
"(",
"key",
",",
"4",
",",
"64",
")",
"\n",
"return",
"NewPointFromQuadkey",
"(",
"i",
",",
"len",
"(",
"key",
")",
")... | // NewPointFromQuadkeyString creates a new point from a quadkey string. | [
"NewPointFromQuadkeyString",
"creates",
"a",
"new",
"point",
"from",
"a",
"quadkey",
"string",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/point.go#L49-L52 |
133,263 | paulmach/go.geo | point.go | NewPointFromGeoHash | func NewPointFromGeoHash(hash string) *Point {
west, east, south, north := geoHash2ranges(hash)
return NewPoint((west+east)/2.0, (north+south)/2.0)
} | go | func NewPointFromGeoHash(hash string) *Point {
west, east, south, north := geoHash2ranges(hash)
return NewPoint((west+east)/2.0, (north+south)/2.0)
} | [
"func",
"NewPointFromGeoHash",
"(",
"hash",
"string",
")",
"*",
"Point",
"{",
"west",
",",
"east",
",",
"south",
",",
"north",
":=",
"geoHash2ranges",
"(",
"hash",
")",
"\n",
"return",
"NewPoint",
"(",
"(",
"west",
"+",
"east",
")",
"/",
"2.0",
",",
... | // NewPointFromGeoHash creates a new point at the center of the geohash range. | [
"NewPointFromGeoHash",
"creates",
"a",
"new",
"point",
"at",
"the",
"center",
"of",
"the",
"geohash",
"range",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/point.go#L55-L58 |
133,264 | paulmach/go.geo | point.go | NewPointFromGeoHashInt64 | func NewPointFromGeoHashInt64(hash int64, bits int) *Point {
west, east, south, north := geoHashInt2ranges(hash, bits)
return NewPoint((west+east)/2.0, (north+south)/2.0)
} | go | func NewPointFromGeoHashInt64(hash int64, bits int) *Point {
west, east, south, north := geoHashInt2ranges(hash, bits)
return NewPoint((west+east)/2.0, (north+south)/2.0)
} | [
"func",
"NewPointFromGeoHashInt64",
"(",
"hash",
"int64",
",",
"bits",
"int",
")",
"*",
"Point",
"{",
"west",
",",
"east",
",",
"south",
",",
"north",
":=",
"geoHashInt2ranges",
"(",
"hash",
",",
"bits",
")",
"\n",
"return",
"NewPoint",
"(",
"(",
"west",... | // NewPointFromGeoHashInt64 creates a new point at the center of the
// integer version of a geohash range. bits indicates the precision of the hash. | [
"NewPointFromGeoHashInt64",
"creates",
"a",
"new",
"point",
"at",
"the",
"center",
"of",
"the",
"integer",
"version",
"of",
"a",
"geohash",
"range",
".",
"bits",
"indicates",
"the",
"precision",
"of",
"the",
"hash",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/point.go#L62-L65 |
133,265 | paulmach/go.geo | point.go | DistanceFrom | func (p *Point) DistanceFrom(point *Point) float64 {
d0 := (point[0] - p[0])
d1 := (point[1] - p[1])
return math.Sqrt(d0*d0 + d1*d1)
} | go | func (p *Point) DistanceFrom(point *Point) float64 {
d0 := (point[0] - p[0])
d1 := (point[1] - p[1])
return math.Sqrt(d0*d0 + d1*d1)
} | [
"func",
"(",
"p",
"*",
"Point",
")",
"DistanceFrom",
"(",
"point",
"*",
"Point",
")",
"float64",
"{",
"d0",
":=",
"(",
"point",
"[",
"0",
"]",
"-",
"p",
"[",
"0",
"]",
")",
"\n",
"d1",
":=",
"(",
"point",
"[",
"1",
"]",
"-",
"p",
"[",
"1",
... | // DistanceFrom returns the Euclidean distance between the points. | [
"DistanceFrom",
"returns",
"the",
"Euclidean",
"distance",
"between",
"the",
"points",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/point.go#L79-L83 |
133,266 | paulmach/go.geo | point.go | SquaredDistanceFrom | func (p *Point) SquaredDistanceFrom(point *Point) float64 {
d0 := (point[0] - p[0])
d1 := (point[1] - p[1])
return d0*d0 + d1*d1
} | go | func (p *Point) SquaredDistanceFrom(point *Point) float64 {
d0 := (point[0] - p[0])
d1 := (point[1] - p[1])
return d0*d0 + d1*d1
} | [
"func",
"(",
"p",
"*",
"Point",
")",
"SquaredDistanceFrom",
"(",
"point",
"*",
"Point",
")",
"float64",
"{",
"d0",
":=",
"(",
"point",
"[",
"0",
"]",
"-",
"p",
"[",
"0",
"]",
")",
"\n",
"d1",
":=",
"(",
"point",
"[",
"1",
"]",
"-",
"p",
"[",
... | // SquaredDistanceFrom returns the squared Euclidean distance between the points.
// This avoids a sqrt computation. | [
"SquaredDistanceFrom",
"returns",
"the",
"squared",
"Euclidean",
"distance",
"between",
"the",
"points",
".",
"This",
"avoids",
"a",
"sqrt",
"computation",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/point.go#L87-L91 |
133,267 | paulmach/go.geo | point.go | GeoDistanceFrom | func (p *Point) GeoDistanceFrom(point *Point, haversine ...bool) float64 {
dLat := deg2rad(point.Lat() - p.Lat())
dLng := math.Abs(deg2rad(point.Lng() - p.Lng()))
if yesHaversine(haversine) {
// yes trig functions
dLat2Sin := math.Sin(dLat / 2)
dLng2Sin := math.Sin(dLng / 2)
a := dLat2Sin*dLat2Sin + math.Co... | go | func (p *Point) GeoDistanceFrom(point *Point, haversine ...bool) float64 {
dLat := deg2rad(point.Lat() - p.Lat())
dLng := math.Abs(deg2rad(point.Lng() - p.Lng()))
if yesHaversine(haversine) {
// yes trig functions
dLat2Sin := math.Sin(dLat / 2)
dLng2Sin := math.Sin(dLng / 2)
a := dLat2Sin*dLat2Sin + math.Co... | [
"func",
"(",
"p",
"*",
"Point",
")",
"GeoDistanceFrom",
"(",
"point",
"*",
"Point",
",",
"haversine",
"...",
"bool",
")",
"float64",
"{",
"dLat",
":=",
"deg2rad",
"(",
"point",
".",
"Lat",
"(",
")",
"-",
"p",
".",
"Lat",
"(",
")",
")",
"\n",
"dLn... | // GeoDistanceFrom returns the geodesic distance in meters. | [
"GeoDistanceFrom",
"returns",
"the",
"geodesic",
"distance",
"in",
"meters",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/point.go#L94-L114 |
133,268 | paulmach/go.geo | point.go | BearingTo | func (p *Point) BearingTo(point *Point) float64 {
dLng := deg2rad(point.Lng() - p.Lng())
pLatRad := deg2rad(p.Lat())
pointLatRad := deg2rad(point.Lat())
y := math.Sin(dLng) * math.Cos(pointLatRad)
x := math.Cos(pLatRad)*math.Sin(pointLatRad) - math.Sin(pLatRad)*math.Cos(pointLatRad)*math.Cos(dLng)
return rad2d... | go | func (p *Point) BearingTo(point *Point) float64 {
dLng := deg2rad(point.Lng() - p.Lng())
pLatRad := deg2rad(p.Lat())
pointLatRad := deg2rad(point.Lat())
y := math.Sin(dLng) * math.Cos(pointLatRad)
x := math.Cos(pLatRad)*math.Sin(pointLatRad) - math.Sin(pLatRad)*math.Cos(pointLatRad)*math.Cos(dLng)
return rad2d... | [
"func",
"(",
"p",
"*",
"Point",
")",
"BearingTo",
"(",
"point",
"*",
"Point",
")",
"float64",
"{",
"dLng",
":=",
"deg2rad",
"(",
"point",
".",
"Lng",
"(",
")",
"-",
"p",
".",
"Lng",
"(",
")",
")",
"\n\n",
"pLatRad",
":=",
"deg2rad",
"(",
"p",
"... | // BearingTo computes the direction one must start traveling on earth
// to be heading to the given point. | [
"BearingTo",
"computes",
"the",
"direction",
"one",
"must",
"start",
"traveling",
"on",
"earth",
"to",
"be",
"heading",
"to",
"the",
"given",
"point",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/point.go#L118-L128 |
133,269 | paulmach/go.geo | point.go | GeoHashInt64 | func (p *Point) GeoHashInt64(bits int) (hash int64) {
// This code was inspired by https://github.com/broady/gogeohash
latMin, latMax := -90.0, 90.0
lngMin, lngMax := -180.0, 180.0
for i := 0; i < bits; i++ {
hash <<= 1
// interleave bits
if i%2 == 0 {
mid := (lngMin + lngMax) / 2.0
if p[0] > mid {
... | go | func (p *Point) GeoHashInt64(bits int) (hash int64) {
// This code was inspired by https://github.com/broady/gogeohash
latMin, latMax := -90.0, 90.0
lngMin, lngMax := -180.0, 180.0
for i := 0; i < bits; i++ {
hash <<= 1
// interleave bits
if i%2 == 0 {
mid := (lngMin + lngMax) / 2.0
if p[0] > mid {
... | [
"func",
"(",
"p",
"*",
"Point",
")",
"GeoHashInt64",
"(",
"bits",
"int",
")",
"(",
"hash",
"int64",
")",
"{",
"// This code was inspired by https://github.com/broady/gogeohash",
"latMin",
",",
"latMax",
":=",
"-",
"90.0",
",",
"90.0",
"\n",
"lngMin",
",",
"lng... | // GeoHashInt64 returns the integer version of the geohash
// down to the given number of bits.
// The main usecase for this function is to be able to do integer based ordering of points.
// In that case the number of bits should be the same for all encodings. | [
"GeoHashInt64",
"returns",
"the",
"integer",
"version",
"of",
"the",
"geohash",
"down",
"to",
"the",
"given",
"number",
"of",
"bits",
".",
"The",
"main",
"usecase",
"for",
"this",
"function",
"is",
"to",
"be",
"able",
"to",
"do",
"integer",
"based",
"order... | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/point.go#L184-L214 |
133,270 | paulmach/go.geo | point.go | Add | func (p *Point) Add(point *Point) *Point {
p[0] += point[0]
p[1] += point[1]
return p
} | go | func (p *Point) Add(point *Point) *Point {
p[0] += point[0]
p[1] += point[1]
return p
} | [
"func",
"(",
"p",
"*",
"Point",
")",
"Add",
"(",
"point",
"*",
"Point",
")",
"*",
"Point",
"{",
"p",
"[",
"0",
"]",
"+=",
"point",
"[",
"0",
"]",
"\n",
"p",
"[",
"1",
"]",
"+=",
"point",
"[",
"1",
"]",
"\n\n",
"return",
"p",
"\n",
"}"
] | // Add a point to the given point. | [
"Add",
"a",
"point",
"to",
"the",
"given",
"point",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/point.go#L217-L222 |
133,271 | paulmach/go.geo | point.go | Subtract | func (p *Point) Subtract(point *Point) *Point {
p[0] -= point[0]
p[1] -= point[1]
return p
} | go | func (p *Point) Subtract(point *Point) *Point {
p[0] -= point[0]
p[1] -= point[1]
return p
} | [
"func",
"(",
"p",
"*",
"Point",
")",
"Subtract",
"(",
"point",
"*",
"Point",
")",
"*",
"Point",
"{",
"p",
"[",
"0",
"]",
"-=",
"point",
"[",
"0",
"]",
"\n",
"p",
"[",
"1",
"]",
"-=",
"point",
"[",
"1",
"]",
"\n\n",
"return",
"p",
"\n",
"}"
... | // Subtract a point from the given point. | [
"Subtract",
"a",
"point",
"from",
"the",
"given",
"point",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/point.go#L225-L230 |
133,272 | paulmach/go.geo | point.go | Scale | func (p *Point) Scale(factor float64) *Point {
p[0] *= factor
p[1] *= factor
return p
} | go | func (p *Point) Scale(factor float64) *Point {
p[0] *= factor
p[1] *= factor
return p
} | [
"func",
"(",
"p",
"*",
"Point",
")",
"Scale",
"(",
"factor",
"float64",
")",
"*",
"Point",
"{",
"p",
"[",
"0",
"]",
"*=",
"factor",
"\n",
"p",
"[",
"1",
"]",
"*=",
"factor",
"\n\n",
"return",
"p",
"\n",
"}"
] | // Scale each component of the point. | [
"Scale",
"each",
"component",
"of",
"the",
"point",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/point.go#L251-L256 |
133,273 | paulmach/go.geo | point.go | Equals | func (p *Point) Equals(point *Point) bool {
if p[0] == point[0] && p[1] == point[1] {
return true
}
return false
} | go | func (p *Point) Equals(point *Point) bool {
if p[0] == point[0] && p[1] == point[1] {
return true
}
return false
} | [
"func",
"(",
"p",
"*",
"Point",
")",
"Equals",
"(",
"point",
"*",
"Point",
")",
"bool",
"{",
"if",
"p",
"[",
"0",
"]",
"==",
"point",
"[",
"0",
"]",
"&&",
"p",
"[",
"1",
"]",
"==",
"point",
"[",
"1",
"]",
"{",
"return",
"true",
"\n",
"}",
... | // Equals checks if the point represents the same point or vector. | [
"Equals",
"checks",
"if",
"the",
"point",
"represents",
"the",
"same",
"point",
"or",
"vector",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/point.go#L274-L280 |
133,274 | paulmach/go.geo | point.go | ToGeoJSON | func (p Point) ToGeoJSON() *geojson.Feature {
return geojson.NewPointFeature([]float64{p[0], p[1]})
} | go | func (p Point) ToGeoJSON() *geojson.Feature {
return geojson.NewPointFeature([]float64{p[0], p[1]})
} | [
"func",
"(",
"p",
"Point",
")",
"ToGeoJSON",
"(",
")",
"*",
"geojson",
".",
"Feature",
"{",
"return",
"geojson",
".",
"NewPointFeature",
"(",
"[",
"]",
"float64",
"{",
"p",
"[",
"0",
"]",
",",
"p",
"[",
"1",
"]",
"}",
")",
"\n",
"}"
] | // ToGeoJSON creates a new geojson feature with a point geometry. | [
"ToGeoJSON",
"creates",
"a",
"new",
"geojson",
"feature",
"with",
"a",
"point",
"geometry",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/point.go#L327-L329 |
133,275 | paulmach/go.geo | point.go | Round | func (p *Point) Round(factor ...int) *Point {
f := 1.0e5
if len(factor) != 0 {
f = float64(factor[0])
}
for idx, val := range p {
x := val * f
p[idx] = math.Floor(x+0.5) / f
}
return p
} | go | func (p *Point) Round(factor ...int) *Point {
f := 1.0e5
if len(factor) != 0 {
f = float64(factor[0])
}
for idx, val := range p {
x := val * f
p[idx] = math.Floor(x+0.5) / f
}
return p
} | [
"func",
"(",
"p",
"*",
"Point",
")",
"Round",
"(",
"factor",
"...",
"int",
")",
"*",
"Point",
"{",
"f",
":=",
"1.0e5",
"\n",
"if",
"len",
"(",
"factor",
")",
"!=",
"0",
"{",
"f",
"=",
"float64",
"(",
"factor",
"[",
"0",
"]",
")",
"\n",
"}",
... | // Round returns a point which coordinates are rounded
// Factor defaults to 1.0e5 | [
"Round",
"returns",
"a",
"point",
"which",
"coordinates",
"are",
"rounded",
"Factor",
"defaults",
"to",
"1",
".",
"0e5"
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/point.go#L344-L356 |
133,276 | paulmach/go.geo | wkb.go | NewPointFromWKB | func NewPointFromWKB(wkb []byte) *Point {
p := &Point{}
if err := p.unmarshalWKB(wkb); err != nil {
return nil
}
return p
} | go | func NewPointFromWKB(wkb []byte) *Point {
p := &Point{}
if err := p.unmarshalWKB(wkb); err != nil {
return nil
}
return p
} | [
"func",
"NewPointFromWKB",
"(",
"wkb",
"[",
"]",
"byte",
")",
"*",
"Point",
"{",
"p",
":=",
"&",
"Point",
"{",
"}",
"\n",
"if",
"err",
":=",
"p",
".",
"unmarshalWKB",
"(",
"wkb",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\... | // NewPointFromWKB will take raw WKB and set the data for a new point.
// The WKB data must be of type Point. Will return nil if invalid WKB point. | [
"NewPointFromWKB",
"will",
"take",
"raw",
"WKB",
"and",
"set",
"the",
"data",
"for",
"a",
"new",
"point",
".",
"The",
"WKB",
"data",
"must",
"be",
"of",
"type",
"Point",
".",
"Will",
"return",
"nil",
"if",
"invalid",
"WKB",
"point",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/wkb.go#L25-L32 |
133,277 | paulmach/go.geo | wkb.go | NewLineFromWKB | func NewLineFromWKB(wkb []byte) *Line {
l := &Line{}
if err := l.unmarshalWKB(wkb); err != nil {
return nil
}
return l
} | go | func NewLineFromWKB(wkb []byte) *Line {
l := &Line{}
if err := l.unmarshalWKB(wkb); err != nil {
return nil
}
return l
} | [
"func",
"NewLineFromWKB",
"(",
"wkb",
"[",
"]",
"byte",
")",
"*",
"Line",
"{",
"l",
":=",
"&",
"Line",
"{",
"}",
"\n",
"if",
"err",
":=",
"l",
".",
"unmarshalWKB",
"(",
"wkb",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n... | // NewLineFromWKB will take raw WKB and set the data for a new line.
// The WKB data must of type LineString and only contain 2 points.
// Will return nil if invalid WKB. | [
"NewLineFromWKB",
"will",
"take",
"raw",
"WKB",
"and",
"set",
"the",
"data",
"for",
"a",
"new",
"line",
".",
"The",
"WKB",
"data",
"must",
"of",
"type",
"LineString",
"and",
"only",
"contain",
"2",
"points",
".",
"Will",
"return",
"nil",
"if",
"invalid",... | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/wkb.go#L37-L44 |
133,278 | paulmach/go.geo | wkb.go | NewPointSetFromWKB | func NewPointSetFromWKB(wkb []byte) *PointSet {
ps := &PointSet{}
if err := ps.unmarshalWKB(wkb); err != nil {
return nil
}
return ps
} | go | func NewPointSetFromWKB(wkb []byte) *PointSet {
ps := &PointSet{}
if err := ps.unmarshalWKB(wkb); err != nil {
return nil
}
return ps
} | [
"func",
"NewPointSetFromWKB",
"(",
"wkb",
"[",
"]",
"byte",
")",
"*",
"PointSet",
"{",
"ps",
":=",
"&",
"PointSet",
"{",
"}",
"\n",
"if",
"err",
":=",
"ps",
".",
"unmarshalWKB",
"(",
"wkb",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
"\n",
... | // NewPointSetFromWKB will take raw WKB and set the data for a new point set.
// The WKB data must be of type LineString, Polygon or MultiPoint.
// Will return nil if invalid WKB. | [
"NewPointSetFromWKB",
"will",
"take",
"raw",
"WKB",
"and",
"set",
"the",
"data",
"for",
"a",
"new",
"point",
"set",
".",
"The",
"WKB",
"data",
"must",
"be",
"of",
"type",
"LineString",
"Polygon",
"or",
"MultiPoint",
".",
"Will",
"return",
"nil",
"if",
"i... | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/wkb.go#L49-L56 |
133,279 | paulmach/go.geo | wkb.go | NewPathFromWKB | func NewPathFromWKB(wkb []byte) *Path {
p := NewPath()
if err := p.PointSet.unmarshalWKB(wkb); err != nil {
return nil
}
return p
} | go | func NewPathFromWKB(wkb []byte) *Path {
p := NewPath()
if err := p.PointSet.unmarshalWKB(wkb); err != nil {
return nil
}
return p
} | [
"func",
"NewPathFromWKB",
"(",
"wkb",
"[",
"]",
"byte",
")",
"*",
"Path",
"{",
"p",
":=",
"NewPath",
"(",
")",
"\n",
"if",
"err",
":=",
"p",
".",
"PointSet",
".",
"unmarshalWKB",
"(",
"wkb",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
"\n... | // NewPathFromWKB will take raw WKB and set the data for a new path.
// The WKB data must be of type LineString, Polygon or MultiPoint.
// Will return nil if invalid WKB. | [
"NewPathFromWKB",
"will",
"take",
"raw",
"WKB",
"and",
"set",
"the",
"data",
"for",
"a",
"new",
"path",
".",
"The",
"WKB",
"data",
"must",
"be",
"of",
"type",
"LineString",
"Polygon",
"or",
"MultiPoint",
".",
"Will",
"return",
"nil",
"if",
"invalid",
"WK... | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/wkb.go#L61-L68 |
133,280 | cloudfoundry/inigo | helpers/portauthority/portauthority.go | ClaimPorts | func (p *portAllocator) ClaimPorts(numPorts int) (uint16, error) {
port := p.nextPort
if p.endingPort < port+uint16(numPorts-1) {
return 0, errors.New("insufficient ports available")
}
p.nextPort = p.nextPort + uint16(numPorts)
return uint16(port), nil
} | go | func (p *portAllocator) ClaimPorts(numPorts int) (uint16, error) {
port := p.nextPort
if p.endingPort < port+uint16(numPorts-1) {
return 0, errors.New("insufficient ports available")
}
p.nextPort = p.nextPort + uint16(numPorts)
return uint16(port), nil
} | [
"func",
"(",
"p",
"*",
"portAllocator",
")",
"ClaimPorts",
"(",
"numPorts",
"int",
")",
"(",
"uint16",
",",
"error",
")",
"{",
"port",
":=",
"p",
".",
"nextPort",
"\n",
"if",
"p",
".",
"endingPort",
"<",
"port",
"+",
"uint16",
"(",
"numPorts",
"-",
... | // ClaimPorts returns a new uint16 port to be used for testing processes.
//
// No guarantees are made that something is not already listening on that port.
// If running multiple processes, you should initialize the portAllocator with different ranges.
// If ports are also allocated by another method, the portAllocato... | [
"ClaimPorts",
"returns",
"a",
"new",
"uint16",
"port",
"to",
"be",
"used",
"for",
"testing",
"processes",
".",
"No",
"guarantees",
"are",
"made",
"that",
"something",
"is",
"not",
"already",
"listening",
"on",
"that",
"port",
".",
"If",
"running",
"multiple"... | 414d9ec47804264460f9347dcbcdcbc5124990b3 | https://github.com/cloudfoundry/inigo/blob/414d9ec47804264460f9347dcbcdcbc5124990b3/helpers/portauthority/portauthority.go#L42-L50 |
133,281 | rancher/rancher-compose | rancher/volume.go | InspectTemplate | func (v *Volume) InspectTemplate(ctx context.Context) (*client.VolumeTemplate, error) {
volumes, err := v.context.Client.VolumeTemplate.List(&client.ListOpts{
Filters: map[string]interface{}{
"name": v.name,
"stackId": v.context.Stack.Id,
},
})
if err != nil {
return nil, err
}
if len(volumes.Data)... | go | func (v *Volume) InspectTemplate(ctx context.Context) (*client.VolumeTemplate, error) {
volumes, err := v.context.Client.VolumeTemplate.List(&client.ListOpts{
Filters: map[string]interface{}{
"name": v.name,
"stackId": v.context.Stack.Id,
},
})
if err != nil {
return nil, err
}
if len(volumes.Data)... | [
"func",
"(",
"v",
"*",
"Volume",
")",
"InspectTemplate",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"*",
"client",
".",
"VolumeTemplate",
",",
"error",
")",
"{",
"volumes",
",",
"err",
":=",
"v",
".",
"context",
".",
"Client",
".",
"VolumeTemplat... | // InspectTemplate looks up a volume template | [
"InspectTemplate",
"looks",
"up",
"a",
"volume",
"template"
] | 88b67b0c10b69c6f0da66d208a3eea7351864dca | https://github.com/rancher/rancher-compose/blob/88b67b0c10b69c6f0da66d208a3eea7351864dca/rancher/volume.go#L73-L89 |
133,282 | rancher/rancher-compose | rancher/volume.go | InspectExternal | func (v *Volume) InspectExternal(ctx context.Context) (*client.Volume, error) {
volumes, err := v.context.Client.Volume.List(&client.ListOpts{
Filters: map[string]interface{}{
"name": v.name,
},
})
if err != nil {
return nil, err
}
if len(volumes.Data) > 0 {
return &volumes.Data[0], nil
}
return nil... | go | func (v *Volume) InspectExternal(ctx context.Context) (*client.Volume, error) {
volumes, err := v.context.Client.Volume.List(&client.ListOpts{
Filters: map[string]interface{}{
"name": v.name,
},
})
if err != nil {
return nil, err
}
if len(volumes.Data) > 0 {
return &volumes.Data[0], nil
}
return nil... | [
"func",
"(",
"v",
"*",
"Volume",
")",
"InspectExternal",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"*",
"client",
".",
"Volume",
",",
"error",
")",
"{",
"volumes",
",",
"err",
":=",
"v",
".",
"context",
".",
"Client",
".",
"Volume",
".",
"Li... | // InspectExternal looks up a volume | [
"InspectExternal",
"looks",
"up",
"a",
"volume"
] | 88b67b0c10b69c6f0da66d208a3eea7351864dca | https://github.com/rancher/rancher-compose/blob/88b67b0c10b69c6f0da66d208a3eea7351864dca/rancher/volume.go#L92-L107 |
133,283 | rancher/rancher-compose | app/app.go | StopCommand | func StopCommand(factory app.ProjectFactory) cli.Command {
return cli.Command{
Name: "stop",
ShortName: "down",
Usage: "Stop services",
Action: app.WithProject(factory, app.ProjectStop),
Flags: []cli.Flag{
cli.IntFlag{
Name: "timeout,t",
Usage: "Specify a shutdown timeout in seconds."... | go | func StopCommand(factory app.ProjectFactory) cli.Command {
return cli.Command{
Name: "stop",
ShortName: "down",
Usage: "Stop services",
Action: app.WithProject(factory, app.ProjectStop),
Flags: []cli.Flag{
cli.IntFlag{
Name: "timeout,t",
Usage: "Specify a shutdown timeout in seconds."... | [
"func",
"StopCommand",
"(",
"factory",
"app",
".",
"ProjectFactory",
")",
"cli",
".",
"Command",
"{",
"return",
"cli",
".",
"Command",
"{",
"Name",
":",
"\"",
"\"",
",",
"ShortName",
":",
"\"",
"\"",
",",
"Usage",
":",
"\"",
"\"",
",",
"Action",
":",... | // StopCommand defines the libcompose stop subcommand. | [
"StopCommand",
"defines",
"the",
"libcompose",
"stop",
"subcommand",
"."
] | 88b67b0c10b69c6f0da66d208a3eea7351864dca | https://github.com/rancher/rancher-compose/blob/88b67b0c10b69c6f0da66d208a3eea7351864dca/app/app.go#L250-L264 |
133,284 | rancher/rancher-compose | lookup/file.go | ResolvePath | func (f *FileResourceLookup) ResolvePath(path, inFile string) string {
vs := strings.SplitN(path, ":", 2)
if len(vs) == 2 && !filepath.IsAbs(vs[0]) {
log.Warnf("Rancher Compose will not resolve relative path %s", vs[0])
}
return path
} | go | func (f *FileResourceLookup) ResolvePath(path, inFile string) string {
vs := strings.SplitN(path, ":", 2)
if len(vs) == 2 && !filepath.IsAbs(vs[0]) {
log.Warnf("Rancher Compose will not resolve relative path %s", vs[0])
}
return path
} | [
"func",
"(",
"f",
"*",
"FileResourceLookup",
")",
"ResolvePath",
"(",
"path",
",",
"inFile",
"string",
")",
"string",
"{",
"vs",
":=",
"strings",
".",
"SplitN",
"(",
"path",
",",
"\"",
"\"",
",",
"2",
")",
"\n",
"if",
"len",
"(",
"vs",
")",
"==",
... | // Give a warning rather than resolve relative paths | [
"Give",
"a",
"warning",
"rather",
"than",
"resolve",
"relative",
"paths"
] | 88b67b0c10b69c6f0da66d208a3eea7351864dca | https://github.com/rancher/rancher-compose/blob/88b67b0c10b69c6f0da66d208a3eea7351864dca/lookup/file.go#L16-L22 |
133,285 | qor/validations | validations.go | NewError | func NewError(resource interface{}, column, err string) error {
return &Error{Resource: resource, Column: column, Message: err}
} | go | func NewError(resource interface{}, column, err string) error {
return &Error{Resource: resource, Column: column, Message: err}
} | [
"func",
"NewError",
"(",
"resource",
"interface",
"{",
"}",
",",
"column",
",",
"err",
"string",
")",
"error",
"{",
"return",
"&",
"Error",
"{",
"Resource",
":",
"resource",
",",
"Column",
":",
"column",
",",
"Message",
":",
"err",
"}",
"\n",
"}"
] | // NewError generate a new error for a model's field | [
"NewError",
"generate",
"a",
"new",
"error",
"for",
"a",
"model",
"s",
"field"
] | f364bca61b46bd48a5e32552a37758864fdf005d | https://github.com/qor/validations/blob/f364bca61b46bd48a5e32552a37758864fdf005d/validations.go#L10-L12 |
133,286 | qor/validations | validations.go | Label | func (err Error) Label() string {
scope := gorm.Scope{Value: err.Resource}
return fmt.Sprintf("%v_%v_%v", scope.GetModelStruct().ModelType.Name(), scope.PrimaryKeyValue(), err.Column)
} | go | func (err Error) Label() string {
scope := gorm.Scope{Value: err.Resource}
return fmt.Sprintf("%v_%v_%v", scope.GetModelStruct().ModelType.Name(), scope.PrimaryKeyValue(), err.Column)
} | [
"func",
"(",
"err",
"Error",
")",
"Label",
"(",
")",
"string",
"{",
"scope",
":=",
"gorm",
".",
"Scope",
"{",
"Value",
":",
"err",
".",
"Resource",
"}",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"scope",
".",
"GetModelStruct",
"(... | // Label is a label including model type, primary key and column name | [
"Label",
"is",
"a",
"label",
"including",
"model",
"type",
"primary",
"key",
"and",
"column",
"name"
] | f364bca61b46bd48a5e32552a37758864fdf005d | https://github.com/qor/validations/blob/f364bca61b46bd48a5e32552a37758864fdf005d/validations.go#L22-L25 |
133,287 | optiopay/kafka | broker.go | NewBrokerConf | func NewBrokerConf(clientID string) BrokerConf {
return BrokerConf{
ClientID: clientID,
DialTimeout: 10 * time.Second,
DialRetryLimit: 10,
DialRetryWait: 500 * time.Millisecond,
AllowTopicCreation: false,
LeaderRetryLimit: 10,
LeaderRetryWait: 500 * time.Millisecond,
Retr... | go | func NewBrokerConf(clientID string) BrokerConf {
return BrokerConf{
ClientID: clientID,
DialTimeout: 10 * time.Second,
DialRetryLimit: 10,
DialRetryWait: 500 * time.Millisecond,
AllowTopicCreation: false,
LeaderRetryLimit: 10,
LeaderRetryWait: 500 * time.Millisecond,
Retr... | [
"func",
"NewBrokerConf",
"(",
"clientID",
"string",
")",
"BrokerConf",
"{",
"return",
"BrokerConf",
"{",
"ClientID",
":",
"clientID",
",",
"DialTimeout",
":",
"10",
"*",
"time",
".",
"Second",
",",
"DialRetryLimit",
":",
"10",
",",
"DialRetryWait",
":",
"500... | // NewBrokerConf returns the default broker configuration. | [
"NewBrokerConf",
"returns",
"the",
"default",
"broker",
"configuration",
"."
] | 6c126522640ec5e8e232d0e219160b30a92814f8 | https://github.com/optiopay/kafka/blob/6c126522640ec5e8e232d0e219160b30a92814f8/broker.go#L189-L203 |
133,288 | optiopay/kafka | broker.go | Dial | func Dial(nodeAddresses []string, conf BrokerConf) (*Broker, error) {
if len(nodeAddresses) == 0 {
return nil, errors.New("no addresses provided")
}
broker := &Broker{
conf: conf,
conns: make(map[int32]*connection),
nodeAddresses: nodeAddresses,
}
for i := 0; i < conf.DialRetryLimit; i++... | go | func Dial(nodeAddresses []string, conf BrokerConf) (*Broker, error) {
if len(nodeAddresses) == 0 {
return nil, errors.New("no addresses provided")
}
broker := &Broker{
conf: conf,
conns: make(map[int32]*connection),
nodeAddresses: nodeAddresses,
}
for i := 0; i < conf.DialRetryLimit; i++... | [
"func",
"Dial",
"(",
"nodeAddresses",
"[",
"]",
"string",
",",
"conf",
"BrokerConf",
")",
"(",
"*",
"Broker",
",",
"error",
")",
"{",
"if",
"len",
"(",
"nodeAddresses",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"... | // Dial connects to any node from a given list of kafka addresses and after
// successful metadata fetch, returns broker.
//
// The returned broker is not initially connected to any kafka node. | [
"Dial",
"connects",
"to",
"any",
"node",
"from",
"a",
"given",
"list",
"of",
"kafka",
"addresses",
"and",
"after",
"successful",
"metadata",
"fetch",
"returns",
"broker",
".",
"The",
"returned",
"broker",
"is",
"not",
"initially",
"connected",
"to",
"any",
"... | 6c126522640ec5e8e232d0e219160b30a92814f8 | https://github.com/optiopay/kafka/blob/6c126522640ec5e8e232d0e219160b30a92814f8/broker.go#L220-L248 |
133,289 | optiopay/kafka | broker.go | Close | func (b *Broker) Close() {
b.mu.Lock()
defer b.mu.Unlock()
for nodeID, conn := range b.conns {
if err := conn.Close(); err != nil {
b.conf.Logger.Info("cannot close node connection",
"nodeID", nodeID,
"error", err)
}
}
} | go | func (b *Broker) Close() {
b.mu.Lock()
defer b.mu.Unlock()
for nodeID, conn := range b.conns {
if err := conn.Close(); err != nil {
b.conf.Logger.Info("cannot close node connection",
"nodeID", nodeID,
"error", err)
}
}
} | [
"func",
"(",
"b",
"*",
"Broker",
")",
"Close",
"(",
")",
"{",
"b",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"b",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"for",
"nodeID",
",",
"conn",
":=",
"range",
"b",
".",
"conns",
"{",
"if",
"e... | // Close closes the broker and all active kafka nodes connections. | [
"Close",
"closes",
"the",
"broker",
"and",
"all",
"active",
"kafka",
"nodes",
"connections",
"."
] | 6c126522640ec5e8e232d0e219160b30a92814f8 | https://github.com/optiopay/kafka/blob/6c126522640ec5e8e232d0e219160b30a92814f8/broker.go#L260-L270 |
133,290 | optiopay/kafka | broker.go | Metadata | func (b *Broker) Metadata() (*proto.MetadataResp, error) {
b.mu.Lock()
defer b.mu.Unlock()
return b.fetchMetadata()
} | go | func (b *Broker) Metadata() (*proto.MetadataResp, error) {
b.mu.Lock()
defer b.mu.Unlock()
return b.fetchMetadata()
} | [
"func",
"(",
"b",
"*",
"Broker",
")",
"Metadata",
"(",
")",
"(",
"*",
"proto",
".",
"MetadataResp",
",",
"error",
")",
"{",
"b",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"b",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"return",
"b",
".... | // Metadata requests metadata information from any node. | [
"Metadata",
"requests",
"metadata",
"information",
"from",
"any",
"node",
"."
] | 6c126522640ec5e8e232d0e219160b30a92814f8 | https://github.com/optiopay/kafka/blob/6c126522640ec5e8e232d0e219160b30a92814f8/broker.go#L273-L277 |
133,291 | optiopay/kafka | broker.go | CreateTopic | func (b *Broker) CreateTopic(topics []proto.TopicInfo, timeout time.Duration, validateOnly bool) (*proto.CreateTopicsResp, error) {
b.mu.Lock()
defer b.mu.Unlock()
var resp *proto.CreateTopicsResp
err := b.callOnClusterController(func(c *connection) error {
var err error
req := proto.CreateTopicsReq{
Timeout... | go | func (b *Broker) CreateTopic(topics []proto.TopicInfo, timeout time.Duration, validateOnly bool) (*proto.CreateTopicsResp, error) {
b.mu.Lock()
defer b.mu.Unlock()
var resp *proto.CreateTopicsResp
err := b.callOnClusterController(func(c *connection) error {
var err error
req := proto.CreateTopicsReq{
Timeout... | [
"func",
"(",
"b",
"*",
"Broker",
")",
"CreateTopic",
"(",
"topics",
"[",
"]",
"proto",
".",
"TopicInfo",
",",
"timeout",
"time",
".",
"Duration",
",",
"validateOnly",
"bool",
")",
"(",
"*",
"proto",
".",
"CreateTopicsResp",
",",
"error",
")",
"{",
"b",... | // CreateTopic request topic creation | [
"CreateTopic",
"request",
"topic",
"creation"
] | 6c126522640ec5e8e232d0e219160b30a92814f8 | https://github.com/optiopay/kafka/blob/6c126522640ec5e8e232d0e219160b30a92814f8/broker.go#L280-L295 |
133,292 | optiopay/kafka | broker.go | refreshMetadata | func (b *Broker) refreshMetadata() error {
meta, err := b.fetchMetadata()
if err == nil {
b.cacheMetadata(meta)
}
return err
} | go | func (b *Broker) refreshMetadata() error {
meta, err := b.fetchMetadata()
if err == nil {
b.cacheMetadata(meta)
}
return err
} | [
"func",
"(",
"b",
"*",
"Broker",
")",
"refreshMetadata",
"(",
")",
"error",
"{",
"meta",
",",
"err",
":=",
"b",
".",
"fetchMetadata",
"(",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"b",
".",
"cacheMetadata",
"(",
"meta",
")",
"\n",
"}",
"\n",
"re... | // refreshMetadata is requesting metadata information from any node and refresh
// internal cached representation.
// Because it's changing internal state, this method requires lock protection,
// but it does not acquire nor release lock itself. | [
"refreshMetadata",
"is",
"requesting",
"metadata",
"information",
"from",
"any",
"node",
"and",
"refresh",
"internal",
"cached",
"representation",
".",
"Because",
"it",
"s",
"changing",
"internal",
"state",
"this",
"method",
"requires",
"lock",
"protection",
"but",
... | 6c126522640ec5e8e232d0e219160b30a92814f8 | https://github.com/optiopay/kafka/blob/6c126522640ec5e8e232d0e219160b30a92814f8/broker.go#L301-L307 |
133,293 | optiopay/kafka | broker.go | muRefreshMetadata | func (b *Broker) muRefreshMetadata() error {
b.mu.Lock()
err := b.refreshMetadata()
b.mu.Unlock()
return err
} | go | func (b *Broker) muRefreshMetadata() error {
b.mu.Lock()
err := b.refreshMetadata()
b.mu.Unlock()
return err
} | [
"func",
"(",
"b",
"*",
"Broker",
")",
"muRefreshMetadata",
"(",
")",
"error",
"{",
"b",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"err",
":=",
"b",
".",
"refreshMetadata",
"(",
")",
"\n",
"b",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"return",
"... | // muRefreshMetadata calls refreshMetadata, but protects it with broker's lock. | [
"muRefreshMetadata",
"calls",
"refreshMetadata",
"but",
"protects",
"it",
"with",
"broker",
"s",
"lock",
"."
] | 6c126522640ec5e8e232d0e219160b30a92814f8 | https://github.com/optiopay/kafka/blob/6c126522640ec5e8e232d0e219160b30a92814f8/broker.go#L310-L315 |
133,294 | optiopay/kafka | broker.go | cacheMetadata | func (b *Broker) cacheMetadata(resp *proto.MetadataResp) {
if !b.metadata.created.IsZero() {
b.conf.Logger.Debug("rewriting old metadata",
"age", time.Now().Sub(b.metadata.created))
}
b.metadata = clusterMetadata{
created: time.Now(),
nodes: make(map[int32]string),
endpoints: make(map[topicPartit... | go | func (b *Broker) cacheMetadata(resp *proto.MetadataResp) {
if !b.metadata.created.IsZero() {
b.conf.Logger.Debug("rewriting old metadata",
"age", time.Now().Sub(b.metadata.created))
}
b.metadata = clusterMetadata{
created: time.Now(),
nodes: make(map[int32]string),
endpoints: make(map[topicPartit... | [
"func",
"(",
"b",
"*",
"Broker",
")",
"cacheMetadata",
"(",
"resp",
"*",
"proto",
".",
"MetadataResp",
")",
"{",
"if",
"!",
"b",
".",
"metadata",
".",
"created",
".",
"IsZero",
"(",
")",
"{",
"b",
".",
"conf",
".",
"Logger",
".",
"Debug",
"(",
"\... | // cacheMetadata creates new internal metadata representation using data from
// given response. It's call has to be protected with lock.
//
// Do not call with partial metadata response, this assumes we have the full
// set of metadata in the response | [
"cacheMetadata",
"creates",
"new",
"internal",
"metadata",
"representation",
"using",
"data",
"from",
"given",
"response",
".",
"It",
"s",
"call",
"has",
"to",
"be",
"protected",
"with",
"lock",
".",
"Do",
"not",
"call",
"with",
"partial",
"metadata",
"respons... | 6c126522640ec5e8e232d0e219160b30a92814f8 | https://github.com/optiopay/kafka/blob/6c126522640ec5e8e232d0e219160b30a92814f8/broker.go#L499-L523 |
133,295 | optiopay/kafka | broker.go | PartitionCount | func (b *Broker) PartitionCount(topic string) (int32, error) {
b.mu.Lock()
defer b.mu.Unlock()
count, ok := b.metadata.partitions[topic]
if ok {
return count, nil
}
return 0, fmt.Errorf("topic %s not found in metadata", topic)
} | go | func (b *Broker) PartitionCount(topic string) (int32, error) {
b.mu.Lock()
defer b.mu.Unlock()
count, ok := b.metadata.partitions[topic]
if ok {
return count, nil
}
return 0, fmt.Errorf("topic %s not found in metadata", topic)
} | [
"func",
"(",
"b",
"*",
"Broker",
")",
"PartitionCount",
"(",
"topic",
"string",
")",
"(",
"int32",
",",
"error",
")",
"{",
"b",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"b",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"count",
",",
"ok"... | // PartitionCount returns how many partitions a given topic has. If a topic
// is not known, 0 and an error are returned. | [
"PartitionCount",
"returns",
"how",
"many",
"partitions",
"a",
"given",
"topic",
"has",
".",
"If",
"a",
"topic",
"is",
"not",
"known",
"0",
"and",
"an",
"error",
"are",
"returned",
"."
] | 6c126522640ec5e8e232d0e219160b30a92814f8 | https://github.com/optiopay/kafka/blob/6c126522640ec5e8e232d0e219160b30a92814f8/broker.go#L527-L537 |
133,296 | optiopay/kafka | broker.go | muCloseDeadConnection | func (b *Broker) muCloseDeadConnection(conn *connection) {
b.mu.Lock()
defer b.mu.Unlock()
for nid, c := range b.conns {
if c == conn {
b.conf.Logger.Debug("closing dead connection",
"nodeID", nid)
delete(b.conns, nid)
_ = c.Close()
if err := b.refreshMetadata(); err != nil {
b.conf.Logger.Deb... | go | func (b *Broker) muCloseDeadConnection(conn *connection) {
b.mu.Lock()
defer b.mu.Unlock()
for nid, c := range b.conns {
if c == conn {
b.conf.Logger.Debug("closing dead connection",
"nodeID", nid)
delete(b.conns, nid)
_ = c.Close()
if err := b.refreshMetadata(); err != nil {
b.conf.Logger.Deb... | [
"func",
"(",
"b",
"*",
"Broker",
")",
"muCloseDeadConnection",
"(",
"conn",
"*",
"connection",
")",
"{",
"b",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"b",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"for",
"nid",
",",
"c",
":=",
"range",... | // muCloseDeadConnection is closing and removing any reference to given
// connection. Because we remove dead connection, additional request to refresh
// metadata is made
//
// muCloseDeadConnection call it protected with broker's lock. | [
"muCloseDeadConnection",
"is",
"closing",
"and",
"removing",
"any",
"reference",
"to",
"given",
"connection",
".",
"Because",
"we",
"remove",
"dead",
"connection",
"additional",
"request",
"to",
"refresh",
"metadata",
"is",
"made",
"muCloseDeadConnection",
"call",
"... | 6c126522640ec5e8e232d0e219160b30a92814f8 | https://github.com/optiopay/kafka/blob/6c126522640ec5e8e232d0e219160b30a92814f8/broker.go#L754-L771 |
133,297 | optiopay/kafka | broker.go | offset | func (b *Broker) offset(topic string, partition int32, timems int64) (offset int64, err error) {
for retry := 0; retry < b.conf.RetryErrLimit; retry++ {
if retry != 0 {
time.Sleep(b.conf.RetryErrWait)
err = b.muRefreshMetadata()
if err != nil {
continue
}
}
var conn *connection
conn, err = b.mu... | go | func (b *Broker) offset(topic string, partition int32, timems int64) (offset int64, err error) {
for retry := 0; retry < b.conf.RetryErrLimit; retry++ {
if retry != 0 {
time.Sleep(b.conf.RetryErrWait)
err = b.muRefreshMetadata()
if err != nil {
continue
}
}
var conn *connection
conn, err = b.mu... | [
"func",
"(",
"b",
"*",
"Broker",
")",
"offset",
"(",
"topic",
"string",
",",
"partition",
"int32",
",",
"timems",
"int64",
")",
"(",
"offset",
"int64",
",",
"err",
"error",
")",
"{",
"for",
"retry",
":=",
"0",
";",
"retry",
"<",
"b",
".",
"conf",
... | // offset will return offset value for given partition. Use timems to specify
// which offset value should be returned. | [
"offset",
"will",
"return",
"offset",
"value",
"for",
"given",
"partition",
".",
"Use",
"timems",
"to",
"specify",
"which",
"offset",
"value",
"should",
"be",
"returned",
"."
] | 6c126522640ec5e8e232d0e219160b30a92814f8 | https://github.com/optiopay/kafka/blob/6c126522640ec5e8e232d0e219160b30a92814f8/broker.go#L775-L845 |
133,298 | optiopay/kafka | broker.go | OffsetEarliest | func (b *Broker) OffsetEarliest(topic string, partition int32) (offset int64, err error) {
return b.offset(topic, partition, -2)
} | go | func (b *Broker) OffsetEarliest(topic string, partition int32) (offset int64, err error) {
return b.offset(topic, partition, -2)
} | [
"func",
"(",
"b",
"*",
"Broker",
")",
"OffsetEarliest",
"(",
"topic",
"string",
",",
"partition",
"int32",
")",
"(",
"offset",
"int64",
",",
"err",
"error",
")",
"{",
"return",
"b",
".",
"offset",
"(",
"topic",
",",
"partition",
",",
"-",
"2",
")",
... | // OffsetEarliest returns the oldest offset available on the given partition. | [
"OffsetEarliest",
"returns",
"the",
"oldest",
"offset",
"available",
"on",
"the",
"given",
"partition",
"."
] | 6c126522640ec5e8e232d0e219160b30a92814f8 | https://github.com/optiopay/kafka/blob/6c126522640ec5e8e232d0e219160b30a92814f8/broker.go#L848-L850 |
133,299 | optiopay/kafka | broker.go | NewProducerConf | func NewProducerConf() ProducerConf {
return ProducerConf{
Compression: proto.CompressionNone,
RequiredAcks: proto.RequiredAcksAll,
RequestTimeout: 5 * time.Second,
RetryLimit: 10,
RetryWait: 200 * time.Millisecond,
Logger: nil,
}
} | go | func NewProducerConf() ProducerConf {
return ProducerConf{
Compression: proto.CompressionNone,
RequiredAcks: proto.RequiredAcksAll,
RequestTimeout: 5 * time.Second,
RetryLimit: 10,
RetryWait: 200 * time.Millisecond,
Logger: nil,
}
} | [
"func",
"NewProducerConf",
"(",
")",
"ProducerConf",
"{",
"return",
"ProducerConf",
"{",
"Compression",
":",
"proto",
".",
"CompressionNone",
",",
"RequiredAcks",
":",
"proto",
".",
"RequiredAcksAll",
",",
"RequestTimeout",
":",
"5",
"*",
"time",
".",
"Second",
... | // NewProducerConf returns a default producer configuration. | [
"NewProducerConf",
"returns",
"a",
"default",
"producer",
"configuration",
"."
] | 6c126522640ec5e8e232d0e219160b30a92814f8 | https://github.com/optiopay/kafka/blob/6c126522640ec5e8e232d0e219160b30a92814f8/broker.go#L886-L895 |
Subsets and Splits
SQL Console for google/code_x_glue_ct_code_to_text
This query implements a thoughtful three-tier curation strategy to build a balanced safety dataset, categorizing code by destructive operations, safe I/O operations, and pure computational negatives with subsampling—revealing important patterns about how destructive intent manifests in Python code for model safety research.
SQL Console for google/code_x_glue_ct_code_to_text
This query performs meaningful classification of Python code samples into safety-relevant tiers based on destructive operations, I/O patterns, and pure computation, which could be valuable for building safety classifiers or curating training data, though the output itself is a filtered/ranked dataset rather than revealing novel statistical insights.