repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1 value | code stringlengths 52 85.5k | code_tokens list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 | partition stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|
paulmach/orb | clip/helpers.go | Ring | func Ring(b orb.Bound, r orb.Ring) orb.Ring {
result := ring(b, r)
if len(result) == 0 {
return nil
}
return result
} | go | func Ring(b orb.Bound, r orb.Ring) orb.Ring {
result := ring(b, r)
if len(result) == 0 {
return nil
}
return result
} | [
"func",
"Ring",
"(",
"b",
"orb",
".",
"Bound",
",",
"r",
"orb",
".",
"Ring",
")",
"orb",
".",
"Ring",
"{",
"result",
":=",
"ring",
"(",
"b",
",",
"r",
")",
"\n",
"if",
"len",
"(",
"result",
")",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"... | // Ring clips the ring to the bounding box and returns another ring.
// This operation will modify the input by using as a scratch space
// so clone if necessary. | [
"Ring",
"clips",
"the",
"ring",
"to",
"the",
"bounding",
"box",
"and",
"returns",
"another",
"ring",
".",
"This",
"operation",
"will",
"modify",
"the",
"input",
"by",
"using",
"as",
"a",
"scratch",
"space",
"so",
"clone",
"if",
"necessary",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/clip/helpers.go#L165-L172 | train |
paulmach/orb | clip/helpers.go | Polygon | func Polygon(b orb.Bound, p orb.Polygon) orb.Polygon {
if len(p) == 0 {
return nil
}
r := Ring(b, p[0])
if r == nil {
return nil
}
result := orb.Polygon{r}
for i := 1; i < len(p); i++ {
r := Ring(b, p[i])
if r != nil {
result = append(result, r)
}
}
return result
} | go | func Polygon(b orb.Bound, p orb.Polygon) orb.Polygon {
if len(p) == 0 {
return nil
}
r := Ring(b, p[0])
if r == nil {
return nil
}
result := orb.Polygon{r}
for i := 1; i < len(p); i++ {
r := Ring(b, p[i])
if r != nil {
result = append(result, r)
}
}
return result
} | [
"func",
"Polygon",
"(",
"b",
"orb",
".",
"Bound",
",",
"p",
"orb",
".",
"Polygon",
")",
"orb",
".",
"Polygon",
"{",
"if",
"len",
"(",
"p",
")",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"r",
":=",
"Ring",
"(",
"b",
",",
"p",
"[",
... | // Polygon clips the polygon to the bounding box excluding the inner rings
// if they do not intersect the bounding box.
// This operation will modify the input by using as a scratch space
// so clone if necessary. | [
"Polygon",
"clips",
"the",
"polygon",
"to",
"the",
"bounding",
"box",
"excluding",
"the",
"inner",
"rings",
"if",
"they",
"do",
"not",
"intersect",
"the",
"bounding",
"box",
".",
"This",
"operation",
"will",
"modify",
"the",
"input",
"by",
"using",
"as",
"... | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/clip/helpers.go#L178-L197 | train |
paulmach/orb | clip/helpers.go | MultiPolygon | func MultiPolygon(b orb.Bound, mp orb.MultiPolygon) orb.MultiPolygon {
var result orb.MultiPolygon
for _, polygon := range mp {
p := Polygon(b, polygon)
if p != nil {
result = append(result, p)
}
}
return result
} | go | func MultiPolygon(b orb.Bound, mp orb.MultiPolygon) orb.MultiPolygon {
var result orb.MultiPolygon
for _, polygon := range mp {
p := Polygon(b, polygon)
if p != nil {
result = append(result, p)
}
}
return result
} | [
"func",
"MultiPolygon",
"(",
"b",
"orb",
".",
"Bound",
",",
"mp",
"orb",
".",
"MultiPolygon",
")",
"orb",
".",
"MultiPolygon",
"{",
"var",
"result",
"orb",
".",
"MultiPolygon",
"\n",
"for",
"_",
",",
"polygon",
":=",
"range",
"mp",
"{",
"p",
":=",
"P... | // MultiPolygon clips the multi polygon to the bounding box excluding
// any polygons if they don't intersect the bounding box.
// This operation will modify the input by using as a scratch space
// so clone if necessary. | [
"MultiPolygon",
"clips",
"the",
"multi",
"polygon",
"to",
"the",
"bounding",
"box",
"excluding",
"any",
"polygons",
"if",
"they",
"don",
"t",
"intersect",
"the",
"bounding",
"box",
".",
"This",
"operation",
"will",
"modify",
"the",
"input",
"by",
"using",
"a... | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/clip/helpers.go#L203-L213 | train |
paulmach/orb | clip/helpers.go | Collection | func Collection(b orb.Bound, c orb.Collection) orb.Collection {
var result orb.Collection
for _, g := range c {
clipped := Geometry(b, g)
if clipped != nil {
result = append(result, clipped)
}
}
return result
} | go | func Collection(b orb.Bound, c orb.Collection) orb.Collection {
var result orb.Collection
for _, g := range c {
clipped := Geometry(b, g)
if clipped != nil {
result = append(result, clipped)
}
}
return result
} | [
"func",
"Collection",
"(",
"b",
"orb",
".",
"Bound",
",",
"c",
"orb",
".",
"Collection",
")",
"orb",
".",
"Collection",
"{",
"var",
"result",
"orb",
".",
"Collection",
"\n",
"for",
"_",
",",
"g",
":=",
"range",
"c",
"{",
"clipped",
":=",
"Geometry",
... | // Collection clips each element in the collection to the bounding box.
// It will exclude elements if they don't intersect the bounding box.
// This operation will modify the input of '2d geometry' by using as a
// scratch space so clone if necessary. | [
"Collection",
"clips",
"each",
"element",
"in",
"the",
"collection",
"to",
"the",
"bounding",
"box",
".",
"It",
"will",
"exclude",
"elements",
"if",
"they",
"don",
"t",
"intersect",
"the",
"bounding",
"box",
".",
"This",
"operation",
"will",
"modify",
"the",... | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/clip/helpers.go#L219-L229 | train |
paulmach/orb | maptile/tilecover/polygon.go | Ring | func Ring(r orb.Ring, z maptile.Zoom) maptile.Set {
if len(r) == 0 {
return make(maptile.Set)
}
return Polygon(orb.Polygon{r}, z)
} | go | func Ring(r orb.Ring, z maptile.Zoom) maptile.Set {
if len(r) == 0 {
return make(maptile.Set)
}
return Polygon(orb.Polygon{r}, z)
} | [
"func",
"Ring",
"(",
"r",
"orb",
".",
"Ring",
",",
"z",
"maptile",
".",
"Zoom",
")",
"maptile",
".",
"Set",
"{",
"if",
"len",
"(",
"r",
")",
"==",
"0",
"{",
"return",
"make",
"(",
"maptile",
".",
"Set",
")",
"\n",
"}",
"\n\n",
"return",
"Polygo... | // Ring creates a tile cover for the ring. | [
"Ring",
"creates",
"a",
"tile",
"cover",
"for",
"the",
"ring",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/maptile/tilecover/polygon.go#L11-L17 | train |
paulmach/orb | maptile/tilecover/polygon.go | Polygon | func Polygon(p orb.Polygon, z maptile.Zoom) maptile.Set {
set := make(maptile.Set)
polygon(set, p, z)
return set
} | go | func Polygon(p orb.Polygon, z maptile.Zoom) maptile.Set {
set := make(maptile.Set)
polygon(set, p, z)
return set
} | [
"func",
"Polygon",
"(",
"p",
"orb",
".",
"Polygon",
",",
"z",
"maptile",
".",
"Zoom",
")",
"maptile",
".",
"Set",
"{",
"set",
":=",
"make",
"(",
"maptile",
".",
"Set",
")",
"\n",
"polygon",
"(",
"set",
",",
"p",
",",
"z",
")",
"\n\n",
"return",
... | // Polygon creates a tile cover for the polygon. | [
"Polygon",
"creates",
"a",
"tile",
"cover",
"for",
"the",
"polygon",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/maptile/tilecover/polygon.go#L20-L25 | train |
paulmach/orb | maptile/tilecover/polygon.go | MultiPolygon | func MultiPolygon(mp orb.MultiPolygon, z maptile.Zoom) maptile.Set {
set := make(maptile.Set)
for _, p := range mp {
polygon(set, p, z)
}
return set
} | go | func MultiPolygon(mp orb.MultiPolygon, z maptile.Zoom) maptile.Set {
set := make(maptile.Set)
for _, p := range mp {
polygon(set, p, z)
}
return set
} | [
"func",
"MultiPolygon",
"(",
"mp",
"orb",
".",
"MultiPolygon",
",",
"z",
"maptile",
".",
"Zoom",
")",
"maptile",
".",
"Set",
"{",
"set",
":=",
"make",
"(",
"maptile",
".",
"Set",
")",
"\n",
"for",
"_",
",",
"p",
":=",
"range",
"mp",
"{",
"polygon",... | // MultiPolygon creates a tile cover for the multi-polygon. | [
"MultiPolygon",
"creates",
"a",
"tile",
"cover",
"for",
"the",
"multi",
"-",
"polygon",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/maptile/tilecover/polygon.go#L28-L35 | train |
paulmach/orb | geometry.go | Bound | func (c Collection) Bound() Bound {
if len(c) == 0 {
return emptyBound
}
var b Bound
start := -1
for i, g := range c {
if g != nil {
start = i
b = g.Bound()
break
}
}
if start == -1 {
return emptyBound
}
for i := start + 1; i < len(c); i++ {
if c[i] == nil {
continue
}
b = b.Union(c[i].Bound())
}
return b
} | go | func (c Collection) Bound() Bound {
if len(c) == 0 {
return emptyBound
}
var b Bound
start := -1
for i, g := range c {
if g != nil {
start = i
b = g.Bound()
break
}
}
if start == -1 {
return emptyBound
}
for i := start + 1; i < len(c); i++ {
if c[i] == nil {
continue
}
b = b.Union(c[i].Bound())
}
return b
} | [
"func",
"(",
"c",
"Collection",
")",
"Bound",
"(",
")",
"Bound",
"{",
"if",
"len",
"(",
"c",
")",
"==",
"0",
"{",
"return",
"emptyBound",
"\n",
"}",
"\n\n",
"var",
"b",
"Bound",
"\n",
"start",
":=",
"-",
"1",
"\n\n",
"for",
"i",
",",
"g",
":=",... | // Bound returns the bounding box of all the Geometries combined. | [
"Bound",
"returns",
"the",
"bounding",
"box",
"of",
"all",
"the",
"Geometries",
"combined",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/geometry.go#L87-L116 | train |
paulmach/orb | geometry.go | Equal | func (c Collection) Equal(collection Collection) bool {
if len(c) != len(collection) {
return false
}
for i, g := range c {
if !Equal(g, collection[i]) {
return false
}
}
return true
} | go | func (c Collection) Equal(collection Collection) bool {
if len(c) != len(collection) {
return false
}
for i, g := range c {
if !Equal(g, collection[i]) {
return false
}
}
return true
} | [
"func",
"(",
"c",
"Collection",
")",
"Equal",
"(",
"collection",
"Collection",
")",
"bool",
"{",
"if",
"len",
"(",
"c",
")",
"!=",
"len",
"(",
"collection",
")",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"for",
"i",
",",
"g",
":=",
"range",
"c",
... | // Equal compares two collections. Returns true if lengths are the same
// and all the sub geometries are the same and in the same order. | [
"Equal",
"compares",
"two",
"collections",
".",
"Returns",
"true",
"if",
"lengths",
"are",
"the",
"same",
"and",
"all",
"the",
"sub",
"geometries",
"are",
"the",
"same",
"and",
"in",
"the",
"same",
"order",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/geometry.go#L120-L132 | train |
paulmach/orb | geometry.go | Clone | func (c Collection) Clone() Collection {
if c == nil {
return nil
}
nc := make(Collection, len(c))
for i, g := range c {
nc[i] = Clone(g)
}
return nc
} | go | func (c Collection) Clone() Collection {
if c == nil {
return nil
}
nc := make(Collection, len(c))
for i, g := range c {
nc[i] = Clone(g)
}
return nc
} | [
"func",
"(",
"c",
"Collection",
")",
"Clone",
"(",
")",
"Collection",
"{",
"if",
"c",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"nc",
":=",
"make",
"(",
"Collection",
",",
"len",
"(",
"c",
")",
")",
"\n",
"for",
"i",
",",
"g",
":=",... | // Clone returns a deep copy of the collection. | [
"Clone",
"returns",
"a",
"deep",
"copy",
"of",
"the",
"collection",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/geometry.go#L135-L146 | train |
paulmach/orb | simplify/radial.go | Radial | func Radial(df orb.DistanceFunc, threshold float64) *RadialSimplifier {
return &RadialSimplifier{
DistanceFunc: df,
Threshold: threshold,
}
} | go | func Radial(df orb.DistanceFunc, threshold float64) *RadialSimplifier {
return &RadialSimplifier{
DistanceFunc: df,
Threshold: threshold,
}
} | [
"func",
"Radial",
"(",
"df",
"orb",
".",
"DistanceFunc",
",",
"threshold",
"float64",
")",
"*",
"RadialSimplifier",
"{",
"return",
"&",
"RadialSimplifier",
"{",
"DistanceFunc",
":",
"df",
",",
"Threshold",
":",
"threshold",
",",
"}",
"\n",
"}"
] | // Radial creates a new RadialSimplifier. | [
"Radial",
"creates",
"a",
"new",
"RadialSimplifier",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/simplify/radial.go#L16-L21 | train |
paulmach/orb | clip/smartclip/smart.go | Geometry | func Geometry(box orb.Bound, g orb.Geometry, o orb.Orientation) orb.Geometry {
if g == nil {
return nil
}
if g.Dimensions() != 2 {
return clip.Geometry(box, g)
}
var mp orb.MultiPolygon
switch g := g.(type) {
case orb.Ring:
mp = Ring(box, g, o)
case orb.Polygon:
mp = Polygon(box, g, o)
case orb.MultiPolygon:
mp = MultiPolygon(box, g, o)
case orb.Bound:
return clip.Geometry(box, g)
case orb.Collection:
var result orb.Collection
for _, c := range g {
c := Geometry(box, c, o)
if c != nil {
result = append(result, c)
}
}
if len(result) == 1 {
return result[0]
}
return result
default:
panic(fmt.Sprintf("geometry type not supported: %T", g))
}
if mp == nil {
return nil
}
if len(mp) == 1 {
return mp[0]
}
return mp
} | go | func Geometry(box orb.Bound, g orb.Geometry, o orb.Orientation) orb.Geometry {
if g == nil {
return nil
}
if g.Dimensions() != 2 {
return clip.Geometry(box, g)
}
var mp orb.MultiPolygon
switch g := g.(type) {
case orb.Ring:
mp = Ring(box, g, o)
case orb.Polygon:
mp = Polygon(box, g, o)
case orb.MultiPolygon:
mp = MultiPolygon(box, g, o)
case orb.Bound:
return clip.Geometry(box, g)
case orb.Collection:
var result orb.Collection
for _, c := range g {
c := Geometry(box, c, o)
if c != nil {
result = append(result, c)
}
}
if len(result) == 1 {
return result[0]
}
return result
default:
panic(fmt.Sprintf("geometry type not supported: %T", g))
}
if mp == nil {
return nil
}
if len(mp) == 1 {
return mp[0]
}
return mp
} | [
"func",
"Geometry",
"(",
"box",
"orb",
".",
"Bound",
",",
"g",
"orb",
".",
"Geometry",
",",
"o",
"orb",
".",
"Orientation",
")",
"orb",
".",
"Geometry",
"{",
"if",
"g",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"if",
"g",
".",
"Dimens... | // Geometry will do a smart more involved clipping and wrapping of the geometry.
// It will return simple OGC geometries. Rings that are NOT closed AND have an
// endpoint in the bound will be implicitly closed. | [
"Geometry",
"will",
"do",
"a",
"smart",
"more",
"involved",
"clipping",
"and",
"wrapping",
"of",
"the",
"geometry",
".",
"It",
"will",
"return",
"simple",
"OGC",
"geometries",
".",
"Rings",
"that",
"are",
"NOT",
"closed",
"AND",
"have",
"an",
"endpoint",
"... | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/clip/smartclip/smart.go#L16-L62 | train |
paulmach/orb | clip/smartclip/smart.go | Ring | func Ring(box orb.Bound, r orb.Ring, o orb.Orientation) orb.MultiPolygon {
if len(r) == 0 {
return nil
}
open, closed := clipRings(box, []orb.Ring{r})
if len(open) == 0 {
// nothing was clipped
if len(closed) == 0 {
return nil // everything outside bound
}
return orb.MultiPolygon{{r}} // everything inside bound
}
// in a well defined ring there will be no closed sections
return smartWrap(box, open, o)
} | go | func Ring(box orb.Bound, r orb.Ring, o orb.Orientation) orb.MultiPolygon {
if len(r) == 0 {
return nil
}
open, closed := clipRings(box, []orb.Ring{r})
if len(open) == 0 {
// nothing was clipped
if len(closed) == 0 {
return nil // everything outside bound
}
return orb.MultiPolygon{{r}} // everything inside bound
}
// in a well defined ring there will be no closed sections
return smartWrap(box, open, o)
} | [
"func",
"Ring",
"(",
"box",
"orb",
".",
"Bound",
",",
"r",
"orb",
".",
"Ring",
",",
"o",
"orb",
".",
"Orientation",
")",
"orb",
".",
"MultiPolygon",
"{",
"if",
"len",
"(",
"r",
")",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"open",
",... | // Ring will smart clip a ring to the boundary. This may result multiple rings so
// a multipolygon is possible. Rings that are NOT closed AND have an endpoint in
// the bound will be implicitly closed. | [
"Ring",
"will",
"smart",
"clip",
"a",
"ring",
"to",
"the",
"boundary",
".",
"This",
"may",
"result",
"multiple",
"rings",
"so",
"a",
"multipolygon",
"is",
"possible",
".",
"Rings",
"that",
"are",
"NOT",
"closed",
"AND",
"have",
"an",
"endpoint",
"in",
"t... | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/clip/smartclip/smart.go#L67-L84 | train |
paulmach/orb | clip/smartclip/smart.go | Polygon | func Polygon(box orb.Bound, p orb.Polygon, o orb.Orientation) orb.MultiPolygon {
if len(p) == 0 {
return nil
}
open, closed := clipRings(box, p)
if len(open) == 0 {
// nothing was clipped
if len(closed) == 0 {
return nil // everything outside bound
}
return orb.MultiPolygon{p} // everything inside bound
}
result := smartWrap(box, open, o)
if len(result) == 1 {
result[0] = append(result[0], closed...)
} else {
for _, i := range closed {
result = addToMultiPolygon(result, i)
}
}
return result
} | go | func Polygon(box orb.Bound, p orb.Polygon, o orb.Orientation) orb.MultiPolygon {
if len(p) == 0 {
return nil
}
open, closed := clipRings(box, p)
if len(open) == 0 {
// nothing was clipped
if len(closed) == 0 {
return nil // everything outside bound
}
return orb.MultiPolygon{p} // everything inside bound
}
result := smartWrap(box, open, o)
if len(result) == 1 {
result[0] = append(result[0], closed...)
} else {
for _, i := range closed {
result = addToMultiPolygon(result, i)
}
}
return result
} | [
"func",
"Polygon",
"(",
"box",
"orb",
".",
"Bound",
",",
"p",
"orb",
".",
"Polygon",
",",
"o",
"orb",
".",
"Orientation",
")",
"orb",
".",
"MultiPolygon",
"{",
"if",
"len",
"(",
"p",
")",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"open"... | // Polygon will smart clip a polygon to the bound.
// Rings that are NOT closed AND have an endpoint in the bound will be
// implicitly closed. | [
"Polygon",
"will",
"smart",
"clip",
"a",
"polygon",
"to",
"the",
"bound",
".",
"Rings",
"that",
"are",
"NOT",
"closed",
"AND",
"have",
"an",
"endpoint",
"in",
"the",
"bound",
"will",
"be",
"implicitly",
"closed",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/clip/smartclip/smart.go#L89-L114 | train |
paulmach/orb | clip/smartclip/smart.go | MultiPolygon | func MultiPolygon(box orb.Bound, mp orb.MultiPolygon, o orb.Orientation) orb.MultiPolygon {
if len(mp) == 0 {
return nil
}
// outer rings
outerRings := make([]orb.Ring, 0, len(mp))
for _, p := range mp {
outerRings = append(outerRings, p[0])
}
outers, closedOuters := clipRings(box, outerRings)
if len(outers) == 0 {
// nothing was clipped
if len(closedOuters) == 0 {
return nil // everything outside bound
}
return mp // everything inside bound
}
// inner rings
var innerRings []orb.Ring
for _, p := range mp {
for _, r := range p[1:] {
innerRings = append(innerRings, r)
}
}
inners, closedInners := clipRings(box, innerRings)
// smart wrap everything that touches the edges
result := smartWrap(box, append(outers, inners...), o)
for _, o := range closedOuters {
result = append(result, orb.Polygon{o})
}
for _, i := range closedInners {
result = addToMultiPolygon(result, i)
}
return result
} | go | func MultiPolygon(box orb.Bound, mp orb.MultiPolygon, o orb.Orientation) orb.MultiPolygon {
if len(mp) == 0 {
return nil
}
// outer rings
outerRings := make([]orb.Ring, 0, len(mp))
for _, p := range mp {
outerRings = append(outerRings, p[0])
}
outers, closedOuters := clipRings(box, outerRings)
if len(outers) == 0 {
// nothing was clipped
if len(closedOuters) == 0 {
return nil // everything outside bound
}
return mp // everything inside bound
}
// inner rings
var innerRings []orb.Ring
for _, p := range mp {
for _, r := range p[1:] {
innerRings = append(innerRings, r)
}
}
inners, closedInners := clipRings(box, innerRings)
// smart wrap everything that touches the edges
result := smartWrap(box, append(outers, inners...), o)
for _, o := range closedOuters {
result = append(result, orb.Polygon{o})
}
for _, i := range closedInners {
result = addToMultiPolygon(result, i)
}
return result
} | [
"func",
"MultiPolygon",
"(",
"box",
"orb",
".",
"Bound",
",",
"mp",
"orb",
".",
"MultiPolygon",
",",
"o",
"orb",
".",
"Orientation",
")",
"orb",
".",
"MultiPolygon",
"{",
"if",
"len",
"(",
"mp",
")",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n\... | // MultiPolygon will smart clip a multipolygon to the bound.
// Rings that are NOT closed AND have an endpoint in the bound will be
// implicitly closed. | [
"MultiPolygon",
"will",
"smart",
"clip",
"a",
"multipolygon",
"to",
"the",
"bound",
".",
"Rings",
"that",
"are",
"NOT",
"closed",
"AND",
"have",
"an",
"endpoint",
"in",
"the",
"bound",
"will",
"be",
"implicitly",
"closed",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/clip/smartclip/smart.go#L119-L161 | train |
paulmach/orb | clip/smartclip/smart.go | clipRings | func clipRings(box orb.Bound, rings []orb.Ring) (open []orb.LineString, closed []orb.Ring) {
var result []orb.LineString
for _, r := range rings {
if !r.Closed() && (box.Contains(r[0]) || box.Contains(r[len(r)-1])) {
r = append(r, r[0])
}
out := clip.LineString(box, orb.LineString(r), clip.OpenBound(true))
if len(out) == 0 {
continue // outside of bound
}
if r.Closed() {
// if the input was a closed ring where the endpoints were within the bound,
// then join the sections.
// This operation is O(n^2), however, n is the number of segments, not edges
// so I think it's manageable.
for i := 0; i < len(out); i++ {
end := out[i][len(out[i])-1]
if end[0] == box.Min[0] || box.Max[0] == end[0] ||
end[1] == box.Min[1] || box.Max[1] == end[1] {
// endpoint must be within the bound to try join
continue
}
for j := 0; j < len(out); j++ {
if i == j {
continue
}
if out[j][0] == end {
out[i] = append(out[i], out[j][1:]...)
i--
out[j] = out[len(out)-1]
out = out[:len(out)-1]
}
}
}
}
result = append(result, out...)
}
at := 0
for _, ls := range result {
// closed ring, so completely inside bound
// unless it touches a boundary
if ls[0] == ls[len(ls)-1] && pointSide(box, ls[0]) == notOnSide {
closed = append(closed, orb.Ring(ls))
} else {
result[at] = ls
at++
}
}
return result[:at], closed
} | go | func clipRings(box orb.Bound, rings []orb.Ring) (open []orb.LineString, closed []orb.Ring) {
var result []orb.LineString
for _, r := range rings {
if !r.Closed() && (box.Contains(r[0]) || box.Contains(r[len(r)-1])) {
r = append(r, r[0])
}
out := clip.LineString(box, orb.LineString(r), clip.OpenBound(true))
if len(out) == 0 {
continue // outside of bound
}
if r.Closed() {
// if the input was a closed ring where the endpoints were within the bound,
// then join the sections.
// This operation is O(n^2), however, n is the number of segments, not edges
// so I think it's manageable.
for i := 0; i < len(out); i++ {
end := out[i][len(out[i])-1]
if end[0] == box.Min[0] || box.Max[0] == end[0] ||
end[1] == box.Min[1] || box.Max[1] == end[1] {
// endpoint must be within the bound to try join
continue
}
for j := 0; j < len(out); j++ {
if i == j {
continue
}
if out[j][0] == end {
out[i] = append(out[i], out[j][1:]...)
i--
out[j] = out[len(out)-1]
out = out[:len(out)-1]
}
}
}
}
result = append(result, out...)
}
at := 0
for _, ls := range result {
// closed ring, so completely inside bound
// unless it touches a boundary
if ls[0] == ls[len(ls)-1] && pointSide(box, ls[0]) == notOnSide {
closed = append(closed, orb.Ring(ls))
} else {
result[at] = ls
at++
}
}
return result[:at], closed
} | [
"func",
"clipRings",
"(",
"box",
"orb",
".",
"Bound",
",",
"rings",
"[",
"]",
"orb",
".",
"Ring",
")",
"(",
"open",
"[",
"]",
"orb",
".",
"LineString",
",",
"closed",
"[",
"]",
"orb",
".",
"Ring",
")",
"{",
"var",
"result",
"[",
"]",
"orb",
"."... | // clipRings will take a set of rings and clip them to the boundary.
// It returns the open lineStrings with endpoints on the boundary and
// the closed interior rings. | [
"clipRings",
"will",
"take",
"a",
"set",
"of",
"rings",
"and",
"clip",
"them",
"to",
"the",
"boundary",
".",
"It",
"returns",
"the",
"open",
"lineStrings",
"with",
"endpoints",
"on",
"the",
"boundary",
"and",
"the",
"closed",
"interior",
"rings",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/clip/smartclip/smart.go#L166-L223 | train |
paulmach/orb | clip/smartclip/smart.go | smartWrap | func smartWrap(box orb.Bound, input []orb.LineString, o orb.Orientation) orb.MultiPolygon {
points := make([]*endpoint, 0, 2*len(input)+2)
for i, r := range input {
// start
points = append(points, &endpoint{
Point: r[0],
Start: true,
Side: pointSide(box, r[0]),
Index: i,
OtherEnd: 2*i + 1,
})
// end
points = append(points, &endpoint{
Point: r[len(r)-1],
Start: false,
Side: pointSide(box, r[len(r)-1]),
Index: i,
OtherEnd: 2 * i,
})
}
if o == orb.CCW {
sort.Sort(&sortableEndpoints{
mls: input,
eps: points,
})
} else {
sort.Sort(sort.Reverse(&sortableEndpoints{
mls: input,
eps: points,
}))
}
var (
result orb.MultiPolygon
current orb.Ring
)
// this operation is O(n^2). Technically we could use a linked list
// and remove points instead of marking them as "used".
// However since n is 2x the number of segements I think we're okay.
for i := 0; i < 2*len(points); i++ {
ep := points[i%len(points)]
if ep.Used {
continue
}
if !ep.Start {
if len(current) == 0 {
current = orb.Ring(input[ep.Index])
ep.Used = true
}
continue
}
if len(current) == 0 {
continue
}
ep.Used = true
// previous was end, connect to this start
var r orb.Ring
if ep.Point == current[len(current)-1] {
r = emptyTwoRing
} else {
r = aroundBound(box, orb.Ring{ep.Point, current[len(current)-1]}, o)
}
if ep.Point.Equal(current[0]) {
// loop complete!!
current = append(current, r[2:]...)
result = append(result, orb.Polygon{current})
current = nil
i = -1 // start over looking for unused endpoints
} else {
if len(r) > 2 {
current = append(current, r[2:len(r)-1]...)
}
current = append(current, input[ep.Index]...)
points[ep.OtherEnd].Used = true
i = ep.OtherEnd
}
}
return result
} | go | func smartWrap(box orb.Bound, input []orb.LineString, o orb.Orientation) orb.MultiPolygon {
points := make([]*endpoint, 0, 2*len(input)+2)
for i, r := range input {
// start
points = append(points, &endpoint{
Point: r[0],
Start: true,
Side: pointSide(box, r[0]),
Index: i,
OtherEnd: 2*i + 1,
})
// end
points = append(points, &endpoint{
Point: r[len(r)-1],
Start: false,
Side: pointSide(box, r[len(r)-1]),
Index: i,
OtherEnd: 2 * i,
})
}
if o == orb.CCW {
sort.Sort(&sortableEndpoints{
mls: input,
eps: points,
})
} else {
sort.Sort(sort.Reverse(&sortableEndpoints{
mls: input,
eps: points,
}))
}
var (
result orb.MultiPolygon
current orb.Ring
)
// this operation is O(n^2). Technically we could use a linked list
// and remove points instead of marking them as "used".
// However since n is 2x the number of segements I think we're okay.
for i := 0; i < 2*len(points); i++ {
ep := points[i%len(points)]
if ep.Used {
continue
}
if !ep.Start {
if len(current) == 0 {
current = orb.Ring(input[ep.Index])
ep.Used = true
}
continue
}
if len(current) == 0 {
continue
}
ep.Used = true
// previous was end, connect to this start
var r orb.Ring
if ep.Point == current[len(current)-1] {
r = emptyTwoRing
} else {
r = aroundBound(box, orb.Ring{ep.Point, current[len(current)-1]}, o)
}
if ep.Point.Equal(current[0]) {
// loop complete!!
current = append(current, r[2:]...)
result = append(result, orb.Polygon{current})
current = nil
i = -1 // start over looking for unused endpoints
} else {
if len(r) > 2 {
current = append(current, r[2:len(r)-1]...)
}
current = append(current, input[ep.Index]...)
points[ep.OtherEnd].Used = true
i = ep.OtherEnd
}
}
return result
} | [
"func",
"smartWrap",
"(",
"box",
"orb",
".",
"Bound",
",",
"input",
"[",
"]",
"orb",
".",
"LineString",
",",
"o",
"orb",
".",
"Orientation",
")",
"orb",
".",
"MultiPolygon",
"{",
"points",
":=",
"make",
"(",
"[",
"]",
"*",
"endpoint",
",",
"0",
","... | // smartWrap takes the open lineStrings with endpoints on the boundary and
// connects them correctly. | [
"smartWrap",
"takes",
"the",
"open",
"lineStrings",
"with",
"endpoints",
"on",
"the",
"boundary",
"and",
"connects",
"them",
"correctly",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/clip/smartclip/smart.go#L248-L337 | train |
paulmach/orb | clip/smartclip/smart.go | pointSide | func pointSide(b orb.Bound, p orb.Point) uint8 {
if p[1] == b.Max[1] {
return 4
} else if p[1] == b.Min[1] {
return 2
} else if p[0] == b.Max[0] {
return 3
} else if p[0] == b.Min[0] {
return 1
}
return notOnSide
} | go | func pointSide(b orb.Bound, p orb.Point) uint8 {
if p[1] == b.Max[1] {
return 4
} else if p[1] == b.Min[1] {
return 2
} else if p[0] == b.Max[0] {
return 3
} else if p[0] == b.Min[0] {
return 1
}
return notOnSide
} | [
"func",
"pointSide",
"(",
"b",
"orb",
".",
"Bound",
",",
"p",
"orb",
".",
"Point",
")",
"uint8",
"{",
"if",
"p",
"[",
"1",
"]",
"==",
"b",
".",
"Max",
"[",
"1",
"]",
"{",
"return",
"4",
"\n",
"}",
"else",
"if",
"p",
"[",
"1",
"]",
"==",
"... | // 4
// +-+
// 1 | | 3
// +-+
// 2 | [
"4",
"+",
"-",
"+",
"1",
"|",
"|",
"3",
"+",
"-",
"+",
"2"
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/clip/smartclip/smart.go#L346-L358 | train |
paulmach/orb | clip/smartclip/smart.go | Less | func (e *sortableEndpoints) Less(i, j int) bool {
if e.eps[i].Side != e.eps[j].Side {
return e.eps[i].Side < e.eps[j].Side
}
switch e.eps[i].Side {
case 1:
if e.eps[i].Point[1] != e.eps[j].Point[1] {
return e.eps[i].Point[1] >= e.eps[j].Point[1]
}
return e.eps[i].Before(e.mls)[1] >= e.eps[j].Before(e.mls)[1]
case 2:
if e.eps[i].Point[0] != e.eps[j].Point[0] {
return e.eps[i].Point[0] < e.eps[j].Point[0]
}
return e.eps[i].Before(e.mls)[0] < e.eps[j].Before(e.mls)[0]
case 3:
if e.eps[i].Point[1] != e.eps[j].Point[1] {
return e.eps[i].Point[1] < e.eps[j].Point[1]
}
return e.eps[i].Before(e.mls)[1] < e.eps[j].Before(e.mls)[1]
case 4:
if e.eps[i].Point[0] != e.eps[j].Point[0] {
return e.eps[i].Point[0] >= e.eps[j].Point[0]
}
return e.eps[i].Before(e.mls)[0] >= e.eps[j].Before(e.mls)[0]
}
panic("unreachable")
} | go | func (e *sortableEndpoints) Less(i, j int) bool {
if e.eps[i].Side != e.eps[j].Side {
return e.eps[i].Side < e.eps[j].Side
}
switch e.eps[i].Side {
case 1:
if e.eps[i].Point[1] != e.eps[j].Point[1] {
return e.eps[i].Point[1] >= e.eps[j].Point[1]
}
return e.eps[i].Before(e.mls)[1] >= e.eps[j].Before(e.mls)[1]
case 2:
if e.eps[i].Point[0] != e.eps[j].Point[0] {
return e.eps[i].Point[0] < e.eps[j].Point[0]
}
return e.eps[i].Before(e.mls)[0] < e.eps[j].Before(e.mls)[0]
case 3:
if e.eps[i].Point[1] != e.eps[j].Point[1] {
return e.eps[i].Point[1] < e.eps[j].Point[1]
}
return e.eps[i].Before(e.mls)[1] < e.eps[j].Before(e.mls)[1]
case 4:
if e.eps[i].Point[0] != e.eps[j].Point[0] {
return e.eps[i].Point[0] >= e.eps[j].Point[0]
}
return e.eps[i].Before(e.mls)[0] >= e.eps[j].Before(e.mls)[0]
}
panic("unreachable")
} | [
"func",
"(",
"e",
"*",
"sortableEndpoints",
")",
"Less",
"(",
"i",
",",
"j",
"int",
")",
"bool",
"{",
"if",
"e",
".",
"eps",
"[",
"i",
"]",
".",
"Side",
"!=",
"e",
".",
"eps",
"[",
"j",
"]",
".",
"Side",
"{",
"return",
"e",
".",
"eps",
"[",... | // Less sorts the points around the bound.
// First comparing what side it's on and then the actual point to determine the order.
// If two points are the same, we sort by the edge attached to the point so lines that are
// "above" are shorted first. | [
"Less",
"sorts",
"the",
"points",
"around",
"the",
"bound",
".",
"First",
"comparing",
"what",
"side",
"it",
"s",
"on",
"and",
"then",
"the",
"actual",
"point",
"to",
"determine",
"the",
"order",
".",
"If",
"two",
"points",
"are",
"the",
"same",
"we",
... | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/clip/smartclip/smart.go#L373-L405 | train |
paulmach/orb | clip/smartclip/smart.go | addToMultiPolygon | func addToMultiPolygon(mp orb.MultiPolygon, ring orb.Ring) orb.MultiPolygon {
for i := range mp {
if polygonContains(mp[i][0], ring) {
mp[i] = append(mp[i], ring)
return mp
}
}
// ring is not in any polygons?
// skip it, TODO: is this correct?
// If input is well formed, I think it is. If it isn't, ¯\_(ツ)_/¯
return mp
} | go | func addToMultiPolygon(mp orb.MultiPolygon, ring orb.Ring) orb.MultiPolygon {
for i := range mp {
if polygonContains(mp[i][0], ring) {
mp[i] = append(mp[i], ring)
return mp
}
}
// ring is not in any polygons?
// skip it, TODO: is this correct?
// If input is well formed, I think it is. If it isn't, ¯\_(ツ)_/¯
return mp
} | [
"func",
"addToMultiPolygon",
"(",
"mp",
"orb",
".",
"MultiPolygon",
",",
"ring",
"orb",
".",
"Ring",
")",
"orb",
".",
"MultiPolygon",
"{",
"for",
"i",
":=",
"range",
"mp",
"{",
"if",
"polygonContains",
"(",
"mp",
"[",
"i",
"]",
"[",
"0",
"]",
",",
... | // addToMultiPolygon does a lookup to see which polygon the ring intersects.
// This should work fine if the input is well formed. | [
"addToMultiPolygon",
"does",
"a",
"lookup",
"to",
"see",
"which",
"polygon",
"the",
"ring",
"intersects",
".",
"This",
"should",
"work",
"fine",
"if",
"the",
"input",
"is",
"well",
"formed",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/clip/smartclip/smart.go#L414-L427 | train |
paulmach/orb | bound.go | ToRing | func (b Bound) ToRing() Ring {
return Ring{
b.Min,
Point{b.Max[0], b.Min[1]},
b.Max,
Point{b.Min[0], b.Max[1]},
b.Min,
}
} | go | func (b Bound) ToRing() Ring {
return Ring{
b.Min,
Point{b.Max[0], b.Min[1]},
b.Max,
Point{b.Min[0], b.Max[1]},
b.Min,
}
} | [
"func",
"(",
"b",
"Bound",
")",
"ToRing",
"(",
")",
"Ring",
"{",
"return",
"Ring",
"{",
"b",
".",
"Min",
",",
"Point",
"{",
"b",
".",
"Max",
"[",
"0",
"]",
",",
"b",
".",
"Min",
"[",
"1",
"]",
"}",
",",
"b",
".",
"Max",
",",
"Point",
"{",... | // ToRing converts the bound into a loop defined
// by the boundary of the box. | [
"ToRing",
"converts",
"the",
"bound",
"into",
"a",
"loop",
"defined",
"by",
"the",
"boundary",
"of",
"the",
"box",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/bound.go#L33-L41 | train |
paulmach/orb | bound.go | Union | func (b Bound) Union(other Bound) Bound {
if other.IsEmpty() {
return b
}
b = b.Extend(other.Min)
b = b.Extend(other.Max)
b = b.Extend(other.LeftTop())
b = b.Extend(other.RightBottom())
return b
} | go | func (b Bound) Union(other Bound) Bound {
if other.IsEmpty() {
return b
}
b = b.Extend(other.Min)
b = b.Extend(other.Max)
b = b.Extend(other.LeftTop())
b = b.Extend(other.RightBottom())
return b
} | [
"func",
"(",
"b",
"Bound",
")",
"Union",
"(",
"other",
"Bound",
")",
"Bound",
"{",
"if",
"other",
".",
"IsEmpty",
"(",
")",
"{",
"return",
"b",
"\n",
"}",
"\n\n",
"b",
"=",
"b",
".",
"Extend",
"(",
"other",
".",
"Min",
")",
"\n",
"b",
"=",
"b... | // Union extends this bound to contain the union of this and the given bound. | [
"Union",
"extends",
"this",
"bound",
"to",
"contain",
"the",
"union",
"of",
"this",
"and",
"the",
"given",
"bound",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/bound.go#L63-L74 | train |
paulmach/orb | bound.go | Pad | func (b Bound) Pad(d float64) Bound {
b.Min[0] -= d
b.Min[1] -= d
b.Max[0] += d
b.Max[1] += d
return b
} | go | func (b Bound) Pad(d float64) Bound {
b.Min[0] -= d
b.Min[1] -= d
b.Max[0] += d
b.Max[1] += d
return b
} | [
"func",
"(",
"b",
"Bound",
")",
"Pad",
"(",
"d",
"float64",
")",
"Bound",
"{",
"b",
".",
"Min",
"[",
"0",
"]",
"-=",
"d",
"\n",
"b",
".",
"Min",
"[",
"1",
"]",
"-=",
"d",
"\n\n",
"b",
".",
"Max",
"[",
"0",
"]",
"+=",
"d",
"\n",
"b",
"."... | // Pad extends the bound in all directions by the given value. | [
"Pad",
"extends",
"the",
"bound",
"in",
"all",
"directions",
"by",
"the",
"given",
"value",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/bound.go#L104-L112 | train |
paulmach/orb | bound.go | Center | func (b Bound) Center() Point {
return Point{
(b.Min[0] + b.Max[0]) / 2.0,
(b.Min[1] + b.Max[1]) / 2.0,
}
} | go | func (b Bound) Center() Point {
return Point{
(b.Min[0] + b.Max[0]) / 2.0,
(b.Min[1] + b.Max[1]) / 2.0,
}
} | [
"func",
"(",
"b",
"Bound",
")",
"Center",
"(",
")",
"Point",
"{",
"return",
"Point",
"{",
"(",
"b",
".",
"Min",
"[",
"0",
"]",
"+",
"b",
".",
"Max",
"[",
"0",
"]",
")",
"/",
"2.0",
",",
"(",
"b",
".",
"Min",
"[",
"1",
"]",
"+",
"b",
"."... | // Center returns the center of the bounds by "averaging" the x and y coords. | [
"Center",
"returns",
"the",
"center",
"of",
"the",
"bounds",
"by",
"averaging",
"the",
"x",
"and",
"y",
"coords",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/bound.go#L115-L120 | train |
paulmach/orb | bound.go | IsEmpty | func (b Bound) IsEmpty() bool {
return b.Min[0] > b.Max[0] || b.Min[1] > b.Max[1]
} | go | func (b Bound) IsEmpty() bool {
return b.Min[0] > b.Max[0] || b.Min[1] > b.Max[1]
} | [
"func",
"(",
"b",
"Bound",
")",
"IsEmpty",
"(",
")",
"bool",
"{",
"return",
"b",
".",
"Min",
"[",
"0",
"]",
">",
"b",
".",
"Max",
"[",
"0",
"]",
"||",
"b",
".",
"Min",
"[",
"1",
"]",
">",
"b",
".",
"Max",
"[",
"1",
"]",
"\n",
"}"
] | // IsEmpty 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. | [
"IsEmpty",
"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"... | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/bound.go#L155-L157 | train |
paulmach/orb | bound.go | IsZero | func (b Bound) IsZero() bool {
return b.Max == Point{} && b.Min == Point{}
} | go | func (b Bound) IsZero() bool {
return b.Max == Point{} && b.Min == Point{}
} | [
"func",
"(",
"b",
"Bound",
")",
"IsZero",
"(",
")",
"bool",
"{",
"return",
"b",
".",
"Max",
"==",
"Point",
"{",
"}",
"&&",
"b",
".",
"Min",
"==",
"Point",
"{",
"}",
"\n",
"}"
] | // IsZero return true if the bound just includes just null island. | [
"IsZero",
"return",
"true",
"if",
"the",
"bound",
"just",
"includes",
"just",
"null",
"island",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/bound.go#L160-L162 | train |
paulmach/orb | bound.go | Equal | func (b Bound) Equal(c Bound) bool {
return b.Min == c.Min && b.Max == c.Max
} | go | func (b Bound) Equal(c Bound) bool {
return b.Min == c.Min && b.Max == c.Max
} | [
"func",
"(",
"b",
"Bound",
")",
"Equal",
"(",
"c",
"Bound",
")",
"bool",
"{",
"return",
"b",
".",
"Min",
"==",
"c",
".",
"Min",
"&&",
"b",
".",
"Max",
"==",
"c",
".",
"Max",
"\n",
"}"
] | // Equal returns if two bounds are equal. | [
"Equal",
"returns",
"if",
"two",
"bounds",
"are",
"equal",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/bound.go#L170-L172 | train |
paulmach/orb | planar/area.go | Area | func Area(g orb.Geometry) float64 {
// TODO: make faster non-centroid version.
_, a := CentroidArea(g)
return a
} | go | func Area(g orb.Geometry) float64 {
// TODO: make faster non-centroid version.
_, a := CentroidArea(g)
return a
} | [
"func",
"Area",
"(",
"g",
"orb",
".",
"Geometry",
")",
"float64",
"{",
"// TODO: make faster non-centroid version.",
"_",
",",
"a",
":=",
"CentroidArea",
"(",
"g",
")",
"\n",
"return",
"a",
"\n",
"}"
] | // Area returns the area of the geometry in the 2d plane. | [
"Area",
"returns",
"the",
"area",
"of",
"the",
"geometry",
"in",
"the",
"2d",
"plane",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/planar/area.go#L13-L17 | train |
paulmach/orb | planar/area.go | CentroidArea | func CentroidArea(g orb.Geometry) (orb.Point, float64) {
if g == nil {
return orb.Point{}, 0
}
switch g := g.(type) {
case orb.Point:
return multiPointCentroid(orb.MultiPoint{g}), 0
case orb.MultiPoint:
return multiPointCentroid(g), 0
case orb.LineString:
return multiLineStringCentroid(orb.MultiLineString{g}), 0
case orb.MultiLineString:
return multiLineStringCentroid(g), 0
case orb.Ring:
return ringCentroidArea(g)
case orb.Polygon:
return polygonCentroidArea(g)
case orb.MultiPolygon:
return multiPolygonCentroidArea(g)
case orb.Collection:
return collectionCentroidArea(g)
case orb.Bound:
return CentroidArea(g.ToRing())
}
panic(fmt.Sprintf("geometry type not supported: %T", g))
} | go | func CentroidArea(g orb.Geometry) (orb.Point, float64) {
if g == nil {
return orb.Point{}, 0
}
switch g := g.(type) {
case orb.Point:
return multiPointCentroid(orb.MultiPoint{g}), 0
case orb.MultiPoint:
return multiPointCentroid(g), 0
case orb.LineString:
return multiLineStringCentroid(orb.MultiLineString{g}), 0
case orb.MultiLineString:
return multiLineStringCentroid(g), 0
case orb.Ring:
return ringCentroidArea(g)
case orb.Polygon:
return polygonCentroidArea(g)
case orb.MultiPolygon:
return multiPolygonCentroidArea(g)
case orb.Collection:
return collectionCentroidArea(g)
case orb.Bound:
return CentroidArea(g.ToRing())
}
panic(fmt.Sprintf("geometry type not supported: %T", g))
} | [
"func",
"CentroidArea",
"(",
"g",
"orb",
".",
"Geometry",
")",
"(",
"orb",
".",
"Point",
",",
"float64",
")",
"{",
"if",
"g",
"==",
"nil",
"{",
"return",
"orb",
".",
"Point",
"{",
"}",
",",
"0",
"\n",
"}",
"\n\n",
"switch",
"g",
":=",
"g",
".",... | // CentroidArea returns both the centroid and the area in the 2d plane.
// Since the area is need for the centroid, return both.
// Polygon area will always be >= zero. Ring area my be negative if it has
// a clockwise winding orider. | [
"CentroidArea",
"returns",
"both",
"the",
"centroid",
"and",
"the",
"area",
"in",
"the",
"2d",
"plane",
".",
"Since",
"the",
"area",
"is",
"need",
"for",
"the",
"centroid",
"return",
"both",
".",
"Polygon",
"area",
"will",
"always",
"be",
">",
"=",
"zero... | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/planar/area.go#L23-L50 | train |
paulmach/orb | encoding/mvt/geometry.go | elMLS | func elMLS(mls orb.MultiLineString) int {
c := 0
for _, ls := range mls {
c += 2 + 2*len(ls)
}
return c
} | go | func elMLS(mls orb.MultiLineString) int {
c := 0
for _, ls := range mls {
c += 2 + 2*len(ls)
}
return c
} | [
"func",
"elMLS",
"(",
"mls",
"orb",
".",
"MultiLineString",
")",
"int",
"{",
"c",
":=",
"0",
"\n",
"for",
"_",
",",
"ls",
":=",
"range",
"mls",
"{",
"c",
"+=",
"2",
"+",
"2",
"*",
"len",
"(",
"ls",
")",
"\n",
"}",
"\n\n",
"return",
"c",
"\n",... | // functions to estimate encoded length | [
"functions",
"to",
"estimate",
"encoded",
"length"
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/encoding/mvt/geometry.go#L433-L440 | train |
paulmach/orb | encoding/mvt/marshal.go | Marshal | func Marshal(layers Layers) ([]byte, error) {
vt := &vectortile.Tile{
Layers: make([]*vectortile.Tile_Layer, 0, len(layers)),
}
for _, l := range layers {
v := l.Version
e := l.Extent
layer := &vectortile.Tile_Layer{
Name: &l.Name,
Version: &v,
Extent: &e,
Features: make([]*vectortile.Tile_Feature, 0, len(l.Features)),
}
kve := newKeyValueEncoder()
for i, f := range l.Features {
t, g, err := encodeGeometry(f.Geometry)
if err != nil {
return nil, errors.WithMessage(err, fmt.Sprintf("layer %s: feature %d: error encoding geometry", l.Name, i))
}
tags, err := encodeProperties(kve, f.Properties)
if err != nil {
return nil, errors.WithMessage(err, fmt.Sprintf("layer %s: feature %d: error encoding properties", l.Name, i))
}
layer.Features = append(layer.Features, &vectortile.Tile_Feature{
Id: convertID(f.ID),
Tags: tags,
Type: &t,
Geometry: g,
})
}
layer.Keys = kve.Keys
layer.Values = kve.Values
vt.Layers = append(vt.Layers, layer)
}
return proto.Marshal(vt)
} | go | func Marshal(layers Layers) ([]byte, error) {
vt := &vectortile.Tile{
Layers: make([]*vectortile.Tile_Layer, 0, len(layers)),
}
for _, l := range layers {
v := l.Version
e := l.Extent
layer := &vectortile.Tile_Layer{
Name: &l.Name,
Version: &v,
Extent: &e,
Features: make([]*vectortile.Tile_Feature, 0, len(l.Features)),
}
kve := newKeyValueEncoder()
for i, f := range l.Features {
t, g, err := encodeGeometry(f.Geometry)
if err != nil {
return nil, errors.WithMessage(err, fmt.Sprintf("layer %s: feature %d: error encoding geometry", l.Name, i))
}
tags, err := encodeProperties(kve, f.Properties)
if err != nil {
return nil, errors.WithMessage(err, fmt.Sprintf("layer %s: feature %d: error encoding properties", l.Name, i))
}
layer.Features = append(layer.Features, &vectortile.Tile_Feature{
Id: convertID(f.ID),
Tags: tags,
Type: &t,
Geometry: g,
})
}
layer.Keys = kve.Keys
layer.Values = kve.Values
vt.Layers = append(vt.Layers, layer)
}
return proto.Marshal(vt)
} | [
"func",
"Marshal",
"(",
"layers",
"Layers",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"vt",
":=",
"&",
"vectortile",
".",
"Tile",
"{",
"Layers",
":",
"make",
"(",
"[",
"]",
"*",
"vectortile",
".",
"Tile_Layer",
",",
"0",
",",
"len",
"("... | // Marshal will take a set of layers and encode them into a Mapbox Vector Tile format. | [
"Marshal",
"will",
"take",
"a",
"set",
"of",
"layers",
"and",
"encode",
"them",
"into",
"a",
"Mapbox",
"Vector",
"Tile",
"format",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/encoding/mvt/marshal.go#L43-L85 | train |
paulmach/orb | encoding/wkt/wkt.go | MarshalString | func MarshalString(g orb.Geometry) string {
buf := bytes.NewBuffer(nil)
wkt(buf, g)
return buf.String()
} | go | func MarshalString(g orb.Geometry) string {
buf := bytes.NewBuffer(nil)
wkt(buf, g)
return buf.String()
} | [
"func",
"MarshalString",
"(",
"g",
"orb",
".",
"Geometry",
")",
"string",
"{",
"buf",
":=",
"bytes",
".",
"NewBuffer",
"(",
"nil",
")",
"\n\n",
"wkt",
"(",
"buf",
",",
"g",
")",
"\n",
"return",
"buf",
".",
"String",
"(",
")",
"\n",
"}"
] | // MarshalString returns a WKT representation of the Geometry if possible. | [
"MarshalString",
"returns",
"a",
"WKT",
"representation",
"of",
"the",
"Geometry",
"if",
"possible",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/encoding/wkt/wkt.go#L11-L16 | train |
paulmach/orb | planar/distance.go | Distance | func Distance(p1, p2 orb.Point) float64 {
d0 := (p1[0] - p2[0])
d1 := (p1[1] - p2[1])
return math.Sqrt(d0*d0 + d1*d1)
} | go | func Distance(p1, p2 orb.Point) float64 {
d0 := (p1[0] - p2[0])
d1 := (p1[1] - p2[1])
return math.Sqrt(d0*d0 + d1*d1)
} | [
"func",
"Distance",
"(",
"p1",
",",
"p2",
"orb",
".",
"Point",
")",
"float64",
"{",
"d0",
":=",
"(",
"p1",
"[",
"0",
"]",
"-",
"p2",
"[",
"0",
"]",
")",
"\n",
"d1",
":=",
"(",
"p1",
"[",
"1",
"]",
"-",
"p2",
"[",
"1",
"]",
")",
"\n",
"r... | // Distance returns the distance between two points in 2d euclidean geometry. | [
"Distance",
"returns",
"the",
"distance",
"between",
"two",
"points",
"in",
"2d",
"euclidean",
"geometry",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/planar/distance.go#L10-L14 | train |
paulmach/orb | planar/distance.go | DistanceSquared | func DistanceSquared(p1, p2 orb.Point) float64 {
d0 := (p1[0] - p2[0])
d1 := (p1[1] - p2[1])
return d0*d0 + d1*d1
} | go | func DistanceSquared(p1, p2 orb.Point) float64 {
d0 := (p1[0] - p2[0])
d1 := (p1[1] - p2[1])
return d0*d0 + d1*d1
} | [
"func",
"DistanceSquared",
"(",
"p1",
",",
"p2",
"orb",
".",
"Point",
")",
"float64",
"{",
"d0",
":=",
"(",
"p1",
"[",
"0",
"]",
"-",
"p2",
"[",
"0",
"]",
")",
"\n",
"d1",
":=",
"(",
"p1",
"[",
"1",
"]",
"-",
"p2",
"[",
"1",
"]",
")",
"\n... | // DistanceSquared returns the square of the distance between two points in 2d euclidean geometry. | [
"DistanceSquared",
"returns",
"the",
"square",
"of",
"the",
"distance",
"between",
"two",
"points",
"in",
"2d",
"euclidean",
"geometry",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/planar/distance.go#L17-L21 | train |
paulmach/orb | geo/bound.go | NewBoundAroundPoint | func NewBoundAroundPoint(center orb.Point, distance float64) orb.Bound {
radDist := distance / orb.EarthRadius
radLat := deg2rad(center[1])
radLon := deg2rad(center[0])
minLat := radLat - radDist
maxLat := radLat + radDist
var minLon, maxLon float64
if minLat > minLatitude && maxLat < maxLatitude {
deltaLon := math.Asin(math.Sin(radDist) / math.Cos(radLat))
minLon = radLon - deltaLon
if minLon < minLongitude {
minLon += 2 * math.Pi
}
maxLon = radLon + deltaLon
if maxLon > maxLongitude {
maxLon -= 2 * math.Pi
}
} else {
minLat = math.Max(minLat, minLatitude)
maxLat = math.Min(maxLat, maxLatitude)
minLon = minLongitude
maxLon = maxLongitude
}
return orb.Bound{
Min: orb.Point{rad2deg(minLon), rad2deg(minLat)},
Max: orb.Point{rad2deg(maxLon), rad2deg(maxLat)},
}
} | go | func NewBoundAroundPoint(center orb.Point, distance float64) orb.Bound {
radDist := distance / orb.EarthRadius
radLat := deg2rad(center[1])
radLon := deg2rad(center[0])
minLat := radLat - radDist
maxLat := radLat + radDist
var minLon, maxLon float64
if minLat > minLatitude && maxLat < maxLatitude {
deltaLon := math.Asin(math.Sin(radDist) / math.Cos(radLat))
minLon = radLon - deltaLon
if minLon < minLongitude {
minLon += 2 * math.Pi
}
maxLon = radLon + deltaLon
if maxLon > maxLongitude {
maxLon -= 2 * math.Pi
}
} else {
minLat = math.Max(minLat, minLatitude)
maxLat = math.Min(maxLat, maxLatitude)
minLon = minLongitude
maxLon = maxLongitude
}
return orb.Bound{
Min: orb.Point{rad2deg(minLon), rad2deg(minLat)},
Max: orb.Point{rad2deg(maxLon), rad2deg(maxLat)},
}
} | [
"func",
"NewBoundAroundPoint",
"(",
"center",
"orb",
".",
"Point",
",",
"distance",
"float64",
")",
"orb",
".",
"Bound",
"{",
"radDist",
":=",
"distance",
"/",
"orb",
".",
"EarthRadius",
"\n",
"radLat",
":=",
"deg2rad",
"(",
"center",
"[",
"1",
"]",
")",... | // NewBoundAroundPoint creates a new bound given a center point,
// and a distance from the center point in meters. | [
"NewBoundAroundPoint",
"creates",
"a",
"new",
"bound",
"given",
"a",
"center",
"point",
"and",
"a",
"distance",
"from",
"the",
"center",
"point",
"in",
"meters",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/geo/bound.go#L11-L40 | train |
paulmach/orb | geo/bound.go | BoundPad | func BoundPad(b orb.Bound, meters float64) orb.Bound {
dy := meters / 111131.75
dx := dy / math.Cos(deg2rad(b.Max[1]))
dx = math.Max(dx, dy/math.Cos(deg2rad(b.Min[1])))
b.Min[0] -= dx
b.Min[1] -= dy
b.Max[0] += dx
b.Max[1] += dy
b.Min[0] = math.Max(b.Min[0], -180)
b.Min[1] = math.Max(b.Min[1], -90)
b.Max[0] = math.Min(b.Max[0], 180)
b.Max[1] = math.Min(b.Max[1], 90)
return b
} | go | func BoundPad(b orb.Bound, meters float64) orb.Bound {
dy := meters / 111131.75
dx := dy / math.Cos(deg2rad(b.Max[1]))
dx = math.Max(dx, dy/math.Cos(deg2rad(b.Min[1])))
b.Min[0] -= dx
b.Min[1] -= dy
b.Max[0] += dx
b.Max[1] += dy
b.Min[0] = math.Max(b.Min[0], -180)
b.Min[1] = math.Max(b.Min[1], -90)
b.Max[0] = math.Min(b.Max[0], 180)
b.Max[1] = math.Min(b.Max[1], 90)
return b
} | [
"func",
"BoundPad",
"(",
"b",
"orb",
".",
"Bound",
",",
"meters",
"float64",
")",
"orb",
".",
"Bound",
"{",
"dy",
":=",
"meters",
"/",
"111131.75",
"\n",
"dx",
":=",
"dy",
"/",
"math",
".",
"Cos",
"(",
"deg2rad",
"(",
"b",
".",
"Max",
"[",
"1",
... | // BoundPad expands the bound in all directions by the given amount of meters. | [
"BoundPad",
"expands",
"the",
"bound",
"in",
"all",
"directions",
"by",
"the",
"given",
"amount",
"of",
"meters",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/geo/bound.go#L43-L61 | train |
paulmach/orb | geo/bound.go | BoundWidth | func BoundWidth(b orb.Bound) float64 {
c := (b.Min[1] + b.Max[1]) / 2.0
s1 := orb.Point{b.Min[0], c}
s2 := orb.Point{b.Max[0], c}
return Distance(s1, s2)
} | go | func BoundWidth(b orb.Bound) float64 {
c := (b.Min[1] + b.Max[1]) / 2.0
s1 := orb.Point{b.Min[0], c}
s2 := orb.Point{b.Max[0], c}
return Distance(s1, s2)
} | [
"func",
"BoundWidth",
"(",
"b",
"orb",
".",
"Bound",
")",
"float64",
"{",
"c",
":=",
"(",
"b",
".",
"Min",
"[",
"1",
"]",
"+",
"b",
".",
"Max",
"[",
"1",
"]",
")",
"/",
"2.0",
"\n\n",
"s1",
":=",
"orb",
".",
"Point",
"{",
"b",
".",
"Min",
... | // BoundWidth returns the approximate width in meters
// of the center of the bound. | [
"BoundWidth",
"returns",
"the",
"approximate",
"width",
"in",
"meters",
"of",
"the",
"center",
"of",
"the",
"bound",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/geo/bound.go#L70-L77 | train |
paulmach/orb | internal/mercator/mercator.go | ToPlanar | func ToPlanar(lng, lat float64, level uint32) (x, y float64) {
maxtiles := float64(uint32(1 << level))
x = (lng/360.0 + 0.5) * maxtiles
// bound it because we have a top of the world problem
siny := math.Sin(lat * math.Pi / 180.0)
if siny < -0.9999 {
y = 0
} else if siny > 0.9999 {
y = maxtiles - 1
} else {
lat = 0.5 + 0.5*math.Log((1.0+siny)/(1.0-siny))/(-2*math.Pi)
y = lat * maxtiles
}
return
} | go | func ToPlanar(lng, lat float64, level uint32) (x, y float64) {
maxtiles := float64(uint32(1 << level))
x = (lng/360.0 + 0.5) * maxtiles
// bound it because we have a top of the world problem
siny := math.Sin(lat * math.Pi / 180.0)
if siny < -0.9999 {
y = 0
} else if siny > 0.9999 {
y = maxtiles - 1
} else {
lat = 0.5 + 0.5*math.Log((1.0+siny)/(1.0-siny))/(-2*math.Pi)
y = lat * maxtiles
}
return
} | [
"func",
"ToPlanar",
"(",
"lng",
",",
"lat",
"float64",
",",
"level",
"uint32",
")",
"(",
"x",
",",
"y",
"float64",
")",
"{",
"maxtiles",
":=",
"float64",
"(",
"uint32",
"(",
"1",
"<<",
"level",
")",
")",
"\n",
"x",
"=",
"(",
"lng",
"/",
"360.0",
... | // ToPlanar converts the point to geo world coordinates at the given live. | [
"ToPlanar",
"converts",
"the",
"point",
"to",
"geo",
"world",
"coordinates",
"at",
"the",
"given",
"live",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/internal/mercator/mercator.go#L30-L47 | train |
paulmach/orb | internal/mercator/mercator.go | ToGeo | func ToGeo(x, y float64, level uint32) (lng, lat float64) {
maxtiles := float64(uint32(1 << level))
lng = 360.0 * (x/maxtiles - 0.5)
lat = 2.0*math.Atan(math.Exp(math.Pi-(2*math.Pi)*(y/maxtiles)))*(180.0/math.Pi) - 90.0
return lng, lat
} | go | func ToGeo(x, y float64, level uint32) (lng, lat float64) {
maxtiles := float64(uint32(1 << level))
lng = 360.0 * (x/maxtiles - 0.5)
lat = 2.0*math.Atan(math.Exp(math.Pi-(2*math.Pi)*(y/maxtiles)))*(180.0/math.Pi) - 90.0
return lng, lat
} | [
"func",
"ToGeo",
"(",
"x",
",",
"y",
"float64",
",",
"level",
"uint32",
")",
"(",
"lng",
",",
"lat",
"float64",
")",
"{",
"maxtiles",
":=",
"float64",
"(",
"uint32",
"(",
"1",
"<<",
"level",
")",
")",
"\n\n",
"lng",
"=",
"360.0",
"*",
"(",
"x",
... | // ToGeo projects world coordinates back to geo coordinates. | [
"ToGeo",
"projects",
"world",
"coordinates",
"back",
"to",
"geo",
"coordinates",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/internal/mercator/mercator.go#L50-L57 | train |
paulmach/orb | clone.go | Clone | func Clone(g Geometry) Geometry {
if g == nil {
return nil
}
switch g := g.(type) {
case Point:
return g
case MultiPoint:
if g == nil {
return nil
}
return g.Clone()
case LineString:
if g == nil {
return nil
}
return g.Clone()
case MultiLineString:
if g == nil {
return nil
}
return g.Clone()
case Ring:
if g == nil {
return nil
}
return g.Clone()
case Polygon:
if g == nil {
return nil
}
return g.Clone()
case MultiPolygon:
if g == nil {
return nil
}
return g.Clone()
case Collection:
if g == nil {
return nil
}
return g.Clone()
case Bound:
return g
}
panic(fmt.Sprintf("geometry type not supported: %T", g))
} | go | func Clone(g Geometry) Geometry {
if g == nil {
return nil
}
switch g := g.(type) {
case Point:
return g
case MultiPoint:
if g == nil {
return nil
}
return g.Clone()
case LineString:
if g == nil {
return nil
}
return g.Clone()
case MultiLineString:
if g == nil {
return nil
}
return g.Clone()
case Ring:
if g == nil {
return nil
}
return g.Clone()
case Polygon:
if g == nil {
return nil
}
return g.Clone()
case MultiPolygon:
if g == nil {
return nil
}
return g.Clone()
case Collection:
if g == nil {
return nil
}
return g.Clone()
case Bound:
return g
}
panic(fmt.Sprintf("geometry type not supported: %T", g))
} | [
"func",
"Clone",
"(",
"g",
"Geometry",
")",
"Geometry",
"{",
"if",
"g",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"switch",
"g",
":=",
"g",
".",
"(",
"type",
")",
"{",
"case",
"Point",
":",
"return",
"g",
"\n",
"case",
"MultiPoint",
"... | // Clone will make a deep copy of the geometry. | [
"Clone",
"will",
"make",
"a",
"deep",
"copy",
"of",
"the",
"geometry",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/clone.go#L8-L56 | train |
paulmach/orb | equal.go | Equal | func Equal(g1, g2 Geometry) bool {
if g1 == nil || g2 == nil {
return g1 == g2
}
if g1.GeoJSONType() != g2.GeoJSONType() {
return false
}
switch g1 := g1.(type) {
case Point:
return g1.Equal(g2.(Point))
case MultiPoint:
return g1.Equal(g2.(MultiPoint))
case LineString:
return g1.Equal(g2.(LineString))
case MultiLineString:
return g1.Equal(g2.(MultiLineString))
case Ring:
g2, ok := g2.(Ring)
if !ok {
return false
}
return g1.Equal(g2)
case Polygon:
g2, ok := g2.(Polygon)
if !ok {
return false
}
return g1.Equal(g2)
case MultiPolygon:
return g1.Equal(g2.(MultiPolygon))
case Collection:
return g1.Equal(g2.(Collection))
case Bound:
g2, ok := g2.(Bound)
if !ok {
return false
}
return g1.Equal(g2)
}
panic(fmt.Sprintf("geometry type not supported: %T", g1))
} | go | func Equal(g1, g2 Geometry) bool {
if g1 == nil || g2 == nil {
return g1 == g2
}
if g1.GeoJSONType() != g2.GeoJSONType() {
return false
}
switch g1 := g1.(type) {
case Point:
return g1.Equal(g2.(Point))
case MultiPoint:
return g1.Equal(g2.(MultiPoint))
case LineString:
return g1.Equal(g2.(LineString))
case MultiLineString:
return g1.Equal(g2.(MultiLineString))
case Ring:
g2, ok := g2.(Ring)
if !ok {
return false
}
return g1.Equal(g2)
case Polygon:
g2, ok := g2.(Polygon)
if !ok {
return false
}
return g1.Equal(g2)
case MultiPolygon:
return g1.Equal(g2.(MultiPolygon))
case Collection:
return g1.Equal(g2.(Collection))
case Bound:
g2, ok := g2.(Bound)
if !ok {
return false
}
return g1.Equal(g2)
}
panic(fmt.Sprintf("geometry type not supported: %T", g1))
} | [
"func",
"Equal",
"(",
"g1",
",",
"g2",
"Geometry",
")",
"bool",
"{",
"if",
"g1",
"==",
"nil",
"||",
"g2",
"==",
"nil",
"{",
"return",
"g1",
"==",
"g2",
"\n",
"}",
"\n\n",
"if",
"g1",
".",
"GeoJSONType",
"(",
")",
"!=",
"g2",
".",
"GeoJSONType",
... | // Equal returns if the two geometrires are equal. | [
"Equal",
"returns",
"if",
"the",
"two",
"geometrires",
"are",
"equal",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/equal.go#L8-L51 | train |
paulmach/orb | round.go | Round | func Round(g Geometry, factor ...int) Geometry {
if g == nil {
return nil
}
f := float64(DefaultRoundingFactor)
if len(factor) > 0 {
f = float64(factor[0])
}
switch g := g.(type) {
case Point:
return Point{
math.Round(g[0]*f) / f,
math.Round(g[1]*f) / f,
}
case MultiPoint:
if g == nil {
return nil
}
roundPoints([]Point(g), f)
return g
case LineString:
if g == nil {
return nil
}
roundPoints([]Point(g), f)
return g
case MultiLineString:
if g == nil {
return nil
}
for _, ls := range g {
roundPoints([]Point(ls), f)
}
return g
case Ring:
if g == nil {
return nil
}
roundPoints([]Point(g), f)
return g
case Polygon:
if g == nil {
return nil
}
for _, r := range g {
roundPoints([]Point(r), f)
}
return g
case MultiPolygon:
if g == nil {
return nil
}
for _, p := range g {
for _, r := range p {
roundPoints([]Point(r), f)
}
}
return g
case Collection:
if g == nil {
return nil
}
for i := range g {
g[i] = Round(g[i], int(f))
}
return g
case Bound:
return Bound{
Min: Point{
math.Round(g.Min[0]*f) / f,
math.Round(g.Min[1]*f) / f,
},
Max: Point{
math.Round(g.Max[0]*f) / f,
math.Round(g.Max[1]*f) / f,
},
}
}
panic(fmt.Sprintf("geometry type not supported: %T", g))
} | go | func Round(g Geometry, factor ...int) Geometry {
if g == nil {
return nil
}
f := float64(DefaultRoundingFactor)
if len(factor) > 0 {
f = float64(factor[0])
}
switch g := g.(type) {
case Point:
return Point{
math.Round(g[0]*f) / f,
math.Round(g[1]*f) / f,
}
case MultiPoint:
if g == nil {
return nil
}
roundPoints([]Point(g), f)
return g
case LineString:
if g == nil {
return nil
}
roundPoints([]Point(g), f)
return g
case MultiLineString:
if g == nil {
return nil
}
for _, ls := range g {
roundPoints([]Point(ls), f)
}
return g
case Ring:
if g == nil {
return nil
}
roundPoints([]Point(g), f)
return g
case Polygon:
if g == nil {
return nil
}
for _, r := range g {
roundPoints([]Point(r), f)
}
return g
case MultiPolygon:
if g == nil {
return nil
}
for _, p := range g {
for _, r := range p {
roundPoints([]Point(r), f)
}
}
return g
case Collection:
if g == nil {
return nil
}
for i := range g {
g[i] = Round(g[i], int(f))
}
return g
case Bound:
return Bound{
Min: Point{
math.Round(g.Min[0]*f) / f,
math.Round(g.Min[1]*f) / f,
},
Max: Point{
math.Round(g.Max[0]*f) / f,
math.Round(g.Max[1]*f) / f,
},
}
}
panic(fmt.Sprintf("geometry type not supported: %T", g))
} | [
"func",
"Round",
"(",
"g",
"Geometry",
",",
"factor",
"...",
"int",
")",
"Geometry",
"{",
"if",
"g",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"f",
":=",
"float64",
"(",
"DefaultRoundingFactor",
")",
"\n",
"if",
"len",
"(",
"factor",
")",... | // Round will round all the coordinates of the geometry to the given factor.
// The default is 6 decimal places. | [
"Round",
"will",
"round",
"all",
"the",
"coordinates",
"of",
"the",
"geometry",
"to",
"the",
"given",
"factor",
".",
"The",
"default",
"is",
"6",
"decimal",
"places",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/round.go#L10-L93 | train |
paulmach/orb | geojson/bbox.go | NewBBox | func NewBBox(b orb.Bound) BBox {
return []float64{
b.Min[0], b.Min[1],
b.Max[0], b.Max[1],
}
} | go | func NewBBox(b orb.Bound) BBox {
return []float64{
b.Min[0], b.Min[1],
b.Max[0], b.Max[1],
}
} | [
"func",
"NewBBox",
"(",
"b",
"orb",
".",
"Bound",
")",
"BBox",
"{",
"return",
"[",
"]",
"float64",
"{",
"b",
".",
"Min",
"[",
"0",
"]",
",",
"b",
".",
"Min",
"[",
"1",
"]",
",",
"b",
".",
"Max",
"[",
"0",
"]",
",",
"b",
".",
"Max",
"[",
... | // NewBBox creates a bbox from a a bound. | [
"NewBBox",
"creates",
"a",
"bbox",
"from",
"a",
"a",
"bound",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/geojson/bbox.go#L10-L15 | train |
paulmach/orb | geojson/bbox.go | Valid | func (bb BBox) Valid() bool {
if bb == nil {
return false
}
return len(bb) >= 4 && len(bb)%2 == 0
} | go | func (bb BBox) Valid() bool {
if bb == nil {
return false
}
return len(bb) >= 4 && len(bb)%2 == 0
} | [
"func",
"(",
"bb",
"BBox",
")",
"Valid",
"(",
")",
"bool",
"{",
"if",
"bb",
"==",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"return",
"len",
"(",
"bb",
")",
">=",
"4",
"&&",
"len",
"(",
"bb",
")",
"%",
"2",
"==",
"0",
"\n",
"}"
] | // Valid checks if the bbox is present and has at least 4 elements. | [
"Valid",
"checks",
"if",
"the",
"bbox",
"is",
"present",
"and",
"has",
"at",
"least",
"4",
"elements",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/geojson/bbox.go#L18-L24 | train |
paulmach/orb | geojson/bbox.go | Bound | func (bb BBox) Bound() orb.Bound {
if !bb.Valid() {
return orb.Bound{}
}
mid := len(bb) / 2
return orb.Bound{
Min: orb.Point{bb[0], bb[1]},
Max: orb.Point{bb[mid], bb[mid+1]},
}
} | go | func (bb BBox) Bound() orb.Bound {
if !bb.Valid() {
return orb.Bound{}
}
mid := len(bb) / 2
return orb.Bound{
Min: orb.Point{bb[0], bb[1]},
Max: orb.Point{bb[mid], bb[mid+1]},
}
} | [
"func",
"(",
"bb",
"BBox",
")",
"Bound",
"(",
")",
"orb",
".",
"Bound",
"{",
"if",
"!",
"bb",
".",
"Valid",
"(",
")",
"{",
"return",
"orb",
".",
"Bound",
"{",
"}",
"\n",
"}",
"\n\n",
"mid",
":=",
"len",
"(",
"bb",
")",
"/",
"2",
"\n\n",
"re... | // Bound returns the orb.Bound for the BBox. | [
"Bound",
"returns",
"the",
"orb",
".",
"Bound",
"for",
"the",
"BBox",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/geojson/bbox.go#L27-L38 | train |
paulmach/orb | encoding/mvt/simplify.go | Simplify | func (ls Layers) Simplify(s orb.Simplifier) {
for _, l := range ls {
l.Simplify(s)
}
} | go | func (ls Layers) Simplify(s orb.Simplifier) {
for _, l := range ls {
l.Simplify(s)
}
} | [
"func",
"(",
"ls",
"Layers",
")",
"Simplify",
"(",
"s",
"orb",
".",
"Simplifier",
")",
"{",
"for",
"_",
",",
"l",
":=",
"range",
"ls",
"{",
"l",
".",
"Simplify",
"(",
"s",
")",
"\n",
"}",
"\n",
"}"
] | // Simplify will run all the geometry of all the layers through the provided simplifer. | [
"Simplify",
"will",
"run",
"all",
"the",
"geometry",
"of",
"all",
"the",
"layers",
"through",
"the",
"provided",
"simplifer",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/encoding/mvt/simplify.go#L9-L13 | train |
paulmach/orb | encoding/mvt/simplify.go | Simplify | func (l *Layer) Simplify(s orb.Simplifier) {
count := 0
for _, f := range l.Features {
g := s.Simplify(f.Geometry)
if g == nil {
continue
}
f.Geometry = g
l.Features[count] = f
count++
}
l.Features = l.Features[:count]
} | go | func (l *Layer) Simplify(s orb.Simplifier) {
count := 0
for _, f := range l.Features {
g := s.Simplify(f.Geometry)
if g == nil {
continue
}
f.Geometry = g
l.Features[count] = f
count++
}
l.Features = l.Features[:count]
} | [
"func",
"(",
"l",
"*",
"Layer",
")",
"Simplify",
"(",
"s",
"orb",
".",
"Simplifier",
")",
"{",
"count",
":=",
"0",
"\n",
"for",
"_",
",",
"f",
":=",
"range",
"l",
".",
"Features",
"{",
"g",
":=",
"s",
".",
"Simplify",
"(",
"f",
".",
"Geometry",... | // Simplify will run the layer geometries through the simplifier. | [
"Simplify",
"will",
"run",
"the",
"layer",
"geometries",
"through",
"the",
"simplifier",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/encoding/mvt/simplify.go#L16-L30 | train |
paulmach/orb | quadtree/quadtree.go | Add | func (q *Quadtree) Add(p orb.Pointer) error {
if p == nil {
return nil
}
point := p.Point()
if !q.bound.Contains(point) {
return ErrPointOutsideOfBounds
}
if q.root == nil {
q.root = &node{
Value: p,
}
return nil
}
q.add(q.root, p, p.Point(),
// q.bound.Left(), q.bound.Right(),
// q.bound.Bottom(), q.bound.Top(),
q.bound.Min[0], q.bound.Max[0],
q.bound.Min[1], q.bound.Max[1],
)
return nil
} | go | func (q *Quadtree) Add(p orb.Pointer) error {
if p == nil {
return nil
}
point := p.Point()
if !q.bound.Contains(point) {
return ErrPointOutsideOfBounds
}
if q.root == nil {
q.root = &node{
Value: p,
}
return nil
}
q.add(q.root, p, p.Point(),
// q.bound.Left(), q.bound.Right(),
// q.bound.Bottom(), q.bound.Top(),
q.bound.Min[0], q.bound.Max[0],
q.bound.Min[1], q.bound.Max[1],
)
return nil
} | [
"func",
"(",
"q",
"*",
"Quadtree",
")",
"Add",
"(",
"p",
"orb",
".",
"Pointer",
")",
"error",
"{",
"if",
"p",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"point",
":=",
"p",
".",
"Point",
"(",
")",
"\n",
"if",
"!",
"q",
".",
"bound"... | // Add puts an object into the quad tree, must be within the quadtree bounds.
// This function is not thread-safe, ie. multiple goroutines cannot insert into
// a single quadtree. | [
"Add",
"puts",
"an",
"object",
"into",
"the",
"quad",
"tree",
"must",
"be",
"within",
"the",
"quadtree",
"bounds",
".",
"This",
"function",
"is",
"not",
"thread",
"-",
"safe",
"ie",
".",
"multiple",
"goroutines",
"cannot",
"insert",
"into",
"a",
"single",
... | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/quadtree/quadtree.go#L53-L78 | train |
paulmach/orb | quadtree/quadtree.go | add | func (q *Quadtree) add(n *node, p orb.Pointer, point orb.Point, left, right, bottom, top float64) {
i := 0
// figure which child of this internal node the point is in.
if cy := (bottom + top) / 2.0; point[1] <= cy {
top = cy
i = 2
} else {
bottom = cy
}
if cx := (left + right) / 2.0; point[0] >= cx {
left = cx
i++
} else {
right = cx
}
if n.Children[i] == nil {
n.Children[i] = &node{Value: p}
return
}
// proceed down to the child to see if it's a leaf yet and we can add the pointer there.
q.add(n.Children[i], p, point, left, right, bottom, top)
} | go | func (q *Quadtree) add(n *node, p orb.Pointer, point orb.Point, left, right, bottom, top float64) {
i := 0
// figure which child of this internal node the point is in.
if cy := (bottom + top) / 2.0; point[1] <= cy {
top = cy
i = 2
} else {
bottom = cy
}
if cx := (left + right) / 2.0; point[0] >= cx {
left = cx
i++
} else {
right = cx
}
if n.Children[i] == nil {
n.Children[i] = &node{Value: p}
return
}
// proceed down to the child to see if it's a leaf yet and we can add the pointer there.
q.add(n.Children[i], p, point, left, right, bottom, top)
} | [
"func",
"(",
"q",
"*",
"Quadtree",
")",
"add",
"(",
"n",
"*",
"node",
",",
"p",
"orb",
".",
"Pointer",
",",
"point",
"orb",
".",
"Point",
",",
"left",
",",
"right",
",",
"bottom",
",",
"top",
"float64",
")",
"{",
"i",
":=",
"0",
"\n\n",
"// fig... | // add is the recursive search to find a place to add the point | [
"add",
"is",
"the",
"recursive",
"search",
"to",
"find",
"a",
"place",
"to",
"add",
"the",
"point"
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/quadtree/quadtree.go#L81-L106 | train |
paulmach/orb | quadtree/quadtree.go | removeNode | func removeNode(n *node) {
var i int
for {
i = -1
if n.Children[0] != nil {
i = 0
} else if n.Children[1] != nil {
i = 1
} else if n.Children[2] != nil {
i = 2
} else if n.Children[3] != nil {
i = 3
}
if i == -1 {
n.Value = nil
return
}
if n.Children[i].Value == nil {
n.Children[i] = nil
continue
}
break
}
n.Value = n.Children[i].Value
removeNode(n.Children[i])
} | go | func removeNode(n *node) {
var i int
for {
i = -1
if n.Children[0] != nil {
i = 0
} else if n.Children[1] != nil {
i = 1
} else if n.Children[2] != nil {
i = 2
} else if n.Children[3] != nil {
i = 3
}
if i == -1 {
n.Value = nil
return
}
if n.Children[i].Value == nil {
n.Children[i] = nil
continue
}
break
}
n.Value = n.Children[i].Value
removeNode(n.Children[i])
} | [
"func",
"removeNode",
"(",
"n",
"*",
"node",
")",
"{",
"var",
"i",
"int",
"\n",
"for",
"{",
"i",
"=",
"-",
"1",
"\n",
"if",
"n",
".",
"Children",
"[",
"0",
"]",
"!=",
"nil",
"{",
"i",
"=",
"0",
"\n",
"}",
"else",
"if",
"n",
".",
"Children",... | // removeNode is the recursive fixing up of the tree when we remove a node. | [
"removeNode",
"is",
"the",
"recursive",
"fixing",
"up",
"of",
"the",
"tree",
"when",
"we",
"remove",
"a",
"node",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/quadtree/quadtree.go#L146-L175 | train |
paulmach/orb | quadtree/quadtree.go | InBoundMatching | func (q *Quadtree) InBoundMatching(buf []orb.Pointer, b orb.Bound, f FilterFunc) []orb.Pointer {
if q.root == nil {
return nil
}
var p []orb.Pointer
if len(buf) > 0 {
p = buf[:0]
}
v := &inBoundVisitor{
bound: &b,
pointers: p,
filter: f,
}
newVisit(v).Visit(q.root,
// q.bound.Left(), q.bound.Right(),
// q.bound.Bottom(), q.bound.Top(),
q.bound.Min[0], q.bound.Max[0],
q.bound.Min[1], q.bound.Max[1],
)
return v.pointers
} | go | func (q *Quadtree) InBoundMatching(buf []orb.Pointer, b orb.Bound, f FilterFunc) []orb.Pointer {
if q.root == nil {
return nil
}
var p []orb.Pointer
if len(buf) > 0 {
p = buf[:0]
}
v := &inBoundVisitor{
bound: &b,
pointers: p,
filter: f,
}
newVisit(v).Visit(q.root,
// q.bound.Left(), q.bound.Right(),
// q.bound.Bottom(), q.bound.Top(),
q.bound.Min[0], q.bound.Max[0],
q.bound.Min[1], q.bound.Max[1],
)
return v.pointers
} | [
"func",
"(",
"q",
"*",
"Quadtree",
")",
"InBoundMatching",
"(",
"buf",
"[",
"]",
"orb",
".",
"Pointer",
",",
"b",
"orb",
".",
"Bound",
",",
"f",
"FilterFunc",
")",
"[",
"]",
"orb",
".",
"Pointer",
"{",
"if",
"q",
".",
"root",
"==",
"nil",
"{",
... | // InBoundMatching returns a slice with all the pointers in the quadtree that are
// within the given bound and matching the give filter function. 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 a pre-created tree. | [
"InBoundMatching",
"returns",
"a",
"slice",
"with",
"all",
"the",
"pointers",
"in",
"the",
"quadtree",
"that",
"are",
"within",
"the",
"given",
"bound",
"and",
"matching",
"the",
"give",
"filter",
"function",
".",
"An",
"optional",
"buffer",
"parameter",
"is",... | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/quadtree/quadtree.go#L274-L297 | train |
paulmach/orb | planar/contains.go | RingContains | func RingContains(r orb.Ring, point orb.Point) bool {
if !r.Bound().Contains(point) {
return false
}
c, on := rayIntersect(point, r[0], r[len(r)-1])
if on {
return true
}
for i := 0; i < len(r)-1; i++ {
inter, on := rayIntersect(point, r[i], r[i+1])
if on {
return true
}
if inter {
c = !c
}
}
return c
} | go | func RingContains(r orb.Ring, point orb.Point) bool {
if !r.Bound().Contains(point) {
return false
}
c, on := rayIntersect(point, r[0], r[len(r)-1])
if on {
return true
}
for i := 0; i < len(r)-1; i++ {
inter, on := rayIntersect(point, r[i], r[i+1])
if on {
return true
}
if inter {
c = !c
}
}
return c
} | [
"func",
"RingContains",
"(",
"r",
"orb",
".",
"Ring",
",",
"point",
"orb",
".",
"Point",
")",
"bool",
"{",
"if",
"!",
"r",
".",
"Bound",
"(",
")",
".",
"Contains",
"(",
"point",
")",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"c",
",",
"on",
":... | // RingContains returns true if the point is inside the ring.
// Points on the boundary are considered in. | [
"RingContains",
"returns",
"true",
"if",
"the",
"point",
"is",
"inside",
"the",
"ring",
".",
"Points",
"on",
"the",
"boundary",
"are",
"considered",
"in",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/planar/contains.go#L11-L33 | train |
paulmach/orb | planar/contains.go | PolygonContains | func PolygonContains(p orb.Polygon, point orb.Point) bool {
if !RingContains(p[0], point) {
return false
}
for i := 1; i < len(p); i++ {
if RingContains(p[i], point) {
return false
}
}
return true
} | go | func PolygonContains(p orb.Polygon, point orb.Point) bool {
if !RingContains(p[0], point) {
return false
}
for i := 1; i < len(p); i++ {
if RingContains(p[i], point) {
return false
}
}
return true
} | [
"func",
"PolygonContains",
"(",
"p",
"orb",
".",
"Polygon",
",",
"point",
"orb",
".",
"Point",
")",
"bool",
"{",
"if",
"!",
"RingContains",
"(",
"p",
"[",
"0",
"]",
",",
"point",
")",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"for",
"i",
":=",
"... | // PolygonContains checks if the point is within the polygon.
// Points on the boundary are considered in. | [
"PolygonContains",
"checks",
"if",
"the",
"point",
"is",
"within",
"the",
"polygon",
".",
"Points",
"on",
"the",
"boundary",
"are",
"considered",
"in",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/planar/contains.go#L37-L49 | train |
paulmach/orb | planar/contains.go | MultiPolygonContains | func MultiPolygonContains(mp orb.MultiPolygon, point orb.Point) bool {
for _, p := range mp {
if PolygonContains(p, point) {
return true
}
}
return false
} | go | func MultiPolygonContains(mp orb.MultiPolygon, point orb.Point) bool {
for _, p := range mp {
if PolygonContains(p, point) {
return true
}
}
return false
} | [
"func",
"MultiPolygonContains",
"(",
"mp",
"orb",
".",
"MultiPolygon",
",",
"point",
"orb",
".",
"Point",
")",
"bool",
"{",
"for",
"_",
",",
"p",
":=",
"range",
"mp",
"{",
"if",
"PolygonContains",
"(",
"p",
",",
"point",
")",
"{",
"return",
"true",
"... | // MultiPolygonContains checks if the point is within the multi-polygon.
// Points on the boundary are considered in. | [
"MultiPolygonContains",
"checks",
"if",
"the",
"point",
"is",
"within",
"the",
"multi",
"-",
"polygon",
".",
"Points",
"on",
"the",
"boundary",
"are",
"considered",
"in",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/planar/contains.go#L53-L61 | train |
paulmach/orb | resample/line_string.go | Resample | func Resample(ls orb.LineString, df orb.DistanceFunc, totalPoints int) orb.LineString {
if totalPoints <= 0 {
return nil
}
ls, ret := resampleEdgeCases(ls, totalPoints)
if ret {
return ls
}
// precomputes the total distance and intermediate distances
total, dists := precomputeDistances(ls, df)
return resample(ls, dists, total, totalPoints)
} | go | func Resample(ls orb.LineString, df orb.DistanceFunc, totalPoints int) orb.LineString {
if totalPoints <= 0 {
return nil
}
ls, ret := resampleEdgeCases(ls, totalPoints)
if ret {
return ls
}
// precomputes the total distance and intermediate distances
total, dists := precomputeDistances(ls, df)
return resample(ls, dists, total, totalPoints)
} | [
"func",
"Resample",
"(",
"ls",
"orb",
".",
"LineString",
",",
"df",
"orb",
".",
"DistanceFunc",
",",
"totalPoints",
"int",
")",
"orb",
".",
"LineString",
"{",
"if",
"totalPoints",
"<=",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"ls",
",",
"ret",
... | // Resample converts the line string into totalPoints-1 evenly spaced segments.
// This function will modify the linestring input. | [
"Resample",
"converts",
"the",
"line",
"string",
"into",
"totalPoints",
"-",
"1",
"evenly",
"spaced",
"segments",
".",
"This",
"function",
"will",
"modify",
"the",
"linestring",
"input",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/resample/line_string.go#L11-L24 | train |
paulmach/orb | resample/line_string.go | ToInterval | func ToInterval(ls orb.LineString, df orb.DistanceFunc, dist float64) orb.LineString {
if dist <= 0 {
return nil
}
// precomputes the total distance and intermediate distances
total, dists := precomputeDistances(ls, df)
totalPoints := int(total/dist) + 1
ls, ret := resampleEdgeCases(ls, totalPoints)
if ret {
return ls
}
return resample(ls, dists, total, totalPoints)
} | go | func ToInterval(ls orb.LineString, df orb.DistanceFunc, dist float64) orb.LineString {
if dist <= 0 {
return nil
}
// precomputes the total distance and intermediate distances
total, dists := precomputeDistances(ls, df)
totalPoints := int(total/dist) + 1
ls, ret := resampleEdgeCases(ls, totalPoints)
if ret {
return ls
}
return resample(ls, dists, total, totalPoints)
} | [
"func",
"ToInterval",
"(",
"ls",
"orb",
".",
"LineString",
",",
"df",
"orb",
".",
"DistanceFunc",
",",
"dist",
"float64",
")",
"orb",
".",
"LineString",
"{",
"if",
"dist",
"<=",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"// precomputes the total distan... | // ToInterval coverts the line string into evenly spaced points of
// about the given distance.
// This function will modify the linestring input. | [
"ToInterval",
"coverts",
"the",
"line",
"string",
"into",
"evenly",
"spaced",
"points",
"of",
"about",
"the",
"given",
"distance",
".",
"This",
"function",
"will",
"modify",
"the",
"linestring",
"input",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/resample/line_string.go#L29-L44 | train |
paulmach/orb | resample/line_string.go | resampleEdgeCases | func resampleEdgeCases(ls orb.LineString, totalPoints int) (orb.LineString, bool) {
// degenerate case
if len(ls) <= 1 {
return ls, true
}
// if all the points are the same, treat as special case.
equal := true
for _, point := range ls {
if !ls[0].Equal(point) {
equal = false
break
}
}
if equal {
if totalPoints > len(ls) {
// extend to be requested length
for len(ls) != totalPoints {
ls = append(ls, ls[0])
}
return ls, true
}
// contract to be requested length
ls = ls[:totalPoints]
return ls, true
}
return ls, false
} | go | func resampleEdgeCases(ls orb.LineString, totalPoints int) (orb.LineString, bool) {
// degenerate case
if len(ls) <= 1 {
return ls, true
}
// if all the points are the same, treat as special case.
equal := true
for _, point := range ls {
if !ls[0].Equal(point) {
equal = false
break
}
}
if equal {
if totalPoints > len(ls) {
// extend to be requested length
for len(ls) != totalPoints {
ls = append(ls, ls[0])
}
return ls, true
}
// contract to be requested length
ls = ls[:totalPoints]
return ls, true
}
return ls, false
} | [
"func",
"resampleEdgeCases",
"(",
"ls",
"orb",
".",
"LineString",
",",
"totalPoints",
"int",
")",
"(",
"orb",
".",
"LineString",
",",
"bool",
")",
"{",
"// degenerate case",
"if",
"len",
"(",
"ls",
")",
"<=",
"1",
"{",
"return",
"ls",
",",
"true",
"\n"... | // resampleEdgeCases is used to handle edge case for
// resampling like not enough points and the line string 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",
"line",
"string",
"is",
"all",
"the",
"same",
"point",
".",
"will",
"return",
"nil",
"if",
"there",
"are",
"no",
"edge"... | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/resample/line_string.go#L95-L126 | train |
paulmach/orb | encoding/wkb/wkb.go | MustMarshal | func MustMarshal(geom orb.Geometry, byteOrder ...binary.ByteOrder) []byte {
d, err := Marshal(geom, byteOrder...)
if err != nil {
panic(err)
}
return d
} | go | func MustMarshal(geom orb.Geometry, byteOrder ...binary.ByteOrder) []byte {
d, err := Marshal(geom, byteOrder...)
if err != nil {
panic(err)
}
return d
} | [
"func",
"MustMarshal",
"(",
"geom",
"orb",
".",
"Geometry",
",",
"byteOrder",
"...",
"binary",
".",
"ByteOrder",
")",
"[",
"]",
"byte",
"{",
"d",
",",
"err",
":=",
"Marshal",
"(",
"geom",
",",
"byteOrder",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
... | // MustMarshal will encode the geometry and panic on error.
// Currently there is no reason to error during geometry marshalling. | [
"MustMarshal",
"will",
"encode",
"the",
"geometry",
"and",
"panic",
"on",
"error",
".",
"Currently",
"there",
"is",
"no",
"reason",
"to",
"error",
"during",
"geometry",
"marshalling",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/encoding/wkb/wkb.go#L45-L52 | train |
paulmach/orb | encoding/wkb/wkb.go | Marshal | func Marshal(geom orb.Geometry, byteOrder ...binary.ByteOrder) ([]byte, error) {
buf := bytes.NewBuffer(make([]byte, 0, geomLength(geom)))
e := NewEncoder(buf)
if len(byteOrder) > 0 {
e.SetByteOrder(byteOrder[0])
}
err := e.Encode(geom)
if err != nil {
return nil, err
}
if buf.Len() == 0 {
return nil, nil
}
return buf.Bytes(), nil
} | go | func Marshal(geom orb.Geometry, byteOrder ...binary.ByteOrder) ([]byte, error) {
buf := bytes.NewBuffer(make([]byte, 0, geomLength(geom)))
e := NewEncoder(buf)
if len(byteOrder) > 0 {
e.SetByteOrder(byteOrder[0])
}
err := e.Encode(geom)
if err != nil {
return nil, err
}
if buf.Len() == 0 {
return nil, nil
}
return buf.Bytes(), nil
} | [
"func",
"Marshal",
"(",
"geom",
"orb",
".",
"Geometry",
",",
"byteOrder",
"...",
"binary",
".",
"ByteOrder",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"buf",
":=",
"bytes",
".",
"NewBuffer",
"(",
"make",
"(",
"[",
"]",
"byte",
",",
"0",
... | // Marshal encodes the geometry with the given byte order. | [
"Marshal",
"encodes",
"the",
"geometry",
"with",
"the",
"given",
"byte",
"order",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/encoding/wkb/wkb.go#L55-L74 | train |
paulmach/orb | encoding/wkb/wkb.go | NewEncoder | func NewEncoder(w io.Writer) *Encoder {
return &Encoder{
w: w,
order: DefaultByteOrder,
}
} | go | func NewEncoder(w io.Writer) *Encoder {
return &Encoder{
w: w,
order: DefaultByteOrder,
}
} | [
"func",
"NewEncoder",
"(",
"w",
"io",
".",
"Writer",
")",
"*",
"Encoder",
"{",
"return",
"&",
"Encoder",
"{",
"w",
":",
"w",
",",
"order",
":",
"DefaultByteOrder",
",",
"}",
"\n",
"}"
] | // NewEncoder creates a new Encoder for the given writer | [
"NewEncoder",
"creates",
"a",
"new",
"Encoder",
"for",
"the",
"given",
"writer"
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/encoding/wkb/wkb.go#L77-L82 | train |
paulmach/orb | encoding/wkb/wkb.go | Encode | func (e *Encoder) Encode(geom orb.Geometry) error {
if geom == nil {
return nil
}
switch g := geom.(type) {
// nil values should not write any data. Empty sizes will still
// write and empty version of that type.
case orb.MultiPoint:
if g == nil {
return nil
}
case orb.LineString:
if g == nil {
return nil
}
case orb.MultiLineString:
if g == nil {
return nil
}
case orb.Polygon:
if g == nil {
return nil
}
case orb.MultiPolygon:
if g == nil {
return nil
}
case orb.Collection:
if g == nil {
return nil
}
// deal with types that are not supported by wkb
case orb.Ring:
if g == nil {
return nil
}
geom = orb.Polygon{g}
case orb.Bound:
geom = g.ToPolygon()
}
var b []byte
if e.order == binary.LittleEndian {
b = []byte{1}
} else {
b = []byte{0}
}
_, err := e.w.Write(b)
if err != nil {
return err
}
if e.buf == nil {
e.buf = make([]byte, 16)
}
switch g := geom.(type) {
case orb.Point:
return e.writePoint(g)
case orb.MultiPoint:
return e.writeMultiPoint(g)
case orb.LineString:
return e.writeLineString(g)
case orb.MultiLineString:
return e.writeMultiLineString(g)
case orb.Polygon:
return e.writePolygon(g)
case orb.MultiPolygon:
return e.writeMultiPolygon(g)
case orb.Collection:
return e.writeCollection(g)
}
panic("unsupported type")
} | go | func (e *Encoder) Encode(geom orb.Geometry) error {
if geom == nil {
return nil
}
switch g := geom.(type) {
// nil values should not write any data. Empty sizes will still
// write and empty version of that type.
case orb.MultiPoint:
if g == nil {
return nil
}
case orb.LineString:
if g == nil {
return nil
}
case orb.MultiLineString:
if g == nil {
return nil
}
case orb.Polygon:
if g == nil {
return nil
}
case orb.MultiPolygon:
if g == nil {
return nil
}
case orb.Collection:
if g == nil {
return nil
}
// deal with types that are not supported by wkb
case orb.Ring:
if g == nil {
return nil
}
geom = orb.Polygon{g}
case orb.Bound:
geom = g.ToPolygon()
}
var b []byte
if e.order == binary.LittleEndian {
b = []byte{1}
} else {
b = []byte{0}
}
_, err := e.w.Write(b)
if err != nil {
return err
}
if e.buf == nil {
e.buf = make([]byte, 16)
}
switch g := geom.(type) {
case orb.Point:
return e.writePoint(g)
case orb.MultiPoint:
return e.writeMultiPoint(g)
case orb.LineString:
return e.writeLineString(g)
case orb.MultiLineString:
return e.writeMultiLineString(g)
case orb.Polygon:
return e.writePolygon(g)
case orb.MultiPolygon:
return e.writeMultiPolygon(g)
case orb.Collection:
return e.writeCollection(g)
}
panic("unsupported type")
} | [
"func",
"(",
"e",
"*",
"Encoder",
")",
"Encode",
"(",
"geom",
"orb",
".",
"Geometry",
")",
"error",
"{",
"if",
"geom",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"switch",
"g",
":=",
"geom",
".",
"(",
"type",
")",
"{",
"// nil values sho... | // Encode will write the geometry encoded as WKB to the given writer. | [
"Encode",
"will",
"write",
"the",
"geometry",
"encoded",
"as",
"WKB",
"to",
"the",
"given",
"writer",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/encoding/wkb/wkb.go#L91-L167 | train |
paulmach/orb | encoding/wkb/wkb.go | Unmarshal | func Unmarshal(b []byte) (orb.Geometry, error) {
g, err := NewDecoder(bytes.NewReader(b)).Decode()
if err == io.EOF || err == io.ErrUnexpectedEOF {
return nil, ErrNotWKB
}
return g, err
} | go | func Unmarshal(b []byte) (orb.Geometry, error) {
g, err := NewDecoder(bytes.NewReader(b)).Decode()
if err == io.EOF || err == io.ErrUnexpectedEOF {
return nil, ErrNotWKB
}
return g, err
} | [
"func",
"Unmarshal",
"(",
"b",
"[",
"]",
"byte",
")",
"(",
"orb",
".",
"Geometry",
",",
"error",
")",
"{",
"g",
",",
"err",
":=",
"NewDecoder",
"(",
"bytes",
".",
"NewReader",
"(",
"b",
")",
")",
".",
"Decode",
"(",
")",
"\n",
"if",
"err",
"=="... | // Unmarshal will decode the type into a Geometry. | [
"Unmarshal",
"will",
"decode",
"the",
"type",
"into",
"a",
"Geometry",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/encoding/wkb/wkb.go#L175-L182 | train |
paulmach/orb | encoding/wkb/wkb.go | Decode | func (d *Decoder) Decode() (orb.Geometry, error) {
byteOrder, typ, err := readByteOrderType(d.r)
if err != nil {
return nil, err
}
switch typ {
case pointType:
return readPoint(d.r, byteOrder)
case multiPointType:
return readMultiPoint(d.r, byteOrder)
case lineStringType:
return readLineString(d.r, byteOrder)
case multiLineStringType:
return readMultiLineString(d.r, byteOrder)
case polygonType:
return readPolygon(d.r, byteOrder)
case multiPolygonType:
return readMultiPolygon(d.r, byteOrder)
case geometryCollectionType:
return readCollection(d.r, byteOrder)
}
return nil, ErrUnsupportedGeometry
} | go | func (d *Decoder) Decode() (orb.Geometry, error) {
byteOrder, typ, err := readByteOrderType(d.r)
if err != nil {
return nil, err
}
switch typ {
case pointType:
return readPoint(d.r, byteOrder)
case multiPointType:
return readMultiPoint(d.r, byteOrder)
case lineStringType:
return readLineString(d.r, byteOrder)
case multiLineStringType:
return readMultiLineString(d.r, byteOrder)
case polygonType:
return readPolygon(d.r, byteOrder)
case multiPolygonType:
return readMultiPolygon(d.r, byteOrder)
case geometryCollectionType:
return readCollection(d.r, byteOrder)
}
return nil, ErrUnsupportedGeometry
} | [
"func",
"(",
"d",
"*",
"Decoder",
")",
"Decode",
"(",
")",
"(",
"orb",
".",
"Geometry",
",",
"error",
")",
"{",
"byteOrder",
",",
"typ",
",",
"err",
":=",
"readByteOrderType",
"(",
"d",
".",
"r",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return"... | // Decode will decode the next geometry off of the steam. | [
"Decode",
"will",
"decode",
"the",
"next",
"geometry",
"off",
"of",
"the",
"steam",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/encoding/wkb/wkb.go#L192-L216 | train |
paulmach/orb | encoding/wkb/wkb.go | geomLength | func geomLength(geom orb.Geometry) int {
switch g := geom.(type) {
case orb.Point:
return 21
case orb.MultiPoint:
return 9 + 21*len(g)
case orb.LineString:
return 9 + 16*len(g)
case orb.MultiLineString:
sum := 0
for _, ls := range g {
sum += 9 + 16*len(ls)
}
return 9 + sum
case orb.Polygon:
sum := 0
for _, r := range g {
sum += 4 + 16*len(r)
}
return 9 + sum
case orb.MultiPolygon:
sum := 0
for _, c := range g {
sum += geomLength(c)
}
return 9 + sum
case orb.Collection:
sum := 0
for _, c := range g {
sum += geomLength(c)
}
return 9 + sum
}
return 0
} | go | func geomLength(geom orb.Geometry) int {
switch g := geom.(type) {
case orb.Point:
return 21
case orb.MultiPoint:
return 9 + 21*len(g)
case orb.LineString:
return 9 + 16*len(g)
case orb.MultiLineString:
sum := 0
for _, ls := range g {
sum += 9 + 16*len(ls)
}
return 9 + sum
case orb.Polygon:
sum := 0
for _, r := range g {
sum += 4 + 16*len(r)
}
return 9 + sum
case orb.MultiPolygon:
sum := 0
for _, c := range g {
sum += geomLength(c)
}
return 9 + sum
case orb.Collection:
sum := 0
for _, c := range g {
sum += geomLength(c)
}
return 9 + sum
}
return 0
} | [
"func",
"geomLength",
"(",
"geom",
"orb",
".",
"Geometry",
")",
"int",
"{",
"switch",
"g",
":=",
"geom",
".",
"(",
"type",
")",
"{",
"case",
"orb",
".",
"Point",
":",
"return",
"21",
"\n",
"case",
"orb",
".",
"MultiPoint",
":",
"return",
"9",
"+",
... | // geomLength helps to do preallocation during a marshal. | [
"geomLength",
"helps",
"to",
"do",
"preallocation",
"during",
"a",
"marshal",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/encoding/wkb/wkb.go#L247-L286 | train |
paulmach/orb | geojson/geometry.go | NewGeometry | func NewGeometry(g orb.Geometry) *Geometry {
jg := &Geometry{}
switch g := g.(type) {
case orb.Ring:
jg.Coordinates = orb.Polygon{g}
case orb.Bound:
jg.Coordinates = g.ToPolygon()
case orb.Collection:
for _, c := range g {
jg.Geometries = append(jg.Geometries, NewGeometry(c))
}
jg.Type = g.GeoJSONType()
default:
jg.Coordinates = g
}
if jg.Coordinates != nil {
jg.Type = jg.Coordinates.GeoJSONType()
}
return jg
} | go | func NewGeometry(g orb.Geometry) *Geometry {
jg := &Geometry{}
switch g := g.(type) {
case orb.Ring:
jg.Coordinates = orb.Polygon{g}
case orb.Bound:
jg.Coordinates = g.ToPolygon()
case orb.Collection:
for _, c := range g {
jg.Geometries = append(jg.Geometries, NewGeometry(c))
}
jg.Type = g.GeoJSONType()
default:
jg.Coordinates = g
}
if jg.Coordinates != nil {
jg.Type = jg.Coordinates.GeoJSONType()
}
return jg
} | [
"func",
"NewGeometry",
"(",
"g",
"orb",
".",
"Geometry",
")",
"*",
"Geometry",
"{",
"jg",
":=",
"&",
"Geometry",
"{",
"}",
"\n",
"switch",
"g",
":=",
"g",
".",
"(",
"type",
")",
"{",
"case",
"orb",
".",
"Ring",
":",
"jg",
".",
"Coordinates",
"=",... | // NewGeometry will create a Geometry object but will convert
// the input into a GoeJSON geometry. For example, it will convert
// Rings and Bounds into Polygons. | [
"NewGeometry",
"will",
"create",
"a",
"Geometry",
"object",
"but",
"will",
"convert",
"the",
"input",
"into",
"a",
"GoeJSON",
"geometry",
".",
"For",
"example",
"it",
"will",
"convert",
"Rings",
"and",
"Bounds",
"into",
"Polygons",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/geojson/geometry.go#L20-L40 | train |
paulmach/orb | geojson/geometry.go | Geometry | func (g Geometry) Geometry() orb.Geometry {
if g.Coordinates != nil {
return g.Coordinates
}
c := make(orb.Collection, 0, len(g.Geometries))
for _, geom := range g.Geometries {
c = append(c, geom.Geometry())
}
return c
} | go | func (g Geometry) Geometry() orb.Geometry {
if g.Coordinates != nil {
return g.Coordinates
}
c := make(orb.Collection, 0, len(g.Geometries))
for _, geom := range g.Geometries {
c = append(c, geom.Geometry())
}
return c
} | [
"func",
"(",
"g",
"Geometry",
")",
"Geometry",
"(",
")",
"orb",
".",
"Geometry",
"{",
"if",
"g",
".",
"Coordinates",
"!=",
"nil",
"{",
"return",
"g",
".",
"Coordinates",
"\n",
"}",
"\n\n",
"c",
":=",
"make",
"(",
"orb",
".",
"Collection",
",",
"0",... | // Geometry returns the orb.Geometry for the geojson Geometry.
// This will convert the "Geometries" into a orb.Collection if applicable. | [
"Geometry",
"returns",
"the",
"orb",
".",
"Geometry",
"for",
"the",
"geojson",
"Geometry",
".",
"This",
"will",
"convert",
"the",
"Geometries",
"into",
"a",
"orb",
".",
"Collection",
"if",
"applicable",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/geojson/geometry.go#L44-L54 | train |
paulmach/orb | geojson/geometry.go | MarshalJSON | func (g Geometry) MarshalJSON() ([]byte, error) {
if g.Coordinates == nil && len(g.Geometries) == 0 {
return []byte(`null`), nil
}
ng := &jsonGeometryMarshall{}
switch g := g.Coordinates.(type) {
case orb.Ring:
ng.Coordinates = orb.Polygon{g}
case orb.Bound:
ng.Coordinates = g.ToPolygon()
case orb.Collection:
ng.Geometries = make([]*Geometry, 0, len(g))
for _, c := range g {
ng.Geometries = append(ng.Geometries, NewGeometry(c))
}
ng.Type = g.GeoJSONType()
default:
ng.Coordinates = g
}
if ng.Coordinates != nil {
ng.Type = ng.Coordinates.GeoJSONType()
}
if len(g.Geometries) > 0 {
ng.Geometries = g.Geometries
ng.Type = orb.Collection{}.GeoJSONType()
}
return json.Marshal(ng)
} | go | func (g Geometry) MarshalJSON() ([]byte, error) {
if g.Coordinates == nil && len(g.Geometries) == 0 {
return []byte(`null`), nil
}
ng := &jsonGeometryMarshall{}
switch g := g.Coordinates.(type) {
case orb.Ring:
ng.Coordinates = orb.Polygon{g}
case orb.Bound:
ng.Coordinates = g.ToPolygon()
case orb.Collection:
ng.Geometries = make([]*Geometry, 0, len(g))
for _, c := range g {
ng.Geometries = append(ng.Geometries, NewGeometry(c))
}
ng.Type = g.GeoJSONType()
default:
ng.Coordinates = g
}
if ng.Coordinates != nil {
ng.Type = ng.Coordinates.GeoJSONType()
}
if len(g.Geometries) > 0 {
ng.Geometries = g.Geometries
ng.Type = orb.Collection{}.GeoJSONType()
}
return json.Marshal(ng)
} | [
"func",
"(",
"g",
"Geometry",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"if",
"g",
".",
"Coordinates",
"==",
"nil",
"&&",
"len",
"(",
"g",
".",
"Geometries",
")",
"==",
"0",
"{",
"return",
"[",
"]",
"byte",
"(... | // MarshalJSON will marshal the geometry into the correct json structure. | [
"MarshalJSON",
"will",
"marshal",
"the",
"geometry",
"into",
"the",
"correct",
"json",
"structure",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/geojson/geometry.go#L57-L87 | train |
paulmach/orb | geojson/geometry.go | UnmarshalJSON | func (g *Geometry) UnmarshalJSON(data []byte) error {
jg := &jsonGeometry{}
err := json.Unmarshal(data, &jg)
if err != nil {
return err
}
switch jg.Type {
case "Point":
p := orb.Point{}
err = json.Unmarshal(jg.Coordinates, &p)
g.Coordinates = p
case "MultiPoint":
mp := orb.MultiPoint{}
err = json.Unmarshal(jg.Coordinates, &mp)
g.Coordinates = mp
case "LineString":
ls := orb.LineString{}
err = json.Unmarshal(jg.Coordinates, &ls)
g.Coordinates = ls
case "MultiLineString":
mls := orb.MultiLineString{}
err = json.Unmarshal(jg.Coordinates, &mls)
g.Coordinates = mls
case "Polygon":
p := orb.Polygon{}
err = json.Unmarshal(jg.Coordinates, &p)
g.Coordinates = p
case "MultiPolygon":
mp := orb.MultiPolygon{}
err = json.Unmarshal(jg.Coordinates, &mp)
g.Coordinates = mp
case "GeometryCollection":
g.Geometries = jg.Geometries
default:
return errors.New("geojson: invalid geometry")
}
return err
} | go | func (g *Geometry) UnmarshalJSON(data []byte) error {
jg := &jsonGeometry{}
err := json.Unmarshal(data, &jg)
if err != nil {
return err
}
switch jg.Type {
case "Point":
p := orb.Point{}
err = json.Unmarshal(jg.Coordinates, &p)
g.Coordinates = p
case "MultiPoint":
mp := orb.MultiPoint{}
err = json.Unmarshal(jg.Coordinates, &mp)
g.Coordinates = mp
case "LineString":
ls := orb.LineString{}
err = json.Unmarshal(jg.Coordinates, &ls)
g.Coordinates = ls
case "MultiLineString":
mls := orb.MultiLineString{}
err = json.Unmarshal(jg.Coordinates, &mls)
g.Coordinates = mls
case "Polygon":
p := orb.Polygon{}
err = json.Unmarshal(jg.Coordinates, &p)
g.Coordinates = p
case "MultiPolygon":
mp := orb.MultiPolygon{}
err = json.Unmarshal(jg.Coordinates, &mp)
g.Coordinates = mp
case "GeometryCollection":
g.Geometries = jg.Geometries
default:
return errors.New("geojson: invalid geometry")
}
return err
} | [
"func",
"(",
"g",
"*",
"Geometry",
")",
"UnmarshalJSON",
"(",
"data",
"[",
"]",
"byte",
")",
"error",
"{",
"jg",
":=",
"&",
"jsonGeometry",
"{",
"}",
"\n",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"data",
",",
"&",
"jg",
")",
"\n",
"if",
"err"... | // UnmarshalJSON will unmarshal the correct geometry from the json structure. | [
"UnmarshalJSON",
"will",
"unmarshal",
"the",
"correct",
"geometry",
"from",
"the",
"json",
"structure",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/geojson/geometry.go#L102-L140 | train |
paulmach/orb | geojson/geometry.go | MarshalJSON | func (mp MultiPoint) MarshalJSON() ([]byte, error) {
return json.Marshal(Geometry{Coordinates: orb.MultiPoint(mp)})
} | go | func (mp MultiPoint) MarshalJSON() ([]byte, error) {
return json.Marshal(Geometry{Coordinates: orb.MultiPoint(mp)})
} | [
"func",
"(",
"mp",
"MultiPoint",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"return",
"json",
".",
"Marshal",
"(",
"Geometry",
"{",
"Coordinates",
":",
"orb",
".",
"MultiPoint",
"(",
"mp",
")",
"}",
")",
"\n",
"}"
... | // MarshalJSON will convert the MultiPoint into a GeoJSON MultiPoint geometry. | [
"MarshalJSON",
"will",
"convert",
"the",
"MultiPoint",
"into",
"a",
"GeoJSON",
"MultiPoint",
"geometry",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/geojson/geometry.go#L181-L183 | train |
paulmach/orb | geojson/geometry.go | MarshalJSON | func (ls LineString) MarshalJSON() ([]byte, error) {
return json.Marshal(Geometry{Coordinates: orb.LineString(ls)})
} | go | func (ls LineString) MarshalJSON() ([]byte, error) {
return json.Marshal(Geometry{Coordinates: orb.LineString(ls)})
} | [
"func",
"(",
"ls",
"LineString",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"return",
"json",
".",
"Marshal",
"(",
"Geometry",
"{",
"Coordinates",
":",
"orb",
".",
"LineString",
"(",
"ls",
")",
"}",
")",
"\n",
"}"
... | // MarshalJSON will convert the LineString into a GeoJSON LineString geometry. | [
"MarshalJSON",
"will",
"convert",
"the",
"LineString",
"into",
"a",
"GeoJSON",
"LineString",
"geometry",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/geojson/geometry.go#L211-L213 | train |
paulmach/orb | geojson/geometry.go | MarshalJSON | func (mls MultiLineString) MarshalJSON() ([]byte, error) {
return json.Marshal(Geometry{Coordinates: orb.MultiLineString(mls)})
} | go | func (mls MultiLineString) MarshalJSON() ([]byte, error) {
return json.Marshal(Geometry{Coordinates: orb.MultiLineString(mls)})
} | [
"func",
"(",
"mls",
"MultiLineString",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"return",
"json",
".",
"Marshal",
"(",
"Geometry",
"{",
"Coordinates",
":",
"orb",
".",
"MultiLineString",
"(",
"mls",
")",
"}",
")",
... | // MarshalJSON will convert the MultiLineString into a GeoJSON MultiLineString geometry. | [
"MarshalJSON",
"will",
"convert",
"the",
"MultiLineString",
"into",
"a",
"GeoJSON",
"MultiLineString",
"geometry",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/geojson/geometry.go#L241-L243 | train |
paulmach/orb | geojson/geometry.go | MarshalJSON | func (p Polygon) MarshalJSON() ([]byte, error) {
return json.Marshal(Geometry{Coordinates: orb.Polygon(p)})
} | go | func (p Polygon) MarshalJSON() ([]byte, error) {
return json.Marshal(Geometry{Coordinates: orb.Polygon(p)})
} | [
"func",
"(",
"p",
"Polygon",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"return",
"json",
".",
"Marshal",
"(",
"Geometry",
"{",
"Coordinates",
":",
"orb",
".",
"Polygon",
"(",
"p",
")",
"}",
")",
"\n",
"}"
] | // MarshalJSON will convert the Polygon into a GeoJSON Polygon geometry. | [
"MarshalJSON",
"will",
"convert",
"the",
"Polygon",
"into",
"a",
"GeoJSON",
"Polygon",
"geometry",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/geojson/geometry.go#L271-L273 | train |
paulmach/orb | geojson/geometry.go | UnmarshalJSON | func (p *Polygon) UnmarshalJSON(data []byte) error {
g := &Geometry{}
err := json.Unmarshal(data, &g)
if err != nil {
return err
}
polygon, ok := g.Coordinates.(orb.Polygon)
if !ok {
return errors.New("geojson: not a Polygon type")
}
*p = Polygon(polygon)
return nil
} | go | func (p *Polygon) UnmarshalJSON(data []byte) error {
g := &Geometry{}
err := json.Unmarshal(data, &g)
if err != nil {
return err
}
polygon, ok := g.Coordinates.(orb.Polygon)
if !ok {
return errors.New("geojson: not a Polygon type")
}
*p = Polygon(polygon)
return nil
} | [
"func",
"(",
"p",
"*",
"Polygon",
")",
"UnmarshalJSON",
"(",
"data",
"[",
"]",
"byte",
")",
"error",
"{",
"g",
":=",
"&",
"Geometry",
"{",
"}",
"\n",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"data",
",",
"&",
"g",
")",
"\n",
"if",
"err",
"!=... | // UnmarshalJSON will unmarshal the GeoJSON Polygon geometry. | [
"UnmarshalJSON",
"will",
"unmarshal",
"the",
"GeoJSON",
"Polygon",
"geometry",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/geojson/geometry.go#L276-L290 | train |
paulmach/orb | clip/clip.go | ring | func ring(box orb.Bound, in orb.Ring) orb.Ring {
var out orb.Ring
if len(in) == 0 {
return in
}
f := in[0]
l := in[len(in)-1]
initClosed := false
if f == l {
initClosed = true
}
for edge := 1; edge <= 8; edge <<= 1 {
out = out[:0]
loopTo := len(in)
// if we're not a nice closed ring, don't implicitly close it.
prev := in[loopTo-1]
if !initClosed {
prev = in[0]
}
prevInside := bitCode(box, prev)&edge == 0
for i := 0; i < loopTo; i++ {
p := in[i]
inside := bitCode(box, p)&edge == 0
// if segment goes through the clip window, add an intersection
if inside != prevInside {
i := intersect(box, edge, prev, p)
out = append(out, i)
}
if inside {
out = append(out, p)
}
prev = p
prevInside = inside
}
if len(out) == 0 {
return nil
}
in, out = out, in
}
out = in // swap back
if initClosed {
// need to make sure our output is also closed.
if l := len(out); l != 0 {
f := out[0]
l := out[l-1]
if f != l {
out = append(out, f)
}
}
}
return out
} | go | func ring(box orb.Bound, in orb.Ring) orb.Ring {
var out orb.Ring
if len(in) == 0 {
return in
}
f := in[0]
l := in[len(in)-1]
initClosed := false
if f == l {
initClosed = true
}
for edge := 1; edge <= 8; edge <<= 1 {
out = out[:0]
loopTo := len(in)
// if we're not a nice closed ring, don't implicitly close it.
prev := in[loopTo-1]
if !initClosed {
prev = in[0]
}
prevInside := bitCode(box, prev)&edge == 0
for i := 0; i < loopTo; i++ {
p := in[i]
inside := bitCode(box, p)&edge == 0
// if segment goes through the clip window, add an intersection
if inside != prevInside {
i := intersect(box, edge, prev, p)
out = append(out, i)
}
if inside {
out = append(out, p)
}
prev = p
prevInside = inside
}
if len(out) == 0 {
return nil
}
in, out = out, in
}
out = in // swap back
if initClosed {
// need to make sure our output is also closed.
if l := len(out); l != 0 {
f := out[0]
l := out[l-1]
if f != l {
out = append(out, f)
}
}
}
return out
} | [
"func",
"ring",
"(",
"box",
"orb",
".",
"Bound",
",",
"in",
"orb",
".",
"Ring",
")",
"orb",
".",
"Ring",
"{",
"var",
"out",
"orb",
".",
"Ring",
"\n",
"if",
"len",
"(",
"in",
")",
"==",
"0",
"{",
"return",
"in",
"\n",
"}",
"\n\n",
"f",
":=",
... | // ring will clip the Ring into a smaller ring around the bounding box boundary. | [
"ring",
"will",
"clip",
"the",
"Ring",
"into",
"a",
"smaller",
"ring",
"around",
"the",
"bounding",
"box",
"boundary",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/clip/clip.go#L85-L150 | train |
paulmach/orb | clip/clip.go | intersect | func intersect(box orb.Bound, edge int, a, b orb.Point) orb.Point {
if edge&8 != 0 {
// top
return orb.Point{a[0] + (b[0]-a[0])*(box.Max[1]-a[1])/(b[1]-a[1]), box.Max[1]}
} else if edge&4 != 0 {
// bottom
return orb.Point{a[0] + (b[0]-a[0])*(box.Min[1]-a[1])/(b[1]-a[1]), box.Min[1]}
} else if edge&2 != 0 {
// right
return orb.Point{box.Max[0], a[1] + (b[1]-a[1])*(box.Max[0]-a[0])/(b[0]-a[0])}
} else if edge&1 != 0 {
// left
return orb.Point{box.Min[0], a[1] + (b[1]-a[1])*(box.Min[0]-a[0])/(b[0]-a[0])}
}
panic("no edge??")
} | go | func intersect(box orb.Bound, edge int, a, b orb.Point) orb.Point {
if edge&8 != 0 {
// top
return orb.Point{a[0] + (b[0]-a[0])*(box.Max[1]-a[1])/(b[1]-a[1]), box.Max[1]}
} else if edge&4 != 0 {
// bottom
return orb.Point{a[0] + (b[0]-a[0])*(box.Min[1]-a[1])/(b[1]-a[1]), box.Min[1]}
} else if edge&2 != 0 {
// right
return orb.Point{box.Max[0], a[1] + (b[1]-a[1])*(box.Max[0]-a[0])/(b[0]-a[0])}
} else if edge&1 != 0 {
// left
return orb.Point{box.Min[0], a[1] + (b[1]-a[1])*(box.Min[0]-a[0])/(b[0]-a[0])}
}
panic("no edge??")
} | [
"func",
"intersect",
"(",
"box",
"orb",
".",
"Bound",
",",
"edge",
"int",
",",
"a",
",",
"b",
"orb",
".",
"Point",
")",
"orb",
".",
"Point",
"{",
"if",
"edge",
"&",
"8",
"!=",
"0",
"{",
"// top",
"return",
"orb",
".",
"Point",
"{",
"a",
"[",
... | // intersect a segment against one of the 4 lines that make up the bbox | [
"intersect",
"a",
"segment",
"against",
"one",
"of",
"the",
"4",
"lines",
"that",
"make",
"up",
"the",
"bbox"
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/clip/clip.go#L192-L208 | train |
paulmach/orb | simplify/visvalingam.go | Visvalingam | func Visvalingam(threshold float64, minPointsToKeep int) *VisvalingamSimplifier {
return &VisvalingamSimplifier{
Threshold: threshold,
ToKeep: minPointsToKeep,
}
} | go | func Visvalingam(threshold float64, minPointsToKeep int) *VisvalingamSimplifier {
return &VisvalingamSimplifier{
Threshold: threshold,
ToKeep: minPointsToKeep,
}
} | [
"func",
"Visvalingam",
"(",
"threshold",
"float64",
",",
"minPointsToKeep",
"int",
")",
"*",
"VisvalingamSimplifier",
"{",
"return",
"&",
"VisvalingamSimplifier",
"{",
"Threshold",
":",
"threshold",
",",
"ToKeep",
":",
"minPointsToKeep",
",",
"}",
"\n",
"}"
] | // Visvalingam creates a new VisvalingamSimplifier. | [
"Visvalingam",
"creates",
"a",
"new",
"VisvalingamSimplifier",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/simplify/visvalingam.go#L19-L24 | train |
paulmach/orb | multi_point.go | Clone | func (mp MultiPoint) Clone() MultiPoint {
if mp == nil {
return nil
}
points := make([]Point, len(mp))
copy(points, mp)
return MultiPoint(points)
} | go | func (mp MultiPoint) Clone() MultiPoint {
if mp == nil {
return nil
}
points := make([]Point, len(mp))
copy(points, mp)
return MultiPoint(points)
} | [
"func",
"(",
"mp",
"MultiPoint",
")",
"Clone",
"(",
")",
"MultiPoint",
"{",
"if",
"mp",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"points",
":=",
"make",
"(",
"[",
"]",
"Point",
",",
"len",
"(",
"mp",
")",
")",
"\n",
"copy",
"(",
"p... | // Clone returns a new copy of the points. | [
"Clone",
"returns",
"a",
"new",
"copy",
"of",
"the",
"points",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/multi_point.go#L17-L26 | train |
paulmach/orb | multi_point.go | Bound | func (mp MultiPoint) Bound() Bound {
if len(mp) == 0 {
return emptyBound
}
b := Bound{mp[0], mp[0]}
for _, p := range mp {
b = b.Extend(p)
}
return b
} | go | func (mp MultiPoint) Bound() Bound {
if len(mp) == 0 {
return emptyBound
}
b := Bound{mp[0], mp[0]}
for _, p := range mp {
b = b.Extend(p)
}
return b
} | [
"func",
"(",
"mp",
"MultiPoint",
")",
"Bound",
"(",
")",
"Bound",
"{",
"if",
"len",
"(",
"mp",
")",
"==",
"0",
"{",
"return",
"emptyBound",
"\n",
"}",
"\n\n",
"b",
":=",
"Bound",
"{",
"mp",
"[",
"0",
"]",
",",
"mp",
"[",
"0",
"]",
"}",
"\n",
... | // Bound returns a bound around the points. Uses rectangular coordinates. | [
"Bound",
"returns",
"a",
"bound",
"around",
"the",
"points",
".",
"Uses",
"rectangular",
"coordinates",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/multi_point.go#L29-L40 | train |
paulmach/orb | multi_point.go | Equal | func (mp MultiPoint) Equal(multiPoint MultiPoint) bool {
if len(mp) != len(multiPoint) {
return false
}
for i := range mp {
if !mp[i].Equal(multiPoint[i]) {
return false
}
}
return true
} | go | func (mp MultiPoint) Equal(multiPoint MultiPoint) bool {
if len(mp) != len(multiPoint) {
return false
}
for i := range mp {
if !mp[i].Equal(multiPoint[i]) {
return false
}
}
return true
} | [
"func",
"(",
"mp",
"MultiPoint",
")",
"Equal",
"(",
"multiPoint",
"MultiPoint",
")",
"bool",
"{",
"if",
"len",
"(",
"mp",
")",
"!=",
"len",
"(",
"multiPoint",
")",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"for",
"i",
":=",
"range",
"mp",
"{",
"if... | // Equal compares two MultiPoint objects. Returns true if lengths are the same
// and all points are Equal, and in the same order. | [
"Equal",
"compares",
"two",
"MultiPoint",
"objects",
".",
"Returns",
"true",
"if",
"lengths",
"are",
"the",
"same",
"and",
"all",
"points",
"are",
"Equal",
"and",
"in",
"the",
"same",
"order",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/multi_point.go#L44-L56 | train |
paulmach/orb | ring.go | Orientation | func (r Ring) Orientation() Orientation {
area := 0.0
// This is a fast planar area computation, which is okay for this use.
// implicitly move everything to near the origin to help with roundoff
offsetX := r[0][0]
offsetY := r[0][1]
for i := 1; i < len(r)-1; i++ {
area += (r[i][0]-offsetX)*(r[i+1][1]-offsetY) -
(r[i+1][0]-offsetX)*(r[i][1]-offsetY)
}
if area > 0 {
return CCW
}
if area < 0 {
return CW
}
// degenerate case, no area
return 0
} | go | func (r Ring) Orientation() Orientation {
area := 0.0
// This is a fast planar area computation, which is okay for this use.
// implicitly move everything to near the origin to help with roundoff
offsetX := r[0][0]
offsetY := r[0][1]
for i := 1; i < len(r)-1; i++ {
area += (r[i][0]-offsetX)*(r[i+1][1]-offsetY) -
(r[i+1][0]-offsetX)*(r[i][1]-offsetY)
}
if area > 0 {
return CCW
}
if area < 0 {
return CW
}
// degenerate case, no area
return 0
} | [
"func",
"(",
"r",
"Ring",
")",
"Orientation",
"(",
")",
"Orientation",
"{",
"area",
":=",
"0.0",
"\n\n",
"// This is a fast planar area computation, which is okay for this use.",
"// implicitly move everything to near the origin to help with roundoff",
"offsetX",
":=",
"r",
"["... | // Orientation returns 1 if the the ring is in couter-clockwise order,
// return -1 if the ring is the clockwise order and 0 if the ring is
// degenerate and had no area. | [
"Orientation",
"returns",
"1",
"if",
"the",
"the",
"ring",
"is",
"in",
"couter",
"-",
"clockwise",
"order",
"return",
"-",
"1",
"if",
"the",
"ring",
"is",
"the",
"clockwise",
"order",
"and",
"0",
"if",
"the",
"ring",
"is",
"degenerate",
"and",
"had",
"... | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/ring.go#L38-L60 | train |
paulmach/orb | ring.go | Equal | func (r Ring) Equal(ring Ring) bool {
return MultiPoint(r).Equal(MultiPoint(ring))
} | go | func (r Ring) Equal(ring Ring) bool {
return MultiPoint(r).Equal(MultiPoint(ring))
} | [
"func",
"(",
"r",
"Ring",
")",
"Equal",
"(",
"ring",
"Ring",
")",
"bool",
"{",
"return",
"MultiPoint",
"(",
"r",
")",
".",
"Equal",
"(",
"MultiPoint",
"(",
"ring",
")",
")",
"\n",
"}"
] | // Equal compares two rings. Returns true if lengths are the same
// and all points are Equal. | [
"Equal",
"compares",
"two",
"rings",
".",
"Returns",
"true",
"if",
"lengths",
"are",
"the",
"same",
"and",
"all",
"points",
"are",
"Equal",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/ring.go#L64-L66 | train |
paulmach/orb | ring.go | Clone | func (r Ring) Clone() Ring {
if r == nil {
return nil
}
ps := MultiPoint(r)
return Ring(ps.Clone())
} | go | func (r Ring) Clone() Ring {
if r == nil {
return nil
}
ps := MultiPoint(r)
return Ring(ps.Clone())
} | [
"func",
"(",
"r",
"Ring",
")",
"Clone",
"(",
")",
"Ring",
"{",
"if",
"r",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"ps",
":=",
"MultiPoint",
"(",
"r",
")",
"\n",
"return",
"Ring",
"(",
"ps",
".",
"Clone",
"(",
")",
")",
"\n",
"}"... | // Clone returns a new copy of the ring. | [
"Clone",
"returns",
"a",
"new",
"copy",
"of",
"the",
"ring",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/ring.go#L69-L76 | train |
paulmach/orb | geojson/properties.go | Clone | func (p Properties) Clone() Properties {
n := make(Properties, len(p))
for k, v := range p {
n[k] = v
}
return n
} | go | func (p Properties) Clone() Properties {
n := make(Properties, len(p))
for k, v := range p {
n[k] = v
}
return n
} | [
"func",
"(",
"p",
"Properties",
")",
"Clone",
"(",
")",
"Properties",
"{",
"n",
":=",
"make",
"(",
"Properties",
",",
"len",
"(",
"p",
")",
")",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"p",
"{",
"n",
"[",
"k",
"]",
"=",
"v",
"\n",
"}",
"... | // Clone returns a shallow copy of the properties. | [
"Clone",
"returns",
"a",
"shallow",
"copy",
"of",
"the",
"properties",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/geojson/properties.go#L105-L112 | train |
paulmach/orb | planar/distance_from.go | DistanceFrom | func DistanceFrom(g orb.Geometry, p orb.Point) float64 {
d, _ := DistanceFromWithIndex(g, p)
return d
} | go | func DistanceFrom(g orb.Geometry, p orb.Point) float64 {
d, _ := DistanceFromWithIndex(g, p)
return d
} | [
"func",
"DistanceFrom",
"(",
"g",
"orb",
".",
"Geometry",
",",
"p",
"orb",
".",
"Point",
")",
"float64",
"{",
"d",
",",
"_",
":=",
"DistanceFromWithIndex",
"(",
"g",
",",
"p",
")",
"\n",
"return",
"d",
"\n",
"}"
] | // DistanceFrom returns the distance from the boundary of the geometry in
// the units of the geometry. | [
"DistanceFrom",
"returns",
"the",
"distance",
"from",
"the",
"boundary",
"of",
"the",
"geometry",
"in",
"the",
"units",
"of",
"the",
"geometry",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/planar/distance_from.go#L42-L45 | train |
paulmach/orb | planar/distance_from.go | DistanceFromWithIndex | func DistanceFromWithIndex(g orb.Geometry, p orb.Point) (float64, int) {
if g == nil {
return math.Inf(1), -1
}
switch g := g.(type) {
case orb.Point:
return Distance(g, p), 0
case orb.MultiPoint:
return multiPointDistanceFrom(g, p)
case orb.LineString:
return lineStringDistanceFrom(g, p)
case orb.MultiLineString:
dist := math.Inf(1)
index := -1
for i, ls := range g {
if d, _ := lineStringDistanceFrom(ls, p); d < dist {
dist = d
index = i
}
}
return dist, index
case orb.Ring:
return lineStringDistanceFrom(orb.LineString(g), p)
case orb.Polygon:
return polygonDistanceFrom(g, p)
case orb.MultiPolygon:
dist := math.Inf(1)
index := -1
for i, poly := range g {
if d, _ := polygonDistanceFrom(poly, p); d < dist {
dist = d
index = i
}
}
return dist, index
case orb.Collection:
dist := math.Inf(1)
index := -1
for i, ge := range g {
if d, _ := DistanceFromWithIndex(ge, p); d < dist {
dist = d
index = i
}
}
return dist, index
case orb.Bound:
return DistanceFromWithIndex(g.ToRing(), p)
}
panic(fmt.Sprintf("geometry type not supported: %T", g))
} | go | func DistanceFromWithIndex(g orb.Geometry, p orb.Point) (float64, int) {
if g == nil {
return math.Inf(1), -1
}
switch g := g.(type) {
case orb.Point:
return Distance(g, p), 0
case orb.MultiPoint:
return multiPointDistanceFrom(g, p)
case orb.LineString:
return lineStringDistanceFrom(g, p)
case orb.MultiLineString:
dist := math.Inf(1)
index := -1
for i, ls := range g {
if d, _ := lineStringDistanceFrom(ls, p); d < dist {
dist = d
index = i
}
}
return dist, index
case orb.Ring:
return lineStringDistanceFrom(orb.LineString(g), p)
case orb.Polygon:
return polygonDistanceFrom(g, p)
case orb.MultiPolygon:
dist := math.Inf(1)
index := -1
for i, poly := range g {
if d, _ := polygonDistanceFrom(poly, p); d < dist {
dist = d
index = i
}
}
return dist, index
case orb.Collection:
dist := math.Inf(1)
index := -1
for i, ge := range g {
if d, _ := DistanceFromWithIndex(ge, p); d < dist {
dist = d
index = i
}
}
return dist, index
case orb.Bound:
return DistanceFromWithIndex(g.ToRing(), p)
}
panic(fmt.Sprintf("geometry type not supported: %T", g))
} | [
"func",
"DistanceFromWithIndex",
"(",
"g",
"orb",
".",
"Geometry",
",",
"p",
"orb",
".",
"Point",
")",
"(",
"float64",
",",
"int",
")",
"{",
"if",
"g",
"==",
"nil",
"{",
"return",
"math",
".",
"Inf",
"(",
"1",
")",
",",
"-",
"1",
"\n",
"}",
"\n... | // DistanceFromWithIndex returns the minimum euclidean distance
// from the boundary of the geometry plus the index of the sub-geometry
// that was the match. | [
"DistanceFromWithIndex",
"returns",
"the",
"minimum",
"euclidean",
"distance",
"from",
"the",
"boundary",
"of",
"the",
"geometry",
"plus",
"the",
"index",
"of",
"the",
"sub",
"-",
"geometry",
"that",
"was",
"the",
"match",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/planar/distance_from.go#L50-L104 | train |
paulmach/orb | point.go | Equal | func (p Point) Equal(point Point) bool {
return p[0] == point[0] && p[1] == point[1]
} | go | func (p Point) Equal(point Point) bool {
return p[0] == point[0] && p[1] == point[1]
} | [
"func",
"(",
"p",
"Point",
")",
"Equal",
"(",
"point",
"Point",
")",
"bool",
"{",
"return",
"p",
"[",
"0",
"]",
"==",
"point",
"[",
"0",
"]",
"&&",
"p",
"[",
"1",
"]",
"==",
"point",
"[",
"1",
"]",
"\n",
"}"
] | // Equal checks if the point represents the same point or vector. | [
"Equal",
"checks",
"if",
"the",
"point",
"represents",
"the",
"same",
"point",
"or",
"vector",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/point.go#L49-L51 | train |
paulmach/orb | project/helpers.go | Geometry | func Geometry(g orb.Geometry, proj orb.Projection) orb.Geometry {
if g == nil {
return nil
}
switch g := g.(type) {
case orb.Point:
return Point(g, proj)
case orb.MultiPoint:
return MultiPoint(g, proj)
case orb.LineString:
return LineString(g, proj)
case orb.MultiLineString:
return MultiLineString(g, proj)
case orb.Ring:
return Ring(g, proj)
case orb.Polygon:
return Polygon(g, proj)
case orb.MultiPolygon:
return MultiPolygon(g, proj)
case orb.Collection:
return Collection(g, proj)
case orb.Bound:
return Bound(g, proj)
}
panic("geometry type not supported")
} | go | func Geometry(g orb.Geometry, proj orb.Projection) orb.Geometry {
if g == nil {
return nil
}
switch g := g.(type) {
case orb.Point:
return Point(g, proj)
case orb.MultiPoint:
return MultiPoint(g, proj)
case orb.LineString:
return LineString(g, proj)
case orb.MultiLineString:
return MultiLineString(g, proj)
case orb.Ring:
return Ring(g, proj)
case orb.Polygon:
return Polygon(g, proj)
case orb.MultiPolygon:
return MultiPolygon(g, proj)
case orb.Collection:
return Collection(g, proj)
case orb.Bound:
return Bound(g, proj)
}
panic("geometry type not supported")
} | [
"func",
"Geometry",
"(",
"g",
"orb",
".",
"Geometry",
",",
"proj",
"orb",
".",
"Projection",
")",
"orb",
".",
"Geometry",
"{",
"if",
"g",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"switch",
"g",
":=",
"g",
".",
"(",
"type",
")",
"{",
... | // Geometry is a helper to project any geomtry. | [
"Geometry",
"is",
"a",
"helper",
"to",
"project",
"any",
"geomtry",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/project/helpers.go#L8-L35 | train |
paulmach/orb | project/helpers.go | Point | func Point(p orb.Point, proj orb.Projection) orb.Point {
return proj(p)
} | go | func Point(p orb.Point, proj orb.Projection) orb.Point {
return proj(p)
} | [
"func",
"Point",
"(",
"p",
"orb",
".",
"Point",
",",
"proj",
"orb",
".",
"Projection",
")",
"orb",
".",
"Point",
"{",
"return",
"proj",
"(",
"p",
")",
"\n",
"}"
] | // Point is a helper to project an a point | [
"Point",
"is",
"a",
"helper",
"to",
"project",
"an",
"a",
"point"
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/project/helpers.go#L38-L40 | train |
paulmach/orb | project/helpers.go | MultiPoint | func MultiPoint(mp orb.MultiPoint, proj orb.Projection) orb.MultiPoint {
for i := range mp {
mp[i] = proj(mp[i])
}
return mp
} | go | func MultiPoint(mp orb.MultiPoint, proj orb.Projection) orb.MultiPoint {
for i := range mp {
mp[i] = proj(mp[i])
}
return mp
} | [
"func",
"MultiPoint",
"(",
"mp",
"orb",
".",
"MultiPoint",
",",
"proj",
"orb",
".",
"Projection",
")",
"orb",
".",
"MultiPoint",
"{",
"for",
"i",
":=",
"range",
"mp",
"{",
"mp",
"[",
"i",
"]",
"=",
"proj",
"(",
"mp",
"[",
"i",
"]",
")",
"\n",
"... | // MultiPoint is a helper to project an entire multi point. | [
"MultiPoint",
"is",
"a",
"helper",
"to",
"project",
"an",
"entire",
"multi",
"point",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/project/helpers.go#L43-L49 | train |
paulmach/orb | project/helpers.go | LineString | func LineString(ls orb.LineString, proj orb.Projection) orb.LineString {
return orb.LineString(MultiPoint(orb.MultiPoint(ls), proj))
} | go | func LineString(ls orb.LineString, proj orb.Projection) orb.LineString {
return orb.LineString(MultiPoint(orb.MultiPoint(ls), proj))
} | [
"func",
"LineString",
"(",
"ls",
"orb",
".",
"LineString",
",",
"proj",
"orb",
".",
"Projection",
")",
"orb",
".",
"LineString",
"{",
"return",
"orb",
".",
"LineString",
"(",
"MultiPoint",
"(",
"orb",
".",
"MultiPoint",
"(",
"ls",
")",
",",
"proj",
")"... | // LineString is a helper to project an entire line string. | [
"LineString",
"is",
"a",
"helper",
"to",
"project",
"an",
"entire",
"line",
"string",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/project/helpers.go#L52-L54 | train |
paulmach/orb | project/helpers.go | MultiLineString | func MultiLineString(mls orb.MultiLineString, proj orb.Projection) orb.MultiLineString {
for i := range mls {
mls[i] = LineString(mls[i], proj)
}
return mls
} | go | func MultiLineString(mls orb.MultiLineString, proj orb.Projection) orb.MultiLineString {
for i := range mls {
mls[i] = LineString(mls[i], proj)
}
return mls
} | [
"func",
"MultiLineString",
"(",
"mls",
"orb",
".",
"MultiLineString",
",",
"proj",
"orb",
".",
"Projection",
")",
"orb",
".",
"MultiLineString",
"{",
"for",
"i",
":=",
"range",
"mls",
"{",
"mls",
"[",
"i",
"]",
"=",
"LineString",
"(",
"mls",
"[",
"i",
... | // MultiLineString is a helper to project an entire multi linestring. | [
"MultiLineString",
"is",
"a",
"helper",
"to",
"project",
"an",
"entire",
"multi",
"linestring",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/project/helpers.go#L57-L63 | train |
paulmach/orb | project/helpers.go | Ring | func Ring(r orb.Ring, proj orb.Projection) orb.Ring {
return orb.Ring(LineString(orb.LineString(r), proj))
} | go | func Ring(r orb.Ring, proj orb.Projection) orb.Ring {
return orb.Ring(LineString(orb.LineString(r), proj))
} | [
"func",
"Ring",
"(",
"r",
"orb",
".",
"Ring",
",",
"proj",
"orb",
".",
"Projection",
")",
"orb",
".",
"Ring",
"{",
"return",
"orb",
".",
"Ring",
"(",
"LineString",
"(",
"orb",
".",
"LineString",
"(",
"r",
")",
",",
"proj",
")",
")",
"\n",
"}"
] | // Ring is a helper to project an entire ring. | [
"Ring",
"is",
"a",
"helper",
"to",
"project",
"an",
"entire",
"ring",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/project/helpers.go#L66-L68 | train |
paulmach/orb | project/helpers.go | Polygon | func Polygon(p orb.Polygon, proj orb.Projection) orb.Polygon {
for i := range p {
p[i] = Ring(p[i], proj)
}
return p
} | go | func Polygon(p orb.Polygon, proj orb.Projection) orb.Polygon {
for i := range p {
p[i] = Ring(p[i], proj)
}
return p
} | [
"func",
"Polygon",
"(",
"p",
"orb",
".",
"Polygon",
",",
"proj",
"orb",
".",
"Projection",
")",
"orb",
".",
"Polygon",
"{",
"for",
"i",
":=",
"range",
"p",
"{",
"p",
"[",
"i",
"]",
"=",
"Ring",
"(",
"p",
"[",
"i",
"]",
",",
"proj",
")",
"\n",... | // Polygon is a helper to project an entire polygon. | [
"Polygon",
"is",
"a",
"helper",
"to",
"project",
"an",
"entire",
"polygon",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/project/helpers.go#L71-L77 | train |
paulmach/orb | project/helpers.go | MultiPolygon | func MultiPolygon(mp orb.MultiPolygon, proj orb.Projection) orb.MultiPolygon {
for i := range mp {
mp[i] = Polygon(mp[i], proj)
}
return mp
} | go | func MultiPolygon(mp orb.MultiPolygon, proj orb.Projection) orb.MultiPolygon {
for i := range mp {
mp[i] = Polygon(mp[i], proj)
}
return mp
} | [
"func",
"MultiPolygon",
"(",
"mp",
"orb",
".",
"MultiPolygon",
",",
"proj",
"orb",
".",
"Projection",
")",
"orb",
".",
"MultiPolygon",
"{",
"for",
"i",
":=",
"range",
"mp",
"{",
"mp",
"[",
"i",
"]",
"=",
"Polygon",
"(",
"mp",
"[",
"i",
"]",
",",
... | // MultiPolygon is a helper to project an entire multi polygon. | [
"MultiPolygon",
"is",
"a",
"helper",
"to",
"project",
"an",
"entire",
"multi",
"polygon",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/project/helpers.go#L80-L86 | train |
paulmach/orb | project/helpers.go | Collection | func Collection(c orb.Collection, proj orb.Projection) orb.Collection {
for i := range c {
c[i] = Geometry(c[i], proj)
}
return c
} | go | func Collection(c orb.Collection, proj orb.Projection) orb.Collection {
for i := range c {
c[i] = Geometry(c[i], proj)
}
return c
} | [
"func",
"Collection",
"(",
"c",
"orb",
".",
"Collection",
",",
"proj",
"orb",
".",
"Projection",
")",
"orb",
".",
"Collection",
"{",
"for",
"i",
":=",
"range",
"c",
"{",
"c",
"[",
"i",
"]",
"=",
"Geometry",
"(",
"c",
"[",
"i",
"]",
",",
"proj",
... | // Collection is a helper to project a rectangle. | [
"Collection",
"is",
"a",
"helper",
"to",
"project",
"a",
"rectangle",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/project/helpers.go#L89-L95 | train |
paulmach/orb | project/helpers.go | Bound | func Bound(bound orb.Bound, proj orb.Projection) orb.Bound {
min := proj(bound.Min)
return orb.Bound{Min: min, Max: min}.Extend(proj(bound.Max))
} | go | func Bound(bound orb.Bound, proj orb.Projection) orb.Bound {
min := proj(bound.Min)
return orb.Bound{Min: min, Max: min}.Extend(proj(bound.Max))
} | [
"func",
"Bound",
"(",
"bound",
"orb",
".",
"Bound",
",",
"proj",
"orb",
".",
"Projection",
")",
"orb",
".",
"Bound",
"{",
"min",
":=",
"proj",
"(",
"bound",
".",
"Min",
")",
"\n",
"return",
"orb",
".",
"Bound",
"{",
"Min",
":",
"min",
",",
"Max",... | // Bound is a helper to project a rectangle. | [
"Bound",
"is",
"a",
"helper",
"to",
"project",
"a",
"rectangle",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/project/helpers.go#L98-L101 | train |
paulmach/orb | geojson/feature_collection.go | Append | func (fc *FeatureCollection) Append(feature *Feature) *FeatureCollection {
fc.Features = append(fc.Features, feature)
return fc
} | go | func (fc *FeatureCollection) Append(feature *Feature) *FeatureCollection {
fc.Features = append(fc.Features, feature)
return fc
} | [
"func",
"(",
"fc",
"*",
"FeatureCollection",
")",
"Append",
"(",
"feature",
"*",
"Feature",
")",
"*",
"FeatureCollection",
"{",
"fc",
".",
"Features",
"=",
"append",
"(",
"fc",
".",
"Features",
",",
"feature",
")",
"\n",
"return",
"fc",
"\n",
"}"
] | // Append appends a feature to the collection. | [
"Append",
"appends",
"a",
"feature",
"to",
"the",
"collection",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/geojson/feature_collection.go#L31-L34 | train |
paulmach/orb | multi_line_string.go | Bound | func (mls MultiLineString) Bound() Bound {
if len(mls) == 0 {
return emptyBound
}
bound := mls[0].Bound()
for i := 1; i < len(mls); i++ {
bound = bound.Union(mls[i].Bound())
}
return bound
} | go | func (mls MultiLineString) Bound() Bound {
if len(mls) == 0 {
return emptyBound
}
bound := mls[0].Bound()
for i := 1; i < len(mls); i++ {
bound = bound.Union(mls[i].Bound())
}
return bound
} | [
"func",
"(",
"mls",
"MultiLineString",
")",
"Bound",
"(",
")",
"Bound",
"{",
"if",
"len",
"(",
"mls",
")",
"==",
"0",
"{",
"return",
"emptyBound",
"\n",
"}",
"\n\n",
"bound",
":=",
"mls",
"[",
"0",
"]",
".",
"Bound",
"(",
")",
"\n",
"for",
"i",
... | // Bound returns a bound around all the line strings. | [
"Bound",
"returns",
"a",
"bound",
"around",
"all",
"the",
"line",
"strings",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/multi_line_string.go#L17-L28 | train |
paulmach/orb | multi_line_string.go | Equal | func (mls MultiLineString) Equal(multiLineString MultiLineString) bool {
if len(mls) != len(multiLineString) {
return false
}
for i, ls := range mls {
if !ls.Equal(multiLineString[i]) {
return false
}
}
return true
} | go | func (mls MultiLineString) Equal(multiLineString MultiLineString) bool {
if len(mls) != len(multiLineString) {
return false
}
for i, ls := range mls {
if !ls.Equal(multiLineString[i]) {
return false
}
}
return true
} | [
"func",
"(",
"mls",
"MultiLineString",
")",
"Equal",
"(",
"multiLineString",
"MultiLineString",
")",
"bool",
"{",
"if",
"len",
"(",
"mls",
")",
"!=",
"len",
"(",
"multiLineString",
")",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"for",
"i",
",",
"ls",
... | // Equal compares two multi line strings. Returns true if lengths are the same
// and all points are Equal. | [
"Equal",
"compares",
"two",
"multi",
"line",
"strings",
".",
"Returns",
"true",
"if",
"lengths",
"are",
"the",
"same",
"and",
"all",
"points",
"are",
"Equal",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/multi_line_string.go#L32-L44 | train |
paulmach/orb | multi_line_string.go | Clone | func (mls MultiLineString) Clone() MultiLineString {
if mls == nil {
return nil
}
nmls := make(MultiLineString, 0, len(mls))
for _, ls := range mls {
nmls = append(nmls, ls.Clone())
}
return nmls
} | go | func (mls MultiLineString) Clone() MultiLineString {
if mls == nil {
return nil
}
nmls := make(MultiLineString, 0, len(mls))
for _, ls := range mls {
nmls = append(nmls, ls.Clone())
}
return nmls
} | [
"func",
"(",
"mls",
"MultiLineString",
")",
"Clone",
"(",
")",
"MultiLineString",
"{",
"if",
"mls",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"nmls",
":=",
"make",
"(",
"MultiLineString",
",",
"0",
",",
"len",
"(",
"mls",
")",
")",
"\n",
... | // Clone returns a new deep copy of the multi line string. | [
"Clone",
"returns",
"a",
"new",
"deep",
"copy",
"of",
"the",
"multi",
"line",
"string",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/multi_line_string.go#L47-L58 | train |
Subsets and Splits
SQL Console for semeru/code-text-go
Retrieves a limited set of code samples with their languages, with a specific case adjustment for 'Go' language.