id
int32 0
167k
| repo
stringlengths 5
54
| path
stringlengths 4
155
| func_name
stringlengths 1
118
| original_string
stringlengths 52
85.5k
| language
stringclasses 1
value | code
stringlengths 52
85.5k
| code_tokens
sequencelengths 21
1.41k
| docstring
stringlengths 6
2.61k
| docstring_tokens
sequencelengths 3
215
| sha
stringlengths 40
40
| url
stringlengths 85
252
|
---|---|---|---|---|---|---|---|---|---|---|---|
151,000 | 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 |
151,001 | 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",
".",
"(",
"type",
")",
"{",
"case",
"orb",
".",
"Point",
":",
"return",
"multiPointCentroid",
"(",
"orb",
".",
"MultiPoint",
"{",
"g",
"}",
")",
",",
"0",
"\n",
"case",
"orb",
".",
"MultiPoint",
":",
"return",
"multiPointCentroid",
"(",
"g",
")",
",",
"0",
"\n",
"case",
"orb",
".",
"LineString",
":",
"return",
"multiLineStringCentroid",
"(",
"orb",
".",
"MultiLineString",
"{",
"g",
"}",
")",
",",
"0",
"\n",
"case",
"orb",
".",
"MultiLineString",
":",
"return",
"multiLineStringCentroid",
"(",
"g",
")",
",",
"0",
"\n",
"case",
"orb",
".",
"Ring",
":",
"return",
"ringCentroidArea",
"(",
"g",
")",
"\n",
"case",
"orb",
".",
"Polygon",
":",
"return",
"polygonCentroidArea",
"(",
"g",
")",
"\n",
"case",
"orb",
".",
"MultiPolygon",
":",
"return",
"multiPolygonCentroidArea",
"(",
"g",
")",
"\n",
"case",
"orb",
".",
"Collection",
":",
"return",
"collectionCentroidArea",
"(",
"g",
")",
"\n",
"case",
"orb",
".",
"Bound",
":",
"return",
"CentroidArea",
"(",
"g",
".",
"ToRing",
"(",
")",
")",
"\n",
"}",
"\n\n",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"g",
")",
")",
"\n",
"}"
] | // 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",
".",
"Ring",
"area",
"my",
"be",
"negative",
"if",
"it",
"has",
"a",
"clockwise",
"winding",
"orider",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/planar/area.go#L23-L50 |
151,002 | 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 |
151,003 | 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",
"(",
"layers",
")",
")",
",",
"}",
"\n\n",
"for",
"_",
",",
"l",
":=",
"range",
"layers",
"{",
"v",
":=",
"l",
".",
"Version",
"\n",
"e",
":=",
"l",
".",
"Extent",
"\n",
"layer",
":=",
"&",
"vectortile",
".",
"Tile_Layer",
"{",
"Name",
":",
"&",
"l",
".",
"Name",
",",
"Version",
":",
"&",
"v",
",",
"Extent",
":",
"&",
"e",
",",
"Features",
":",
"make",
"(",
"[",
"]",
"*",
"vectortile",
".",
"Tile_Feature",
",",
"0",
",",
"len",
"(",
"l",
".",
"Features",
")",
")",
",",
"}",
"\n\n",
"kve",
":=",
"newKeyValueEncoder",
"(",
")",
"\n",
"for",
"i",
",",
"f",
":=",
"range",
"l",
".",
"Features",
"{",
"t",
",",
"g",
",",
"err",
":=",
"encodeGeometry",
"(",
"f",
".",
"Geometry",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"WithMessage",
"(",
"err",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"l",
".",
"Name",
",",
"i",
")",
")",
"\n",
"}",
"\n\n",
"tags",
",",
"err",
":=",
"encodeProperties",
"(",
"kve",
",",
"f",
".",
"Properties",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"WithMessage",
"(",
"err",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"l",
".",
"Name",
",",
"i",
")",
")",
"\n",
"}",
"\n\n",
"layer",
".",
"Features",
"=",
"append",
"(",
"layer",
".",
"Features",
",",
"&",
"vectortile",
".",
"Tile_Feature",
"{",
"Id",
":",
"convertID",
"(",
"f",
".",
"ID",
")",
",",
"Tags",
":",
"tags",
",",
"Type",
":",
"&",
"t",
",",
"Geometry",
":",
"g",
",",
"}",
")",
"\n",
"}",
"\n\n",
"layer",
".",
"Keys",
"=",
"kve",
".",
"Keys",
"\n",
"layer",
".",
"Values",
"=",
"kve",
".",
"Values",
"\n\n",
"vt",
".",
"Layers",
"=",
"append",
"(",
"vt",
".",
"Layers",
",",
"layer",
")",
"\n",
"}",
"\n\n",
"return",
"proto",
".",
"Marshal",
"(",
"vt",
")",
"\n",
"}"
] | // 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 |
151,004 | 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 |
151,005 | 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",
"return",
"math",
".",
"Sqrt",
"(",
"d0",
"*",
"d0",
"+",
"d1",
"*",
"d1",
")",
"\n",
"}"
] | // 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 |
151,006 | 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",
"return",
"d0",
"*",
"d0",
"+",
"d1",
"*",
"d1",
"\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 |
151,007 | 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",
"]",
")",
"\n",
"radLon",
":=",
"deg2rad",
"(",
"center",
"[",
"0",
"]",
")",
"\n",
"minLat",
":=",
"radLat",
"-",
"radDist",
"\n",
"maxLat",
":=",
"radLat",
"+",
"radDist",
"\n\n",
"var",
"minLon",
",",
"maxLon",
"float64",
"\n",
"if",
"minLat",
">",
"minLatitude",
"&&",
"maxLat",
"<",
"maxLatitude",
"{",
"deltaLon",
":=",
"math",
".",
"Asin",
"(",
"math",
".",
"Sin",
"(",
"radDist",
")",
"/",
"math",
".",
"Cos",
"(",
"radLat",
")",
")",
"\n",
"minLon",
"=",
"radLon",
"-",
"deltaLon",
"\n",
"if",
"minLon",
"<",
"minLongitude",
"{",
"minLon",
"+=",
"2",
"*",
"math",
".",
"Pi",
"\n",
"}",
"\n",
"maxLon",
"=",
"radLon",
"+",
"deltaLon",
"\n",
"if",
"maxLon",
">",
"maxLongitude",
"{",
"maxLon",
"-=",
"2",
"*",
"math",
".",
"Pi",
"\n",
"}",
"\n",
"}",
"else",
"{",
"minLat",
"=",
"math",
".",
"Max",
"(",
"minLat",
",",
"minLatitude",
")",
"\n",
"maxLat",
"=",
"math",
".",
"Min",
"(",
"maxLat",
",",
"maxLatitude",
")",
"\n",
"minLon",
"=",
"minLongitude",
"\n",
"maxLon",
"=",
"maxLongitude",
"\n",
"}",
"\n\n",
"return",
"orb",
".",
"Bound",
"{",
"Min",
":",
"orb",
".",
"Point",
"{",
"rad2deg",
"(",
"minLon",
")",
",",
"rad2deg",
"(",
"minLat",
")",
"}",
",",
"Max",
":",
"orb",
".",
"Point",
"{",
"rad2deg",
"(",
"maxLon",
")",
",",
"rad2deg",
"(",
"maxLat",
")",
"}",
",",
"}",
"\n",
"}"
] | // 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 |
151,008 | 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",
"]",
")",
")",
"\n",
"dx",
"=",
"math",
".",
"Max",
"(",
"dx",
",",
"dy",
"/",
"math",
".",
"Cos",
"(",
"deg2rad",
"(",
"b",
".",
"Min",
"[",
"1",
"]",
")",
")",
")",
"\n\n",
"b",
".",
"Min",
"[",
"0",
"]",
"-=",
"dx",
"\n",
"b",
".",
"Min",
"[",
"1",
"]",
"-=",
"dy",
"\n\n",
"b",
".",
"Max",
"[",
"0",
"]",
"+=",
"dx",
"\n",
"b",
".",
"Max",
"[",
"1",
"]",
"+=",
"dy",
"\n\n",
"b",
".",
"Min",
"[",
"0",
"]",
"=",
"math",
".",
"Max",
"(",
"b",
".",
"Min",
"[",
"0",
"]",
",",
"-",
"180",
")",
"\n",
"b",
".",
"Min",
"[",
"1",
"]",
"=",
"math",
".",
"Max",
"(",
"b",
".",
"Min",
"[",
"1",
"]",
",",
"-",
"90",
")",
"\n\n",
"b",
".",
"Max",
"[",
"0",
"]",
"=",
"math",
".",
"Min",
"(",
"b",
".",
"Max",
"[",
"0",
"]",
",",
"180",
")",
"\n",
"b",
".",
"Max",
"[",
"1",
"]",
"=",
"math",
".",
"Min",
"(",
"b",
".",
"Max",
"[",
"1",
"]",
",",
"90",
")",
"\n\n",
"return",
"b",
"\n",
"}"
] | // 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 |
151,009 | 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",
"[",
"0",
"]",
",",
"c",
"}",
"\n",
"s2",
":=",
"orb",
".",
"Point",
"{",
"b",
".",
"Max",
"[",
"0",
"]",
",",
"c",
"}",
"\n\n",
"return",
"Distance",
"(",
"s1",
",",
"s2",
")",
"\n",
"}"
] | // 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 |
151,010 | 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",
"+",
"0.5",
")",
"*",
"maxtiles",
"\n\n",
"// bound it because we have a top of the world problem",
"siny",
":=",
"math",
".",
"Sin",
"(",
"lat",
"*",
"math",
".",
"Pi",
"/",
"180.0",
")",
"\n\n",
"if",
"siny",
"<",
"-",
"0.9999",
"{",
"y",
"=",
"0",
"\n",
"}",
"else",
"if",
"siny",
">",
"0.9999",
"{",
"y",
"=",
"maxtiles",
"-",
"1",
"\n",
"}",
"else",
"{",
"lat",
"=",
"0.5",
"+",
"0.5",
"*",
"math",
".",
"Log",
"(",
"(",
"1.0",
"+",
"siny",
")",
"/",
"(",
"1.0",
"-",
"siny",
")",
")",
"/",
"(",
"-",
"2",
"*",
"math",
".",
"Pi",
")",
"\n",
"y",
"=",
"lat",
"*",
"maxtiles",
"\n",
"}",
"\n\n",
"return",
"\n",
"}"
] | // 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 |
151,011 | 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",
"/",
"maxtiles",
"-",
"0.5",
")",
"\n",
"lat",
"=",
"2.0",
"*",
"math",
".",
"Atan",
"(",
"math",
".",
"Exp",
"(",
"math",
".",
"Pi",
"-",
"(",
"2",
"*",
"math",
".",
"Pi",
")",
"*",
"(",
"y",
"/",
"maxtiles",
")",
")",
")",
"*",
"(",
"180.0",
"/",
"math",
".",
"Pi",
")",
"-",
"90.0",
"\n\n",
"return",
"lng",
",",
"lat",
"\n",
"}"
] | // 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 |
151,012 | 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",
":",
"if",
"g",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"g",
".",
"Clone",
"(",
")",
"\n",
"case",
"LineString",
":",
"if",
"g",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"g",
".",
"Clone",
"(",
")",
"\n",
"case",
"MultiLineString",
":",
"if",
"g",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"g",
".",
"Clone",
"(",
")",
"\n",
"case",
"Ring",
":",
"if",
"g",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"g",
".",
"Clone",
"(",
")",
"\n",
"case",
"Polygon",
":",
"if",
"g",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"g",
".",
"Clone",
"(",
")",
"\n",
"case",
"MultiPolygon",
":",
"if",
"g",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"g",
".",
"Clone",
"(",
")",
"\n",
"case",
"Collection",
":",
"if",
"g",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"g",
".",
"Clone",
"(",
")",
"\n",
"case",
"Bound",
":",
"return",
"g",
"\n",
"}",
"\n\n",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"g",
")",
")",
"\n",
"}"
] | // 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 |
151,013 | 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",
"(",
")",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"switch",
"g1",
":=",
"g1",
".",
"(",
"type",
")",
"{",
"case",
"Point",
":",
"return",
"g1",
".",
"Equal",
"(",
"g2",
".",
"(",
"Point",
")",
")",
"\n",
"case",
"MultiPoint",
":",
"return",
"g1",
".",
"Equal",
"(",
"g2",
".",
"(",
"MultiPoint",
")",
")",
"\n",
"case",
"LineString",
":",
"return",
"g1",
".",
"Equal",
"(",
"g2",
".",
"(",
"LineString",
")",
")",
"\n",
"case",
"MultiLineString",
":",
"return",
"g1",
".",
"Equal",
"(",
"g2",
".",
"(",
"MultiLineString",
")",
")",
"\n",
"case",
"Ring",
":",
"g2",
",",
"ok",
":=",
"g2",
".",
"(",
"Ring",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"g1",
".",
"Equal",
"(",
"g2",
")",
"\n",
"case",
"Polygon",
":",
"g2",
",",
"ok",
":=",
"g2",
".",
"(",
"Polygon",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"g1",
".",
"Equal",
"(",
"g2",
")",
"\n",
"case",
"MultiPolygon",
":",
"return",
"g1",
".",
"Equal",
"(",
"g2",
".",
"(",
"MultiPolygon",
")",
")",
"\n",
"case",
"Collection",
":",
"return",
"g1",
".",
"Equal",
"(",
"g2",
".",
"(",
"Collection",
")",
")",
"\n",
"case",
"Bound",
":",
"g2",
",",
"ok",
":=",
"g2",
".",
"(",
"Bound",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"g1",
".",
"Equal",
"(",
"g2",
")",
"\n",
"}",
"\n\n",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"g1",
")",
")",
"\n",
"}"
] | // 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 |
151,014 | 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",
")",
">",
"0",
"{",
"f",
"=",
"float64",
"(",
"factor",
"[",
"0",
"]",
")",
"\n",
"}",
"\n\n",
"switch",
"g",
":=",
"g",
".",
"(",
"type",
")",
"{",
"case",
"Point",
":",
"return",
"Point",
"{",
"math",
".",
"Round",
"(",
"g",
"[",
"0",
"]",
"*",
"f",
")",
"/",
"f",
",",
"math",
".",
"Round",
"(",
"g",
"[",
"1",
"]",
"*",
"f",
")",
"/",
"f",
",",
"}",
"\n",
"case",
"MultiPoint",
":",
"if",
"g",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"roundPoints",
"(",
"[",
"]",
"Point",
"(",
"g",
")",
",",
"f",
")",
"\n",
"return",
"g",
"\n",
"case",
"LineString",
":",
"if",
"g",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"roundPoints",
"(",
"[",
"]",
"Point",
"(",
"g",
")",
",",
"f",
")",
"\n",
"return",
"g",
"\n",
"case",
"MultiLineString",
":",
"if",
"g",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"for",
"_",
",",
"ls",
":=",
"range",
"g",
"{",
"roundPoints",
"(",
"[",
"]",
"Point",
"(",
"ls",
")",
",",
"f",
")",
"\n",
"}",
"\n",
"return",
"g",
"\n",
"case",
"Ring",
":",
"if",
"g",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"roundPoints",
"(",
"[",
"]",
"Point",
"(",
"g",
")",
",",
"f",
")",
"\n",
"return",
"g",
"\n",
"case",
"Polygon",
":",
"if",
"g",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"for",
"_",
",",
"r",
":=",
"range",
"g",
"{",
"roundPoints",
"(",
"[",
"]",
"Point",
"(",
"r",
")",
",",
"f",
")",
"\n",
"}",
"\n",
"return",
"g",
"\n",
"case",
"MultiPolygon",
":",
"if",
"g",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"for",
"_",
",",
"p",
":=",
"range",
"g",
"{",
"for",
"_",
",",
"r",
":=",
"range",
"p",
"{",
"roundPoints",
"(",
"[",
"]",
"Point",
"(",
"r",
")",
",",
"f",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"g",
"\n",
"case",
"Collection",
":",
"if",
"g",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"for",
"i",
":=",
"range",
"g",
"{",
"g",
"[",
"i",
"]",
"=",
"Round",
"(",
"g",
"[",
"i",
"]",
",",
"int",
"(",
"f",
")",
")",
"\n",
"}",
"\n",
"return",
"g",
"\n",
"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",
",",
"}",
",",
"}",
"\n",
"}",
"\n\n",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"g",
")",
")",
"\n",
"}"
] | // 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 |
151,015 | 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",
"[",
"1",
"]",
",",
"}",
"\n",
"}"
] | // 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 |
151,016 | 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 |
151,017 | 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",
"return",
"orb",
".",
"Bound",
"{",
"Min",
":",
"orb",
".",
"Point",
"{",
"bb",
"[",
"0",
"]",
",",
"bb",
"[",
"1",
"]",
"}",
",",
"Max",
":",
"orb",
".",
"Point",
"{",
"bb",
"[",
"mid",
"]",
",",
"bb",
"[",
"mid",
"+",
"1",
"]",
"}",
",",
"}",
"\n",
"}"
] | // 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 |
151,018 | 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 |
151,019 | 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",
")",
"\n",
"if",
"g",
"==",
"nil",
"{",
"continue",
"\n",
"}",
"\n\n",
"f",
".",
"Geometry",
"=",
"g",
"\n",
"l",
".",
"Features",
"[",
"count",
"]",
"=",
"f",
"\n",
"count",
"++",
"\n",
"}",
"\n\n",
"l",
".",
"Features",
"=",
"l",
".",
"Features",
"[",
":",
"count",
"]",
"\n",
"}"
] | // 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 |
151,020 | 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",
".",
"Contains",
"(",
"point",
")",
"{",
"return",
"ErrPointOutsideOfBounds",
"\n",
"}",
"\n\n",
"if",
"q",
".",
"root",
"==",
"nil",
"{",
"q",
".",
"root",
"=",
"&",
"node",
"{",
"Value",
":",
"p",
",",
"}",
"\n",
"return",
"nil",
"\n",
"}",
"\n\n",
"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",
"]",
",",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // 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",
"quadtree",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/quadtree/quadtree.go#L53-L78 |
151,021 | 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",
"// figure which child of this internal node the point is in.",
"if",
"cy",
":=",
"(",
"bottom",
"+",
"top",
")",
"/",
"2.0",
";",
"point",
"[",
"1",
"]",
"<=",
"cy",
"{",
"top",
"=",
"cy",
"\n",
"i",
"=",
"2",
"\n",
"}",
"else",
"{",
"bottom",
"=",
"cy",
"\n",
"}",
"\n\n",
"if",
"cx",
":=",
"(",
"left",
"+",
"right",
")",
"/",
"2.0",
";",
"point",
"[",
"0",
"]",
">=",
"cx",
"{",
"left",
"=",
"cx",
"\n",
"i",
"++",
"\n",
"}",
"else",
"{",
"right",
"=",
"cx",
"\n",
"}",
"\n\n",
"if",
"n",
".",
"Children",
"[",
"i",
"]",
"==",
"nil",
"{",
"n",
".",
"Children",
"[",
"i",
"]",
"=",
"&",
"node",
"{",
"Value",
":",
"p",
"}",
"\n",
"return",
"\n",
"}",
"\n\n",
"// 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",
")",
"\n",
"}"
] | // 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 |
151,022 | 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",
"[",
"1",
"]",
"!=",
"nil",
"{",
"i",
"=",
"1",
"\n",
"}",
"else",
"if",
"n",
".",
"Children",
"[",
"2",
"]",
"!=",
"nil",
"{",
"i",
"=",
"2",
"\n",
"}",
"else",
"if",
"n",
".",
"Children",
"[",
"3",
"]",
"!=",
"nil",
"{",
"i",
"=",
"3",
"\n",
"}",
"\n\n",
"if",
"i",
"==",
"-",
"1",
"{",
"n",
".",
"Value",
"=",
"nil",
"\n",
"return",
"\n",
"}",
"\n\n",
"if",
"n",
".",
"Children",
"[",
"i",
"]",
".",
"Value",
"==",
"nil",
"{",
"n",
".",
"Children",
"[",
"i",
"]",
"=",
"nil",
"\n",
"continue",
"\n",
"}",
"\n\n",
"break",
"\n",
"}",
"\n\n",
"n",
".",
"Value",
"=",
"n",
".",
"Children",
"[",
"i",
"]",
".",
"Value",
"\n",
"removeNode",
"(",
"n",
".",
"Children",
"[",
"i",
"]",
")",
"\n",
"}"
] | // 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 |
151,023 | 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",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"var",
"p",
"[",
"]",
"orb",
".",
"Pointer",
"\n",
"if",
"len",
"(",
"buf",
")",
">",
"0",
"{",
"p",
"=",
"buf",
"[",
":",
"0",
"]",
"\n",
"}",
"\n",
"v",
":=",
"&",
"inBoundVisitor",
"{",
"bound",
":",
"&",
"b",
",",
"pointers",
":",
"p",
",",
"filter",
":",
"f",
",",
"}",
"\n\n",
"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",
"]",
",",
")",
"\n\n",
"return",
"v",
".",
"pointers",
"\n",
"}"
] | // 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",
"provided",
"to",
"allow",
"for",
"the",
"reuse",
"of",
"result",
"slice",
"memory",
".",
"This",
"function",
"is",
"thread",
"safe",
".",
"Multiple",
"goroutines",
"can",
"read",
"from",
"a",
"pre",
"-",
"created",
"tree",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/quadtree/quadtree.go#L274-L297 |
151,024 | 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",
":=",
"rayIntersect",
"(",
"point",
",",
"r",
"[",
"0",
"]",
",",
"r",
"[",
"len",
"(",
"r",
")",
"-",
"1",
"]",
")",
"\n",
"if",
"on",
"{",
"return",
"true",
"\n",
"}",
"\n\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"len",
"(",
"r",
")",
"-",
"1",
";",
"i",
"++",
"{",
"inter",
",",
"on",
":=",
"rayIntersect",
"(",
"point",
",",
"r",
"[",
"i",
"]",
",",
"r",
"[",
"i",
"+",
"1",
"]",
")",
"\n",
"if",
"on",
"{",
"return",
"true",
"\n",
"}",
"\n\n",
"if",
"inter",
"{",
"c",
"=",
"!",
"c",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"c",
"\n",
"}"
] | // 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 |
151,025 | 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",
":=",
"1",
";",
"i",
"<",
"len",
"(",
"p",
")",
";",
"i",
"++",
"{",
"if",
"RingContains",
"(",
"p",
"[",
"i",
"]",
",",
"point",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"true",
"\n",
"}"
] | // 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 |
151,026 | 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",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"false",
"\n",
"}"
] | // 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 |
151,027 | 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",
":=",
"resampleEdgeCases",
"(",
"ls",
",",
"totalPoints",
")",
"\n",
"if",
"ret",
"{",
"return",
"ls",
"\n",
"}",
"\n\n",
"// precomputes the total distance and intermediate distances",
"total",
",",
"dists",
":=",
"precomputeDistances",
"(",
"ls",
",",
"df",
")",
"\n",
"return",
"resample",
"(",
"ls",
",",
"dists",
",",
"total",
",",
"totalPoints",
")",
"\n",
"}"
] | // 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 |
151,028 | 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 distance and intermediate distances",
"total",
",",
"dists",
":=",
"precomputeDistances",
"(",
"ls",
",",
"df",
")",
"\n\n",
"totalPoints",
":=",
"int",
"(",
"total",
"/",
"dist",
")",
"+",
"1",
"\n",
"ls",
",",
"ret",
":=",
"resampleEdgeCases",
"(",
"ls",
",",
"totalPoints",
")",
"\n",
"if",
"ret",
"{",
"return",
"ls",
"\n",
"}",
"\n\n",
"return",
"resample",
"(",
"ls",
",",
"dists",
",",
"total",
",",
"totalPoints",
")",
"\n",
"}"
] | // 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 |
151,029 | 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",
"}",
"\n\n",
"// if all the points are the same, treat as special case.",
"equal",
":=",
"true",
"\n",
"for",
"_",
",",
"point",
":=",
"range",
"ls",
"{",
"if",
"!",
"ls",
"[",
"0",
"]",
".",
"Equal",
"(",
"point",
")",
"{",
"equal",
"=",
"false",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"equal",
"{",
"if",
"totalPoints",
">",
"len",
"(",
"ls",
")",
"{",
"// extend to be requested length",
"for",
"len",
"(",
"ls",
")",
"!=",
"totalPoints",
"{",
"ls",
"=",
"append",
"(",
"ls",
",",
"ls",
"[",
"0",
"]",
")",
"\n",
"}",
"\n\n",
"return",
"ls",
",",
"true",
"\n",
"}",
"\n\n",
"// contract to be requested length",
"ls",
"=",
"ls",
"[",
":",
"totalPoints",
"]",
"\n",
"return",
"ls",
",",
"true",
"\n",
"}",
"\n\n",
"return",
"ls",
",",
"false",
"\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",
"cases",
".",
"If",
"return",
"true",
"if",
"one",
"of",
"these",
"edge",
"cases",
"was",
"found",
"and",
"handled",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/resample/line_string.go#L95-L126 |
151,030 | 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",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"d",
"\n",
"}"
] | // 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 |
151,031 | 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",
",",
"geomLength",
"(",
"geom",
")",
")",
")",
"\n\n",
"e",
":=",
"NewEncoder",
"(",
"buf",
")",
"\n",
"if",
"len",
"(",
"byteOrder",
")",
">",
"0",
"{",
"e",
".",
"SetByteOrder",
"(",
"byteOrder",
"[",
"0",
"]",
")",
"\n",
"}",
"\n\n",
"err",
":=",
"e",
".",
"Encode",
"(",
"geom",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"buf",
".",
"Len",
"(",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n\n",
"return",
"buf",
".",
"Bytes",
"(",
")",
",",
"nil",
"\n",
"}"
] | // 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 |
151,032 | 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 |
151,033 | 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 should not write any data. Empty sizes will still",
"// write and empty version of that type.",
"case",
"orb",
".",
"MultiPoint",
":",
"if",
"g",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"case",
"orb",
".",
"LineString",
":",
"if",
"g",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"case",
"orb",
".",
"MultiLineString",
":",
"if",
"g",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"case",
"orb",
".",
"Polygon",
":",
"if",
"g",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"case",
"orb",
".",
"MultiPolygon",
":",
"if",
"g",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"case",
"orb",
".",
"Collection",
":",
"if",
"g",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"// deal with types that are not supported by wkb",
"case",
"orb",
".",
"Ring",
":",
"if",
"g",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"geom",
"=",
"orb",
".",
"Polygon",
"{",
"g",
"}",
"\n",
"case",
"orb",
".",
"Bound",
":",
"geom",
"=",
"g",
".",
"ToPolygon",
"(",
")",
"\n",
"}",
"\n\n",
"var",
"b",
"[",
"]",
"byte",
"\n",
"if",
"e",
".",
"order",
"==",
"binary",
".",
"LittleEndian",
"{",
"b",
"=",
"[",
"]",
"byte",
"{",
"1",
"}",
"\n",
"}",
"else",
"{",
"b",
"=",
"[",
"]",
"byte",
"{",
"0",
"}",
"\n",
"}",
"\n\n",
"_",
",",
"err",
":=",
"e",
".",
"w",
".",
"Write",
"(",
"b",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"e",
".",
"buf",
"==",
"nil",
"{",
"e",
".",
"buf",
"=",
"make",
"(",
"[",
"]",
"byte",
",",
"16",
")",
"\n",
"}",
"\n\n",
"switch",
"g",
":=",
"geom",
".",
"(",
"type",
")",
"{",
"case",
"orb",
".",
"Point",
":",
"return",
"e",
".",
"writePoint",
"(",
"g",
")",
"\n",
"case",
"orb",
".",
"MultiPoint",
":",
"return",
"e",
".",
"writeMultiPoint",
"(",
"g",
")",
"\n",
"case",
"orb",
".",
"LineString",
":",
"return",
"e",
".",
"writeLineString",
"(",
"g",
")",
"\n",
"case",
"orb",
".",
"MultiLineString",
":",
"return",
"e",
".",
"writeMultiLineString",
"(",
"g",
")",
"\n",
"case",
"orb",
".",
"Polygon",
":",
"return",
"e",
".",
"writePolygon",
"(",
"g",
")",
"\n",
"case",
"orb",
".",
"MultiPolygon",
":",
"return",
"e",
".",
"writeMultiPolygon",
"(",
"g",
")",
"\n",
"case",
"orb",
".",
"Collection",
":",
"return",
"e",
".",
"writeCollection",
"(",
"g",
")",
"\n",
"}",
"\n\n",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}"
] | // 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 |
151,034 | 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",
"==",
"io",
".",
"EOF",
"||",
"err",
"==",
"io",
".",
"ErrUnexpectedEOF",
"{",
"return",
"nil",
",",
"ErrNotWKB",
"\n",
"}",
"\n\n",
"return",
"g",
",",
"err",
"\n",
"}"
] | // 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 |
151,035 | 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",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"switch",
"typ",
"{",
"case",
"pointType",
":",
"return",
"readPoint",
"(",
"d",
".",
"r",
",",
"byteOrder",
")",
"\n",
"case",
"multiPointType",
":",
"return",
"readMultiPoint",
"(",
"d",
".",
"r",
",",
"byteOrder",
")",
"\n",
"case",
"lineStringType",
":",
"return",
"readLineString",
"(",
"d",
".",
"r",
",",
"byteOrder",
")",
"\n",
"case",
"multiLineStringType",
":",
"return",
"readMultiLineString",
"(",
"d",
".",
"r",
",",
"byteOrder",
")",
"\n",
"case",
"polygonType",
":",
"return",
"readPolygon",
"(",
"d",
".",
"r",
",",
"byteOrder",
")",
"\n",
"case",
"multiPolygonType",
":",
"return",
"readMultiPolygon",
"(",
"d",
".",
"r",
",",
"byteOrder",
")",
"\n",
"case",
"geometryCollectionType",
":",
"return",
"readCollection",
"(",
"d",
".",
"r",
",",
"byteOrder",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
",",
"ErrUnsupportedGeometry",
"\n",
"}"
] | // 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 |
151,036 | 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",
"+",
"21",
"*",
"len",
"(",
"g",
")",
"\n",
"case",
"orb",
".",
"LineString",
":",
"return",
"9",
"+",
"16",
"*",
"len",
"(",
"g",
")",
"\n",
"case",
"orb",
".",
"MultiLineString",
":",
"sum",
":=",
"0",
"\n",
"for",
"_",
",",
"ls",
":=",
"range",
"g",
"{",
"sum",
"+=",
"9",
"+",
"16",
"*",
"len",
"(",
"ls",
")",
"\n",
"}",
"\n\n",
"return",
"9",
"+",
"sum",
"\n",
"case",
"orb",
".",
"Polygon",
":",
"sum",
":=",
"0",
"\n",
"for",
"_",
",",
"r",
":=",
"range",
"g",
"{",
"sum",
"+=",
"4",
"+",
"16",
"*",
"len",
"(",
"r",
")",
"\n",
"}",
"\n\n",
"return",
"9",
"+",
"sum",
"\n",
"case",
"orb",
".",
"MultiPolygon",
":",
"sum",
":=",
"0",
"\n",
"for",
"_",
",",
"c",
":=",
"range",
"g",
"{",
"sum",
"+=",
"geomLength",
"(",
"c",
")",
"\n",
"}",
"\n\n",
"return",
"9",
"+",
"sum",
"\n",
"case",
"orb",
".",
"Collection",
":",
"sum",
":=",
"0",
"\n",
"for",
"_",
",",
"c",
":=",
"range",
"g",
"{",
"sum",
"+=",
"geomLength",
"(",
"c",
")",
"\n",
"}",
"\n\n",
"return",
"9",
"+",
"sum",
"\n",
"}",
"\n\n",
"return",
"0",
"\n",
"}"
] | // 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 |
151,037 | 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",
"=",
"orb",
".",
"Polygon",
"{",
"g",
"}",
"\n",
"case",
"orb",
".",
"Bound",
":",
"jg",
".",
"Coordinates",
"=",
"g",
".",
"ToPolygon",
"(",
")",
"\n",
"case",
"orb",
".",
"Collection",
":",
"for",
"_",
",",
"c",
":=",
"range",
"g",
"{",
"jg",
".",
"Geometries",
"=",
"append",
"(",
"jg",
".",
"Geometries",
",",
"NewGeometry",
"(",
"c",
")",
")",
"\n",
"}",
"\n",
"jg",
".",
"Type",
"=",
"g",
".",
"GeoJSONType",
"(",
")",
"\n",
"default",
":",
"jg",
".",
"Coordinates",
"=",
"g",
"\n",
"}",
"\n\n",
"if",
"jg",
".",
"Coordinates",
"!=",
"nil",
"{",
"jg",
".",
"Type",
"=",
"jg",
".",
"Coordinates",
".",
"GeoJSONType",
"(",
")",
"\n",
"}",
"\n",
"return",
"jg",
"\n",
"}"
] | // 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 |
151,038 | 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",
",",
"len",
"(",
"g",
".",
"Geometries",
")",
")",
"\n",
"for",
"_",
",",
"geom",
":=",
"range",
"g",
".",
"Geometries",
"{",
"c",
"=",
"append",
"(",
"c",
",",
"geom",
".",
"Geometry",
"(",
")",
")",
"\n",
"}",
"\n",
"return",
"c",
"\n",
"}"
] | // 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 |
151,039 | 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",
"(",
"`null`",
")",
",",
"nil",
"\n",
"}",
"\n\n",
"ng",
":=",
"&",
"jsonGeometryMarshall",
"{",
"}",
"\n",
"switch",
"g",
":=",
"g",
".",
"Coordinates",
".",
"(",
"type",
")",
"{",
"case",
"orb",
".",
"Ring",
":",
"ng",
".",
"Coordinates",
"=",
"orb",
".",
"Polygon",
"{",
"g",
"}",
"\n",
"case",
"orb",
".",
"Bound",
":",
"ng",
".",
"Coordinates",
"=",
"g",
".",
"ToPolygon",
"(",
")",
"\n",
"case",
"orb",
".",
"Collection",
":",
"ng",
".",
"Geometries",
"=",
"make",
"(",
"[",
"]",
"*",
"Geometry",
",",
"0",
",",
"len",
"(",
"g",
")",
")",
"\n",
"for",
"_",
",",
"c",
":=",
"range",
"g",
"{",
"ng",
".",
"Geometries",
"=",
"append",
"(",
"ng",
".",
"Geometries",
",",
"NewGeometry",
"(",
"c",
")",
")",
"\n",
"}",
"\n",
"ng",
".",
"Type",
"=",
"g",
".",
"GeoJSONType",
"(",
")",
"\n",
"default",
":",
"ng",
".",
"Coordinates",
"=",
"g",
"\n",
"}",
"\n\n",
"if",
"ng",
".",
"Coordinates",
"!=",
"nil",
"{",
"ng",
".",
"Type",
"=",
"ng",
".",
"Coordinates",
".",
"GeoJSONType",
"(",
")",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"g",
".",
"Geometries",
")",
">",
"0",
"{",
"ng",
".",
"Geometries",
"=",
"g",
".",
"Geometries",
"\n",
"ng",
".",
"Type",
"=",
"orb",
".",
"Collection",
"{",
"}",
".",
"GeoJSONType",
"(",
")",
"\n",
"}",
"\n",
"return",
"json",
".",
"Marshal",
"(",
"ng",
")",
"\n",
"}"
] | // 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 |
151,040 | 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",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"switch",
"jg",
".",
"Type",
"{",
"case",
"\"",
"\"",
":",
"p",
":=",
"orb",
".",
"Point",
"{",
"}",
"\n",
"err",
"=",
"json",
".",
"Unmarshal",
"(",
"jg",
".",
"Coordinates",
",",
"&",
"p",
")",
"\n",
"g",
".",
"Coordinates",
"=",
"p",
"\n",
"case",
"\"",
"\"",
":",
"mp",
":=",
"orb",
".",
"MultiPoint",
"{",
"}",
"\n",
"err",
"=",
"json",
".",
"Unmarshal",
"(",
"jg",
".",
"Coordinates",
",",
"&",
"mp",
")",
"\n",
"g",
".",
"Coordinates",
"=",
"mp",
"\n",
"case",
"\"",
"\"",
":",
"ls",
":=",
"orb",
".",
"LineString",
"{",
"}",
"\n",
"err",
"=",
"json",
".",
"Unmarshal",
"(",
"jg",
".",
"Coordinates",
",",
"&",
"ls",
")",
"\n",
"g",
".",
"Coordinates",
"=",
"ls",
"\n",
"case",
"\"",
"\"",
":",
"mls",
":=",
"orb",
".",
"MultiLineString",
"{",
"}",
"\n",
"err",
"=",
"json",
".",
"Unmarshal",
"(",
"jg",
".",
"Coordinates",
",",
"&",
"mls",
")",
"\n",
"g",
".",
"Coordinates",
"=",
"mls",
"\n",
"case",
"\"",
"\"",
":",
"p",
":=",
"orb",
".",
"Polygon",
"{",
"}",
"\n",
"err",
"=",
"json",
".",
"Unmarshal",
"(",
"jg",
".",
"Coordinates",
",",
"&",
"p",
")",
"\n",
"g",
".",
"Coordinates",
"=",
"p",
"\n",
"case",
"\"",
"\"",
":",
"mp",
":=",
"orb",
".",
"MultiPolygon",
"{",
"}",
"\n",
"err",
"=",
"json",
".",
"Unmarshal",
"(",
"jg",
".",
"Coordinates",
",",
"&",
"mp",
")",
"\n",
"g",
".",
"Coordinates",
"=",
"mp",
"\n",
"case",
"\"",
"\"",
":",
"g",
".",
"Geometries",
"=",
"jg",
".",
"Geometries",
"\n",
"default",
":",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"err",
"\n",
"}"
] | // 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 |
151,041 | 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 |
151,042 | 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 |
151,043 | 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",
")",
"}",
")",
"\n",
"}"
] | // 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 |
151,044 | 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 |
151,045 | 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",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"polygon",
",",
"ok",
":=",
"g",
".",
"Coordinates",
".",
"(",
"orb",
".",
"Polygon",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"*",
"p",
"=",
"Polygon",
"(",
"polygon",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // 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 |
151,046 | 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",
":=",
"in",
"[",
"0",
"]",
"\n",
"l",
":=",
"in",
"[",
"len",
"(",
"in",
")",
"-",
"1",
"]",
"\n\n",
"initClosed",
":=",
"false",
"\n",
"if",
"f",
"==",
"l",
"{",
"initClosed",
"=",
"true",
"\n",
"}",
"\n\n",
"for",
"edge",
":=",
"1",
";",
"edge",
"<=",
"8",
";",
"edge",
"<<=",
"1",
"{",
"out",
"=",
"out",
"[",
":",
"0",
"]",
"\n\n",
"loopTo",
":=",
"len",
"(",
"in",
")",
"\n\n",
"// if we're not a nice closed ring, don't implicitly close it.",
"prev",
":=",
"in",
"[",
"loopTo",
"-",
"1",
"]",
"\n",
"if",
"!",
"initClosed",
"{",
"prev",
"=",
"in",
"[",
"0",
"]",
"\n",
"}",
"\n\n",
"prevInside",
":=",
"bitCode",
"(",
"box",
",",
"prev",
")",
"&",
"edge",
"==",
"0",
"\n\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"loopTo",
";",
"i",
"++",
"{",
"p",
":=",
"in",
"[",
"i",
"]",
"\n",
"inside",
":=",
"bitCode",
"(",
"box",
",",
"p",
")",
"&",
"edge",
"==",
"0",
"\n\n",
"// if segment goes through the clip window, add an intersection",
"if",
"inside",
"!=",
"prevInside",
"{",
"i",
":=",
"intersect",
"(",
"box",
",",
"edge",
",",
"prev",
",",
"p",
")",
"\n",
"out",
"=",
"append",
"(",
"out",
",",
"i",
")",
"\n",
"}",
"\n",
"if",
"inside",
"{",
"out",
"=",
"append",
"(",
"out",
",",
"p",
")",
"\n",
"}",
"\n\n",
"prev",
"=",
"p",
"\n",
"prevInside",
"=",
"inside",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"out",
")",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"in",
",",
"out",
"=",
"out",
",",
"in",
"\n",
"}",
"\n",
"out",
"=",
"in",
"// swap back",
"\n\n",
"if",
"initClosed",
"{",
"// need to make sure our output is also closed.",
"if",
"l",
":=",
"len",
"(",
"out",
")",
";",
"l",
"!=",
"0",
"{",
"f",
":=",
"out",
"[",
"0",
"]",
"\n",
"l",
":=",
"out",
"[",
"l",
"-",
"1",
"]",
"\n\n",
"if",
"f",
"!=",
"l",
"{",
"out",
"=",
"append",
"(",
"out",
",",
"f",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"out",
"\n",
"}"
] | // 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 |
151,047 | 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",
"[",
"0",
"]",
"+",
"(",
"b",
"[",
"0",
"]",
"-",
"a",
"[",
"0",
"]",
")",
"*",
"(",
"box",
".",
"Max",
"[",
"1",
"]",
"-",
"a",
"[",
"1",
"]",
")",
"/",
"(",
"b",
"[",
"1",
"]",
"-",
"a",
"[",
"1",
"]",
")",
",",
"box",
".",
"Max",
"[",
"1",
"]",
"}",
"\n",
"}",
"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",
"]",
"}",
"\n",
"}",
"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",
"]",
")",
"}",
"\n",
"}",
"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",
"]",
")",
"}",
"\n",
"}",
"\n\n",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}"
] | // 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 |
151,048 | 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 |
151,049 | 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",
"(",
"points",
",",
"mp",
")",
"\n\n",
"return",
"MultiPoint",
"(",
"points",
")",
"\n",
"}"
] | // 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 |
151,050 | 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",
"for",
"_",
",",
"p",
":=",
"range",
"mp",
"{",
"b",
"=",
"b",
".",
"Extend",
"(",
"p",
")",
"\n",
"}",
"\n\n",
"return",
"b",
"\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 |
151,051 | 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",
"!",
"mp",
"[",
"i",
"]",
".",
"Equal",
"(",
"multiPoint",
"[",
"i",
"]",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"true",
"\n",
"}"
] | // 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 |
151,052 | 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",
"[",
"0",
"]",
"[",
"0",
"]",
"\n",
"offsetY",
":=",
"r",
"[",
"0",
"]",
"[",
"1",
"]",
"\n",
"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",
")",
"\n",
"}",
"\n\n",
"if",
"area",
">",
"0",
"{",
"return",
"CCW",
"\n",
"}",
"\n\n",
"if",
"area",
"<",
"0",
"{",
"return",
"CW",
"\n",
"}",
"\n\n",
"// degenerate case, no area",
"return",
"0",
"\n",
"}"
] | // 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",
"no",
"area",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/ring.go#L38-L60 |
151,053 | 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 |
151,054 | 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 |
151,055 | 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",
"}",
"\n\n",
"return",
"n",
"\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 |
151,056 | 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 |
151,057 | 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\n",
"switch",
"g",
":=",
"g",
".",
"(",
"type",
")",
"{",
"case",
"orb",
".",
"Point",
":",
"return",
"Distance",
"(",
"g",
",",
"p",
")",
",",
"0",
"\n",
"case",
"orb",
".",
"MultiPoint",
":",
"return",
"multiPointDistanceFrom",
"(",
"g",
",",
"p",
")",
"\n",
"case",
"orb",
".",
"LineString",
":",
"return",
"lineStringDistanceFrom",
"(",
"g",
",",
"p",
")",
"\n",
"case",
"orb",
".",
"MultiLineString",
":",
"dist",
":=",
"math",
".",
"Inf",
"(",
"1",
")",
"\n",
"index",
":=",
"-",
"1",
"\n",
"for",
"i",
",",
"ls",
":=",
"range",
"g",
"{",
"if",
"d",
",",
"_",
":=",
"lineStringDistanceFrom",
"(",
"ls",
",",
"p",
")",
";",
"d",
"<",
"dist",
"{",
"dist",
"=",
"d",
"\n",
"index",
"=",
"i",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"dist",
",",
"index",
"\n",
"case",
"orb",
".",
"Ring",
":",
"return",
"lineStringDistanceFrom",
"(",
"orb",
".",
"LineString",
"(",
"g",
")",
",",
"p",
")",
"\n",
"case",
"orb",
".",
"Polygon",
":",
"return",
"polygonDistanceFrom",
"(",
"g",
",",
"p",
")",
"\n",
"case",
"orb",
".",
"MultiPolygon",
":",
"dist",
":=",
"math",
".",
"Inf",
"(",
"1",
")",
"\n",
"index",
":=",
"-",
"1",
"\n",
"for",
"i",
",",
"poly",
":=",
"range",
"g",
"{",
"if",
"d",
",",
"_",
":=",
"polygonDistanceFrom",
"(",
"poly",
",",
"p",
")",
";",
"d",
"<",
"dist",
"{",
"dist",
"=",
"d",
"\n",
"index",
"=",
"i",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"dist",
",",
"index",
"\n",
"case",
"orb",
".",
"Collection",
":",
"dist",
":=",
"math",
".",
"Inf",
"(",
"1",
")",
"\n",
"index",
":=",
"-",
"1",
"\n",
"for",
"i",
",",
"ge",
":=",
"range",
"g",
"{",
"if",
"d",
",",
"_",
":=",
"DistanceFromWithIndex",
"(",
"ge",
",",
"p",
")",
";",
"d",
"<",
"dist",
"{",
"dist",
"=",
"d",
"\n",
"index",
"=",
"i",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"dist",
",",
"index",
"\n",
"case",
"orb",
".",
"Bound",
":",
"return",
"DistanceFromWithIndex",
"(",
"g",
".",
"ToRing",
"(",
")",
",",
"p",
")",
"\n",
"}",
"\n\n",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"g",
")",
")",
"\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 |
151,058 | 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 |
151,059 | 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",
")",
"{",
"case",
"orb",
".",
"Point",
":",
"return",
"Point",
"(",
"g",
",",
"proj",
")",
"\n",
"case",
"orb",
".",
"MultiPoint",
":",
"return",
"MultiPoint",
"(",
"g",
",",
"proj",
")",
"\n",
"case",
"orb",
".",
"LineString",
":",
"return",
"LineString",
"(",
"g",
",",
"proj",
")",
"\n",
"case",
"orb",
".",
"MultiLineString",
":",
"return",
"MultiLineString",
"(",
"g",
",",
"proj",
")",
"\n",
"case",
"orb",
".",
"Ring",
":",
"return",
"Ring",
"(",
"g",
",",
"proj",
")",
"\n",
"case",
"orb",
".",
"Polygon",
":",
"return",
"Polygon",
"(",
"g",
",",
"proj",
")",
"\n",
"case",
"orb",
".",
"MultiPolygon",
":",
"return",
"MultiPolygon",
"(",
"g",
",",
"proj",
")",
"\n",
"case",
"orb",
".",
"Collection",
":",
"return",
"Collection",
"(",
"g",
",",
"proj",
")",
"\n",
"case",
"orb",
".",
"Bound",
":",
"return",
"Bound",
"(",
"g",
",",
"proj",
")",
"\n",
"}",
"\n\n",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}"
] | // 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 |
151,060 | 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 |
151,061 | 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",
"}",
"\n\n",
"return",
"mp",
"\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 |
151,062 | 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",
")",
")",
"\n",
"}"
] | // 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 |
151,063 | 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",
"]",
",",
"proj",
")",
"\n",
"}",
"\n\n",
"return",
"mls",
"\n",
"}"
] | // 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 |
151,064 | 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 |
151,065 | 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",
"}",
"\n\n",
"return",
"p",
"\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 |
151,066 | 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",
"]",
",",
"proj",
")",
"\n",
"}",
"\n\n",
"return",
"mp",
"\n",
"}"
] | // 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 |
151,067 | 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",
")",
"\n",
"}",
"\n\n",
"return",
"c",
"\n",
"}"
] | // 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 |
151,068 | 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",
":",
"min",
"}",
".",
"Extend",
"(",
"proj",
"(",
"bound",
".",
"Max",
")",
")",
"\n",
"}"
] | // 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 |
151,069 | 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 |
151,070 | 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",
":=",
"1",
";",
"i",
"<",
"len",
"(",
"mls",
")",
";",
"i",
"++",
"{",
"bound",
"=",
"bound",
".",
"Union",
"(",
"mls",
"[",
"i",
"]",
".",
"Bound",
"(",
")",
")",
"\n",
"}",
"\n\n",
"return",
"bound",
"\n",
"}"
] | // 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 |
151,071 | 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",
":=",
"range",
"mls",
"{",
"if",
"!",
"ls",
".",
"Equal",
"(",
"multiLineString",
"[",
"i",
"]",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"true",
"\n",
"}"
] | // 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 |
151,072 | 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",
"for",
"_",
",",
"ls",
":=",
"range",
"mls",
"{",
"nmls",
"=",
"append",
"(",
"nmls",
",",
"ls",
".",
"Clone",
"(",
")",
")",
"\n",
"}",
"\n\n",
"return",
"nmls",
"\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 |
151,073 | paulmach/orb | encoding/mvt/clip.go | Clip | func (ls Layers) Clip(box orb.Bound) {
for _, l := range ls {
l.Clip(box)
}
} | go | func (ls Layers) Clip(box orb.Bound) {
for _, l := range ls {
l.Clip(box)
}
} | [
"func",
"(",
"ls",
"Layers",
")",
"Clip",
"(",
"box",
"orb",
".",
"Bound",
")",
"{",
"for",
"_",
",",
"l",
":=",
"range",
"ls",
"{",
"l",
".",
"Clip",
"(",
"box",
")",
"\n",
"}",
"\n",
"}"
] | // Clip will clip all geometries in all layers to the given bounds. | [
"Clip",
"will",
"clip",
"all",
"geometries",
"in",
"all",
"layers",
"to",
"the",
"given",
"bounds",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/encoding/mvt/clip.go#L18-L22 |
151,074 | paulmach/orb | encoding/mvt/clip.go | Clip | func (l *Layer) Clip(box orb.Bound) {
for _, f := range l.Features {
g := clip.Geometry(box, f.Geometry)
f.Geometry = g
}
} | go | func (l *Layer) Clip(box orb.Bound) {
for _, f := range l.Features {
g := clip.Geometry(box, f.Geometry)
f.Geometry = g
}
} | [
"func",
"(",
"l",
"*",
"Layer",
")",
"Clip",
"(",
"box",
"orb",
".",
"Bound",
")",
"{",
"for",
"_",
",",
"f",
":=",
"range",
"l",
".",
"Features",
"{",
"g",
":=",
"clip",
".",
"Geometry",
"(",
"box",
",",
"f",
".",
"Geometry",
")",
"\n",
"f",
".",
"Geometry",
"=",
"g",
"\n",
"}",
"\n",
"}"
] | // Clip will clip all geometries in this layer to the given bounds. | [
"Clip",
"will",
"clip",
"all",
"geometries",
"in",
"this",
"layer",
"to",
"the",
"given",
"bounds",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/encoding/mvt/clip.go#L25-L30 |
151,075 | paulmach/orb | clip/smartclip/around_bound.go | aroundBound | func aroundBound(
box orb.Bound,
in orb.Ring,
o orb.Orientation,
) orb.Ring {
if o != orb.CCW && o != orb.CW {
panic("invalid orientation")
}
if len(in) == 0 {
return nil
}
next := nexts[o]
f := in[0]
l := in[len(in)-1]
target := bitCodeOpen(box, f)
current := bitCodeOpen(box, l)
if target == 0 || current == 0 {
panic("endpoints must be outside bound")
}
if current == target {
// endpoints long an edge. Need to figure out what order they're in
// to figure out if we just need to connect them or go all the way around.
points := []*endpoint{
{
Point: f,
Start: true,
Side: pointSide(box, f),
Index: 0,
},
{
Point: l,
Start: false,
Side: pointSide(box, l),
Index: 0,
},
}
se := &sortableEndpoints{
mls: []orb.LineString{orb.LineString(in)},
eps: points,
}
if o == orb.CCW {
sort.Sort(se)
} else {
sort.Sort(sort.Reverse(se))
}
if !points[0].Start {
if f != in[len(in)-1] {
in = append(in, f)
}
return in
}
}
// move to next and go until we're all the way around.
current = next[current]
for target != current {
in = append(in, pointFor(box, current))
current = next[current]
}
// add first point to the end to make it a ring
in = append(in, f)
return in
} | go | func aroundBound(
box orb.Bound,
in orb.Ring,
o orb.Orientation,
) orb.Ring {
if o != orb.CCW && o != orb.CW {
panic("invalid orientation")
}
if len(in) == 0 {
return nil
}
next := nexts[o]
f := in[0]
l := in[len(in)-1]
target := bitCodeOpen(box, f)
current := bitCodeOpen(box, l)
if target == 0 || current == 0 {
panic("endpoints must be outside bound")
}
if current == target {
// endpoints long an edge. Need to figure out what order they're in
// to figure out if we just need to connect them or go all the way around.
points := []*endpoint{
{
Point: f,
Start: true,
Side: pointSide(box, f),
Index: 0,
},
{
Point: l,
Start: false,
Side: pointSide(box, l),
Index: 0,
},
}
se := &sortableEndpoints{
mls: []orb.LineString{orb.LineString(in)},
eps: points,
}
if o == orb.CCW {
sort.Sort(se)
} else {
sort.Sort(sort.Reverse(se))
}
if !points[0].Start {
if f != in[len(in)-1] {
in = append(in, f)
}
return in
}
}
// move to next and go until we're all the way around.
current = next[current]
for target != current {
in = append(in, pointFor(box, current))
current = next[current]
}
// add first point to the end to make it a ring
in = append(in, f)
return in
} | [
"func",
"aroundBound",
"(",
"box",
"orb",
".",
"Bound",
",",
"in",
"orb",
".",
"Ring",
",",
"o",
"orb",
".",
"Orientation",
",",
")",
"orb",
".",
"Ring",
"{",
"if",
"o",
"!=",
"orb",
".",
"CCW",
"&&",
"o",
"!=",
"orb",
".",
"CW",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"in",
")",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"next",
":=",
"nexts",
"[",
"o",
"]",
"\n\n",
"f",
":=",
"in",
"[",
"0",
"]",
"\n",
"l",
":=",
"in",
"[",
"len",
"(",
"in",
")",
"-",
"1",
"]",
"\n\n",
"target",
":=",
"bitCodeOpen",
"(",
"box",
",",
"f",
")",
"\n",
"current",
":=",
"bitCodeOpen",
"(",
"box",
",",
"l",
")",
"\n\n",
"if",
"target",
"==",
"0",
"||",
"current",
"==",
"0",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"current",
"==",
"target",
"{",
"// endpoints long an edge. Need to figure out what order they're in",
"// to figure out if we just need to connect them or go all the way around.",
"points",
":=",
"[",
"]",
"*",
"endpoint",
"{",
"{",
"Point",
":",
"f",
",",
"Start",
":",
"true",
",",
"Side",
":",
"pointSide",
"(",
"box",
",",
"f",
")",
",",
"Index",
":",
"0",
",",
"}",
",",
"{",
"Point",
":",
"l",
",",
"Start",
":",
"false",
",",
"Side",
":",
"pointSide",
"(",
"box",
",",
"l",
")",
",",
"Index",
":",
"0",
",",
"}",
",",
"}",
"\n\n",
"se",
":=",
"&",
"sortableEndpoints",
"{",
"mls",
":",
"[",
"]",
"orb",
".",
"LineString",
"{",
"orb",
".",
"LineString",
"(",
"in",
")",
"}",
",",
"eps",
":",
"points",
",",
"}",
"\n\n",
"if",
"o",
"==",
"orb",
".",
"CCW",
"{",
"sort",
".",
"Sort",
"(",
"se",
")",
"\n",
"}",
"else",
"{",
"sort",
".",
"Sort",
"(",
"sort",
".",
"Reverse",
"(",
"se",
")",
")",
"\n",
"}",
"\n\n",
"if",
"!",
"points",
"[",
"0",
"]",
".",
"Start",
"{",
"if",
"f",
"!=",
"in",
"[",
"len",
"(",
"in",
")",
"-",
"1",
"]",
"{",
"in",
"=",
"append",
"(",
"in",
",",
"f",
")",
"\n",
"}",
"\n",
"return",
"in",
"\n",
"}",
"\n",
"}",
"\n\n",
"// move to next and go until we're all the way around.",
"current",
"=",
"next",
"[",
"current",
"]",
"\n",
"for",
"target",
"!=",
"current",
"{",
"in",
"=",
"append",
"(",
"in",
",",
"pointFor",
"(",
"box",
",",
"current",
")",
")",
"\n",
"current",
"=",
"next",
"[",
"current",
"]",
"\n",
"}",
"\n\n",
"// add first point to the end to make it a ring",
"in",
"=",
"append",
"(",
"in",
",",
"f",
")",
"\n",
"return",
"in",
"\n",
"}"
] | // aroundBound will connect the endpoints of the linestring provided
// by wrapping the line around the bounds in the direction provided.
// Will append to the input. | [
"aroundBound",
"will",
"connect",
"the",
"endpoints",
"of",
"the",
"linestring",
"provided",
"by",
"wrapping",
"the",
"line",
"around",
"the",
"bounds",
"in",
"the",
"direction",
"provided",
".",
"Will",
"append",
"to",
"the",
"input",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/clip/smartclip/around_bound.go#L12-L84 |
151,076 | paulmach/orb | clip/smartclip/around_bound.go | pointFor | func pointFor(b orb.Bound, code int) orb.Point {
switch code {
case 1:
return orb.Point{b.Min[0], (b.Max[1] + b.Min[1]) / 2}
case 2:
return orb.Point{b.Max[0], (b.Max[1] + b.Min[1]) / 2}
case 4:
return orb.Point{(b.Max[0] + b.Min[0]) / 2, b.Min[1]}
case 5:
return orb.Point{b.Min[0], b.Min[1]}
case 6:
return orb.Point{b.Max[0], b.Min[1]}
case 8:
return orb.Point{(b.Max[0] + b.Min[0]) / 2, b.Max[1]}
case 9:
return orb.Point{b.Min[0], b.Max[1]}
case 10:
return orb.Point{b.Max[0], b.Max[1]}
}
panic("invalid code")
} | go | func pointFor(b orb.Bound, code int) orb.Point {
switch code {
case 1:
return orb.Point{b.Min[0], (b.Max[1] + b.Min[1]) / 2}
case 2:
return orb.Point{b.Max[0], (b.Max[1] + b.Min[1]) / 2}
case 4:
return orb.Point{(b.Max[0] + b.Min[0]) / 2, b.Min[1]}
case 5:
return orb.Point{b.Min[0], b.Min[1]}
case 6:
return orb.Point{b.Max[0], b.Min[1]}
case 8:
return orb.Point{(b.Max[0] + b.Min[0]) / 2, b.Max[1]}
case 9:
return orb.Point{b.Min[0], b.Max[1]}
case 10:
return orb.Point{b.Max[0], b.Max[1]}
}
panic("invalid code")
} | [
"func",
"pointFor",
"(",
"b",
"orb",
".",
"Bound",
",",
"code",
"int",
")",
"orb",
".",
"Point",
"{",
"switch",
"code",
"{",
"case",
"1",
":",
"return",
"orb",
".",
"Point",
"{",
"b",
".",
"Min",
"[",
"0",
"]",
",",
"(",
"b",
".",
"Max",
"[",
"1",
"]",
"+",
"b",
".",
"Min",
"[",
"1",
"]",
")",
"/",
"2",
"}",
"\n",
"case",
"2",
":",
"return",
"orb",
".",
"Point",
"{",
"b",
".",
"Max",
"[",
"0",
"]",
",",
"(",
"b",
".",
"Max",
"[",
"1",
"]",
"+",
"b",
".",
"Min",
"[",
"1",
"]",
")",
"/",
"2",
"}",
"\n",
"case",
"4",
":",
"return",
"orb",
".",
"Point",
"{",
"(",
"b",
".",
"Max",
"[",
"0",
"]",
"+",
"b",
".",
"Min",
"[",
"0",
"]",
")",
"/",
"2",
",",
"b",
".",
"Min",
"[",
"1",
"]",
"}",
"\n",
"case",
"5",
":",
"return",
"orb",
".",
"Point",
"{",
"b",
".",
"Min",
"[",
"0",
"]",
",",
"b",
".",
"Min",
"[",
"1",
"]",
"}",
"\n",
"case",
"6",
":",
"return",
"orb",
".",
"Point",
"{",
"b",
".",
"Max",
"[",
"0",
"]",
",",
"b",
".",
"Min",
"[",
"1",
"]",
"}",
"\n",
"case",
"8",
":",
"return",
"orb",
".",
"Point",
"{",
"(",
"b",
".",
"Max",
"[",
"0",
"]",
"+",
"b",
".",
"Min",
"[",
"0",
"]",
")",
"/",
"2",
",",
"b",
".",
"Max",
"[",
"1",
"]",
"}",
"\n",
"case",
"9",
":",
"return",
"orb",
".",
"Point",
"{",
"b",
".",
"Min",
"[",
"0",
"]",
",",
"b",
".",
"Max",
"[",
"1",
"]",
"}",
"\n",
"case",
"10",
":",
"return",
"orb",
".",
"Point",
"{",
"b",
".",
"Max",
"[",
"0",
"]",
",",
"b",
".",
"Max",
"[",
"1",
"]",
"}",
"\n",
"}",
"\n\n",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}"
] | // pointFor returns a representative point for the side of the given bitCode. | [
"pointFor",
"returns",
"a",
"representative",
"point",
"for",
"the",
"side",
"of",
"the",
"given",
"bitCode",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/clip/smartclip/around_bound.go#L110-L131 |
151,077 | paulmach/orb | line_string.go | Reverse | func (ls LineString) Reverse() {
l := len(ls) - 1
for i := 0; i <= l/2; i++ {
ls[i], ls[l-i] = ls[l-i], ls[i]
}
} | go | func (ls LineString) Reverse() {
l := len(ls) - 1
for i := 0; i <= l/2; i++ {
ls[i], ls[l-i] = ls[l-i], ls[i]
}
} | [
"func",
"(",
"ls",
"LineString",
")",
"Reverse",
"(",
")",
"{",
"l",
":=",
"len",
"(",
"ls",
")",
"-",
"1",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<=",
"l",
"/",
"2",
";",
"i",
"++",
"{",
"ls",
"[",
"i",
"]",
",",
"ls",
"[",
"l",
"-",
"i",
"]",
"=",
"ls",
"[",
"l",
"-",
"i",
"]",
",",
"ls",
"[",
"i",
"]",
"\n",
"}",
"\n",
"}"
] | // Reverse will reverse the line string.
// This is done inplace, ie. it modifies the original data. | [
"Reverse",
"will",
"reverse",
"the",
"line",
"string",
".",
"This",
"is",
"done",
"inplace",
"ie",
".",
"it",
"modifies",
"the",
"original",
"data",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/line_string.go#L18-L23 |
151,078 | paulmach/orb | line_string.go | Equal | func (ls LineString) Equal(lineString LineString) bool {
return MultiPoint(ls).Equal(MultiPoint(lineString))
} | go | func (ls LineString) Equal(lineString LineString) bool {
return MultiPoint(ls).Equal(MultiPoint(lineString))
} | [
"func",
"(",
"ls",
"LineString",
")",
"Equal",
"(",
"lineString",
"LineString",
")",
"bool",
"{",
"return",
"MultiPoint",
"(",
"ls",
")",
".",
"Equal",
"(",
"MultiPoint",
"(",
"lineString",
")",
")",
"\n",
"}"
] | // Equal compares two line strings. Returns true if lengths are the same
// and all points are Equal. | [
"Equal",
"compares",
"two",
"line",
"strings",
".",
"Returns",
"true",
"if",
"lengths",
"are",
"the",
"same",
"and",
"all",
"points",
"are",
"Equal",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/line_string.go#L32-L34 |
151,079 | paulmach/orb | line_string.go | Clone | func (ls LineString) Clone() LineString {
ps := MultiPoint(ls)
return LineString(ps.Clone())
} | go | func (ls LineString) Clone() LineString {
ps := MultiPoint(ls)
return LineString(ps.Clone())
} | [
"func",
"(",
"ls",
"LineString",
")",
"Clone",
"(",
")",
"LineString",
"{",
"ps",
":=",
"MultiPoint",
"(",
"ls",
")",
"\n",
"return",
"LineString",
"(",
"ps",
".",
"Clone",
"(",
")",
")",
"\n",
"}"
] | // Clone returns a new copy of the line string. | [
"Clone",
"returns",
"a",
"new",
"copy",
"of",
"the",
"line",
"string",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/line_string.go#L37-L40 |
151,080 | paulmach/orb | geo/distance.go | Distance | func Distance(p1, p2 orb.Point) float64 {
dLat := deg2rad(p1[1] - p2[1])
dLon := deg2rad(p1[0] - p2[0])
dLon = math.Abs(dLon)
if dLon > math.Pi {
dLon = 2*math.Pi - dLon
}
// fast way using pythagorean theorem on an equirectangular projection
x := dLon * math.Cos(deg2rad((p1[1]+p2[1])/2.0))
return math.Sqrt(dLat*dLat+x*x) * orb.EarthRadius
} | go | func Distance(p1, p2 orb.Point) float64 {
dLat := deg2rad(p1[1] - p2[1])
dLon := deg2rad(p1[0] - p2[0])
dLon = math.Abs(dLon)
if dLon > math.Pi {
dLon = 2*math.Pi - dLon
}
// fast way using pythagorean theorem on an equirectangular projection
x := dLon * math.Cos(deg2rad((p1[1]+p2[1])/2.0))
return math.Sqrt(dLat*dLat+x*x) * orb.EarthRadius
} | [
"func",
"Distance",
"(",
"p1",
",",
"p2",
"orb",
".",
"Point",
")",
"float64",
"{",
"dLat",
":=",
"deg2rad",
"(",
"p1",
"[",
"1",
"]",
"-",
"p2",
"[",
"1",
"]",
")",
"\n",
"dLon",
":=",
"deg2rad",
"(",
"p1",
"[",
"0",
"]",
"-",
"p2",
"[",
"0",
"]",
")",
"\n\n",
"dLon",
"=",
"math",
".",
"Abs",
"(",
"dLon",
")",
"\n",
"if",
"dLon",
">",
"math",
".",
"Pi",
"{",
"dLon",
"=",
"2",
"*",
"math",
".",
"Pi",
"-",
"dLon",
"\n",
"}",
"\n\n",
"// fast way using pythagorean theorem on an equirectangular projection",
"x",
":=",
"dLon",
"*",
"math",
".",
"Cos",
"(",
"deg2rad",
"(",
"(",
"p1",
"[",
"1",
"]",
"+",
"p2",
"[",
"1",
"]",
")",
"/",
"2.0",
")",
")",
"\n",
"return",
"math",
".",
"Sqrt",
"(",
"dLat",
"*",
"dLat",
"+",
"x",
"*",
"x",
")",
"*",
"orb",
".",
"EarthRadius",
"\n",
"}"
] | // Distance returns the distance between two points on the earth. | [
"Distance",
"returns",
"the",
"distance",
"between",
"two",
"points",
"on",
"the",
"earth",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/geo/distance.go#L10-L22 |
151,081 | paulmach/orb | geo/distance.go | DistanceHaversine | func DistanceHaversine(p1, p2 orb.Point) float64 {
dLat := deg2rad(p1[1] - p2[1])
dLon := deg2rad(p1[0] - p2[0])
dLat2Sin := math.Sin(dLat / 2)
dLon2Sin := math.Sin(dLon / 2)
a := dLat2Sin*dLat2Sin + math.Cos(deg2rad(p2[1]))*math.Cos(deg2rad(p1[1]))*dLon2Sin*dLon2Sin
return 2.0 * orb.EarthRadius * math.Atan2(math.Sqrt(a), math.Sqrt(1-a))
} | go | func DistanceHaversine(p1, p2 orb.Point) float64 {
dLat := deg2rad(p1[1] - p2[1])
dLon := deg2rad(p1[0] - p2[0])
dLat2Sin := math.Sin(dLat / 2)
dLon2Sin := math.Sin(dLon / 2)
a := dLat2Sin*dLat2Sin + math.Cos(deg2rad(p2[1]))*math.Cos(deg2rad(p1[1]))*dLon2Sin*dLon2Sin
return 2.0 * orb.EarthRadius * math.Atan2(math.Sqrt(a), math.Sqrt(1-a))
} | [
"func",
"DistanceHaversine",
"(",
"p1",
",",
"p2",
"orb",
".",
"Point",
")",
"float64",
"{",
"dLat",
":=",
"deg2rad",
"(",
"p1",
"[",
"1",
"]",
"-",
"p2",
"[",
"1",
"]",
")",
"\n",
"dLon",
":=",
"deg2rad",
"(",
"p1",
"[",
"0",
"]",
"-",
"p2",
"[",
"0",
"]",
")",
"\n\n",
"dLat2Sin",
":=",
"math",
".",
"Sin",
"(",
"dLat",
"/",
"2",
")",
"\n",
"dLon2Sin",
":=",
"math",
".",
"Sin",
"(",
"dLon",
"/",
"2",
")",
"\n",
"a",
":=",
"dLat2Sin",
"*",
"dLat2Sin",
"+",
"math",
".",
"Cos",
"(",
"deg2rad",
"(",
"p2",
"[",
"1",
"]",
")",
")",
"*",
"math",
".",
"Cos",
"(",
"deg2rad",
"(",
"p1",
"[",
"1",
"]",
")",
")",
"*",
"dLon2Sin",
"*",
"dLon2Sin",
"\n\n",
"return",
"2.0",
"*",
"orb",
".",
"EarthRadius",
"*",
"math",
".",
"Atan2",
"(",
"math",
".",
"Sqrt",
"(",
"a",
")",
",",
"math",
".",
"Sqrt",
"(",
"1",
"-",
"a",
")",
")",
"\n",
"}"
] | // DistanceHaversine computes the distance on the earth using the
// more accurate haversine formula. | [
"DistanceHaversine",
"computes",
"the",
"distance",
"on",
"the",
"earth",
"using",
"the",
"more",
"accurate",
"haversine",
"formula",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/geo/distance.go#L26-L35 |
151,082 | paulmach/orb | geo/distance.go | Bearing | func Bearing(from, to orb.Point) float64 {
dLon := deg2rad(to[0] - from[0])
fromLatRad := deg2rad(from[1])
toLatRad := deg2rad(to[1])
y := math.Sin(dLon) * math.Cos(toLatRad)
x := math.Cos(fromLatRad)*math.Sin(toLatRad) - math.Sin(fromLatRad)*math.Cos(toLatRad)*math.Cos(dLon)
return rad2deg(math.Atan2(y, x))
} | go | func Bearing(from, to orb.Point) float64 {
dLon := deg2rad(to[0] - from[0])
fromLatRad := deg2rad(from[1])
toLatRad := deg2rad(to[1])
y := math.Sin(dLon) * math.Cos(toLatRad)
x := math.Cos(fromLatRad)*math.Sin(toLatRad) - math.Sin(fromLatRad)*math.Cos(toLatRad)*math.Cos(dLon)
return rad2deg(math.Atan2(y, x))
} | [
"func",
"Bearing",
"(",
"from",
",",
"to",
"orb",
".",
"Point",
")",
"float64",
"{",
"dLon",
":=",
"deg2rad",
"(",
"to",
"[",
"0",
"]",
"-",
"from",
"[",
"0",
"]",
")",
"\n\n",
"fromLatRad",
":=",
"deg2rad",
"(",
"from",
"[",
"1",
"]",
")",
"\n",
"toLatRad",
":=",
"deg2rad",
"(",
"to",
"[",
"1",
"]",
")",
"\n\n",
"y",
":=",
"math",
".",
"Sin",
"(",
"dLon",
")",
"*",
"math",
".",
"Cos",
"(",
"toLatRad",
")",
"\n",
"x",
":=",
"math",
".",
"Cos",
"(",
"fromLatRad",
")",
"*",
"math",
".",
"Sin",
"(",
"toLatRad",
")",
"-",
"math",
".",
"Sin",
"(",
"fromLatRad",
")",
"*",
"math",
".",
"Cos",
"(",
"toLatRad",
")",
"*",
"math",
".",
"Cos",
"(",
"dLon",
")",
"\n\n",
"return",
"rad2deg",
"(",
"math",
".",
"Atan2",
"(",
"y",
",",
"x",
")",
")",
"\n",
"}"
] | // Bearing computes the direction one must start traveling on earth
// to be heading from, to the given points. | [
"Bearing",
"computes",
"the",
"direction",
"one",
"must",
"start",
"traveling",
"on",
"earth",
"to",
"be",
"heading",
"from",
"to",
"the",
"given",
"points",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/geo/distance.go#L39-L49 |
151,083 | paulmach/orb | geo/distance.go | Midpoint | func Midpoint(p, p2 orb.Point) orb.Point {
dLon := deg2rad(p2[0] - p[0])
aLatRad := deg2rad(p[1])
bLatRad := deg2rad(p2[1])
x := math.Cos(bLatRad) * math.Cos(dLon)
y := math.Cos(bLatRad) * math.Sin(dLon)
r := orb.Point{
deg2rad(p[0]) + math.Atan2(y, math.Cos(aLatRad)+x),
math.Atan2(math.Sin(aLatRad)+math.Sin(bLatRad), math.Sqrt((math.Cos(aLatRad)+x)*(math.Cos(aLatRad)+x)+y*y)),
}
// convert back to degrees
r[0] = rad2deg(r[0])
r[1] = rad2deg(r[1])
return r
} | go | func Midpoint(p, p2 orb.Point) orb.Point {
dLon := deg2rad(p2[0] - p[0])
aLatRad := deg2rad(p[1])
bLatRad := deg2rad(p2[1])
x := math.Cos(bLatRad) * math.Cos(dLon)
y := math.Cos(bLatRad) * math.Sin(dLon)
r := orb.Point{
deg2rad(p[0]) + math.Atan2(y, math.Cos(aLatRad)+x),
math.Atan2(math.Sin(aLatRad)+math.Sin(bLatRad), math.Sqrt((math.Cos(aLatRad)+x)*(math.Cos(aLatRad)+x)+y*y)),
}
// convert back to degrees
r[0] = rad2deg(r[0])
r[1] = rad2deg(r[1])
return r
} | [
"func",
"Midpoint",
"(",
"p",
",",
"p2",
"orb",
".",
"Point",
")",
"orb",
".",
"Point",
"{",
"dLon",
":=",
"deg2rad",
"(",
"p2",
"[",
"0",
"]",
"-",
"p",
"[",
"0",
"]",
")",
"\n\n",
"aLatRad",
":=",
"deg2rad",
"(",
"p",
"[",
"1",
"]",
")",
"\n",
"bLatRad",
":=",
"deg2rad",
"(",
"p2",
"[",
"1",
"]",
")",
"\n\n",
"x",
":=",
"math",
".",
"Cos",
"(",
"bLatRad",
")",
"*",
"math",
".",
"Cos",
"(",
"dLon",
")",
"\n",
"y",
":=",
"math",
".",
"Cos",
"(",
"bLatRad",
")",
"*",
"math",
".",
"Sin",
"(",
"dLon",
")",
"\n\n",
"r",
":=",
"orb",
".",
"Point",
"{",
"deg2rad",
"(",
"p",
"[",
"0",
"]",
")",
"+",
"math",
".",
"Atan2",
"(",
"y",
",",
"math",
".",
"Cos",
"(",
"aLatRad",
")",
"+",
"x",
")",
",",
"math",
".",
"Atan2",
"(",
"math",
".",
"Sin",
"(",
"aLatRad",
")",
"+",
"math",
".",
"Sin",
"(",
"bLatRad",
")",
",",
"math",
".",
"Sqrt",
"(",
"(",
"math",
".",
"Cos",
"(",
"aLatRad",
")",
"+",
"x",
")",
"*",
"(",
"math",
".",
"Cos",
"(",
"aLatRad",
")",
"+",
"x",
")",
"+",
"y",
"*",
"y",
")",
")",
",",
"}",
"\n\n",
"// convert back to degrees",
"r",
"[",
"0",
"]",
"=",
"rad2deg",
"(",
"r",
"[",
"0",
"]",
")",
"\n",
"r",
"[",
"1",
"]",
"=",
"rad2deg",
"(",
"r",
"[",
"1",
"]",
")",
"\n\n",
"return",
"r",
"\n",
"}"
] | // Midpoint returns the half-way point along a great circle path between the two points. | [
"Midpoint",
"returns",
"the",
"half",
"-",
"way",
"point",
"along",
"a",
"great",
"circle",
"path",
"between",
"the",
"two",
"points",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/geo/distance.go#L52-L71 |
151,084 | paulmach/orb | maptile/set.go | ToFeatureCollection | func (s Set) ToFeatureCollection() *geojson.FeatureCollection {
fc := geojson.NewFeatureCollection()
fc.Features = make([]*geojson.Feature, 0, len(s))
for t := range s {
fc.Append(geojson.NewFeature(t.Bound().ToPolygon()))
}
return fc
} | go | func (s Set) ToFeatureCollection() *geojson.FeatureCollection {
fc := geojson.NewFeatureCollection()
fc.Features = make([]*geojson.Feature, 0, len(s))
for t := range s {
fc.Append(geojson.NewFeature(t.Bound().ToPolygon()))
}
return fc
} | [
"func",
"(",
"s",
"Set",
")",
"ToFeatureCollection",
"(",
")",
"*",
"geojson",
".",
"FeatureCollection",
"{",
"fc",
":=",
"geojson",
".",
"NewFeatureCollection",
"(",
")",
"\n",
"fc",
".",
"Features",
"=",
"make",
"(",
"[",
"]",
"*",
"geojson",
".",
"Feature",
",",
"0",
",",
"len",
"(",
"s",
")",
")",
"\n",
"for",
"t",
":=",
"range",
"s",
"{",
"fc",
".",
"Append",
"(",
"geojson",
".",
"NewFeature",
"(",
"t",
".",
"Bound",
"(",
")",
".",
"ToPolygon",
"(",
")",
")",
")",
"\n",
"}",
"\n\n",
"return",
"fc",
"\n",
"}"
] | // ToFeatureCollection converts a set of tiles into a feature collection.
// This method is mostly useful for debugging output. | [
"ToFeatureCollection",
"converts",
"a",
"set",
"of",
"tiles",
"into",
"a",
"feature",
"collection",
".",
"This",
"method",
"is",
"mostly",
"useful",
"for",
"debugging",
"output",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/maptile/set.go#L12-L20 |
151,085 | paulmach/orb | maptile/set.go | Merge | func (s Set) Merge(set Set) {
for t, v := range set {
if v {
s[t] = true
}
}
} | go | func (s Set) Merge(set Set) {
for t, v := range set {
if v {
s[t] = true
}
}
} | [
"func",
"(",
"s",
"Set",
")",
"Merge",
"(",
"set",
"Set",
")",
"{",
"for",
"t",
",",
"v",
":=",
"range",
"set",
"{",
"if",
"v",
"{",
"s",
"[",
"t",
"]",
"=",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // Merge will merge the given set into the existing set. | [
"Merge",
"will",
"merge",
"the",
"given",
"set",
"into",
"the",
"existing",
"set",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/maptile/set.go#L23-L29 |
151,086 | paulmach/orb | maptile/tilecover/line_string.go | LineString | func LineString(ls orb.LineString, z maptile.Zoom) maptile.Set {
set := make(maptile.Set)
line(set, ls, z, nil)
return set
} | go | func LineString(ls orb.LineString, z maptile.Zoom) maptile.Set {
set := make(maptile.Set)
line(set, ls, z, nil)
return set
} | [
"func",
"LineString",
"(",
"ls",
"orb",
".",
"LineString",
",",
"z",
"maptile",
".",
"Zoom",
")",
"maptile",
".",
"Set",
"{",
"set",
":=",
"make",
"(",
"maptile",
".",
"Set",
")",
"\n",
"line",
"(",
"set",
",",
"ls",
",",
"z",
",",
"nil",
")",
"\n\n",
"return",
"set",
"\n",
"}"
] | // LineString creates a tile cover for the line string. | [
"LineString",
"creates",
"a",
"tile",
"cover",
"for",
"the",
"line",
"string",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/maptile/tilecover/line_string.go#L11-L16 |
151,087 | paulmach/orb | maptile/tilecover/line_string.go | MultiLineString | func MultiLineString(mls orb.MultiLineString, z maptile.Zoom) maptile.Set {
set := make(maptile.Set)
for _, ls := range mls {
line(set, ls, z, nil)
}
return set
} | go | func MultiLineString(mls orb.MultiLineString, z maptile.Zoom) maptile.Set {
set := make(maptile.Set)
for _, ls := range mls {
line(set, ls, z, nil)
}
return set
} | [
"func",
"MultiLineString",
"(",
"mls",
"orb",
".",
"MultiLineString",
",",
"z",
"maptile",
".",
"Zoom",
")",
"maptile",
".",
"Set",
"{",
"set",
":=",
"make",
"(",
"maptile",
".",
"Set",
")",
"\n",
"for",
"_",
",",
"ls",
":=",
"range",
"mls",
"{",
"line",
"(",
"set",
",",
"ls",
",",
"z",
",",
"nil",
")",
"\n",
"}",
"\n\n",
"return",
"set",
"\n",
"}"
] | // MultiLineString creates a tile cover for the line strings. | [
"MultiLineString",
"creates",
"a",
"tile",
"cover",
"for",
"the",
"line",
"strings",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/maptile/tilecover/line_string.go#L19-L26 |
151,088 | paulmach/orb | maptile/tile.go | ToFeatureCollection | func (ts Tiles) ToFeatureCollection() *geojson.FeatureCollection {
fc := geojson.NewFeatureCollection()
fc.Features = make([]*geojson.Feature, 0, len(ts))
for _, t := range ts {
fc.Append(geojson.NewFeature(t.Bound().ToPolygon()))
}
return fc
} | go | func (ts Tiles) ToFeatureCollection() *geojson.FeatureCollection {
fc := geojson.NewFeatureCollection()
fc.Features = make([]*geojson.Feature, 0, len(ts))
for _, t := range ts {
fc.Append(geojson.NewFeature(t.Bound().ToPolygon()))
}
return fc
} | [
"func",
"(",
"ts",
"Tiles",
")",
"ToFeatureCollection",
"(",
")",
"*",
"geojson",
".",
"FeatureCollection",
"{",
"fc",
":=",
"geojson",
".",
"NewFeatureCollection",
"(",
")",
"\n",
"fc",
".",
"Features",
"=",
"make",
"(",
"[",
"]",
"*",
"geojson",
".",
"Feature",
",",
"0",
",",
"len",
"(",
"ts",
")",
")",
"\n",
"for",
"_",
",",
"t",
":=",
"range",
"ts",
"{",
"fc",
".",
"Append",
"(",
"geojson",
".",
"NewFeature",
"(",
"t",
".",
"Bound",
"(",
")",
".",
"ToPolygon",
"(",
")",
")",
")",
"\n",
"}",
"\n\n",
"return",
"fc",
"\n",
"}"
] | // ToFeatureCollection converts the tiles into a feature collection.
// This method is mostly useful for debugging output. | [
"ToFeatureCollection",
"converts",
"the",
"tiles",
"into",
"a",
"feature",
"collection",
".",
"This",
"method",
"is",
"mostly",
"useful",
"for",
"debugging",
"output",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/maptile/tile.go#L19-L27 |
151,089 | paulmach/orb | maptile/tile.go | New | func New(x, y uint32, z Zoom) Tile {
return Tile{x, y, z}
} | go | func New(x, y uint32, z Zoom) Tile {
return Tile{x, y, z}
} | [
"func",
"New",
"(",
"x",
",",
"y",
"uint32",
",",
"z",
"Zoom",
")",
"Tile",
"{",
"return",
"Tile",
"{",
"x",
",",
"y",
",",
"z",
"}",
"\n",
"}"
] | // New creates a new tile with the given coordinates. | [
"New",
"creates",
"a",
"new",
"tile",
"with",
"the",
"given",
"coordinates",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/maptile/tile.go#L39-L41 |
151,090 | paulmach/orb | maptile/tile.go | FromQuadkey | func FromQuadkey(k uint64, z Zoom) Tile {
t := Tile{Z: z}
for i := Zoom(0); i < z; i++ {
t.X |= uint32((k & (1 << (2 * i))) >> i)
t.Y |= uint32((k & (1 << (2*i + 1))) >> (i + 1))
}
return t
} | go | func FromQuadkey(k uint64, z Zoom) Tile {
t := Tile{Z: z}
for i := Zoom(0); i < z; i++ {
t.X |= uint32((k & (1 << (2 * i))) >> i)
t.Y |= uint32((k & (1 << (2*i + 1))) >> (i + 1))
}
return t
} | [
"func",
"FromQuadkey",
"(",
"k",
"uint64",
",",
"z",
"Zoom",
")",
"Tile",
"{",
"t",
":=",
"Tile",
"{",
"Z",
":",
"z",
"}",
"\n\n",
"for",
"i",
":=",
"Zoom",
"(",
"0",
")",
";",
"i",
"<",
"z",
";",
"i",
"++",
"{",
"t",
".",
"X",
"|=",
"uint32",
"(",
"(",
"k",
"&",
"(",
"1",
"<<",
"(",
"2",
"*",
"i",
")",
")",
")",
">>",
"i",
")",
"\n",
"t",
".",
"Y",
"|=",
"uint32",
"(",
"(",
"k",
"&",
"(",
"1",
"<<",
"(",
"2",
"*",
"i",
"+",
"1",
")",
")",
")",
">>",
"(",
"i",
"+",
"1",
")",
")",
"\n",
"}",
"\n\n",
"return",
"t",
"\n",
"}"
] | // FromQuadkey creates the tile from the quadkey. | [
"FromQuadkey",
"creates",
"the",
"tile",
"from",
"the",
"quadkey",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/maptile/tile.go#L59-L68 |
151,091 | paulmach/orb | maptile/tile.go | Parent | func (t Tile) Parent() Tile {
if t.Z == 0 {
return t
}
return Tile{
X: t.X >> 1,
Y: t.Y >> 1,
Z: t.Z - 1,
}
} | go | func (t Tile) Parent() Tile {
if t.Z == 0 {
return t
}
return Tile{
X: t.X >> 1,
Y: t.Y >> 1,
Z: t.Z - 1,
}
} | [
"func",
"(",
"t",
"Tile",
")",
"Parent",
"(",
")",
"Tile",
"{",
"if",
"t",
".",
"Z",
"==",
"0",
"{",
"return",
"t",
"\n",
"}",
"\n\n",
"return",
"Tile",
"{",
"X",
":",
"t",
".",
"X",
">>",
"1",
",",
"Y",
":",
"t",
".",
"Y",
">>",
"1",
",",
"Z",
":",
"t",
".",
"Z",
"-",
"1",
",",
"}",
"\n",
"}"
] | // Parent returns the parent of the tile. | [
"Parent",
"returns",
"the",
"parent",
"of",
"the",
"tile",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/maptile/tile.go#L129-L139 |
151,092 | paulmach/orb | maptile/tile.go | Fraction | func Fraction(ll orb.Point, z Zoom) orb.Point {
var p orb.Point
factor := uint32(1 << z)
maxtiles := float64(factor)
lng := ll[0]/360.0 + 0.5
p[0] = lng * maxtiles
// bound it because we have a top of the world problem
if ll[1] < -85.0511 {
p[1] = maxtiles - 1
} else if ll[1] > 85.0511 {
p[1] = 0
} else {
siny := math.Sin(ll[1] * math.Pi / 180.0)
lat := 0.5 + 0.5*math.Log((1.0+siny)/(1.0-siny))/(-2*math.Pi)
p[1] = lat * maxtiles
}
return p
} | go | func Fraction(ll orb.Point, z Zoom) orb.Point {
var p orb.Point
factor := uint32(1 << z)
maxtiles := float64(factor)
lng := ll[0]/360.0 + 0.5
p[0] = lng * maxtiles
// bound it because we have a top of the world problem
if ll[1] < -85.0511 {
p[1] = maxtiles - 1
} else if ll[1] > 85.0511 {
p[1] = 0
} else {
siny := math.Sin(ll[1] * math.Pi / 180.0)
lat := 0.5 + 0.5*math.Log((1.0+siny)/(1.0-siny))/(-2*math.Pi)
p[1] = lat * maxtiles
}
return p
} | [
"func",
"Fraction",
"(",
"ll",
"orb",
".",
"Point",
",",
"z",
"Zoom",
")",
"orb",
".",
"Point",
"{",
"var",
"p",
"orb",
".",
"Point",
"\n\n",
"factor",
":=",
"uint32",
"(",
"1",
"<<",
"z",
")",
"\n",
"maxtiles",
":=",
"float64",
"(",
"factor",
")",
"\n\n",
"lng",
":=",
"ll",
"[",
"0",
"]",
"/",
"360.0",
"+",
"0.5",
"\n",
"p",
"[",
"0",
"]",
"=",
"lng",
"*",
"maxtiles",
"\n\n",
"// bound it because we have a top of the world problem",
"if",
"ll",
"[",
"1",
"]",
"<",
"-",
"85.0511",
"{",
"p",
"[",
"1",
"]",
"=",
"maxtiles",
"-",
"1",
"\n",
"}",
"else",
"if",
"ll",
"[",
"1",
"]",
">",
"85.0511",
"{",
"p",
"[",
"1",
"]",
"=",
"0",
"\n",
"}",
"else",
"{",
"siny",
":=",
"math",
".",
"Sin",
"(",
"ll",
"[",
"1",
"]",
"*",
"math",
".",
"Pi",
"/",
"180.0",
")",
"\n",
"lat",
":=",
"0.5",
"+",
"0.5",
"*",
"math",
".",
"Log",
"(",
"(",
"1.0",
"+",
"siny",
")",
"/",
"(",
"1.0",
"-",
"siny",
")",
")",
"/",
"(",
"-",
"2",
"*",
"math",
".",
"Pi",
")",
"\n",
"p",
"[",
"1",
"]",
"=",
"lat",
"*",
"maxtiles",
"\n",
"}",
"\n\n",
"return",
"p",
"\n",
"}"
] | // Fraction returns the precise tile fraction at the given zoom.
// Will return 2^zoom-1 if the point is below 85.0511 S. | [
"Fraction",
"returns",
"the",
"precise",
"tile",
"fraction",
"at",
"the",
"given",
"zoom",
".",
"Will",
"return",
"2^zoom",
"-",
"1",
"if",
"the",
"point",
"is",
"below",
"85",
".",
"0511",
"S",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/maptile/tile.go#L143-L164 |
151,093 | paulmach/orb | maptile/tile.go | SharedParent | func (t Tile) SharedParent(tile Tile) Tile {
// bring both tiles to the lowest zoom.
if t.Z != tile.Z {
if t.Z < tile.Z {
tile = tile.toZoom(t.Z)
} else {
t = t.toZoom(tile.Z)
}
}
if t == tile {
return t
}
// go version < 1.9
// bit package usage was about 10% faster
//
// TODO: use build flags to support older versions of go.
//
// move from most significant to least until there isn't a match.
// for i := t.Z - 1; i >= 0; i-- {
// if t.X&(1<<i) != tile.X&(1<<i) ||
// t.Y&(1<<i) != tile.Y&(1<<i) {
// return Tile{
// t.X >> (i + 1),
// t.Y >> (i + 1),
// t.Z - (i + 1),
// }
// }
// }
//
// if we reach here the tiles are the same, which was checked above.
// panic("unreachable")
// bits different for x and y
xc := uint32(32 - bits.LeadingZeros32(t.X^tile.X))
yc := uint32(32 - bits.LeadingZeros32(t.Y^tile.Y))
// max of xc, yc
maxc := xc
if yc > maxc {
maxc = yc
}
return Tile{
X: t.X >> maxc,
Y: t.Y >> maxc,
Z: t.Z - Zoom(maxc),
}
} | go | func (t Tile) SharedParent(tile Tile) Tile {
// bring both tiles to the lowest zoom.
if t.Z != tile.Z {
if t.Z < tile.Z {
tile = tile.toZoom(t.Z)
} else {
t = t.toZoom(tile.Z)
}
}
if t == tile {
return t
}
// go version < 1.9
// bit package usage was about 10% faster
//
// TODO: use build flags to support older versions of go.
//
// move from most significant to least until there isn't a match.
// for i := t.Z - 1; i >= 0; i-- {
// if t.X&(1<<i) != tile.X&(1<<i) ||
// t.Y&(1<<i) != tile.Y&(1<<i) {
// return Tile{
// t.X >> (i + 1),
// t.Y >> (i + 1),
// t.Z - (i + 1),
// }
// }
// }
//
// if we reach here the tiles are the same, which was checked above.
// panic("unreachable")
// bits different for x and y
xc := uint32(32 - bits.LeadingZeros32(t.X^tile.X))
yc := uint32(32 - bits.LeadingZeros32(t.Y^tile.Y))
// max of xc, yc
maxc := xc
if yc > maxc {
maxc = yc
}
return Tile{
X: t.X >> maxc,
Y: t.Y >> maxc,
Z: t.Z - Zoom(maxc),
}
} | [
"func",
"(",
"t",
"Tile",
")",
"SharedParent",
"(",
"tile",
"Tile",
")",
"Tile",
"{",
"// bring both tiles to the lowest zoom.",
"if",
"t",
".",
"Z",
"!=",
"tile",
".",
"Z",
"{",
"if",
"t",
".",
"Z",
"<",
"tile",
".",
"Z",
"{",
"tile",
"=",
"tile",
".",
"toZoom",
"(",
"t",
".",
"Z",
")",
"\n",
"}",
"else",
"{",
"t",
"=",
"t",
".",
"toZoom",
"(",
"tile",
".",
"Z",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"t",
"==",
"tile",
"{",
"return",
"t",
"\n",
"}",
"\n\n",
"// go version < 1.9",
"// bit package usage was about 10% faster",
"//",
"// TODO: use build flags to support older versions of go.",
"//",
"// move from most significant to least until there isn't a match.",
"// for i := t.Z - 1; i >= 0; i-- {",
"// \tif t.X&(1<<i) != tile.X&(1<<i) ||",
"// \t\tt.Y&(1<<i) != tile.Y&(1<<i) {",
"// \t\treturn Tile{",
"// \t\t\tt.X >> (i + 1),",
"// \t\t\tt.Y >> (i + 1),",
"// \t\t\tt.Z - (i + 1),",
"// \t\t}",
"// \t}",
"// }",
"//",
"// if we reach here the tiles are the same, which was checked above.",
"// panic(\"unreachable\")",
"// bits different for x and y",
"xc",
":=",
"uint32",
"(",
"32",
"-",
"bits",
".",
"LeadingZeros32",
"(",
"t",
".",
"X",
"^",
"tile",
".",
"X",
")",
")",
"\n",
"yc",
":=",
"uint32",
"(",
"32",
"-",
"bits",
".",
"LeadingZeros32",
"(",
"t",
".",
"Y",
"^",
"tile",
".",
"Y",
")",
")",
"\n\n",
"// max of xc, yc",
"maxc",
":=",
"xc",
"\n",
"if",
"yc",
">",
"maxc",
"{",
"maxc",
"=",
"yc",
"\n\n",
"}",
"\n\n",
"return",
"Tile",
"{",
"X",
":",
"t",
".",
"X",
">>",
"maxc",
",",
"Y",
":",
"t",
".",
"Y",
">>",
"maxc",
",",
"Z",
":",
"t",
".",
"Z",
"-",
"Zoom",
"(",
"maxc",
")",
",",
"}",
"\n",
"}"
] | // SharedParent returns the tile that contains both the tiles. | [
"SharedParent",
"returns",
"the",
"tile",
"that",
"contains",
"both",
"the",
"tiles",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/maptile/tile.go#L167-L217 |
151,094 | paulmach/orb | maptile/tile.go | Children | func (t Tile) Children() Tiles {
return Tiles{
Tile{t.X << 1, t.Y << 1, t.Z + 1},
Tile{(t.X << 1) + 1, t.Y << 1, t.Z + 1},
Tile{(t.X << 1) + 1, (t.Y << 1) + 1, t.Z + 1},
Tile{t.X << 1, (t.Y << 1) + 1, t.Z + 1},
}
} | go | func (t Tile) Children() Tiles {
return Tiles{
Tile{t.X << 1, t.Y << 1, t.Z + 1},
Tile{(t.X << 1) + 1, t.Y << 1, t.Z + 1},
Tile{(t.X << 1) + 1, (t.Y << 1) + 1, t.Z + 1},
Tile{t.X << 1, (t.Y << 1) + 1, t.Z + 1},
}
} | [
"func",
"(",
"t",
"Tile",
")",
"Children",
"(",
")",
"Tiles",
"{",
"return",
"Tiles",
"{",
"Tile",
"{",
"t",
".",
"X",
"<<",
"1",
",",
"t",
".",
"Y",
"<<",
"1",
",",
"t",
".",
"Z",
"+",
"1",
"}",
",",
"Tile",
"{",
"(",
"t",
".",
"X",
"<<",
"1",
")",
"+",
"1",
",",
"t",
".",
"Y",
"<<",
"1",
",",
"t",
".",
"Z",
"+",
"1",
"}",
",",
"Tile",
"{",
"(",
"t",
".",
"X",
"<<",
"1",
")",
"+",
"1",
",",
"(",
"t",
".",
"Y",
"<<",
"1",
")",
"+",
"1",
",",
"t",
".",
"Z",
"+",
"1",
"}",
",",
"Tile",
"{",
"t",
".",
"X",
"<<",
"1",
",",
"(",
"t",
".",
"Y",
"<<",
"1",
")",
"+",
"1",
",",
"t",
".",
"Z",
"+",
"1",
"}",
",",
"}",
"\n",
"}"
] | // Children returns the 4 children of the tile. | [
"Children",
"returns",
"the",
"4",
"children",
"of",
"the",
"tile",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/maptile/tile.go#L220-L227 |
151,095 | paulmach/orb | maptile/tile.go | Quadkey | func (t Tile) Quadkey() uint64 {
var i, result uint64
for i = 0; i < uint64(t.Z); i++ {
result |= (uint64(t.X) & (1 << i)) << i
result |= (uint64(t.Y) & (1 << i)) << (i + 1)
}
return result
} | go | func (t Tile) Quadkey() uint64 {
var i, result uint64
for i = 0; i < uint64(t.Z); i++ {
result |= (uint64(t.X) & (1 << i)) << i
result |= (uint64(t.Y) & (1 << i)) << (i + 1)
}
return result
} | [
"func",
"(",
"t",
"Tile",
")",
"Quadkey",
"(",
")",
"uint64",
"{",
"var",
"i",
",",
"result",
"uint64",
"\n",
"for",
"i",
"=",
"0",
";",
"i",
"<",
"uint64",
"(",
"t",
".",
"Z",
")",
";",
"i",
"++",
"{",
"result",
"|=",
"(",
"uint64",
"(",
"t",
".",
"X",
")",
"&",
"(",
"1",
"<<",
"i",
")",
")",
"<<",
"i",
"\n",
"result",
"|=",
"(",
"uint64",
"(",
"t",
".",
"Y",
")",
"&",
"(",
"1",
"<<",
"i",
")",
")",
"<<",
"(",
"i",
"+",
"1",
")",
"\n",
"}",
"\n\n",
"return",
"result",
"\n",
"}"
] | // Quadkey returns the quad key for the tile. | [
"Quadkey",
"returns",
"the",
"quad",
"key",
"for",
"the",
"tile",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/maptile/tile.go#L235-L243 |
151,096 | paulmach/orb | maptile/tile.go | Range | func (t Tile) Range(z Zoom) (min, max Tile) {
if z < t.Z {
t = t.toZoom(z)
return t, t
}
offset := z - t.Z
return Tile{
X: t.X << offset,
Y: t.Y << offset,
Z: z,
}, Tile{
X: ((t.X + 1) << offset) - 1,
Y: ((t.Y + 1) << offset) - 1,
Z: z,
}
} | go | func (t Tile) Range(z Zoom) (min, max Tile) {
if z < t.Z {
t = t.toZoom(z)
return t, t
}
offset := z - t.Z
return Tile{
X: t.X << offset,
Y: t.Y << offset,
Z: z,
}, Tile{
X: ((t.X + 1) << offset) - 1,
Y: ((t.Y + 1) << offset) - 1,
Z: z,
}
} | [
"func",
"(",
"t",
"Tile",
")",
"Range",
"(",
"z",
"Zoom",
")",
"(",
"min",
",",
"max",
"Tile",
")",
"{",
"if",
"z",
"<",
"t",
".",
"Z",
"{",
"t",
"=",
"t",
".",
"toZoom",
"(",
"z",
")",
"\n",
"return",
"t",
",",
"t",
"\n",
"}",
"\n\n",
"offset",
":=",
"z",
"-",
"t",
".",
"Z",
"\n",
"return",
"Tile",
"{",
"X",
":",
"t",
".",
"X",
"<<",
"offset",
",",
"Y",
":",
"t",
".",
"Y",
"<<",
"offset",
",",
"Z",
":",
"z",
",",
"}",
",",
"Tile",
"{",
"X",
":",
"(",
"(",
"t",
".",
"X",
"+",
"1",
")",
"<<",
"offset",
")",
"-",
"1",
",",
"Y",
":",
"(",
"(",
"t",
".",
"Y",
"+",
"1",
")",
"<<",
"offset",
")",
"-",
"1",
",",
"Z",
":",
"z",
",",
"}",
"\n",
"}"
] | // Range returns the min and max tile "range" to cover the tile
// at the given zoom. | [
"Range",
"returns",
"the",
"min",
"and",
"max",
"tile",
"range",
"to",
"cover",
"the",
"tile",
"at",
"the",
"given",
"zoom",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/maptile/tile.go#L247-L263 |
151,097 | paulmach/orb | geo/area.go | Area | func Area(g orb.Geometry) float64 {
if g == nil {
return 0
}
switch g := g.(type) {
case orb.Point, orb.MultiPoint, orb.LineString, orb.MultiLineString:
return 0
case orb.Ring:
return math.Abs(ringArea(g))
case orb.Polygon:
return polygonArea(g)
case orb.MultiPolygon:
return multiPolygonArea(g)
case orb.Collection:
return collectionArea(g)
case orb.Bound:
return Area(g.ToRing())
}
panic(fmt.Sprintf("geometry type not supported: %T", g))
} | go | func Area(g orb.Geometry) float64 {
if g == nil {
return 0
}
switch g := g.(type) {
case orb.Point, orb.MultiPoint, orb.LineString, orb.MultiLineString:
return 0
case orb.Ring:
return math.Abs(ringArea(g))
case orb.Polygon:
return polygonArea(g)
case orb.MultiPolygon:
return multiPolygonArea(g)
case orb.Collection:
return collectionArea(g)
case orb.Bound:
return Area(g.ToRing())
}
panic(fmt.Sprintf("geometry type not supported: %T", g))
} | [
"func",
"Area",
"(",
"g",
"orb",
".",
"Geometry",
")",
"float64",
"{",
"if",
"g",
"==",
"nil",
"{",
"return",
"0",
"\n",
"}",
"\n\n",
"switch",
"g",
":=",
"g",
".",
"(",
"type",
")",
"{",
"case",
"orb",
".",
"Point",
",",
"orb",
".",
"MultiPoint",
",",
"orb",
".",
"LineString",
",",
"orb",
".",
"MultiLineString",
":",
"return",
"0",
"\n",
"case",
"orb",
".",
"Ring",
":",
"return",
"math",
".",
"Abs",
"(",
"ringArea",
"(",
"g",
")",
")",
"\n",
"case",
"orb",
".",
"Polygon",
":",
"return",
"polygonArea",
"(",
"g",
")",
"\n",
"case",
"orb",
".",
"MultiPolygon",
":",
"return",
"multiPolygonArea",
"(",
"g",
")",
"\n",
"case",
"orb",
".",
"Collection",
":",
"return",
"collectionArea",
"(",
"g",
")",
"\n",
"case",
"orb",
".",
"Bound",
":",
"return",
"Area",
"(",
"g",
".",
"ToRing",
"(",
")",
")",
"\n",
"}",
"\n\n",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"g",
")",
")",
"\n",
"}"
] | // Area returns the area of the geometry on the earth. | [
"Area",
"returns",
"the",
"area",
"of",
"the",
"geometry",
"on",
"the",
"earth",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/geo/area.go#L12-L33 |
151,098 | paulmach/orb | geojson/feature.go | UnmarshalJSON | func (f *Feature) UnmarshalJSON(data []byte) error {
jf := &jsonFeature{}
err := json.Unmarshal(data, &jf)
if err != nil {
return err
}
if jf.Type != "Feature" {
return fmt.Errorf("geojson: not a feature: type=%s", jf.Type)
}
*f = Feature{
ID: jf.ID,
Type: jf.Type,
Properties: jf.Properties,
BBox: jf.BBox,
Geometry: jf.Geometry.Coordinates,
}
return nil
} | go | func (f *Feature) UnmarshalJSON(data []byte) error {
jf := &jsonFeature{}
err := json.Unmarshal(data, &jf)
if err != nil {
return err
}
if jf.Type != "Feature" {
return fmt.Errorf("geojson: not a feature: type=%s", jf.Type)
}
*f = Feature{
ID: jf.ID,
Type: jf.Type,
Properties: jf.Properties,
BBox: jf.BBox,
Geometry: jf.Geometry.Coordinates,
}
return nil
} | [
"func",
"(",
"f",
"*",
"Feature",
")",
"UnmarshalJSON",
"(",
"data",
"[",
"]",
"byte",
")",
"error",
"{",
"jf",
":=",
"&",
"jsonFeature",
"{",
"}",
"\n",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"data",
",",
"&",
"jf",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"jf",
".",
"Type",
"!=",
"\"",
"\"",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"jf",
".",
"Type",
")",
"\n",
"}",
"\n\n",
"*",
"f",
"=",
"Feature",
"{",
"ID",
":",
"jf",
".",
"ID",
",",
"Type",
":",
"jf",
".",
"Type",
",",
"Properties",
":",
"jf",
".",
"Properties",
",",
"BBox",
":",
"jf",
".",
"BBox",
",",
"Geometry",
":",
"jf",
".",
"Geometry",
".",
"Coordinates",
",",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // UnmarshalJSON handles the correct unmarshalling of the data
// into the orb.Geometry types. | [
"UnmarshalJSON",
"handles",
"the",
"correct",
"unmarshalling",
"of",
"the",
"data",
"into",
"the",
"orb",
".",
"Geometry",
"types",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/geojson/feature.go#L70-L90 |
151,099 | paulmach/orb | maptile/tilecover/helpers.go | Geometry | func Geometry(g orb.Geometry, z maptile.Zoom) maptile.Set {
if g == nil {
return nil
}
switch g := g.(type) {
case orb.Point:
return Point(g, z)
case orb.MultiPoint:
return MultiPoint(g, z)
case orb.LineString:
return LineString(g, z)
case orb.MultiLineString:
return MultiLineString(g, z)
case orb.Ring:
return Ring(g, z)
case orb.Polygon:
return Polygon(g, z)
case orb.MultiPolygon:
return MultiPolygon(g, z)
case orb.Collection:
return Collection(g, z)
case orb.Bound:
return Bound(g, z)
}
panic(fmt.Sprintf("geometry type not supported: %T", g))
} | go | func Geometry(g orb.Geometry, z maptile.Zoom) maptile.Set {
if g == nil {
return nil
}
switch g := g.(type) {
case orb.Point:
return Point(g, z)
case orb.MultiPoint:
return MultiPoint(g, z)
case orb.LineString:
return LineString(g, z)
case orb.MultiLineString:
return MultiLineString(g, z)
case orb.Ring:
return Ring(g, z)
case orb.Polygon:
return Polygon(g, z)
case orb.MultiPolygon:
return MultiPolygon(g, z)
case orb.Collection:
return Collection(g, z)
case orb.Bound:
return Bound(g, z)
}
panic(fmt.Sprintf("geometry type not supported: %T", g))
} | [
"func",
"Geometry",
"(",
"g",
"orb",
".",
"Geometry",
",",
"z",
"maptile",
".",
"Zoom",
")",
"maptile",
".",
"Set",
"{",
"if",
"g",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"switch",
"g",
":=",
"g",
".",
"(",
"type",
")",
"{",
"case",
"orb",
".",
"Point",
":",
"return",
"Point",
"(",
"g",
",",
"z",
")",
"\n",
"case",
"orb",
".",
"MultiPoint",
":",
"return",
"MultiPoint",
"(",
"g",
",",
"z",
")",
"\n",
"case",
"orb",
".",
"LineString",
":",
"return",
"LineString",
"(",
"g",
",",
"z",
")",
"\n",
"case",
"orb",
".",
"MultiLineString",
":",
"return",
"MultiLineString",
"(",
"g",
",",
"z",
")",
"\n",
"case",
"orb",
".",
"Ring",
":",
"return",
"Ring",
"(",
"g",
",",
"z",
")",
"\n",
"case",
"orb",
".",
"Polygon",
":",
"return",
"Polygon",
"(",
"g",
",",
"z",
")",
"\n",
"case",
"orb",
".",
"MultiPolygon",
":",
"return",
"MultiPolygon",
"(",
"g",
",",
"z",
")",
"\n",
"case",
"orb",
".",
"Collection",
":",
"return",
"Collection",
"(",
"g",
",",
"z",
")",
"\n",
"case",
"orb",
".",
"Bound",
":",
"return",
"Bound",
"(",
"g",
",",
"z",
")",
"\n",
"}",
"\n\n",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"g",
")",
")",
"\n",
"}"
] | // Geometry returns the covering set of tiles for the given geometry. | [
"Geometry",
"returns",
"the",
"covering",
"set",
"of",
"tiles",
"for",
"the",
"given",
"geometry",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/maptile/tilecover/helpers.go#L12-L39 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.