id
int32
0
167k
repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
listlengths
21
1.41k
docstring
stringlengths
6
2.61k
docstring_tokens
listlengths
3
215
sha
stringlengths
40
40
url
stringlengths
85
252
20,800
go-gl/mathgl
mgl32/vecn.go
Zero
func (vn *VecN) Zero(n int) { vn.Resize(n) for i := range vn.vec { vn.vec[i] = 0 } }
go
func (vn *VecN) Zero(n int) { vn.Resize(n) for i := range vn.vec { vn.vec[i] = 0 } }
[ "func", "(", "vn", "*", "VecN", ")", "Zero", "(", "n", "int", ")", "{", "vn", ".", "Resize", "(", "n", ")", "\n", "for", "i", ":=", "range", "vn", ".", "vec", "{", "vn", ".", "vec", "[", "i", "]", "=", "0", "\n", "}", "\n", "}" ]
// Zero sets the vector's size to n and zeroes out the vector. // If n is bigger than the vector's size, it will realloc.
[ "Zero", "sets", "the", "vector", "s", "size", "to", "n", "and", "zeroes", "out", "the", "vector", ".", "If", "n", "is", "bigger", "than", "the", "vector", "s", "size", "it", "will", "realloc", "." ]
c4601bc793c7a480dab005cf969aab0d7a7fb07d
https://github.com/go-gl/mathgl/blob/c4601bc793c7a480dab005cf969aab0d7a7fb07d/mgl32/vecn.go#L131-L136
20,801
go-gl/mathgl
mgl32/vecn.go
Cross
func (vn *VecN) Cross(dst *VecN, other *VecN) *VecN { if vn == nil || other == nil { return nil } if len(vn.vec) != 3 || len(other.vec) != 3 { panic("Cannot take binary cross product of non-3D elements (7D cross product not implemented)") } dst = dst.Resize(3) dst.vec[0], dst.vec[1], dst.vec[2] = vn.vec[1]*other.vec[2]-vn.vec[2]*other.vec[1], vn.vec[2]*other.vec[0]-vn.vec[0]*other.vec[2], vn.vec[0]*other.vec[1]-vn.vec[1]*other.vec[0] return dst }
go
func (vn *VecN) Cross(dst *VecN, other *VecN) *VecN { if vn == nil || other == nil { return nil } if len(vn.vec) != 3 || len(other.vec) != 3 { panic("Cannot take binary cross product of non-3D elements (7D cross product not implemented)") } dst = dst.Resize(3) dst.vec[0], dst.vec[1], dst.vec[2] = vn.vec[1]*other.vec[2]-vn.vec[2]*other.vec[1], vn.vec[2]*other.vec[0]-vn.vec[0]*other.vec[2], vn.vec[0]*other.vec[1]-vn.vec[1]*other.vec[0] return dst }
[ "func", "(", "vn", "*", "VecN", ")", "Cross", "(", "dst", "*", "VecN", ",", "other", "*", "VecN", ")", "*", "VecN", "{", "if", "vn", "==", "nil", "||", "other", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "if", "len", "(", "vn", ".", "vec", ")", "!=", "3", "||", "len", "(", "other", ".", "vec", ")", "!=", "3", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n\n", "dst", "=", "dst", ".", "Resize", "(", "3", ")", "\n", "dst", ".", "vec", "[", "0", "]", ",", "dst", ".", "vec", "[", "1", "]", ",", "dst", ".", "vec", "[", "2", "]", "=", "vn", ".", "vec", "[", "1", "]", "*", "other", ".", "vec", "[", "2", "]", "-", "vn", ".", "vec", "[", "2", "]", "*", "other", ".", "vec", "[", "1", "]", ",", "vn", ".", "vec", "[", "2", "]", "*", "other", ".", "vec", "[", "0", "]", "-", "vn", ".", "vec", "[", "0", "]", "*", "other", ".", "vec", "[", "2", "]", ",", "vn", ".", "vec", "[", "0", "]", "*", "other", ".", "vec", "[", "1", "]", "-", "vn", ".", "vec", "[", "1", "]", "*", "other", ".", "vec", "[", "0", "]", "\n\n", "return", "dst", "\n", "}" ]
// Cross takes the binary cross product of vn and other, and stores it in dst. // If either vn or other are not of size 3 this function will panic // // If dst is not of sufficient size, or is nil, a new slice is allocated. // Dst is permitted to be one of the other arguments
[ "Cross", "takes", "the", "binary", "cross", "product", "of", "vn", "and", "other", "and", "stores", "it", "in", "dst", ".", "If", "either", "vn", "or", "other", "are", "not", "of", "size", "3", "this", "function", "will", "panic", "If", "dst", "is", "not", "of", "sufficient", "size", "or", "is", "nil", "a", "new", "slice", "is", "allocated", ".", "Dst", "is", "permitted", "to", "be", "one", "of", "the", "other", "arguments" ]
c4601bc793c7a480dab005cf969aab0d7a7fb07d
https://github.com/go-gl/mathgl/blob/c4601bc793c7a480dab005cf969aab0d7a7fb07d/mgl32/vecn.go#L185-L197
20,802
go-gl/mathgl
mgl32/vecn.go
Mul
func (vn *VecN) Mul(dst *VecN, c float32) *VecN { if vn == nil { return nil } dst = dst.Resize(len(vn.vec)) for i, el := range vn.vec { dst.vec[i] = el * c } return dst }
go
func (vn *VecN) Mul(dst *VecN, c float32) *VecN { if vn == nil { return nil } dst = dst.Resize(len(vn.vec)) for i, el := range vn.vec { dst.vec[i] = el * c } return dst }
[ "func", "(", "vn", "*", "VecN", ")", "Mul", "(", "dst", "*", "VecN", ",", "c", "float32", ")", "*", "VecN", "{", "if", "vn", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "dst", "=", "dst", ".", "Resize", "(", "len", "(", "vn", ".", "vec", ")", ")", "\n\n", "for", "i", ",", "el", ":=", "range", "vn", ".", "vec", "{", "dst", ".", "vec", "[", "i", "]", "=", "el", "*", "c", "\n", "}", "\n\n", "return", "dst", "\n", "}" ]
// Mul multiplies the vector by some scalar value and stores the result in dst, // which will be returned. Dst will be appropriately resized to the size of vn. // // The destination can be vn itself and nothing will go wrong.
[ "Mul", "multiplies", "the", "vector", "by", "some", "scalar", "value", "and", "stores", "the", "result", "in", "dst", "which", "will", "be", "returned", ".", "Dst", "will", "be", "appropriately", "resized", "to", "the", "size", "of", "vn", ".", "The", "destination", "can", "be", "vn", "itself", "and", "nothing", "will", "go", "wrong", "." ]
c4601bc793c7a480dab005cf969aab0d7a7fb07d
https://github.com/go-gl/mathgl/blob/c4601bc793c7a480dab005cf969aab0d7a7fb07d/mgl32/vecn.go#L270-L281
20,803
go-gl/mathgl
mgl32/vecn.go
Vec2
func (vn *VecN) Vec2() Vec2 { raw := vn.Raw() return Vec2{raw[0], raw[1]} }
go
func (vn *VecN) Vec2() Vec2 { raw := vn.Raw() return Vec2{raw[0], raw[1]} }
[ "func", "(", "vn", "*", "VecN", ")", "Vec2", "(", ")", "Vec2", "{", "raw", ":=", "vn", ".", "Raw", "(", ")", "\n", "return", "Vec2", "{", "raw", "[", "0", "]", ",", "raw", "[", "1", "]", "}", "\n", "}" ]
// Vec2 constructs a 2-dimensional vector by discarding coordinates.
[ "Vec2", "constructs", "a", "2", "-", "dimensional", "vector", "by", "discarding", "coordinates", "." ]
c4601bc793c7a480dab005cf969aab0d7a7fb07d
https://github.com/go-gl/mathgl/blob/c4601bc793c7a480dab005cf969aab0d7a7fb07d/mgl32/vecn.go#L356-L359
20,804
go-gl/mathgl
mgl32/vecn.go
Vec3
func (vn *VecN) Vec3() Vec3 { raw := vn.Raw() return Vec3{raw[0], raw[1], raw[2]} }
go
func (vn *VecN) Vec3() Vec3 { raw := vn.Raw() return Vec3{raw[0], raw[1], raw[2]} }
[ "func", "(", "vn", "*", "VecN", ")", "Vec3", "(", ")", "Vec3", "{", "raw", ":=", "vn", ".", "Raw", "(", ")", "\n", "return", "Vec3", "{", "raw", "[", "0", "]", ",", "raw", "[", "1", "]", ",", "raw", "[", "2", "]", "}", "\n", "}" ]
// Vec3 constructs a 3-dimensional vector by discarding coordinates.
[ "Vec3", "constructs", "a", "3", "-", "dimensional", "vector", "by", "discarding", "coordinates", "." ]
c4601bc793c7a480dab005cf969aab0d7a7fb07d
https://github.com/go-gl/mathgl/blob/c4601bc793c7a480dab005cf969aab0d7a7fb07d/mgl32/vecn.go#L362-L365
20,805
go-gl/mathgl
mgl32/vecn.go
Vec4
func (vn *VecN) Vec4() Vec4 { raw := vn.Raw() return Vec4{raw[0], raw[1], raw[2], raw[3]} }
go
func (vn *VecN) Vec4() Vec4 { raw := vn.Raw() return Vec4{raw[0], raw[1], raw[2], raw[3]} }
[ "func", "(", "vn", "*", "VecN", ")", "Vec4", "(", ")", "Vec4", "{", "raw", ":=", "vn", ".", "Raw", "(", ")", "\n", "return", "Vec4", "{", "raw", "[", "0", "]", ",", "raw", "[", "1", "]", ",", "raw", "[", "2", "]", ",", "raw", "[", "3", "]", "}", "\n", "}" ]
// Vec4 constructs a 4-dimensional vector by discarding coordinates.
[ "Vec4", "constructs", "a", "4", "-", "dimensional", "vector", "by", "discarding", "coordinates", "." ]
c4601bc793c7a480dab005cf969aab0d7a7fb07d
https://github.com/go-gl/mathgl/blob/c4601bc793c7a480dab005cf969aab0d7a7fb07d/mgl32/vecn.go#L368-L371
20,806
go-gl/mathgl
mgl32/matmn.go
CopyMatMN
func CopyMatMN(dst, src *MatMxN) { if dst == nil || src == nil { return } dst.Reshape(src.m, src.n) copy(dst.dat, src.dat) }
go
func CopyMatMN(dst, src *MatMxN) { if dst == nil || src == nil { return } dst.Reshape(src.m, src.n) copy(dst.dat, src.dat) }
[ "func", "CopyMatMN", "(", "dst", ",", "src", "*", "MatMxN", ")", "{", "if", "dst", "==", "nil", "||", "src", "==", "nil", "{", "return", "\n", "}", "\n", "dst", ".", "Reshape", "(", "src", ".", "m", ",", "src", ".", "n", ")", "\n", "copy", "(", "dst", ".", "dat", ",", "src", ".", "dat", ")", "\n", "}" ]
// CopyMatMN copies src into dst. This Reshapes dst // to the same size as src. // // If dst or src is nil, this is a no-op
[ "CopyMatMN", "copies", "src", "into", "dst", ".", "This", "Reshapes", "dst", "to", "the", "same", "size", "as", "src", ".", "If", "dst", "or", "src", "is", "nil", "this", "is", "a", "no", "-", "op" ]
c4601bc793c7a480dab005cf969aab0d7a7fb07d
https://github.com/go-gl/mathgl/blob/c4601bc793c7a480dab005cf969aab0d7a7fb07d/mgl32/matmn.go#L66-L72
20,807
go-gl/mathgl
mgl32/matmn.go
IdentN
func IdentN(dst *MatMxN, n int) *MatMxN { dst = dst.Reshape(n, n) for i := 0; i < n; i++ { for j := 0; j < n; j++ { if i == j { dst.Set(i, j, 1) } else { dst.Set(i, j, 0) } } } return dst }
go
func IdentN(dst *MatMxN, n int) *MatMxN { dst = dst.Reshape(n, n) for i := 0; i < n; i++ { for j := 0; j < n; j++ { if i == j { dst.Set(i, j, 1) } else { dst.Set(i, j, 0) } } } return dst }
[ "func", "IdentN", "(", "dst", "*", "MatMxN", ",", "n", "int", ")", "*", "MatMxN", "{", "dst", "=", "dst", ".", "Reshape", "(", "n", ",", "n", ")", "\n\n", "for", "i", ":=", "0", ";", "i", "<", "n", ";", "i", "++", "{", "for", "j", ":=", "0", ";", "j", "<", "n", ";", "j", "++", "{", "if", "i", "==", "j", "{", "dst", ".", "Set", "(", "i", ",", "j", ",", "1", ")", "\n", "}", "else", "{", "dst", ".", "Set", "(", "i", ",", "j", ",", "0", ")", "\n", "}", "\n", "}", "\n", "}", "\n\n", "return", "dst", "\n", "}" ]
// IdentN stores the NxN identity matrix in dst, reallocating as necessary.
[ "IdentN", "stores", "the", "NxN", "identity", "matrix", "in", "dst", "reallocating", "as", "necessary", "." ]
c4601bc793c7a480dab005cf969aab0d7a7fb07d
https://github.com/go-gl/mathgl/blob/c4601bc793c7a480dab005cf969aab0d7a7fb07d/mgl32/matmn.go#L75-L89
20,808
go-gl/mathgl
mgl32/matmn.go
Zero
func (mat *MatMxN) Zero(m, n int) { if mat == nil { return } mat.Reshape(m, n) for i := range mat.dat { mat.dat[i] = 0 } }
go
func (mat *MatMxN) Zero(m, n int) { if mat == nil { return } mat.Reshape(m, n) for i := range mat.dat { mat.dat[i] = 0 } }
[ "func", "(", "mat", "*", "MatMxN", ")", "Zero", "(", "m", ",", "n", "int", ")", "{", "if", "mat", "==", "nil", "{", "return", "\n", "}", "\n\n", "mat", ".", "Reshape", "(", "m", ",", "n", ")", "\n", "for", "i", ":=", "range", "mat", ".", "dat", "{", "mat", ".", "dat", "[", "i", "]", "=", "0", "\n", "}", "\n", "}" ]
// Zero reshapes the matrix to m by n and zeroes out all // elements.
[ "Zero", "reshapes", "the", "matrix", "to", "m", "by", "n", "and", "zeroes", "out", "all", "elements", "." ]
c4601bc793c7a480dab005cf969aab0d7a7fb07d
https://github.com/go-gl/mathgl/blob/c4601bc793c7a480dab005cf969aab0d7a7fb07d/mgl32/matmn.go#L116-L125
20,809
go-gl/mathgl
mgl32/matmn.go
destroy
func (mat *MatMxN) destroy() { if mat == nil { return } if shouldPool && mat.dat != nil { returnToPool(mat.dat) } mat.m, mat.n = 0, 0 mat.dat = nil }
go
func (mat *MatMxN) destroy() { if mat == nil { return } if shouldPool && mat.dat != nil { returnToPool(mat.dat) } mat.m, mat.n = 0, 0 mat.dat = nil }
[ "func", "(", "mat", "*", "MatMxN", ")", "destroy", "(", ")", "{", "if", "mat", "==", "nil", "{", "return", "\n", "}", "\n\n", "if", "shouldPool", "&&", "mat", ".", "dat", "!=", "nil", "{", "returnToPool", "(", "mat", ".", "dat", ")", "\n", "}", "\n", "mat", ".", "m", ",", "mat", ".", "n", "=", "0", ",", "0", "\n", "mat", ".", "dat", "=", "nil", "\n", "}" ]
// destroy returns the underlying matrix slice to the memory pool
[ "destroy", "returns", "the", "underlying", "matrix", "slice", "to", "the", "memory", "pool" ]
c4601bc793c7a480dab005cf969aab0d7a7fb07d
https://github.com/go-gl/mathgl/blob/c4601bc793c7a480dab005cf969aab0d7a7fb07d/mgl32/matmn.go#L128-L138
20,810
go-gl/mathgl
mgl32/matmn.go
Transpose
func (mat *MatMxN) Transpose(dst *MatMxN) (t *MatMxN) { if mat == nil { return nil } if dst == mat { dst = NewMatrix(mat.n, mat.m) // Copy data to correct matrix, // delete temporary buffer, // and set the return value to the // correct one defer func() { copy(mat.dat, dst.dat) mat.m, mat.n = mat.n, mat.m dst.destroy() t = mat }() return mat } else { dst = dst.Reshape(mat.n, mat.m) } for r := 0; r < mat.m; r++ { for c := 0; c < mat.n; c++ { dst.dat[r*dst.m+c] = mat.dat[c*mat.m+r] } } return dst }
go
func (mat *MatMxN) Transpose(dst *MatMxN) (t *MatMxN) { if mat == nil { return nil } if dst == mat { dst = NewMatrix(mat.n, mat.m) // Copy data to correct matrix, // delete temporary buffer, // and set the return value to the // correct one defer func() { copy(mat.dat, dst.dat) mat.m, mat.n = mat.n, mat.m dst.destroy() t = mat }() return mat } else { dst = dst.Reshape(mat.n, mat.m) } for r := 0; r < mat.m; r++ { for c := 0; c < mat.n; c++ { dst.dat[r*dst.m+c] = mat.dat[c*mat.m+r] } } return dst }
[ "func", "(", "mat", "*", "MatMxN", ")", "Transpose", "(", "dst", "*", "MatMxN", ")", "(", "t", "*", "MatMxN", ")", "{", "if", "mat", "==", "nil", "{", "return", "nil", "\n", "}", "\n\n", "if", "dst", "==", "mat", "{", "dst", "=", "NewMatrix", "(", "mat", ".", "n", ",", "mat", ".", "m", ")", "\n\n", "// Copy data to correct matrix,", "// delete temporary buffer,", "// and set the return value to the", "// correct one", "defer", "func", "(", ")", "{", "copy", "(", "mat", ".", "dat", ",", "dst", ".", "dat", ")", "\n\n", "mat", ".", "m", ",", "mat", ".", "n", "=", "mat", ".", "n", ",", "mat", ".", "m", "\n\n", "dst", ".", "destroy", "(", ")", "\n", "t", "=", "mat", "\n", "}", "(", ")", "\n\n", "return", "mat", "\n", "}", "else", "{", "dst", "=", "dst", ".", "Reshape", "(", "mat", ".", "n", ",", "mat", ".", "m", ")", "\n", "}", "\n\n", "for", "r", ":=", "0", ";", "r", "<", "mat", ".", "m", ";", "r", "++", "{", "for", "c", ":=", "0", ";", "c", "<", "mat", ".", "n", ";", "c", "++", "{", "dst", ".", "dat", "[", "r", "*", "dst", ".", "m", "+", "c", "]", "=", "mat", ".", "dat", "[", "c", "*", "mat", ".", "m", "+", "r", "]", "\n", "}", "\n", "}", "\n\n", "return", "dst", "\n", "}" ]
// Transpose takes the transpose of mat and puts it in dst. // // If dst is not of the correct dimensions, it will be Reshaped, // if dst and mat are the same, a temporary matrix of the correct size will // be allocated; these resources will be released via the memory pool. // // This should be improved in the future.
[ "Transpose", "takes", "the", "transpose", "of", "mat", "and", "puts", "it", "in", "dst", ".", "If", "dst", "is", "not", "of", "the", "correct", "dimensions", "it", "will", "be", "Reshaped", "if", "dst", "and", "mat", "are", "the", "same", "a", "temporary", "matrix", "of", "the", "correct", "size", "will", "be", "allocated", ";", "these", "resources", "will", "be", "released", "via", "the", "memory", "pool", ".", "This", "should", "be", "improved", "in", "the", "future", "." ]
c4601bc793c7a480dab005cf969aab0d7a7fb07d
https://github.com/go-gl/mathgl/blob/c4601bc793c7a480dab005cf969aab0d7a7fb07d/mgl32/matmn.go#L228-L261
20,811
go-gl/mathgl
mgl32/matmn.go
NumRowCols
func (mat *MatMxN) NumRowCols() (rows, cols int) { return mat.m, mat.n }
go
func (mat *MatMxN) NumRowCols() (rows, cols int) { return mat.m, mat.n }
[ "func", "(", "mat", "*", "MatMxN", ")", "NumRowCols", "(", ")", "(", "rows", ",", "cols", "int", ")", "{", "return", "mat", ".", "m", ",", "mat", ".", "n", "\n", "}" ]
// NumRowCols returns the number of rows and columns in this matrix // as a single operation
[ "NumRowCols", "returns", "the", "number", "of", "rows", "and", "columns", "in", "this", "matrix", "as", "a", "single", "operation" ]
c4601bc793c7a480dab005cf969aab0d7a7fb07d
https://github.com/go-gl/mathgl/blob/c4601bc793c7a480dab005cf969aab0d7a7fb07d/mgl32/matmn.go#L284-L286
20,812
go-gl/mathgl
mgl32/matmn.go
Add
func (mat *MatMxN) Add(dst *MatMxN, addend *MatMxN) *MatMxN { if mat == nil || addend == nil || mat.m != addend.m || mat.n != addend.n { return nil } dst = dst.Reshape(mat.m, mat.n) // No need to care about rows and columns // since it's element-wise anyway for i, el := range mat.dat { dst.dat[i] = el + addend.dat[i] } return dst }
go
func (mat *MatMxN) Add(dst *MatMxN, addend *MatMxN) *MatMxN { if mat == nil || addend == nil || mat.m != addend.m || mat.n != addend.n { return nil } dst = dst.Reshape(mat.m, mat.n) // No need to care about rows and columns // since it's element-wise anyway for i, el := range mat.dat { dst.dat[i] = el + addend.dat[i] } return dst }
[ "func", "(", "mat", "*", "MatMxN", ")", "Add", "(", "dst", "*", "MatMxN", ",", "addend", "*", "MatMxN", ")", "*", "MatMxN", "{", "if", "mat", "==", "nil", "||", "addend", "==", "nil", "||", "mat", ".", "m", "!=", "addend", ".", "m", "||", "mat", ".", "n", "!=", "addend", ".", "n", "{", "return", "nil", "\n", "}", "\n\n", "dst", "=", "dst", ".", "Reshape", "(", "mat", ".", "m", ",", "mat", ".", "n", ")", "\n\n", "// No need to care about rows and columns", "// since it's element-wise anyway", "for", "i", ",", "el", ":=", "range", "mat", ".", "dat", "{", "dst", ".", "dat", "[", "i", "]", "=", "el", "+", "addend", ".", "dat", "[", "i", "]", "\n", "}", "\n\n", "return", "dst", "\n", "}" ]
// Add is the arithemtic + operator defined on a MatMxN.
[ "Add", "is", "the", "arithemtic", "+", "operator", "defined", "on", "a", "MatMxN", "." ]
c4601bc793c7a480dab005cf969aab0d7a7fb07d
https://github.com/go-gl/mathgl/blob/c4601bc793c7a480dab005cf969aab0d7a7fb07d/mgl32/matmn.go#L305-L319
20,813
go-gl/mathgl
mgl32/matmn.go
Sub
func (mat *MatMxN) Sub(dst *MatMxN, subtrahend *MatMxN) *MatMxN { if mat == nil || subtrahend == nil || mat.m != subtrahend.m || mat.n != subtrahend.n { return nil } dst = dst.Reshape(mat.m, mat.n) // No need to care about rows and columns // since it's element-wise anyway for i, el := range mat.dat { dst.dat[i] = el - subtrahend.dat[i] } return dst }
go
func (mat *MatMxN) Sub(dst *MatMxN, subtrahend *MatMxN) *MatMxN { if mat == nil || subtrahend == nil || mat.m != subtrahend.m || mat.n != subtrahend.n { return nil } dst = dst.Reshape(mat.m, mat.n) // No need to care about rows and columns // since it's element-wise anyway for i, el := range mat.dat { dst.dat[i] = el - subtrahend.dat[i] } return dst }
[ "func", "(", "mat", "*", "MatMxN", ")", "Sub", "(", "dst", "*", "MatMxN", ",", "subtrahend", "*", "MatMxN", ")", "*", "MatMxN", "{", "if", "mat", "==", "nil", "||", "subtrahend", "==", "nil", "||", "mat", ".", "m", "!=", "subtrahend", ".", "m", "||", "mat", ".", "n", "!=", "subtrahend", ".", "n", "{", "return", "nil", "\n", "}", "\n\n", "dst", "=", "dst", ".", "Reshape", "(", "mat", ".", "m", ",", "mat", ".", "n", ")", "\n\n", "// No need to care about rows and columns", "// since it's element-wise anyway", "for", "i", ",", "el", ":=", "range", "mat", ".", "dat", "{", "dst", ".", "dat", "[", "i", "]", "=", "el", "-", "subtrahend", ".", "dat", "[", "i", "]", "\n", "}", "\n\n", "return", "dst", "\n", "}" ]
// Sub is the arithemtic - operator defined on a MatMxN.
[ "Sub", "is", "the", "arithemtic", "-", "operator", "defined", "on", "a", "MatMxN", "." ]
c4601bc793c7a480dab005cf969aab0d7a7fb07d
https://github.com/go-gl/mathgl/blob/c4601bc793c7a480dab005cf969aab0d7a7fb07d/mgl32/matmn.go#L322-L336
20,814
go-gl/mathgl
mgl32/matmn.go
Mul
func (mat *MatMxN) Mul(dst *MatMxN, c float32) *MatMxN { if mat == nil { return nil } dst = dst.Reshape(mat.m, mat.n) for i, el := range mat.dat { dst.dat[i] = el * c } return dst }
go
func (mat *MatMxN) Mul(dst *MatMxN, c float32) *MatMxN { if mat == nil { return nil } dst = dst.Reshape(mat.m, mat.n) for i, el := range mat.dat { dst.dat[i] = el * c } return dst }
[ "func", "(", "mat", "*", "MatMxN", ")", "Mul", "(", "dst", "*", "MatMxN", ",", "c", "float32", ")", "*", "MatMxN", "{", "if", "mat", "==", "nil", "{", "return", "nil", "\n", "}", "\n\n", "dst", "=", "dst", ".", "Reshape", "(", "mat", ".", "m", ",", "mat", ".", "n", ")", "\n\n", "for", "i", ",", "el", ":=", "range", "mat", ".", "dat", "{", "dst", ".", "dat", "[", "i", "]", "=", "el", "*", "c", "\n", "}", "\n\n", "return", "dst", "\n", "}" ]
// Mul performs a scalar multiplication between mat and some constant c, // storing the result in dst. Mat and dst can be equal. If dst is not the // correct size, a Reshape will occur.
[ "Mul", "performs", "a", "scalar", "multiplication", "between", "mat", "and", "some", "constant", "c", "storing", "the", "result", "in", "dst", ".", "Mat", "and", "dst", "can", "be", "equal", ".", "If", "dst", "is", "not", "the", "correct", "size", "a", "Reshape", "will", "occur", "." ]
c4601bc793c7a480dab005cf969aab0d7a7fb07d
https://github.com/go-gl/mathgl/blob/c4601bc793c7a480dab005cf969aab0d7a7fb07d/mgl32/matmn.go#L387-L399
20,815
go-gl/mathgl
mgl32/matmn.go
MulNx1
func (mat *MatMxN) MulNx1(dst, v *VecN) *VecN { if mat == nil || v == nil || mat.n != len(v.vec) { return nil } if dst == v { v = NewVecN(len(v.vec)) copy(v.vec, dst.vec) defer v.destroy() } dst = dst.Resize(mat.m) for r := 0; r < mat.m; r++ { dst.vec[r] = 0 for c := 0; c < mat.n; c++ { dst.vec[r] += mat.At(r, c) * v.vec[c] } } return dst }
go
func (mat *MatMxN) MulNx1(dst, v *VecN) *VecN { if mat == nil || v == nil || mat.n != len(v.vec) { return nil } if dst == v { v = NewVecN(len(v.vec)) copy(v.vec, dst.vec) defer v.destroy() } dst = dst.Resize(mat.m) for r := 0; r < mat.m; r++ { dst.vec[r] = 0 for c := 0; c < mat.n; c++ { dst.vec[r] += mat.At(r, c) * v.vec[c] } } return dst }
[ "func", "(", "mat", "*", "MatMxN", ")", "MulNx1", "(", "dst", ",", "v", "*", "VecN", ")", "*", "VecN", "{", "if", "mat", "==", "nil", "||", "v", "==", "nil", "||", "mat", ".", "n", "!=", "len", "(", "v", ".", "vec", ")", "{", "return", "nil", "\n", "}", "\n", "if", "dst", "==", "v", "{", "v", "=", "NewVecN", "(", "len", "(", "v", ".", "vec", ")", ")", "\n", "copy", "(", "v", ".", "vec", ",", "dst", ".", "vec", ")", "\n\n", "defer", "v", ".", "destroy", "(", ")", "\n", "}", "\n\n", "dst", "=", "dst", ".", "Resize", "(", "mat", ".", "m", ")", "\n\n", "for", "r", ":=", "0", ";", "r", "<", "mat", ".", "m", ";", "r", "++", "{", "dst", ".", "vec", "[", "r", "]", "=", "0", "\n\n", "for", "c", ":=", "0", ";", "c", "<", "mat", ".", "n", ";", "c", "++", "{", "dst", ".", "vec", "[", "r", "]", "+=", "mat", ".", "At", "(", "r", ",", "c", ")", "*", "v", ".", "vec", "[", "c", "]", "\n", "}", "\n", "}", "\n\n", "return", "dst", "\n", "}" ]
// MulNx1 multiplies the matrix by a vector of size n. If mat or v is nil, this // returns nil. If the number of columns in mat does not match the Size of v, // this also returns nil. // // Dst will be resized if it's not big enough. If dst == v; a temporary vector // will be allocated and returned via the realloc callback when complete.
[ "MulNx1", "multiplies", "the", "matrix", "by", "a", "vector", "of", "size", "n", ".", "If", "mat", "or", "v", "is", "nil", "this", "returns", "nil", ".", "If", "the", "number", "of", "columns", "in", "mat", "does", "not", "match", "the", "Size", "of", "v", "this", "also", "returns", "nil", ".", "Dst", "will", "be", "resized", "if", "it", "s", "not", "big", "enough", ".", "If", "dst", "==", "v", ";", "a", "temporary", "vector", "will", "be", "allocated", "and", "returned", "via", "the", "realloc", "callback", "when", "complete", "." ]
c4601bc793c7a480dab005cf969aab0d7a7fb07d
https://github.com/go-gl/mathgl/blob/c4601bc793c7a480dab005cf969aab0d7a7fb07d/mgl32/matmn.go#L407-L429
20,816
go-gl/mathgl
mgl64/quat.go
Add
func (q1 Quat) Add(q2 Quat) Quat { return Quat{q1.W + q2.W, q1.V.Add(q2.V)} }
go
func (q1 Quat) Add(q2 Quat) Quat { return Quat{q1.W + q2.W, q1.V.Add(q2.V)} }
[ "func", "(", "q1", "Quat", ")", "Add", "(", "q2", "Quat", ")", "Quat", "{", "return", "Quat", "{", "q1", ".", "W", "+", "q2", ".", "W", ",", "q1", ".", "V", ".", "Add", "(", "q2", ".", "V", ")", "}", "\n", "}" ]
// Add adds two quaternions. It's no more complicated than // adding their W and V components.
[ "Add", "adds", "two", "quaternions", ".", "It", "s", "no", "more", "complicated", "than", "adding", "their", "W", "and", "V", "components", "." ]
c4601bc793c7a480dab005cf969aab0d7a7fb07d
https://github.com/go-gl/mathgl/blob/c4601bc793c7a480dab005cf969aab0d7a7fb07d/mgl64/quat.go#L83-L85
20,817
go-gl/mathgl
mgl64/quat.go
Sub
func (q1 Quat) Sub(q2 Quat) Quat { return Quat{q1.W - q2.W, q1.V.Sub(q2.V)} }
go
func (q1 Quat) Sub(q2 Quat) Quat { return Quat{q1.W - q2.W, q1.V.Sub(q2.V)} }
[ "func", "(", "q1", "Quat", ")", "Sub", "(", "q2", "Quat", ")", "Quat", "{", "return", "Quat", "{", "q1", ".", "W", "-", "q2", ".", "W", ",", "q1", ".", "V", ".", "Sub", "(", "q2", ".", "V", ")", "}", "\n", "}" ]
// Sub subtracts two quaternions. It's no more complicated than // subtracting their W and V components.
[ "Sub", "subtracts", "two", "quaternions", ".", "It", "s", "no", "more", "complicated", "than", "subtracting", "their", "W", "and", "V", "components", "." ]
c4601bc793c7a480dab005cf969aab0d7a7fb07d
https://github.com/go-gl/mathgl/blob/c4601bc793c7a480dab005cf969aab0d7a7fb07d/mgl64/quat.go#L89-L91
20,818
go-gl/mathgl
mgl64/quat.go
Len
func (q1 Quat) Len() float64 { return float64(math.Sqrt(float64(q1.W*q1.W + q1.V[0]*q1.V[0] + q1.V[1]*q1.V[1] + q1.V[2]*q1.V[2]))) }
go
func (q1 Quat) Len() float64 { return float64(math.Sqrt(float64(q1.W*q1.W + q1.V[0]*q1.V[0] + q1.V[1]*q1.V[1] + q1.V[2]*q1.V[2]))) }
[ "func", "(", "q1", "Quat", ")", "Len", "(", ")", "float64", "{", "return", "float64", "(", "math", ".", "Sqrt", "(", "float64", "(", "q1", ".", "W", "*", "q1", ".", "W", "+", "q1", ".", "V", "[", "0", "]", "*", "q1", ".", "V", "[", "0", "]", "+", "q1", ".", "V", "[", "1", "]", "*", "q1", ".", "V", "[", "1", "]", "+", "q1", ".", "V", "[", "2", "]", "*", "q1", ".", "V", "[", "2", "]", ")", ")", ")", "\n", "}" ]
// Len gives the Length of the quaternion, also known as its Norm. This is the // same thing as the Len of a Vec4.
[ "Len", "gives", "the", "Length", "of", "the", "quaternion", "also", "known", "as", "its", "Norm", ".", "This", "is", "the", "same", "thing", "as", "the", "Len", "of", "a", "Vec4", "." ]
c4601bc793c7a480dab005cf969aab0d7a7fb07d
https://github.com/go-gl/mathgl/blob/c4601bc793c7a480dab005cf969aab0d7a7fb07d/mgl64/quat.go#L113-L115
20,819
go-gl/mathgl
mgl64/quat.go
Mat4
func (q1 Quat) Mat4() Mat4 { w, x, y, z := q1.W, q1.V[0], q1.V[1], q1.V[2] return Mat4{ 1 - 2*y*y - 2*z*z, 2*x*y + 2*w*z, 2*x*z - 2*w*y, 0, 2*x*y - 2*w*z, 1 - 2*x*x - 2*z*z, 2*y*z + 2*w*x, 0, 2*x*z + 2*w*y, 2*y*z - 2*w*x, 1 - 2*x*x - 2*y*y, 0, 0, 0, 0, 1, } }
go
func (q1 Quat) Mat4() Mat4 { w, x, y, z := q1.W, q1.V[0], q1.V[1], q1.V[2] return Mat4{ 1 - 2*y*y - 2*z*z, 2*x*y + 2*w*z, 2*x*z - 2*w*y, 0, 2*x*y - 2*w*z, 1 - 2*x*x - 2*z*z, 2*y*z + 2*w*x, 0, 2*x*z + 2*w*y, 2*y*z - 2*w*x, 1 - 2*x*x - 2*y*y, 0, 0, 0, 0, 1, } }
[ "func", "(", "q1", "Quat", ")", "Mat4", "(", ")", "Mat4", "{", "w", ",", "x", ",", "y", ",", "z", ":=", "q1", ".", "W", ",", "q1", ".", "V", "[", "0", "]", ",", "q1", ".", "V", "[", "1", "]", ",", "q1", ".", "V", "[", "2", "]", "\n", "return", "Mat4", "{", "1", "-", "2", "*", "y", "*", "y", "-", "2", "*", "z", "*", "z", ",", "2", "*", "x", "*", "y", "+", "2", "*", "w", "*", "z", ",", "2", "*", "x", "*", "z", "-", "2", "*", "w", "*", "y", ",", "0", ",", "2", "*", "x", "*", "y", "-", "2", "*", "w", "*", "z", ",", "1", "-", "2", "*", "x", "*", "x", "-", "2", "*", "z", "*", "z", ",", "2", "*", "y", "*", "z", "+", "2", "*", "w", "*", "x", ",", "0", ",", "2", "*", "x", "*", "z", "+", "2", "*", "w", "*", "y", ",", "2", "*", "y", "*", "z", "-", "2", "*", "w", "*", "x", ",", "1", "-", "2", "*", "x", "*", "x", "-", "2", "*", "y", "*", "y", ",", "0", ",", "0", ",", "0", ",", "0", ",", "1", ",", "}", "\n", "}" ]
// Mat4 returns the homogeneous 3D rotation matrix corresponding to the // quaternion.
[ "Mat4", "returns", "the", "homogeneous", "3D", "rotation", "matrix", "corresponding", "to", "the", "quaternion", "." ]
c4601bc793c7a480dab005cf969aab0d7a7fb07d
https://github.com/go-gl/mathgl/blob/c4601bc793c7a480dab005cf969aab0d7a7fb07d/mgl64/quat.go#L168-L176
20,820
go-gl/mathgl
mgl64/quat.go
ApproxEqual
func (q1 Quat) ApproxEqual(q2 Quat) bool { return FloatEqual(q1.W, q2.W) && q1.V.ApproxEqual(q2.V) }
go
func (q1 Quat) ApproxEqual(q2 Quat) bool { return FloatEqual(q1.W, q2.W) && q1.V.ApproxEqual(q2.V) }
[ "func", "(", "q1", "Quat", ")", "ApproxEqual", "(", "q2", "Quat", ")", "bool", "{", "return", "FloatEqual", "(", "q1", ".", "W", ",", "q2", ".", "W", ")", "&&", "q1", ".", "V", ".", "ApproxEqual", "(", "q2", ".", "V", ")", "\n", "}" ]
// ApproxEqual returns whether the quaternions are approximately equal, as if // FloatEqual was called on each matching element
[ "ApproxEqual", "returns", "whether", "the", "quaternions", "are", "approximately", "equal", "as", "if", "FloatEqual", "was", "called", "on", "each", "matching", "element" ]
c4601bc793c7a480dab005cf969aab0d7a7fb07d
https://github.com/go-gl/mathgl/blob/c4601bc793c7a480dab005cf969aab0d7a7fb07d/mgl64/quat.go#L185-L187
20,821
go-gl/mathgl
mgl64/quat.go
Mat4ToQuat
func Mat4ToQuat(m Mat4) Quat { // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm if tr := m[0] + m[5] + m[10]; tr > 0 { s := float64(0.5 / math.Sqrt(float64(tr+1.0))) return Quat{ 0.25 / s, Vec3{ (m[6] - m[9]) * s, (m[8] - m[2]) * s, (m[1] - m[4]) * s, }, } } if (m[0] > m[5]) && (m[0] > m[10]) { s := float64(2.0 * math.Sqrt(float64(1.0+m[0]-m[5]-m[10]))) return Quat{ (m[6] - m[9]) / s, Vec3{ 0.25 * s, (m[4] + m[1]) / s, (m[8] + m[2]) / s, }, } } if m[5] > m[10] { s := float64(2.0 * math.Sqrt(float64(1.0+m[5]-m[0]-m[10]))) return Quat{ (m[8] - m[2]) / s, Vec3{ (m[4] + m[1]) / s, 0.25 * s, (m[9] + m[6]) / s, }, } } s := float64(2.0 * math.Sqrt(float64(1.0+m[10]-m[0]-m[5]))) return Quat{ (m[1] - m[4]) / s, Vec3{ (m[8] + m[2]) / s, (m[9] + m[6]) / s, 0.25 * s, }, } }
go
func Mat4ToQuat(m Mat4) Quat { // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm if tr := m[0] + m[5] + m[10]; tr > 0 { s := float64(0.5 / math.Sqrt(float64(tr+1.0))) return Quat{ 0.25 / s, Vec3{ (m[6] - m[9]) * s, (m[8] - m[2]) * s, (m[1] - m[4]) * s, }, } } if (m[0] > m[5]) && (m[0] > m[10]) { s := float64(2.0 * math.Sqrt(float64(1.0+m[0]-m[5]-m[10]))) return Quat{ (m[6] - m[9]) / s, Vec3{ 0.25 * s, (m[4] + m[1]) / s, (m[8] + m[2]) / s, }, } } if m[5] > m[10] { s := float64(2.0 * math.Sqrt(float64(1.0+m[5]-m[0]-m[10]))) return Quat{ (m[8] - m[2]) / s, Vec3{ (m[4] + m[1]) / s, 0.25 * s, (m[9] + m[6]) / s, }, } } s := float64(2.0 * math.Sqrt(float64(1.0+m[10]-m[0]-m[5]))) return Quat{ (m[1] - m[4]) / s, Vec3{ (m[8] + m[2]) / s, (m[9] + m[6]) / s, 0.25 * s, }, } }
[ "func", "Mat4ToQuat", "(", "m", "Mat4", ")", "Quat", "{", "// http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm", "if", "tr", ":=", "m", "[", "0", "]", "+", "m", "[", "5", "]", "+", "m", "[", "10", "]", ";", "tr", ">", "0", "{", "s", ":=", "float64", "(", "0.5", "/", "math", ".", "Sqrt", "(", "float64", "(", "tr", "+", "1.0", ")", ")", ")", "\n", "return", "Quat", "{", "0.25", "/", "s", ",", "Vec3", "{", "(", "m", "[", "6", "]", "-", "m", "[", "9", "]", ")", "*", "s", ",", "(", "m", "[", "8", "]", "-", "m", "[", "2", "]", ")", "*", "s", ",", "(", "m", "[", "1", "]", "-", "m", "[", "4", "]", ")", "*", "s", ",", "}", ",", "}", "\n", "}", "\n\n", "if", "(", "m", "[", "0", "]", ">", "m", "[", "5", "]", ")", "&&", "(", "m", "[", "0", "]", ">", "m", "[", "10", "]", ")", "{", "s", ":=", "float64", "(", "2.0", "*", "math", ".", "Sqrt", "(", "float64", "(", "1.0", "+", "m", "[", "0", "]", "-", "m", "[", "5", "]", "-", "m", "[", "10", "]", ")", ")", ")", "\n", "return", "Quat", "{", "(", "m", "[", "6", "]", "-", "m", "[", "9", "]", ")", "/", "s", ",", "Vec3", "{", "0.25", "*", "s", ",", "(", "m", "[", "4", "]", "+", "m", "[", "1", "]", ")", "/", "s", ",", "(", "m", "[", "8", "]", "+", "m", "[", "2", "]", ")", "/", "s", ",", "}", ",", "}", "\n", "}", "\n\n", "if", "m", "[", "5", "]", ">", "m", "[", "10", "]", "{", "s", ":=", "float64", "(", "2.0", "*", "math", ".", "Sqrt", "(", "float64", "(", "1.0", "+", "m", "[", "5", "]", "-", "m", "[", "0", "]", "-", "m", "[", "10", "]", ")", ")", ")", "\n", "return", "Quat", "{", "(", "m", "[", "8", "]", "-", "m", "[", "2", "]", ")", "/", "s", ",", "Vec3", "{", "(", "m", "[", "4", "]", "+", "m", "[", "1", "]", ")", "/", "s", ",", "0.25", "*", "s", ",", "(", "m", "[", "9", "]", "+", "m", "[", "6", "]", ")", "/", "s", ",", "}", ",", "}", "\n\n", "}", "\n\n", "s", ":=", "float64", "(", "2.0", "*", "math", ".", "Sqrt", "(", "float64", "(", "1.0", "+", "m", "[", "10", "]", "-", "m", "[", "0", "]", "-", "m", "[", "5", "]", ")", ")", ")", "\n", "return", "Quat", "{", "(", "m", "[", "1", "]", "-", "m", "[", "4", "]", ")", "/", "s", ",", "Vec3", "{", "(", "m", "[", "8", "]", "+", "m", "[", "2", "]", ")", "/", "s", ",", "(", "m", "[", "9", "]", "+", "m", "[", "6", "]", ")", "/", "s", ",", "0.25", "*", "s", ",", "}", ",", "}", "\n", "}" ]
// Mat4ToQuat converts a pure rotation matrix into a quaternion
[ "Mat4ToQuat", "converts", "a", "pure", "rotation", "matrix", "into", "a", "quaternion" ]
c4601bc793c7a480dab005cf969aab0d7a7fb07d
https://github.com/go-gl/mathgl/blob/c4601bc793c7a480dab005cf969aab0d7a7fb07d/mgl64/quat.go#L354-L403
20,822
go-gl/mathgl
mgl64/quat.go
QuatLookAtV
func QuatLookAtV(eye, center, up Vec3) Quat { // http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-17-quaternions/#I_need_an_equivalent_of_gluLookAt__How_do_I_orient_an_object_towards_a_point__ // https://bitbucket.org/sinbad/ogre/src/d2ef494c4a2f5d6e2f0f17d3bfb9fd936d5423bb/OgreMain/src/OgreCamera.cpp?at=default#cl-161 direction := center.Sub(eye).Normalize() // Find the rotation between the front of the object (that we assume towards Z-, // but this depends on your model) and the desired direction rotDir := QuatBetweenVectors(Vec3{0, 0, -1}, direction) // Recompute up so that it's perpendicular to the direction // You can skip that part if you really want to force up //right := direction.Cross(up) //up = right.Cross(direction) // Because of the 1rst rotation, the up is probably completely screwed up. // Find the rotation between the "up" of the rotated object, and the desired up upCur := rotDir.Rotate(Vec3{0, 1, 0}) rotUp := QuatBetweenVectors(upCur, up) rotTarget := rotUp.Mul(rotDir) // remember, in reverse order. return rotTarget.Inverse() // camera rotation should be inversed! }
go
func QuatLookAtV(eye, center, up Vec3) Quat { // http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-17-quaternions/#I_need_an_equivalent_of_gluLookAt__How_do_I_orient_an_object_towards_a_point__ // https://bitbucket.org/sinbad/ogre/src/d2ef494c4a2f5d6e2f0f17d3bfb9fd936d5423bb/OgreMain/src/OgreCamera.cpp?at=default#cl-161 direction := center.Sub(eye).Normalize() // Find the rotation between the front of the object (that we assume towards Z-, // but this depends on your model) and the desired direction rotDir := QuatBetweenVectors(Vec3{0, 0, -1}, direction) // Recompute up so that it's perpendicular to the direction // You can skip that part if you really want to force up //right := direction.Cross(up) //up = right.Cross(direction) // Because of the 1rst rotation, the up is probably completely screwed up. // Find the rotation between the "up" of the rotated object, and the desired up upCur := rotDir.Rotate(Vec3{0, 1, 0}) rotUp := QuatBetweenVectors(upCur, up) rotTarget := rotUp.Mul(rotDir) // remember, in reverse order. return rotTarget.Inverse() // camera rotation should be inversed! }
[ "func", "QuatLookAtV", "(", "eye", ",", "center", ",", "up", "Vec3", ")", "Quat", "{", "// http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-17-quaternions/#I_need_an_equivalent_of_gluLookAt__How_do_I_orient_an_object_towards_a_point__", "// https://bitbucket.org/sinbad/ogre/src/d2ef494c4a2f5d6e2f0f17d3bfb9fd936d5423bb/OgreMain/src/OgreCamera.cpp?at=default#cl-161", "direction", ":=", "center", ".", "Sub", "(", "eye", ")", ".", "Normalize", "(", ")", "\n\n", "// Find the rotation between the front of the object (that we assume towards Z-,", "// but this depends on your model) and the desired direction", "rotDir", ":=", "QuatBetweenVectors", "(", "Vec3", "{", "0", ",", "0", ",", "-", "1", "}", ",", "direction", ")", "\n\n", "// Recompute up so that it's perpendicular to the direction", "// You can skip that part if you really want to force up", "//right := direction.Cross(up)", "//up = right.Cross(direction)", "// Because of the 1rst rotation, the up is probably completely screwed up.", "// Find the rotation between the \"up\" of the rotated object, and the desired up", "upCur", ":=", "rotDir", ".", "Rotate", "(", "Vec3", "{", "0", ",", "1", ",", "0", "}", ")", "\n", "rotUp", ":=", "QuatBetweenVectors", "(", "upCur", ",", "up", ")", "\n\n", "rotTarget", ":=", "rotUp", ".", "Mul", "(", "rotDir", ")", "// remember, in reverse order.", "\n", "return", "rotTarget", ".", "Inverse", "(", ")", "// camera rotation should be inversed!", "\n", "}" ]
// QuatLookAtV creates a rotation from an eye vector to a center vector // // It assumes the front of the rotated object at Z- and up at Y+
[ "QuatLookAtV", "creates", "a", "rotation", "from", "an", "eye", "vector", "to", "a", "center", "vector", "It", "assumes", "the", "front", "of", "the", "rotated", "object", "at", "Z", "-", "and", "up", "at", "Y", "+" ]
c4601bc793c7a480dab005cf969aab0d7a7fb07d
https://github.com/go-gl/mathgl/blob/c4601bc793c7a480dab005cf969aab0d7a7fb07d/mgl64/quat.go#L408-L430
20,823
go-gl/mathgl
mgl64/conv.go
SphericalToCylindrical
func SphericalToCylindrical(r, theta, phi float64) (rho, phi2, z float64) { s, c := math.Sincos(float64(theta)) rho = r * float64(s) z = r * float64(c) phi2 = phi return }
go
func SphericalToCylindrical(r, theta, phi float64) (rho, phi2, z float64) { s, c := math.Sincos(float64(theta)) rho = r * float64(s) z = r * float64(c) phi2 = phi return }
[ "func", "SphericalToCylindrical", "(", "r", ",", "theta", ",", "phi", "float64", ")", "(", "rho", ",", "phi2", ",", "z", "float64", ")", "{", "s", ",", "c", ":=", "math", ".", "Sincos", "(", "float64", "(", "theta", ")", ")", "\n\n", "rho", "=", "r", "*", "float64", "(", "s", ")", "\n", "z", "=", "r", "*", "float64", "(", "c", ")", "\n", "phi2", "=", "phi", "\n\n", "return", "\n", "}" ]
// SphericalToCylindrical converts spherical coordinates with radius r, // inclination theta, and azimuth phi to cylindrical coordinates with radial // distance r, azimuth phi, and height z. // // Angles are in radians
[ "SphericalToCylindrical", "converts", "spherical", "coordinates", "with", "radius", "r", "inclination", "theta", "and", "azimuth", "phi", "to", "cylindrical", "coordinates", "with", "radial", "distance", "r", "azimuth", "phi", "and", "height", "z", ".", "Angles", "are", "in", "radians" ]
c4601bc793c7a480dab005cf969aab0d7a7fb07d
https://github.com/go-gl/mathgl/blob/c4601bc793c7a480dab005cf969aab0d7a7fb07d/mgl64/conv.go#L55-L63
20,824
go-gl/mathgl
mgl64/conv.go
CylindircalToSpherical
func CylindircalToSpherical(rho, phi, z float64) (r, theta, phi2 float64) { r = float64(math.Hypot(float64(rho), float64(z))) phi2 = phi theta = float64(math.Atan2(float64(rho), float64(z))) return }
go
func CylindircalToSpherical(rho, phi, z float64) (r, theta, phi2 float64) { r = float64(math.Hypot(float64(rho), float64(z))) phi2 = phi theta = float64(math.Atan2(float64(rho), float64(z))) return }
[ "func", "CylindircalToSpherical", "(", "rho", ",", "phi", ",", "z", "float64", ")", "(", "r", ",", "theta", ",", "phi2", "float64", ")", "{", "r", "=", "float64", "(", "math", ".", "Hypot", "(", "float64", "(", "rho", ")", ",", "float64", "(", "z", ")", ")", ")", "\n", "phi2", "=", "phi", "\n", "theta", "=", "float64", "(", "math", ".", "Atan2", "(", "float64", "(", "rho", ")", ",", "float64", "(", "z", ")", ")", ")", "\n\n", "return", "\n", "}" ]
// CylindircalToSpherical converts cylindrical coordinates with radial distance // r, azimuth phi, and height z to spherical coordinates with radius r, // inclination theta, and azimuth phi. // // Angles are in radians
[ "CylindircalToSpherical", "converts", "cylindrical", "coordinates", "with", "radial", "distance", "r", "azimuth", "phi", "and", "height", "z", "to", "spherical", "coordinates", "with", "radius", "r", "inclination", "theta", "and", "azimuth", "phi", ".", "Angles", "are", "in", "radians" ]
c4601bc793c7a480dab005cf969aab0d7a7fb07d
https://github.com/go-gl/mathgl/blob/c4601bc793c7a480dab005cf969aab0d7a7fb07d/mgl64/conv.go#L70-L76
20,825
go-gl/mathgl
mgl32/transform.go
ExtractMaxScale
func ExtractMaxScale(m Mat4) float32 { scaleX := float64(m[0]*m[0] + m[1]*m[1] + m[2]*m[2]) scaleY := float64(m[4]*m[4] + m[5]*m[5] + m[6]*m[6]) scaleZ := float64(m[8]*m[8] + m[9]*m[9] + m[10]*m[10]) return float32(math.Sqrt(math.Max(scaleX, math.Max(scaleY, scaleZ)))) }
go
func ExtractMaxScale(m Mat4) float32 { scaleX := float64(m[0]*m[0] + m[1]*m[1] + m[2]*m[2]) scaleY := float64(m[4]*m[4] + m[5]*m[5] + m[6]*m[6]) scaleZ := float64(m[8]*m[8] + m[9]*m[9] + m[10]*m[10]) return float32(math.Sqrt(math.Max(scaleX, math.Max(scaleY, scaleZ)))) }
[ "func", "ExtractMaxScale", "(", "m", "Mat4", ")", "float32", "{", "scaleX", ":=", "float64", "(", "m", "[", "0", "]", "*", "m", "[", "0", "]", "+", "m", "[", "1", "]", "*", "m", "[", "1", "]", "+", "m", "[", "2", "]", "*", "m", "[", "2", "]", ")", "\n", "scaleY", ":=", "float64", "(", "m", "[", "4", "]", "*", "m", "[", "4", "]", "+", "m", "[", "5", "]", "*", "m", "[", "5", "]", "+", "m", "[", "6", "]", "*", "m", "[", "6", "]", ")", "\n", "scaleZ", ":=", "float64", "(", "m", "[", "8", "]", "*", "m", "[", "8", "]", "+", "m", "[", "9", "]", "*", "m", "[", "9", "]", "+", "m", "[", "10", "]", "*", "m", "[", "10", "]", ")", "\n\n", "return", "float32", "(", "math", ".", "Sqrt", "(", "math", ".", "Max", "(", "scaleX", ",", "math", ".", "Max", "(", "scaleY", ",", "scaleZ", ")", ")", ")", ")", "\n", "}" ]
// ExtractMaxScale extracts the maximum scaling from a homogeneous matrix
[ "ExtractMaxScale", "extracts", "the", "maximum", "scaling", "from", "a", "homogeneous", "matrix" ]
c4601bc793c7a480dab005cf969aab0d7a7fb07d
https://github.com/go-gl/mathgl/blob/c4601bc793c7a480dab005cf969aab0d7a7fb07d/mgl32/transform.go#L175-L181
20,826
go-gl/mathgl
mgl64/project.go
LookAt
func LookAt(eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ float64) Mat4 { return LookAtV(Vec3{eyeX, eyeY, eyeZ}, Vec3{centerX, centerY, centerZ}, Vec3{upX, upY, upZ}) }
go
func LookAt(eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ float64) Mat4 { return LookAtV(Vec3{eyeX, eyeY, eyeZ}, Vec3{centerX, centerY, centerZ}, Vec3{upX, upY, upZ}) }
[ "func", "LookAt", "(", "eyeX", ",", "eyeY", ",", "eyeZ", ",", "centerX", ",", "centerY", ",", "centerZ", ",", "upX", ",", "upY", ",", "upZ", "float64", ")", "Mat4", "{", "return", "LookAtV", "(", "Vec3", "{", "eyeX", ",", "eyeY", ",", "eyeZ", "}", ",", "Vec3", "{", "centerX", ",", "centerY", ",", "centerZ", "}", ",", "Vec3", "{", "upX", ",", "upY", ",", "upZ", "}", ")", "\n", "}" ]
// LookAt generates a transform matrix from world space to the given eye space.
[ "LookAt", "generates", "a", "transform", "matrix", "from", "world", "space", "to", "the", "given", "eye", "space", "." ]
c4601bc793c7a480dab005cf969aab0d7a7fb07d
https://github.com/go-gl/mathgl/blob/c4601bc793c7a480dab005cf969aab0d7a7fb07d/mgl64/project.go#L44-L46
20,827
go-gl/mathgl
mgl32/mempool.go
returnToPool
func returnToPool(slice []float32) { if cap(slice) == 0 { return } pool, exact := binLog(cap(slice)) if !exact { panic("attempt to pool slice with non-exact cap. If you're a user, please file an issue with github.com/go-gl/mathgl about this bug. This should never happen.") } getPool(pool).Put(slice) }
go
func returnToPool(slice []float32) { if cap(slice) == 0 { return } pool, exact := binLog(cap(slice)) if !exact { panic("attempt to pool slice with non-exact cap. If you're a user, please file an issue with github.com/go-gl/mathgl about this bug. This should never happen.") } getPool(pool).Put(slice) }
[ "func", "returnToPool", "(", "slice", "[", "]", "float32", ")", "{", "if", "cap", "(", "slice", ")", "==", "0", "{", "return", "\n", "}", "\n\n", "pool", ",", "exact", ":=", "binLog", "(", "cap", "(", "slice", ")", ")", "\n\n", "if", "!", "exact", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n\n", "getPool", "(", "pool", ")", ".", "Put", "(", "slice", ")", "\n", "}" ]
// Returns a slice to the appropriate pool. If the slice does not have a cap that's precisely // a power of 2, this will panic.
[ "Returns", "a", "slice", "to", "the", "appropriate", "pool", ".", "If", "the", "slice", "does", "not", "have", "a", "cap", "that", "s", "precisely", "a", "power", "of", "2", "this", "will", "panic", "." ]
c4601bc793c7a480dab005cf969aab0d7a7fb07d
https://github.com/go-gl/mathgl/blob/c4601bc793c7a480dab005cf969aab0d7a7fb07d/mgl32/mempool.go#L82-L94
20,828
go-gl/mathgl
mgl32/mempool.go
binLog
func binLog(val int) (int, bool) { if val <= 0 { return -1, false } exact := true l := 0 for ; val > 1; val = val >> 1 { // If the current lsb is 1 and the number // is not equal to 1, this is not an exact // log, but rather a rounding of it if val&1 != 0 { exact = false } l++ } return l, exact }
go
func binLog(val int) (int, bool) { if val <= 0 { return -1, false } exact := true l := 0 for ; val > 1; val = val >> 1 { // If the current lsb is 1 and the number // is not equal to 1, this is not an exact // log, but rather a rounding of it if val&1 != 0 { exact = false } l++ } return l, exact }
[ "func", "binLog", "(", "val", "int", ")", "(", "int", ",", "bool", ")", "{", "if", "val", "<=", "0", "{", "return", "-", "1", ",", "false", "\n", "}", "\n\n", "exact", ":=", "true", "\n", "l", ":=", "0", "\n", "for", ";", "val", ">", "1", ";", "val", "=", "val", ">>", "1", "{", "// If the current lsb is 1 and the number", "// is not equal to 1, this is not an exact", "// log, but rather a rounding of it", "if", "val", "&", "1", "!=", "0", "{", "exact", "=", "false", "\n", "}", "\n", "l", "++", "\n", "}", "\n\n", "return", "l", ",", "exact", "\n", "}" ]
// This returns the integer base 2 log of the value // and whether the log is exact or rounded down. // // This is only for positive integers. // // There are faster ways to do this, I'm open to suggestions. Most rely on knowing system endianness // which Go makes hard to do. I'm hesistant to use float conversions and the math package because of off-by-one errors.
[ "This", "returns", "the", "integer", "base", "2", "log", "of", "the", "value", "and", "whether", "the", "log", "is", "exact", "or", "rounded", "down", ".", "This", "is", "only", "for", "positive", "integers", ".", "There", "are", "faster", "ways", "to", "do", "this", "I", "m", "open", "to", "suggestions", ".", "Most", "rely", "on", "knowing", "system", "endianness", "which", "Go", "makes", "hard", "to", "do", ".", "I", "m", "hesistant", "to", "use", "float", "conversions", "and", "the", "math", "package", "because", "of", "off", "-", "by", "-", "one", "errors", "." ]
c4601bc793c7a480dab005cf969aab0d7a7fb07d
https://github.com/go-gl/mathgl/blob/c4601bc793c7a480dab005cf969aab0d7a7fb07d/mgl32/mempool.go#L103-L121
20,829
go-gl/mathgl
mgl64/shapes.go
QuadraticBezierCurve2D
func QuadraticBezierCurve2D(t float64, cPoint1, cPoint2, cPoint3 Vec2) Vec2 { if t < 0.0 || t > 1.0 { panic("Can't interpolate on bezier curve with t out of range [0.0,1.0]") } return cPoint1.Mul((1.0 - t) * (1.0 - t)).Add(cPoint2.Mul(2 * (1 - t) * t)).Add(cPoint3.Mul(t * t)) }
go
func QuadraticBezierCurve2D(t float64, cPoint1, cPoint2, cPoint3 Vec2) Vec2 { if t < 0.0 || t > 1.0 { panic("Can't interpolate on bezier curve with t out of range [0.0,1.0]") } return cPoint1.Mul((1.0 - t) * (1.0 - t)).Add(cPoint2.Mul(2 * (1 - t) * t)).Add(cPoint3.Mul(t * t)) }
[ "func", "QuadraticBezierCurve2D", "(", "t", "float64", ",", "cPoint1", ",", "cPoint2", ",", "cPoint3", "Vec2", ")", "Vec2", "{", "if", "t", "<", "0.0", "||", "t", ">", "1.0", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n\n", "return", "cPoint1", ".", "Mul", "(", "(", "1.0", "-", "t", ")", "*", "(", "1.0", "-", "t", ")", ")", ".", "Add", "(", "cPoint2", ".", "Mul", "(", "2", "*", "(", "1", "-", "t", ")", "*", "t", ")", ")", ".", "Add", "(", "cPoint3", ".", "Mul", "(", "t", "*", "t", ")", ")", "\n", "}" ]
// QuadraticBezierCurve2D interpolates the point t on the given bezier curve.
[ "QuadraticBezierCurve2D", "interpolates", "the", "point", "t", "on", "the", "given", "bezier", "curve", "." ]
c4601bc793c7a480dab005cf969aab0d7a7fb07d
https://github.com/go-gl/mathgl/blob/c4601bc793c7a480dab005cf969aab0d7a7fb07d/mgl64/shapes.go#L68-L74
20,830
go-gl/mathgl
mgl64/shapes.go
QuadraticBezierCurve3D
func QuadraticBezierCurve3D(t float64, cPoint1, cPoint2, cPoint3 Vec3) Vec3 { if t < 0.0 || t > 1.0 { panic("Can't interpolate on bezier curve with t out of range [0.0,1.0]") } return cPoint1.Mul((1.0 - t) * (1.0 - t)).Add(cPoint2.Mul(2 * (1 - t) * t)).Add(cPoint3.Mul(t * t)) }
go
func QuadraticBezierCurve3D(t float64, cPoint1, cPoint2, cPoint3 Vec3) Vec3 { if t < 0.0 || t > 1.0 { panic("Can't interpolate on bezier curve with t out of range [0.0,1.0]") } return cPoint1.Mul((1.0 - t) * (1.0 - t)).Add(cPoint2.Mul(2 * (1 - t) * t)).Add(cPoint3.Mul(t * t)) }
[ "func", "QuadraticBezierCurve3D", "(", "t", "float64", ",", "cPoint1", ",", "cPoint2", ",", "cPoint3", "Vec3", ")", "Vec3", "{", "if", "t", "<", "0.0", "||", "t", ">", "1.0", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n\n", "return", "cPoint1", ".", "Mul", "(", "(", "1.0", "-", "t", ")", "*", "(", "1.0", "-", "t", ")", ")", ".", "Add", "(", "cPoint2", ".", "Mul", "(", "2", "*", "(", "1", "-", "t", ")", "*", "t", ")", ")", ".", "Add", "(", "cPoint3", ".", "Mul", "(", "t", "*", "t", ")", ")", "\n", "}" ]
// QuadraticBezierCurve3D interpolates the point t on the given bezier curve.
[ "QuadraticBezierCurve3D", "interpolates", "the", "point", "t", "on", "the", "given", "bezier", "curve", "." ]
c4601bc793c7a480dab005cf969aab0d7a7fb07d
https://github.com/go-gl/mathgl/blob/c4601bc793c7a480dab005cf969aab0d7a7fb07d/mgl64/shapes.go#L77-L83
20,831
go-gl/mathgl
mgl64/shapes.go
BezierCurve3D
func BezierCurve3D(t float64, cPoints []Vec3) Vec3 { if t < 0.0 || t > 1.0 { panic("Input to bezier has t not in range [0,1]. If you think this is a precision error, use mathgl.Clamp[f|d] before calling this function") } n := len(cPoints) - 1 point := cPoints[0].Mul(float64(math.Pow(float64(1.0-t), float64(n)))) for i := 1; i <= n; i++ { point = point.Add(cPoints[i].Mul(float64(float64(choose(n, i)) * math.Pow(float64(1-t), float64(n-i)) * math.Pow(float64(t), float64(i))))) // P += P_i * nCi * (1-t)^(n-i) * t^i } return point }
go
func BezierCurve3D(t float64, cPoints []Vec3) Vec3 { if t < 0.0 || t > 1.0 { panic("Input to bezier has t not in range [0,1]. If you think this is a precision error, use mathgl.Clamp[f|d] before calling this function") } n := len(cPoints) - 1 point := cPoints[0].Mul(float64(math.Pow(float64(1.0-t), float64(n)))) for i := 1; i <= n; i++ { point = point.Add(cPoints[i].Mul(float64(float64(choose(n, i)) * math.Pow(float64(1-t), float64(n-i)) * math.Pow(float64(t), float64(i))))) // P += P_i * nCi * (1-t)^(n-i) * t^i } return point }
[ "func", "BezierCurve3D", "(", "t", "float64", ",", "cPoints", "[", "]", "Vec3", ")", "Vec3", "{", "if", "t", "<", "0.0", "||", "t", ">", "1.0", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n\n", "n", ":=", "len", "(", "cPoints", ")", "-", "1", "\n", "point", ":=", "cPoints", "[", "0", "]", ".", "Mul", "(", "float64", "(", "math", ".", "Pow", "(", "float64", "(", "1.0", "-", "t", ")", ",", "float64", "(", "n", ")", ")", ")", ")", "\n\n", "for", "i", ":=", "1", ";", "i", "<=", "n", ";", "i", "++", "{", "point", "=", "point", ".", "Add", "(", "cPoints", "[", "i", "]", ".", "Mul", "(", "float64", "(", "float64", "(", "choose", "(", "n", ",", "i", ")", ")", "*", "math", ".", "Pow", "(", "float64", "(", "1", "-", "t", ")", ",", "float64", "(", "n", "-", "i", ")", ")", "*", "math", ".", "Pow", "(", "float64", "(", "t", ")", ",", "float64", "(", "i", ")", ")", ")", ")", ")", "// P += P_i * nCi * (1-t)^(n-i) * t^i", "\n", "}", "\n\n", "return", "point", "\n", "}" ]
// BezierCurve3D same as the 2D version, except the line is in 3D space
[ "BezierCurve3D", "same", "as", "the", "2D", "version", "except", "the", "line", "is", "in", "3D", "space" ]
c4601bc793c7a480dab005cf969aab0d7a7fb07d
https://github.com/go-gl/mathgl/blob/c4601bc793c7a480dab005cf969aab0d7a7fb07d/mgl64/shapes.go#L126-L139
20,832
go-gl/mathgl
mgl64/shapes.go
MakeBezierCurve3D
func MakeBezierCurve3D(numPoints int, cPoints []Vec3) (line []Vec3) { line = make([]Vec3, numPoints) if numPoints == 0 { return } else if numPoints == 1 { line[0] = cPoints[0] return } else if numPoints == 2 { line[0] = cPoints[0] line[1] = cPoints[len(cPoints)-1] return } line[0] = cPoints[0] for i := 1; i < numPoints-1; i++ { line[i] = BezierCurve3D(Clamp(float64(i)/float64(numPoints-1), 0.0, 1.0), cPoints) } line[numPoints-1] = cPoints[len(cPoints)-1] return }
go
func MakeBezierCurve3D(numPoints int, cPoints []Vec3) (line []Vec3) { line = make([]Vec3, numPoints) if numPoints == 0 { return } else if numPoints == 1 { line[0] = cPoints[0] return } else if numPoints == 2 { line[0] = cPoints[0] line[1] = cPoints[len(cPoints)-1] return } line[0] = cPoints[0] for i := 1; i < numPoints-1; i++ { line[i] = BezierCurve3D(Clamp(float64(i)/float64(numPoints-1), 0.0, 1.0), cPoints) } line[numPoints-1] = cPoints[len(cPoints)-1] return }
[ "func", "MakeBezierCurve3D", "(", "numPoints", "int", ",", "cPoints", "[", "]", "Vec3", ")", "(", "line", "[", "]", "Vec3", ")", "{", "line", "=", "make", "(", "[", "]", "Vec3", ",", "numPoints", ")", "\n", "if", "numPoints", "==", "0", "{", "return", "\n", "}", "else", "if", "numPoints", "==", "1", "{", "line", "[", "0", "]", "=", "cPoints", "[", "0", "]", "\n", "return", "\n", "}", "else", "if", "numPoints", "==", "2", "{", "line", "[", "0", "]", "=", "cPoints", "[", "0", "]", "\n", "line", "[", "1", "]", "=", "cPoints", "[", "len", "(", "cPoints", ")", "-", "1", "]", "\n", "return", "\n", "}", "\n\n", "line", "[", "0", "]", "=", "cPoints", "[", "0", "]", "\n", "for", "i", ":=", "1", ";", "i", "<", "numPoints", "-", "1", ";", "i", "++", "{", "line", "[", "i", "]", "=", "BezierCurve3D", "(", "Clamp", "(", "float64", "(", "i", ")", "/", "float64", "(", "numPoints", "-", "1", ")", ",", "0.0", ",", "1.0", ")", ",", "cPoints", ")", "\n", "}", "\n", "line", "[", "numPoints", "-", "1", "]", "=", "cPoints", "[", "len", "(", "cPoints", ")", "-", "1", "]", "\n\n", "return", "\n", "}" ]
// MakeBezierCurve3D same as the 2D version, except with the line in 3D space.
[ "MakeBezierCurve3D", "same", "as", "the", "2D", "version", "except", "with", "the", "line", "in", "3D", "space", "." ]
c4601bc793c7a480dab005cf969aab0d7a7fb07d
https://github.com/go-gl/mathgl/blob/c4601bc793c7a480dab005cf969aab0d7a7fb07d/mgl64/shapes.go#L174-L194
20,833
go-gl/mathgl
mgl64/shapes.go
BezierSplineInterpolate2D
func BezierSplineInterpolate2D(t float64, ranges [][2]float64, cPoints [][]Vec2) Vec2 { if len(ranges) != len(cPoints) { panic("Each bezier curve needs a range") } for i, curveRange := range ranges { if t >= curveRange[0] && t <= curveRange[1] { return BezierCurve2D((t-curveRange[0])/(curveRange[1]-curveRange[0]), cPoints[i]) } } panic("t is out of the range of all bezier curves in this spline") }
go
func BezierSplineInterpolate2D(t float64, ranges [][2]float64, cPoints [][]Vec2) Vec2 { if len(ranges) != len(cPoints) { panic("Each bezier curve needs a range") } for i, curveRange := range ranges { if t >= curveRange[0] && t <= curveRange[1] { return BezierCurve2D((t-curveRange[0])/(curveRange[1]-curveRange[0]), cPoints[i]) } } panic("t is out of the range of all bezier curves in this spline") }
[ "func", "BezierSplineInterpolate2D", "(", "t", "float64", ",", "ranges", "[", "]", "[", "2", "]", "float64", ",", "cPoints", "[", "]", "[", "]", "Vec2", ")", "Vec2", "{", "if", "len", "(", "ranges", ")", "!=", "len", "(", "cPoints", ")", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n\n", "for", "i", ",", "curveRange", ":=", "range", "ranges", "{", "if", "t", ">=", "curveRange", "[", "0", "]", "&&", "t", "<=", "curveRange", "[", "1", "]", "{", "return", "BezierCurve2D", "(", "(", "t", "-", "curveRange", "[", "0", "]", ")", "/", "(", "curveRange", "[", "1", "]", "-", "curveRange", "[", "0", "]", ")", ",", "cPoints", "[", "i", "]", ")", "\n", "}", "\n", "}", "\n\n", "panic", "(", "\"", "\"", ")", "\n", "}" ]
// BezierSplineInterpolate2D does interpolation over a spline of several bezier // curves. Each bezier curve must have a finite range, though the spline may be // disjoint. The bezier curves are not required to be in any particular order. // // If t is out of the range of all given curves, this function will panic
[ "BezierSplineInterpolate2D", "does", "interpolation", "over", "a", "spline", "of", "several", "bezier", "curves", ".", "Each", "bezier", "curve", "must", "have", "a", "finite", "range", "though", "the", "spline", "may", "be", "disjoint", ".", "The", "bezier", "curves", "are", "not", "required", "to", "be", "in", "any", "particular", "order", ".", "If", "t", "is", "out", "of", "the", "range", "of", "all", "given", "curves", "this", "function", "will", "panic" ]
c4601bc793c7a480dab005cf969aab0d7a7fb07d
https://github.com/go-gl/mathgl/blob/c4601bc793c7a480dab005cf969aab0d7a7fb07d/mgl64/shapes.go#L230-L242
20,834
go-gl/mathgl
mgl32/matstack/matstack.go
Pop
func (ms *MatStack) Pop() error { if len(*ms) == 1 { return errors.New("Cannot pop from mat stack, at minimum stack length of 1") } (*ms) = (*ms)[:len(*ms)-1] return nil }
go
func (ms *MatStack) Pop() error { if len(*ms) == 1 { return errors.New("Cannot pop from mat stack, at minimum stack length of 1") } (*ms) = (*ms)[:len(*ms)-1] return nil }
[ "func", "(", "ms", "*", "MatStack", ")", "Pop", "(", ")", "error", "{", "if", "len", "(", "*", "ms", ")", "==", "1", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "(", "*", "ms", ")", "=", "(", "*", "ms", ")", "[", ":", "len", "(", "*", "ms", ")", "-", "1", "]", "\n\n", "return", "nil", "\n", "}" ]
// Pop removes the first element of the matrix from the stack, if there is only // one element left there is an error.
[ "Pop", "removes", "the", "first", "element", "of", "the", "matrix", "from", "the", "stack", "if", "there", "is", "only", "one", "element", "left", "there", "is", "an", "error", "." ]
c4601bc793c7a480dab005cf969aab0d7a7fb07d
https://github.com/go-gl/mathgl/blob/c4601bc793c7a480dab005cf969aab0d7a7fb07d/mgl32/matstack/matstack.go#L25-L32
20,835
go-gl/mathgl
mgl32/vector.go
ApproxEqual
func (v1 Vec3) ApproxEqual(v2 Vec3) bool { for i := range v1 { if !FloatEqual(v1[i], v2[i]) { return false } } return true }
go
func (v1 Vec3) ApproxEqual(v2 Vec3) bool { for i := range v1 { if !FloatEqual(v1[i], v2[i]) { return false } } return true }
[ "func", "(", "v1", "Vec3", ")", "ApproxEqual", "(", "v2", "Vec3", ")", "bool", "{", "for", "i", ":=", "range", "v1", "{", "if", "!", "FloatEqual", "(", "v1", "[", "i", "]", ",", "v2", "[", "i", "]", ")", "{", "return", "false", "\n", "}", "\n", "}", "\n", "return", "true", "\n", "}" ]
// ApproxEqual takes in a vector and does an element-wise approximate float // comparison as if FloatEqual had been used
[ "ApproxEqual", "takes", "in", "a", "vector", "and", "does", "an", "element", "-", "wise", "approximate", "float", "comparison", "as", "if", "FloatEqual", "had", "been", "used" ]
c4601bc793c7a480dab005cf969aab0d7a7fb07d
https://github.com/go-gl/mathgl/blob/c4601bc793c7a480dab005cf969aab0d7a7fb07d/mgl32/vector.go#L314-L321
20,836
go-gl/mathgl
mgl32/vector.go
ApproxEqualThreshold
func (v1 Vec3) ApproxEqualThreshold(v2 Vec3, threshold float32) bool { for i := range v1 { if !FloatEqualThreshold(v1[i], v2[i], threshold) { return false } } return true }
go
func (v1 Vec3) ApproxEqualThreshold(v2 Vec3, threshold float32) bool { for i := range v1 { if !FloatEqualThreshold(v1[i], v2[i], threshold) { return false } } return true }
[ "func", "(", "v1", "Vec3", ")", "ApproxEqualThreshold", "(", "v2", "Vec3", ",", "threshold", "float32", ")", "bool", "{", "for", "i", ":=", "range", "v1", "{", "if", "!", "FloatEqualThreshold", "(", "v1", "[", "i", "]", ",", "v2", "[", "i", "]", ",", "threshold", ")", "{", "return", "false", "\n", "}", "\n", "}", "\n", "return", "true", "\n", "}" ]
// ApproxEqualThreshold takes in a threshold for comparing two floats, and uses // it to do an element-wise comparison of the vector to another.
[ "ApproxEqualThreshold", "takes", "in", "a", "threshold", "for", "comparing", "two", "floats", "and", "uses", "it", "to", "do", "an", "element", "-", "wise", "comparison", "of", "the", "vector", "to", "another", "." ]
c4601bc793c7a480dab005cf969aab0d7a7fb07d
https://github.com/go-gl/mathgl/blob/c4601bc793c7a480dab005cf969aab0d7a7fb07d/mgl32/vector.go#L325-L332
20,837
go-gl/mathgl
mgl32/vector.go
ApproxFuncEqual
func (v1 Vec3) ApproxFuncEqual(v2 Vec3, eq func(float32, float32) bool) bool { for i := range v1 { if !eq(v1[i], v2[i]) { return false } } return true }
go
func (v1 Vec3) ApproxFuncEqual(v2 Vec3, eq func(float32, float32) bool) bool { for i := range v1 { if !eq(v1[i], v2[i]) { return false } } return true }
[ "func", "(", "v1", "Vec3", ")", "ApproxFuncEqual", "(", "v2", "Vec3", ",", "eq", "func", "(", "float32", ",", "float32", ")", "bool", ")", "bool", "{", "for", "i", ":=", "range", "v1", "{", "if", "!", "eq", "(", "v1", "[", "i", "]", ",", "v2", "[", "i", "]", ")", "{", "return", "false", "\n", "}", "\n", "}", "\n", "return", "true", "\n", "}" ]
// ApproxFuncEqual takes in a func that compares two floats, and uses it to do an element-wise // comparison of the vector to another. This is intended to be used with FloatEqualFunc
[ "ApproxFuncEqual", "takes", "in", "a", "func", "that", "compares", "two", "floats", "and", "uses", "it", "to", "do", "an", "element", "-", "wise", "comparison", "of", "the", "vector", "to", "another", ".", "This", "is", "intended", "to", "be", "used", "with", "FloatEqualFunc" ]
c4601bc793c7a480dab005cf969aab0d7a7fb07d
https://github.com/go-gl/mathgl/blob/c4601bc793c7a480dab005cf969aab0d7a7fb07d/mgl32/vector.go#L336-L343
20,838
go-gl/mathgl
mgl64/matstack/transformStack.go
Push
func (ms *TransformStack) Push(m mgl64.Mat4) { prev := (*ms)[len(*ms)-1] (*ms) = append(*ms, prev.Mul4(m)) }
go
func (ms *TransformStack) Push(m mgl64.Mat4) { prev := (*ms)[len(*ms)-1] (*ms) = append(*ms, prev.Mul4(m)) }
[ "func", "(", "ms", "*", "TransformStack", ")", "Push", "(", "m", "mgl64", ".", "Mat4", ")", "{", "prev", ":=", "(", "*", "ms", ")", "[", "len", "(", "*", "ms", ")", "-", "1", "]", "\n", "(", "*", "ms", ")", "=", "append", "(", "*", "ms", ",", "prev", ".", "Mul4", "(", "m", ")", ")", "\n", "}" ]
// Push multiplies the current top matrix by m, and pushes the result on the // stack.
[ "Push", "multiplies", "the", "current", "top", "matrix", "by", "m", "and", "pushes", "the", "result", "on", "the", "stack", "." ]
c4601bc793c7a480dab005cf969aab0d7a7fb07d
https://github.com/go-gl/mathgl/blob/c4601bc793c7a480dab005cf969aab0d7a7fb07d/mgl64/matstack/transformStack.go#L34-L37
20,839
go-gl/mathgl
mgl64/matstack/transformStack.go
Pop
func (ms *TransformStack) Pop() (mgl64.Mat4, error) { if len(*ms) == 1 { return mgl64.Mat4{}, errors.New("attempt to pop last element of the stack; Matrix Stack must have at least one element") } retVal := (*ms)[len(*ms)-1] (*ms) = (*ms)[:len(*ms)-1] return retVal, nil }
go
func (ms *TransformStack) Pop() (mgl64.Mat4, error) { if len(*ms) == 1 { return mgl64.Mat4{}, errors.New("attempt to pop last element of the stack; Matrix Stack must have at least one element") } retVal := (*ms)[len(*ms)-1] (*ms) = (*ms)[:len(*ms)-1] return retVal, nil }
[ "func", "(", "ms", "*", "TransformStack", ")", "Pop", "(", ")", "(", "mgl64", ".", "Mat4", ",", "error", ")", "{", "if", "len", "(", "*", "ms", ")", "==", "1", "{", "return", "mgl64", ".", "Mat4", "{", "}", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "retVal", ":=", "(", "*", "ms", ")", "[", "len", "(", "*", "ms", ")", "-", "1", "]", "\n\n", "(", "*", "ms", ")", "=", "(", "*", "ms", ")", "[", ":", "len", "(", "*", "ms", ")", "-", "1", "]", "\n\n", "return", "retVal", ",", "nil", "\n", "}" ]
// Pop the current matrix off the top of the stack and returns it. If the matrix // stack only has one element left, this will return an error.
[ "Pop", "the", "current", "matrix", "off", "the", "top", "of", "the", "stack", "and", "returns", "it", ".", "If", "the", "matrix", "stack", "only", "has", "one", "element", "left", "this", "will", "return", "an", "error", "." ]
c4601bc793c7a480dab005cf969aab0d7a7fb07d
https://github.com/go-gl/mathgl/blob/c4601bc793c7a480dab005cf969aab0d7a7fb07d/mgl64/matstack/transformStack.go#L41-L51
20,840
go-gl/mathgl
mgl64/matstack/transformStack.go
Unwind
func (ms *TransformStack) Unwind(n int) error { if n > len(*ms)-1 { return errors.New("Cannot unwind a matrix to below 1 value") } (*ms) = (*ms)[:len(*ms)-n] return nil }
go
func (ms *TransformStack) Unwind(n int) error { if n > len(*ms)-1 { return errors.New("Cannot unwind a matrix to below 1 value") } (*ms) = (*ms)[:len(*ms)-n] return nil }
[ "func", "(", "ms", "*", "TransformStack", ")", "Unwind", "(", "n", "int", ")", "error", "{", "if", "n", ">", "len", "(", "*", "ms", ")", "-", "1", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "(", "*", "ms", ")", "=", "(", "*", "ms", ")", "[", ":", "len", "(", "*", "ms", ")", "-", "n", "]", "\n", "return", "nil", "\n", "}" ]
// Unwind cuts down the matrix as if Pop had been called n times. If n would // bring the matrix down below 1 element, this does nothing and returns an // error.
[ "Unwind", "cuts", "down", "the", "matrix", "as", "if", "Pop", "had", "been", "called", "n", "times", ".", "If", "n", "would", "bring", "the", "matrix", "down", "below", "1", "element", "this", "does", "nothing", "and", "returns", "an", "error", "." ]
c4601bc793c7a480dab005cf969aab0d7a7fb07d
https://github.com/go-gl/mathgl/blob/c4601bc793c7a480dab005cf969aab0d7a7fb07d/mgl64/matstack/transformStack.go#L68-L75
20,841
go-gl/mathgl
mgl64/matstack/transformStack.go
Rebase
func Rebase(ms *TransformStack, from int, m *TransformStack) (*TransformStack, error) { if from <= 0 || from >= len(*ms) { return nil, errors.New("Cannot rebase, index out of range") } // Shift tmp so that the element immediately // preceding our target is the "top" element of the list. tmp := ms.Copy() if from == 1 { (*tmp) = append(*tmp, mgl64.Mat4{}) } copy((*tmp)[1:], (*tmp)[from-1:]) if from-2 > 0 { (*tmp) = (*tmp)[:len(*tmp)-(from-2)] } err := tmp.Reseed(1, m.Peek()) if err != nil { return nil, err } (*tmp) = append(*m, (*tmp)[2:]...) return tmp, nil }
go
func Rebase(ms *TransformStack, from int, m *TransformStack) (*TransformStack, error) { if from <= 0 || from >= len(*ms) { return nil, errors.New("Cannot rebase, index out of range") } // Shift tmp so that the element immediately // preceding our target is the "top" element of the list. tmp := ms.Copy() if from == 1 { (*tmp) = append(*tmp, mgl64.Mat4{}) } copy((*tmp)[1:], (*tmp)[from-1:]) if from-2 > 0 { (*tmp) = (*tmp)[:len(*tmp)-(from-2)] } err := tmp.Reseed(1, m.Peek()) if err != nil { return nil, err } (*tmp) = append(*m, (*tmp)[2:]...) return tmp, nil }
[ "func", "Rebase", "(", "ms", "*", "TransformStack", ",", "from", "int", ",", "m", "*", "TransformStack", ")", "(", "*", "TransformStack", ",", "error", ")", "{", "if", "from", "<=", "0", "||", "from", ">=", "len", "(", "*", "ms", ")", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "// Shift tmp so that the element immediately", "// preceding our target is the \"top\" element of the list.", "tmp", ":=", "ms", ".", "Copy", "(", ")", "\n", "if", "from", "==", "1", "{", "(", "*", "tmp", ")", "=", "append", "(", "*", "tmp", ",", "mgl64", ".", "Mat4", "{", "}", ")", "\n", "}", "\n", "copy", "(", "(", "*", "tmp", ")", "[", "1", ":", "]", ",", "(", "*", "tmp", ")", "[", "from", "-", "1", ":", "]", ")", "\n", "if", "from", "-", "2", ">", "0", "{", "(", "*", "tmp", ")", "=", "(", "*", "tmp", ")", "[", ":", "len", "(", "*", "tmp", ")", "-", "(", "from", "-", "2", ")", "]", "\n", "}", "\n\n", "err", ":=", "tmp", ".", "Reseed", "(", "1", ",", "m", ".", "Peek", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "(", "*", "tmp", ")", "=", "append", "(", "*", "m", ",", "(", "*", "tmp", ")", "[", "2", ":", "]", "...", ")", "\n\n", "return", "tmp", ",", "nil", "\n", "}" ]
// Rebase replays the current matrix stack as if the transformation that occurred at index "from" // in ms had instead started at the top of m. // // This returns a brand new stack containing all of m followed by all transformations // at from and after on ms as if they has been done on m instead.
[ "Rebase", "replays", "the", "current", "matrix", "stack", "as", "if", "the", "transformation", "that", "occurred", "at", "index", "from", "in", "ms", "had", "instead", "started", "at", "the", "top", "of", "m", ".", "This", "returns", "a", "brand", "new", "stack", "containing", "all", "of", "m", "followed", "by", "all", "transformations", "at", "from", "and", "after", "on", "ms", "as", "if", "they", "has", "been", "done", "on", "m", "instead", "." ]
c4601bc793c7a480dab005cf969aab0d7a7fb07d
https://github.com/go-gl/mathgl/blob/c4601bc793c7a480dab005cf969aab0d7a7fb07d/mgl64/matstack/transformStack.go#L144-L168
20,842
go-gl/mathgl
mgl32/project.go
Frustum
func Frustum(left, right, bottom, top, near, far float32) Mat4 { rml, tmb, fmn := (right - left), (top - bottom), (far - near) A, B, C, D := (right+left)/rml, (top+bottom)/tmb, -(far+near)/fmn, -(2*far*near)/fmn return Mat4{float32((2. * near) / rml), 0, 0, 0, 0, float32((2. * near) / tmb), 0, 0, float32(A), float32(B), float32(C), -1, 0, 0, float32(D), 0} }
go
func Frustum(left, right, bottom, top, near, far float32) Mat4 { rml, tmb, fmn := (right - left), (top - bottom), (far - near) A, B, C, D := (right+left)/rml, (top+bottom)/tmb, -(far+near)/fmn, -(2*far*near)/fmn return Mat4{float32((2. * near) / rml), 0, 0, 0, 0, float32((2. * near) / tmb), 0, 0, float32(A), float32(B), float32(C), -1, 0, 0, float32(D), 0} }
[ "func", "Frustum", "(", "left", ",", "right", ",", "bottom", ",", "top", ",", "near", ",", "far", "float32", ")", "Mat4", "{", "rml", ",", "tmb", ",", "fmn", ":=", "(", "right", "-", "left", ")", ",", "(", "top", "-", "bottom", ")", ",", "(", "far", "-", "near", ")", "\n", "A", ",", "B", ",", "C", ",", "D", ":=", "(", "right", "+", "left", ")", "/", "rml", ",", "(", "top", "+", "bottom", ")", "/", "tmb", ",", "-", "(", "far", "+", "near", ")", "/", "fmn", ",", "-", "(", "2", "*", "far", "*", "near", ")", "/", "fmn", "\n\n", "return", "Mat4", "{", "float32", "(", "(", "2.", "*", "near", ")", "/", "rml", ")", ",", "0", ",", "0", ",", "0", ",", "0", ",", "float32", "(", "(", "2.", "*", "near", ")", "/", "tmb", ")", ",", "0", ",", "0", ",", "float32", "(", "A", ")", ",", "float32", "(", "B", ")", ",", "float32", "(", "C", ")", ",", "-", "1", ",", "0", ",", "0", ",", "float32", "(", "D", ")", ",", "0", "}", "\n", "}" ]
// Frustum generates a Frustum Matrix.
[ "Frustum", "generates", "a", "Frustum", "Matrix", "." ]
c4601bc793c7a480dab005cf969aab0d7a7fb07d
https://github.com/go-gl/mathgl/blob/c4601bc793c7a480dab005cf969aab0d7a7fb07d/mgl32/project.go#L34-L39
20,843
go-gl/mathgl
mgl32/project.go
LookAtV
func LookAtV(eye, center, up Vec3) Mat4 { f := center.Sub(eye).Normalize() s := f.Cross(up.Normalize()).Normalize() u := s.Cross(f) M := Mat4{ s[0], u[0], -f[0], 0, s[1], u[1], -f[1], 0, s[2], u[2], -f[2], 0, 0, 0, 0, 1, } return M.Mul4(Translate3D(float32(-eye[0]), float32(-eye[1]), float32(-eye[2]))) }
go
func LookAtV(eye, center, up Vec3) Mat4 { f := center.Sub(eye).Normalize() s := f.Cross(up.Normalize()).Normalize() u := s.Cross(f) M := Mat4{ s[0], u[0], -f[0], 0, s[1], u[1], -f[1], 0, s[2], u[2], -f[2], 0, 0, 0, 0, 1, } return M.Mul4(Translate3D(float32(-eye[0]), float32(-eye[1]), float32(-eye[2]))) }
[ "func", "LookAtV", "(", "eye", ",", "center", ",", "up", "Vec3", ")", "Mat4", "{", "f", ":=", "center", ".", "Sub", "(", "eye", ")", ".", "Normalize", "(", ")", "\n", "s", ":=", "f", ".", "Cross", "(", "up", ".", "Normalize", "(", ")", ")", ".", "Normalize", "(", ")", "\n", "u", ":=", "s", ".", "Cross", "(", "f", ")", "\n\n", "M", ":=", "Mat4", "{", "s", "[", "0", "]", ",", "u", "[", "0", "]", ",", "-", "f", "[", "0", "]", ",", "0", ",", "s", "[", "1", "]", ",", "u", "[", "1", "]", ",", "-", "f", "[", "1", "]", ",", "0", ",", "s", "[", "2", "]", ",", "u", "[", "2", "]", ",", "-", "f", "[", "2", "]", ",", "0", ",", "0", ",", "0", ",", "0", ",", "1", ",", "}", "\n\n", "return", "M", ".", "Mul4", "(", "Translate3D", "(", "float32", "(", "-", "eye", "[", "0", "]", ")", ",", "float32", "(", "-", "eye", "[", "1", "]", ")", ",", "float32", "(", "-", "eye", "[", "2", "]", ")", ")", ")", "\n", "}" ]
// LookAtV generates a transform matrix from world space into the specific eye // space.
[ "LookAtV", "generates", "a", "transform", "matrix", "from", "world", "space", "into", "the", "specific", "eye", "space", "." ]
c4601bc793c7a480dab005cf969aab0d7a7fb07d
https://github.com/go-gl/mathgl/blob/c4601bc793c7a480dab005cf969aab0d7a7fb07d/mgl32/project.go#L48-L61
20,844
go-gl/mathgl
mgl64/transform.go
Extract3DScale
func Extract3DScale(m Mat4) (x, y, z float64) { return float64(math.Sqrt(float64(m[0]*m[0] + m[1]*m[1] + m[2]*m[2]))), float64(math.Sqrt(float64(m[4]*m[4] + m[5]*m[5] + m[6]*m[6]))), float64(math.Sqrt(float64(m[8]*m[8] + m[9]*m[9] + m[10]*m[10]))) }
go
func Extract3DScale(m Mat4) (x, y, z float64) { return float64(math.Sqrt(float64(m[0]*m[0] + m[1]*m[1] + m[2]*m[2]))), float64(math.Sqrt(float64(m[4]*m[4] + m[5]*m[5] + m[6]*m[6]))), float64(math.Sqrt(float64(m[8]*m[8] + m[9]*m[9] + m[10]*m[10]))) }
[ "func", "Extract3DScale", "(", "m", "Mat4", ")", "(", "x", ",", "y", ",", "z", "float64", ")", "{", "return", "float64", "(", "math", ".", "Sqrt", "(", "float64", "(", "m", "[", "0", "]", "*", "m", "[", "0", "]", "+", "m", "[", "1", "]", "*", "m", "[", "1", "]", "+", "m", "[", "2", "]", "*", "m", "[", "2", "]", ")", ")", ")", ",", "float64", "(", "math", ".", "Sqrt", "(", "float64", "(", "m", "[", "4", "]", "*", "m", "[", "4", "]", "+", "m", "[", "5", "]", "*", "m", "[", "5", "]", "+", "m", "[", "6", "]", "*", "m", "[", "6", "]", ")", ")", ")", ",", "float64", "(", "math", ".", "Sqrt", "(", "float64", "(", "m", "[", "8", "]", "*", "m", "[", "8", "]", "+", "m", "[", "9", "]", "*", "m", "[", "9", "]", "+", "m", "[", "10", "]", "*", "m", "[", "10", "]", ")", ")", ")", "\n", "}" ]
// Extract3DScale extracts the 3d scaling from a homogeneous matrix
[ "Extract3DScale", "extracts", "the", "3d", "scaling", "from", "a", "homogeneous", "matrix" ]
c4601bc793c7a480dab005cf969aab0d7a7fb07d
https://github.com/go-gl/mathgl/blob/c4601bc793c7a480dab005cf969aab0d7a7fb07d/mgl64/transform.go#L170-L174
20,845
go-gl/mathgl
mgl32/quat.go
QuatRotate
func QuatRotate(angle float32, axis Vec3) Quat { // angle = (float32(math.Pi) * angle) / 180.0 c, s := float32(math.Cos(float64(angle/2))), float32(math.Sin(float64(angle/2))) return Quat{c, axis.Mul(s)} }
go
func QuatRotate(angle float32, axis Vec3) Quat { // angle = (float32(math.Pi) * angle) / 180.0 c, s := float32(math.Cos(float64(angle/2))), float32(math.Sin(float64(angle/2))) return Quat{c, axis.Mul(s)} }
[ "func", "QuatRotate", "(", "angle", "float32", ",", "axis", "Vec3", ")", "Quat", "{", "// angle = (float32(math.Pi) * angle) / 180.0", "c", ",", "s", ":=", "float32", "(", "math", ".", "Cos", "(", "float64", "(", "angle", "/", "2", ")", ")", ")", ",", "float32", "(", "math", ".", "Sin", "(", "float64", "(", "angle", "/", "2", ")", ")", ")", "\n\n", "return", "Quat", "{", "c", ",", "axis", ".", "Mul", "(", "s", ")", "}", "\n", "}" ]
// QuatRotate creates an angle from an axis and an angle relative to that axis. // // This is cheaper than HomogRotate3D.
[ "QuatRotate", "creates", "an", "angle", "from", "an", "axis", "and", "an", "angle", "relative", "to", "that", "axis", ".", "This", "is", "cheaper", "than", "HomogRotate3D", "." ]
c4601bc793c7a480dab005cf969aab0d7a7fb07d
https://github.com/go-gl/mathgl/blob/c4601bc793c7a480dab005cf969aab0d7a7fb07d/mgl32/quat.go#L56-L62
20,846
go-gl/mathgl
mgl32/quat.go
ApproxEqualThreshold
func (q1 Quat) ApproxEqualThreshold(q2 Quat, epsilon float32) bool { return FloatEqualThreshold(q1.W, q2.W, epsilon) && q1.V.ApproxEqualThreshold(q2.V, epsilon) }
go
func (q1 Quat) ApproxEqualThreshold(q2 Quat, epsilon float32) bool { return FloatEqualThreshold(q1.W, q2.W, epsilon) && q1.V.ApproxEqualThreshold(q2.V, epsilon) }
[ "func", "(", "q1", "Quat", ")", "ApproxEqualThreshold", "(", "q2", "Quat", ",", "epsilon", "float32", ")", "bool", "{", "return", "FloatEqualThreshold", "(", "q1", ".", "W", ",", "q2", ".", "W", ",", "epsilon", ")", "&&", "q1", ".", "V", ".", "ApproxEqualThreshold", "(", "q2", ".", "V", ",", "epsilon", ")", "\n", "}" ]
// ApproxEqualThreshold returns whether the quaternions are approximately equal with a given tolerence, as if // FloatEqualThreshold was called on each matching element with the given epsilon
[ "ApproxEqualThreshold", "returns", "whether", "the", "quaternions", "are", "approximately", "equal", "with", "a", "given", "tolerence", "as", "if", "FloatEqualThreshold", "was", "called", "on", "each", "matching", "element", "with", "the", "given", "epsilon" ]
c4601bc793c7a480dab005cf969aab0d7a7fb07d
https://github.com/go-gl/mathgl/blob/c4601bc793c7a480dab005cf969aab0d7a7fb07d/mgl32/quat.go#L189-L191
20,847
go-gl/mathgl
mgl32/quat.go
ApproxEqualFunc
func (q1 Quat) ApproxEqualFunc(q2 Quat, f func(float32, float32) bool) bool { return f(q1.W, q2.W) && q1.V.ApproxFuncEqual(q2.V, f) }
go
func (q1 Quat) ApproxEqualFunc(q2 Quat, f func(float32, float32) bool) bool { return f(q1.W, q2.W) && q1.V.ApproxFuncEqual(q2.V, f) }
[ "func", "(", "q1", "Quat", ")", "ApproxEqualFunc", "(", "q2", "Quat", ",", "f", "func", "(", "float32", ",", "float32", ")", "bool", ")", "bool", "{", "return", "f", "(", "q1", ".", "W", ",", "q2", ".", "W", ")", "&&", "q1", ".", "V", ".", "ApproxFuncEqual", "(", "q2", ".", "V", ",", "f", ")", "\n", "}" ]
// ApproxEqualFunc returns whether the quaternions are approximately equal using the given comparison function, as if // the function had been called on each individual element
[ "ApproxEqualFunc", "returns", "whether", "the", "quaternions", "are", "approximately", "equal", "using", "the", "given", "comparison", "function", "as", "if", "the", "function", "had", "been", "called", "on", "each", "individual", "element" ]
c4601bc793c7a480dab005cf969aab0d7a7fb07d
https://github.com/go-gl/mathgl/blob/c4601bc793c7a480dab005cf969aab0d7a7fb07d/mgl32/quat.go#L195-L197
20,848
go-gl/mathgl
mgl32/quat.go
OrientationEqualThreshold
func (q1 Quat) OrientationEqualThreshold(q2 Quat, epsilon float32) bool { return Abs(q1.Normalize().Dot(q2.Normalize())) > 1-epsilon }
go
func (q1 Quat) OrientationEqualThreshold(q2 Quat, epsilon float32) bool { return Abs(q1.Normalize().Dot(q2.Normalize())) > 1-epsilon }
[ "func", "(", "q1", "Quat", ")", "OrientationEqualThreshold", "(", "q2", "Quat", ",", "epsilon", "float32", ")", "bool", "{", "return", "Abs", "(", "q1", ".", "Normalize", "(", ")", ".", "Dot", "(", "q2", ".", "Normalize", "(", ")", ")", ")", ">", "1", "-", "epsilon", "\n", "}" ]
// OrientationEqualThreshold returns whether the quaternions represents the same orientation with a given tolerence
[ "OrientationEqualThreshold", "returns", "whether", "the", "quaternions", "represents", "the", "same", "orientation", "with", "a", "given", "tolerence" ]
c4601bc793c7a480dab005cf969aab0d7a7fb07d
https://github.com/go-gl/mathgl/blob/c4601bc793c7a480dab005cf969aab0d7a7fb07d/mgl32/quat.go#L208-L210
20,849
go-gl/mathgl
mgl32/quat.go
QuatBetweenVectors
func QuatBetweenVectors(start, dest Vec3) Quat { // http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-17-quaternions/#I_need_an_equivalent_of_gluLookAt__How_do_I_orient_an_object_towards_a_point__ // https://github.com/g-truc/glm/blob/0.9.5/glm/gtx/quaternion.inl#L225 // https://bitbucket.org/sinbad/ogre/src/d2ef494c4a2f5d6e2f0f17d3bfb9fd936d5423bb/OgreMain/include/OgreVector3.h?at=default#cl-654 start = start.Normalize() dest = dest.Normalize() epsilon := float32(0.001) cosTheta := start.Dot(dest) if cosTheta < -1.0+epsilon { // special case when vectors in opposite directions: // there is no "ideal" rotation axis // So guess one; any will do as long as it's perpendicular to start axis := Vec3{1, 0, 0}.Cross(start) if axis.Dot(axis) < epsilon { // bad luck, they were parallel, try again! axis = Vec3{0, 1, 0}.Cross(start) } return QuatRotate(math.Pi, axis.Normalize()) } axis := start.Cross(dest) s := float32(math.Sqrt(float64(1.0+cosTheta) * 2.0)) return Quat{ s * 0.5, axis.Mul(1.0 / s), } }
go
func QuatBetweenVectors(start, dest Vec3) Quat { // http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-17-quaternions/#I_need_an_equivalent_of_gluLookAt__How_do_I_orient_an_object_towards_a_point__ // https://github.com/g-truc/glm/blob/0.9.5/glm/gtx/quaternion.inl#L225 // https://bitbucket.org/sinbad/ogre/src/d2ef494c4a2f5d6e2f0f17d3bfb9fd936d5423bb/OgreMain/include/OgreVector3.h?at=default#cl-654 start = start.Normalize() dest = dest.Normalize() epsilon := float32(0.001) cosTheta := start.Dot(dest) if cosTheta < -1.0+epsilon { // special case when vectors in opposite directions: // there is no "ideal" rotation axis // So guess one; any will do as long as it's perpendicular to start axis := Vec3{1, 0, 0}.Cross(start) if axis.Dot(axis) < epsilon { // bad luck, they were parallel, try again! axis = Vec3{0, 1, 0}.Cross(start) } return QuatRotate(math.Pi, axis.Normalize()) } axis := start.Cross(dest) s := float32(math.Sqrt(float64(1.0+cosTheta) * 2.0)) return Quat{ s * 0.5, axis.Mul(1.0 / s), } }
[ "func", "QuatBetweenVectors", "(", "start", ",", "dest", "Vec3", ")", "Quat", "{", "// http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-17-quaternions/#I_need_an_equivalent_of_gluLookAt__How_do_I_orient_an_object_towards_a_point__", "// https://github.com/g-truc/glm/blob/0.9.5/glm/gtx/quaternion.inl#L225", "// https://bitbucket.org/sinbad/ogre/src/d2ef494c4a2f5d6e2f0f17d3bfb9fd936d5423bb/OgreMain/include/OgreVector3.h?at=default#cl-654", "start", "=", "start", ".", "Normalize", "(", ")", "\n", "dest", "=", "dest", ".", "Normalize", "(", ")", "\n", "epsilon", ":=", "float32", "(", "0.001", ")", "\n\n", "cosTheta", ":=", "start", ".", "Dot", "(", "dest", ")", "\n", "if", "cosTheta", "<", "-", "1.0", "+", "epsilon", "{", "// special case when vectors in opposite directions:", "// there is no \"ideal\" rotation axis", "// So guess one; any will do as long as it's perpendicular to start", "axis", ":=", "Vec3", "{", "1", ",", "0", ",", "0", "}", ".", "Cross", "(", "start", ")", "\n", "if", "axis", ".", "Dot", "(", "axis", ")", "<", "epsilon", "{", "// bad luck, they were parallel, try again!", "axis", "=", "Vec3", "{", "0", ",", "1", ",", "0", "}", ".", "Cross", "(", "start", ")", "\n", "}", "\n\n", "return", "QuatRotate", "(", "math", ".", "Pi", ",", "axis", ".", "Normalize", "(", ")", ")", "\n", "}", "\n\n", "axis", ":=", "start", ".", "Cross", "(", "dest", ")", "\n", "s", ":=", "float32", "(", "math", ".", "Sqrt", "(", "float64", "(", "1.0", "+", "cosTheta", ")", "*", "2.0", ")", ")", "\n\n", "return", "Quat", "{", "s", "*", "0.5", ",", "axis", ".", "Mul", "(", "1.0", "/", "s", ")", ",", "}", "\n", "}" ]
// QuatBetweenVectors calculates the rotation between two vectors
[ "QuatBetweenVectors", "calculates", "the", "rotation", "between", "two", "vectors" ]
c4601bc793c7a480dab005cf969aab0d7a7fb07d
https://github.com/go-gl/mathgl/blob/c4601bc793c7a480dab005cf969aab0d7a7fb07d/mgl32/quat.go#L431-L461
20,850
go-gl/mathgl
mgl32/matrix.go
Mat2FromRows
func Mat2FromRows(row0, row1 Vec2) Mat2 { return Mat2{row0[0], row1[0], row0[1], row1[1]} }
go
func Mat2FromRows(row0, row1 Vec2) Mat2 { return Mat2{row0[0], row1[0], row0[1], row1[1]} }
[ "func", "Mat2FromRows", "(", "row0", ",", "row1", "Vec2", ")", "Mat2", "{", "return", "Mat2", "{", "row0", "[", "0", "]", ",", "row1", "[", "0", "]", ",", "row0", "[", "1", "]", ",", "row1", "[", "1", "]", "}", "\n", "}" ]
// Mat2FromRows builds a new matrix from row vectors. // The resulting matrix will still be in column major order, but this can be // good for hand-building matrices.
[ "Mat2FromRows", "builds", "a", "new", "matrix", "from", "row", "vectors", ".", "The", "resulting", "matrix", "will", "still", "be", "in", "column", "major", "order", "but", "this", "can", "be", "good", "for", "hand", "-", "building", "matrices", "." ]
c4601bc793c7a480dab005cf969aab0d7a7fb07d
https://github.com/go-gl/mathgl/blob/c4601bc793c7a480dab005cf969aab0d7a7fb07d/mgl32/matrix.go#L119-L121
20,851
go-gl/mathgl
mgl32/matrix.go
Mat2FromCols
func Mat2FromCols(col0, col1 Vec2) Mat2 { return Mat2{col0[0], col0[1], col1[0], col1[1]} }
go
func Mat2FromCols(col0, col1 Vec2) Mat2 { return Mat2{col0[0], col0[1], col1[0], col1[1]} }
[ "func", "Mat2FromCols", "(", "col0", ",", "col1", "Vec2", ")", "Mat2", "{", "return", "Mat2", "{", "col0", "[", "0", "]", ",", "col0", "[", "1", "]", ",", "col1", "[", "0", "]", ",", "col1", "[", "1", "]", "}", "\n", "}" ]
// Mat2FromCols builds a new matrix from column vectors.
[ "Mat2FromCols", "builds", "a", "new", "matrix", "from", "column", "vectors", "." ]
c4601bc793c7a480dab005cf969aab0d7a7fb07d
https://github.com/go-gl/mathgl/blob/c4601bc793c7a480dab005cf969aab0d7a7fb07d/mgl32/matrix.go#L124-L126
20,852
go-gl/mathgl
mgl32/matrix.go
Mat2x3FromRows
func Mat2x3FromRows(row0, row1 Vec3) Mat2x3 { return Mat2x3{row0[0], row1[0], row0[1], row1[1], row0[2], row1[2]} }
go
func Mat2x3FromRows(row0, row1 Vec3) Mat2x3 { return Mat2x3{row0[0], row1[0], row0[1], row1[1], row0[2], row1[2]} }
[ "func", "Mat2x3FromRows", "(", "row0", ",", "row1", "Vec3", ")", "Mat2x3", "{", "return", "Mat2x3", "{", "row0", "[", "0", "]", ",", "row1", "[", "0", "]", ",", "row0", "[", "1", "]", ",", "row1", "[", "1", "]", ",", "row0", "[", "2", "]", ",", "row1", "[", "2", "]", "}", "\n", "}" ]
// Mat2x3FromRows builds a new matrix from row vectors. // The resulting matrix will still be in column major order, but this can be // good for hand-building matrices.
[ "Mat2x3FromRows", "builds", "a", "new", "matrix", "from", "row", "vectors", ".", "The", "resulting", "matrix", "will", "still", "be", "in", "column", "major", "order", "but", "this", "can", "be", "good", "for", "hand", "-", "building", "matrices", "." ]
c4601bc793c7a480dab005cf969aab0d7a7fb07d
https://github.com/go-gl/mathgl/blob/c4601bc793c7a480dab005cf969aab0d7a7fb07d/mgl32/matrix.go#L374-L376
20,853
go-gl/mathgl
mgl32/matrix.go
Mat2x3FromCols
func Mat2x3FromCols(col0, col1, col2 Vec2) Mat2x3 { return Mat2x3{col0[0], col0[1], col1[0], col1[1], col2[0], col2[1]} }
go
func Mat2x3FromCols(col0, col1, col2 Vec2) Mat2x3 { return Mat2x3{col0[0], col0[1], col1[0], col1[1], col2[0], col2[1]} }
[ "func", "Mat2x3FromCols", "(", "col0", ",", "col1", ",", "col2", "Vec2", ")", "Mat2x3", "{", "return", "Mat2x3", "{", "col0", "[", "0", "]", ",", "col0", "[", "1", "]", ",", "col1", "[", "0", "]", ",", "col1", "[", "1", "]", ",", "col2", "[", "0", "]", ",", "col2", "[", "1", "]", "}", "\n", "}" ]
// Mat2x3FromCols builds a new matrix from column vectors.
[ "Mat2x3FromCols", "builds", "a", "new", "matrix", "from", "column", "vectors", "." ]
c4601bc793c7a480dab005cf969aab0d7a7fb07d
https://github.com/go-gl/mathgl/blob/c4601bc793c7a480dab005cf969aab0d7a7fb07d/mgl32/matrix.go#L379-L381
20,854
go-gl/mathgl
mgl32/matrix.go
Mat2x4FromRows
func Mat2x4FromRows(row0, row1 Vec4) Mat2x4 { return Mat2x4{row0[0], row1[0], row0[1], row1[1], row0[2], row1[2], row0[3], row1[3]} }
go
func Mat2x4FromRows(row0, row1 Vec4) Mat2x4 { return Mat2x4{row0[0], row1[0], row0[1], row1[1], row0[2], row1[2], row0[3], row1[3]} }
[ "func", "Mat2x4FromRows", "(", "row0", ",", "row1", "Vec4", ")", "Mat2x4", "{", "return", "Mat2x4", "{", "row0", "[", "0", "]", ",", "row1", "[", "0", "]", ",", "row0", "[", "1", "]", ",", "row1", "[", "1", "]", ",", "row0", "[", "2", "]", ",", "row1", "[", "2", "]", ",", "row0", "[", "3", "]", ",", "row1", "[", "3", "]", "}", "\n", "}" ]
// Mat2x4FromRows builds a new matrix from row vectors. // The resulting matrix will still be in column major order, but this can be // good for hand-building matrices.
[ "Mat2x4FromRows", "builds", "a", "new", "matrix", "from", "row", "vectors", ".", "The", "resulting", "matrix", "will", "still", "be", "in", "column", "major", "order", "but", "this", "can", "be", "good", "for", "hand", "-", "building", "matrices", "." ]
c4601bc793c7a480dab005cf969aab0d7a7fb07d
https://github.com/go-gl/mathgl/blob/c4601bc793c7a480dab005cf969aab0d7a7fb07d/mgl32/matrix.go#L592-L594
20,855
go-gl/mathgl
mgl32/matrix.go
Mat2x4FromCols
func Mat2x4FromCols(col0, col1, col2, col3 Vec2) Mat2x4 { return Mat2x4{col0[0], col0[1], col1[0], col1[1], col2[0], col2[1], col3[0], col3[1]} }
go
func Mat2x4FromCols(col0, col1, col2, col3 Vec2) Mat2x4 { return Mat2x4{col0[0], col0[1], col1[0], col1[1], col2[0], col2[1], col3[0], col3[1]} }
[ "func", "Mat2x4FromCols", "(", "col0", ",", "col1", ",", "col2", ",", "col3", "Vec2", ")", "Mat2x4", "{", "return", "Mat2x4", "{", "col0", "[", "0", "]", ",", "col0", "[", "1", "]", ",", "col1", "[", "0", "]", ",", "col1", "[", "1", "]", ",", "col2", "[", "0", "]", ",", "col2", "[", "1", "]", ",", "col3", "[", "0", "]", ",", "col3", "[", "1", "]", "}", "\n", "}" ]
// Mat2x4FromCols builds a new matrix from column vectors.
[ "Mat2x4FromCols", "builds", "a", "new", "matrix", "from", "column", "vectors", "." ]
c4601bc793c7a480dab005cf969aab0d7a7fb07d
https://github.com/go-gl/mathgl/blob/c4601bc793c7a480dab005cf969aab0d7a7fb07d/mgl32/matrix.go#L597-L599
20,856
go-gl/mathgl
mgl32/matrix.go
Mat3x2FromRows
func Mat3x2FromRows(row0, row1, row2 Vec2) Mat3x2 { return Mat3x2{row0[0], row1[0], row2[0], row0[1], row1[1], row2[1]} }
go
func Mat3x2FromRows(row0, row1, row2 Vec2) Mat3x2 { return Mat3x2{row0[0], row1[0], row2[0], row0[1], row1[1], row2[1]} }
[ "func", "Mat3x2FromRows", "(", "row0", ",", "row1", ",", "row2", "Vec2", ")", "Mat3x2", "{", "return", "Mat3x2", "{", "row0", "[", "0", "]", ",", "row1", "[", "0", "]", ",", "row2", "[", "0", "]", ",", "row0", "[", "1", "]", ",", "row1", "[", "1", "]", ",", "row2", "[", "1", "]", "}", "\n", "}" ]
// Mat3x2FromRows builds a new matrix from row vectors. // The resulting matrix will still be in column major order, but this can be // good for hand-building matrices.
[ "Mat3x2FromRows", "builds", "a", "new", "matrix", "from", "row", "vectors", ".", "The", "resulting", "matrix", "will", "still", "be", "in", "column", "major", "order", "but", "this", "can", "be", "good", "for", "hand", "-", "building", "matrices", "." ]
c4601bc793c7a480dab005cf969aab0d7a7fb07d
https://github.com/go-gl/mathgl/blob/c4601bc793c7a480dab005cf969aab0d7a7fb07d/mgl32/matrix.go#L810-L812
20,857
go-gl/mathgl
mgl32/matrix.go
Mat3x2FromCols
func Mat3x2FromCols(col0, col1 Vec3) Mat3x2 { return Mat3x2{col0[0], col0[1], col0[2], col1[0], col1[1], col1[2]} }
go
func Mat3x2FromCols(col0, col1 Vec3) Mat3x2 { return Mat3x2{col0[0], col0[1], col0[2], col1[0], col1[1], col1[2]} }
[ "func", "Mat3x2FromCols", "(", "col0", ",", "col1", "Vec3", ")", "Mat3x2", "{", "return", "Mat3x2", "{", "col0", "[", "0", "]", ",", "col0", "[", "1", "]", ",", "col0", "[", "2", "]", ",", "col1", "[", "0", "]", ",", "col1", "[", "1", "]", ",", "col1", "[", "2", "]", "}", "\n", "}" ]
// Mat3x2FromCols builds a new matrix from column vectors.
[ "Mat3x2FromCols", "builds", "a", "new", "matrix", "from", "column", "vectors", "." ]
c4601bc793c7a480dab005cf969aab0d7a7fb07d
https://github.com/go-gl/mathgl/blob/c4601bc793c7a480dab005cf969aab0d7a7fb07d/mgl32/matrix.go#L815-L817
20,858
go-gl/mathgl
mgl32/matrix.go
Mat3FromRows
func Mat3FromRows(row0, row1, row2 Vec3) Mat3 { return Mat3{row0[0], row1[0], row2[0], row0[1], row1[1], row2[1], row0[2], row1[2], row2[2]} }
go
func Mat3FromRows(row0, row1, row2 Vec3) Mat3 { return Mat3{row0[0], row1[0], row2[0], row0[1], row1[1], row2[1], row0[2], row1[2], row2[2]} }
[ "func", "Mat3FromRows", "(", "row0", ",", "row1", ",", "row2", "Vec3", ")", "Mat3", "{", "return", "Mat3", "{", "row0", "[", "0", "]", ",", "row1", "[", "0", "]", ",", "row2", "[", "0", "]", ",", "row0", "[", "1", "]", ",", "row1", "[", "1", "]", ",", "row2", "[", "1", "]", ",", "row0", "[", "2", "]", ",", "row1", "[", "2", "]", ",", "row2", "[", "2", "]", "}", "\n", "}" ]
// Mat3FromRows builds a new matrix from row vectors. // The resulting matrix will still be in column major order, but this can be // good for hand-building matrices.
[ "Mat3FromRows", "builds", "a", "new", "matrix", "from", "row", "vectors", ".", "The", "resulting", "matrix", "will", "still", "be", "in", "column", "major", "order", "but", "this", "can", "be", "good", "for", "hand", "-", "building", "matrices", "." ]
c4601bc793c7a480dab005cf969aab0d7a7fb07d
https://github.com/go-gl/mathgl/blob/c4601bc793c7a480dab005cf969aab0d7a7fb07d/mgl32/matrix.go#L1062-L1064
20,859
go-gl/mathgl
mgl32/matrix.go
Mat3FromCols
func Mat3FromCols(col0, col1, col2 Vec3) Mat3 { return Mat3{col0[0], col0[1], col0[2], col1[0], col1[1], col1[2], col2[0], col2[1], col2[2]} }
go
func Mat3FromCols(col0, col1, col2 Vec3) Mat3 { return Mat3{col0[0], col0[1], col0[2], col1[0], col1[1], col1[2], col2[0], col2[1], col2[2]} }
[ "func", "Mat3FromCols", "(", "col0", ",", "col1", ",", "col2", "Vec3", ")", "Mat3", "{", "return", "Mat3", "{", "col0", "[", "0", "]", ",", "col0", "[", "1", "]", ",", "col0", "[", "2", "]", ",", "col1", "[", "0", "]", ",", "col1", "[", "1", "]", ",", "col1", "[", "2", "]", ",", "col2", "[", "0", "]", ",", "col2", "[", "1", "]", ",", "col2", "[", "2", "]", "}", "\n", "}" ]
// Mat3FromCols builds a new matrix from column vectors.
[ "Mat3FromCols", "builds", "a", "new", "matrix", "from", "column", "vectors", "." ]
c4601bc793c7a480dab005cf969aab0d7a7fb07d
https://github.com/go-gl/mathgl/blob/c4601bc793c7a480dab005cf969aab0d7a7fb07d/mgl32/matrix.go#L1067-L1069
20,860
go-gl/mathgl
mgl32/matrix.go
Mat3x4FromRows
func Mat3x4FromRows(row0, row1, row2 Vec4) Mat3x4 { return Mat3x4{row0[0], row1[0], row2[0], row0[1], row1[1], row2[1], row0[2], row1[2], row2[2], row0[3], row1[3], row2[3]} }
go
func Mat3x4FromRows(row0, row1, row2 Vec4) Mat3x4 { return Mat3x4{row0[0], row1[0], row2[0], row0[1], row1[1], row2[1], row0[2], row1[2], row2[2], row0[3], row1[3], row2[3]} }
[ "func", "Mat3x4FromRows", "(", "row0", ",", "row1", ",", "row2", "Vec4", ")", "Mat3x4", "{", "return", "Mat3x4", "{", "row0", "[", "0", "]", ",", "row1", "[", "0", "]", ",", "row2", "[", "0", "]", ",", "row0", "[", "1", "]", ",", "row1", "[", "1", "]", ",", "row2", "[", "1", "]", ",", "row0", "[", "2", "]", ",", "row1", "[", "2", "]", ",", "row2", "[", "2", "]", ",", "row0", "[", "3", "]", ",", "row1", "[", "3", "]", ",", "row2", "[", "3", "]", "}", "\n", "}" ]
// Mat3x4FromRows builds a new matrix from row vectors. // The resulting matrix will still be in column major order, but this can be // good for hand-building matrices.
[ "Mat3x4FromRows", "builds", "a", "new", "matrix", "from", "row", "vectors", ".", "The", "resulting", "matrix", "will", "still", "be", "in", "column", "major", "order", "but", "this", "can", "be", "good", "for", "hand", "-", "building", "matrices", "." ]
c4601bc793c7a480dab005cf969aab0d7a7fb07d
https://github.com/go-gl/mathgl/blob/c4601bc793c7a480dab005cf969aab0d7a7fb07d/mgl32/matrix.go#L1337-L1339
20,861
go-gl/mathgl
mgl32/matrix.go
Mat3x4FromCols
func Mat3x4FromCols(col0, col1, col2, col3 Vec3) Mat3x4 { return Mat3x4{col0[0], col0[1], col0[2], col1[0], col1[1], col1[2], col2[0], col2[1], col2[2], col3[0], col3[1], col3[2]} }
go
func Mat3x4FromCols(col0, col1, col2, col3 Vec3) Mat3x4 { return Mat3x4{col0[0], col0[1], col0[2], col1[0], col1[1], col1[2], col2[0], col2[1], col2[2], col3[0], col3[1], col3[2]} }
[ "func", "Mat3x4FromCols", "(", "col0", ",", "col1", ",", "col2", ",", "col3", "Vec3", ")", "Mat3x4", "{", "return", "Mat3x4", "{", "col0", "[", "0", "]", ",", "col0", "[", "1", "]", ",", "col0", "[", "2", "]", ",", "col1", "[", "0", "]", ",", "col1", "[", "1", "]", ",", "col1", "[", "2", "]", ",", "col2", "[", "0", "]", ",", "col2", "[", "1", "]", ",", "col2", "[", "2", "]", ",", "col3", "[", "0", "]", ",", "col3", "[", "1", "]", ",", "col3", "[", "2", "]", "}", "\n", "}" ]
// Mat3x4FromCols builds a new matrix from column vectors.
[ "Mat3x4FromCols", "builds", "a", "new", "matrix", "from", "column", "vectors", "." ]
c4601bc793c7a480dab005cf969aab0d7a7fb07d
https://github.com/go-gl/mathgl/blob/c4601bc793c7a480dab005cf969aab0d7a7fb07d/mgl32/matrix.go#L1342-L1344
20,862
go-gl/mathgl
mgl32/matrix.go
Mat4x2FromRows
func Mat4x2FromRows(row0, row1, row2, row3 Vec2) Mat4x2 { return Mat4x2{row0[0], row1[0], row2[0], row3[0], row0[1], row1[1], row2[1], row3[1]} }
go
func Mat4x2FromRows(row0, row1, row2, row3 Vec2) Mat4x2 { return Mat4x2{row0[0], row1[0], row2[0], row3[0], row0[1], row1[1], row2[1], row3[1]} }
[ "func", "Mat4x2FromRows", "(", "row0", ",", "row1", ",", "row2", ",", "row3", "Vec2", ")", "Mat4x2", "{", "return", "Mat4x2", "{", "row0", "[", "0", "]", ",", "row1", "[", "0", "]", ",", "row2", "[", "0", "]", ",", "row3", "[", "0", "]", ",", "row0", "[", "1", "]", ",", "row1", "[", "1", "]", ",", "row2", "[", "1", "]", ",", "row3", "[", "1", "]", "}", "\n", "}" ]
// Mat4x2FromRows builds a new matrix from row vectors. // The resulting matrix will still be in column major order, but this can be // good for hand-building matrices.
[ "Mat4x2FromRows", "builds", "a", "new", "matrix", "from", "row", "vectors", ".", "The", "resulting", "matrix", "will", "still", "be", "in", "column", "major", "order", "but", "this", "can", "be", "good", "for", "hand", "-", "building", "matrices", "." ]
c4601bc793c7a480dab005cf969aab0d7a7fb07d
https://github.com/go-gl/mathgl/blob/c4601bc793c7a480dab005cf969aab0d7a7fb07d/mgl32/matrix.go#L1565-L1567
20,863
go-gl/mathgl
mgl32/matrix.go
Mat4x2FromCols
func Mat4x2FromCols(col0, col1 Vec4) Mat4x2 { return Mat4x2{col0[0], col0[1], col0[2], col0[3], col1[0], col1[1], col1[2], col1[3]} }
go
func Mat4x2FromCols(col0, col1 Vec4) Mat4x2 { return Mat4x2{col0[0], col0[1], col0[2], col0[3], col1[0], col1[1], col1[2], col1[3]} }
[ "func", "Mat4x2FromCols", "(", "col0", ",", "col1", "Vec4", ")", "Mat4x2", "{", "return", "Mat4x2", "{", "col0", "[", "0", "]", ",", "col0", "[", "1", "]", ",", "col0", "[", "2", "]", ",", "col0", "[", "3", "]", ",", "col1", "[", "0", "]", ",", "col1", "[", "1", "]", ",", "col1", "[", "2", "]", ",", "col1", "[", "3", "]", "}", "\n", "}" ]
// Mat4x2FromCols builds a new matrix from column vectors.
[ "Mat4x2FromCols", "builds", "a", "new", "matrix", "from", "column", "vectors", "." ]
c4601bc793c7a480dab005cf969aab0d7a7fb07d
https://github.com/go-gl/mathgl/blob/c4601bc793c7a480dab005cf969aab0d7a7fb07d/mgl32/matrix.go#L1570-L1572
20,864
go-gl/mathgl
mgl32/matrix.go
ApproxEqual
func (m1 Mat4x2) ApproxEqual(m2 Mat4x2) bool { for i := range m1 { if !FloatEqual(m1[i], m2[i]) { return false } } return true }
go
func (m1 Mat4x2) ApproxEqual(m2 Mat4x2) bool { for i := range m1 { if !FloatEqual(m1[i], m2[i]) { return false } } return true }
[ "func", "(", "m1", "Mat4x2", ")", "ApproxEqual", "(", "m2", "Mat4x2", ")", "bool", "{", "for", "i", ":=", "range", "m1", "{", "if", "!", "FloatEqual", "(", "m1", "[", "i", "]", ",", "m2", "[", "i", "]", ")", "{", "return", "false", "\n", "}", "\n", "}", "\n", "return", "true", "\n", "}" ]
// ApproxEqual performs an element-wise approximate equality test between two matrices, // as if FloatEqual had been used.
[ "ApproxEqual", "performs", "an", "element", "-", "wise", "approximate", "equality", "test", "between", "two", "matrices", "as", "if", "FloatEqual", "had", "been", "used", "." ]
c4601bc793c7a480dab005cf969aab0d7a7fb07d
https://github.com/go-gl/mathgl/blob/c4601bc793c7a480dab005cf969aab0d7a7fb07d/mgl32/matrix.go#L1681-L1688
20,865
go-gl/mathgl
mgl32/matrix.go
Mat4x3FromRows
func Mat4x3FromRows(row0, row1, row2, row3 Vec3) Mat4x3 { return Mat4x3{row0[0], row1[0], row2[0], row3[0], row0[1], row1[1], row2[1], row3[1], row0[2], row1[2], row2[2], row3[2]} }
go
func Mat4x3FromRows(row0, row1, row2, row3 Vec3) Mat4x3 { return Mat4x3{row0[0], row1[0], row2[0], row3[0], row0[1], row1[1], row2[1], row3[1], row0[2], row1[2], row2[2], row3[2]} }
[ "func", "Mat4x3FromRows", "(", "row0", ",", "row1", ",", "row2", ",", "row3", "Vec3", ")", "Mat4x3", "{", "return", "Mat4x3", "{", "row0", "[", "0", "]", ",", "row1", "[", "0", "]", ",", "row2", "[", "0", "]", ",", "row3", "[", "0", "]", ",", "row0", "[", "1", "]", ",", "row1", "[", "1", "]", ",", "row2", "[", "1", "]", ",", "row3", "[", "1", "]", ",", "row0", "[", "2", "]", ",", "row1", "[", "2", "]", ",", "row2", "[", "2", "]", ",", "row3", "[", "2", "]", "}", "\n", "}" ]
// Mat4x3FromRows builds a new matrix from row vectors. // The resulting matrix will still be in column major order, but this can be // good for hand-building matrices.
[ "Mat4x3FromRows", "builds", "a", "new", "matrix", "from", "row", "vectors", ".", "The", "resulting", "matrix", "will", "still", "be", "in", "column", "major", "order", "but", "this", "can", "be", "good", "for", "hand", "-", "building", "matrices", "." ]
c4601bc793c7a480dab005cf969aab0d7a7fb07d
https://github.com/go-gl/mathgl/blob/c4601bc793c7a480dab005cf969aab0d7a7fb07d/mgl32/matrix.go#L1803-L1805
20,866
go-gl/mathgl
mgl32/matrix.go
Mat4x3FromCols
func Mat4x3FromCols(col0, col1, col2 Vec4) Mat4x3 { return Mat4x3{col0[0], col0[1], col0[2], col0[3], col1[0], col1[1], col1[2], col1[3], col2[0], col2[1], col2[2], col2[3]} }
go
func Mat4x3FromCols(col0, col1, col2 Vec4) Mat4x3 { return Mat4x3{col0[0], col0[1], col0[2], col0[3], col1[0], col1[1], col1[2], col1[3], col2[0], col2[1], col2[2], col2[3]} }
[ "func", "Mat4x3FromCols", "(", "col0", ",", "col1", ",", "col2", "Vec4", ")", "Mat4x3", "{", "return", "Mat4x3", "{", "col0", "[", "0", "]", ",", "col0", "[", "1", "]", ",", "col0", "[", "2", "]", ",", "col0", "[", "3", "]", ",", "col1", "[", "0", "]", ",", "col1", "[", "1", "]", ",", "col1", "[", "2", "]", ",", "col1", "[", "3", "]", ",", "col2", "[", "0", "]", ",", "col2", "[", "1", "]", ",", "col2", "[", "2", "]", ",", "col2", "[", "3", "]", "}", "\n", "}" ]
// Mat4x3FromCols builds a new matrix from column vectors.
[ "Mat4x3FromCols", "builds", "a", "new", "matrix", "from", "column", "vectors", "." ]
c4601bc793c7a480dab005cf969aab0d7a7fb07d
https://github.com/go-gl/mathgl/blob/c4601bc793c7a480dab005cf969aab0d7a7fb07d/mgl32/matrix.go#L1808-L1810
20,867
go-gl/mathgl
mgl32/matrix.go
Mat4FromRows
func Mat4FromRows(row0, row1, row2, row3 Vec4) Mat4 { return Mat4{row0[0], row1[0], row2[0], row3[0], row0[1], row1[1], row2[1], row3[1], row0[2], row1[2], row2[2], row3[2], row0[3], row1[3], row2[3], row3[3]} }
go
func Mat4FromRows(row0, row1, row2, row3 Vec4) Mat4 { return Mat4{row0[0], row1[0], row2[0], row3[0], row0[1], row1[1], row2[1], row3[1], row0[2], row1[2], row2[2], row3[2], row0[3], row1[3], row2[3], row3[3]} }
[ "func", "Mat4FromRows", "(", "row0", ",", "row1", ",", "row2", ",", "row3", "Vec4", ")", "Mat4", "{", "return", "Mat4", "{", "row0", "[", "0", "]", ",", "row1", "[", "0", "]", ",", "row2", "[", "0", "]", ",", "row3", "[", "0", "]", ",", "row0", "[", "1", "]", ",", "row1", "[", "1", "]", ",", "row2", "[", "1", "]", ",", "row3", "[", "1", "]", ",", "row0", "[", "2", "]", ",", "row1", "[", "2", "]", ",", "row2", "[", "2", "]", ",", "row3", "[", "2", "]", ",", "row0", "[", "3", "]", ",", "row1", "[", "3", "]", ",", "row2", "[", "3", "]", ",", "row3", "[", "3", "]", "}", "\n", "}" ]
// Mat4FromRows builds a new matrix from row vectors. // The resulting matrix will still be in column major order, but this can be // good for hand-building matrices.
[ "Mat4FromRows", "builds", "a", "new", "matrix", "from", "row", "vectors", ".", "The", "resulting", "matrix", "will", "still", "be", "in", "column", "major", "order", "but", "this", "can", "be", "good", "for", "hand", "-", "building", "matrices", "." ]
c4601bc793c7a480dab005cf969aab0d7a7fb07d
https://github.com/go-gl/mathgl/blob/c4601bc793c7a480dab005cf969aab0d7a7fb07d/mgl32/matrix.go#L2065-L2067
20,868
go-gl/mathgl
mgl32/matrix.go
Mat4FromCols
func Mat4FromCols(col0, col1, col2, col3 Vec4) Mat4 { return Mat4{col0[0], col0[1], col0[2], col0[3], col1[0], col1[1], col1[2], col1[3], col2[0], col2[1], col2[2], col2[3], col3[0], col3[1], col3[2], col3[3]} }
go
func Mat4FromCols(col0, col1, col2, col3 Vec4) Mat4 { return Mat4{col0[0], col0[1], col0[2], col0[3], col1[0], col1[1], col1[2], col1[3], col2[0], col2[1], col2[2], col2[3], col3[0], col3[1], col3[2], col3[3]} }
[ "func", "Mat4FromCols", "(", "col0", ",", "col1", ",", "col2", ",", "col3", "Vec4", ")", "Mat4", "{", "return", "Mat4", "{", "col0", "[", "0", "]", ",", "col0", "[", "1", "]", ",", "col0", "[", "2", "]", ",", "col0", "[", "3", "]", ",", "col1", "[", "0", "]", ",", "col1", "[", "1", "]", ",", "col1", "[", "2", "]", ",", "col1", "[", "3", "]", ",", "col2", "[", "0", "]", ",", "col2", "[", "1", "]", ",", "col2", "[", "2", "]", ",", "col2", "[", "3", "]", ",", "col3", "[", "0", "]", ",", "col3", "[", "1", "]", ",", "col3", "[", "2", "]", ",", "col3", "[", "3", "]", "}", "\n", "}" ]
// Mat4FromCols builds a new matrix from column vectors.
[ "Mat4FromCols", "builds", "a", "new", "matrix", "from", "column", "vectors", "." ]
c4601bc793c7a480dab005cf969aab0d7a7fb07d
https://github.com/go-gl/mathgl/blob/c4601bc793c7a480dab005cf969aab0d7a7fb07d/mgl32/matrix.go#L2070-L2072
20,869
go-gl/mathgl
mgl32/matrix.go
String
func (m Mat4) String() string { buf := new(bytes.Buffer) w := tabwriter.NewWriter(buf, 4, 4, 1, ' ', tabwriter.AlignRight) for i := 0; i < 4; i++ { for _, col := range m.Row(i) { fmt.Fprintf(w, "%f\t", col) } fmt.Fprintln(w, "") } w.Flush() return buf.String() }
go
func (m Mat4) String() string { buf := new(bytes.Buffer) w := tabwriter.NewWriter(buf, 4, 4, 1, ' ', tabwriter.AlignRight) for i := 0; i < 4; i++ { for _, col := range m.Row(i) { fmt.Fprintf(w, "%f\t", col) } fmt.Fprintln(w, "") } w.Flush() return buf.String() }
[ "func", "(", "m", "Mat4", ")", "String", "(", ")", "string", "{", "buf", ":=", "new", "(", "bytes", ".", "Buffer", ")", "\n", "w", ":=", "tabwriter", ".", "NewWriter", "(", "buf", ",", "4", ",", "4", ",", "1", ",", "' '", ",", "tabwriter", ".", "AlignRight", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "4", ";", "i", "++", "{", "for", "_", ",", "col", ":=", "range", "m", ".", "Row", "(", "i", ")", "{", "fmt", ".", "Fprintf", "(", "w", ",", "\"", "\\t", "\"", ",", "col", ")", "\n", "}", "\n\n", "fmt", ".", "Fprintln", "(", "w", ",", "\"", "\"", ")", "\n", "}", "\n", "w", ".", "Flush", "(", ")", "\n\n", "return", "buf", ".", "String", "(", ")", "\n", "}" ]
// Pretty prints the matrix
[ "Pretty", "prints", "the", "matrix" ]
c4601bc793c7a480dab005cf969aab0d7a7fb07d
https://github.com/go-gl/mathgl/blob/c4601bc793c7a480dab005cf969aab0d7a7fb07d/mgl32/matrix.go#L2328-L2341
20,870
go-gl/mathgl
mgl32/matstack/transformStack.go
reseed
func (ms *TransformStack) reseed(n int, change mgl32.Mat4) error { backup := []mgl32.Mat4((*ms)[n:]) backup = append([]mgl32.Mat4{}, backup...) // copy into new slice curr := (*ms)[n] (*ms)[n] = (*ms)[n-1].Mul4(change) for i := n + 1; i < len(*ms); i++ { inv := curr.Inv() blank := mgl32.Mat4{} if inv == blank { ms.undoRebase(n, backup) return NoInverseError{Loc: i - 1, Mat: curr} } ghost := inv.Mul4((*ms)[i]) curr = (*ms)[i] (*ms)[i] = (*ms)[i-1].Mul4(ghost) } return nil }
go
func (ms *TransformStack) reseed(n int, change mgl32.Mat4) error { backup := []mgl32.Mat4((*ms)[n:]) backup = append([]mgl32.Mat4{}, backup...) // copy into new slice curr := (*ms)[n] (*ms)[n] = (*ms)[n-1].Mul4(change) for i := n + 1; i < len(*ms); i++ { inv := curr.Inv() blank := mgl32.Mat4{} if inv == blank { ms.undoRebase(n, backup) return NoInverseError{Loc: i - 1, Mat: curr} } ghost := inv.Mul4((*ms)[i]) curr = (*ms)[i] (*ms)[i] = (*ms)[i-1].Mul4(ghost) } return nil }
[ "func", "(", "ms", "*", "TransformStack", ")", "reseed", "(", "n", "int", ",", "change", "mgl32", ".", "Mat4", ")", "error", "{", "backup", ":=", "[", "]", "mgl32", ".", "Mat4", "(", "(", "*", "ms", ")", "[", "n", ":", "]", ")", "\n", "backup", "=", "append", "(", "[", "]", "mgl32", ".", "Mat4", "{", "}", ",", "backup", "...", ")", "// copy into new slice", "\n\n", "curr", ":=", "(", "*", "ms", ")", "[", "n", "]", "\n", "(", "*", "ms", ")", "[", "n", "]", "=", "(", "*", "ms", ")", "[", "n", "-", "1", "]", ".", "Mul4", "(", "change", ")", "\n\n", "for", "i", ":=", "n", "+", "1", ";", "i", "<", "len", "(", "*", "ms", ")", ";", "i", "++", "{", "inv", ":=", "curr", ".", "Inv", "(", ")", "\n\n", "blank", ":=", "mgl32", ".", "Mat4", "{", "}", "\n", "if", "inv", "==", "blank", "{", "ms", ".", "undoRebase", "(", "n", ",", "backup", ")", "\n", "return", "NoInverseError", "{", "Loc", ":", "i", "-", "1", ",", "Mat", ":", "curr", "}", "\n", "}", "\n\n", "ghost", ":=", "inv", ".", "Mul4", "(", "(", "*", "ms", ")", "[", "i", "]", ")", "\n\n", "curr", "=", "(", "*", "ms", ")", "[", "i", "]", "\n", "(", "*", "ms", ")", "[", "i", "]", "=", "(", "*", "ms", ")", "[", "i", "-", "1", "]", ".", "Mul4", "(", "ghost", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Operates like reseed with no bounds checking; allows us to overwrite // the leading identity matrix with Rebase.
[ "Operates", "like", "reseed", "with", "no", "bounds", "checking", ";", "allows", "us", "to", "overwrite", "the", "leading", "identity", "matrix", "with", "Rebase", "." ]
c4601bc793c7a480dab005cf969aab0d7a7fb07d
https://github.com/go-gl/mathgl/blob/c4601bc793c7a480dab005cf969aab0d7a7fb07d/mgl32/matstack/transformStack.go#L106-L129
20,871
go-gl/mathgl
mgl32/shapes.go
CubicBezierCurve2D
func CubicBezierCurve2D(t float32, cPoint1, cPoint2, cPoint3, cPoint4 Vec2) Vec2 { if t < 0.0 || t > 1.0 { panic("Can't interpolate on bezier curve with t out of range [0.0,1.0]") } return cPoint1.Mul((1 - t) * (1 - t) * (1 - t)).Add(cPoint2.Mul(3 * (1 - t) * (1 - t) * t)).Add(cPoint3.Mul(3 * (1 - t) * t * t)).Add(cPoint4.Mul(t * t * t)) }
go
func CubicBezierCurve2D(t float32, cPoint1, cPoint2, cPoint3, cPoint4 Vec2) Vec2 { if t < 0.0 || t > 1.0 { panic("Can't interpolate on bezier curve with t out of range [0.0,1.0]") } return cPoint1.Mul((1 - t) * (1 - t) * (1 - t)).Add(cPoint2.Mul(3 * (1 - t) * (1 - t) * t)).Add(cPoint3.Mul(3 * (1 - t) * t * t)).Add(cPoint4.Mul(t * t * t)) }
[ "func", "CubicBezierCurve2D", "(", "t", "float32", ",", "cPoint1", ",", "cPoint2", ",", "cPoint3", ",", "cPoint4", "Vec2", ")", "Vec2", "{", "if", "t", "<", "0.0", "||", "t", ">", "1.0", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n\n", "return", "cPoint1", ".", "Mul", "(", "(", "1", "-", "t", ")", "*", "(", "1", "-", "t", ")", "*", "(", "1", "-", "t", ")", ")", ".", "Add", "(", "cPoint2", ".", "Mul", "(", "3", "*", "(", "1", "-", "t", ")", "*", "(", "1", "-", "t", ")", "*", "t", ")", ")", ".", "Add", "(", "cPoint3", ".", "Mul", "(", "3", "*", "(", "1", "-", "t", ")", "*", "t", "*", "t", ")", ")", ".", "Add", "(", "cPoint4", ".", "Mul", "(", "t", "*", "t", "*", "t", ")", ")", "\n", "}" ]
// CubicBezierCurve2D interpolates the point t on the given bezier curve.
[ "CubicBezierCurve2D", "interpolates", "the", "point", "t", "on", "the", "given", "bezier", "curve", "." ]
c4601bc793c7a480dab005cf969aab0d7a7fb07d
https://github.com/go-gl/mathgl/blob/c4601bc793c7a480dab005cf969aab0d7a7fb07d/mgl32/shapes.go#L84-L90
20,872
go-gl/mathgl
mgl32/shapes.go
CubicBezierCurve3D
func CubicBezierCurve3D(t float32, cPoint1, cPoint2, cPoint3, cPoint4 Vec3) Vec3 { if t < 0.0 || t > 1.0 { panic("Can't interpolate on bezier curve with t out of range [0.0,1.0]") } return cPoint1.Mul((1 - t) * (1 - t) * (1 - t)).Add(cPoint2.Mul(3 * (1 - t) * (1 - t) * t)).Add(cPoint3.Mul(3 * (1 - t) * t * t)).Add(cPoint4.Mul(t * t * t)) }
go
func CubicBezierCurve3D(t float32, cPoint1, cPoint2, cPoint3, cPoint4 Vec3) Vec3 { if t < 0.0 || t > 1.0 { panic("Can't interpolate on bezier curve with t out of range [0.0,1.0]") } return cPoint1.Mul((1 - t) * (1 - t) * (1 - t)).Add(cPoint2.Mul(3 * (1 - t) * (1 - t) * t)).Add(cPoint3.Mul(3 * (1 - t) * t * t)).Add(cPoint4.Mul(t * t * t)) }
[ "func", "CubicBezierCurve3D", "(", "t", "float32", ",", "cPoint1", ",", "cPoint2", ",", "cPoint3", ",", "cPoint4", "Vec3", ")", "Vec3", "{", "if", "t", "<", "0.0", "||", "t", ">", "1.0", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n\n", "return", "cPoint1", ".", "Mul", "(", "(", "1", "-", "t", ")", "*", "(", "1", "-", "t", ")", "*", "(", "1", "-", "t", ")", ")", ".", "Add", "(", "cPoint2", ".", "Mul", "(", "3", "*", "(", "1", "-", "t", ")", "*", "(", "1", "-", "t", ")", "*", "t", ")", ")", ".", "Add", "(", "cPoint3", ".", "Mul", "(", "3", "*", "(", "1", "-", "t", ")", "*", "t", "*", "t", ")", ")", ".", "Add", "(", "cPoint4", ".", "Mul", "(", "t", "*", "t", "*", "t", ")", ")", "\n", "}" ]
// CubicBezierCurve3D interpolates the point t on the given bezier curve.
[ "CubicBezierCurve3D", "interpolates", "the", "point", "t", "on", "the", "given", "bezier", "curve", "." ]
c4601bc793c7a480dab005cf969aab0d7a7fb07d
https://github.com/go-gl/mathgl/blob/c4601bc793c7a480dab005cf969aab0d7a7fb07d/mgl32/shapes.go#L93-L99
20,873
go-gl/mathgl
mgl32/shapes.go
BezierSplineInterpolate3D
func BezierSplineInterpolate3D(t float32, ranges [][2]float32, cPoints [][]Vec3) Vec3 { if len(ranges) != len(cPoints) { panic("Each bezier curve needs a range") } for i, curveRange := range ranges { if t >= curveRange[0] && t <= curveRange[1] { return BezierCurve3D((t-curveRange[0])/(curveRange[1]-curveRange[0]), cPoints[i]) } } panic("t is out of the range of all bezier curves in this spline") }
go
func BezierSplineInterpolate3D(t float32, ranges [][2]float32, cPoints [][]Vec3) Vec3 { if len(ranges) != len(cPoints) { panic("Each bezier curve needs a range") } for i, curveRange := range ranges { if t >= curveRange[0] && t <= curveRange[1] { return BezierCurve3D((t-curveRange[0])/(curveRange[1]-curveRange[0]), cPoints[i]) } } panic("t is out of the range of all bezier curves in this spline") }
[ "func", "BezierSplineInterpolate3D", "(", "t", "float32", ",", "ranges", "[", "]", "[", "2", "]", "float32", ",", "cPoints", "[", "]", "[", "]", "Vec3", ")", "Vec3", "{", "if", "len", "(", "ranges", ")", "!=", "len", "(", "cPoints", ")", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n\n", "for", "i", ",", "curveRange", ":=", "range", "ranges", "{", "if", "t", ">=", "curveRange", "[", "0", "]", "&&", "t", "<=", "curveRange", "[", "1", "]", "{", "return", "BezierCurve3D", "(", "(", "t", "-", "curveRange", "[", "0", "]", ")", "/", "(", "curveRange", "[", "1", "]", "-", "curveRange", "[", "0", "]", ")", ",", "cPoints", "[", "i", "]", ")", "\n", "}", "\n", "}", "\n\n", "panic", "(", "\"", "\"", ")", "\n", "}" ]
// BezierSplineInterpolate3D does interpolation over a spline of several bezier // curves. Each bezier curve must have a finite range, though the spline may be // disjoint. The bezier curves are not required to be in any particular order. // // If t is out of the range of all given curves, this function will panic
[ "BezierSplineInterpolate3D", "does", "interpolation", "over", "a", "spline", "of", "several", "bezier", "curves", ".", "Each", "bezier", "curve", "must", "have", "a", "finite", "range", "though", "the", "spline", "may", "be", "disjoint", ".", "The", "bezier", "curves", "are", "not", "required", "to", "be", "in", "any", "particular", "order", ".", "If", "t", "is", "out", "of", "the", "range", "of", "all", "given", "curves", "this", "function", "will", "panic" ]
c4601bc793c7a480dab005cf969aab0d7a7fb07d
https://github.com/go-gl/mathgl/blob/c4601bc793c7a480dab005cf969aab0d7a7fb07d/mgl32/shapes.go#L247-L259
20,874
go-gl/mathgl
mgl64/matrix.go
ApproxEqualThreshold
func (m1 Mat2) ApproxEqualThreshold(m2 Mat2, threshold float64) bool { for i := range m1 { if !FloatEqualThreshold(m1[i], m2[i], threshold) { return false } } return true }
go
func (m1 Mat2) ApproxEqualThreshold(m2 Mat2, threshold float64) bool { for i := range m1 { if !FloatEqualThreshold(m1[i], m2[i], threshold) { return false } } return true }
[ "func", "(", "m1", "Mat2", ")", "ApproxEqualThreshold", "(", "m2", "Mat2", ",", "threshold", "float64", ")", "bool", "{", "for", "i", ":=", "range", "m1", "{", "if", "!", "FloatEqualThreshold", "(", "m1", "[", "i", "]", ",", "m2", "[", "i", "]", ",", "threshold", ")", "{", "return", "false", "\n", "}", "\n", "}", "\n", "return", "true", "\n", "}" ]
// ApproxEqualThreshold performs an element-wise approximate equality test between two matrices // with a given epsilon threshold, as if FloatEqualThreshold had been used.
[ "ApproxEqualThreshold", "performs", "an", "element", "-", "wise", "approximate", "equality", "test", "between", "two", "matrices", "with", "a", "given", "epsilon", "threshold", "as", "if", "FloatEqualThreshold", "had", "been", "used", "." ]
c4601bc793c7a480dab005cf969aab0d7a7fb07d
https://github.com/go-gl/mathgl/blob/c4601bc793c7a480dab005cf969aab0d7a7fb07d/mgl64/matrix.go#L260-L267
20,875
go-gl/mathgl
mgl64/matrix.go
ApproxFuncEqual
func (m1 Mat2) ApproxFuncEqual(m2 Mat2, eq func(float64, float64) bool) bool { for i := range m1 { if !eq(m1[i], m2[i]) { return false } } return true }
go
func (m1 Mat2) ApproxFuncEqual(m2 Mat2, eq func(float64, float64) bool) bool { for i := range m1 { if !eq(m1[i], m2[i]) { return false } } return true }
[ "func", "(", "m1", "Mat2", ")", "ApproxFuncEqual", "(", "m2", "Mat2", ",", "eq", "func", "(", "float64", ",", "float64", ")", "bool", ")", "bool", "{", "for", "i", ":=", "range", "m1", "{", "if", "!", "eq", "(", "m1", "[", "i", "]", ",", "m2", "[", "i", "]", ")", "{", "return", "false", "\n", "}", "\n", "}", "\n", "return", "true", "\n", "}" ]
// ApproxFuncEqual performs an element-wise approximate equality test between two matrices // with a given equality functions, intended to be used with FloatEqualFunc; although and comparison // function may be used in practice.
[ "ApproxFuncEqual", "performs", "an", "element", "-", "wise", "approximate", "equality", "test", "between", "two", "matrices", "with", "a", "given", "equality", "functions", "intended", "to", "be", "used", "with", "FloatEqualFunc", ";", "although", "and", "comparison", "function", "may", "be", "used", "in", "practice", "." ]
c4601bc793c7a480dab005cf969aab0d7a7fb07d
https://github.com/go-gl/mathgl/blob/c4601bc793c7a480dab005cf969aab0d7a7fb07d/mgl64/matrix.go#L272-L279
20,876
rkt/rkt
tools/depsgen/main.go
getAllDepTypes
func getAllDepTypes() []string { depTypes := make([]string, 0, len(cmds)) for depType := range cmds { depTypes = append(depTypes, depType) } sort.Strings(depTypes) return depTypes }
go
func getAllDepTypes() []string { depTypes := make([]string, 0, len(cmds)) for depType := range cmds { depTypes = append(depTypes, depType) } sort.Strings(depTypes) return depTypes }
[ "func", "getAllDepTypes", "(", ")", "[", "]", "string", "{", "depTypes", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "len", "(", "cmds", ")", ")", "\n", "for", "depType", ":=", "range", "cmds", "{", "depTypes", "=", "append", "(", "depTypes", ",", "depType", ")", "\n", "}", "\n", "sort", ".", "Strings", "(", "depTypes", ")", "\n", "return", "depTypes", "\n", "}" ]
// getAllDepTypes returns a sorted list of names of all dep type // commands.
[ "getAllDepTypes", "returns", "a", "sorted", "list", "of", "names", "of", "all", "dep", "type", "commands", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/tools/depsgen/main.go#L47-L54
20,877
rkt/rkt
rkt/image/io.go
getIoProgressReader
func getIoProgressReader(label string, res *http.Response) io.Reader { prefix := "Downloading " + label fmtBytesSize := 18 barSize := int64(80 - len(prefix) - fmtBytesSize) bar := ioprogress.DrawTextFormatBarForW(barSize, os.Stderr) fmtfunc := func(progress, total int64) string { // Content-Length is set to -1 when unknown. if total == -1 { return fmt.Sprintf( "%s: %v of an unknown total size", prefix, ioprogress.ByteUnitStr(progress), ) } return fmt.Sprintf( "%s: %s %s", prefix, bar(progress, total), ioprogress.DrawTextFormatBytes(progress, total), ) } return &ioprogress.Reader{ Reader: res.Body, Size: res.ContentLength, DrawFunc: ioprogress.DrawTerminalf(os.Stderr, fmtfunc), DrawInterval: time.Second, } }
go
func getIoProgressReader(label string, res *http.Response) io.Reader { prefix := "Downloading " + label fmtBytesSize := 18 barSize := int64(80 - len(prefix) - fmtBytesSize) bar := ioprogress.DrawTextFormatBarForW(barSize, os.Stderr) fmtfunc := func(progress, total int64) string { // Content-Length is set to -1 when unknown. if total == -1 { return fmt.Sprintf( "%s: %v of an unknown total size", prefix, ioprogress.ByteUnitStr(progress), ) } return fmt.Sprintf( "%s: %s %s", prefix, bar(progress, total), ioprogress.DrawTextFormatBytes(progress, total), ) } return &ioprogress.Reader{ Reader: res.Body, Size: res.ContentLength, DrawFunc: ioprogress.DrawTerminalf(os.Stderr, fmtfunc), DrawInterval: time.Second, } }
[ "func", "getIoProgressReader", "(", "label", "string", ",", "res", "*", "http", ".", "Response", ")", "io", ".", "Reader", "{", "prefix", ":=", "\"", "\"", "+", "label", "\n", "fmtBytesSize", ":=", "18", "\n", "barSize", ":=", "int64", "(", "80", "-", "len", "(", "prefix", ")", "-", "fmtBytesSize", ")", "\n", "bar", ":=", "ioprogress", ".", "DrawTextFormatBarForW", "(", "barSize", ",", "os", ".", "Stderr", ")", "\n", "fmtfunc", ":=", "func", "(", "progress", ",", "total", "int64", ")", "string", "{", "// Content-Length is set to -1 when unknown.", "if", "total", "==", "-", "1", "{", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "prefix", ",", "ioprogress", ".", "ByteUnitStr", "(", "progress", ")", ",", ")", "\n", "}", "\n", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "prefix", ",", "bar", "(", "progress", ",", "total", ")", ",", "ioprogress", ".", "DrawTextFormatBytes", "(", "progress", ",", "total", ")", ",", ")", "\n", "}", "\n", "return", "&", "ioprogress", ".", "Reader", "{", "Reader", ":", "res", ".", "Body", ",", "Size", ":", "res", ".", "ContentLength", ",", "DrawFunc", ":", "ioprogress", ".", "DrawTerminalf", "(", "os", ".", "Stderr", ",", "fmtfunc", ")", ",", "DrawInterval", ":", "time", ".", "Second", ",", "}", "\n", "}" ]
// getIoProgressReader returns a reader that wraps the HTTP response // body, so it prints a pretty progress bar when reading data from it.
[ "getIoProgressReader", "returns", "a", "reader", "that", "wraps", "the", "HTTP", "response", "body", "so", "it", "prints", "a", "pretty", "progress", "bar", "when", "reading", "data", "from", "it", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/image/io.go#L60-L87
20,878
rkt/rkt
rkt/image/io.go
Close
func (f *removeOnClose) Close() error { if f == nil || f.File == nil { return nil } name := f.File.Name() if err := f.File.Close(); err != nil { return err } if err := os.Remove(name); err != nil && !os.IsNotExist(err) { return err } return nil }
go
func (f *removeOnClose) Close() error { if f == nil || f.File == nil { return nil } name := f.File.Name() if err := f.File.Close(); err != nil { return err } if err := os.Remove(name); err != nil && !os.IsNotExist(err) { return err } return nil }
[ "func", "(", "f", "*", "removeOnClose", ")", "Close", "(", ")", "error", "{", "if", "f", "==", "nil", "||", "f", ".", "File", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "name", ":=", "f", ".", "File", ".", "Name", "(", ")", "\n", "if", "err", ":=", "f", ".", "File", ".", "Close", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "err", ":=", "os", ".", "Remove", "(", "name", ")", ";", "err", "!=", "nil", "&&", "!", "os", ".", "IsNotExist", "(", "err", ")", "{", "return", "err", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Close closes the file and then removes it from disk. No error is // returned if the file did not exist at the point of removal.
[ "Close", "closes", "the", "file", "and", "then", "removes", "it", "from", "disk", ".", "No", "error", "is", "returned", "if", "the", "file", "did", "not", "exist", "at", "the", "point", "of", "removal", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/image/io.go#L107-L119
20,879
rkt/rkt
rkt/image/io.go
getTmpROC
func getTmpROC(s *imagestore.Store, path string) (*removeOnClose, error) { h := sha512.New() h.Write([]byte(path)) pathHash := s.HashToKey(h) tmp, err := s.TmpNamedFile(pathHash) if err != nil { return nil, errwrap.Wrap(errors.New("error setting up temporary file"), err) } // let's lock the file to avoid concurrent writes to the temporary file, it // will go away when removing the temp file _, err = lock.TryExclusiveLock(tmp.Name(), lock.RegFile) if err != nil { if err != lock.ErrLocked { return nil, errwrap.Wrap(errors.New("failed to lock temporary file"), err) } log.Printf("another rkt instance is downloading this file, waiting...") _, err = lock.ExclusiveLock(tmp.Name(), lock.RegFile) if err != nil { return nil, errwrap.Wrap(errors.New("failed to lock temporary file"), err) } } return &removeOnClose{File: tmp}, nil }
go
func getTmpROC(s *imagestore.Store, path string) (*removeOnClose, error) { h := sha512.New() h.Write([]byte(path)) pathHash := s.HashToKey(h) tmp, err := s.TmpNamedFile(pathHash) if err != nil { return nil, errwrap.Wrap(errors.New("error setting up temporary file"), err) } // let's lock the file to avoid concurrent writes to the temporary file, it // will go away when removing the temp file _, err = lock.TryExclusiveLock(tmp.Name(), lock.RegFile) if err != nil { if err != lock.ErrLocked { return nil, errwrap.Wrap(errors.New("failed to lock temporary file"), err) } log.Printf("another rkt instance is downloading this file, waiting...") _, err = lock.ExclusiveLock(tmp.Name(), lock.RegFile) if err != nil { return nil, errwrap.Wrap(errors.New("failed to lock temporary file"), err) } } return &removeOnClose{File: tmp}, nil }
[ "func", "getTmpROC", "(", "s", "*", "imagestore", ".", "Store", ",", "path", "string", ")", "(", "*", "removeOnClose", ",", "error", ")", "{", "h", ":=", "sha512", ".", "New", "(", ")", "\n", "h", ".", "Write", "(", "[", "]", "byte", "(", "path", ")", ")", "\n", "pathHash", ":=", "s", ".", "HashToKey", "(", "h", ")", "\n\n", "tmp", ",", "err", ":=", "s", ".", "TmpNamedFile", "(", "pathHash", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errwrap", ".", "Wrap", "(", "errors", ".", "New", "(", "\"", "\"", ")", ",", "err", ")", "\n", "}", "\n\n", "// let's lock the file to avoid concurrent writes to the temporary file, it", "// will go away when removing the temp file", "_", ",", "err", "=", "lock", ".", "TryExclusiveLock", "(", "tmp", ".", "Name", "(", ")", ",", "lock", ".", "RegFile", ")", "\n", "if", "err", "!=", "nil", "{", "if", "err", "!=", "lock", ".", "ErrLocked", "{", "return", "nil", ",", "errwrap", ".", "Wrap", "(", "errors", ".", "New", "(", "\"", "\"", ")", ",", "err", ")", "\n", "}", "\n", "log", ".", "Printf", "(", "\"", "\"", ")", "\n", "_", ",", "err", "=", "lock", ".", "ExclusiveLock", "(", "tmp", ".", "Name", "(", ")", ",", "lock", ".", "RegFile", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errwrap", ".", "Wrap", "(", "errors", ".", "New", "(", "\"", "\"", ")", ",", "err", ")", "\n", "}", "\n", "}", "\n\n", "return", "&", "removeOnClose", "{", "File", ":", "tmp", "}", ",", "nil", "\n", "}" ]
// getTmpROC returns a removeOnClose instance wrapping a temporary // file provided by the passed store. The actual file name is based on // a hash of the passed path.
[ "getTmpROC", "returns", "a", "removeOnClose", "instance", "wrapping", "a", "temporary", "file", "provided", "by", "the", "passed", "store", ".", "The", "actual", "file", "name", "is", "based", "on", "a", "hash", "of", "the", "passed", "path", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/image/io.go#L124-L149
20,880
rkt/rkt
stage0/manifest.go
getStage1Entrypoint
func getStage1Entrypoint(cdir string, entrypoint string) (string, error) { b, err := ioutil.ReadFile(common.Stage1ManifestPath(cdir)) if err != nil { return "", errwrap.Wrap(errors.New("error reading pod manifest"), err) } s1m := schema.ImageManifest{} if err := json.Unmarshal(b, &s1m); err != nil { return "", errwrap.Wrap(errors.New("error unmarshaling stage1 manifest"), err) } if ep, ok := s1m.Annotations.Get(entrypoint); ok { return ep, nil } return "", fmt.Errorf("entrypoint %q not found", entrypoint) }
go
func getStage1Entrypoint(cdir string, entrypoint string) (string, error) { b, err := ioutil.ReadFile(common.Stage1ManifestPath(cdir)) if err != nil { return "", errwrap.Wrap(errors.New("error reading pod manifest"), err) } s1m := schema.ImageManifest{} if err := json.Unmarshal(b, &s1m); err != nil { return "", errwrap.Wrap(errors.New("error unmarshaling stage1 manifest"), err) } if ep, ok := s1m.Annotations.Get(entrypoint); ok { return ep, nil } return "", fmt.Errorf("entrypoint %q not found", entrypoint) }
[ "func", "getStage1Entrypoint", "(", "cdir", "string", ",", "entrypoint", "string", ")", "(", "string", ",", "error", ")", "{", "b", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "common", ".", "Stage1ManifestPath", "(", "cdir", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "errwrap", ".", "Wrap", "(", "errors", ".", "New", "(", "\"", "\"", ")", ",", "err", ")", "\n", "}", "\n\n", "s1m", ":=", "schema", ".", "ImageManifest", "{", "}", "\n", "if", "err", ":=", "json", ".", "Unmarshal", "(", "b", ",", "&", "s1m", ")", ";", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "errwrap", ".", "Wrap", "(", "errors", ".", "New", "(", "\"", "\"", ")", ",", "err", ")", "\n", "}", "\n\n", "if", "ep", ",", "ok", ":=", "s1m", ".", "Annotations", ".", "Get", "(", "entrypoint", ")", ";", "ok", "{", "return", "ep", ",", "nil", "\n", "}", "\n\n", "return", "\"", "\"", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "entrypoint", ")", "\n", "}" ]
// getStage1Entrypoint retrieves the named entrypoint from the stage1 manifest for a given pod
[ "getStage1Entrypoint", "retrieves", "the", "named", "entrypoint", "from", "the", "stage1", "manifest", "for", "a", "given", "pod" ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage0/manifest.go#L69-L85
20,881
rkt/rkt
stage0/manifest.go
getStage1InterfaceVersion
func getStage1InterfaceVersion(cdir string) (int, error) { b, err := ioutil.ReadFile(common.Stage1ManifestPath(cdir)) if err != nil { return -1, errwrap.Wrap(errors.New("error reading pod manifest"), err) } s1m := schema.ImageManifest{} if err := json.Unmarshal(b, &s1m); err != nil { return -1, errwrap.Wrap(errors.New("error unmarshaling stage1 manifest"), err) } if iv, ok := s1m.Annotations.Get(interfaceVersion); ok { v, err := strconv.Atoi(iv) if err != nil { return -1, errwrap.Wrap(errors.New("error parsing interface version"), err) } return v, nil } // "interface-version" annotation not found, assume version 1 return 1, nil }
go
func getStage1InterfaceVersion(cdir string) (int, error) { b, err := ioutil.ReadFile(common.Stage1ManifestPath(cdir)) if err != nil { return -1, errwrap.Wrap(errors.New("error reading pod manifest"), err) } s1m := schema.ImageManifest{} if err := json.Unmarshal(b, &s1m); err != nil { return -1, errwrap.Wrap(errors.New("error unmarshaling stage1 manifest"), err) } if iv, ok := s1m.Annotations.Get(interfaceVersion); ok { v, err := strconv.Atoi(iv) if err != nil { return -1, errwrap.Wrap(errors.New("error parsing interface version"), err) } return v, nil } // "interface-version" annotation not found, assume version 1 return 1, nil }
[ "func", "getStage1InterfaceVersion", "(", "cdir", "string", ")", "(", "int", ",", "error", ")", "{", "b", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "common", ".", "Stage1ManifestPath", "(", "cdir", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "-", "1", ",", "errwrap", ".", "Wrap", "(", "errors", ".", "New", "(", "\"", "\"", ")", ",", "err", ")", "\n", "}", "\n\n", "s1m", ":=", "schema", ".", "ImageManifest", "{", "}", "\n", "if", "err", ":=", "json", ".", "Unmarshal", "(", "b", ",", "&", "s1m", ")", ";", "err", "!=", "nil", "{", "return", "-", "1", ",", "errwrap", ".", "Wrap", "(", "errors", ".", "New", "(", "\"", "\"", ")", ",", "err", ")", "\n", "}", "\n\n", "if", "iv", ",", "ok", ":=", "s1m", ".", "Annotations", ".", "Get", "(", "interfaceVersion", ")", ";", "ok", "{", "v", ",", "err", ":=", "strconv", ".", "Atoi", "(", "iv", ")", "\n", "if", "err", "!=", "nil", "{", "return", "-", "1", ",", "errwrap", ".", "Wrap", "(", "errors", ".", "New", "(", "\"", "\"", ")", ",", "err", ")", "\n", "}", "\n", "return", "v", ",", "nil", "\n", "}", "\n\n", "// \"interface-version\" annotation not found, assume version 1", "return", "1", ",", "nil", "\n", "}" ]
// getStage1InterfaceVersion retrieves the interface version from the stage1 // manifest for a given pod
[ "getStage1InterfaceVersion", "retrieves", "the", "interface", "version", "from", "the", "stage1", "manifest", "for", "a", "given", "pod" ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage0/manifest.go#L89-L110
20,882
rkt/rkt
networking/podenv.go
loadNets
func (e *podEnv) loadNets() ([]activeNet, error) { if e.netsLoadList.None() { stderr.Printf("networking namespace with loopback only") return nil, nil } nets, err := e.newNetLoader().loadNets(e.netsLoadList) if err != nil { return nil, err } netSlice := make([]activeNet, 0, len(nets)) for _, net := range nets { netSlice = append(netSlice, net) } sort.Sort(byFilename(netSlice)) missing := missingNets(e.netsLoadList, netSlice) if len(missing) > 0 { return nil, fmt.Errorf("networks not found: %v", strings.Join(missing, ", ")) } // Add the runtime args to the network instances. // We don't do this earlier because we also load networks in other contexts for _, n := range nets { n.runtime.Args = e.netsLoadList.SpecificArgs(n.conf.Name) } return netSlice, nil }
go
func (e *podEnv) loadNets() ([]activeNet, error) { if e.netsLoadList.None() { stderr.Printf("networking namespace with loopback only") return nil, nil } nets, err := e.newNetLoader().loadNets(e.netsLoadList) if err != nil { return nil, err } netSlice := make([]activeNet, 0, len(nets)) for _, net := range nets { netSlice = append(netSlice, net) } sort.Sort(byFilename(netSlice)) missing := missingNets(e.netsLoadList, netSlice) if len(missing) > 0 { return nil, fmt.Errorf("networks not found: %v", strings.Join(missing, ", ")) } // Add the runtime args to the network instances. // We don't do this earlier because we also load networks in other contexts for _, n := range nets { n.runtime.Args = e.netsLoadList.SpecificArgs(n.conf.Name) } return netSlice, nil }
[ "func", "(", "e", "*", "podEnv", ")", "loadNets", "(", ")", "(", "[", "]", "activeNet", ",", "error", ")", "{", "if", "e", ".", "netsLoadList", ".", "None", "(", ")", "{", "stderr", ".", "Printf", "(", "\"", "\"", ")", "\n", "return", "nil", ",", "nil", "\n", "}", "\n\n", "nets", ",", "err", ":=", "e", ".", "newNetLoader", "(", ")", ".", "loadNets", "(", "e", ".", "netsLoadList", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "netSlice", ":=", "make", "(", "[", "]", "activeNet", ",", "0", ",", "len", "(", "nets", ")", ")", "\n", "for", "_", ",", "net", ":=", "range", "nets", "{", "netSlice", "=", "append", "(", "netSlice", ",", "net", ")", "\n", "}", "\n", "sort", ".", "Sort", "(", "byFilename", "(", "netSlice", ")", ")", "\n\n", "missing", ":=", "missingNets", "(", "e", ".", "netsLoadList", ",", "netSlice", ")", "\n", "if", "len", "(", "missing", ")", ">", "0", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "strings", ".", "Join", "(", "missing", ",", "\"", "\"", ")", ")", "\n", "}", "\n\n", "// Add the runtime args to the network instances.", "// We don't do this earlier because we also load networks in other contexts", "for", "_", ",", "n", ":=", "range", "nets", "{", "n", ".", "runtime", ".", "Args", "=", "e", ".", "netsLoadList", ".", "SpecificArgs", "(", "n", ".", "conf", ".", "Name", ")", "\n", "}", "\n", "return", "netSlice", ",", "nil", "\n", "}" ]
// Loads nets specified by user, both from a configurable user location and builtin from stage1. User supplied network // configs override what is built into stage1. // The order in which networks are applied to pods will be defined by their filenames.
[ "Loads", "nets", "specified", "by", "user", "both", "from", "a", "configurable", "user", "location", "and", "builtin", "from", "stage1", ".", "User", "supplied", "network", "configs", "override", "what", "is", "built", "into", "stage1", ".", "The", "order", "in", "which", "networks", "are", "applied", "to", "pods", "will", "be", "defined", "by", "their", "filenames", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/networking/podenv.go#L75-L102
20,883
rkt/rkt
stage1/init/common/app.go
prepareApp
func prepareApp(p *stage1commontypes.Pod, ra *schema.RuntimeApp) (*preparedApp, error) { pa := preparedApp{ app: ra, env: ra.App.Environment, noNewPrivileges: getAppNoNewPrivileges(ra.App.Isolators), } var err error // Determine numeric uid and gid u, g, err := ParseUserGroup(p, ra) if err != nil { return nil, errwrap.Wrap(errors.New("unable to determine app's uid and gid"), err) } if u < 0 || g < 0 { return nil, errors.New("Invalid uid or gid") } pa.uid = uint32(u) pa.gid = uint32(g) // Set some rkt-provided environment variables pa.env.Set("AC_APP_NAME", ra.Name.String()) if p.MetadataServiceURL != "" { pa.env.Set("AC_METADATA_URL", p.MetadataServiceURL) } // Determine capability set pa.capabilities, err = getAppCapabilities(ra.App.Isolators) if err != nil { return nil, errwrap.Wrap(errors.New("unable to construct capabilities"), err) } // Determine mounts cfd := ConvertedFromDocker(p.Images[ra.Name.String()]) pa.mounts, err = GenerateMounts(ra, p.Manifest.Volumes, cfd) if err != nil { return nil, errwrap.Wrap(errors.New("unable to compute mounts"), err) } // Compute resources pa.resources, err = computeAppResources(ra.App.Isolators) if err != nil { return nil, errwrap.Wrap(errors.New("unable to compute resources"), err) } // Protect kernel tunables by default if !p.InsecureOptions.DisablePaths { pa.roPaths = append(pa.roPaths, protectKernelROPaths...) pa.hiddenPaths = append(pa.hiddenDirs, protectKernelHiddenPaths...) pa.hiddenDirs = append(pa.hiddenDirs, protectKernelHiddenDirs...) } // Seccomp if !p.InsecureOptions.DisableSeccomp { pa.seccomp, err = generateSeccompFilter(p, &pa) if err != nil { return nil, err } if pa.seccomp != nil && pa.seccomp.forceNoNewPrivileges { pa.noNewPrivileges = true } } // Write the systemd-sysusers config file if err := generateSysusers(p, pa.app, int(pa.uid), int(pa.gid), &p.UidRange); err != nil { return nil, errwrap.Wrapf("unable to generate sysusers file", err) } return &pa, nil }
go
func prepareApp(p *stage1commontypes.Pod, ra *schema.RuntimeApp) (*preparedApp, error) { pa := preparedApp{ app: ra, env: ra.App.Environment, noNewPrivileges: getAppNoNewPrivileges(ra.App.Isolators), } var err error // Determine numeric uid and gid u, g, err := ParseUserGroup(p, ra) if err != nil { return nil, errwrap.Wrap(errors.New("unable to determine app's uid and gid"), err) } if u < 0 || g < 0 { return nil, errors.New("Invalid uid or gid") } pa.uid = uint32(u) pa.gid = uint32(g) // Set some rkt-provided environment variables pa.env.Set("AC_APP_NAME", ra.Name.String()) if p.MetadataServiceURL != "" { pa.env.Set("AC_METADATA_URL", p.MetadataServiceURL) } // Determine capability set pa.capabilities, err = getAppCapabilities(ra.App.Isolators) if err != nil { return nil, errwrap.Wrap(errors.New("unable to construct capabilities"), err) } // Determine mounts cfd := ConvertedFromDocker(p.Images[ra.Name.String()]) pa.mounts, err = GenerateMounts(ra, p.Manifest.Volumes, cfd) if err != nil { return nil, errwrap.Wrap(errors.New("unable to compute mounts"), err) } // Compute resources pa.resources, err = computeAppResources(ra.App.Isolators) if err != nil { return nil, errwrap.Wrap(errors.New("unable to compute resources"), err) } // Protect kernel tunables by default if !p.InsecureOptions.DisablePaths { pa.roPaths = append(pa.roPaths, protectKernelROPaths...) pa.hiddenPaths = append(pa.hiddenDirs, protectKernelHiddenPaths...) pa.hiddenDirs = append(pa.hiddenDirs, protectKernelHiddenDirs...) } // Seccomp if !p.InsecureOptions.DisableSeccomp { pa.seccomp, err = generateSeccompFilter(p, &pa) if err != nil { return nil, err } if pa.seccomp != nil && pa.seccomp.forceNoNewPrivileges { pa.noNewPrivileges = true } } // Write the systemd-sysusers config file if err := generateSysusers(p, pa.app, int(pa.uid), int(pa.gid), &p.UidRange); err != nil { return nil, errwrap.Wrapf("unable to generate sysusers file", err) } return &pa, nil }
[ "func", "prepareApp", "(", "p", "*", "stage1commontypes", ".", "Pod", ",", "ra", "*", "schema", ".", "RuntimeApp", ")", "(", "*", "preparedApp", ",", "error", ")", "{", "pa", ":=", "preparedApp", "{", "app", ":", "ra", ",", "env", ":", "ra", ".", "App", ".", "Environment", ",", "noNewPrivileges", ":", "getAppNoNewPrivileges", "(", "ra", ".", "App", ".", "Isolators", ")", ",", "}", "\n", "var", "err", "error", "\n\n", "// Determine numeric uid and gid", "u", ",", "g", ",", "err", ":=", "ParseUserGroup", "(", "p", ",", "ra", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errwrap", ".", "Wrap", "(", "errors", ".", "New", "(", "\"", "\"", ")", ",", "err", ")", "\n", "}", "\n", "if", "u", "<", "0", "||", "g", "<", "0", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "pa", ".", "uid", "=", "uint32", "(", "u", ")", "\n", "pa", ".", "gid", "=", "uint32", "(", "g", ")", "\n\n", "// Set some rkt-provided environment variables", "pa", ".", "env", ".", "Set", "(", "\"", "\"", ",", "ra", ".", "Name", ".", "String", "(", ")", ")", "\n", "if", "p", ".", "MetadataServiceURL", "!=", "\"", "\"", "{", "pa", ".", "env", ".", "Set", "(", "\"", "\"", ",", "p", ".", "MetadataServiceURL", ")", "\n", "}", "\n\n", "// Determine capability set", "pa", ".", "capabilities", ",", "err", "=", "getAppCapabilities", "(", "ra", ".", "App", ".", "Isolators", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errwrap", ".", "Wrap", "(", "errors", ".", "New", "(", "\"", "\"", ")", ",", "err", ")", "\n", "}", "\n\n", "// Determine mounts", "cfd", ":=", "ConvertedFromDocker", "(", "p", ".", "Images", "[", "ra", ".", "Name", ".", "String", "(", ")", "]", ")", "\n", "pa", ".", "mounts", ",", "err", "=", "GenerateMounts", "(", "ra", ",", "p", ".", "Manifest", ".", "Volumes", ",", "cfd", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errwrap", ".", "Wrap", "(", "errors", ".", "New", "(", "\"", "\"", ")", ",", "err", ")", "\n", "}", "\n\n", "// Compute resources", "pa", ".", "resources", ",", "err", "=", "computeAppResources", "(", "ra", ".", "App", ".", "Isolators", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errwrap", ".", "Wrap", "(", "errors", ".", "New", "(", "\"", "\"", ")", ",", "err", ")", "\n", "}", "\n\n", "// Protect kernel tunables by default", "if", "!", "p", ".", "InsecureOptions", ".", "DisablePaths", "{", "pa", ".", "roPaths", "=", "append", "(", "pa", ".", "roPaths", ",", "protectKernelROPaths", "...", ")", "\n", "pa", ".", "hiddenPaths", "=", "append", "(", "pa", ".", "hiddenDirs", ",", "protectKernelHiddenPaths", "...", ")", "\n", "pa", ".", "hiddenDirs", "=", "append", "(", "pa", ".", "hiddenDirs", ",", "protectKernelHiddenDirs", "...", ")", "\n", "}", "\n\n", "// Seccomp", "if", "!", "p", ".", "InsecureOptions", ".", "DisableSeccomp", "{", "pa", ".", "seccomp", ",", "err", "=", "generateSeccompFilter", "(", "p", ",", "&", "pa", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "pa", ".", "seccomp", "!=", "nil", "&&", "pa", ".", "seccomp", ".", "forceNoNewPrivileges", "{", "pa", ".", "noNewPrivileges", "=", "true", "\n", "}", "\n", "}", "\n\n", "// Write the systemd-sysusers config file", "if", "err", ":=", "generateSysusers", "(", "p", ",", "pa", ".", "app", ",", "int", "(", "pa", ".", "uid", ")", ",", "int", "(", "pa", ".", "gid", ")", ",", "&", "p", ".", "UidRange", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "errwrap", ".", "Wrapf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "return", "&", "pa", ",", "nil", "\n", "}" ]
// prepareApp sets up the internal runtime context for a specific app.
[ "prepareApp", "sets", "up", "the", "internal", "runtime", "context", "for", "a", "specific", "app", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/init/common/app.go#L98-L166
20,884
rkt/rkt
stage1/init/common/app.go
computeAppResources
func computeAppResources(isolators types.Isolators) (appResources, error) { res := appResources{} var err error withIsolator := func(name string, f func() error) error { ok, err := cgroup.IsIsolatorSupported(name) if err != nil { return errwrap.Wrapf("could not check for isolator "+name, err) } if !ok { fmt.Fprintf(os.Stderr, "warning: resource/%s isolator set but support disabled in the kernel, skipping\n", name) return nil } return f() } for _, isolator := range isolators { if err != nil { return res, err } switch v := isolator.Value().(type) { case *types.ResourceMemory: err = withIsolator("memory", func() error { if v.Limit() == nil { return nil } val := uint64(v.Limit().Value()) res.MemoryLimit = &val return nil }) case *types.ResourceCPU: err = withIsolator("cpu", func() error { if v.Limit() == nil { return nil } if v.Limit().Value() > MaxMilliValue { return fmt.Errorf("cpu limit exceeds the maximum millivalue: %v", v.Limit().String()) } val := uint64(v.Limit().MilliValue() / 10) res.CPUQuota = &val return nil }) case *types.LinuxCPUShares: err = withIsolator("cpu", func() error { val := uint64(*v) res.LinuxCPUShares = &val return nil }) case *types.LinuxOOMScoreAdj: val := int(*v) res.LinuxOOMScoreAdjust = &val } } return res, err }
go
func computeAppResources(isolators types.Isolators) (appResources, error) { res := appResources{} var err error withIsolator := func(name string, f func() error) error { ok, err := cgroup.IsIsolatorSupported(name) if err != nil { return errwrap.Wrapf("could not check for isolator "+name, err) } if !ok { fmt.Fprintf(os.Stderr, "warning: resource/%s isolator set but support disabled in the kernel, skipping\n", name) return nil } return f() } for _, isolator := range isolators { if err != nil { return res, err } switch v := isolator.Value().(type) { case *types.ResourceMemory: err = withIsolator("memory", func() error { if v.Limit() == nil { return nil } val := uint64(v.Limit().Value()) res.MemoryLimit = &val return nil }) case *types.ResourceCPU: err = withIsolator("cpu", func() error { if v.Limit() == nil { return nil } if v.Limit().Value() > MaxMilliValue { return fmt.Errorf("cpu limit exceeds the maximum millivalue: %v", v.Limit().String()) } val := uint64(v.Limit().MilliValue() / 10) res.CPUQuota = &val return nil }) case *types.LinuxCPUShares: err = withIsolator("cpu", func() error { val := uint64(*v) res.LinuxCPUShares = &val return nil }) case *types.LinuxOOMScoreAdj: val := int(*v) res.LinuxOOMScoreAdjust = &val } } return res, err }
[ "func", "computeAppResources", "(", "isolators", "types", ".", "Isolators", ")", "(", "appResources", ",", "error", ")", "{", "res", ":=", "appResources", "{", "}", "\n", "var", "err", "error", "\n\n", "withIsolator", ":=", "func", "(", "name", "string", ",", "f", "func", "(", ")", "error", ")", "error", "{", "ok", ",", "err", ":=", "cgroup", ".", "IsIsolatorSupported", "(", "name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errwrap", ".", "Wrapf", "(", "\"", "\"", "+", "name", ",", "err", ")", "\n", "}", "\n\n", "if", "!", "ok", "{", "fmt", ".", "Fprintf", "(", "os", ".", "Stderr", ",", "\"", "\\n", "\"", ",", "name", ")", "\n", "return", "nil", "\n", "}", "\n\n", "return", "f", "(", ")", "\n", "}", "\n\n", "for", "_", ",", "isolator", ":=", "range", "isolators", "{", "if", "err", "!=", "nil", "{", "return", "res", ",", "err", "\n", "}", "\n\n", "switch", "v", ":=", "isolator", ".", "Value", "(", ")", ".", "(", "type", ")", "{", "case", "*", "types", ".", "ResourceMemory", ":", "err", "=", "withIsolator", "(", "\"", "\"", ",", "func", "(", ")", "error", "{", "if", "v", ".", "Limit", "(", ")", "==", "nil", "{", "return", "nil", "\n", "}", "\n\n", "val", ":=", "uint64", "(", "v", ".", "Limit", "(", ")", ".", "Value", "(", ")", ")", "\n", "res", ".", "MemoryLimit", "=", "&", "val", "\n", "return", "nil", "\n", "}", ")", "\n", "case", "*", "types", ".", "ResourceCPU", ":", "err", "=", "withIsolator", "(", "\"", "\"", ",", "func", "(", ")", "error", "{", "if", "v", ".", "Limit", "(", ")", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "if", "v", ".", "Limit", "(", ")", ".", "Value", "(", ")", ">", "MaxMilliValue", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "v", ".", "Limit", "(", ")", ".", "String", "(", ")", ")", "\n", "}", "\n\n", "val", ":=", "uint64", "(", "v", ".", "Limit", "(", ")", ".", "MilliValue", "(", ")", "/", "10", ")", "\n", "res", ".", "CPUQuota", "=", "&", "val", "\n", "return", "nil", "\n", "}", ")", "\n", "case", "*", "types", ".", "LinuxCPUShares", ":", "err", "=", "withIsolator", "(", "\"", "\"", ",", "func", "(", ")", "error", "{", "val", ":=", "uint64", "(", "*", "v", ")", "\n", "res", ".", "LinuxCPUShares", "=", "&", "val", "\n", "return", "nil", "\n", "}", ")", "\n", "case", "*", "types", ".", "LinuxOOMScoreAdj", ":", "val", ":=", "int", "(", "*", "v", ")", "\n", "res", ".", "LinuxOOMScoreAdjust", "=", "&", "val", "\n", "}", "\n", "}", "\n\n", "return", "res", ",", "err", "\n", "}" ]
// computeAppResources processes any isolators that manipulate cgroups.
[ "computeAppResources", "processes", "any", "isolators", "that", "manipulate", "cgroups", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/init/common/app.go#L169-L229
20,885
rkt/rkt
store/imagestore/aciinfo.go
GetACIInfosWithKeyPrefix
func GetACIInfosWithKeyPrefix(tx *sql.Tx, prefix string) ([]*ACIInfo, error) { var aciinfos []*ACIInfo rows, err := tx.Query("SELECT * from aciinfo WHERE hasPrefix(blobkey, $1)", prefix) if err != nil { return nil, err } defer rows.Close() for rows.Next() { aciinfo := &ACIInfo{} if err := aciinfoRowScan(rows, aciinfo); err != nil { return nil, err } aciinfos = append(aciinfos, aciinfo) } if err := rows.Err(); err != nil { return nil, err } return aciinfos, err }
go
func GetACIInfosWithKeyPrefix(tx *sql.Tx, prefix string) ([]*ACIInfo, error) { var aciinfos []*ACIInfo rows, err := tx.Query("SELECT * from aciinfo WHERE hasPrefix(blobkey, $1)", prefix) if err != nil { return nil, err } defer rows.Close() for rows.Next() { aciinfo := &ACIInfo{} if err := aciinfoRowScan(rows, aciinfo); err != nil { return nil, err } aciinfos = append(aciinfos, aciinfo) } if err := rows.Err(); err != nil { return nil, err } return aciinfos, err }
[ "func", "GetACIInfosWithKeyPrefix", "(", "tx", "*", "sql", ".", "Tx", ",", "prefix", "string", ")", "(", "[", "]", "*", "ACIInfo", ",", "error", ")", "{", "var", "aciinfos", "[", "]", "*", "ACIInfo", "\n", "rows", ",", "err", ":=", "tx", ".", "Query", "(", "\"", "\"", ",", "prefix", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "defer", "rows", ".", "Close", "(", ")", "\n", "for", "rows", ".", "Next", "(", ")", "{", "aciinfo", ":=", "&", "ACIInfo", "{", "}", "\n", "if", "err", ":=", "aciinfoRowScan", "(", "rows", ",", "aciinfo", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "aciinfos", "=", "append", "(", "aciinfos", ",", "aciinfo", ")", "\n", "}", "\n", "if", "err", ":=", "rows", ".", "Err", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "aciinfos", ",", "err", "\n", "}" ]
// GetAciInfosWithKeyPrefix returns all the ACIInfos with a blobkey starting with the given prefix.
[ "GetAciInfosWithKeyPrefix", "returns", "all", "the", "ACIInfos", "with", "a", "blobkey", "starting", "with", "the", "given", "prefix", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/store/imagestore/aciinfo.go#L68-L86
20,886
rkt/rkt
store/imagestore/aciinfo.go
GetACIInfosWithName
func GetACIInfosWithName(tx *sql.Tx, name string) ([]*ACIInfo, bool, error) { var aciinfos []*ACIInfo found := false rows, err := tx.Query("SELECT * from aciinfo WHERE name == $1", name) if err != nil { return nil, false, err } defer rows.Close() for rows.Next() { found = true aciinfo := &ACIInfo{} if err := aciinfoRowScan(rows, aciinfo); err != nil { return nil, false, err } aciinfos = append(aciinfos, aciinfo) } if err := rows.Err(); err != nil { return nil, false, err } return aciinfos, found, err }
go
func GetACIInfosWithName(tx *sql.Tx, name string) ([]*ACIInfo, bool, error) { var aciinfos []*ACIInfo found := false rows, err := tx.Query("SELECT * from aciinfo WHERE name == $1", name) if err != nil { return nil, false, err } defer rows.Close() for rows.Next() { found = true aciinfo := &ACIInfo{} if err := aciinfoRowScan(rows, aciinfo); err != nil { return nil, false, err } aciinfos = append(aciinfos, aciinfo) } if err := rows.Err(); err != nil { return nil, false, err } return aciinfos, found, err }
[ "func", "GetACIInfosWithName", "(", "tx", "*", "sql", ".", "Tx", ",", "name", "string", ")", "(", "[", "]", "*", "ACIInfo", ",", "bool", ",", "error", ")", "{", "var", "aciinfos", "[", "]", "*", "ACIInfo", "\n", "found", ":=", "false", "\n", "rows", ",", "err", ":=", "tx", ".", "Query", "(", "\"", "\"", ",", "name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "false", ",", "err", "\n", "}", "\n", "defer", "rows", ".", "Close", "(", ")", "\n", "for", "rows", ".", "Next", "(", ")", "{", "found", "=", "true", "\n", "aciinfo", ":=", "&", "ACIInfo", "{", "}", "\n", "if", "err", ":=", "aciinfoRowScan", "(", "rows", ",", "aciinfo", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "false", ",", "err", "\n", "}", "\n", "aciinfos", "=", "append", "(", "aciinfos", ",", "aciinfo", ")", "\n", "}", "\n", "if", "err", ":=", "rows", ".", "Err", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "false", ",", "err", "\n", "}", "\n", "return", "aciinfos", ",", "found", ",", "err", "\n", "}" ]
// GetAciInfosWithName returns all the ACIInfos for a given name. found will be // false if no aciinfo exists.
[ "GetAciInfosWithName", "returns", "all", "the", "ACIInfos", "for", "a", "given", "name", ".", "found", "will", "be", "false", "if", "no", "aciinfo", "exists", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/store/imagestore/aciinfo.go#L90-L110
20,887
rkt/rkt
store/imagestore/aciinfo.go
GetACIInfoWithBlobKey
func GetACIInfoWithBlobKey(tx *sql.Tx, blobKey string) (*ACIInfo, bool, error) { aciinfo := &ACIInfo{} found := false rows, err := tx.Query("SELECT * from aciinfo WHERE blobkey == $1", blobKey) if err != nil { return nil, false, err } defer rows.Close() for rows.Next() { found = true if err := aciinfoRowScan(rows, aciinfo); err != nil { return nil, false, err } // No more than one row for blobkey must exist. break } if err := rows.Err(); err != nil { return nil, false, err } return aciinfo, found, err }
go
func GetACIInfoWithBlobKey(tx *sql.Tx, blobKey string) (*ACIInfo, bool, error) { aciinfo := &ACIInfo{} found := false rows, err := tx.Query("SELECT * from aciinfo WHERE blobkey == $1", blobKey) if err != nil { return nil, false, err } defer rows.Close() for rows.Next() { found = true if err := aciinfoRowScan(rows, aciinfo); err != nil { return nil, false, err } // No more than one row for blobkey must exist. break } if err := rows.Err(); err != nil { return nil, false, err } return aciinfo, found, err }
[ "func", "GetACIInfoWithBlobKey", "(", "tx", "*", "sql", ".", "Tx", ",", "blobKey", "string", ")", "(", "*", "ACIInfo", ",", "bool", ",", "error", ")", "{", "aciinfo", ":=", "&", "ACIInfo", "{", "}", "\n", "found", ":=", "false", "\n", "rows", ",", "err", ":=", "tx", ".", "Query", "(", "\"", "\"", ",", "blobKey", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "false", ",", "err", "\n", "}", "\n", "defer", "rows", ".", "Close", "(", ")", "\n", "for", "rows", ".", "Next", "(", ")", "{", "found", "=", "true", "\n", "if", "err", ":=", "aciinfoRowScan", "(", "rows", ",", "aciinfo", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "false", ",", "err", "\n", "}", "\n", "// No more than one row for blobkey must exist.", "break", "\n", "}", "\n", "if", "err", ":=", "rows", ".", "Err", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "false", ",", "err", "\n", "}", "\n", "return", "aciinfo", ",", "found", ",", "err", "\n", "}" ]
// GetAciInfosWithBlobKey returns the ACIInfo with the given blobKey. found will be // false if no aciinfo exists.
[ "GetAciInfosWithBlobKey", "returns", "the", "ACIInfo", "with", "the", "given", "blobKey", ".", "found", "will", "be", "false", "if", "no", "aciinfo", "exists", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/store/imagestore/aciinfo.go#L114-L134
20,888
rkt/rkt
store/imagestore/aciinfo.go
GetAllACIInfos
func GetAllACIInfos(tx *sql.Tx, sortfields []string, ascending bool) ([]*ACIInfo, error) { var aciinfos []*ACIInfo query := "SELECT * from aciinfo" if len(sortfields) > 0 { query += fmt.Sprintf(" ORDER BY %s ", strings.Join(sortfields, ", ")) if ascending { query += "ASC" } else { query += "DESC" } } rows, err := tx.Query(query) if err != nil { return nil, err } defer rows.Close() for rows.Next() { aciinfo := &ACIInfo{} if err := aciinfoRowScan(rows, aciinfo); err != nil { return nil, err } aciinfos = append(aciinfos, aciinfo) } if err := rows.Err(); err != nil { return nil, err } return aciinfos, err }
go
func GetAllACIInfos(tx *sql.Tx, sortfields []string, ascending bool) ([]*ACIInfo, error) { var aciinfos []*ACIInfo query := "SELECT * from aciinfo" if len(sortfields) > 0 { query += fmt.Sprintf(" ORDER BY %s ", strings.Join(sortfields, ", ")) if ascending { query += "ASC" } else { query += "DESC" } } rows, err := tx.Query(query) if err != nil { return nil, err } defer rows.Close() for rows.Next() { aciinfo := &ACIInfo{} if err := aciinfoRowScan(rows, aciinfo); err != nil { return nil, err } aciinfos = append(aciinfos, aciinfo) } if err := rows.Err(); err != nil { return nil, err } return aciinfos, err }
[ "func", "GetAllACIInfos", "(", "tx", "*", "sql", ".", "Tx", ",", "sortfields", "[", "]", "string", ",", "ascending", "bool", ")", "(", "[", "]", "*", "ACIInfo", ",", "error", ")", "{", "var", "aciinfos", "[", "]", "*", "ACIInfo", "\n", "query", ":=", "\"", "\"", "\n", "if", "len", "(", "sortfields", ")", ">", "0", "{", "query", "+=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "strings", ".", "Join", "(", "sortfields", ",", "\"", "\"", ")", ")", "\n", "if", "ascending", "{", "query", "+=", "\"", "\"", "\n", "}", "else", "{", "query", "+=", "\"", "\"", "\n", "}", "\n", "}", "\n", "rows", ",", "err", ":=", "tx", ".", "Query", "(", "query", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "defer", "rows", ".", "Close", "(", ")", "\n", "for", "rows", ".", "Next", "(", ")", "{", "aciinfo", ":=", "&", "ACIInfo", "{", "}", "\n", "if", "err", ":=", "aciinfoRowScan", "(", "rows", ",", "aciinfo", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "aciinfos", "=", "append", "(", "aciinfos", ",", "aciinfo", ")", "\n", "}", "\n", "if", "err", ":=", "rows", ".", "Err", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "aciinfos", ",", "err", "\n", "}" ]
// GetAllACIInfos returns all the ACIInfos sorted by optional sortfields and // with ascending or descending order.
[ "GetAllACIInfos", "returns", "all", "the", "ACIInfos", "sorted", "by", "optional", "sortfields", "and", "with", "ascending", "or", "descending", "order", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/store/imagestore/aciinfo.go#L138-L165
20,889
rkt/rkt
store/imagestore/aciinfo.go
WriteACIInfo
func WriteACIInfo(tx *sql.Tx, aciinfo *ACIInfo) error { // ql doesn't have an INSERT OR UPDATE function so // it's faster to remove and reinsert the row _, err := tx.Exec("DELETE from aciinfo where blobkey == $1", aciinfo.BlobKey) if err != nil { return err } _, err = tx.Exec("INSERT into aciinfo (blobkey, name, importtime, lastused, latest, size, treestoresize) VALUES ($1, $2, $3, $4, $5, $6, $7)", aciinfo.BlobKey, aciinfo.Name, aciinfo.ImportTime, aciinfo.LastUsed, aciinfo.Latest, aciinfo.Size, aciinfo.TreeStoreSize) if err != nil { return err } return nil }
go
func WriteACIInfo(tx *sql.Tx, aciinfo *ACIInfo) error { // ql doesn't have an INSERT OR UPDATE function so // it's faster to remove and reinsert the row _, err := tx.Exec("DELETE from aciinfo where blobkey == $1", aciinfo.BlobKey) if err != nil { return err } _, err = tx.Exec("INSERT into aciinfo (blobkey, name, importtime, lastused, latest, size, treestoresize) VALUES ($1, $2, $3, $4, $5, $6, $7)", aciinfo.BlobKey, aciinfo.Name, aciinfo.ImportTime, aciinfo.LastUsed, aciinfo.Latest, aciinfo.Size, aciinfo.TreeStoreSize) if err != nil { return err } return nil }
[ "func", "WriteACIInfo", "(", "tx", "*", "sql", ".", "Tx", ",", "aciinfo", "*", "ACIInfo", ")", "error", "{", "// ql doesn't have an INSERT OR UPDATE function so", "// it's faster to remove and reinsert the row", "_", ",", "err", ":=", "tx", ".", "Exec", "(", "\"", "\"", ",", "aciinfo", ".", "BlobKey", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "_", ",", "err", "=", "tx", ".", "Exec", "(", "\"", "\"", ",", "aciinfo", ".", "BlobKey", ",", "aciinfo", ".", "Name", ",", "aciinfo", ".", "ImportTime", ",", "aciinfo", ".", "LastUsed", ",", "aciinfo", ".", "Latest", ",", "aciinfo", ".", "Size", ",", "aciinfo", ".", "TreeStoreSize", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// WriteACIInfo adds or updates the provided aciinfo.
[ "WriteACIInfo", "adds", "or", "updates", "the", "provided", "aciinfo", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/store/imagestore/aciinfo.go#L168-L181
20,890
rkt/rkt
stage1/init/kvm/hypervisor/hvqemu/qemu_driver.go
StartCmd
func StartCmd(wdPath, name, kernelPath string, nds []kvm.NetDescriber, cpu, mem int64, debug bool) []string { var ( driverConfiguration = hypervisor.KvmHypervisor{ Bin: "./qemu", KernelParams: []string{ "root=/dev/root", "rootfstype=9p", "rootflags=trans=virtio,version=9p2000.L,cache=mmap", "rw", "systemd.default_standard_error=journal+console", "systemd.default_standard_output=journal+console", }, } ) driverConfiguration.InitKernelParams(debug) cmd := []string{ filepath.Join(wdPath, driverConfiguration.Bin), "-L", wdPath, "-no-reboot", "-display", "none", "-enable-kvm", "-smp", strconv.FormatInt(cpu, 10), "-m", strconv.FormatInt(mem, 10), "-kernel", kernelPath, "-fsdev", "local,id=root,path=stage1/rootfs,security_model=none", "-device", "virtio-9p-pci,fsdev=root,mount_tag=/dev/root", "-append", fmt.Sprintf("%s", strings.Join(driverConfiguration.KernelParams, " ")), "-chardev", "stdio,id=virtiocon0,signal=off", "-device", "virtio-serial", "-device", "virtconsole,chardev=virtiocon0", } return append(cmd, kvmNetArgs(nds)...) }
go
func StartCmd(wdPath, name, kernelPath string, nds []kvm.NetDescriber, cpu, mem int64, debug bool) []string { var ( driverConfiguration = hypervisor.KvmHypervisor{ Bin: "./qemu", KernelParams: []string{ "root=/dev/root", "rootfstype=9p", "rootflags=trans=virtio,version=9p2000.L,cache=mmap", "rw", "systemd.default_standard_error=journal+console", "systemd.default_standard_output=journal+console", }, } ) driverConfiguration.InitKernelParams(debug) cmd := []string{ filepath.Join(wdPath, driverConfiguration.Bin), "-L", wdPath, "-no-reboot", "-display", "none", "-enable-kvm", "-smp", strconv.FormatInt(cpu, 10), "-m", strconv.FormatInt(mem, 10), "-kernel", kernelPath, "-fsdev", "local,id=root,path=stage1/rootfs,security_model=none", "-device", "virtio-9p-pci,fsdev=root,mount_tag=/dev/root", "-append", fmt.Sprintf("%s", strings.Join(driverConfiguration.KernelParams, " ")), "-chardev", "stdio,id=virtiocon0,signal=off", "-device", "virtio-serial", "-device", "virtconsole,chardev=virtiocon0", } return append(cmd, kvmNetArgs(nds)...) }
[ "func", "StartCmd", "(", "wdPath", ",", "name", ",", "kernelPath", "string", ",", "nds", "[", "]", "kvm", ".", "NetDescriber", ",", "cpu", ",", "mem", "int64", ",", "debug", "bool", ")", "[", "]", "string", "{", "var", "(", "driverConfiguration", "=", "hypervisor", ".", "KvmHypervisor", "{", "Bin", ":", "\"", "\"", ",", "KernelParams", ":", "[", "]", "string", "{", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "}", ",", "}", "\n", ")", "\n\n", "driverConfiguration", ".", "InitKernelParams", "(", "debug", ")", "\n\n", "cmd", ":=", "[", "]", "string", "{", "filepath", ".", "Join", "(", "wdPath", ",", "driverConfiguration", ".", "Bin", ")", ",", "\"", "\"", ",", "wdPath", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "strconv", ".", "FormatInt", "(", "cpu", ",", "10", ")", ",", "\"", "\"", ",", "strconv", ".", "FormatInt", "(", "mem", ",", "10", ")", ",", "\"", "\"", ",", "kernelPath", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "strings", ".", "Join", "(", "driverConfiguration", ".", "KernelParams", ",", "\"", "\"", ")", ")", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "}", "\n", "return", "append", "(", "cmd", ",", "kvmNetArgs", "(", "nds", ")", "...", ")", "\n", "}" ]
// StartCmd takes path to stage1, name of the machine, path to kernel, network describers, memory in megabytes // and quantity of cpus and prepares command line to run QEMU process
[ "StartCmd", "takes", "path", "to", "stage1", "name", "of", "the", "machine", "path", "to", "kernel", "network", "describers", "memory", "in", "megabytes", "and", "quantity", "of", "cpus", "and", "prepares", "command", "line", "to", "run", "QEMU", "process" ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/init/kvm/hypervisor/hvqemu/qemu_driver.go#L29-L63
20,891
rkt/rkt
stage1/init/kvm/hypervisor/hvqemu/qemu_driver.go
kvmNetArgs
func kvmNetArgs(nds []kvm.NetDescriber) []string { var qemuArgs []string for _, nd := range nds { qemuArgs = append(qemuArgs, []string{"-net", "nic,model=virtio"}...) qemuNic := fmt.Sprintf("tap,ifname=%s,script=no,downscript=no,vhost=on", nd.IfName()) qemuArgs = append(qemuArgs, []string{"-net", qemuNic}...) } return qemuArgs }
go
func kvmNetArgs(nds []kvm.NetDescriber) []string { var qemuArgs []string for _, nd := range nds { qemuArgs = append(qemuArgs, []string{"-net", "nic,model=virtio"}...) qemuNic := fmt.Sprintf("tap,ifname=%s,script=no,downscript=no,vhost=on", nd.IfName()) qemuArgs = append(qemuArgs, []string{"-net", qemuNic}...) } return qemuArgs }
[ "func", "kvmNetArgs", "(", "nds", "[", "]", "kvm", ".", "NetDescriber", ")", "[", "]", "string", "{", "var", "qemuArgs", "[", "]", "string", "\n\n", "for", "_", ",", "nd", ":=", "range", "nds", "{", "qemuArgs", "=", "append", "(", "qemuArgs", ",", "[", "]", "string", "{", "\"", "\"", ",", "\"", "\"", "}", "...", ")", "\n", "qemuNic", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "nd", ".", "IfName", "(", ")", ")", "\n", "qemuArgs", "=", "append", "(", "qemuArgs", ",", "[", "]", "string", "{", "\"", "\"", ",", "qemuNic", "}", "...", ")", "\n", "}", "\n\n", "return", "qemuArgs", "\n", "}" ]
// kvmNetArgs returns additional arguments that need to be passed // to qemu to configure networks properly. Logic is based on // network configuration extracted from Networking struct // and essentially from activeNets that expose NetDescriber behavior
[ "kvmNetArgs", "returns", "additional", "arguments", "that", "need", "to", "be", "passed", "to", "qemu", "to", "configure", "networks", "properly", ".", "Logic", "is", "based", "on", "network", "configuration", "extracted", "from", "Networking", "struct", "and", "essentially", "from", "activeNets", "that", "expose", "NetDescriber", "behavior" ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/init/kvm/hypervisor/hvqemu/qemu_driver.go#L69-L79
20,892
rkt/rkt
stage1/init/kvm/hypervisor/hypervisor.go
InitKernelParams
func (hv *KvmHypervisor) InitKernelParams(isDebug bool) { hv.KernelParams = append(hv.KernelParams, []string{ "console=hvc0", "init=/usr/lib/systemd/systemd", "no_timer_check", "noreplace-smp", "tsc=reliable"}...) if isDebug { hv.KernelParams = append(hv.KernelParams, []string{ "debug", "systemd.log_level=debug", "systemd.show_status=true", }...) } else { hv.KernelParams = append(hv.KernelParams, []string{ "systemd.show_status=false", "systemd.log_target=null", "rd.udev.log-priority=3", "quiet=vga", "quiet systemd.log_level=emerg", }...) } customKernelParams := os.Getenv("RKT_HYPERVISOR_EXTRA_KERNEL_PARAMS") if customKernelParams != "" { hv.KernelParams = append(hv.KernelParams, customKernelParams) } }
go
func (hv *KvmHypervisor) InitKernelParams(isDebug bool) { hv.KernelParams = append(hv.KernelParams, []string{ "console=hvc0", "init=/usr/lib/systemd/systemd", "no_timer_check", "noreplace-smp", "tsc=reliable"}...) if isDebug { hv.KernelParams = append(hv.KernelParams, []string{ "debug", "systemd.log_level=debug", "systemd.show_status=true", }...) } else { hv.KernelParams = append(hv.KernelParams, []string{ "systemd.show_status=false", "systemd.log_target=null", "rd.udev.log-priority=3", "quiet=vga", "quiet systemd.log_level=emerg", }...) } customKernelParams := os.Getenv("RKT_HYPERVISOR_EXTRA_KERNEL_PARAMS") if customKernelParams != "" { hv.KernelParams = append(hv.KernelParams, customKernelParams) } }
[ "func", "(", "hv", "*", "KvmHypervisor", ")", "InitKernelParams", "(", "isDebug", "bool", ")", "{", "hv", ".", "KernelParams", "=", "append", "(", "hv", ".", "KernelParams", ",", "[", "]", "string", "{", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", "}", "...", ")", "\n\n", "if", "isDebug", "{", "hv", ".", "KernelParams", "=", "append", "(", "hv", ".", "KernelParams", ",", "[", "]", "string", "{", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "}", "...", ")", "\n", "}", "else", "{", "hv", ".", "KernelParams", "=", "append", "(", "hv", ".", "KernelParams", ",", "[", "]", "string", "{", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "}", "...", ")", "\n", "}", "\n\n", "customKernelParams", ":=", "os", ".", "Getenv", "(", "\"", "\"", ")", "\n", "if", "customKernelParams", "!=", "\"", "\"", "{", "hv", ".", "KernelParams", "=", "append", "(", "hv", ".", "KernelParams", ",", "customKernelParams", ")", "\n", "}", "\n", "}" ]
// InitKernelParams sets debug and common parameters passed to the kernel
[ "InitKernelParams", "sets", "debug", "and", "common", "parameters", "passed", "to", "the", "kernel" ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/init/kvm/hypervisor/hypervisor.go#L26-L54
20,893
rkt/rkt
rkt/image/dockerfetcher.go
Hash
func (f *dockerFetcher) Hash(u *url.URL) (string, error) { ensureLogger(f.Debug) dockerURL, err := d2acommon.ParseDockerURL(path.Join(u.Host, u.Path)) if err != nil { return "", fmt.Errorf(`invalid docker URL %q; expected syntax is "docker://[REGISTRY_HOST[:REGISTRY_PORT]/]IMAGE_NAME[:TAG]"`, u) } latest := dockerURL.Tag == "latest" return f.fetchImageFrom(u, latest) }
go
func (f *dockerFetcher) Hash(u *url.URL) (string, error) { ensureLogger(f.Debug) dockerURL, err := d2acommon.ParseDockerURL(path.Join(u.Host, u.Path)) if err != nil { return "", fmt.Errorf(`invalid docker URL %q; expected syntax is "docker://[REGISTRY_HOST[:REGISTRY_PORT]/]IMAGE_NAME[:TAG]"`, u) } latest := dockerURL.Tag == "latest" return f.fetchImageFrom(u, latest) }
[ "func", "(", "f", "*", "dockerFetcher", ")", "Hash", "(", "u", "*", "url", ".", "URL", ")", "(", "string", ",", "error", ")", "{", "ensureLogger", "(", "f", ".", "Debug", ")", "\n", "dockerURL", ",", "err", ":=", "d2acommon", ".", "ParseDockerURL", "(", "path", ".", "Join", "(", "u", ".", "Host", ",", "u", ".", "Path", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "fmt", ".", "Errorf", "(", "`invalid docker URL %q; expected syntax is \"docker://[REGISTRY_HOST[:REGISTRY_PORT]/]IMAGE_NAME[:TAG]\"`", ",", "u", ")", "\n", "}", "\n", "latest", ":=", "dockerURL", ".", "Tag", "==", "\"", "\"", "\n", "return", "f", ".", "fetchImageFrom", "(", "u", ",", "latest", ")", "\n", "}" ]
// Hash uses docker2aci to download the image and convert it to // ACI, then stores it in the store and returns the hash.
[ "Hash", "uses", "docker2aci", "to", "download", "the", "image", "and", "convert", "it", "to", "ACI", "then", "stores", "it", "in", "the", "store", "and", "returns", "the", "hash", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/image/dockerfetcher.go#L51-L59
20,894
rkt/rkt
stage0/registration.go
registerPod
func registerPod(root string, uuid *types.UUID, apps schema.AppList) (token string, rerr error) { u := uuid.String() var err error token, err = generateMDSToken() if err != nil { rerr = errwrap.Wrap(errors.New("failed to generate MDS token"), err) return } pmfPath := common.PodManifestPath(root) pmf, err := os.Open(pmfPath) if err != nil { rerr = errwrap.Wrap(fmt.Errorf("failed to open runtime manifest (%v)", pmfPath), err) return } pth := fmt.Sprintf("/pods/%v?token=%v", u, token) err = httpRequest("PUT", pth, pmf) pmf.Close() if err != nil { rerr = errwrap.Wrap(errors.New("failed to register pod with metadata svc"), err) return } defer func() { if rerr != nil { unregisterPod(root, uuid) } }() rf, err := os.Create(filepath.Join(root, mdsRegisteredFile)) if err != nil { rerr = errwrap.Wrap(errors.New("failed to create mds-register file"), err) return } rf.Close() for _, app := range apps { ampath := common.ImageManifestPath(root, app.Name) amf, err := os.Open(ampath) if err != nil { rerr = errwrap.Wrap(fmt.Errorf("failed reading app manifest %q", ampath), err) return } err = registerApp(u, app.Name.String(), amf) amf.Close() if err != nil { rerr = errwrap.Wrap(errors.New("failed to register app with metadata svc"), err) return } } return }
go
func registerPod(root string, uuid *types.UUID, apps schema.AppList) (token string, rerr error) { u := uuid.String() var err error token, err = generateMDSToken() if err != nil { rerr = errwrap.Wrap(errors.New("failed to generate MDS token"), err) return } pmfPath := common.PodManifestPath(root) pmf, err := os.Open(pmfPath) if err != nil { rerr = errwrap.Wrap(fmt.Errorf("failed to open runtime manifest (%v)", pmfPath), err) return } pth := fmt.Sprintf("/pods/%v?token=%v", u, token) err = httpRequest("PUT", pth, pmf) pmf.Close() if err != nil { rerr = errwrap.Wrap(errors.New("failed to register pod with metadata svc"), err) return } defer func() { if rerr != nil { unregisterPod(root, uuid) } }() rf, err := os.Create(filepath.Join(root, mdsRegisteredFile)) if err != nil { rerr = errwrap.Wrap(errors.New("failed to create mds-register file"), err) return } rf.Close() for _, app := range apps { ampath := common.ImageManifestPath(root, app.Name) amf, err := os.Open(ampath) if err != nil { rerr = errwrap.Wrap(fmt.Errorf("failed reading app manifest %q", ampath), err) return } err = registerApp(u, app.Name.String(), amf) amf.Close() if err != nil { rerr = errwrap.Wrap(errors.New("failed to register app with metadata svc"), err) return } } return }
[ "func", "registerPod", "(", "root", "string", ",", "uuid", "*", "types", ".", "UUID", ",", "apps", "schema", ".", "AppList", ")", "(", "token", "string", ",", "rerr", "error", ")", "{", "u", ":=", "uuid", ".", "String", "(", ")", "\n\n", "var", "err", "error", "\n", "token", ",", "err", "=", "generateMDSToken", "(", ")", "\n", "if", "err", "!=", "nil", "{", "rerr", "=", "errwrap", ".", "Wrap", "(", "errors", ".", "New", "(", "\"", "\"", ")", ",", "err", ")", "\n", "return", "\n", "}", "\n\n", "pmfPath", ":=", "common", ".", "PodManifestPath", "(", "root", ")", "\n", "pmf", ",", "err", ":=", "os", ".", "Open", "(", "pmfPath", ")", "\n", "if", "err", "!=", "nil", "{", "rerr", "=", "errwrap", ".", "Wrap", "(", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "pmfPath", ")", ",", "err", ")", "\n", "return", "\n", "}", "\n\n", "pth", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "u", ",", "token", ")", "\n", "err", "=", "httpRequest", "(", "\"", "\"", ",", "pth", ",", "pmf", ")", "\n", "pmf", ".", "Close", "(", ")", "\n", "if", "err", "!=", "nil", "{", "rerr", "=", "errwrap", ".", "Wrap", "(", "errors", ".", "New", "(", "\"", "\"", ")", ",", "err", ")", "\n", "return", "\n", "}", "\n\n", "defer", "func", "(", ")", "{", "if", "rerr", "!=", "nil", "{", "unregisterPod", "(", "root", ",", "uuid", ")", "\n", "}", "\n", "}", "(", ")", "\n\n", "rf", ",", "err", ":=", "os", ".", "Create", "(", "filepath", ".", "Join", "(", "root", ",", "mdsRegisteredFile", ")", ")", "\n", "if", "err", "!=", "nil", "{", "rerr", "=", "errwrap", ".", "Wrap", "(", "errors", ".", "New", "(", "\"", "\"", ")", ",", "err", ")", "\n", "return", "\n", "}", "\n", "rf", ".", "Close", "(", ")", "\n\n", "for", "_", ",", "app", ":=", "range", "apps", "{", "ampath", ":=", "common", ".", "ImageManifestPath", "(", "root", ",", "app", ".", "Name", ")", "\n", "amf", ",", "err", ":=", "os", ".", "Open", "(", "ampath", ")", "\n", "if", "err", "!=", "nil", "{", "rerr", "=", "errwrap", ".", "Wrap", "(", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "ampath", ")", ",", "err", ")", "\n", "return", "\n", "}", "\n\n", "err", "=", "registerApp", "(", "u", ",", "app", ".", "Name", ".", "String", "(", ")", ",", "amf", ")", "\n", "amf", ".", "Close", "(", ")", "\n", "if", "err", "!=", "nil", "{", "rerr", "=", "errwrap", ".", "Wrap", "(", "errors", ".", "New", "(", "\"", "\"", ")", ",", "err", ")", "\n", "return", "\n", "}", "\n", "}", "\n\n", "return", "\n", "}" ]
// registerPod registers pod with metadata service. // Returns authentication token to be passed in the URL
[ "registerPod", "registers", "pod", "with", "metadata", "service", ".", "Returns", "authentication", "token", "to", "be", "passed", "in", "the", "URL" ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage0/registration.go#L54-L109
20,895
rkt/rkt
stage0/registration.go
unregisterPod
func unregisterPod(root string, uuid *types.UUID) error { _, err := os.Stat(filepath.Join(root, mdsRegisteredFile)) switch { case err == nil: pth := path.Join("/pods", uuid.String()) return httpRequest("DELETE", pth, nil) case os.IsNotExist(err): return nil default: return err } }
go
func unregisterPod(root string, uuid *types.UUID) error { _, err := os.Stat(filepath.Join(root, mdsRegisteredFile)) switch { case err == nil: pth := path.Join("/pods", uuid.String()) return httpRequest("DELETE", pth, nil) case os.IsNotExist(err): return nil default: return err } }
[ "func", "unregisterPod", "(", "root", "string", ",", "uuid", "*", "types", ".", "UUID", ")", "error", "{", "_", ",", "err", ":=", "os", ".", "Stat", "(", "filepath", ".", "Join", "(", "root", ",", "mdsRegisteredFile", ")", ")", "\n", "switch", "{", "case", "err", "==", "nil", ":", "pth", ":=", "path", ".", "Join", "(", "\"", "\"", ",", "uuid", ".", "String", "(", ")", ")", "\n", "return", "httpRequest", "(", "\"", "\"", ",", "pth", ",", "nil", ")", "\n\n", "case", "os", ".", "IsNotExist", "(", "err", ")", ":", "return", "nil", "\n\n", "default", ":", "return", "err", "\n", "}", "\n", "}" ]
// unregisterPod unregisters pod with the metadata service.
[ "unregisterPod", "unregisters", "pod", "with", "the", "metadata", "service", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage0/registration.go#L112-L125
20,896
rkt/rkt
stage0/registration.go
CheckMdsAvailability
func CheckMdsAvailability() error { if conn, err := net.Dial("unix", common.MetadataServiceRegSock); err != nil { return errUnreachable } else { conn.Close() return nil } }
go
func CheckMdsAvailability() error { if conn, err := net.Dial("unix", common.MetadataServiceRegSock); err != nil { return errUnreachable } else { conn.Close() return nil } }
[ "func", "CheckMdsAvailability", "(", ")", "error", "{", "if", "conn", ",", "err", ":=", "net", ".", "Dial", "(", "\"", "\"", ",", "common", ".", "MetadataServiceRegSock", ")", ";", "err", "!=", "nil", "{", "return", "errUnreachable", "\n", "}", "else", "{", "conn", ".", "Close", "(", ")", "\n", "return", "nil", "\n", "}", "\n", "}" ]
// CheckMdsAvailability checks whether a local metadata service can be reached.
[ "CheckMdsAvailability", "checks", "whether", "a", "local", "metadata", "service", "can", "be", "reached", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage0/registration.go#L196-L203
20,897
rkt/rkt
networking/netinfo/netinfo.go
MergeCNIResult
func (ni *NetInfo) MergeCNIResult(result types.Result) { ni.IP = result.IP4.IP.IP ni.Mask = net.IP(result.IP4.IP.Mask) ni.HostIP = result.IP4.Gateway ni.IP4 = result.IP4 ni.DNS = result.DNS }
go
func (ni *NetInfo) MergeCNIResult(result types.Result) { ni.IP = result.IP4.IP.IP ni.Mask = net.IP(result.IP4.IP.Mask) ni.HostIP = result.IP4.Gateway ni.IP4 = result.IP4 ni.DNS = result.DNS }
[ "func", "(", "ni", "*", "NetInfo", ")", "MergeCNIResult", "(", "result", "types", ".", "Result", ")", "{", "ni", ".", "IP", "=", "result", ".", "IP4", ".", "IP", ".", "IP", "\n", "ni", ".", "Mask", "=", "net", ".", "IP", "(", "result", ".", "IP4", ".", "IP", ".", "Mask", ")", "\n", "ni", ".", "HostIP", "=", "result", ".", "IP4", ".", "Gateway", "\n", "ni", ".", "IP4", "=", "result", ".", "IP4", "\n", "ni", ".", "DNS", "=", "result", ".", "DNS", "\n", "}" ]
// MergeCNIResult will incorporate the result of a CNI plugin's execution
[ "MergeCNIResult", "will", "incorporate", "the", "result", "of", "a", "CNI", "plugin", "s", "execution" ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/networking/netinfo/netinfo.go#L74-L80
20,898
rkt/rkt
pkg/multicall/multicall.go
Add
func Add(name string, fn commandFn) Entrypoint { if _, ok := commands[name]; ok { panic(fmt.Errorf("command with name %q already exists", name)) } commands[name] = fn return Entrypoint(name) }
go
func Add(name string, fn commandFn) Entrypoint { if _, ok := commands[name]; ok { panic(fmt.Errorf("command with name %q already exists", name)) } commands[name] = fn return Entrypoint(name) }
[ "func", "Add", "(", "name", "string", ",", "fn", "commandFn", ")", "Entrypoint", "{", "if", "_", ",", "ok", ":=", "commands", "[", "name", "]", ";", "ok", "{", "panic", "(", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "name", ")", ")", "\n", "}", "\n", "commands", "[", "name", "]", "=", "fn", "\n", "return", "Entrypoint", "(", "name", ")", "\n", "}" ]
// Add adds a new multicall command. name is the command name and fn is the // function that will be executed for the specified command. It returns the // related Entrypoint. // Packages adding new multicall commands should call Add in their init // function.
[ "Add", "adds", "a", "new", "multicall", "command", ".", "name", "is", "the", "command", "name", "and", "fn", "is", "the", "function", "that", "will", "be", "executed", "for", "the", "specified", "command", ".", "It", "returns", "the", "related", "Entrypoint", ".", "Packages", "adding", "new", "multicall", "commands", "should", "call", "Add", "in", "their", "init", "function", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/multicall/multicall.go#L52-L58
20,899
rkt/rkt
rkt/stage1hash.go
addStage1ImageFlags
func addStage1ImageFlags(flags *pflag.FlagSet) { for _, data := range stage1FlagsData { wrapper := &stage1ImageLocationFlag{ loc: &overriddenStage1Location, kind: data.kind, } flags.Var(wrapper, data.flag, data.help) } }
go
func addStage1ImageFlags(flags *pflag.FlagSet) { for _, data := range stage1FlagsData { wrapper := &stage1ImageLocationFlag{ loc: &overriddenStage1Location, kind: data.kind, } flags.Var(wrapper, data.flag, data.help) } }
[ "func", "addStage1ImageFlags", "(", "flags", "*", "pflag", ".", "FlagSet", ")", "{", "for", "_", ",", "data", ":=", "range", "stage1FlagsData", "{", "wrapper", ":=", "&", "stage1ImageLocationFlag", "{", "loc", ":", "&", "overriddenStage1Location", ",", "kind", ":", "data", ".", "kind", ",", "}", "\n", "flags", ".", "Var", "(", "wrapper", ",", "data", ".", "flag", ",", "data", ".", "help", ")", "\n", "}", "\n", "}" ]
// addStage1ImageFlags adds flags for specifying custom stage1 image
[ "addStage1ImageFlags", "adds", "flags", "for", "specifying", "custom", "stage1", "image" ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/stage1hash.go#L157-L165