repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1 value | code stringlengths 52 85.5k | code_tokens list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 | partition stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|
twpayne/go-geom | encoding/wkbcommon/wkbcommon.go | WriteFlatCoords2 | func WriteFlatCoords2(w io.Writer, byteOrder binary.ByteOrder, flatCoords []float64, ends []int, stride int) error {
if err := WriteUInt32(w, byteOrder, uint32(len(ends))); err != nil {
return err
}
offset := 0
for _, end := range ends {
if err := WriteFlatCoords1(w, byteOrder, flatCoords[offset:end], stride); err != nil {
return err
}
offset = end
}
return nil
} | go | func WriteFlatCoords2(w io.Writer, byteOrder binary.ByteOrder, flatCoords []float64, ends []int, stride int) error {
if err := WriteUInt32(w, byteOrder, uint32(len(ends))); err != nil {
return err
}
offset := 0
for _, end := range ends {
if err := WriteFlatCoords1(w, byteOrder, flatCoords[offset:end], stride); err != nil {
return err
}
offset = end
}
return nil
} | [
"func",
"WriteFlatCoords2",
"(",
"w",
"io",
".",
"Writer",
",",
"byteOrder",
"binary",
".",
"ByteOrder",
",",
"flatCoords",
"[",
"]",
"float64",
",",
"ends",
"[",
"]",
"int",
",",
"stride",
"int",
")",
"error",
"{",
"if",
"err",
":=",
"WriteUInt32",
"(... | // WriteFlatCoords2 writes flat coordinates 2. | [
"WriteFlatCoords2",
"writes",
"flat",
"coordinates",
"2",
"."
] | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/encoding/wkbcommon/wkbcommon.go#L167-L179 | train |
twpayne/go-geom | sorting/sorting.go | IsLess2D | func IsLess2D(v1, v2 []float64) bool {
if v1[0] < v2[0] {
return true
}
if v1[0] > v2[0] {
return false
}
if v1[1] < v2[1] {
return true
}
return false
} | go | func IsLess2D(v1, v2 []float64) bool {
if v1[0] < v2[0] {
return true
}
if v1[0] > v2[0] {
return false
}
if v1[1] < v2[1] {
return true
}
return false
} | [
"func",
"IsLess2D",
"(",
"v1",
",",
"v2",
"[",
"]",
"float64",
")",
"bool",
"{",
"if",
"v1",
"[",
"0",
"]",
"<",
"v2",
"[",
"0",
"]",
"{",
"return",
"true",
"\n",
"}",
"\n",
"if",
"v1",
"[",
"0",
"]",
">",
"v2",
"[",
"0",
"]",
"{",
"retur... | // IsLess2D is a comparator that compares based on the size of the x and y coords.
//
// First the x coordinates are compared.
// if x coords are equal then the y coords are compared | [
"IsLess2D",
"is",
"a",
"comparator",
"that",
"compares",
"based",
"on",
"the",
"size",
"of",
"the",
"x",
"and",
"y",
"coords",
".",
"First",
"the",
"x",
"coordinates",
"are",
"compared",
".",
"if",
"x",
"coords",
"are",
"equal",
"then",
"the",
"y",
"co... | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/sorting/sorting.go#L24-L36 | train |
twpayne/go-geom | sorting/sorting.go | NewFlatCoordSorting2D | func NewFlatCoordSorting2D(layout geom.Layout, coordData []float64) FlatCoord {
return NewFlatCoordSorting(layout, coordData, IsLess2D)
} | go | func NewFlatCoordSorting2D(layout geom.Layout, coordData []float64) FlatCoord {
return NewFlatCoordSorting(layout, coordData, IsLess2D)
} | [
"func",
"NewFlatCoordSorting2D",
"(",
"layout",
"geom",
".",
"Layout",
",",
"coordData",
"[",
"]",
"float64",
")",
"FlatCoord",
"{",
"return",
"NewFlatCoordSorting",
"(",
"layout",
",",
"coordData",
",",
"IsLess2D",
")",
"\n",
"}"
] | // NewFlatCoordSorting2D creates a Compare2D based sort.Interface implementation | [
"NewFlatCoordSorting2D",
"creates",
"a",
"Compare2D",
"based",
"sort",
".",
"Interface",
"implementation"
] | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/sorting/sorting.go#L39-L41 | train |
twpayne/go-geom | sorting/sorting.go | NewFlatCoordSorting | func NewFlatCoordSorting(layout geom.Layout, coordData []float64, comparator IsLess) FlatCoord {
return FlatCoord{
isLess: comparator,
coords: coordData,
layout: layout,
stride: layout.Stride(),
}
} | go | func NewFlatCoordSorting(layout geom.Layout, coordData []float64, comparator IsLess) FlatCoord {
return FlatCoord{
isLess: comparator,
coords: coordData,
layout: layout,
stride: layout.Stride(),
}
} | [
"func",
"NewFlatCoordSorting",
"(",
"layout",
"geom",
".",
"Layout",
",",
"coordData",
"[",
"]",
"float64",
",",
"comparator",
"IsLess",
")",
"FlatCoord",
"{",
"return",
"FlatCoord",
"{",
"isLess",
":",
"comparator",
",",
"coords",
":",
"coordData",
",",
"la... | // NewFlatCoordSorting creates a sort.Interface implementation based on the Comparator function | [
"NewFlatCoordSorting",
"creates",
"a",
"sort",
".",
"Interface",
"implementation",
"based",
"on",
"the",
"Comparator",
"function"
] | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/sorting/sorting.go#L44-L51 | train |
twpayne/go-geom | linestring.go | NewLineStringFlat | func NewLineStringFlat(layout Layout, flatCoords []float64) *LineString {
g := new(LineString)
g.layout = layout
g.stride = layout.Stride()
g.flatCoords = flatCoords
return g
} | go | func NewLineStringFlat(layout Layout, flatCoords []float64) *LineString {
g := new(LineString)
g.layout = layout
g.stride = layout.Stride()
g.flatCoords = flatCoords
return g
} | [
"func",
"NewLineStringFlat",
"(",
"layout",
"Layout",
",",
"flatCoords",
"[",
"]",
"float64",
")",
"*",
"LineString",
"{",
"g",
":=",
"new",
"(",
"LineString",
")",
"\n",
"g",
".",
"layout",
"=",
"layout",
"\n",
"g",
".",
"stride",
"=",
"layout",
".",
... | // NewLineStringFlat returns a new LineString with layout l and control points
// flatCoords. | [
"NewLineStringFlat",
"returns",
"a",
"new",
"LineString",
"with",
"layout",
"l",
"and",
"control",
"points",
"flatCoords",
"."
] | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/linestring.go#L16-L22 | train |
twpayne/go-geom | linestring.go | Interpolate | func (g *LineString) Interpolate(val float64, dim int) (int, float64) {
n := len(g.flatCoords)
if n == 0 {
panic("geom: empty linestring")
}
if val <= g.flatCoords[dim] {
return 0, 0
}
if g.flatCoords[n-g.stride+dim] <= val {
return (n - 1) / g.stride, 0
}
low := 0
high := n / g.stride
for low < high {
mid := (low + high) / 2
if val < g.flatCoords[mid*g.stride+dim] {
high = mid
} else {
low = mid + 1
}
}
low--
val0 := g.flatCoords[low*g.stride+dim]
if val == val0 {
return low, 0
}
val1 := g.flatCoords[(low+1)*g.stride+dim]
return low, (val - val0) / (val1 - val0)
} | go | func (g *LineString) Interpolate(val float64, dim int) (int, float64) {
n := len(g.flatCoords)
if n == 0 {
panic("geom: empty linestring")
}
if val <= g.flatCoords[dim] {
return 0, 0
}
if g.flatCoords[n-g.stride+dim] <= val {
return (n - 1) / g.stride, 0
}
low := 0
high := n / g.stride
for low < high {
mid := (low + high) / 2
if val < g.flatCoords[mid*g.stride+dim] {
high = mid
} else {
low = mid + 1
}
}
low--
val0 := g.flatCoords[low*g.stride+dim]
if val == val0 {
return low, 0
}
val1 := g.flatCoords[(low+1)*g.stride+dim]
return low, (val - val0) / (val1 - val0)
} | [
"func",
"(",
"g",
"*",
"LineString",
")",
"Interpolate",
"(",
"val",
"float64",
",",
"dim",
"int",
")",
"(",
"int",
",",
"float64",
")",
"{",
"n",
":=",
"len",
"(",
"g",
".",
"flatCoords",
")",
"\n",
"if",
"n",
"==",
"0",
"{",
"panic",
"(",
"\"... | // Interpolate returns the index and delta of val in dimension dim. | [
"Interpolate",
"returns",
"the",
"index",
"and",
"delta",
"of",
"val",
"in",
"dimension",
"dim",
"."
] | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/linestring.go#L40-L68 | train |
twpayne/go-geom | linestring.go | Length | func (g *LineString) Length() float64 {
return length1(g.flatCoords, 0, len(g.flatCoords), g.stride)
} | go | func (g *LineString) Length() float64 {
return length1(g.flatCoords, 0, len(g.flatCoords), g.stride)
} | [
"func",
"(",
"g",
"*",
"LineString",
")",
"Length",
"(",
")",
"float64",
"{",
"return",
"length1",
"(",
"g",
".",
"flatCoords",
",",
"0",
",",
"len",
"(",
"g",
".",
"flatCoords",
")",
",",
"g",
".",
"stride",
")",
"\n",
"}"
] | // Length returns the length of g. | [
"Length",
"returns",
"the",
"length",
"of",
"g",
"."
] | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/linestring.go#L71-L73 | train |
twpayne/go-geom | linestring.go | MustSetCoords | func (g *LineString) MustSetCoords(coords []Coord) *LineString {
Must(g.SetCoords(coords))
return g
} | go | func (g *LineString) MustSetCoords(coords []Coord) *LineString {
Must(g.SetCoords(coords))
return g
} | [
"func",
"(",
"g",
"*",
"LineString",
")",
"MustSetCoords",
"(",
"coords",
"[",
"]",
"Coord",
")",
"*",
"LineString",
"{",
"Must",
"(",
"g",
".",
"SetCoords",
"(",
"coords",
")",
")",
"\n",
"return",
"g",
"\n",
"}"
] | // MustSetCoords is like SetCoords but it panics on any error. | [
"MustSetCoords",
"is",
"like",
"SetCoords",
"but",
"it",
"panics",
"on",
"any",
"error",
"."
] | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/linestring.go#L76-L79 | train |
twpayne/go-geom | linestring.go | SubLineString | func (g *LineString) SubLineString(start, stop int) *LineString {
return NewLineStringFlat(g.layout, g.flatCoords[start*g.stride:stop*g.stride])
} | go | func (g *LineString) SubLineString(start, stop int) *LineString {
return NewLineStringFlat(g.layout, g.flatCoords[start*g.stride:stop*g.stride])
} | [
"func",
"(",
"g",
"*",
"LineString",
")",
"SubLineString",
"(",
"start",
",",
"stop",
"int",
")",
"*",
"LineString",
"{",
"return",
"NewLineStringFlat",
"(",
"g",
".",
"layout",
",",
"g",
".",
"flatCoords",
"[",
"start",
"*",
"g",
".",
"stride",
":",
... | // SubLineString returns a LineString from starts at index start and stops at
// index stop of g. The returned LineString aliases g. | [
"SubLineString",
"returns",
"a",
"LineString",
"from",
"starts",
"at",
"index",
"start",
"and",
"stops",
"at",
"index",
"stop",
"of",
"g",
".",
"The",
"returned",
"LineString",
"aliases",
"g",
"."
] | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/linestring.go#L97-L99 | train |
twpayne/go-geom | transform/tree_set.go | NewTreeSet | func NewTreeSet(layout geom.Layout, compare Compare) *TreeSet {
return &TreeSet{
layout: layout,
stride: layout.Stride(),
compare: compare,
}
} | go | func NewTreeSet(layout geom.Layout, compare Compare) *TreeSet {
return &TreeSet{
layout: layout,
stride: layout.Stride(),
compare: compare,
}
} | [
"func",
"NewTreeSet",
"(",
"layout",
"geom",
".",
"Layout",
",",
"compare",
"Compare",
")",
"*",
"TreeSet",
"{",
"return",
"&",
"TreeSet",
"{",
"layout",
":",
"layout",
",",
"stride",
":",
"layout",
".",
"Stride",
"(",
")",
",",
"compare",
":",
"compar... | // NewTreeSet creates a new TreeSet instance | [
"NewTreeSet",
"creates",
"a",
"new",
"TreeSet",
"instance"
] | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/transform/tree_set.go#L32-L38 | train |
twpayne/go-geom | transform/tree_set.go | Insert | func (set *TreeSet) Insert(coord geom.Coord) bool {
if set.stride == 0 {
set.stride = set.layout.Stride()
}
if len(coord) < set.stride {
panic(fmt.Sprintf("Coordinate inserted into tree does not have a sufficient number of points for the provided layout. Length of Coord was %v but should have been %v", len(coord), set.stride))
}
tree, added := set.insertImpl(set.tree, coord)
if added {
set.tree = tree
set.size++
}
return added
} | go | func (set *TreeSet) Insert(coord geom.Coord) bool {
if set.stride == 0 {
set.stride = set.layout.Stride()
}
if len(coord) < set.stride {
panic(fmt.Sprintf("Coordinate inserted into tree does not have a sufficient number of points for the provided layout. Length of Coord was %v but should have been %v", len(coord), set.stride))
}
tree, added := set.insertImpl(set.tree, coord)
if added {
set.tree = tree
set.size++
}
return added
} | [
"func",
"(",
"set",
"*",
"TreeSet",
")",
"Insert",
"(",
"coord",
"geom",
".",
"Coord",
")",
"bool",
"{",
"if",
"set",
".",
"stride",
"==",
"0",
"{",
"set",
".",
"stride",
"=",
"set",
".",
"layout",
".",
"Stride",
"(",
")",
"\n",
"}",
"\n",
"if"... | // Insert adds a new coordinate to the tree set
// the coordinate must be the same size as the Stride of the layout provided
// when constructing the TreeSet
// Returns true if the coordinate was added, false if it was already in the tree | [
"Insert",
"adds",
"a",
"new",
"coordinate",
"to",
"the",
"tree",
"set",
"the",
"coordinate",
"must",
"be",
"the",
"same",
"size",
"as",
"the",
"Stride",
"of",
"the",
"layout",
"provided",
"when",
"constructing",
"the",
"TreeSet",
"Returns",
"true",
"if",
"... | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/transform/tree_set.go#L44-L58 | train |
twpayne/go-geom | transform/tree_set.go | ToFlatArray | func (set *TreeSet) ToFlatArray() []float64 {
stride := set.layout.Stride()
array := make([]float64, set.size*stride)
i := 0
set.walk(set.tree, func(v []float64) {
for j := 0; j < stride; j++ {
array[i+j] = v[j]
}
i += stride
})
return array
} | go | func (set *TreeSet) ToFlatArray() []float64 {
stride := set.layout.Stride()
array := make([]float64, set.size*stride)
i := 0
set.walk(set.tree, func(v []float64) {
for j := 0; j < stride; j++ {
array[i+j] = v[j]
}
i += stride
})
return array
} | [
"func",
"(",
"set",
"*",
"TreeSet",
")",
"ToFlatArray",
"(",
")",
"[",
"]",
"float64",
"{",
"stride",
":=",
"set",
".",
"layout",
".",
"Stride",
"(",
")",
"\n",
"array",
":=",
"make",
"(",
"[",
"]",
"float64",
",",
"set",
".",
"size",
"*",
"strid... | // ToFlatArray returns an array of floats containing all the coordinates in the TreeSet | [
"ToFlatArray",
"returns",
"an",
"array",
"of",
"floats",
"containing",
"all",
"the",
"coordinates",
"in",
"the",
"TreeSet"
] | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/transform/tree_set.go#L61-L74 | train |
twpayne/go-geom | xy/internal/lineintersector/line_intersector.go | PointIntersectsLine | func PointIntersectsLine(strategy Strategy, point, lineStart, lineEnd geom.Coord) (hasIntersection bool) {
intersectorData := &lineIntersectorData{
strategy: strategy,
inputLines: [2][2]geom.Coord{{lineStart, lineEnd}, {}},
intersectionPoints: [2]geom.Coord{{0, 0}, {0, 0}},
}
intersectorData.pa = intersectorData.intersectionPoints[0]
intersectorData.pb = intersectorData.intersectionPoints[1]
strategy.computePointOnLineIntersection(intersectorData, point, lineStart, lineEnd)
return intersectorData.intersectionType != lineintersection.NoIntersection
} | go | func PointIntersectsLine(strategy Strategy, point, lineStart, lineEnd geom.Coord) (hasIntersection bool) {
intersectorData := &lineIntersectorData{
strategy: strategy,
inputLines: [2][2]geom.Coord{{lineStart, lineEnd}, {}},
intersectionPoints: [2]geom.Coord{{0, 0}, {0, 0}},
}
intersectorData.pa = intersectorData.intersectionPoints[0]
intersectorData.pb = intersectorData.intersectionPoints[1]
strategy.computePointOnLineIntersection(intersectorData, point, lineStart, lineEnd)
return intersectorData.intersectionType != lineintersection.NoIntersection
} | [
"func",
"PointIntersectsLine",
"(",
"strategy",
"Strategy",
",",
"point",
",",
"lineStart",
",",
"lineEnd",
"geom",
".",
"Coord",
")",
"(",
"hasIntersection",
"bool",
")",
"{",
"intersectorData",
":=",
"&",
"lineIntersectorData",
"{",
"strategy",
":",
"strategy"... | // PointIntersectsLine tests if point intersects the line | [
"PointIntersectsLine",
"tests",
"if",
"point",
"intersects",
"the",
"line"
] | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/xy/internal/lineintersector/line_intersector.go#L17-L30 | train |
twpayne/go-geom | xy/internal/lineintersector/line_intersector.go | rParameter | func rParameter(p1, p2, p geom.Coord) float64 {
var r float64
// compute maximum delta, for numerical stability
// also handle case of p1-p2 being vertical or horizontal
dx := math.Abs(p2[0] - p1[0])
dy := math.Abs(p2[1] - p1[1])
if dx > dy {
r = (p[0] - p1[0]) / (p2[0] - p1[0])
} else {
r = (p[1] - p1[1]) / (p2[1] - p1[1])
}
return r
} | go | func rParameter(p1, p2, p geom.Coord) float64 {
var r float64
// compute maximum delta, for numerical stability
// also handle case of p1-p2 being vertical or horizontal
dx := math.Abs(p2[0] - p1[0])
dy := math.Abs(p2[1] - p1[1])
if dx > dy {
r = (p[0] - p1[0]) / (p2[0] - p1[0])
} else {
r = (p[1] - p1[1]) / (p2[1] - p1[1])
}
return r
} | [
"func",
"rParameter",
"(",
"p1",
",",
"p2",
",",
"p",
"geom",
".",
"Coord",
")",
"float64",
"{",
"var",
"r",
"float64",
"\n",
"// compute maximum delta, for numerical stability",
"// also handle case of p1-p2 being vertical or horizontal",
"dx",
":=",
"math",
".",
"Ab... | /**
* RParameter computes the parameter for the point p
* in the parameterized equation
* of the line from p1 to p2.
* This is equal to the 'distance' of p along p1-p2
*/ | [
"RParameter",
"computes",
"the",
"parameter",
"for",
"the",
"point",
"p",
"in",
"the",
"parameterized",
"equation",
"of",
"the",
"line",
"from",
"p1",
"to",
"p2",
".",
"This",
"is",
"equal",
"to",
"the",
"distance",
"of",
"p",
"along",
"p1",
"-",
"p2"
] | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/xy/internal/lineintersector/line_intersector.go#L83-L95 | train |
twpayne/go-geom | xy/point_centroid.go | AddPoint | func (calc *PointCentroidCalculator) AddPoint(point *geom.Point) {
calc.AddCoord(geom.Coord(point.FlatCoords()))
} | go | func (calc *PointCentroidCalculator) AddPoint(point *geom.Point) {
calc.AddCoord(geom.Coord(point.FlatCoords()))
} | [
"func",
"(",
"calc",
"*",
"PointCentroidCalculator",
")",
"AddPoint",
"(",
"point",
"*",
"geom",
".",
"Point",
")",
"{",
"calc",
".",
"AddCoord",
"(",
"geom",
".",
"Coord",
"(",
"point",
".",
"FlatCoords",
"(",
")",
")",
")",
"\n",
"}"
] | // AddPoint adds a point to the calculation | [
"AddPoint",
"adds",
"a",
"point",
"to",
"the",
"calculation"
] | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/xy/point_centroid.go#L69-L71 | train |
twpayne/go-geom | xy/point_centroid.go | AddCoord | func (calc *PointCentroidCalculator) AddCoord(point geom.Coord) {
calc.ptCount++
calc.centSum[0] += point[0]
calc.centSum[1] += point[1]
} | go | func (calc *PointCentroidCalculator) AddCoord(point geom.Coord) {
calc.ptCount++
calc.centSum[0] += point[0]
calc.centSum[1] += point[1]
} | [
"func",
"(",
"calc",
"*",
"PointCentroidCalculator",
")",
"AddCoord",
"(",
"point",
"geom",
".",
"Coord",
")",
"{",
"calc",
".",
"ptCount",
"++",
"\n",
"calc",
".",
"centSum",
"[",
"0",
"]",
"+=",
"point",
"[",
"0",
"]",
"\n",
"calc",
".",
"centSum",... | // AddCoord adds a point to the calculation | [
"AddCoord",
"adds",
"a",
"point",
"to",
"the",
"calculation"
] | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/xy/point_centroid.go#L74-L78 | train |
twpayne/go-geom | xy/point_centroid.go | GetCentroid | func (calc *PointCentroidCalculator) GetCentroid() geom.Coord {
cent := geom.Coord{0, 0}
cent[0] = calc.centSum[0] / float64(calc.ptCount)
cent[1] = calc.centSum[1] / float64(calc.ptCount)
return cent
} | go | func (calc *PointCentroidCalculator) GetCentroid() geom.Coord {
cent := geom.Coord{0, 0}
cent[0] = calc.centSum[0] / float64(calc.ptCount)
cent[1] = calc.centSum[1] / float64(calc.ptCount)
return cent
} | [
"func",
"(",
"calc",
"*",
"PointCentroidCalculator",
")",
"GetCentroid",
"(",
")",
"geom",
".",
"Coord",
"{",
"cent",
":=",
"geom",
".",
"Coord",
"{",
"0",
",",
"0",
"}",
"\n",
"cent",
"[",
"0",
"]",
"=",
"calc",
".",
"centSum",
"[",
"0",
"]",
"/... | // GetCentroid obtains centroid currently calculated. Returns a 0 coord if no coords have been added | [
"GetCentroid",
"obtains",
"centroid",
"currently",
"calculated",
".",
"Returns",
"a",
"0",
"coord",
"if",
"no",
"coords",
"have",
"been",
"added"
] | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/xy/point_centroid.go#L81-L86 | train |
twpayne/go-geom | xy/internal/cga.go | Distance2D | func Distance2D(c1, c2 geom.Coord) float64 {
dx := c1[0] - c2[0]
dy := c1[1] - c2[1]
return math.Sqrt(dx*dx + dy*dy)
} | go | func Distance2D(c1, c2 geom.Coord) float64 {
dx := c1[0] - c2[0]
dy := c1[1] - c2[1]
return math.Sqrt(dx*dx + dy*dy)
} | [
"func",
"Distance2D",
"(",
"c1",
",",
"c2",
"geom",
".",
"Coord",
")",
"float64",
"{",
"dx",
":=",
"c1",
"[",
"0",
"]",
"-",
"c2",
"[",
"0",
"]",
"\n",
"dy",
":=",
"c1",
"[",
"1",
"]",
"-",
"c2",
"[",
"1",
"]",
"\n\n",
"return",
"math",
"."... | // Distance2D calculates the 2d distance between the two coordinates | [
"Distance2D",
"calculates",
"the",
"2d",
"distance",
"between",
"the",
"two",
"coordinates"
] | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/xy/internal/cga.go#L59-L64 | train |
twpayne/go-geom | multipolygon.go | NewMultiPolygonFlat | func NewMultiPolygonFlat(layout Layout, flatCoords []float64, endss [][]int) *MultiPolygon {
g := new(MultiPolygon)
g.layout = layout
g.stride = layout.Stride()
g.flatCoords = flatCoords
g.endss = endss
return g
} | go | func NewMultiPolygonFlat(layout Layout, flatCoords []float64, endss [][]int) *MultiPolygon {
g := new(MultiPolygon)
g.layout = layout
g.stride = layout.Stride()
g.flatCoords = flatCoords
g.endss = endss
return g
} | [
"func",
"NewMultiPolygonFlat",
"(",
"layout",
"Layout",
",",
"flatCoords",
"[",
"]",
"float64",
",",
"endss",
"[",
"]",
"[",
"]",
"int",
")",
"*",
"MultiPolygon",
"{",
"g",
":=",
"new",
"(",
"MultiPolygon",
")",
"\n",
"g",
".",
"layout",
"=",
"layout",... | // NewMultiPolygonFlat returns a new MultiPolygon with the given flat coordinates. | [
"NewMultiPolygonFlat",
"returns",
"a",
"new",
"MultiPolygon",
"with",
"the",
"given",
"flat",
"coordinates",
"."
] | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/multipolygon.go#L14-L21 | train |
twpayne/go-geom | multipolygon.go | Area | func (g *MultiPolygon) Area() float64 {
return doubleArea3(g.flatCoords, 0, g.endss, g.stride) / 2
} | go | func (g *MultiPolygon) Area() float64 {
return doubleArea3(g.flatCoords, 0, g.endss, g.stride) / 2
} | [
"func",
"(",
"g",
"*",
"MultiPolygon",
")",
"Area",
"(",
")",
"float64",
"{",
"return",
"doubleArea3",
"(",
"g",
".",
"flatCoords",
",",
"0",
",",
"g",
".",
"endss",
",",
"g",
".",
"stride",
")",
"/",
"2",
"\n",
"}"
] | // Area returns the sum of the area of the individual Polygons. | [
"Area",
"returns",
"the",
"sum",
"of",
"the",
"area",
"of",
"the",
"individual",
"Polygons",
"."
] | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/multipolygon.go#L24-L26 | train |
twpayne/go-geom | multipolygon.go | Length | func (g *MultiPolygon) Length() float64 {
return length3(g.flatCoords, 0, g.endss, g.stride)
} | go | func (g *MultiPolygon) Length() float64 {
return length3(g.flatCoords, 0, g.endss, g.stride)
} | [
"func",
"(",
"g",
"*",
"MultiPolygon",
")",
"Length",
"(",
")",
"float64",
"{",
"return",
"length3",
"(",
"g",
".",
"flatCoords",
",",
"0",
",",
"g",
".",
"endss",
",",
"g",
".",
"stride",
")",
"\n",
"}"
] | // Length returns the sum of the perimeters of the Polygons. | [
"Length",
"returns",
"the",
"sum",
"of",
"the",
"perimeters",
"of",
"the",
"Polygons",
"."
] | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/multipolygon.go#L39-L41 | train |
twpayne/go-geom | multipolygon.go | Polygon | func (g *MultiPolygon) Polygon(i int) *Polygon {
offset := 0
if i > 0 {
ends := g.endss[i-1]
offset = ends[len(ends)-1]
}
ends := make([]int, len(g.endss[i]))
if offset == 0 {
copy(ends, g.endss[i])
} else {
for j, end := range g.endss[i] {
ends[j] = end - offset
}
}
return NewPolygonFlat(g.layout, g.flatCoords[offset:g.endss[i][len(g.endss[i])-1]], ends)
} | go | func (g *MultiPolygon) Polygon(i int) *Polygon {
offset := 0
if i > 0 {
ends := g.endss[i-1]
offset = ends[len(ends)-1]
}
ends := make([]int, len(g.endss[i]))
if offset == 0 {
copy(ends, g.endss[i])
} else {
for j, end := range g.endss[i] {
ends[j] = end - offset
}
}
return NewPolygonFlat(g.layout, g.flatCoords[offset:g.endss[i][len(g.endss[i])-1]], ends)
} | [
"func",
"(",
"g",
"*",
"MultiPolygon",
")",
"Polygon",
"(",
"i",
"int",
")",
"*",
"Polygon",
"{",
"offset",
":=",
"0",
"\n",
"if",
"i",
">",
"0",
"{",
"ends",
":=",
"g",
".",
"endss",
"[",
"i",
"-",
"1",
"]",
"\n",
"offset",
"=",
"ends",
"[",... | // Polygon returns the ith Polygon. | [
"Polygon",
"returns",
"the",
"ith",
"Polygon",
"."
] | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/multipolygon.go#L55-L70 | train |
twpayne/go-geom | multipolygon.go | Push | func (g *MultiPolygon) Push(p *Polygon) error {
if p.layout != g.layout {
return ErrLayoutMismatch{Got: p.layout, Want: g.layout}
}
offset := len(g.flatCoords)
ends := make([]int, len(p.ends))
if offset == 0 {
copy(ends, p.ends)
} else {
for i, end := range p.ends {
ends[i] = end + offset
}
}
g.flatCoords = append(g.flatCoords, p.flatCoords...)
g.endss = append(g.endss, ends)
return nil
} | go | func (g *MultiPolygon) Push(p *Polygon) error {
if p.layout != g.layout {
return ErrLayoutMismatch{Got: p.layout, Want: g.layout}
}
offset := len(g.flatCoords)
ends := make([]int, len(p.ends))
if offset == 0 {
copy(ends, p.ends)
} else {
for i, end := range p.ends {
ends[i] = end + offset
}
}
g.flatCoords = append(g.flatCoords, p.flatCoords...)
g.endss = append(g.endss, ends)
return nil
} | [
"func",
"(",
"g",
"*",
"MultiPolygon",
")",
"Push",
"(",
"p",
"*",
"Polygon",
")",
"error",
"{",
"if",
"p",
".",
"layout",
"!=",
"g",
".",
"layout",
"{",
"return",
"ErrLayoutMismatch",
"{",
"Got",
":",
"p",
".",
"layout",
",",
"Want",
":",
"g",
"... | // Push appends a Polygon. | [
"Push",
"appends",
"a",
"Polygon",
"."
] | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/multipolygon.go#L73-L89 | train |
twpayne/go-geom | xy/internal/lineintersector/robust_line_intersector.go | normalizeToEnvCentre | func normalizeToEnvCentre(line1Start, line1End, line2Start, line2End, normPt geom.Coord) {
// Note: All these "max" checks are inlined for performance.
// It would be visually cleaner to do that but requires more function calls
line1MinX := line1End[0]
if line1Start[0] < line1End[0] {
line1MinX = line1Start[0]
}
line1MinY := line1End[1]
if line1Start[1] < line1End[1] {
line1MinY = line1Start[1]
}
line1MaxX := line1End[0]
if line1Start[0] > line1End[0] {
line1MaxX = line1Start[0]
}
line1MaxY := line1End[1]
if line1Start[1] > line1End[1] {
line1MaxY = line1Start[1]
}
line2MinX := line2End[0]
if line2Start[0] < line2End[0] {
line2MinX = line2Start[0]
}
line2MinY := line2End[1]
if line2Start[1] < line2End[1] {
line2MinY = line2Start[1]
}
line2MaxX := line2End[0]
if line2Start[0] > line2End[0] {
line2MaxX = line2Start[0]
}
line2MaxY := line2End[1]
if line2Start[1] > line2End[1] {
line2MaxY = line2Start[1]
}
intMinX := line2MinX
if line1MinX > line2MinX {
intMinX = line1MinX
}
intMaxX := line2MaxX
if line1MaxX < line2MaxX {
intMaxX = line1MaxX
}
intMinY := line2MinY
if line1MinY > line2MinY {
intMinY = line1MinY
}
intMaxY := line2MaxY
if line1MaxY < line2MaxY {
intMaxY = line1MaxY
}
intMidX := (intMinX + intMaxX) / 2.0
intMidY := (intMinY + intMaxY) / 2.0
normPt[0] = intMidX
normPt[1] = intMidY
line1Start[0] -= normPt[0]
line1Start[1] -= normPt[1]
line1End[0] -= normPt[0]
line1End[1] -= normPt[1]
line2Start[0] -= normPt[0]
line2Start[1] -= normPt[1]
line2End[0] -= normPt[0]
line2End[1] -= normPt[1]
} | go | func normalizeToEnvCentre(line1Start, line1End, line2Start, line2End, normPt geom.Coord) {
// Note: All these "max" checks are inlined for performance.
// It would be visually cleaner to do that but requires more function calls
line1MinX := line1End[0]
if line1Start[0] < line1End[0] {
line1MinX = line1Start[0]
}
line1MinY := line1End[1]
if line1Start[1] < line1End[1] {
line1MinY = line1Start[1]
}
line1MaxX := line1End[0]
if line1Start[0] > line1End[0] {
line1MaxX = line1Start[0]
}
line1MaxY := line1End[1]
if line1Start[1] > line1End[1] {
line1MaxY = line1Start[1]
}
line2MinX := line2End[0]
if line2Start[0] < line2End[0] {
line2MinX = line2Start[0]
}
line2MinY := line2End[1]
if line2Start[1] < line2End[1] {
line2MinY = line2Start[1]
}
line2MaxX := line2End[0]
if line2Start[0] > line2End[0] {
line2MaxX = line2Start[0]
}
line2MaxY := line2End[1]
if line2Start[1] > line2End[1] {
line2MaxY = line2Start[1]
}
intMinX := line2MinX
if line1MinX > line2MinX {
intMinX = line1MinX
}
intMaxX := line2MaxX
if line1MaxX < line2MaxX {
intMaxX = line1MaxX
}
intMinY := line2MinY
if line1MinY > line2MinY {
intMinY = line1MinY
}
intMaxY := line2MaxY
if line1MaxY < line2MaxY {
intMaxY = line1MaxY
}
intMidX := (intMinX + intMaxX) / 2.0
intMidY := (intMinY + intMaxY) / 2.0
normPt[0] = intMidX
normPt[1] = intMidY
line1Start[0] -= normPt[0]
line1Start[1] -= normPt[1]
line1End[0] -= normPt[0]
line1End[1] -= normPt[1]
line2Start[0] -= normPt[0]
line2Start[1] -= normPt[1]
line2End[0] -= normPt[0]
line2End[1] -= normPt[1]
} | [
"func",
"normalizeToEnvCentre",
"(",
"line1Start",
",",
"line1End",
",",
"line2Start",
",",
"line2End",
",",
"normPt",
"geom",
".",
"Coord",
")",
"{",
"// Note: All these \"max\" checks are inlined for performance.",
"// It would be visually cleaner to do that but requires more f... | /**
* Normalize the supplied coordinates to
* so that the midpoint of their intersection envelope
* lies at the origin.
*/ | [
"Normalize",
"the",
"supplied",
"coordinates",
"to",
"so",
"that",
"the",
"midpoint",
"of",
"their",
"intersection",
"envelope",
"lies",
"at",
"the",
"origin",
"."
] | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/xy/internal/lineintersector/robust_line_intersector.go#L263-L332 | train |
twpayne/go-geom | geometrycollection.go | Layout | func (g *GeometryCollection) Layout() Layout {
maxLayout := NoLayout
for _, g := range g.geoms {
switch l := g.Layout(); l {
case XYZ:
if maxLayout == XYM {
maxLayout = XYZM
} else if l > maxLayout {
maxLayout = l
}
case XYM:
if maxLayout == XYZ {
maxLayout = XYZM
} else if l > maxLayout {
maxLayout = l
}
default:
if l > maxLayout {
maxLayout = l
}
}
}
return maxLayout
} | go | func (g *GeometryCollection) Layout() Layout {
maxLayout := NoLayout
for _, g := range g.geoms {
switch l := g.Layout(); l {
case XYZ:
if maxLayout == XYM {
maxLayout = XYZM
} else if l > maxLayout {
maxLayout = l
}
case XYM:
if maxLayout == XYZ {
maxLayout = XYZM
} else if l > maxLayout {
maxLayout = l
}
default:
if l > maxLayout {
maxLayout = l
}
}
}
return maxLayout
} | [
"func",
"(",
"g",
"*",
"GeometryCollection",
")",
"Layout",
"(",
")",
"Layout",
"{",
"maxLayout",
":=",
"NoLayout",
"\n",
"for",
"_",
",",
"g",
":=",
"range",
"g",
".",
"geoms",
"{",
"switch",
"l",
":=",
"g",
".",
"Layout",
"(",
")",
";",
"l",
"{... | // Layout returns the smallest layout that covers all of the layouts in g's
// geometries. | [
"Layout",
"returns",
"the",
"smallest",
"layout",
"that",
"covers",
"all",
"of",
"the",
"layouts",
"in",
"g",
"s",
"geometries",
"."
] | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/geometrycollection.go#L27-L50 | train |
twpayne/go-geom | geometrycollection.go | Bounds | func (g *GeometryCollection) Bounds() *Bounds {
// FIXME this needs work for mixing layouts, e.g. XYZ and XYM
b := NewBounds(g.Layout())
for _, g := range g.geoms {
b = b.Extend(g)
}
return b
} | go | func (g *GeometryCollection) Bounds() *Bounds {
// FIXME this needs work for mixing layouts, e.g. XYZ and XYM
b := NewBounds(g.Layout())
for _, g := range g.geoms {
b = b.Extend(g)
}
return b
} | [
"func",
"(",
"g",
"*",
"GeometryCollection",
")",
"Bounds",
"(",
")",
"*",
"Bounds",
"{",
"// FIXME this needs work for mixing layouts, e.g. XYZ and XYM",
"b",
":=",
"NewBounds",
"(",
"g",
".",
"Layout",
"(",
")",
")",
"\n",
"for",
"_",
",",
"g",
":=",
"rang... | // Bounds returns the bounds of all the geometries in g. | [
"Bounds",
"returns",
"the",
"bounds",
"of",
"all",
"the",
"geometries",
"in",
"g",
"."
] | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/geometrycollection.go#L63-L70 | train |
twpayne/go-geom | geometrycollection.go | MustPush | func (g *GeometryCollection) MustPush(gs ...T) *GeometryCollection {
if err := g.Push(gs...); err != nil {
panic(err)
}
return g
} | go | func (g *GeometryCollection) MustPush(gs ...T) *GeometryCollection {
if err := g.Push(gs...); err != nil {
panic(err)
}
return g
} | [
"func",
"(",
"g",
"*",
"GeometryCollection",
")",
"MustPush",
"(",
"gs",
"...",
"T",
")",
"*",
"GeometryCollection",
"{",
"if",
"err",
":=",
"g",
".",
"Push",
"(",
"gs",
"...",
")",
";",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}... | // MustPush pushes gs to g. It panics on any error. | [
"MustPush",
"pushes",
"gs",
"to",
"g",
".",
"It",
"panics",
"on",
"any",
"error",
"."
] | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/geometrycollection.go#L98-L103 | train |
twpayne/go-geom | geometrycollection.go | Push | func (g *GeometryCollection) Push(gs ...T) error {
g.geoms = append(g.geoms, gs...)
return nil
} | go | func (g *GeometryCollection) Push(gs ...T) error {
g.geoms = append(g.geoms, gs...)
return nil
} | [
"func",
"(",
"g",
"*",
"GeometryCollection",
")",
"Push",
"(",
"gs",
"...",
"T",
")",
"error",
"{",
"g",
".",
"geoms",
"=",
"append",
"(",
"g",
".",
"geoms",
",",
"gs",
"...",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // Push appends geometries. | [
"Push",
"appends",
"geometries",
"."
] | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/geometrycollection.go#L106-L109 | train |
twpayne/go-geom | geometrycollection.go | SetSRID | func (g *GeometryCollection) SetSRID(srid int) *GeometryCollection {
g.srid = srid
return g
} | go | func (g *GeometryCollection) SetSRID(srid int) *GeometryCollection {
g.srid = srid
return g
} | [
"func",
"(",
"g",
"*",
"GeometryCollection",
")",
"SetSRID",
"(",
"srid",
"int",
")",
"*",
"GeometryCollection",
"{",
"g",
".",
"srid",
"=",
"srid",
"\n",
"return",
"g",
"\n",
"}"
] | // SetSRID sets g's SRID and the SRID of all its elements. | [
"SetSRID",
"sets",
"g",
"s",
"SRID",
"and",
"the",
"SRID",
"of",
"all",
"its",
"elements",
"."
] | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/geometrycollection.go#L112-L115 | train |
twpayne/go-geom | encoding/igc/encode.go | Encode | func (enc *Encoder) Encode(ls *geom.LineString) error {
if enc.a != "" {
if _, err := fmt.Fprintf(enc.w, "A%s\n", enc.a); err != nil {
return err
}
}
var t0 time.Time
for i, n := 0, ls.NumCoords(); i < n; i++ {
coord := ls.Coord(i)
t := time.Unix(int64(coord[3]), 0).UTC()
if t.Day() != t0.Day() || t.Month() != t0.Month() || t.Year() != t0.Year() {
if _, err := fmt.Fprintf(enc.w, "HFDTE%02d%02d%02d\n", t.Day(), t.Month(), t.Year()%100); err != nil {
return err
}
t0 = t
}
latMMin := int(math.Abs(60000 * coord[1]))
if latMMin > 90*60000 {
latMMin = 90 * 60000
}
latDeg, latMMin := latMMin/60000, latMMin%60000
var latHemi string
if coord[1] < 0 {
latHemi = "S"
} else {
latHemi = "N"
}
lngMMin := int(math.Abs(60000 * coord[0]))
if lngMMin > 180*60000 {
lngMMin = 180 * 60000
}
lngDeg, lngMMin := lngMMin/60000, lngMMin%60000
var lngHemi string
if coord[0] < 0 {
lngHemi = "W"
} else {
lngHemi = "E"
}
alt := clamp(int(coord[2]), 0, 10000)
if _, err := fmt.Fprintf(enc.w, "B%02d%02d%02d%02d%05d%s%03d%05d%sA%05d%05d\n", t.Hour(), t.Minute(), t.Second(), latDeg, latMMin, latHemi, lngDeg, lngMMin, lngHemi, alt, alt); err != nil {
return err
}
}
return nil
} | go | func (enc *Encoder) Encode(ls *geom.LineString) error {
if enc.a != "" {
if _, err := fmt.Fprintf(enc.w, "A%s\n", enc.a); err != nil {
return err
}
}
var t0 time.Time
for i, n := 0, ls.NumCoords(); i < n; i++ {
coord := ls.Coord(i)
t := time.Unix(int64(coord[3]), 0).UTC()
if t.Day() != t0.Day() || t.Month() != t0.Month() || t.Year() != t0.Year() {
if _, err := fmt.Fprintf(enc.w, "HFDTE%02d%02d%02d\n", t.Day(), t.Month(), t.Year()%100); err != nil {
return err
}
t0 = t
}
latMMin := int(math.Abs(60000 * coord[1]))
if latMMin > 90*60000 {
latMMin = 90 * 60000
}
latDeg, latMMin := latMMin/60000, latMMin%60000
var latHemi string
if coord[1] < 0 {
latHemi = "S"
} else {
latHemi = "N"
}
lngMMin := int(math.Abs(60000 * coord[0]))
if lngMMin > 180*60000 {
lngMMin = 180 * 60000
}
lngDeg, lngMMin := lngMMin/60000, lngMMin%60000
var lngHemi string
if coord[0] < 0 {
lngHemi = "W"
} else {
lngHemi = "E"
}
alt := clamp(int(coord[2]), 0, 10000)
if _, err := fmt.Fprintf(enc.w, "B%02d%02d%02d%02d%05d%s%03d%05d%sA%05d%05d\n", t.Hour(), t.Minute(), t.Second(), latDeg, latMMin, latHemi, lngDeg, lngMMin, lngHemi, alt, alt); err != nil {
return err
}
}
return nil
} | [
"func",
"(",
"enc",
"*",
"Encoder",
")",
"Encode",
"(",
"ls",
"*",
"geom",
".",
"LineString",
")",
"error",
"{",
"if",
"enc",
".",
"a",
"!=",
"\"",
"\"",
"{",
"if",
"_",
",",
"err",
":=",
"fmt",
".",
"Fprintf",
"(",
"enc",
".",
"w",
",",
"\""... | // Encode encodes a LineString. | [
"Encode",
"encodes",
"a",
"LineString",
"."
] | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/encoding/igc/encode.go#L42-L86 | train |
twpayne/go-geom | multilinestring.go | NewMultiLineStringFlat | func NewMultiLineStringFlat(layout Layout, flatCoords []float64, ends []int) *MultiLineString {
g := new(MultiLineString)
g.layout = layout
g.stride = layout.Stride()
g.flatCoords = flatCoords
g.ends = ends
return g
} | go | func NewMultiLineStringFlat(layout Layout, flatCoords []float64, ends []int) *MultiLineString {
g := new(MultiLineString)
g.layout = layout
g.stride = layout.Stride()
g.flatCoords = flatCoords
g.ends = ends
return g
} | [
"func",
"NewMultiLineStringFlat",
"(",
"layout",
"Layout",
",",
"flatCoords",
"[",
"]",
"float64",
",",
"ends",
"[",
"]",
"int",
")",
"*",
"MultiLineString",
"{",
"g",
":=",
"new",
"(",
"MultiLineString",
")",
"\n",
"g",
".",
"layout",
"=",
"layout",
"\n... | // NewMultiLineStringFlat returns a new MultiLineString with the given flat coordinates. | [
"NewMultiLineStringFlat",
"returns",
"a",
"new",
"MultiLineString",
"with",
"the",
"given",
"flat",
"coordinates",
"."
] | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/multilinestring.go#L14-L21 | train |
twpayne/go-geom | multilinestring.go | Length | func (g *MultiLineString) Length() float64 {
return length2(g.flatCoords, 0, g.ends, g.stride)
} | go | func (g *MultiLineString) Length() float64 {
return length2(g.flatCoords, 0, g.ends, g.stride)
} | [
"func",
"(",
"g",
"*",
"MultiLineString",
")",
"Length",
"(",
")",
"float64",
"{",
"return",
"length2",
"(",
"g",
".",
"flatCoords",
",",
"0",
",",
"g",
".",
"ends",
",",
"g",
".",
"stride",
")",
"\n",
"}"
] | // Length returns the sum of the length of the LineStrings. | [
"Length",
"returns",
"the",
"sum",
"of",
"the",
"length",
"of",
"the",
"LineStrings",
"."
] | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/multilinestring.go#L39-L41 | train |
twpayne/go-geom | multilinestring.go | LineString | func (g *MultiLineString) LineString(i int) *LineString {
offset := 0
if i > 0 {
offset = g.ends[i-1]
}
return NewLineStringFlat(g.layout, g.flatCoords[offset:g.ends[i]])
} | go | func (g *MultiLineString) LineString(i int) *LineString {
offset := 0
if i > 0 {
offset = g.ends[i-1]
}
return NewLineStringFlat(g.layout, g.flatCoords[offset:g.ends[i]])
} | [
"func",
"(",
"g",
"*",
"MultiLineString",
")",
"LineString",
"(",
"i",
"int",
")",
"*",
"LineString",
"{",
"offset",
":=",
"0",
"\n",
"if",
"i",
">",
"0",
"{",
"offset",
"=",
"g",
".",
"ends",
"[",
"i",
"-",
"1",
"]",
"\n",
"}",
"\n",
"return",... | // LineString returns the ith LineString. | [
"LineString",
"returns",
"the",
"ith",
"LineString",
"."
] | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/multilinestring.go#L44-L50 | train |
twpayne/go-geom | multilinestring.go | Push | func (g *MultiLineString) Push(ls *LineString) error {
if ls.layout != g.layout {
return ErrLayoutMismatch{Got: ls.layout, Want: g.layout}
}
g.flatCoords = append(g.flatCoords, ls.flatCoords...)
g.ends = append(g.ends, len(g.flatCoords))
return nil
} | go | func (g *MultiLineString) Push(ls *LineString) error {
if ls.layout != g.layout {
return ErrLayoutMismatch{Got: ls.layout, Want: g.layout}
}
g.flatCoords = append(g.flatCoords, ls.flatCoords...)
g.ends = append(g.ends, len(g.flatCoords))
return nil
} | [
"func",
"(",
"g",
"*",
"MultiLineString",
")",
"Push",
"(",
"ls",
"*",
"LineString",
")",
"error",
"{",
"if",
"ls",
".",
"layout",
"!=",
"g",
".",
"layout",
"{",
"return",
"ErrLayoutMismatch",
"{",
"Got",
":",
"ls",
".",
"layout",
",",
"Want",
":",
... | // Push appends a LineString. | [
"Push",
"appends",
"a",
"LineString",
"."
] | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/multilinestring.go#L64-L71 | train |
twpayne/go-geom | encoding/geojson/geojson.go | Encode | func Encode(g geom.T) (*Geometry, error) {
switch g := g.(type) {
case *geom.Point:
var coords json.RawMessage
coords, err := json.Marshal(g.Coords())
if err != nil {
return nil, err
}
return &Geometry{
Type: "Point",
Coordinates: &coords,
}, nil
case *geom.LineString:
var coords json.RawMessage
coords, err := json.Marshal(g.Coords())
if err != nil {
return nil, err
}
return &Geometry{
Type: "LineString",
Coordinates: &coords,
}, nil
case *geom.Polygon:
var coords json.RawMessage
coords, err := json.Marshal(g.Coords())
if err != nil {
return nil, err
}
return &Geometry{
Type: "Polygon",
Coordinates: &coords,
}, nil
case *geom.MultiPoint:
var coords json.RawMessage
coords, err := json.Marshal(g.Coords())
if err != nil {
return nil, err
}
return &Geometry{
Type: "MultiPoint",
Coordinates: &coords,
}, nil
case *geom.MultiLineString:
var coords json.RawMessage
coords, err := json.Marshal(g.Coords())
if err != nil {
return nil, err
}
return &Geometry{
Type: "MultiLineString",
Coordinates: &coords,
}, nil
case *geom.MultiPolygon:
var coords json.RawMessage
coords, err := json.Marshal(g.Coords())
if err != nil {
return nil, err
}
return &Geometry{
Type: "MultiPolygon",
Coordinates: &coords,
}, nil
case *geom.GeometryCollection:
geometries := make([]*Geometry, len(g.Geoms()))
for i, subGeometry := range g.Geoms() {
var err error
geometries[i], err = Encode(subGeometry)
if err != nil {
return nil, err
}
}
return &Geometry{
Type: "GeometryCollection",
Geometries: geometries,
}, nil
default:
return nil, geom.ErrUnsupportedType{Value: g}
}
} | go | func Encode(g geom.T) (*Geometry, error) {
switch g := g.(type) {
case *geom.Point:
var coords json.RawMessage
coords, err := json.Marshal(g.Coords())
if err != nil {
return nil, err
}
return &Geometry{
Type: "Point",
Coordinates: &coords,
}, nil
case *geom.LineString:
var coords json.RawMessage
coords, err := json.Marshal(g.Coords())
if err != nil {
return nil, err
}
return &Geometry{
Type: "LineString",
Coordinates: &coords,
}, nil
case *geom.Polygon:
var coords json.RawMessage
coords, err := json.Marshal(g.Coords())
if err != nil {
return nil, err
}
return &Geometry{
Type: "Polygon",
Coordinates: &coords,
}, nil
case *geom.MultiPoint:
var coords json.RawMessage
coords, err := json.Marshal(g.Coords())
if err != nil {
return nil, err
}
return &Geometry{
Type: "MultiPoint",
Coordinates: &coords,
}, nil
case *geom.MultiLineString:
var coords json.RawMessage
coords, err := json.Marshal(g.Coords())
if err != nil {
return nil, err
}
return &Geometry{
Type: "MultiLineString",
Coordinates: &coords,
}, nil
case *geom.MultiPolygon:
var coords json.RawMessage
coords, err := json.Marshal(g.Coords())
if err != nil {
return nil, err
}
return &Geometry{
Type: "MultiPolygon",
Coordinates: &coords,
}, nil
case *geom.GeometryCollection:
geometries := make([]*Geometry, len(g.Geoms()))
for i, subGeometry := range g.Geoms() {
var err error
geometries[i], err = Encode(subGeometry)
if err != nil {
return nil, err
}
}
return &Geometry{
Type: "GeometryCollection",
Geometries: geometries,
}, nil
default:
return nil, geom.ErrUnsupportedType{Value: g}
}
} | [
"func",
"Encode",
"(",
"g",
"geom",
".",
"T",
")",
"(",
"*",
"Geometry",
",",
"error",
")",
"{",
"switch",
"g",
":=",
"g",
".",
"(",
"type",
")",
"{",
"case",
"*",
"geom",
".",
"Point",
":",
"var",
"coords",
"json",
".",
"RawMessage",
"\n",
"co... | // Encode encodes g as a GeoJSON geometry. | [
"Encode",
"encodes",
"g",
"as",
"a",
"GeoJSON",
"geometry",
"."
] | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/encoding/geojson/geojson.go#L197-L275 | train |
twpayne/go-geom | encoding/geojson/geojson.go | UnmarshalJSON | func (f *Feature) UnmarshalJSON(data []byte) error {
var gf geojsonFeature
if err := json.Unmarshal(data, &gf); err != nil {
return err
}
if gf.Type != "Feature" {
return ErrUnsupportedType(gf.Type)
}
f.ID = gf.ID
var err error
f.Geometry, err = gf.Geometry.Decode()
if err != nil {
return err
}
f.Properties = gf.Properties
return nil
} | go | func (f *Feature) UnmarshalJSON(data []byte) error {
var gf geojsonFeature
if err := json.Unmarshal(data, &gf); err != nil {
return err
}
if gf.Type != "Feature" {
return ErrUnsupportedType(gf.Type)
}
f.ID = gf.ID
var err error
f.Geometry, err = gf.Geometry.Decode()
if err != nil {
return err
}
f.Properties = gf.Properties
return nil
} | [
"func",
"(",
"f",
"*",
"Feature",
")",
"UnmarshalJSON",
"(",
"data",
"[",
"]",
"byte",
")",
"error",
"{",
"var",
"gf",
"geojsonFeature",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"data",
",",
"&",
"gf",
")",
";",
"err",
"!=",
"nil",
... | // UnmarshalJSON implements json.Unmarshaler.UnmarshalJSON. | [
"UnmarshalJSON",
"implements",
"json",
".",
"Unmarshaler",
".",
"UnmarshalJSON",
"."
] | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/encoding/geojson/geojson.go#L312-L328 | train |
twpayne/go-geom | encoding/geojson/geojson.go | UnmarshalJSON | func (fc *FeatureCollection) UnmarshalJSON(data []byte) error {
var gfc geojsonFeatureCollection
if err := json.Unmarshal(data, &gfc); err != nil {
return err
}
if gfc.Type != "FeatureCollection" {
return ErrUnsupportedType(gfc.Type)
}
fc.Features = gfc.Features
return nil
} | go | func (fc *FeatureCollection) UnmarshalJSON(data []byte) error {
var gfc geojsonFeatureCollection
if err := json.Unmarshal(data, &gfc); err != nil {
return err
}
if gfc.Type != "FeatureCollection" {
return ErrUnsupportedType(gfc.Type)
}
fc.Features = gfc.Features
return nil
} | [
"func",
"(",
"fc",
"*",
"FeatureCollection",
")",
"UnmarshalJSON",
"(",
"data",
"[",
"]",
"byte",
")",
"error",
"{",
"var",
"gfc",
"geojsonFeatureCollection",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"data",
",",
"&",
"gfc",
")",
";",
"e... | // UnmarshalJSON implements json.Unmarshaler.UnmarshalJSON | [
"UnmarshalJSON",
"implements",
"json",
".",
"Unmarshaler",
".",
"UnmarshalJSON"
] | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/encoding/geojson/geojson.go#L343-L353 | train |
twpayne/go-geom | xy/internal/centralendpoint/intersector.go | GetIntersection | func GetIntersection(line1End1, line1End2, line2End1, line2End2 geom.Coord) geom.Coord {
intersector := centralEndpointIntersector{
line1End1: line1End1,
line1End2: line1End2,
line2End1: line2End1,
line2End2: line2End2,
}
intersector.compute()
return intersector.intersectionPoint
} | go | func GetIntersection(line1End1, line1End2, line2End1, line2End2 geom.Coord) geom.Coord {
intersector := centralEndpointIntersector{
line1End1: line1End1,
line1End2: line1End2,
line2End1: line2End1,
line2End2: line2End2,
}
intersector.compute()
return intersector.intersectionPoint
} | [
"func",
"GetIntersection",
"(",
"line1End1",
",",
"line1End2",
",",
"line2End1",
",",
"line2End2",
"geom",
".",
"Coord",
")",
"geom",
".",
"Coord",
"{",
"intersector",
":=",
"centralEndpointIntersector",
"{",
"line1End1",
":",
"line1End1",
",",
"line1End2",
":",... | // GetIntersection computes an approximate intersection of two line segments by taking the most central of the endpoints of the segments.
//
// This is effective in cases where the segments are nearly parallel and should intersect at an endpoint.
// It is also a reasonable strategy for cases where the endpoint of one segment lies on or almost on the interior of another one.
// Taking the most central endpoint ensures that the computed intersection point lies in the envelope of the segments.
//
// Also, by always returning one of the input points, this should result in reducing segment fragmentation.
// Intended to be used as a last resort for computing ill-conditioned intersection situations which cause other methods to fail. | [
"GetIntersection",
"computes",
"an",
"approximate",
"intersection",
"of",
"two",
"line",
"segments",
"by",
"taking",
"the",
"most",
"central",
"of",
"the",
"endpoints",
"of",
"the",
"segments",
".",
"This",
"is",
"effective",
"in",
"cases",
"where",
"the",
"se... | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/xy/internal/centralendpoint/intersector.go#L18-L27 | train |
twpayne/go-geom | xy/internal/raycrossing/ray-crossing-counter.go | LocatePointInRing | func LocatePointInRing(layout geom.Layout, p geom.Coord, ring []float64) location.Type {
counter := rayCrossingCounter{p: p}
stride := layout.Stride()
for i := stride; i < len(ring); i += stride {
p1 := geom.Coord(ring[i : i+2])
p2 := geom.Coord(ring[i-stride : i-stride+2])
counter.countSegment(p1, p2)
if counter.isPointOnSegment {
return counter.getLocation()
}
}
return counter.getLocation()
} | go | func LocatePointInRing(layout geom.Layout, p geom.Coord, ring []float64) location.Type {
counter := rayCrossingCounter{p: p}
stride := layout.Stride()
for i := stride; i < len(ring); i += stride {
p1 := geom.Coord(ring[i : i+2])
p2 := geom.Coord(ring[i-stride : i-stride+2])
counter.countSegment(p1, p2)
if counter.isPointOnSegment {
return counter.getLocation()
}
}
return counter.getLocation()
} | [
"func",
"LocatePointInRing",
"(",
"layout",
"geom",
".",
"Layout",
",",
"p",
"geom",
".",
"Coord",
",",
"ring",
"[",
"]",
"float64",
")",
"location",
".",
"Type",
"{",
"counter",
":=",
"rayCrossingCounter",
"{",
"p",
":",
"p",
"}",
"\n\n",
"stride",
":... | // LocatePointInRing determine where the point is with regards to the ring | [
"LocatePointInRing",
"determine",
"where",
"the",
"point",
"is",
"with",
"regards",
"to",
"the",
"ring"
] | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/xy/internal/raycrossing/ray-crossing-counter.go#L10-L25 | train |
twpayne/go-geom | xy/internal/raycrossing/ray-crossing-counter.go | countSegment | func (counter *rayCrossingCounter) countSegment(p1, p2 geom.Coord) {
/**
* For each segment, check if it crosses
* a horizontal ray running from the test point in the positive x direction.
*/
// check if the segment is strictly to the left of the test point
if p1[0] < counter.p[0] && p2[0] < counter.p[0] {
return
}
// check if the point is equal to the current ring vertex
if counter.p[0] == p2[0] && counter.p[1] == p2[1] {
counter.isPointOnSegment = true
return
}
/**
* For horizontal segments, check if the point is on the segment.
* Otherwise, horizontal segments are not counted.
*/
if p1[1] == counter.p[1] && p2[1] == counter.p[1] {
minx := p1[0]
maxx := p2[0]
if minx > maxx {
minx = p2[0]
maxx = p1[0]
}
if counter.p[0] >= minx && counter.p[0] <= maxx {
counter.isPointOnSegment = true
}
return
}
/**
* Evaluate all non-horizontal segments which cross a horizontal ray to the
* right of the test pt. To avoid double-counting shared vertices, we use the
* convention that
* <ul>
* <li>an upward edge includes its starting endpoint, and excludes its
* final endpoint
* <li>a downward edge excludes its starting endpoint, and includes its
* final endpoint
* </ul>
*/
if ((p1[1] > counter.p[1]) && (p2[1] <= counter.p[1])) || ((p2[1] > counter.p[1]) && (p1[1] <= counter.p[1])) {
// translate the segment so that the test point lies on the origin
x1 := p1[0] - counter.p[0]
y1 := p1[1] - counter.p[1]
x2 := p2[0] - counter.p[0]
y2 := p2[1] - counter.p[1]
/**
* The translated segment straddles the x-axis. Compute the sign of the
* ordinate of intersection with the x-axis. (y2 != y1, so denominator
* will never be 0.0)
*/
// double xIntSign = RobustDeterminant.signOfDet2x2(x1, y1, x2, y2) / (y2
// - y1);
// MD - faster & more robust computation?
xIntSign := robustdeterminate.SignOfDet2x2(x1, y1, x2, y2)
if xIntSign == 0.0 {
counter.isPointOnSegment = true
return
}
if y2 < y1 {
xIntSign = -xIntSign
}
// xsave = xInt;
// System.out.println("xIntSign(" + x1 + ", " + y1 + ", " + x2 + ", " + y2 + " = " + xIntSign);
// The segment crosses the ray if the sign is strictly positive.
if xIntSign > 0.0 {
counter.crossingCount++
}
}
} | go | func (counter *rayCrossingCounter) countSegment(p1, p2 geom.Coord) {
/**
* For each segment, check if it crosses
* a horizontal ray running from the test point in the positive x direction.
*/
// check if the segment is strictly to the left of the test point
if p1[0] < counter.p[0] && p2[0] < counter.p[0] {
return
}
// check if the point is equal to the current ring vertex
if counter.p[0] == p2[0] && counter.p[1] == p2[1] {
counter.isPointOnSegment = true
return
}
/**
* For horizontal segments, check if the point is on the segment.
* Otherwise, horizontal segments are not counted.
*/
if p1[1] == counter.p[1] && p2[1] == counter.p[1] {
minx := p1[0]
maxx := p2[0]
if minx > maxx {
minx = p2[0]
maxx = p1[0]
}
if counter.p[0] >= minx && counter.p[0] <= maxx {
counter.isPointOnSegment = true
}
return
}
/**
* Evaluate all non-horizontal segments which cross a horizontal ray to the
* right of the test pt. To avoid double-counting shared vertices, we use the
* convention that
* <ul>
* <li>an upward edge includes its starting endpoint, and excludes its
* final endpoint
* <li>a downward edge excludes its starting endpoint, and includes its
* final endpoint
* </ul>
*/
if ((p1[1] > counter.p[1]) && (p2[1] <= counter.p[1])) || ((p2[1] > counter.p[1]) && (p1[1] <= counter.p[1])) {
// translate the segment so that the test point lies on the origin
x1 := p1[0] - counter.p[0]
y1 := p1[1] - counter.p[1]
x2 := p2[0] - counter.p[0]
y2 := p2[1] - counter.p[1]
/**
* The translated segment straddles the x-axis. Compute the sign of the
* ordinate of intersection with the x-axis. (y2 != y1, so denominator
* will never be 0.0)
*/
// double xIntSign = RobustDeterminant.signOfDet2x2(x1, y1, x2, y2) / (y2
// - y1);
// MD - faster & more robust computation?
xIntSign := robustdeterminate.SignOfDet2x2(x1, y1, x2, y2)
if xIntSign == 0.0 {
counter.isPointOnSegment = true
return
}
if y2 < y1 {
xIntSign = -xIntSign
}
// xsave = xInt;
// System.out.println("xIntSign(" + x1 + ", " + y1 + ", " + x2 + ", " + y2 + " = " + xIntSign);
// The segment crosses the ray if the sign is strictly positive.
if xIntSign > 0.0 {
counter.crossingCount++
}
}
} | [
"func",
"(",
"counter",
"*",
"rayCrossingCounter",
")",
"countSegment",
"(",
"p1",
",",
"p2",
"geom",
".",
"Coord",
")",
"{",
"/**\n\t * For each segment, check if it crosses\n\t * a horizontal ray running from the test point in the positive x direction.\n\t */",
"// check if the s... | /**
* Counts a segment
*
* @param p1 an endpoint of the segment
* @param p2 another endpoint of the segment
*/ | [
"Counts",
"a",
"segment"
] | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/xy/internal/raycrossing/ray-crossing-counter.go#L62-L137 | train |
twpayne/go-geom | xy/line_centroid.go | NewLineCentroidCalculator | func NewLineCentroidCalculator(layout geom.Layout) *LineCentroidCalculator {
return &LineCentroidCalculator{
layout: layout,
stride: layout.Stride(),
centSum: geom.Coord(make([]float64, layout.Stride())),
}
} | go | func NewLineCentroidCalculator(layout geom.Layout) *LineCentroidCalculator {
return &LineCentroidCalculator{
layout: layout,
stride: layout.Stride(),
centSum: geom.Coord(make([]float64, layout.Stride())),
}
} | [
"func",
"NewLineCentroidCalculator",
"(",
"layout",
"geom",
".",
"Layout",
")",
"*",
"LineCentroidCalculator",
"{",
"return",
"&",
"LineCentroidCalculator",
"{",
"layout",
":",
"layout",
",",
"stride",
":",
"layout",
".",
"Stride",
"(",
")",
",",
"centSum",
":... | // NewLineCentroidCalculator creates a new instance of the calculator.
// Once a calculator is created polygons, linestrings or linear rings can be added and the
// GetCentroid method can be used at any point to get the current centroid
// the centroid will naturally change each time a geometry is added | [
"NewLineCentroidCalculator",
"creates",
"a",
"new",
"instance",
"of",
"the",
"calculator",
".",
"Once",
"a",
"calculator",
"is",
"created",
"polygons",
"linestrings",
"or",
"linear",
"rings",
"can",
"be",
"added",
"and",
"the",
"GetCentroid",
"method",
"can",
"b... | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/xy/line_centroid.go#L64-L70 | train |
twpayne/go-geom | xy/line_centroid.go | AddPolygon | func (calc *LineCentroidCalculator) AddPolygon(polygon *geom.Polygon) *LineCentroidCalculator {
for i := 0; i < polygon.NumLinearRings(); i++ {
calc.AddLinearRing(polygon.LinearRing(i))
}
return calc
} | go | func (calc *LineCentroidCalculator) AddPolygon(polygon *geom.Polygon) *LineCentroidCalculator {
for i := 0; i < polygon.NumLinearRings(); i++ {
calc.AddLinearRing(polygon.LinearRing(i))
}
return calc
} | [
"func",
"(",
"calc",
"*",
"LineCentroidCalculator",
")",
"AddPolygon",
"(",
"polygon",
"*",
"geom",
".",
"Polygon",
")",
"*",
"LineCentroidCalculator",
"{",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"polygon",
".",
"NumLinearRings",
"(",
")",
";",
"i",
"++",... | // AddPolygon adds a Polygon to the calculation. | [
"AddPolygon",
"adds",
"a",
"Polygon",
"to",
"the",
"calculation",
"."
] | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/xy/line_centroid.go#L81-L87 | train |
twpayne/go-geom | xy/line_centroid.go | AddLine | func (calc *LineCentroidCalculator) AddLine(line *geom.LineString) *LineCentroidCalculator {
coords := line.FlatCoords()
calc.addLine(coords, 0, len(coords))
return calc
} | go | func (calc *LineCentroidCalculator) AddLine(line *geom.LineString) *LineCentroidCalculator {
coords := line.FlatCoords()
calc.addLine(coords, 0, len(coords))
return calc
} | [
"func",
"(",
"calc",
"*",
"LineCentroidCalculator",
")",
"AddLine",
"(",
"line",
"*",
"geom",
".",
"LineString",
")",
"*",
"LineCentroidCalculator",
"{",
"coords",
":=",
"line",
".",
"FlatCoords",
"(",
")",
"\n",
"calc",
".",
"addLine",
"(",
"coords",
",",... | // AddLine adds a LineString to the current calculation | [
"AddLine",
"adds",
"a",
"LineString",
"to",
"the",
"current",
"calculation"
] | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/xy/line_centroid.go#L90-L94 | train |
twpayne/go-geom | xy/line_centroid.go | AddLinearRing | func (calc *LineCentroidCalculator) AddLinearRing(line *geom.LinearRing) *LineCentroidCalculator {
coords := line.FlatCoords()
calc.addLine(coords, 0, len(coords))
return calc
} | go | func (calc *LineCentroidCalculator) AddLinearRing(line *geom.LinearRing) *LineCentroidCalculator {
coords := line.FlatCoords()
calc.addLine(coords, 0, len(coords))
return calc
} | [
"func",
"(",
"calc",
"*",
"LineCentroidCalculator",
")",
"AddLinearRing",
"(",
"line",
"*",
"geom",
".",
"LinearRing",
")",
"*",
"LineCentroidCalculator",
"{",
"coords",
":=",
"line",
".",
"FlatCoords",
"(",
")",
"\n",
"calc",
".",
"addLine",
"(",
"coords",
... | // AddLinearRing adds a LinearRing to the current calculation | [
"AddLinearRing",
"adds",
"a",
"LinearRing",
"to",
"the",
"current",
"calculation"
] | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/xy/line_centroid.go#L97-L101 | train |
twpayne/go-geom | xy/cga.go | IsOnLine | func IsOnLine(layout geom.Layout, point geom.Coord, lineSegmentCoordinates []float64) bool {
stride := layout.Stride()
if len(lineSegmentCoordinates) < (2 * stride) {
panic(fmt.Sprintf("At least two coordinates are required in the lineSegmentsCoordinates array in 'algorithms.IsOnLine', was: %v", lineSegmentCoordinates))
}
strategy := lineintersector.RobustLineIntersector{}
for i := stride; i < len(lineSegmentCoordinates); i += stride {
segmentStart := lineSegmentCoordinates[i-stride : i-stride+2]
segmentEnd := lineSegmentCoordinates[i : i+2]
if lineintersector.PointIntersectsLine(strategy, point, geom.Coord(segmentStart), geom.Coord(segmentEnd)) {
return true
}
}
return false
} | go | func IsOnLine(layout geom.Layout, point geom.Coord, lineSegmentCoordinates []float64) bool {
stride := layout.Stride()
if len(lineSegmentCoordinates) < (2 * stride) {
panic(fmt.Sprintf("At least two coordinates are required in the lineSegmentsCoordinates array in 'algorithms.IsOnLine', was: %v", lineSegmentCoordinates))
}
strategy := lineintersector.RobustLineIntersector{}
for i := stride; i < len(lineSegmentCoordinates); i += stride {
segmentStart := lineSegmentCoordinates[i-stride : i-stride+2]
segmentEnd := lineSegmentCoordinates[i : i+2]
if lineintersector.PointIntersectsLine(strategy, point, geom.Coord(segmentStart), geom.Coord(segmentEnd)) {
return true
}
}
return false
} | [
"func",
"IsOnLine",
"(",
"layout",
"geom",
".",
"Layout",
",",
"point",
"geom",
".",
"Coord",
",",
"lineSegmentCoordinates",
"[",
"]",
"float64",
")",
"bool",
"{",
"stride",
":=",
"layout",
".",
"Stride",
"(",
")",
"\n",
"if",
"len",
"(",
"lineSegmentCoo... | // IsOnLine tests whether a point lies on the line segments defined by a list of
// coordinates.
//
// Returns true if the point is a vertex of the line or lies in the interior
// of a line segment in the linestring | [
"IsOnLine",
"tests",
"whether",
"a",
"point",
"lies",
"on",
"the",
"line",
"segments",
"defined",
"by",
"a",
"list",
"of",
"coordinates",
".",
"Returns",
"true",
"if",
"the",
"point",
"is",
"a",
"vertex",
"of",
"the",
"line",
"or",
"lies",
"in",
"the",
... | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/xy/cga.go#L63-L79 | train |
twpayne/go-geom | xy/cga.go | DistanceFromPointToLineString | func DistanceFromPointToLineString(layout geom.Layout, p geom.Coord, line []float64) float64 {
if len(line) < 2 {
panic(fmt.Sprintf("Line array must contain at least one vertex: %v", line))
}
// this handles the case of length = 1
firstPoint := line[0:2]
minDistance := internal.Distance2D(p, firstPoint)
stride := layout.Stride()
for i := 0; i < len(line)-stride; i += stride {
point1 := geom.Coord(line[i : i+2])
point2 := geom.Coord(line[i+stride : i+stride+2])
dist := DistanceFromPointToLine(p, point1, point2)
if dist < minDistance {
minDistance = dist
}
}
return minDistance
} | go | func DistanceFromPointToLineString(layout geom.Layout, p geom.Coord, line []float64) float64 {
if len(line) < 2 {
panic(fmt.Sprintf("Line array must contain at least one vertex: %v", line))
}
// this handles the case of length = 1
firstPoint := line[0:2]
minDistance := internal.Distance2D(p, firstPoint)
stride := layout.Stride()
for i := 0; i < len(line)-stride; i += stride {
point1 := geom.Coord(line[i : i+2])
point2 := geom.Coord(line[i+stride : i+stride+2])
dist := DistanceFromPointToLine(p, point1, point2)
if dist < minDistance {
minDistance = dist
}
}
return minDistance
} | [
"func",
"DistanceFromPointToLineString",
"(",
"layout",
"geom",
".",
"Layout",
",",
"p",
"geom",
".",
"Coord",
",",
"line",
"[",
"]",
"float64",
")",
"float64",
"{",
"if",
"len",
"(",
"line",
")",
"<",
"2",
"{",
"panic",
"(",
"fmt",
".",
"Sprintf",
"... | // DistanceFromPointToLineString computes the distance from a point to a sequence of line segments.
//
// Param p - a point
// Param line - a sequence of contiguous line segments defined by their vertices | [
"DistanceFromPointToLineString",
"computes",
"the",
"distance",
"from",
"a",
"point",
"to",
"a",
"sequence",
"of",
"line",
"segments",
".",
"Param",
"p",
"-",
"a",
"point",
"Param",
"line",
"-",
"a",
"sequence",
"of",
"contiguous",
"line",
"segments",
"defined... | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/xy/cga.go#L231-L248 | train |
twpayne/go-geom | xy/cga.go | SignedArea | func SignedArea(layout geom.Layout, ring []float64) float64 {
stride := layout.Stride()
if len(ring) < 3*stride {
return 0.0
}
sum := 0.0
// Based on the Shoelace formula.
// http://en.wikipedia.org/wiki/Shoelace_formula
x0 := ring[0]
lenMinusOnePoint := len(ring) - stride
for i := stride; i < lenMinusOnePoint; i += stride {
x := ring[i] - x0
y1 := ring[i+stride+1]
y2 := ring[i-stride+1]
sum += x * (y2 - y1)
}
return sum / 2.0
} | go | func SignedArea(layout geom.Layout, ring []float64) float64 {
stride := layout.Stride()
if len(ring) < 3*stride {
return 0.0
}
sum := 0.0
// Based on the Shoelace formula.
// http://en.wikipedia.org/wiki/Shoelace_formula
x0 := ring[0]
lenMinusOnePoint := len(ring) - stride
for i := stride; i < lenMinusOnePoint; i += stride {
x := ring[i] - x0
y1 := ring[i+stride+1]
y2 := ring[i-stride+1]
sum += x * (y2 - y1)
}
return sum / 2.0
} | [
"func",
"SignedArea",
"(",
"layout",
"geom",
".",
"Layout",
",",
"ring",
"[",
"]",
"float64",
")",
"float64",
"{",
"stride",
":=",
"layout",
".",
"Stride",
"(",
")",
"\n",
"if",
"len",
"(",
"ring",
")",
"<",
"3",
"*",
"stride",
"{",
"return",
"0.0"... | // SignedArea computes the signed area for a ring. The signed area is positive if the
// ring is oriented CW, negative if the ring is oriented CCW, and zero if the
// ring is degenerate or flat. | [
"SignedArea",
"computes",
"the",
"signed",
"area",
"for",
"a",
"ring",
".",
"The",
"signed",
"area",
"is",
"positive",
"if",
"the",
"ring",
"is",
"oriented",
"CW",
"negative",
"if",
"the",
"ring",
"is",
"oriented",
"CCW",
"and",
"zero",
"if",
"the",
"rin... | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/xy/cga.go#L328-L345 | train |
twpayne/go-geom | xy/cga.go | Distance | func Distance(c1, c2 geom.Coord) float64 {
return internal.Distance2D(c1, c2)
} | go | func Distance(c1, c2 geom.Coord) float64 {
return internal.Distance2D(c1, c2)
} | [
"func",
"Distance",
"(",
"c1",
",",
"c2",
"geom",
".",
"Coord",
")",
"float64",
"{",
"return",
"internal",
".",
"Distance2D",
"(",
"c1",
",",
"c2",
")",
"\n",
"}"
] | // Distance calculates the 2d distance between the two coordinates | [
"Distance",
"calculates",
"the",
"2d",
"distance",
"between",
"the",
"two",
"coordinates"
] | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/xy/cga.go#L369-L371 | train |
twpayne/go-geom | xy/convex_hull.go | ConvexHull | func ConvexHull(geometry geom.T) geom.T {
// copy coords because the algorithm reorders them
calc := convexHullCalculator{
layout: geometry.Layout(),
stride: geometry.Layout().Stride(),
inputPts: geometry.FlatCoords(),
}
return calc.getConvexHull()
} | go | func ConvexHull(geometry geom.T) geom.T {
// copy coords because the algorithm reorders them
calc := convexHullCalculator{
layout: geometry.Layout(),
stride: geometry.Layout().Stride(),
inputPts: geometry.FlatCoords(),
}
return calc.getConvexHull()
} | [
"func",
"ConvexHull",
"(",
"geometry",
"geom",
".",
"T",
")",
"geom",
".",
"T",
"{",
"// copy coords because the algorithm reorders them",
"calc",
":=",
"convexHullCalculator",
"{",
"layout",
":",
"geometry",
".",
"Layout",
"(",
")",
",",
"stride",
":",
"geometr... | // ConvexHull computes the convex hull of the geometry.
// A convex hull is the smallest convex geometry that contains
// all the points in the input geometry
// Uses the Graham Scan algorithm | [
"ConvexHull",
"computes",
"the",
"convex",
"hull",
"of",
"the",
"geometry",
".",
"A",
"convex",
"hull",
"is",
"the",
"smallest",
"convex",
"geometry",
"that",
"contains",
"all",
"the",
"points",
"in",
"the",
"input",
"geometry",
"Uses",
"the",
"Graham",
"Sca... | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/xy/convex_hull.go#L24-L33 | train |
twpayne/go-geom | xy/convex_hull.go | ConvexHullFlat | func ConvexHullFlat(layout geom.Layout, coords []float64) geom.T {
calc := convexHullCalculator{
inputPts: coords,
layout: layout,
stride: layout.Stride(),
}
return calc.getConvexHull()
} | go | func ConvexHullFlat(layout geom.Layout, coords []float64) geom.T {
calc := convexHullCalculator{
inputPts: coords,
layout: layout,
stride: layout.Stride(),
}
return calc.getConvexHull()
} | [
"func",
"ConvexHullFlat",
"(",
"layout",
"geom",
".",
"Layout",
",",
"coords",
"[",
"]",
"float64",
")",
"geom",
".",
"T",
"{",
"calc",
":=",
"convexHullCalculator",
"{",
"inputPts",
":",
"coords",
",",
"layout",
":",
"layout",
",",
"stride",
":",
"layou... | // ConvexHullFlat computes the convex hull of the geometry.
// A convex hull is the smallest convex geometry that contains
// all the points in the input coordinates
// Uses the Graham Scan algorithm | [
"ConvexHullFlat",
"computes",
"the",
"convex",
"hull",
"of",
"the",
"geometry",
".",
"A",
"convex",
"hull",
"is",
"the",
"smallest",
"convex",
"geometry",
"that",
"contains",
"all",
"the",
"points",
"in",
"the",
"input",
"coordinates",
"Uses",
"the",
"Graham",... | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/xy/convex_hull.go#L39-L46 | train |
twpayne/go-geom | flat.go | Bounds | func (g *geom0) Bounds() *Bounds {
return NewBounds(g.layout).extendFlatCoords(g.flatCoords, 0, len(g.flatCoords), g.stride)
} | go | func (g *geom0) Bounds() *Bounds {
return NewBounds(g.layout).extendFlatCoords(g.flatCoords, 0, len(g.flatCoords), g.stride)
} | [
"func",
"(",
"g",
"*",
"geom0",
")",
"Bounds",
"(",
")",
"*",
"Bounds",
"{",
"return",
"NewBounds",
"(",
"g",
".",
"layout",
")",
".",
"extendFlatCoords",
"(",
"g",
".",
"flatCoords",
",",
"0",
",",
"len",
"(",
"g",
".",
"flatCoords",
")",
",",
"... | // Bounds returns the bounds of g. | [
"Bounds",
"returns",
"the",
"bounds",
"of",
"g",
"."
] | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/flat.go#L27-L29 | train |
twpayne/go-geom | flat.go | Coords | func (g *geom0) Coords() Coord {
return inflate0(g.flatCoords, 0, len(g.flatCoords), g.stride)
} | go | func (g *geom0) Coords() Coord {
return inflate0(g.flatCoords, 0, len(g.flatCoords), g.stride)
} | [
"func",
"(",
"g",
"*",
"geom0",
")",
"Coords",
"(",
")",
"Coord",
"{",
"return",
"inflate0",
"(",
"g",
".",
"flatCoords",
",",
"0",
",",
"len",
"(",
"g",
".",
"flatCoords",
")",
",",
"g",
".",
"stride",
")",
"\n",
"}"
] | // Coords returns all the coordinates in g, i.e. a single coordinate. | [
"Coords",
"returns",
"all",
"the",
"coordinates",
"in",
"g",
"i",
".",
"e",
".",
"a",
"single",
"coordinate",
"."
] | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/flat.go#L32-L34 | train |
twpayne/go-geom | flat.go | Reserve | func (g *geom0) Reserve(n int) {
if cap(g.flatCoords) < n*g.stride {
fcs := make([]float64, len(g.flatCoords), n*g.stride)
copy(fcs, g.flatCoords)
g.flatCoords = fcs
}
} | go | func (g *geom0) Reserve(n int) {
if cap(g.flatCoords) < n*g.stride {
fcs := make([]float64, len(g.flatCoords), n*g.stride)
copy(fcs, g.flatCoords)
g.flatCoords = fcs
}
} | [
"func",
"(",
"g",
"*",
"geom0",
")",
"Reserve",
"(",
"n",
"int",
")",
"{",
"if",
"cap",
"(",
"g",
".",
"flatCoords",
")",
"<",
"n",
"*",
"g",
".",
"stride",
"{",
"fcs",
":=",
"make",
"(",
"[",
"]",
"float64",
",",
"len",
"(",
"g",
".",
"fla... | // Reserve reserves space in g for n coordinates. | [
"Reserve",
"reserves",
"space",
"in",
"g",
"for",
"n",
"coordinates",
"."
] | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/flat.go#L63-L69 | train |
twpayne/go-geom | flat.go | Coord | func (g *geom1) Coord(i int) Coord {
return g.flatCoords[i*g.stride : (i+1)*g.stride]
} | go | func (g *geom1) Coord(i int) Coord {
return g.flatCoords[i*g.stride : (i+1)*g.stride]
} | [
"func",
"(",
"g",
"*",
"geom1",
")",
"Coord",
"(",
"i",
"int",
")",
"Coord",
"{",
"return",
"g",
".",
"flatCoords",
"[",
"i",
"*",
"g",
".",
"stride",
":",
"(",
"i",
"+",
"1",
")",
"*",
"g",
".",
"stride",
"]",
"\n",
"}"
] | // Coord returns the ith coord of g. | [
"Coord",
"returns",
"the",
"ith",
"coord",
"of",
"g",
"."
] | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/flat.go#L104-L106 | train |
twpayne/go-geom | flat.go | Coords | func (g *geom1) Coords() []Coord {
return inflate1(g.flatCoords, 0, len(g.flatCoords), g.stride)
} | go | func (g *geom1) Coords() []Coord {
return inflate1(g.flatCoords, 0, len(g.flatCoords), g.stride)
} | [
"func",
"(",
"g",
"*",
"geom1",
")",
"Coords",
"(",
")",
"[",
"]",
"Coord",
"{",
"return",
"inflate1",
"(",
"g",
".",
"flatCoords",
",",
"0",
",",
"len",
"(",
"g",
".",
"flatCoords",
")",
",",
"g",
".",
"stride",
")",
"\n",
"}"
] | // Coords unpacks and returns all of g's coordinates. | [
"Coords",
"unpacks",
"and",
"returns",
"all",
"of",
"g",
"s",
"coordinates",
"."
] | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/flat.go#L109-L111 | train |
twpayne/go-geom | flat.go | Coords | func (g *geom2) Coords() [][]Coord {
return inflate2(g.flatCoords, 0, g.ends, g.stride)
} | go | func (g *geom2) Coords() [][]Coord {
return inflate2(g.flatCoords, 0, g.ends, g.stride)
} | [
"func",
"(",
"g",
"*",
"geom2",
")",
"Coords",
"(",
")",
"[",
"]",
"[",
"]",
"Coord",
"{",
"return",
"inflate2",
"(",
"g",
".",
"flatCoords",
",",
"0",
",",
"g",
".",
"ends",
",",
"g",
".",
"stride",
")",
"\n",
"}"
] | // Coords returns all of g's coordinates. | [
"Coords",
"returns",
"all",
"of",
"g",
"s",
"coordinates",
"."
] | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/flat.go#L141-L143 | train |
twpayne/go-geom | flat.go | Coords | func (g *geom3) Coords() [][][]Coord {
return inflate3(g.flatCoords, 0, g.endss, g.stride)
} | go | func (g *geom3) Coords() [][][]Coord {
return inflate3(g.flatCoords, 0, g.endss, g.stride)
} | [
"func",
"(",
"g",
"*",
"geom3",
")",
"Coords",
"(",
")",
"[",
"]",
"[",
"]",
"[",
"]",
"Coord",
"{",
"return",
"inflate3",
"(",
"g",
".",
"flatCoords",
",",
"0",
",",
"g",
".",
"endss",
",",
"g",
".",
"stride",
")",
"\n",
"}"
] | // Coords returns all the coordinates in g. | [
"Coords",
"returns",
"all",
"the",
"coordinates",
"in",
"g",
"."
] | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/flat.go#L189-L191 | train |
twpayne/go-geom | xyz/vector.go | VectorDot | func VectorDot(v1Start, v1End, v2Start, v2End geom.Coord) float64 {
v1Startv2Endx := v1End[0] - v1Start[0]
v1Startv2Endy := v1End[1] - v1Start[1]
v1Startv2Endz := v1End[2] - v1Start[2]
v2Startv2Endx := v2End[0] - v2Start[0]
v2Startv2Endy := v2End[1] - v2Start[1]
v2Startv2Endz := v2End[2] - v2Start[2]
return v1Startv2Endx*v2Startv2Endx + v1Startv2Endy*v2Startv2Endy + v1Startv2Endz*v2Startv2Endz
} | go | func VectorDot(v1Start, v1End, v2Start, v2End geom.Coord) float64 {
v1Startv2Endx := v1End[0] - v1Start[0]
v1Startv2Endy := v1End[1] - v1Start[1]
v1Startv2Endz := v1End[2] - v1Start[2]
v2Startv2Endx := v2End[0] - v2Start[0]
v2Startv2Endy := v2End[1] - v2Start[1]
v2Startv2Endz := v2End[2] - v2Start[2]
return v1Startv2Endx*v2Startv2Endx + v1Startv2Endy*v2Startv2Endy + v1Startv2Endz*v2Startv2Endz
} | [
"func",
"VectorDot",
"(",
"v1Start",
",",
"v1End",
",",
"v2Start",
",",
"v2End",
"geom",
".",
"Coord",
")",
"float64",
"{",
"v1Startv2Endx",
":=",
"v1End",
"[",
"0",
"]",
"-",
"v1Start",
"[",
"0",
"]",
"\n",
"v1Startv2Endy",
":=",
"v1End",
"[",
"1",
... | // VectorDot calculates the dot product of two vectors | [
"VectorDot",
"calculates",
"the",
"dot",
"product",
"of",
"two",
"vectors"
] | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/xyz/vector.go#L10-L18 | train |
twpayne/go-geom | xyz/vector.go | VectorNormalize | func VectorNormalize(vector geom.Coord) geom.Coord {
vLen := VectorLength(vector)
return geom.Coord{vector[0] / vLen, vector[1] / vLen, vector[2] / vLen}
} | go | func VectorNormalize(vector geom.Coord) geom.Coord {
vLen := VectorLength(vector)
return geom.Coord{vector[0] / vLen, vector[1] / vLen, vector[2] / vLen}
} | [
"func",
"VectorNormalize",
"(",
"vector",
"geom",
".",
"Coord",
")",
"geom",
".",
"Coord",
"{",
"vLen",
":=",
"VectorLength",
"(",
"vector",
")",
"\n",
"return",
"geom",
".",
"Coord",
"{",
"vector",
"[",
"0",
"]",
"/",
"vLen",
",",
"vector",
"[",
"1"... | // VectorNormalize creates a coordinate that is the normalized vector from 0,0,0 to vector | [
"VectorNormalize",
"creates",
"a",
"coordinate",
"that",
"is",
"the",
"normalized",
"vector",
"from",
"0",
"0",
"0",
"to",
"vector"
] | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/xyz/vector.go#L21-L24 | train |
twpayne/go-geom | xyz/vector.go | VectorLength | func VectorLength(vector geom.Coord) float64 {
return math.Sqrt(vector[0]*vector[0] + vector[1]*vector[1] + vector[2]*vector[2])
} | go | func VectorLength(vector geom.Coord) float64 {
return math.Sqrt(vector[0]*vector[0] + vector[1]*vector[1] + vector[2]*vector[2])
} | [
"func",
"VectorLength",
"(",
"vector",
"geom",
".",
"Coord",
")",
"float64",
"{",
"return",
"math",
".",
"Sqrt",
"(",
"vector",
"[",
"0",
"]",
"*",
"vector",
"[",
"0",
"]",
"+",
"vector",
"[",
"1",
"]",
"*",
"vector",
"[",
"1",
"]",
"+",
"vector"... | // VectorLength calculates the length of the vector from 0,0,0 to vector | [
"VectorLength",
"calculates",
"the",
"length",
"of",
"the",
"vector",
"from",
"0",
"0",
"0",
"to",
"vector"
] | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/xyz/vector.go#L27-L29 | train |
twpayne/go-geom | encoding/kml/kml.go | Encode | func Encode(g geom.T) (kml.Element, error) {
switch g := g.(type) {
case *geom.Point:
return EncodePoint(g), nil
case *geom.LineString:
return EncodeLineString(g), nil
case *geom.LinearRing:
return EncodeLinearRing(g), nil
case *geom.MultiLineString:
return EncodeMultiLineString(g), nil
case *geom.MultiPoint:
return EncodeMultiPoint(g), nil
case *geom.MultiPolygon:
return EncodeMultiPolygon(g), nil
case *geom.Polygon:
return EncodePolygon(g), nil
case *geom.GeometryCollection:
return EncodeGeometryCollection(g)
default:
return nil, geom.ErrUnsupportedType{Value: g}
}
} | go | func Encode(g geom.T) (kml.Element, error) {
switch g := g.(type) {
case *geom.Point:
return EncodePoint(g), nil
case *geom.LineString:
return EncodeLineString(g), nil
case *geom.LinearRing:
return EncodeLinearRing(g), nil
case *geom.MultiLineString:
return EncodeMultiLineString(g), nil
case *geom.MultiPoint:
return EncodeMultiPoint(g), nil
case *geom.MultiPolygon:
return EncodeMultiPolygon(g), nil
case *geom.Polygon:
return EncodePolygon(g), nil
case *geom.GeometryCollection:
return EncodeGeometryCollection(g)
default:
return nil, geom.ErrUnsupportedType{Value: g}
}
} | [
"func",
"Encode",
"(",
"g",
"geom",
".",
"T",
")",
"(",
"kml",
".",
"Element",
",",
"error",
")",
"{",
"switch",
"g",
":=",
"g",
".",
"(",
"type",
")",
"{",
"case",
"*",
"geom",
".",
"Point",
":",
"return",
"EncodePoint",
"(",
"g",
")",
",",
... | // Encode encodes an arbitrary geometry. | [
"Encode",
"encodes",
"an",
"arbitrary",
"geometry",
"."
] | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/encoding/kml/kml.go#L10-L31 | train |
twpayne/go-geom | encoding/kml/kml.go | EncodeLineString | func EncodeLineString(ls *geom.LineString) kml.Element {
flatCoords := ls.FlatCoords()
return kml.LineString(kml.CoordinatesFlat(flatCoords, 0, len(flatCoords), ls.Stride(), dim(ls.Layout())))
} | go | func EncodeLineString(ls *geom.LineString) kml.Element {
flatCoords := ls.FlatCoords()
return kml.LineString(kml.CoordinatesFlat(flatCoords, 0, len(flatCoords), ls.Stride(), dim(ls.Layout())))
} | [
"func",
"EncodeLineString",
"(",
"ls",
"*",
"geom",
".",
"LineString",
")",
"kml",
".",
"Element",
"{",
"flatCoords",
":=",
"ls",
".",
"FlatCoords",
"(",
")",
"\n",
"return",
"kml",
".",
"LineString",
"(",
"kml",
".",
"CoordinatesFlat",
"(",
"flatCoords",
... | // EncodeLineString encodes a LineString. | [
"EncodeLineString",
"encodes",
"a",
"LineString",
"."
] | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/encoding/kml/kml.go#L34-L37 | train |
twpayne/go-geom | encoding/kml/kml.go | EncodeLinearRing | func EncodeLinearRing(lr *geom.LinearRing) kml.Element {
flatCoords := lr.FlatCoords()
return kml.LinearRing(kml.CoordinatesFlat(flatCoords, 0, len(flatCoords), lr.Stride(), dim(lr.Layout())))
} | go | func EncodeLinearRing(lr *geom.LinearRing) kml.Element {
flatCoords := lr.FlatCoords()
return kml.LinearRing(kml.CoordinatesFlat(flatCoords, 0, len(flatCoords), lr.Stride(), dim(lr.Layout())))
} | [
"func",
"EncodeLinearRing",
"(",
"lr",
"*",
"geom",
".",
"LinearRing",
")",
"kml",
".",
"Element",
"{",
"flatCoords",
":=",
"lr",
".",
"FlatCoords",
"(",
")",
"\n",
"return",
"kml",
".",
"LinearRing",
"(",
"kml",
".",
"CoordinatesFlat",
"(",
"flatCoords",
... | // EncodeLinearRing encodes a LinearRing. | [
"EncodeLinearRing",
"encodes",
"a",
"LinearRing",
"."
] | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/encoding/kml/kml.go#L40-L43 | train |
twpayne/go-geom | encoding/kml/kml.go | EncodeMultiLineString | func EncodeMultiLineString(mls *geom.MultiLineString) kml.Element {
lineStrings := make([]kml.Element, mls.NumLineStrings())
flatCoords := mls.FlatCoords()
ends := mls.Ends()
stride := mls.Stride()
d := dim(mls.Layout())
offset := 0
for i, end := range ends {
lineStrings[i] = kml.LineString(kml.CoordinatesFlat(flatCoords, offset, end, stride, d))
offset = end
}
return kml.MultiGeometry(lineStrings...)
} | go | func EncodeMultiLineString(mls *geom.MultiLineString) kml.Element {
lineStrings := make([]kml.Element, mls.NumLineStrings())
flatCoords := mls.FlatCoords()
ends := mls.Ends()
stride := mls.Stride()
d := dim(mls.Layout())
offset := 0
for i, end := range ends {
lineStrings[i] = kml.LineString(kml.CoordinatesFlat(flatCoords, offset, end, stride, d))
offset = end
}
return kml.MultiGeometry(lineStrings...)
} | [
"func",
"EncodeMultiLineString",
"(",
"mls",
"*",
"geom",
".",
"MultiLineString",
")",
"kml",
".",
"Element",
"{",
"lineStrings",
":=",
"make",
"(",
"[",
"]",
"kml",
".",
"Element",
",",
"mls",
".",
"NumLineStrings",
"(",
")",
")",
"\n",
"flatCoords",
":... | // EncodeMultiLineString encodes a MultiLineString. | [
"EncodeMultiLineString",
"encodes",
"a",
"MultiLineString",
"."
] | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/encoding/kml/kml.go#L46-L58 | train |
twpayne/go-geom | encoding/kml/kml.go | EncodeMultiPoint | func EncodeMultiPoint(mp *geom.MultiPoint) kml.Element {
points := make([]kml.Element, mp.NumPoints())
flatCoords := mp.FlatCoords()
stride := mp.Stride()
d := dim(mp.Layout())
for i, offset, end := 0, 0, len(flatCoords); offset < end; i++ {
points[i] = kml.Point(kml.CoordinatesFlat(flatCoords, offset, offset+stride, stride, d))
offset += stride
}
return kml.MultiGeometry(points...)
} | go | func EncodeMultiPoint(mp *geom.MultiPoint) kml.Element {
points := make([]kml.Element, mp.NumPoints())
flatCoords := mp.FlatCoords()
stride := mp.Stride()
d := dim(mp.Layout())
for i, offset, end := 0, 0, len(flatCoords); offset < end; i++ {
points[i] = kml.Point(kml.CoordinatesFlat(flatCoords, offset, offset+stride, stride, d))
offset += stride
}
return kml.MultiGeometry(points...)
} | [
"func",
"EncodeMultiPoint",
"(",
"mp",
"*",
"geom",
".",
"MultiPoint",
")",
"kml",
".",
"Element",
"{",
"points",
":=",
"make",
"(",
"[",
"]",
"kml",
".",
"Element",
",",
"mp",
".",
"NumPoints",
"(",
")",
")",
"\n",
"flatCoords",
":=",
"mp",
".",
"... | // EncodeMultiPoint encodes a MultiPoint. | [
"EncodeMultiPoint",
"encodes",
"a",
"MultiPoint",
"."
] | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/encoding/kml/kml.go#L61-L71 | train |
twpayne/go-geom | encoding/kml/kml.go | EncodeMultiPolygon | func EncodeMultiPolygon(mp *geom.MultiPolygon) kml.Element {
polygons := make([]kml.Element, mp.NumPolygons())
flatCoords := mp.FlatCoords()
endss := mp.Endss()
stride := mp.Stride()
d := dim(mp.Layout())
offset := 0
for i, ends := range endss {
boundaries := make([]kml.Element, len(ends))
for j, end := range ends {
linearRing := kml.LinearRing(kml.CoordinatesFlat(flatCoords, offset, end, stride, d))
if j == 0 {
boundaries[j] = kml.OuterBoundaryIs(linearRing)
} else {
boundaries[j] = kml.InnerBoundaryIs(linearRing)
}
offset = end
}
polygons[i] = kml.Polygon(boundaries...)
}
return kml.MultiGeometry(polygons...)
} | go | func EncodeMultiPolygon(mp *geom.MultiPolygon) kml.Element {
polygons := make([]kml.Element, mp.NumPolygons())
flatCoords := mp.FlatCoords()
endss := mp.Endss()
stride := mp.Stride()
d := dim(mp.Layout())
offset := 0
for i, ends := range endss {
boundaries := make([]kml.Element, len(ends))
for j, end := range ends {
linearRing := kml.LinearRing(kml.CoordinatesFlat(flatCoords, offset, end, stride, d))
if j == 0 {
boundaries[j] = kml.OuterBoundaryIs(linearRing)
} else {
boundaries[j] = kml.InnerBoundaryIs(linearRing)
}
offset = end
}
polygons[i] = kml.Polygon(boundaries...)
}
return kml.MultiGeometry(polygons...)
} | [
"func",
"EncodeMultiPolygon",
"(",
"mp",
"*",
"geom",
".",
"MultiPolygon",
")",
"kml",
".",
"Element",
"{",
"polygons",
":=",
"make",
"(",
"[",
"]",
"kml",
".",
"Element",
",",
"mp",
".",
"NumPolygons",
"(",
")",
")",
"\n",
"flatCoords",
":=",
"mp",
... | // EncodeMultiPolygon encodes a MultiPolygon. | [
"EncodeMultiPolygon",
"encodes",
"a",
"MultiPolygon",
"."
] | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/encoding/kml/kml.go#L74-L95 | train |
twpayne/go-geom | encoding/kml/kml.go | EncodePoint | func EncodePoint(p *geom.Point) kml.Element {
flatCoords := p.FlatCoords()
return kml.Point(kml.CoordinatesFlat(flatCoords, 0, len(flatCoords), p.Stride(), dim(p.Layout())))
} | go | func EncodePoint(p *geom.Point) kml.Element {
flatCoords := p.FlatCoords()
return kml.Point(kml.CoordinatesFlat(flatCoords, 0, len(flatCoords), p.Stride(), dim(p.Layout())))
} | [
"func",
"EncodePoint",
"(",
"p",
"*",
"geom",
".",
"Point",
")",
"kml",
".",
"Element",
"{",
"flatCoords",
":=",
"p",
".",
"FlatCoords",
"(",
")",
"\n",
"return",
"kml",
".",
"Point",
"(",
"kml",
".",
"CoordinatesFlat",
"(",
"flatCoords",
",",
"0",
"... | // EncodePoint encodes a Point. | [
"EncodePoint",
"encodes",
"a",
"Point",
"."
] | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/encoding/kml/kml.go#L98-L101 | train |
twpayne/go-geom | encoding/kml/kml.go | EncodePolygon | func EncodePolygon(p *geom.Polygon) kml.Element {
boundaries := make([]kml.Element, p.NumLinearRings())
stride := p.Stride()
flatCoords := p.FlatCoords()
d := dim(p.Layout())
offset := 0
for i, end := range p.Ends() {
linearRing := kml.LinearRing(kml.CoordinatesFlat(flatCoords, offset, end, stride, d))
if i == 0 {
boundaries[i] = kml.OuterBoundaryIs(linearRing)
} else {
boundaries[i] = kml.InnerBoundaryIs(linearRing)
}
offset = end
}
return kml.Polygon(boundaries...)
} | go | func EncodePolygon(p *geom.Polygon) kml.Element {
boundaries := make([]kml.Element, p.NumLinearRings())
stride := p.Stride()
flatCoords := p.FlatCoords()
d := dim(p.Layout())
offset := 0
for i, end := range p.Ends() {
linearRing := kml.LinearRing(kml.CoordinatesFlat(flatCoords, offset, end, stride, d))
if i == 0 {
boundaries[i] = kml.OuterBoundaryIs(linearRing)
} else {
boundaries[i] = kml.InnerBoundaryIs(linearRing)
}
offset = end
}
return kml.Polygon(boundaries...)
} | [
"func",
"EncodePolygon",
"(",
"p",
"*",
"geom",
".",
"Polygon",
")",
"kml",
".",
"Element",
"{",
"boundaries",
":=",
"make",
"(",
"[",
"]",
"kml",
".",
"Element",
",",
"p",
".",
"NumLinearRings",
"(",
")",
")",
"\n",
"stride",
":=",
"p",
".",
"Stri... | // EncodePolygon encodes a Polygon. | [
"EncodePolygon",
"encodes",
"a",
"Polygon",
"."
] | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/encoding/kml/kml.go#L104-L120 | train |
twpayne/go-geom | encoding/kml/kml.go | EncodeGeometryCollection | func EncodeGeometryCollection(g *geom.GeometryCollection) (kml.Element, error) {
geometries := make([]kml.Element, g.NumGeoms())
for i, g := range g.Geoms() {
var err error
geometries[i], err = Encode(g)
if err != nil {
return nil, err
}
}
return kml.MultiGeometry(geometries...), nil
} | go | func EncodeGeometryCollection(g *geom.GeometryCollection) (kml.Element, error) {
geometries := make([]kml.Element, g.NumGeoms())
for i, g := range g.Geoms() {
var err error
geometries[i], err = Encode(g)
if err != nil {
return nil, err
}
}
return kml.MultiGeometry(geometries...), nil
} | [
"func",
"EncodeGeometryCollection",
"(",
"g",
"*",
"geom",
".",
"GeometryCollection",
")",
"(",
"kml",
".",
"Element",
",",
"error",
")",
"{",
"geometries",
":=",
"make",
"(",
"[",
"]",
"kml",
".",
"Element",
",",
"g",
".",
"NumGeoms",
"(",
")",
")",
... | // EncodeGeometryCollection encodes a GeometryCollection. | [
"EncodeGeometryCollection",
"encodes",
"a",
"GeometryCollection",
"."
] | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/encoding/kml/kml.go#L123-L133 | train |
twpayne/go-geom | multipoint.go | NewMultiPointFlat | func NewMultiPointFlat(layout Layout, flatCoords []float64) *MultiPoint {
g := new(MultiPoint)
g.layout = layout
g.stride = layout.Stride()
g.flatCoords = flatCoords
return g
} | go | func NewMultiPointFlat(layout Layout, flatCoords []float64) *MultiPoint {
g := new(MultiPoint)
g.layout = layout
g.stride = layout.Stride()
g.flatCoords = flatCoords
return g
} | [
"func",
"NewMultiPointFlat",
"(",
"layout",
"Layout",
",",
"flatCoords",
"[",
"]",
"float64",
")",
"*",
"MultiPoint",
"{",
"g",
":=",
"new",
"(",
"MultiPoint",
")",
"\n",
"g",
".",
"layout",
"=",
"layout",
"\n",
"g",
".",
"stride",
"=",
"layout",
".",
... | // NewMultiPointFlat returns a new MultiPoint with the given flat coordinates. | [
"NewMultiPointFlat",
"returns",
"a",
"new",
"MultiPoint",
"with",
"the",
"given",
"flat",
"coordinates",
"."
] | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/multipoint.go#L14-L20 | train |
twpayne/go-geom | multipoint.go | Point | func (g *MultiPoint) Point(i int) *Point {
return NewPointFlat(g.layout, g.Coord(i))
} | go | func (g *MultiPoint) Point(i int) *Point {
return NewPointFlat(g.layout, g.Coord(i))
} | [
"func",
"(",
"g",
"*",
"MultiPoint",
")",
"Point",
"(",
"i",
"int",
")",
"*",
"Point",
"{",
"return",
"NewPointFlat",
"(",
"g",
".",
"layout",
",",
"g",
".",
"Coord",
"(",
"i",
")",
")",
"\n",
"}"
] | // Point returns the ith Point. | [
"Point",
"returns",
"the",
"ith",
"Point",
"."
] | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/multipoint.go#L68-L70 | train |
twpayne/go-geom | multipoint.go | Push | func (g *MultiPoint) Push(p *Point) error {
if p.layout != g.layout {
return ErrLayoutMismatch{Got: p.layout, Want: g.layout}
}
g.flatCoords = append(g.flatCoords, p.flatCoords...)
return nil
} | go | func (g *MultiPoint) Push(p *Point) error {
if p.layout != g.layout {
return ErrLayoutMismatch{Got: p.layout, Want: g.layout}
}
g.flatCoords = append(g.flatCoords, p.flatCoords...)
return nil
} | [
"func",
"(",
"g",
"*",
"MultiPoint",
")",
"Push",
"(",
"p",
"*",
"Point",
")",
"error",
"{",
"if",
"p",
".",
"layout",
"!=",
"g",
".",
"layout",
"{",
"return",
"ErrLayoutMismatch",
"{",
"Got",
":",
"p",
".",
"layout",
",",
"Want",
":",
"g",
".",
... | // Push appends a point. | [
"Push",
"appends",
"a",
"point",
"."
] | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/multipoint.go#L73-L79 | train |
twpayne/go-geom | xy/area_centroid.go | NewAreaCentroidCalculator | func NewAreaCentroidCalculator(layout geom.Layout) *AreaCentroidCalculator {
return &AreaCentroidCalculator{
layout: layout,
stride: layout.Stride(),
centSum: geom.Coord(make([]float64, layout.Stride())),
triangleCent3: geom.Coord(make([]float64, layout.Stride())),
cg3: geom.Coord(make([]float64, layout.Stride())),
}
} | go | func NewAreaCentroidCalculator(layout geom.Layout) *AreaCentroidCalculator {
return &AreaCentroidCalculator{
layout: layout,
stride: layout.Stride(),
centSum: geom.Coord(make([]float64, layout.Stride())),
triangleCent3: geom.Coord(make([]float64, layout.Stride())),
cg3: geom.Coord(make([]float64, layout.Stride())),
}
} | [
"func",
"NewAreaCentroidCalculator",
"(",
"layout",
"geom",
".",
"Layout",
")",
"*",
"AreaCentroidCalculator",
"{",
"return",
"&",
"AreaCentroidCalculator",
"{",
"layout",
":",
"layout",
",",
"stride",
":",
"layout",
".",
"Stride",
"(",
")",
",",
"centSum",
":... | // NewAreaCentroidCalculator creates a new instance of the calculator.
// Once a calculator is created polygons can be added to it and the
// GetCentroid method can be used at any point to get the current centroid
// the centroid will naturally change each time a polygon is added | [
"NewAreaCentroidCalculator",
"creates",
"a",
"new",
"instance",
"of",
"the",
"calculator",
".",
"Once",
"a",
"calculator",
"is",
"created",
"polygons",
"can",
"be",
"added",
"to",
"it",
"and",
"the",
"GetCentroid",
"method",
"can",
"be",
"used",
"at",
"any",
... | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/xy/area_centroid.go#L72-L80 | train |
twpayne/go-geom | xy/area_centroid.go | AddPolygon | func (calc *AreaCentroidCalculator) AddPolygon(polygon *geom.Polygon) {
calc.setBasePoint(polygon.Coord(0))
calc.addShell(polygon.LinearRing(0).FlatCoords())
for i := 1; i < polygon.NumLinearRings(); i++ {
calc.addHole(polygon.LinearRing(i).FlatCoords())
}
} | go | func (calc *AreaCentroidCalculator) AddPolygon(polygon *geom.Polygon) {
calc.setBasePoint(polygon.Coord(0))
calc.addShell(polygon.LinearRing(0).FlatCoords())
for i := 1; i < polygon.NumLinearRings(); i++ {
calc.addHole(polygon.LinearRing(i).FlatCoords())
}
} | [
"func",
"(",
"calc",
"*",
"AreaCentroidCalculator",
")",
"AddPolygon",
"(",
"polygon",
"*",
"geom",
".",
"Polygon",
")",
"{",
"calc",
".",
"setBasePoint",
"(",
"polygon",
".",
"Coord",
"(",
"0",
")",
")",
"\n\n",
"calc",
".",
"addShell",
"(",
"polygon",
... | // AddPolygon adds a polygon to the calculation. | [
"AddPolygon",
"adds",
"a",
"polygon",
"to",
"the",
"calculation",
"."
] | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/xy/area_centroid.go#L102-L109 | train |
twpayne/go-geom | xy/area_centroid.go | centroid3 | func centroid3(p1, p2, p3, c geom.Coord) {
c[0] = p1[0] + p2[0] + p3[0]
c[1] = p1[1] + p2[1] + p3[1]
} | go | func centroid3(p1, p2, p3, c geom.Coord) {
c[0] = p1[0] + p2[0] + p3[0]
c[1] = p1[1] + p2[1] + p3[1]
} | [
"func",
"centroid3",
"(",
"p1",
",",
"p2",
",",
"p3",
",",
"c",
"geom",
".",
"Coord",
")",
"{",
"c",
"[",
"0",
"]",
"=",
"p1",
"[",
"0",
"]",
"+",
"p2",
"[",
"0",
"]",
"+",
"p3",
"[",
"0",
"]",
"\n",
"c",
"[",
"1",
"]",
"=",
"p1",
"["... | // Returns three times the centroid of the triangle p1-p2-p3.
// The factor of 3 is left in to permit division to be avoided until later. | [
"Returns",
"three",
"times",
"the",
"centroid",
"of",
"the",
"triangle",
"p1",
"-",
"p2",
"-",
"p3",
".",
"The",
"factor",
"of",
"3",
"is",
"left",
"in",
"to",
"permit",
"division",
"to",
"be",
"avoided",
"until",
"later",
"."
] | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/xy/area_centroid.go#L165-L168 | train |
twpayne/go-geom | xy/area_centroid.go | area2 | func area2(p1, p2, p3 geom.Coord) float64 {
return (p2[0]-p1[0])*(p3[1]-p1[1]) - (p3[0]-p1[0])*(p2[1]-p1[1])
} | go | func area2(p1, p2, p3 geom.Coord) float64 {
return (p2[0]-p1[0])*(p3[1]-p1[1]) - (p3[0]-p1[0])*(p2[1]-p1[1])
} | [
"func",
"area2",
"(",
"p1",
",",
"p2",
",",
"p3",
"geom",
".",
"Coord",
")",
"float64",
"{",
"return",
"(",
"p2",
"[",
"0",
"]",
"-",
"p1",
"[",
"0",
"]",
")",
"*",
"(",
"p3",
"[",
"1",
"]",
"-",
"p1",
"[",
"1",
"]",
")",
"-",
"(",
"p3"... | // Returns twice the signed area of the triangle p1-p2-p3,
// positive if a,b,c are oriented ccw, and negative if cw. | [
"Returns",
"twice",
"the",
"signed",
"area",
"of",
"the",
"triangle",
"p1",
"-",
"p2",
"-",
"p3",
"positive",
"if",
"a",
"b",
"c",
"are",
"oriented",
"ccw",
"and",
"negative",
"if",
"cw",
"."
] | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/xy/area_centroid.go#L172-L174 | train |
twpayne/go-geom | xy/radial_comparator.go | NewRadialSorting | func NewRadialSorting(layout geom.Layout, coordData []float64, focalPoint geom.Coord) sort.Interface {
isLess := func(v1, v2 []float64) bool {
orient := bigxy.OrientationIndex(focalPoint, v1, v2)
if orient == orientation.CounterClockwise {
return false
}
if orient == orientation.Clockwise {
return true
}
dxp := v1[0] - focalPoint[0]
dyp := v1[1] - focalPoint[1]
dxq := v2[0] - focalPoint[0]
dyq := v2[1] - focalPoint[1]
// points are collinear - check distance
op := dxp*dxp + dyp*dyp
oq := dxq*dxq + dyq*dyq
return op < oq
}
return sorting.NewFlatCoordSorting(layout, coordData, isLess)
} | go | func NewRadialSorting(layout geom.Layout, coordData []float64, focalPoint geom.Coord) sort.Interface {
isLess := func(v1, v2 []float64) bool {
orient := bigxy.OrientationIndex(focalPoint, v1, v2)
if orient == orientation.CounterClockwise {
return false
}
if orient == orientation.Clockwise {
return true
}
dxp := v1[0] - focalPoint[0]
dyp := v1[1] - focalPoint[1]
dxq := v2[0] - focalPoint[0]
dyq := v2[1] - focalPoint[1]
// points are collinear - check distance
op := dxp*dxp + dyp*dyp
oq := dxq*dxq + dyq*dyq
return op < oq
}
return sorting.NewFlatCoordSorting(layout, coordData, isLess)
} | [
"func",
"NewRadialSorting",
"(",
"layout",
"geom",
".",
"Layout",
",",
"coordData",
"[",
"]",
"float64",
",",
"focalPoint",
"geom",
".",
"Coord",
")",
"sort",
".",
"Interface",
"{",
"isLess",
":=",
"func",
"(",
"v1",
",",
"v2",
"[",
"]",
"float64",
")"... | // NewRadialSorting creates an implementation sort.Interface which will sort the wrapped coordinate array
// radially around the focal point. The comparison is based on the angle and distance
// from the focal point.
// First the angle is checked.
// Counter clockwise indicates a greater value and clockwise indicates a lesser value
// If co-linear then the coordinate nearer to the focalPoint is considered less. | [
"NewRadialSorting",
"creates",
"an",
"implementation",
"sort",
".",
"Interface",
"which",
"will",
"sort",
"the",
"wrapped",
"coordinate",
"array",
"radially",
"around",
"the",
"focal",
"point",
".",
"The",
"comparison",
"is",
"based",
"on",
"the",
"angle",
"and"... | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/xy/radial_comparator.go#L18-L40 | train |
twpayne/go-geom | encoding/wkbcommon/binary.go | ReadUInt32 | func ReadUInt32(r io.Reader, byteOrder binary.ByteOrder) (uint32, error) {
var buf [4]byte
if _, err := io.ReadFull(r, buf[:]); err != nil {
return 0, err
}
return byteOrder.Uint32(buf[:]), nil
} | go | func ReadUInt32(r io.Reader, byteOrder binary.ByteOrder) (uint32, error) {
var buf [4]byte
if _, err := io.ReadFull(r, buf[:]); err != nil {
return 0, err
}
return byteOrder.Uint32(buf[:]), nil
} | [
"func",
"ReadUInt32",
"(",
"r",
"io",
".",
"Reader",
",",
"byteOrder",
"binary",
".",
"ByteOrder",
")",
"(",
"uint32",
",",
"error",
")",
"{",
"var",
"buf",
"[",
"4",
"]",
"byte",
"\n",
"if",
"_",
",",
"err",
":=",
"io",
".",
"ReadFull",
"(",
"r"... | // ReadUInt32 reads a uint32 from r. | [
"ReadUInt32",
"reads",
"a",
"uint32",
"from",
"r",
"."
] | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/encoding/wkbcommon/binary.go#L16-L22 | train |
twpayne/go-geom | encoding/wkbcommon/binary.go | ReadByte | func ReadByte(r io.Reader) (byte, error) {
var buf [1]byte
if _, err := r.Read(buf[:]); err != nil {
return 0, err
}
return buf[0], nil
} | go | func ReadByte(r io.Reader) (byte, error) {
var buf [1]byte
if _, err := r.Read(buf[:]); err != nil {
return 0, err
}
return buf[0], nil
} | [
"func",
"ReadByte",
"(",
"r",
"io",
".",
"Reader",
")",
"(",
"byte",
",",
"error",
")",
"{",
"var",
"buf",
"[",
"1",
"]",
"byte",
"\n",
"if",
"_",
",",
"err",
":=",
"r",
".",
"Read",
"(",
"buf",
"[",
":",
"]",
")",
";",
"err",
"!=",
"nil",
... | // ReadByte reads a byte from r. | [
"ReadByte",
"reads",
"a",
"byte",
"from",
"r",
"."
] | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/encoding/wkbcommon/binary.go#L38-L44 | train |
twpayne/go-geom | encoding/wkbcommon/binary.go | WriteUInt32 | func WriteUInt32(w io.Writer, byteOrder binary.ByteOrder, value uint32) error {
var buf [4]byte
byteOrder.PutUint32(buf[:], value)
_, err := w.Write(buf[:])
return err
} | go | func WriteUInt32(w io.Writer, byteOrder binary.ByteOrder, value uint32) error {
var buf [4]byte
byteOrder.PutUint32(buf[:], value)
_, err := w.Write(buf[:])
return err
} | [
"func",
"WriteUInt32",
"(",
"w",
"io",
".",
"Writer",
",",
"byteOrder",
"binary",
".",
"ByteOrder",
",",
"value",
"uint32",
")",
"error",
"{",
"var",
"buf",
"[",
"4",
"]",
"byte",
"\n",
"byteOrder",
".",
"PutUint32",
"(",
"buf",
"[",
":",
"]",
",",
... | // WriteUInt32 writes a uint32 to w. | [
"WriteUInt32",
"writes",
"a",
"uint32",
"to",
"w",
"."
] | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/encoding/wkbcommon/binary.go#L62-L67 | train |
twpayne/go-geom | encoding/wkbcommon/binary.go | WriteByte | func WriteByte(w io.Writer, value byte) error {
var buf [1]byte
buf[0] = value
_, err := w.Write(buf[:])
return err
} | go | func WriteByte(w io.Writer, value byte) error {
var buf [1]byte
buf[0] = value
_, err := w.Write(buf[:])
return err
} | [
"func",
"WriteByte",
"(",
"w",
"io",
".",
"Writer",
",",
"value",
"byte",
")",
"error",
"{",
"var",
"buf",
"[",
"1",
"]",
"byte",
"\n",
"buf",
"[",
"0",
"]",
"=",
"value",
"\n",
"_",
",",
"err",
":=",
"w",
".",
"Write",
"(",
"buf",
"[",
":",
... | // WriteByte wrties a byte to w. | [
"WriteByte",
"wrties",
"a",
"byte",
"to",
"w",
"."
] | e21b3afba225b21d05fbcbeb8ece2c79c96554c5 | https://github.com/twpayne/go-geom/blob/e21b3afba225b21d05fbcbeb8ece2c79c96554c5/encoding/wkbcommon/binary.go#L70-L75 | train |
pquerna/ffjson | fflib/v1/buffer_pool.go | poolNum | func poolNum(i int) int {
// TODO(pquerna): convert to log2 w/ bsr asm instruction:
// <https://groups.google.com/forum/#!topic/golang-nuts/uAb5J1_y7ns>
if i <= 64 {
return 0
} else if i <= 128 {
return 1
} else if i <= 256 {
return 2
} else if i <= 512 {
return 3
} else if i <= 1024 {
return 4
} else if i <= 2048 {
return 5
} else if i <= 4096 {
return 6
} else if i <= 8192 {
return 7
} else if i <= 16384 {
return 8
} else if i <= 32768 {
return 9
} else if i <= 65536 {
return 10
} else if i <= 131072 {
return 11
} else if i <= 262144 {
return 12
} else if i <= 524288 {
return 13
} else {
return -1
}
} | go | func poolNum(i int) int {
// TODO(pquerna): convert to log2 w/ bsr asm instruction:
// <https://groups.google.com/forum/#!topic/golang-nuts/uAb5J1_y7ns>
if i <= 64 {
return 0
} else if i <= 128 {
return 1
} else if i <= 256 {
return 2
} else if i <= 512 {
return 3
} else if i <= 1024 {
return 4
} else if i <= 2048 {
return 5
} else if i <= 4096 {
return 6
} else if i <= 8192 {
return 7
} else if i <= 16384 {
return 8
} else if i <= 32768 {
return 9
} else if i <= 65536 {
return 10
} else if i <= 131072 {
return 11
} else if i <= 262144 {
return 12
} else if i <= 524288 {
return 13
} else {
return -1
}
} | [
"func",
"poolNum",
"(",
"i",
"int",
")",
"int",
"{",
"// TODO(pquerna): convert to log2 w/ bsr asm instruction:",
"// \t<https://groups.google.com/forum/#!topic/golang-nuts/uAb5J1_y7ns>",
"if",
"i",
"<=",
"64",
"{",
"return",
"0",
"\n",
"}",
"else",
"if",
"i",
"<=",
"12... | // This returns the pool number that will give a buffer of
// at least 'i' bytes. | [
"This",
"returns",
"the",
"pool",
"number",
"that",
"will",
"give",
"a",
"buffer",
"of",
"at",
"least",
"i",
"bytes",
"."
] | e517b90714f7c0eabe6d2e570a5886ae077d6db6 | https://github.com/pquerna/ffjson/blob/e517b90714f7c0eabe6d2e570a5886ae077d6db6/fflib/v1/buffer_pool.go#L28-L62 | train |
pquerna/ffjson | fflib/v1/buffer_pool.go | Pool | func Pool(b []byte) {
if b == nil {
return
}
c := cap(b)
// Our smallest buffer is 64 bytes, so we discard smaller buffers.
if c < 64 {
return
}
// We need to put the incoming buffer into the NEXT buffer,
// since a buffer guarantees AT LEAST the number of bytes available
// that is the top of this buffer.
// That is the reason for dividing the cap by 2, so it gets into the NEXT bucket.
// We add 2 to avoid rounding down if size is exactly power of 2.
pn := poolNum((c + 2) >> 1)
if pn != -1 {
pools[pn].Put(b[0:0])
}
// if we didn't have a slot for this []byte, we just drop it and let the GC
// take care of it.
} | go | func Pool(b []byte) {
if b == nil {
return
}
c := cap(b)
// Our smallest buffer is 64 bytes, so we discard smaller buffers.
if c < 64 {
return
}
// We need to put the incoming buffer into the NEXT buffer,
// since a buffer guarantees AT LEAST the number of bytes available
// that is the top of this buffer.
// That is the reason for dividing the cap by 2, so it gets into the NEXT bucket.
// We add 2 to avoid rounding down if size is exactly power of 2.
pn := poolNum((c + 2) >> 1)
if pn != -1 {
pools[pn].Put(b[0:0])
}
// if we didn't have a slot for this []byte, we just drop it and let the GC
// take care of it.
} | [
"func",
"Pool",
"(",
"b",
"[",
"]",
"byte",
")",
"{",
"if",
"b",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"c",
":=",
"cap",
"(",
"b",
")",
"\n\n",
"// Our smallest buffer is 64 bytes, so we discard smaller buffers.",
"if",
"c",
"<",
"64",
"{",
"retur... | // Send a buffer to the Pool to reuse for other instances.
// You may no longer utilize the content of the buffer, since it may be used
// by other goroutines. | [
"Send",
"a",
"buffer",
"to",
"the",
"Pool",
"to",
"reuse",
"for",
"other",
"instances",
".",
"You",
"may",
"no",
"longer",
"utilize",
"the",
"content",
"of",
"the",
"buffer",
"since",
"it",
"may",
"be",
"used",
"by",
"other",
"goroutines",
"."
] | e517b90714f7c0eabe6d2e570a5886ae077d6db6 | https://github.com/pquerna/ffjson/blob/e517b90714f7c0eabe6d2e570a5886ae077d6db6/fflib/v1/buffer_pool.go#L67-L89 | train |
pquerna/ffjson | ffjson/marshal.go | Marshal | func Marshal(v interface{}) ([]byte, error) {
f, ok := v.(marshalerFaster)
if ok {
buf := fflib.Buffer{}
err := f.MarshalJSONBuf(&buf)
b := buf.Bytes()
if err != nil {
if len(b) > 0 {
Pool(b)
}
return nil, err
}
return b, nil
}
j, ok := v.(json.Marshaler)
if ok {
return j.MarshalJSON()
}
return json.Marshal(v)
} | go | func Marshal(v interface{}) ([]byte, error) {
f, ok := v.(marshalerFaster)
if ok {
buf := fflib.Buffer{}
err := f.MarshalJSONBuf(&buf)
b := buf.Bytes()
if err != nil {
if len(b) > 0 {
Pool(b)
}
return nil, err
}
return b, nil
}
j, ok := v.(json.Marshaler)
if ok {
return j.MarshalJSON()
}
return json.Marshal(v)
} | [
"func",
"Marshal",
"(",
"v",
"interface",
"{",
"}",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"f",
",",
"ok",
":=",
"v",
".",
"(",
"marshalerFaster",
")",
"\n",
"if",
"ok",
"{",
"buf",
":=",
"fflib",
".",
"Buffer",
"{",
"}",
"\n",
"... | // Marshal will act the same way as json.Marshal, except
// it will choose the ffjson marshal function before falling
// back to using json.Marshal.
// Using this function will bypass the internal copying and parsing
// the json library normally does, which greatly speeds up encoding time.
// It is ok to call this function even if no ffjson code has been
// generated for the data type you pass in the interface. | [
"Marshal",
"will",
"act",
"the",
"same",
"way",
"as",
"json",
".",
"Marshal",
"except",
"it",
"will",
"choose",
"the",
"ffjson",
"marshal",
"function",
"before",
"falling",
"back",
"to",
"using",
"json",
".",
"Marshal",
".",
"Using",
"this",
"function",
"w... | e517b90714f7c0eabe6d2e570a5886ae077d6db6 | https://github.com/pquerna/ffjson/blob/e517b90714f7c0eabe6d2e570a5886ae077d6db6/ffjson/marshal.go#L42-L62 | train |
pquerna/ffjson | ffjson/marshal.go | Unmarshal | func Unmarshal(data []byte, v interface{}) error {
f, ok := v.(unmarshalFaster)
if ok {
fs := fflib.NewFFLexer(data)
return f.UnmarshalJSONFFLexer(fs, fflib.FFParse_map_start)
}
j, ok := v.(json.Unmarshaler)
if ok {
return j.UnmarshalJSON(data)
}
return json.Unmarshal(data, v)
} | go | func Unmarshal(data []byte, v interface{}) error {
f, ok := v.(unmarshalFaster)
if ok {
fs := fflib.NewFFLexer(data)
return f.UnmarshalJSONFFLexer(fs, fflib.FFParse_map_start)
}
j, ok := v.(json.Unmarshaler)
if ok {
return j.UnmarshalJSON(data)
}
return json.Unmarshal(data, v)
} | [
"func",
"Unmarshal",
"(",
"data",
"[",
"]",
"byte",
",",
"v",
"interface",
"{",
"}",
")",
"error",
"{",
"f",
",",
"ok",
":=",
"v",
".",
"(",
"unmarshalFaster",
")",
"\n",
"if",
"ok",
"{",
"fs",
":=",
"fflib",
".",
"NewFFLexer",
"(",
"data",
")",
... | // Unmarshal will act the same way as json.Unmarshal, except
// it will choose the ffjson unmarshal function before falling
// back to using json.Unmarshal.
// The overhead of unmarshal is lower than on Marshal,
// however this should still provide a speedup for your encoding.
// It is ok to call this function even if no ffjson code has been
// generated for the data type you pass in the interface. | [
"Unmarshal",
"will",
"act",
"the",
"same",
"way",
"as",
"json",
".",
"Unmarshal",
"except",
"it",
"will",
"choose",
"the",
"ffjson",
"unmarshal",
"function",
"before",
"falling",
"back",
"to",
"using",
"json",
".",
"Unmarshal",
".",
"The",
"overhead",
"of",
... | e517b90714f7c0eabe6d2e570a5886ae077d6db6 | https://github.com/pquerna/ffjson/blob/e517b90714f7c0eabe6d2e570a5886ae077d6db6/ffjson/marshal.go#L84-L96 | train |
pquerna/ffjson | fflib/v1/iota.go | FormatBits2 | func FormatBits2(dst FormatBitsWriter, u uint64, base int, neg bool) {
if base < 2 || base > len(digits) {
panic("strconv: illegal AppendInt/FormatInt base")
}
// fast path for small common numbers
if u <= 10 {
if neg {
dst.WriteByte('-')
}
dst.Write(smallNumbers[u])
return
}
// 2 <= base && base <= len(digits)
var a = makeSlice(65)
// var a [64 + 1]byte // +1 for sign of 64bit value in base 2
i := len(a)
if neg {
u = -u
}
// convert bits
if base == 10 {
// common case: use constants for / and % because
// the compiler can optimize it into a multiply+shift,
// and unroll loop
for u >= 100 {
i -= 2
q := u / 100
j := uintptr(u - q*100)
a[i+1] = digits01[j]
a[i+0] = digits10[j]
u = q
}
if u >= 10 {
i--
q := u / 10
a[i] = digits[uintptr(u-q*10)]
u = q
}
} else if s := shifts[base]; s > 0 {
// base is power of 2: use shifts and masks instead of / and %
b := uint64(base)
m := uintptr(b) - 1 // == 1<<s - 1
for u >= b {
i--
a[i] = digits[uintptr(u)&m]
u >>= s
}
} else {
// general case
b := uint64(base)
for u >= b {
i--
a[i] = digits[uintptr(u%b)]
u /= b
}
}
// u < base
i--
a[i] = digits[uintptr(u)]
// add sign, if any
if neg {
i--
a[i] = '-'
}
dst.Write(a[i:])
Pool(a)
return
} | go | func FormatBits2(dst FormatBitsWriter, u uint64, base int, neg bool) {
if base < 2 || base > len(digits) {
panic("strconv: illegal AppendInt/FormatInt base")
}
// fast path for small common numbers
if u <= 10 {
if neg {
dst.WriteByte('-')
}
dst.Write(smallNumbers[u])
return
}
// 2 <= base && base <= len(digits)
var a = makeSlice(65)
// var a [64 + 1]byte // +1 for sign of 64bit value in base 2
i := len(a)
if neg {
u = -u
}
// convert bits
if base == 10 {
// common case: use constants for / and % because
// the compiler can optimize it into a multiply+shift,
// and unroll loop
for u >= 100 {
i -= 2
q := u / 100
j := uintptr(u - q*100)
a[i+1] = digits01[j]
a[i+0] = digits10[j]
u = q
}
if u >= 10 {
i--
q := u / 10
a[i] = digits[uintptr(u-q*10)]
u = q
}
} else if s := shifts[base]; s > 0 {
// base is power of 2: use shifts and masks instead of / and %
b := uint64(base)
m := uintptr(b) - 1 // == 1<<s - 1
for u >= b {
i--
a[i] = digits[uintptr(u)&m]
u >>= s
}
} else {
// general case
b := uint64(base)
for u >= b {
i--
a[i] = digits[uintptr(u%b)]
u /= b
}
}
// u < base
i--
a[i] = digits[uintptr(u)]
// add sign, if any
if neg {
i--
a[i] = '-'
}
dst.Write(a[i:])
Pool(a)
return
} | [
"func",
"FormatBits2",
"(",
"dst",
"FormatBitsWriter",
",",
"u",
"uint64",
",",
"base",
"int",
",",
"neg",
"bool",
")",
"{",
"if",
"base",
"<",
"2",
"||",
"base",
">",
"len",
"(",
"digits",
")",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n"... | // FormatBits2 computes the string representation of u in the given base.
// If neg is set, u is treated as negative int64 value. If append_ is
// set, the string is appended to dst and the resulting byte slice is
// returned as the first result value; otherwise the string is returned
// as the second result value.
// | [
"FormatBits2",
"computes",
"the",
"string",
"representation",
"of",
"u",
"in",
"the",
"given",
"base",
".",
"If",
"neg",
"is",
"set",
"u",
"is",
"treated",
"as",
"negative",
"int64",
"value",
".",
"If",
"append_",
"is",
"set",
"the",
"string",
"is",
"app... | e517b90714f7c0eabe6d2e570a5886ae077d6db6 | https://github.com/pquerna/ffjson/blob/e517b90714f7c0eabe6d2e570a5886ae077d6db6/fflib/v1/iota.go#L83-L161 | train |
pquerna/ffjson | fflib/v1/reader.go | Reset | func (r *ffReader) Reset(d []byte) {
r.s = d
r.i = 0
r.l = len(d)
} | go | func (r *ffReader) Reset(d []byte) {
r.s = d
r.i = 0
r.l = len(d)
} | [
"func",
"(",
"r",
"*",
"ffReader",
")",
"Reset",
"(",
"d",
"[",
"]",
"byte",
")",
"{",
"r",
".",
"s",
"=",
"d",
"\n",
"r",
".",
"i",
"=",
"0",
"\n",
"r",
".",
"l",
"=",
"len",
"(",
"d",
")",
"\n",
"}"
] | // Reset the reader, and add new input. | [
"Reset",
"the",
"reader",
"and",
"add",
"new",
"input",
"."
] | e517b90714f7c0eabe6d2e570a5886ae077d6db6 | https://github.com/pquerna/ffjson/blob/e517b90714f7c0eabe6d2e570a5886ae077d6db6/fflib/v1/reader.go#L52-L56 | train |
pquerna/ffjson | fflib/v1/reader.go | PosWithLine | func (r *ffReader) PosWithLine() (int, int) {
currentLine := 1
currentChar := 0
for i := 0; i < r.i; i++ {
c := r.s[i]
currentChar++
if c == '\n' {
currentLine++
currentChar = 0
}
}
return currentLine, currentChar
} | go | func (r *ffReader) PosWithLine() (int, int) {
currentLine := 1
currentChar := 0
for i := 0; i < r.i; i++ {
c := r.s[i]
currentChar++
if c == '\n' {
currentLine++
currentChar = 0
}
}
return currentLine, currentChar
} | [
"func",
"(",
"r",
"*",
"ffReader",
")",
"PosWithLine",
"(",
")",
"(",
"int",
",",
"int",
")",
"{",
"currentLine",
":=",
"1",
"\n",
"currentChar",
":=",
"0",
"\n\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"r",
".",
"i",
";",
"i",
"++",
"{",
"c"... | // Calcuates the Position with line and line offset,
// because this isn't counted for performance reasons,
// it will iterate the buffer from the beginning, and should
// only be used in error-paths. | [
"Calcuates",
"the",
"Position",
"with",
"line",
"and",
"line",
"offset",
"because",
"this",
"isn",
"t",
"counted",
"for",
"performance",
"reasons",
"it",
"will",
"iterate",
"the",
"buffer",
"from",
"the",
"beginning",
"and",
"should",
"only",
"be",
"used",
"... | e517b90714f7c0eabe6d2e570a5886ae077d6db6 | https://github.com/pquerna/ffjson/blob/e517b90714f7c0eabe6d2e570a5886ae077d6db6/fflib/v1/reader.go#L62-L76 | train |
pquerna/ffjson | fflib/v1/ftoa.go | formatBits | func formatBits(dst EncodingBuffer, u uint64, base int, neg bool) {
if base < 2 || base > len(digits) {
panic("strconv: illegal AppendInt/FormatInt base")
}
// 2 <= base && base <= len(digits)
var a [64 + 1]byte // +1 for sign of 64bit value in base 2
i := len(a)
if neg {
u = -u
}
// convert bits
if base == 10 {
// common case: use constants for / because
// the compiler can optimize it into a multiply+shift
if ^uintptr(0)>>32 == 0 {
for u > uint64(^uintptr(0)) {
q := u / 1e9
us := uintptr(u - q*1e9) // us % 1e9 fits into a uintptr
for j := 9; j > 0; j-- {
i--
qs := us / 10
a[i] = byte(us - qs*10 + '0')
us = qs
}
u = q
}
}
// u guaranteed to fit into a uintptr
us := uintptr(u)
for us >= 10 {
i--
q := us / 10
a[i] = byte(us - q*10 + '0')
us = q
}
// u < 10
i--
a[i] = byte(us + '0')
} else if s := shifts[base]; s > 0 {
// base is power of 2: use shifts and masks instead of / and %
b := uint64(base)
m := uintptr(b) - 1 // == 1<<s - 1
for u >= b {
i--
a[i] = digits[uintptr(u)&m]
u >>= s
}
// u < base
i--
a[i] = digits[uintptr(u)]
} else {
// general case
b := uint64(base)
for u >= b {
i--
q := u / b
a[i] = digits[uintptr(u-q*b)]
u = q
}
// u < base
i--
a[i] = digits[uintptr(u)]
}
// add sign, if any
if neg {
i--
a[i] = '-'
}
dst.Write(a[i:])
} | go | func formatBits(dst EncodingBuffer, u uint64, base int, neg bool) {
if base < 2 || base > len(digits) {
panic("strconv: illegal AppendInt/FormatInt base")
}
// 2 <= base && base <= len(digits)
var a [64 + 1]byte // +1 for sign of 64bit value in base 2
i := len(a)
if neg {
u = -u
}
// convert bits
if base == 10 {
// common case: use constants for / because
// the compiler can optimize it into a multiply+shift
if ^uintptr(0)>>32 == 0 {
for u > uint64(^uintptr(0)) {
q := u / 1e9
us := uintptr(u - q*1e9) // us % 1e9 fits into a uintptr
for j := 9; j > 0; j-- {
i--
qs := us / 10
a[i] = byte(us - qs*10 + '0')
us = qs
}
u = q
}
}
// u guaranteed to fit into a uintptr
us := uintptr(u)
for us >= 10 {
i--
q := us / 10
a[i] = byte(us - q*10 + '0')
us = q
}
// u < 10
i--
a[i] = byte(us + '0')
} else if s := shifts[base]; s > 0 {
// base is power of 2: use shifts and masks instead of / and %
b := uint64(base)
m := uintptr(b) - 1 // == 1<<s - 1
for u >= b {
i--
a[i] = digits[uintptr(u)&m]
u >>= s
}
// u < base
i--
a[i] = digits[uintptr(u)]
} else {
// general case
b := uint64(base)
for u >= b {
i--
q := u / b
a[i] = digits[uintptr(u-q*b)]
u = q
}
// u < base
i--
a[i] = digits[uintptr(u)]
}
// add sign, if any
if neg {
i--
a[i] = '-'
}
dst.Write(a[i:])
} | [
"func",
"formatBits",
"(",
"dst",
"EncodingBuffer",
",",
"u",
"uint64",
",",
"base",
"int",
",",
"neg",
"bool",
")",
"{",
"if",
"base",
"<",
"2",
"||",
"base",
">",
"len",
"(",
"digits",
")",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
... | // formatBits computes the string representation of u in the given base.
// If neg is set, u is treated as negative int64 value. | [
"formatBits",
"computes",
"the",
"string",
"representation",
"of",
"u",
"in",
"the",
"given",
"base",
".",
"If",
"neg",
"is",
"set",
"u",
"is",
"treated",
"as",
"negative",
"int64",
"value",
"."
] | e517b90714f7c0eabe6d2e570a5886ae077d6db6 | https://github.com/pquerna/ffjson/blob/e517b90714f7c0eabe6d2e570a5886ae077d6db6/fflib/v1/ftoa.go#L464-L542 | train |
pquerna/ffjson | inception/encoder.go | lastConditional | func lastConditional(fields []*StructField) bool {
if len(fields) > 0 {
f := fields[len(fields)-1]
return f.OmitEmpty
}
return false
} | go | func lastConditional(fields []*StructField) bool {
if len(fields) > 0 {
f := fields[len(fields)-1]
return f.OmitEmpty
}
return false
} | [
"func",
"lastConditional",
"(",
"fields",
"[",
"]",
"*",
"StructField",
")",
"bool",
"{",
"if",
"len",
"(",
"fields",
")",
">",
"0",
"{",
"f",
":=",
"fields",
"[",
"len",
"(",
"fields",
")",
"-",
"1",
"]",
"\n",
"return",
"f",
".",
"OmitEmpty",
"... | // We check if the last field is conditional. | [
"We",
"check",
"if",
"the",
"last",
"field",
"is",
"conditional",
"."
] | e517b90714f7c0eabe6d2e570a5886ae077d6db6 | https://github.com/pquerna/ffjson/blob/e517b90714f7c0eabe6d2e570a5886ae077d6db6/inception/encoder.go#L475-L481 | train |
pquerna/ffjson | fflib/v1/extfloat.go | Normalize | func (f *extFloat) Normalize() (shift uint) {
mant, exp := f.mant, f.exp
if mant == 0 {
return 0
}
if mant>>(64-32) == 0 {
mant <<= 32
exp -= 32
}
if mant>>(64-16) == 0 {
mant <<= 16
exp -= 16
}
if mant>>(64-8) == 0 {
mant <<= 8
exp -= 8
}
if mant>>(64-4) == 0 {
mant <<= 4
exp -= 4
}
if mant>>(64-2) == 0 {
mant <<= 2
exp -= 2
}
if mant>>(64-1) == 0 {
mant <<= 1
exp -= 1
}
shift = uint(f.exp - exp)
f.mant, f.exp = mant, exp
return
} | go | func (f *extFloat) Normalize() (shift uint) {
mant, exp := f.mant, f.exp
if mant == 0 {
return 0
}
if mant>>(64-32) == 0 {
mant <<= 32
exp -= 32
}
if mant>>(64-16) == 0 {
mant <<= 16
exp -= 16
}
if mant>>(64-8) == 0 {
mant <<= 8
exp -= 8
}
if mant>>(64-4) == 0 {
mant <<= 4
exp -= 4
}
if mant>>(64-2) == 0 {
mant <<= 2
exp -= 2
}
if mant>>(64-1) == 0 {
mant <<= 1
exp -= 1
}
shift = uint(f.exp - exp)
f.mant, f.exp = mant, exp
return
} | [
"func",
"(",
"f",
"*",
"extFloat",
")",
"Normalize",
"(",
")",
"(",
"shift",
"uint",
")",
"{",
"mant",
",",
"exp",
":=",
"f",
".",
"mant",
",",
"f",
".",
"exp",
"\n",
"if",
"mant",
"==",
"0",
"{",
"return",
"0",
"\n",
"}",
"\n",
"if",
"mant",... | // Normalize normalizes f so that the highest bit of the mantissa is
// set, and returns the number by which the mantissa was left-shifted. | [
"Normalize",
"normalizes",
"f",
"so",
"that",
"the",
"highest",
"bit",
"of",
"the",
"mantissa",
"is",
"set",
"and",
"returns",
"the",
"number",
"by",
"which",
"the",
"mantissa",
"was",
"left",
"-",
"shifted",
"."
] | e517b90714f7c0eabe6d2e570a5886ae077d6db6 | https://github.com/pquerna/ffjson/blob/e517b90714f7c0eabe6d2e570a5886ae077d6db6/fflib/v1/extfloat.go#L199-L231 | train |
pquerna/ffjson | fflib/v1/extfloat.go | frexp10Many | func frexp10Many(a, b, c *extFloat) (exp10 int) {
exp10, i := c.frexp10()
a.Multiply(powersOfTen[i])
b.Multiply(powersOfTen[i])
return
} | go | func frexp10Many(a, b, c *extFloat) (exp10 int) {
exp10, i := c.frexp10()
a.Multiply(powersOfTen[i])
b.Multiply(powersOfTen[i])
return
} | [
"func",
"frexp10Many",
"(",
"a",
",",
"b",
",",
"c",
"*",
"extFloat",
")",
"(",
"exp10",
"int",
")",
"{",
"exp10",
",",
"i",
":=",
"c",
".",
"frexp10",
"(",
")",
"\n",
"a",
".",
"Multiply",
"(",
"powersOfTen",
"[",
"i",
"]",
")",
"\n",
"b",
"... | // frexp10Many applies a common shift by a power of ten to a, b, c. | [
"frexp10Many",
"applies",
"a",
"common",
"shift",
"by",
"a",
"power",
"of",
"ten",
"to",
"a",
"b",
"c",
"."
] | e517b90714f7c0eabe6d2e570a5886ae077d6db6 | https://github.com/pquerna/ffjson/blob/e517b90714f7c0eabe6d2e570a5886ae077d6db6/fflib/v1/extfloat.go#L368-L373 | train |
pquerna/ffjson | fflib/v1/extfloat.go | FixedDecimal | func (f *extFloat) FixedDecimal(d *decimalSlice, n int) bool {
if f.mant == 0 {
d.nd = 0
d.dp = 0
d.neg = f.neg
return true
}
if n == 0 {
panic("strconv: internal error: extFloat.FixedDecimal called with n == 0")
}
// Multiply by an appropriate power of ten to have a reasonable
// number to process.
f.Normalize()
exp10, _ := f.frexp10()
shift := uint(-f.exp)
integer := uint32(f.mant >> shift)
fraction := f.mant - (uint64(integer) << shift)
ε := uint64(1) // ε is the uncertainty we have on the mantissa of f.
// Write exactly n digits to d.
needed := n // how many digits are left to write.
integerDigits := 0 // the number of decimal digits of integer.
pow10 := uint64(1) // the power of ten by which f was scaled.
for i, pow := 0, uint64(1); i < 20; i++ {
if pow > uint64(integer) {
integerDigits = i
break
}
pow *= 10
}
rest := integer
if integerDigits > needed {
// the integral part is already large, trim the last digits.
pow10 = uint64pow10[integerDigits-needed]
integer /= uint32(pow10)
rest -= integer * uint32(pow10)
} else {
rest = 0
}
// Write the digits of integer: the digits of rest are omitted.
var buf [32]byte
pos := len(buf)
for v := integer; v > 0; {
v1 := v / 10
v -= 10 * v1
pos--
buf[pos] = byte(v + '0')
v = v1
}
for i := pos; i < len(buf); i++ {
d.d[i-pos] = buf[i]
}
nd := len(buf) - pos
d.nd = nd
d.dp = integerDigits + exp10
needed -= nd
if needed > 0 {
if rest != 0 || pow10 != 1 {
panic("strconv: internal error, rest != 0 but needed > 0")
}
// Emit digits for the fractional part. Each time, 10*fraction
// fits in a uint64 without overflow.
for needed > 0 {
fraction *= 10
ε *= 10 // the uncertainty scales as we multiply by ten.
if 2*ε > 1<<shift {
// the error is so large it could modify which digit to write, abort.
return false
}
digit := fraction >> shift
d.d[nd] = byte(digit + '0')
fraction -= digit << shift
nd++
needed--
}
d.nd = nd
}
// We have written a truncation of f (a numerator / 10^d.dp). The remaining part
// can be interpreted as a small number (< 1) to be added to the last digit of the
// numerator.
//
// If rest > 0, the amount is:
// (rest<<shift | fraction) / (pow10 << shift)
// fraction being known with a ±ε uncertainty.
// The fact that n > 0 guarantees that pow10 << shift does not overflow a uint64.
//
// If rest = 0, pow10 == 1 and the amount is
// fraction / (1 << shift)
// fraction being known with a ±ε uncertainty.
//
// We pass this information to the rounding routine for adjustment.
ok := adjustLastDigitFixed(d, uint64(rest)<<shift|fraction, pow10, shift, ε)
if !ok {
return false
}
// Trim trailing zeros.
for i := d.nd - 1; i >= 0; i-- {
if d.d[i] != '0' {
d.nd = i + 1
break
}
}
return true
} | go | func (f *extFloat) FixedDecimal(d *decimalSlice, n int) bool {
if f.mant == 0 {
d.nd = 0
d.dp = 0
d.neg = f.neg
return true
}
if n == 0 {
panic("strconv: internal error: extFloat.FixedDecimal called with n == 0")
}
// Multiply by an appropriate power of ten to have a reasonable
// number to process.
f.Normalize()
exp10, _ := f.frexp10()
shift := uint(-f.exp)
integer := uint32(f.mant >> shift)
fraction := f.mant - (uint64(integer) << shift)
ε := uint64(1) // ε is the uncertainty we have on the mantissa of f.
// Write exactly n digits to d.
needed := n // how many digits are left to write.
integerDigits := 0 // the number of decimal digits of integer.
pow10 := uint64(1) // the power of ten by which f was scaled.
for i, pow := 0, uint64(1); i < 20; i++ {
if pow > uint64(integer) {
integerDigits = i
break
}
pow *= 10
}
rest := integer
if integerDigits > needed {
// the integral part is already large, trim the last digits.
pow10 = uint64pow10[integerDigits-needed]
integer /= uint32(pow10)
rest -= integer * uint32(pow10)
} else {
rest = 0
}
// Write the digits of integer: the digits of rest are omitted.
var buf [32]byte
pos := len(buf)
for v := integer; v > 0; {
v1 := v / 10
v -= 10 * v1
pos--
buf[pos] = byte(v + '0')
v = v1
}
for i := pos; i < len(buf); i++ {
d.d[i-pos] = buf[i]
}
nd := len(buf) - pos
d.nd = nd
d.dp = integerDigits + exp10
needed -= nd
if needed > 0 {
if rest != 0 || pow10 != 1 {
panic("strconv: internal error, rest != 0 but needed > 0")
}
// Emit digits for the fractional part. Each time, 10*fraction
// fits in a uint64 without overflow.
for needed > 0 {
fraction *= 10
ε *= 10 // the uncertainty scales as we multiply by ten.
if 2*ε > 1<<shift {
// the error is so large it could modify which digit to write, abort.
return false
}
digit := fraction >> shift
d.d[nd] = byte(digit + '0')
fraction -= digit << shift
nd++
needed--
}
d.nd = nd
}
// We have written a truncation of f (a numerator / 10^d.dp). The remaining part
// can be interpreted as a small number (< 1) to be added to the last digit of the
// numerator.
//
// If rest > 0, the amount is:
// (rest<<shift | fraction) / (pow10 << shift)
// fraction being known with a ±ε uncertainty.
// The fact that n > 0 guarantees that pow10 << shift does not overflow a uint64.
//
// If rest = 0, pow10 == 1 and the amount is
// fraction / (1 << shift)
// fraction being known with a ±ε uncertainty.
//
// We pass this information to the rounding routine for adjustment.
ok := adjustLastDigitFixed(d, uint64(rest)<<shift|fraction, pow10, shift, ε)
if !ok {
return false
}
// Trim trailing zeros.
for i := d.nd - 1; i >= 0; i-- {
if d.d[i] != '0' {
d.nd = i + 1
break
}
}
return true
} | [
"func",
"(",
"f",
"*",
"extFloat",
")",
"FixedDecimal",
"(",
"d",
"*",
"decimalSlice",
",",
"n",
"int",
")",
"bool",
"{",
"if",
"f",
".",
"mant",
"==",
"0",
"{",
"d",
".",
"nd",
"=",
"0",
"\n",
"d",
".",
"dp",
"=",
"0",
"\n",
"d",
".",
"neg... | // FixedDecimal stores in d the first n significant digits
// of the decimal representation of f. It returns false
// if it cannot be sure of the answer. | [
"FixedDecimal",
"stores",
"in",
"d",
"the",
"first",
"n",
"significant",
"digits",
"of",
"the",
"decimal",
"representation",
"of",
"f",
".",
"It",
"returns",
"false",
"if",
"it",
"cannot",
"be",
"sure",
"of",
"the",
"answer",
"."
] | e517b90714f7c0eabe6d2e570a5886ae077d6db6 | https://github.com/pquerna/ffjson/blob/e517b90714f7c0eabe6d2e570a5886ae077d6db6/fflib/v1/extfloat.go#L378-L486 | train |
pquerna/ffjson | fflib/v1/lexer.go | Reset | func (ffl *FFLexer) Reset(input []byte) {
ffl.Token = FFTok_init
ffl.Error = FFErr_e_ok
ffl.BigError = nil
ffl.reader.Reset(input)
ffl.lastCurrentChar = 0
ffl.Output.Reset()
} | go | func (ffl *FFLexer) Reset(input []byte) {
ffl.Token = FFTok_init
ffl.Error = FFErr_e_ok
ffl.BigError = nil
ffl.reader.Reset(input)
ffl.lastCurrentChar = 0
ffl.Output.Reset()
} | [
"func",
"(",
"ffl",
"*",
"FFLexer",
")",
"Reset",
"(",
"input",
"[",
"]",
"byte",
")",
"{",
"ffl",
".",
"Token",
"=",
"FFTok_init",
"\n",
"ffl",
".",
"Error",
"=",
"FFErr_e_ok",
"\n",
"ffl",
".",
"BigError",
"=",
"nil",
"\n",
"ffl",
".",
"reader",
... | // Reset the Lexer and add new input. | [
"Reset",
"the",
"Lexer",
"and",
"add",
"new",
"input",
"."
] | e517b90714f7c0eabe6d2e570a5886ae077d6db6 | https://github.com/pquerna/ffjson/blob/e517b90714f7c0eabe6d2e570a5886ae077d6db6/fflib/v1/lexer.go#L130-L137 | train |
pquerna/ffjson | fflib/v1/decimal.go | Assign | func (a *decimal) Assign(v uint64) {
var buf [24]byte
// Write reversed decimal in buf.
n := 0
for v > 0 {
v1 := v / 10
v -= 10 * v1
buf[n] = byte(v + '0')
n++
v = v1
}
// Reverse again to produce forward decimal in a.d.
a.nd = 0
for n--; n >= 0; n-- {
a.d[a.nd] = buf[n]
a.nd++
}
a.dp = a.nd
trim(a)
} | go | func (a *decimal) Assign(v uint64) {
var buf [24]byte
// Write reversed decimal in buf.
n := 0
for v > 0 {
v1 := v / 10
v -= 10 * v1
buf[n] = byte(v + '0')
n++
v = v1
}
// Reverse again to produce forward decimal in a.d.
a.nd = 0
for n--; n >= 0; n-- {
a.d[a.nd] = buf[n]
a.nd++
}
a.dp = a.nd
trim(a)
} | [
"func",
"(",
"a",
"*",
"decimal",
")",
"Assign",
"(",
"v",
"uint64",
")",
"{",
"var",
"buf",
"[",
"24",
"]",
"byte",
"\n\n",
"// Write reversed decimal in buf.",
"n",
":=",
"0",
"\n",
"for",
"v",
">",
"0",
"{",
"v1",
":=",
"v",
"/",
"10",
"\n",
"... | // Assign v to a. | [
"Assign",
"v",
"to",
"a",
"."
] | e517b90714f7c0eabe6d2e570a5886ae077d6db6 | https://github.com/pquerna/ffjson/blob/e517b90714f7c0eabe6d2e570a5886ae077d6db6/fflib/v1/decimal.go#L81-L102 | train |
pquerna/ffjson | fflib/v1/decimal.go | prefixIsLessThan | func prefixIsLessThan(b []byte, s string) bool {
for i := 0; i < len(s); i++ {
if i >= len(b) {
return true
}
if b[i] != s[i] {
return b[i] < s[i]
}
}
return false
} | go | func prefixIsLessThan(b []byte, s string) bool {
for i := 0; i < len(s); i++ {
if i >= len(b) {
return true
}
if b[i] != s[i] {
return b[i] < s[i]
}
}
return false
} | [
"func",
"prefixIsLessThan",
"(",
"b",
"[",
"]",
"byte",
",",
"s",
"string",
")",
"bool",
"{",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"len",
"(",
"s",
")",
";",
"i",
"++",
"{",
"if",
"i",
">=",
"len",
"(",
"b",
")",
"{",
"return",
"true",
"\n... | // Is the leading prefix of b lexicographically less than s? | [
"Is",
"the",
"leading",
"prefix",
"of",
"b",
"lexicographically",
"less",
"than",
"s?"
] | e517b90714f7c0eabe6d2e570a5886ae077d6db6 | https://github.com/pquerna/ffjson/blob/e517b90714f7c0eabe6d2e570a5886ae077d6db6/fflib/v1/decimal.go#L219-L229 | train |
pquerna/ffjson | fflib/v1/decimal.go | shouldRoundUp | func shouldRoundUp(a *decimal, nd int) bool {
if nd < 0 || nd >= a.nd {
return false
}
if a.d[nd] == '5' && nd+1 == a.nd { // exactly halfway - round to even
// if we truncated, a little higher than what's recorded - always round up
if a.trunc {
return true
}
return nd > 0 && (a.d[nd-1]-'0')%2 != 0
}
// not halfway - digit tells all
return a.d[nd] >= '5'
} | go | func shouldRoundUp(a *decimal, nd int) bool {
if nd < 0 || nd >= a.nd {
return false
}
if a.d[nd] == '5' && nd+1 == a.nd { // exactly halfway - round to even
// if we truncated, a little higher than what's recorded - always round up
if a.trunc {
return true
}
return nd > 0 && (a.d[nd-1]-'0')%2 != 0
}
// not halfway - digit tells all
return a.d[nd] >= '5'
} | [
"func",
"shouldRoundUp",
"(",
"a",
"*",
"decimal",
",",
"nd",
"int",
")",
"bool",
"{",
"if",
"nd",
"<",
"0",
"||",
"nd",
">=",
"a",
".",
"nd",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"a",
".",
"d",
"[",
"nd",
"]",
"==",
"'5'",
"&&",
... | // If we chop a at nd digits, should we round up? | [
"If",
"we",
"chop",
"a",
"at",
"nd",
"digits",
"should",
"we",
"round",
"up?"
] | e517b90714f7c0eabe6d2e570a5886ae077d6db6 | https://github.com/pquerna/ffjson/blob/e517b90714f7c0eabe6d2e570a5886ae077d6db6/fflib/v1/decimal.go#L298-L311 | train |
pquerna/ffjson | fflib/v1/decimal.go | RoundedInteger | func (a *decimal) RoundedInteger() uint64 {
if a.dp > 20 {
return 0xFFFFFFFFFFFFFFFF
}
var i int
n := uint64(0)
for i = 0; i < a.dp && i < a.nd; i++ {
n = n*10 + uint64(a.d[i]-'0')
}
for ; i < a.dp; i++ {
n *= 10
}
if shouldRoundUp(a, a.dp) {
n++
}
return n
} | go | func (a *decimal) RoundedInteger() uint64 {
if a.dp > 20 {
return 0xFFFFFFFFFFFFFFFF
}
var i int
n := uint64(0)
for i = 0; i < a.dp && i < a.nd; i++ {
n = n*10 + uint64(a.d[i]-'0')
}
for ; i < a.dp; i++ {
n *= 10
}
if shouldRoundUp(a, a.dp) {
n++
}
return n
} | [
"func",
"(",
"a",
"*",
"decimal",
")",
"RoundedInteger",
"(",
")",
"uint64",
"{",
"if",
"a",
".",
"dp",
">",
"20",
"{",
"return",
"0xFFFFFFFFFFFFFFFF",
"\n",
"}",
"\n",
"var",
"i",
"int",
"\n",
"n",
":=",
"uint64",
"(",
"0",
")",
"\n",
"for",
"i"... | // Extract integer part, rounded appropriately.
// No guarantees about overflow. | [
"Extract",
"integer",
"part",
"rounded",
"appropriately",
".",
"No",
"guarantees",
"about",
"overflow",
"."
] | e517b90714f7c0eabe6d2e570a5886ae077d6db6 | https://github.com/pquerna/ffjson/blob/e517b90714f7c0eabe6d2e570a5886ae077d6db6/fflib/v1/decimal.go#L362-L378 | train |
pquerna/ffjson | inception/writerstack.go | Write | func (w *ConditionalWrite) Write(s string) {
w.Queued = append(w.Queued, s)
} | go | func (w *ConditionalWrite) Write(s string) {
w.Queued = append(w.Queued, s)
} | [
"func",
"(",
"w",
"*",
"ConditionalWrite",
")",
"Write",
"(",
"s",
"string",
")",
"{",
"w",
".",
"Queued",
"=",
"append",
"(",
"w",
".",
"Queued",
",",
"s",
")",
"\n",
"}"
] | // Write will add a string to be written | [
"Write",
"will",
"add",
"a",
"string",
"to",
"be",
"written"
] | e517b90714f7c0eabe6d2e570a5886ae077d6db6 | https://github.com/pquerna/ffjson/blob/e517b90714f7c0eabe6d2e570a5886ae077d6db6/inception/writerstack.go#L11-L13 | train |
pquerna/ffjson | inception/writerstack.go | DeleteLast | func (w *ConditionalWrite) DeleteLast() {
if len(w.Queued) == 0 {
return
}
w.Queued = w.Queued[:len(w.Queued)-1]
} | go | func (w *ConditionalWrite) DeleteLast() {
if len(w.Queued) == 0 {
return
}
w.Queued = w.Queued[:len(w.Queued)-1]
} | [
"func",
"(",
"w",
"*",
"ConditionalWrite",
")",
"DeleteLast",
"(",
")",
"{",
"if",
"len",
"(",
"w",
".",
"Queued",
")",
"==",
"0",
"{",
"return",
"\n",
"}",
"\n",
"w",
".",
"Queued",
"=",
"w",
".",
"Queued",
"[",
":",
"len",
"(",
"w",
".",
"Q... | // DeleteLast will delete the last added write | [
"DeleteLast",
"will",
"delete",
"the",
"last",
"added",
"write"
] | e517b90714f7c0eabe6d2e570a5886ae077d6db6 | https://github.com/pquerna/ffjson/blob/e517b90714f7c0eabe6d2e570a5886ae077d6db6/inception/writerstack.go#L16-L21 | train |
Subsets and Splits
SQL Console for semeru/code-text-go
Retrieves a limited set of code samples with their languages, with a specific case adjustment for 'Go' language.