repo
stringlengths
5
67
path
stringlengths
4
218
func_name
stringlengths
0
151
original_string
stringlengths
52
373k
language
stringclasses
6 values
code
stringlengths
52
373k
code_tokens
listlengths
10
512
docstring
stringlengths
3
47.2k
docstring_tokens
listlengths
3
234
sha
stringlengths
40
40
url
stringlengths
85
339
partition
stringclasses
3 values
faiface/pixel
pixelgl/window.go
SetTitle
func (w *Window) SetTitle(title string) { mainthread.Call(func() { w.window.SetTitle(title) }) }
go
func (w *Window) SetTitle(title string) { mainthread.Call(func() { w.window.SetTitle(title) }) }
[ "func", "(", "w", "*", "Window", ")", "SetTitle", "(", "title", "string", ")", "{", "mainthread", ".", "Call", "(", "func", "(", ")", "{", "w", ".", "window", ".", "SetTitle", "(", "title", ")", "\n", "}", ")", "\n", "}" ]
// SetTitle changes the title of the Window.
[ "SetTitle", "changes", "the", "title", "of", "the", "Window", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/pixelgl/window.go#L224-L228
train
faiface/pixel
pixelgl/window.go
SetBounds
func (w *Window) SetBounds(bounds pixel.Rect) { w.bounds = bounds mainthread.Call(func() { _, _, width, height := intBounds(bounds) w.window.SetSize(width, height) }) }
go
func (w *Window) SetBounds(bounds pixel.Rect) { w.bounds = bounds mainthread.Call(func() { _, _, width, height := intBounds(bounds) w.window.SetSize(width, height) }) }
[ "func", "(", "w", "*", "Window", ")", "SetBounds", "(", "bounds", "pixel", ".", "Rect", ")", "{", "w", ".", "bounds", "=", "bounds", "\n", "mainthread", ".", "Call", "(", "func", "(", ")", "{", "_", ",", "_", ",", "width", ",", "height", ":=", "intBounds", "(", "bounds", ")", "\n", "w", ".", "window", ".", "SetSize", "(", "width", ",", "height", ")", "\n", "}", ")", "\n", "}" ]
// SetBounds sets the bounds of the Window in pixels. Bounds can be fractional, but the actual size // of the window will be rounded to integers.
[ "SetBounds", "sets", "the", "bounds", "of", "the", "Window", "in", "pixels", ".", "Bounds", "can", "be", "fractional", "but", "the", "actual", "size", "of", "the", "window", "will", "be", "rounded", "to", "integers", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/pixelgl/window.go#L232-L238
train
faiface/pixel
pixelgl/window.go
SetPos
func (w *Window) SetPos(pos pixel.Vec) { mainthread.Call(func() { left, top := int(pos.X), int(pos.Y) w.window.SetPos(left, top) }) }
go
func (w *Window) SetPos(pos pixel.Vec) { mainthread.Call(func() { left, top := int(pos.X), int(pos.Y) w.window.SetPos(left, top) }) }
[ "func", "(", "w", "*", "Window", ")", "SetPos", "(", "pos", "pixel", ".", "Vec", ")", "{", "mainthread", ".", "Call", "(", "func", "(", ")", "{", "left", ",", "top", ":=", "int", "(", "pos", ".", "X", ")", ",", "int", "(", "pos", ".", "Y", ")", "\n", "w", ".", "window", ".", "SetPos", "(", "left", ",", "top", ")", "\n", "}", ")", "\n", "}" ]
// SetPos sets the position, in screen coordinates, of the upper-left corner // of the client area of the window. Position can be fractional, but the actual position // of the window will be rounded to integers. // // If it is a full screen window, this function does nothing.
[ "SetPos", "sets", "the", "position", "in", "screen", "coordinates", "of", "the", "upper", "-", "left", "corner", "of", "the", "client", "area", "of", "the", "window", ".", "Position", "can", "be", "fractional", "but", "the", "actual", "position", "of", "the", "window", "will", "be", "rounded", "to", "integers", ".", "If", "it", "is", "a", "full", "screen", "window", "this", "function", "does", "nothing", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/pixelgl/window.go#L245-L250
train
faiface/pixel
pixelgl/window.go
GetPos
func (w *Window) GetPos() pixel.Vec { var v pixel.Vec mainthread.Call(func() { x, y := w.window.GetPos() v = pixel.V(float64(x), float64(y)) }) return v }
go
func (w *Window) GetPos() pixel.Vec { var v pixel.Vec mainthread.Call(func() { x, y := w.window.GetPos() v = pixel.V(float64(x), float64(y)) }) return v }
[ "func", "(", "w", "*", "Window", ")", "GetPos", "(", ")", "pixel", ".", "Vec", "{", "var", "v", "pixel", ".", "Vec", "\n", "mainthread", ".", "Call", "(", "func", "(", ")", "{", "x", ",", "y", ":=", "w", ".", "window", ".", "GetPos", "(", ")", "\n", "v", "=", "pixel", ".", "V", "(", "float64", "(", "x", ")", ",", "float64", "(", "y", ")", ")", "\n", "}", ")", "\n", "return", "v", "\n", "}" ]
// GetPos gets the position, in screen coordinates, of the upper-left corner // of the client area of the window. The position is rounded to integers.
[ "GetPos", "gets", "the", "position", "in", "screen", "coordinates", "of", "the", "upper", "-", "left", "corner", "of", "the", "client", "area", "of", "the", "window", ".", "The", "position", "is", "rounded", "to", "integers", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/pixelgl/window.go#L254-L261
train
faiface/pixel
pixelgl/window.go
SetMonitor
func (w *Window) SetMonitor(monitor *Monitor) { if w.Monitor() != monitor { if monitor != nil { w.setFullscreen(monitor) } else { w.setWindowed() } } }
go
func (w *Window) SetMonitor(monitor *Monitor) { if w.Monitor() != monitor { if monitor != nil { w.setFullscreen(monitor) } else { w.setWindowed() } } }
[ "func", "(", "w", "*", "Window", ")", "SetMonitor", "(", "monitor", "*", "Monitor", ")", "{", "if", "w", ".", "Monitor", "(", ")", "!=", "monitor", "{", "if", "monitor", "!=", "nil", "{", "w", ".", "setFullscreen", "(", "monitor", ")", "\n", "}", "else", "{", "w", ".", "setWindowed", "(", ")", "\n", "}", "\n", "}", "\n", "}" ]
// SetMonitor sets the Window fullscreen on the given Monitor. If the Monitor is nil, the Window // will be restored to windowed state instead. // // The Window will be automatically set to the Monitor's resolution. If you want a different // resolution, you will need to set it manually with SetBounds method.
[ "SetMonitor", "sets", "the", "Window", "fullscreen", "on", "the", "given", "Monitor", ".", "If", "the", "Monitor", "is", "nil", "the", "Window", "will", "be", "restored", "to", "windowed", "state", "instead", ".", "The", "Window", "will", "be", "automatically", "set", "to", "the", "Monitor", "s", "resolution", ".", "If", "you", "want", "a", "different", "resolution", "you", "will", "need", "to", "set", "it", "manually", "with", "SetBounds", "method", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/pixelgl/window.go#L304-L312
train
faiface/pixel
pixelgl/window.go
Monitor
func (w *Window) Monitor() *Monitor { var monitor *glfw.Monitor mainthread.Call(func() { monitor = w.window.GetMonitor() }) if monitor == nil { return nil } return &Monitor{ monitor: monitor, } }
go
func (w *Window) Monitor() *Monitor { var monitor *glfw.Monitor mainthread.Call(func() { monitor = w.window.GetMonitor() }) if monitor == nil { return nil } return &Monitor{ monitor: monitor, } }
[ "func", "(", "w", "*", "Window", ")", "Monitor", "(", ")", "*", "Monitor", "{", "var", "monitor", "*", "glfw", ".", "Monitor", "\n", "mainthread", ".", "Call", "(", "func", "(", ")", "{", "monitor", "=", "w", ".", "window", ".", "GetMonitor", "(", ")", "\n", "}", ")", "\n", "if", "monitor", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "return", "&", "Monitor", "{", "monitor", ":", "monitor", ",", "}", "\n", "}" ]
// Monitor returns a monitor the Window is fullscreen on. If the Window is not fullscreen, this // function returns nil.
[ "Monitor", "returns", "a", "monitor", "the", "Window", "is", "fullscreen", "on", ".", "If", "the", "Window", "is", "not", "fullscreen", "this", "function", "returns", "nil", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/pixelgl/window.go#L316-L327
train
faiface/pixel
pixelgl/window.go
Focused
func (w *Window) Focused() bool { var focused bool mainthread.Call(func() { focused = w.window.GetAttrib(glfw.Focused) == glfw.True }) return focused }
go
func (w *Window) Focused() bool { var focused bool mainthread.Call(func() { focused = w.window.GetAttrib(glfw.Focused) == glfw.True }) return focused }
[ "func", "(", "w", "*", "Window", ")", "Focused", "(", ")", "bool", "{", "var", "focused", "bool", "\n", "mainthread", ".", "Call", "(", "func", "(", ")", "{", "focused", "=", "w", ".", "window", ".", "GetAttrib", "(", "glfw", ".", "Focused", ")", "==", "glfw", ".", "True", "\n", "}", ")", "\n", "return", "focused", "\n", "}" ]
// Focused returns true if the Window has input focus.
[ "Focused", "returns", "true", "if", "the", "Window", "has", "input", "focus", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/pixelgl/window.go#L330-L336
train
faiface/pixel
pixelgl/window.go
SetCursorVisible
func (w *Window) SetCursorVisible(visible bool) { w.cursorVisible = visible mainthread.Call(func() { if visible { w.window.SetInputMode(glfw.CursorMode, glfw.CursorNormal) } else { w.window.SetInputMode(glfw.CursorMode, glfw.CursorHidden) } }) }
go
func (w *Window) SetCursorVisible(visible bool) { w.cursorVisible = visible mainthread.Call(func() { if visible { w.window.SetInputMode(glfw.CursorMode, glfw.CursorNormal) } else { w.window.SetInputMode(glfw.CursorMode, glfw.CursorHidden) } }) }
[ "func", "(", "w", "*", "Window", ")", "SetCursorVisible", "(", "visible", "bool", ")", "{", "w", ".", "cursorVisible", "=", "visible", "\n", "mainthread", ".", "Call", "(", "func", "(", ")", "{", "if", "visible", "{", "w", ".", "window", ".", "SetInputMode", "(", "glfw", ".", "CursorMode", ",", "glfw", ".", "CursorNormal", ")", "\n", "}", "else", "{", "w", ".", "window", ".", "SetInputMode", "(", "glfw", ".", "CursorMode", ",", "glfw", ".", "CursorHidden", ")", "\n", "}", "\n", "}", ")", "\n", "}" ]
// SetCursorVisible sets the visibility of the mouse cursor inside the Window client area.
[ "SetCursorVisible", "sets", "the", "visibility", "of", "the", "mouse", "cursor", "inside", "the", "Window", "client", "area", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/pixelgl/window.go#L349-L358
train
faiface/pixel
pixelgl/window.go
MakeTriangles
func (w *Window) MakeTriangles(t pixel.Triangles) pixel.TargetTriangles { return w.canvas.MakeTriangles(t) }
go
func (w *Window) MakeTriangles(t pixel.Triangles) pixel.TargetTriangles { return w.canvas.MakeTriangles(t) }
[ "func", "(", "w", "*", "Window", ")", "MakeTriangles", "(", "t", "pixel", ".", "Triangles", ")", "pixel", ".", "TargetTriangles", "{", "return", "w", ".", "canvas", ".", "MakeTriangles", "(", "t", ")", "\n", "}" ]
// MakeTriangles generates a specialized copy of the supplied Triangles that will draw onto this // Window. // // Window supports TrianglesPosition, TrianglesColor and TrianglesPicture.
[ "MakeTriangles", "generates", "a", "specialized", "copy", "of", "the", "supplied", "Triangles", "that", "will", "draw", "onto", "this", "Window", ".", "Window", "supports", "TrianglesPosition", "TrianglesColor", "and", "TrianglesPicture", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/pixelgl/window.go#L382-L384
train
faiface/pixel
pixelgl/window.go
MakePicture
func (w *Window) MakePicture(p pixel.Picture) pixel.TargetPicture { return w.canvas.MakePicture(p) }
go
func (w *Window) MakePicture(p pixel.Picture) pixel.TargetPicture { return w.canvas.MakePicture(p) }
[ "func", "(", "w", "*", "Window", ")", "MakePicture", "(", "p", "pixel", ".", "Picture", ")", "pixel", ".", "TargetPicture", "{", "return", "w", ".", "canvas", ".", "MakePicture", "(", "p", ")", "\n", "}" ]
// MakePicture generates a specialized copy of the supplied Picture that will draw onto this Window. // // Window supports PictureColor.
[ "MakePicture", "generates", "a", "specialized", "copy", "of", "the", "supplied", "Picture", "that", "will", "draw", "onto", "this", "Window", ".", "Window", "supports", "PictureColor", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/pixelgl/window.go#L389-L391
train
faiface/pixel
pixelgl/window.go
SetColorMask
func (w *Window) SetColorMask(c color.Color) { w.canvas.SetColorMask(c) }
go
func (w *Window) SetColorMask(c color.Color) { w.canvas.SetColorMask(c) }
[ "func", "(", "w", "*", "Window", ")", "SetColorMask", "(", "c", "color", ".", "Color", ")", "{", "w", ".", "canvas", ".", "SetColorMask", "(", "c", ")", "\n", "}" ]
// SetColorMask sets a global color mask for the Window.
[ "SetColorMask", "sets", "a", "global", "color", "mask", "for", "the", "Window", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/pixelgl/window.go#L399-L401
train
faiface/pixel
pixelgl/window.go
SetComposeMethod
func (w *Window) SetComposeMethod(cmp pixel.ComposeMethod) { w.canvas.SetComposeMethod(cmp) }
go
func (w *Window) SetComposeMethod(cmp pixel.ComposeMethod) { w.canvas.SetComposeMethod(cmp) }
[ "func", "(", "w", "*", "Window", ")", "SetComposeMethod", "(", "cmp", "pixel", ".", "ComposeMethod", ")", "{", "w", ".", "canvas", ".", "SetComposeMethod", "(", "cmp", ")", "\n", "}" ]
// SetComposeMethod sets a Porter-Duff composition method to be used in the following draws onto // this Window.
[ "SetComposeMethod", "sets", "a", "Porter", "-", "Duff", "composition", "method", "to", "be", "used", "in", "the", "following", "draws", "onto", "this", "Window", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/pixelgl/window.go#L405-L407
train
faiface/pixel
pixelgl/window.go
Clear
func (w *Window) Clear(c color.Color) { w.canvas.Clear(c) }
go
func (w *Window) Clear(c color.Color) { w.canvas.Clear(c) }
[ "func", "(", "w", "*", "Window", ")", "Clear", "(", "c", "color", ".", "Color", ")", "{", "w", ".", "canvas", ".", "Clear", "(", "c", ")", "\n", "}" ]
// Clear clears the Window with a single color.
[ "Clear", "clears", "the", "Window", "with", "a", "single", "color", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/pixelgl/window.go#L422-L424
train
faiface/pixel
pixelgl/window.go
Color
func (w *Window) Color(at pixel.Vec) pixel.RGBA { return w.canvas.Color(at) }
go
func (w *Window) Color(at pixel.Vec) pixel.RGBA { return w.canvas.Color(at) }
[ "func", "(", "w", "*", "Window", ")", "Color", "(", "at", "pixel", ".", "Vec", ")", "pixel", ".", "RGBA", "{", "return", "w", ".", "canvas", ".", "Color", "(", "at", ")", "\n", "}" ]
// Color returns the color of the pixel over the given position inside the Window.
[ "Color", "returns", "the", "color", "of", "the", "pixel", "over", "the", "given", "position", "inside", "the", "Window", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/pixelgl/window.go#L427-L429
train
faiface/pixel
text/atlas.go
Contains
func (a *Atlas) Contains(r rune) bool { _, ok := a.mapping[r] return ok }
go
func (a *Atlas) Contains(r rune) bool { _, ok := a.mapping[r] return ok }
[ "func", "(", "a", "*", "Atlas", ")", "Contains", "(", "r", "rune", ")", "bool", "{", "_", ",", "ok", ":=", "a", ".", "mapping", "[", "r", "]", "\n", "return", "ok", "\n", "}" ]
// Contains reports wheter r in contained within the Atlas.
[ "Contains", "reports", "wheter", "r", "in", "contained", "within", "the", "Atlas", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/text/atlas.go#L108-L111
train
faiface/pixel
text/atlas.go
Kern
func (a *Atlas) Kern(r0, r1 rune) float64 { return i2f(a.face.Kern(r0, r1)) }
go
func (a *Atlas) Kern(r0, r1 rune) float64 { return i2f(a.face.Kern(r0, r1)) }
[ "func", "(", "a", "*", "Atlas", ")", "Kern", "(", "r0", ",", "r1", "rune", ")", "float64", "{", "return", "i2f", "(", "a", ".", "face", ".", "Kern", "(", "r0", ",", "r1", ")", ")", "\n", "}" ]
// Kern returns the kerning distance between runes r0 and r1. Positive distance means that the // glyphs should be further apart.
[ "Kern", "returns", "the", "kerning", "distance", "between", "runes", "r0", "and", "r1", ".", "Positive", "distance", "means", "that", "the", "glyphs", "should", "be", "further", "apart", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/text/atlas.go#L120-L122
train
faiface/pixel
text/atlas.go
DrawRune
func (a *Atlas) DrawRune(prevR, r rune, dot pixel.Vec) (rect, frame, bounds pixel.Rect, newDot pixel.Vec) { if !a.Contains(r) { r = unicode.ReplacementChar } if !a.Contains(unicode.ReplacementChar) { return pixel.Rect{}, pixel.Rect{}, pixel.Rect{}, dot } if !a.Contains(prevR) { prevR = unicode.ReplacementChar } if prevR >= 0 { dot.X += a.Kern(prevR, r) } glyph := a.Glyph(r) rect = glyph.Frame.Moved(dot.Sub(glyph.Dot)) bounds = rect if bounds.W()*bounds.H() != 0 { bounds = pixel.R( bounds.Min.X, dot.Y-a.Descent(), bounds.Max.X, dot.Y+a.Ascent(), ) } dot.X += glyph.Advance return rect, glyph.Frame, bounds, dot }
go
func (a *Atlas) DrawRune(prevR, r rune, dot pixel.Vec) (rect, frame, bounds pixel.Rect, newDot pixel.Vec) { if !a.Contains(r) { r = unicode.ReplacementChar } if !a.Contains(unicode.ReplacementChar) { return pixel.Rect{}, pixel.Rect{}, pixel.Rect{}, dot } if !a.Contains(prevR) { prevR = unicode.ReplacementChar } if prevR >= 0 { dot.X += a.Kern(prevR, r) } glyph := a.Glyph(r) rect = glyph.Frame.Moved(dot.Sub(glyph.Dot)) bounds = rect if bounds.W()*bounds.H() != 0 { bounds = pixel.R( bounds.Min.X, dot.Y-a.Descent(), bounds.Max.X, dot.Y+a.Ascent(), ) } dot.X += glyph.Advance return rect, glyph.Frame, bounds, dot }
[ "func", "(", "a", "*", "Atlas", ")", "DrawRune", "(", "prevR", ",", "r", "rune", ",", "dot", "pixel", ".", "Vec", ")", "(", "rect", ",", "frame", ",", "bounds", "pixel", ".", "Rect", ",", "newDot", "pixel", ".", "Vec", ")", "{", "if", "!", "a", ".", "Contains", "(", "r", ")", "{", "r", "=", "unicode", ".", "ReplacementChar", "\n", "}", "\n", "if", "!", "a", ".", "Contains", "(", "unicode", ".", "ReplacementChar", ")", "{", "return", "pixel", ".", "Rect", "{", "}", ",", "pixel", ".", "Rect", "{", "}", ",", "pixel", ".", "Rect", "{", "}", ",", "dot", "\n", "}", "\n", "if", "!", "a", ".", "Contains", "(", "prevR", ")", "{", "prevR", "=", "unicode", ".", "ReplacementChar", "\n", "}", "\n", "if", "prevR", ">=", "0", "{", "dot", ".", "X", "+=", "a", ".", "Kern", "(", "prevR", ",", "r", ")", "\n", "}", "\n", "glyph", ":=", "a", ".", "Glyph", "(", "r", ")", "\n", "rect", "=", "glyph", ".", "Frame", ".", "Moved", "(", "dot", ".", "Sub", "(", "glyph", ".", "Dot", ")", ")", "\n", "bounds", "=", "rect", "\n", "if", "bounds", ".", "W", "(", ")", "*", "bounds", ".", "H", "(", ")", "!=", "0", "{", "bounds", "=", "pixel", ".", "R", "(", "bounds", ".", "Min", ".", "X", ",", "dot", ".", "Y", "-", "a", ".", "Descent", "(", ")", ",", "bounds", ".", "Max", ".", "X", ",", "dot", ".", "Y", "+", "a", ".", "Ascent", "(", ")", ",", ")", "\n", "}", "\n", "dot", ".", "X", "+=", "glyph", ".", "Advance", "\n", "return", "rect", ",", "glyph", ".", "Frame", ",", "bounds", ",", "dot", "\n", "}" ]
// DrawRune returns parameters necessary for drawing a rune glyph. // // Rect is a rectangle where the glyph should be positioned. Frame is the glyph frame inside the // Atlas's Picture. NewDot is the new position of the dot.
[ "DrawRune", "returns", "parameters", "necessary", "for", "drawing", "a", "rune", "glyph", ".", "Rect", "is", "a", "rectangle", "where", "the", "glyph", "should", "be", "positioned", ".", "Frame", "is", "the", "glyph", "frame", "inside", "the", "Atlas", "s", "Picture", ".", "NewDot", "is", "the", "new", "position", "of", "the", "dot", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/text/atlas.go#L143-L175
train
faiface/pixel
text/atlas.go
makeSquareMapping
func makeSquareMapping(face font.Face, runes []rune, padding fixed.Int26_6) (map[rune]fixedGlyph, fixed.Rectangle26_6) { width := sort.Search(int(fixed.I(1024*1024)), func(i int) bool { width := fixed.Int26_6(i) _, bounds := makeMapping(face, runes, padding, width) return bounds.Max.X-bounds.Min.X >= bounds.Max.Y-bounds.Min.Y }) return makeMapping(face, runes, padding, fixed.Int26_6(width)) }
go
func makeSquareMapping(face font.Face, runes []rune, padding fixed.Int26_6) (map[rune]fixedGlyph, fixed.Rectangle26_6) { width := sort.Search(int(fixed.I(1024*1024)), func(i int) bool { width := fixed.Int26_6(i) _, bounds := makeMapping(face, runes, padding, width) return bounds.Max.X-bounds.Min.X >= bounds.Max.Y-bounds.Min.Y }) return makeMapping(face, runes, padding, fixed.Int26_6(width)) }
[ "func", "makeSquareMapping", "(", "face", "font", ".", "Face", ",", "runes", "[", "]", "rune", ",", "padding", "fixed", ".", "Int26_6", ")", "(", "map", "[", "rune", "]", "fixedGlyph", ",", "fixed", ".", "Rectangle26_6", ")", "{", "width", ":=", "sort", ".", "Search", "(", "int", "(", "fixed", ".", "I", "(", "1024", "*", "1024", ")", ")", ",", "func", "(", "i", "int", ")", "bool", "{", "width", ":=", "fixed", ".", "Int26_6", "(", "i", ")", "\n", "_", ",", "bounds", ":=", "makeMapping", "(", "face", ",", "runes", ",", "padding", ",", "width", ")", "\n", "return", "bounds", ".", "Max", ".", "X", "-", "bounds", ".", "Min", ".", "X", ">=", "bounds", ".", "Max", ".", "Y", "-", "bounds", ".", "Min", ".", "Y", "\n", "}", ")", "\n", "return", "makeMapping", "(", "face", ",", "runes", ",", "padding", ",", "fixed", ".", "Int26_6", "(", "width", ")", ")", "\n", "}" ]
// makeSquareMapping finds an optimal glyph arrangement of the given runes, so that their common // bounding box is as square as possible.
[ "makeSquareMapping", "finds", "an", "optimal", "glyph", "arrangement", "of", "the", "given", "runes", "so", "that", "their", "common", "bounding", "box", "is", "as", "square", "as", "possible", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/text/atlas.go#L185-L192
train
faiface/pixel
text/atlas.go
makeMapping
func makeMapping(face font.Face, runes []rune, padding, width fixed.Int26_6) (map[rune]fixedGlyph, fixed.Rectangle26_6) { mapping := make(map[rune]fixedGlyph) bounds := fixed.Rectangle26_6{} dot := fixed.P(0, 0) for _, r := range runes { b, advance, ok := face.GlyphBounds(r) if !ok { fmt.Println(r) continue } // this is important for drawing, artifacts arise otherwise frame := fixed.Rectangle26_6{ Min: fixed.P(b.Min.X.Floor(), b.Min.Y.Floor()), Max: fixed.P(b.Max.X.Ceil(), b.Max.Y.Ceil()), } dot.X -= frame.Min.X frame = frame.Add(dot) mapping[r] = fixedGlyph{ dot: dot, frame: frame, advance: advance, } bounds = bounds.Union(frame) dot.X = frame.Max.X // padding + align to integer dot.X += padding dot.X = fixed.I(dot.X.Ceil()) // width exceeded, new row if frame.Max.X >= width { dot.X = 0 dot.Y += face.Metrics().Ascent + face.Metrics().Descent // padding + align to integer dot.Y += padding dot.Y = fixed.I(dot.Y.Ceil()) } } return mapping, bounds }
go
func makeMapping(face font.Face, runes []rune, padding, width fixed.Int26_6) (map[rune]fixedGlyph, fixed.Rectangle26_6) { mapping := make(map[rune]fixedGlyph) bounds := fixed.Rectangle26_6{} dot := fixed.P(0, 0) for _, r := range runes { b, advance, ok := face.GlyphBounds(r) if !ok { fmt.Println(r) continue } // this is important for drawing, artifacts arise otherwise frame := fixed.Rectangle26_6{ Min: fixed.P(b.Min.X.Floor(), b.Min.Y.Floor()), Max: fixed.P(b.Max.X.Ceil(), b.Max.Y.Ceil()), } dot.X -= frame.Min.X frame = frame.Add(dot) mapping[r] = fixedGlyph{ dot: dot, frame: frame, advance: advance, } bounds = bounds.Union(frame) dot.X = frame.Max.X // padding + align to integer dot.X += padding dot.X = fixed.I(dot.X.Ceil()) // width exceeded, new row if frame.Max.X >= width { dot.X = 0 dot.Y += face.Metrics().Ascent + face.Metrics().Descent // padding + align to integer dot.Y += padding dot.Y = fixed.I(dot.Y.Ceil()) } } return mapping, bounds }
[ "func", "makeMapping", "(", "face", "font", ".", "Face", ",", "runes", "[", "]", "rune", ",", "padding", ",", "width", "fixed", ".", "Int26_6", ")", "(", "map", "[", "rune", "]", "fixedGlyph", ",", "fixed", ".", "Rectangle26_6", ")", "{", "mapping", ":=", "make", "(", "map", "[", "rune", "]", "fixedGlyph", ")", "\n", "bounds", ":=", "fixed", ".", "Rectangle26_6", "{", "}", "\n", "dot", ":=", "fixed", ".", "P", "(", "0", ",", "0", ")", "\n", "for", "_", ",", "r", ":=", "range", "runes", "{", "b", ",", "advance", ",", "ok", ":=", "face", ".", "GlyphBounds", "(", "r", ")", "\n", "if", "!", "ok", "{", "fmt", ".", "Println", "(", "r", ")", "\n", "continue", "\n", "}", "\n", "frame", ":=", "fixed", ".", "Rectangle26_6", "{", "Min", ":", "fixed", ".", "P", "(", "b", ".", "Min", ".", "X", ".", "Floor", "(", ")", ",", "b", ".", "Min", ".", "Y", ".", "Floor", "(", ")", ")", ",", "Max", ":", "fixed", ".", "P", "(", "b", ".", "Max", ".", "X", ".", "Ceil", "(", ")", ",", "b", ".", "Max", ".", "Y", ".", "Ceil", "(", ")", ")", ",", "}", "\n", "dot", ".", "X", "-=", "frame", ".", "Min", ".", "X", "\n", "frame", "=", "frame", ".", "Add", "(", "dot", ")", "\n", "mapping", "[", "r", "]", "=", "fixedGlyph", "{", "dot", ":", "dot", ",", "frame", ":", "frame", ",", "advance", ":", "advance", ",", "}", "\n", "bounds", "=", "bounds", ".", "Union", "(", "frame", ")", "\n", "dot", ".", "X", "=", "frame", ".", "Max", ".", "X", "\n", "dot", ".", "X", "+=", "padding", "\n", "dot", ".", "X", "=", "fixed", ".", "I", "(", "dot", ".", "X", ".", "Ceil", "(", ")", ")", "\n", "if", "frame", ".", "Max", ".", "X", ">=", "width", "{", "dot", ".", "X", "=", "0", "\n", "dot", ".", "Y", "+=", "face", ".", "Metrics", "(", ")", ".", "Ascent", "+", "face", ".", "Metrics", "(", ")", ".", "Descent", "\n", "dot", ".", "Y", "+=", "padding", "\n", "dot", ".", "Y", "=", "fixed", ".", "I", "(", "dot", ".", "Y", ".", "Ceil", "(", ")", ")", "\n", "}", "\n", "}", "\n", "return", "mapping", ",", "bounds", "\n", "}" ]
// makeMapping arranges glyphs of the given runes into rows in such a way, that no glyph is located // fully to the right of the specified width. Specifically, it places glyphs in a row one by one and // once it reaches the specified width, it starts a new row.
[ "makeMapping", "arranges", "glyphs", "of", "the", "given", "runes", "into", "rows", "in", "such", "a", "way", "that", "no", "glyph", "is", "located", "fully", "to", "the", "right", "of", "the", "specified", "width", ".", "Specifically", "it", "places", "glyphs", "in", "a", "row", "one", "by", "one", "and", "once", "it", "reaches", "the", "specified", "width", "it", "starts", "a", "new", "row", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/text/atlas.go#L197-L244
train
faiface/pixel
pixelgl/canvas.go
NewCanvas
func NewCanvas(bounds pixel.Rect) *Canvas { c := &Canvas{ gf: NewGLFrame(bounds), mat: mgl32.Ident3(), col: mgl32.Vec4{1, 1, 1, 1}, } baseShader(c) c.SetBounds(bounds) c.shader.update() return c }
go
func NewCanvas(bounds pixel.Rect) *Canvas { c := &Canvas{ gf: NewGLFrame(bounds), mat: mgl32.Ident3(), col: mgl32.Vec4{1, 1, 1, 1}, } baseShader(c) c.SetBounds(bounds) c.shader.update() return c }
[ "func", "NewCanvas", "(", "bounds", "pixel", ".", "Rect", ")", "*", "Canvas", "{", "c", ":=", "&", "Canvas", "{", "gf", ":", "NewGLFrame", "(", "bounds", ")", ",", "mat", ":", "mgl32", ".", "Ident3", "(", ")", ",", "col", ":", "mgl32", ".", "Vec4", "{", "1", ",", "1", ",", "1", ",", "1", "}", ",", "}", "\n", "baseShader", "(", "c", ")", "\n", "c", ".", "SetBounds", "(", "bounds", ")", "\n", "c", ".", "shader", ".", "update", "(", ")", "\n", "return", "c", "\n", "}" ]
// NewCanvas creates a new empty, fully transparent Canvas with given bounds.
[ "NewCanvas", "creates", "a", "new", "empty", "fully", "transparent", "Canvas", "with", "given", "bounds", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/pixelgl/canvas.go#L33-L44
train
faiface/pixel
pixelgl/canvas.go
SetUniform
func (c *Canvas) SetUniform(name string, value interface{}) { c.shader.setUniform(name, value) }
go
func (c *Canvas) SetUniform(name string, value interface{}) { c.shader.setUniform(name, value) }
[ "func", "(", "c", "*", "Canvas", ")", "SetUniform", "(", "name", "string", ",", "value", "interface", "{", "}", ")", "{", "c", ".", "shader", ".", "setUniform", "(", "name", ",", "value", ")", "\n", "}" ]
// SetUniform will update the named uniform with the value of any supported underlying // attribute variable. If the uniform already exists, including defaults, they will be reassigned // to the new value. The value can be a pointer.
[ "SetUniform", "will", "update", "the", "named", "uniform", "with", "the", "value", "of", "any", "supported", "underlying", "attribute", "variable", ".", "If", "the", "uniform", "already", "exists", "including", "defaults", "they", "will", "be", "reassigned", "to", "the", "new", "value", ".", "The", "value", "can", "be", "a", "pointer", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/pixelgl/canvas.go#L49-L51
train
faiface/pixel
pixelgl/canvas.go
SetFragmentShader
func (c *Canvas) SetFragmentShader(src string) { c.shader.fs = src c.shader.update() }
go
func (c *Canvas) SetFragmentShader(src string) { c.shader.fs = src c.shader.update() }
[ "func", "(", "c", "*", "Canvas", ")", "SetFragmentShader", "(", "src", "string", ")", "{", "c", ".", "shader", ".", "fs", "=", "src", "\n", "c", ".", "shader", ".", "update", "(", ")", "\n", "}" ]
// SetFragmentShader allows you to set a new fragment shader on the underlying // framebuffer. Argument "src" is the GLSL source, not a filename.
[ "SetFragmentShader", "allows", "you", "to", "set", "a", "new", "fragment", "shader", "on", "the", "underlying", "framebuffer", ".", "Argument", "src", "is", "the", "GLSL", "source", "not", "a", "filename", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/pixelgl/canvas.go#L55-L58
train
faiface/pixel
pixelgl/canvas.go
MakeTriangles
func (c *Canvas) MakeTriangles(t pixel.Triangles) pixel.TargetTriangles { return &canvasTriangles{ GLTriangles: NewGLTriangles(c.shader.s, t), dst: c, } }
go
func (c *Canvas) MakeTriangles(t pixel.Triangles) pixel.TargetTriangles { return &canvasTriangles{ GLTriangles: NewGLTriangles(c.shader.s, t), dst: c, } }
[ "func", "(", "c", "*", "Canvas", ")", "MakeTriangles", "(", "t", "pixel", ".", "Triangles", ")", "pixel", ".", "TargetTriangles", "{", "return", "&", "canvasTriangles", "{", "GLTriangles", ":", "NewGLTriangles", "(", "c", ".", "shader", ".", "s", ",", "t", ")", ",", "dst", ":", "c", ",", "}", "\n", "}" ]
// MakeTriangles creates a specialized copy of the supplied Triangles that draws onto this Canvas. // // TrianglesPosition, TrianglesColor and TrianglesPicture are supported.
[ "MakeTriangles", "creates", "a", "specialized", "copy", "of", "the", "supplied", "Triangles", "that", "draws", "onto", "this", "Canvas", ".", "TrianglesPosition", "TrianglesColor", "and", "TrianglesPicture", "are", "supported", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/pixelgl/canvas.go#L63-L68
train
faiface/pixel
pixelgl/canvas.go
MakePicture
func (c *Canvas) MakePicture(p pixel.Picture) pixel.TargetPicture { if cp, ok := p.(*canvasPicture); ok { return &canvasPicture{ GLPicture: cp.GLPicture, dst: c, } } if gp, ok := p.(GLPicture); ok { return &canvasPicture{ GLPicture: gp, dst: c, } } return &canvasPicture{ GLPicture: NewGLPicture(p), dst: c, } }
go
func (c *Canvas) MakePicture(p pixel.Picture) pixel.TargetPicture { if cp, ok := p.(*canvasPicture); ok { return &canvasPicture{ GLPicture: cp.GLPicture, dst: c, } } if gp, ok := p.(GLPicture); ok { return &canvasPicture{ GLPicture: gp, dst: c, } } return &canvasPicture{ GLPicture: NewGLPicture(p), dst: c, } }
[ "func", "(", "c", "*", "Canvas", ")", "MakePicture", "(", "p", "pixel", ".", "Picture", ")", "pixel", ".", "TargetPicture", "{", "if", "cp", ",", "ok", ":=", "p", ".", "(", "*", "canvasPicture", ")", ";", "ok", "{", "return", "&", "canvasPicture", "{", "GLPicture", ":", "cp", ".", "GLPicture", ",", "dst", ":", "c", ",", "}", "\n", "}", "\n", "if", "gp", ",", "ok", ":=", "p", ".", "(", "GLPicture", ")", ";", "ok", "{", "return", "&", "canvasPicture", "{", "GLPicture", ":", "gp", ",", "dst", ":", "c", ",", "}", "\n", "}", "\n", "return", "&", "canvasPicture", "{", "GLPicture", ":", "NewGLPicture", "(", "p", ")", ",", "dst", ":", "c", ",", "}", "\n", "}" ]
// MakePicture create a specialized copy of the supplied Picture that draws onto this Canvas. // // PictureColor is supported.
[ "MakePicture", "create", "a", "specialized", "copy", "of", "the", "supplied", "Picture", "that", "draws", "onto", "this", "Canvas", ".", "PictureColor", "is", "supported", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/pixelgl/canvas.go#L73-L90
train
faiface/pixel
pixelgl/canvas.go
SetColorMask
func (c *Canvas) SetColorMask(col color.Color) { rgba := pixel.Alpha(1) if col != nil { rgba = pixel.ToRGBA(col) } c.col = mgl32.Vec4{ float32(rgba.R), float32(rgba.G), float32(rgba.B), float32(rgba.A), } }
go
func (c *Canvas) SetColorMask(col color.Color) { rgba := pixel.Alpha(1) if col != nil { rgba = pixel.ToRGBA(col) } c.col = mgl32.Vec4{ float32(rgba.R), float32(rgba.G), float32(rgba.B), float32(rgba.A), } }
[ "func", "(", "c", "*", "Canvas", ")", "SetColorMask", "(", "col", "color", ".", "Color", ")", "{", "rgba", ":=", "pixel", ".", "Alpha", "(", "1", ")", "\n", "if", "col", "!=", "nil", "{", "rgba", "=", "pixel", ".", "ToRGBA", "(", "col", ")", "\n", "}", "\n", "c", ".", "col", "=", "mgl32", ".", "Vec4", "{", "float32", "(", "rgba", ".", "R", ")", ",", "float32", "(", "rgba", ".", "G", ")", ",", "float32", "(", "rgba", ".", "B", ")", ",", "float32", "(", "rgba", ".", "A", ")", ",", "}", "\n", "}" ]
// SetColorMask sets a color that every color in triangles or a picture will be multiplied by.
[ "SetColorMask", "sets", "a", "color", "that", "every", "color", "in", "triangles", "or", "a", "picture", "will", "be", "multiplied", "by", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/pixelgl/canvas.go#L105-L116
train
faiface/pixel
pixelgl/canvas.go
SetBounds
func (c *Canvas) SetBounds(bounds pixel.Rect) { c.gf.SetBounds(bounds) if c.sprite == nil { c.sprite = pixel.NewSprite(nil, pixel.Rect{}) } c.sprite.Set(c, c.Bounds()) //c.sprite.SetMatrix(pixel.IM.Moved(c.Bounds().Center())) }
go
func (c *Canvas) SetBounds(bounds pixel.Rect) { c.gf.SetBounds(bounds) if c.sprite == nil { c.sprite = pixel.NewSprite(nil, pixel.Rect{}) } c.sprite.Set(c, c.Bounds()) //c.sprite.SetMatrix(pixel.IM.Moved(c.Bounds().Center())) }
[ "func", "(", "c", "*", "Canvas", ")", "SetBounds", "(", "bounds", "pixel", ".", "Rect", ")", "{", "c", ".", "gf", ".", "SetBounds", "(", "bounds", ")", "\n", "if", "c", ".", "sprite", "==", "nil", "{", "c", ".", "sprite", "=", "pixel", ".", "NewSprite", "(", "nil", ",", "pixel", ".", "Rect", "{", "}", ")", "\n", "}", "\n", "c", ".", "sprite", ".", "Set", "(", "c", ",", "c", ".", "Bounds", "(", ")", ")", "\n", "}" ]
// SetBounds resizes the Canvas to the new bounds. Old content will be preserved.
[ "SetBounds", "resizes", "the", "Canvas", "to", "the", "new", "bounds", ".", "Old", "content", "will", "be", "preserved", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/pixelgl/canvas.go#L125-L132
train
faiface/pixel
pixelgl/canvas.go
Clear
func (c *Canvas) Clear(color color.Color) { c.gf.Dirty() rgba := pixel.ToRGBA(color) // color masking rgba = rgba.Mul(pixel.RGBA{ R: float64(c.col[0]), G: float64(c.col[1]), B: float64(c.col[2]), A: float64(c.col[3]), }) mainthread.CallNonBlock(func() { c.setGlhfBounds() c.gf.Frame().Begin() glhf.Clear( float32(rgba.R), float32(rgba.G), float32(rgba.B), float32(rgba.A), ) c.gf.Frame().End() }) }
go
func (c *Canvas) Clear(color color.Color) { c.gf.Dirty() rgba := pixel.ToRGBA(color) // color masking rgba = rgba.Mul(pixel.RGBA{ R: float64(c.col[0]), G: float64(c.col[1]), B: float64(c.col[2]), A: float64(c.col[3]), }) mainthread.CallNonBlock(func() { c.setGlhfBounds() c.gf.Frame().Begin() glhf.Clear( float32(rgba.R), float32(rgba.G), float32(rgba.B), float32(rgba.A), ) c.gf.Frame().End() }) }
[ "func", "(", "c", "*", "Canvas", ")", "Clear", "(", "color", "color", ".", "Color", ")", "{", "c", ".", "gf", ".", "Dirty", "(", ")", "\n", "rgba", ":=", "pixel", ".", "ToRGBA", "(", "color", ")", "\n", "rgba", "=", "rgba", ".", "Mul", "(", "pixel", ".", "RGBA", "{", "R", ":", "float64", "(", "c", ".", "col", "[", "0", "]", ")", ",", "G", ":", "float64", "(", "c", ".", "col", "[", "1", "]", ")", ",", "B", ":", "float64", "(", "c", ".", "col", "[", "2", "]", ")", ",", "A", ":", "float64", "(", "c", ".", "col", "[", "3", "]", ")", ",", "}", ")", "\n", "mainthread", ".", "CallNonBlock", "(", "func", "(", ")", "{", "c", ".", "setGlhfBounds", "(", ")", "\n", "c", ".", "gf", ".", "Frame", "(", ")", ".", "Begin", "(", ")", "\n", "glhf", ".", "Clear", "(", "float32", "(", "rgba", ".", "R", ")", ",", "float32", "(", "rgba", ".", "G", ")", ",", "float32", "(", "rgba", ".", "B", ")", ",", "float32", "(", "rgba", ".", "A", ")", ",", ")", "\n", "c", ".", "gf", ".", "Frame", "(", ")", ".", "End", "(", ")", "\n", "}", ")", "\n", "}" ]
// Clear fills the whole Canvas with a single color.
[ "Clear", "fills", "the", "whole", "Canvas", "with", "a", "single", "color", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/pixelgl/canvas.go#L188-L212
train
faiface/pixel
pixelgl/canvas.go
Color
func (c *Canvas) Color(at pixel.Vec) pixel.RGBA { return c.gf.Color(at) }
go
func (c *Canvas) Color(at pixel.Vec) pixel.RGBA { return c.gf.Color(at) }
[ "func", "(", "c", "*", "Canvas", ")", "Color", "(", "at", "pixel", ".", "Vec", ")", "pixel", ".", "RGBA", "{", "return", "c", ".", "gf", ".", "Color", "(", "at", ")", "\n", "}" ]
// Color returns the color of the pixel over the given position inside the Canvas.
[ "Color", "returns", "the", "color", "of", "the", "pixel", "over", "the", "given", "position", "inside", "the", "Canvas", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/pixelgl/canvas.go#L215-L217
train
faiface/pixel
pixelgl/canvas.go
Pixels
func (c *Canvas) Pixels() []uint8 { var pixels []uint8 mainthread.Call(func() { tex := c.Texture() tex.Begin() pixels = tex.Pixels(0, 0, tex.Width(), tex.Height()) tex.End() }) return pixels }
go
func (c *Canvas) Pixels() []uint8 { var pixels []uint8 mainthread.Call(func() { tex := c.Texture() tex.Begin() pixels = tex.Pixels(0, 0, tex.Width(), tex.Height()) tex.End() }) return pixels }
[ "func", "(", "c", "*", "Canvas", ")", "Pixels", "(", ")", "[", "]", "uint8", "{", "var", "pixels", "[", "]", "uint8", "\n", "mainthread", ".", "Call", "(", "func", "(", ")", "{", "tex", ":=", "c", ".", "Texture", "(", ")", "\n", "tex", ".", "Begin", "(", ")", "\n", "pixels", "=", "tex", ".", "Pixels", "(", "0", ",", "0", ",", "tex", ".", "Width", "(", ")", ",", "tex", ".", "Height", "(", ")", ")", "\n", "tex", ".", "End", "(", ")", "\n", "}", ")", "\n", "return", "pixels", "\n", "}" ]
// Pixels returns an alpha-premultiplied RGBA sequence of the content of the Canvas.
[ "Pixels", "returns", "an", "alpha", "-", "premultiplied", "RGBA", "sequence", "of", "the", "content", "of", "the", "Canvas", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/pixelgl/canvas.go#L245-L256
train
faiface/pixel
pixelgl/canvas.go
Draw
func (c *Canvas) Draw(t pixel.Target, matrix pixel.Matrix) { c.sprite.Draw(t, matrix) }
go
func (c *Canvas) Draw(t pixel.Target, matrix pixel.Matrix) { c.sprite.Draw(t, matrix) }
[ "func", "(", "c", "*", "Canvas", ")", "Draw", "(", "t", "pixel", ".", "Target", ",", "matrix", "pixel", ".", "Matrix", ")", "{", "c", ".", "sprite", ".", "Draw", "(", "t", ",", "matrix", ")", "\n", "}" ]
// Draw draws the content of the Canvas onto another Target, transformed by the given Matrix, just // like if it was a Sprite containing the whole Canvas.
[ "Draw", "draws", "the", "content", "of", "the", "Canvas", "onto", "another", "Target", "transformed", "by", "the", "given", "Matrix", "just", "like", "if", "it", "was", "a", "Sprite", "containing", "the", "whole", "Canvas", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/pixelgl/canvas.go#L260-L262
train
faiface/pixel
pixelgl/canvas.go
DrawColorMask
func (c *Canvas) DrawColorMask(t pixel.Target, matrix pixel.Matrix, mask color.Color) { c.sprite.DrawColorMask(t, matrix, mask) }
go
func (c *Canvas) DrawColorMask(t pixel.Target, matrix pixel.Matrix, mask color.Color) { c.sprite.DrawColorMask(t, matrix, mask) }
[ "func", "(", "c", "*", "Canvas", ")", "DrawColorMask", "(", "t", "pixel", ".", "Target", ",", "matrix", "pixel", ".", "Matrix", ",", "mask", "color", ".", "Color", ")", "{", "c", ".", "sprite", ".", "DrawColorMask", "(", "t", ",", "matrix", ",", "mask", ")", "\n", "}" ]
// DrawColorMask draws the content of the Canvas onto another Target, transformed by the given // Matrix and multiplied by the given mask, just like if it was a Sprite containing the whole Canvas. // // If the color mask is nil, a fully opaque white mask will be used causing no effect.
[ "DrawColorMask", "draws", "the", "content", "of", "the", "Canvas", "onto", "another", "Target", "transformed", "by", "the", "given", "Matrix", "and", "multiplied", "by", "the", "given", "mask", "just", "like", "if", "it", "was", "a", "Sprite", "containing", "the", "whole", "Canvas", ".", "If", "the", "color", "mask", "is", "nil", "a", "fully", "opaque", "white", "mask", "will", "be", "used", "causing", "no", "effect", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/pixelgl/canvas.go#L268-L270
train
faiface/pixel
pixelgl/joystick.go
JoystickPresent
func (w *Window) JoystickPresent(js Joystick) bool { return w.currJoy.connected[js] }
go
func (w *Window) JoystickPresent(js Joystick) bool { return w.currJoy.connected[js] }
[ "func", "(", "w", "*", "Window", ")", "JoystickPresent", "(", "js", "Joystick", ")", "bool", "{", "return", "w", ".", "currJoy", ".", "connected", "[", "js", "]", "\n", "}" ]
// JoystickPresent returns if the joystick is currently connected. // // This API is experimental.
[ "JoystickPresent", "returns", "if", "the", "joystick", "is", "currently", "connected", ".", "This", "API", "is", "experimental", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/pixelgl/joystick.go#L35-L37
train
faiface/pixel
pixelgl/joystick.go
JoystickName
func (w *Window) JoystickName(js Joystick) string { return w.currJoy.name[js] }
go
func (w *Window) JoystickName(js Joystick) string { return w.currJoy.name[js] }
[ "func", "(", "w", "*", "Window", ")", "JoystickName", "(", "js", "Joystick", ")", "string", "{", "return", "w", ".", "currJoy", ".", "name", "[", "js", "]", "\n", "}" ]
// JoystickName returns the name of the joystick. A disconnected joystick will return an // empty string. // // This API is experimental.
[ "JoystickName", "returns", "the", "name", "of", "the", "joystick", ".", "A", "disconnected", "joystick", "will", "return", "an", "empty", "string", ".", "This", "API", "is", "experimental", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/pixelgl/joystick.go#L43-L45
train
faiface/pixel
pixelgl/joystick.go
JoystickButtonCount
func (w *Window) JoystickButtonCount(js Joystick) int { return len(w.currJoy.buttons[js]) }
go
func (w *Window) JoystickButtonCount(js Joystick) int { return len(w.currJoy.buttons[js]) }
[ "func", "(", "w", "*", "Window", ")", "JoystickButtonCount", "(", "js", "Joystick", ")", "int", "{", "return", "len", "(", "w", ".", "currJoy", ".", "buttons", "[", "js", "]", ")", "\n", "}" ]
// JoystickButtonCount returns the number of buttons a connected joystick has. // // This API is experimental.
[ "JoystickButtonCount", "returns", "the", "number", "of", "buttons", "a", "connected", "joystick", "has", ".", "This", "API", "is", "experimental", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/pixelgl/joystick.go#L50-L52
train
faiface/pixel
pixelgl/joystick.go
JoystickAxisCount
func (w *Window) JoystickAxisCount(js Joystick) int { return len(w.currJoy.axis[js]) }
go
func (w *Window) JoystickAxisCount(js Joystick) int { return len(w.currJoy.axis[js]) }
[ "func", "(", "w", "*", "Window", ")", "JoystickAxisCount", "(", "js", "Joystick", ")", "int", "{", "return", "len", "(", "w", ".", "currJoy", ".", "axis", "[", "js", "]", ")", "\n", "}" ]
// JoystickAxisCount returns the number of axes a connected joystick has. // // This API is experimental.
[ "JoystickAxisCount", "returns", "the", "number", "of", "axes", "a", "connected", "joystick", "has", ".", "This", "API", "is", "experimental", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/pixelgl/joystick.go#L57-L59
train
faiface/pixel
pixelgl/joystick.go
JoystickPressed
func (w *Window) JoystickPressed(js Joystick, button int) bool { return w.currJoy.getButton(js, button) }
go
func (w *Window) JoystickPressed(js Joystick, button int) bool { return w.currJoy.getButton(js, button) }
[ "func", "(", "w", "*", "Window", ")", "JoystickPressed", "(", "js", "Joystick", ",", "button", "int", ")", "bool", "{", "return", "w", ".", "currJoy", ".", "getButton", "(", "js", ",", "button", ")", "\n", "}" ]
// JoystickPressed returns whether the joystick Button is currently pressed down. // If the button index is out of range, this will return false. // // This API is experimental.
[ "JoystickPressed", "returns", "whether", "the", "joystick", "Button", "is", "currently", "pressed", "down", ".", "If", "the", "button", "index", "is", "out", "of", "range", "this", "will", "return", "false", ".", "This", "API", "is", "experimental", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/pixelgl/joystick.go#L65-L67
train
faiface/pixel
pixelgl/joystick.go
JoystickJustPressed
func (w *Window) JoystickJustPressed(js Joystick, button int) bool { return w.currJoy.getButton(js, button) && !w.prevJoy.getButton(js, button) }
go
func (w *Window) JoystickJustPressed(js Joystick, button int) bool { return w.currJoy.getButton(js, button) && !w.prevJoy.getButton(js, button) }
[ "func", "(", "w", "*", "Window", ")", "JoystickJustPressed", "(", "js", "Joystick", ",", "button", "int", ")", "bool", "{", "return", "w", ".", "currJoy", ".", "getButton", "(", "js", ",", "button", ")", "&&", "!", "w", ".", "prevJoy", ".", "getButton", "(", "js", ",", "button", ")", "\n", "}" ]
// JoystickJustPressed returns whether the joystick Button has just been pressed down. // If the button index is out of range, this will return false. // // This API is experimental.
[ "JoystickJustPressed", "returns", "whether", "the", "joystick", "Button", "has", "just", "been", "pressed", "down", ".", "If", "the", "button", "index", "is", "out", "of", "range", "this", "will", "return", "false", ".", "This", "API", "is", "experimental", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/pixelgl/joystick.go#L73-L75
train
faiface/pixel
pixelgl/joystick.go
JoystickAxis
func (w *Window) JoystickAxis(js Joystick, axis int) float64 { return w.currJoy.getAxis(js, axis) }
go
func (w *Window) JoystickAxis(js Joystick, axis int) float64 { return w.currJoy.getAxis(js, axis) }
[ "func", "(", "w", "*", "Window", ")", "JoystickAxis", "(", "js", "Joystick", ",", "axis", "int", ")", "float64", "{", "return", "w", ".", "currJoy", ".", "getAxis", "(", "js", ",", "axis", ")", "\n", "}" ]
// JoystickAxis returns the value of a joystick axis at the last call to Window.Update. // If the axis index is out of range, this will return 0. // // This API is experimental.
[ "JoystickAxis", "returns", "the", "value", "of", "a", "joystick", "axis", "at", "the", "last", "call", "to", "Window", ".", "Update", ".", "If", "the", "axis", "index", "is", "out", "of", "range", "this", "will", "return", "0", ".", "This", "API", "is", "experimental", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/pixelgl/joystick.go#L89-L91
train
faiface/pixel
pixelgl/joystick.go
updateJoystickInput
func (w *Window) updateJoystickInput() { for js := Joystick1; js <= JoystickLast; js++ { // Determine and store if the joystick was connected joystickPresent := glfw.JoystickPresent(glfw.Joystick(js)) w.tempJoy.connected[js] = joystickPresent if joystickPresent { w.tempJoy.buttons[js] = glfw.GetJoystickButtons(glfw.Joystick(js)) w.tempJoy.axis[js] = glfw.GetJoystickAxes(glfw.Joystick(js)) if !w.currJoy.connected[js] { // The joystick was recently connected, we get the name w.tempJoy.name[js] = glfw.GetJoystickName(glfw.Joystick(js)) } else { // Use the name from the previous one w.tempJoy.name[js] = w.currJoy.name[js] } } else { w.tempJoy.buttons[js] = []byte{} w.tempJoy.axis[js] = []float32{} w.tempJoy.name[js] = "" } } w.prevJoy = w.currJoy w.currJoy = w.tempJoy }
go
func (w *Window) updateJoystickInput() { for js := Joystick1; js <= JoystickLast; js++ { // Determine and store if the joystick was connected joystickPresent := glfw.JoystickPresent(glfw.Joystick(js)) w.tempJoy.connected[js] = joystickPresent if joystickPresent { w.tempJoy.buttons[js] = glfw.GetJoystickButtons(glfw.Joystick(js)) w.tempJoy.axis[js] = glfw.GetJoystickAxes(glfw.Joystick(js)) if !w.currJoy.connected[js] { // The joystick was recently connected, we get the name w.tempJoy.name[js] = glfw.GetJoystickName(glfw.Joystick(js)) } else { // Use the name from the previous one w.tempJoy.name[js] = w.currJoy.name[js] } } else { w.tempJoy.buttons[js] = []byte{} w.tempJoy.axis[js] = []float32{} w.tempJoy.name[js] = "" } } w.prevJoy = w.currJoy w.currJoy = w.tempJoy }
[ "func", "(", "w", "*", "Window", ")", "updateJoystickInput", "(", ")", "{", "for", "js", ":=", "Joystick1", ";", "js", "<=", "JoystickLast", ";", "js", "++", "{", "joystickPresent", ":=", "glfw", ".", "JoystickPresent", "(", "glfw", ".", "Joystick", "(", "js", ")", ")", "\n", "w", ".", "tempJoy", ".", "connected", "[", "js", "]", "=", "joystickPresent", "\n", "if", "joystickPresent", "{", "w", ".", "tempJoy", ".", "buttons", "[", "js", "]", "=", "glfw", ".", "GetJoystickButtons", "(", "glfw", ".", "Joystick", "(", "js", ")", ")", "\n", "w", ".", "tempJoy", ".", "axis", "[", "js", "]", "=", "glfw", ".", "GetJoystickAxes", "(", "glfw", ".", "Joystick", "(", "js", ")", ")", "\n", "if", "!", "w", ".", "currJoy", ".", "connected", "[", "js", "]", "{", "w", ".", "tempJoy", ".", "name", "[", "js", "]", "=", "glfw", ".", "GetJoystickName", "(", "glfw", ".", "Joystick", "(", "js", ")", ")", "\n", "}", "else", "{", "w", ".", "tempJoy", ".", "name", "[", "js", "]", "=", "w", ".", "currJoy", ".", "name", "[", "js", "]", "\n", "}", "\n", "}", "else", "{", "w", ".", "tempJoy", ".", "buttons", "[", "js", "]", "=", "[", "]", "byte", "{", "}", "\n", "w", ".", "tempJoy", ".", "axis", "[", "js", "]", "=", "[", "]", "float32", "{", "}", "\n", "w", ".", "tempJoy", ".", "name", "[", "js", "]", "=", "\"\"", "\n", "}", "\n", "}", "\n", "w", ".", "prevJoy", "=", "w", ".", "currJoy", "\n", "w", ".", "currJoy", "=", "w", ".", "tempJoy", "\n", "}" ]
// Used internally during Window.UpdateInput to update the state of the joysticks.
[ "Used", "internally", "during", "Window", ".", "UpdateInput", "to", "update", "the", "state", "of", "the", "joysticks", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/pixelgl/joystick.go#L94-L120
train
faiface/pixel
pixelgl/joystick.go
getButton
func (js *joystickState) getButton(joystick Joystick, button int) bool { // Check that the joystick and button is valid, return false by default if js.buttons[joystick] == nil || button >= len(js.buttons[joystick]) || button < 0 { return false } return js.buttons[joystick][byte(button)] == 1 }
go
func (js *joystickState) getButton(joystick Joystick, button int) bool { // Check that the joystick and button is valid, return false by default if js.buttons[joystick] == nil || button >= len(js.buttons[joystick]) || button < 0 { return false } return js.buttons[joystick][byte(button)] == 1 }
[ "func", "(", "js", "*", "joystickState", ")", "getButton", "(", "joystick", "Joystick", ",", "button", "int", ")", "bool", "{", "if", "js", ".", "buttons", "[", "joystick", "]", "==", "nil", "||", "button", ">=", "len", "(", "js", ".", "buttons", "[", "joystick", "]", ")", "||", "button", "<", "0", "{", "return", "false", "\n", "}", "\n", "return", "js", ".", "buttons", "[", "joystick", "]", "[", "byte", "(", "button", ")", "]", "==", "1", "\n", "}" ]
// Returns if a button on a joystick is down, returning false if the button or joystick is invalid.
[ "Returns", "if", "a", "button", "on", "a", "joystick", "is", "down", "returning", "false", "if", "the", "button", "or", "joystick", "is", "invalid", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/pixelgl/joystick.go#L130-L136
train
faiface/pixel
pixelgl/joystick.go
getAxis
func (js *joystickState) getAxis(joystick Joystick, axis int) float64 { // Check that the joystick and axis is valid, return 0 by default. if js.axis[joystick] == nil || axis >= len(js.axis[joystick]) || axis < 0 { return 0 } return float64(js.axis[joystick][axis]) }
go
func (js *joystickState) getAxis(joystick Joystick, axis int) float64 { // Check that the joystick and axis is valid, return 0 by default. if js.axis[joystick] == nil || axis >= len(js.axis[joystick]) || axis < 0 { return 0 } return float64(js.axis[joystick][axis]) }
[ "func", "(", "js", "*", "joystickState", ")", "getAxis", "(", "joystick", "Joystick", ",", "axis", "int", ")", "float64", "{", "if", "js", ".", "axis", "[", "joystick", "]", "==", "nil", "||", "axis", ">=", "len", "(", "js", ".", "axis", "[", "joystick", "]", ")", "||", "axis", "<", "0", "{", "return", "0", "\n", "}", "\n", "return", "float64", "(", "js", ".", "axis", "[", "joystick", "]", "[", "axis", "]", ")", "\n", "}" ]
// Returns the value of a joystick axis, returning 0 if the button or joystick is invalid.
[ "Returns", "the", "value", "of", "a", "joystick", "axis", "returning", "0", "if", "the", "button", "or", "joystick", "is", "invalid", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/pixelgl/joystick.go#L139-L145
train
faiface/pixel
sprite.go
NewSprite
func NewSprite(pic Picture, frame Rect) *Sprite { tri := MakeTrianglesData(6) s := &Sprite{ tri: tri, d: Drawer{Triangles: tri}, } s.matrix = IM s.mask = Alpha(1) s.Set(pic, frame) return s }
go
func NewSprite(pic Picture, frame Rect) *Sprite { tri := MakeTrianglesData(6) s := &Sprite{ tri: tri, d: Drawer{Triangles: tri}, } s.matrix = IM s.mask = Alpha(1) s.Set(pic, frame) return s }
[ "func", "NewSprite", "(", "pic", "Picture", ",", "frame", "Rect", ")", "*", "Sprite", "{", "tri", ":=", "MakeTrianglesData", "(", "6", ")", "\n", "s", ":=", "&", "Sprite", "{", "tri", ":", "tri", ",", "d", ":", "Drawer", "{", "Triangles", ":", "tri", "}", ",", "}", "\n", "s", ".", "matrix", "=", "IM", "\n", "s", ".", "mask", "=", "Alpha", "(", "1", ")", "\n", "s", ".", "Set", "(", "pic", ",", "frame", ")", "\n", "return", "s", "\n", "}" ]
// NewSprite creates a Sprite from the supplied frame of a Picture.
[ "NewSprite", "creates", "a", "Sprite", "from", "the", "supplied", "frame", "of", "a", "Picture", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/sprite.go#L26-L36
train
faiface/pixel
sprite.go
Set
func (s *Sprite) Set(pic Picture, frame Rect) { s.d.Picture = pic if frame != s.frame { s.frame = frame s.calcData() } }
go
func (s *Sprite) Set(pic Picture, frame Rect) { s.d.Picture = pic if frame != s.frame { s.frame = frame s.calcData() } }
[ "func", "(", "s", "*", "Sprite", ")", "Set", "(", "pic", "Picture", ",", "frame", "Rect", ")", "{", "s", ".", "d", ".", "Picture", "=", "pic", "\n", "if", "frame", "!=", "s", ".", "frame", "{", "s", ".", "frame", "=", "frame", "\n", "s", ".", "calcData", "(", ")", "\n", "}", "\n", "}" ]
// Set sets a new frame of a Picture for this Sprite.
[ "Set", "sets", "a", "new", "frame", "of", "a", "Picture", "for", "this", "Sprite", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/sprite.go#L39-L45
train
faiface/pixel
sprite.go
Draw
func (s *Sprite) Draw(t Target, matrix Matrix) { s.DrawColorMask(t, matrix, nil) }
go
func (s *Sprite) Draw(t Target, matrix Matrix) { s.DrawColorMask(t, matrix, nil) }
[ "func", "(", "s", "*", "Sprite", ")", "Draw", "(", "t", "Target", ",", "matrix", "Matrix", ")", "{", "s", ".", "DrawColorMask", "(", "t", ",", "matrix", ",", "nil", ")", "\n", "}" ]
// Draw draws the Sprite onto the provided Target. The Sprite will be transformed by the given Matrix. // // This method is equivalent to calling DrawColorMask with nil color mask.
[ "Draw", "draws", "the", "Sprite", "onto", "the", "provided", "Target", ".", "The", "Sprite", "will", "be", "transformed", "by", "the", "given", "Matrix", ".", "This", "method", "is", "equivalent", "to", "calling", "DrawColorMask", "with", "nil", "color", "mask", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/sprite.go#L60-L62
train
faiface/pixel
sprite.go
DrawColorMask
func (s *Sprite) DrawColorMask(t Target, matrix Matrix, mask color.Color) { dirty := false if matrix != s.matrix { s.matrix = matrix dirty = true } if mask == nil { mask = Alpha(1) } rgba := ToRGBA(mask) if rgba != s.mask { s.mask = rgba dirty = true } if dirty { s.calcData() } s.d.Draw(t) }
go
func (s *Sprite) DrawColorMask(t Target, matrix Matrix, mask color.Color) { dirty := false if matrix != s.matrix { s.matrix = matrix dirty = true } if mask == nil { mask = Alpha(1) } rgba := ToRGBA(mask) if rgba != s.mask { s.mask = rgba dirty = true } if dirty { s.calcData() } s.d.Draw(t) }
[ "func", "(", "s", "*", "Sprite", ")", "DrawColorMask", "(", "t", "Target", ",", "matrix", "Matrix", ",", "mask", "color", ".", "Color", ")", "{", "dirty", ":=", "false", "\n", "if", "matrix", "!=", "s", ".", "matrix", "{", "s", ".", "matrix", "=", "matrix", "\n", "dirty", "=", "true", "\n", "}", "\n", "if", "mask", "==", "nil", "{", "mask", "=", "Alpha", "(", "1", ")", "\n", "}", "\n", "rgba", ":=", "ToRGBA", "(", "mask", ")", "\n", "if", "rgba", "!=", "s", ".", "mask", "{", "s", ".", "mask", "=", "rgba", "\n", "dirty", "=", "true", "\n", "}", "\n", "if", "dirty", "{", "s", ".", "calcData", "(", ")", "\n", "}", "\n", "s", ".", "d", ".", "Draw", "(", "t", ")", "\n", "}" ]
// DrawColorMask draws the Sprite onto the provided Target. The Sprite will be transformed by the // given Matrix and all of it's color will be multiplied by the given mask. // // If the mask is nil, a fully opaque white mask will be used, which causes no effect.
[ "DrawColorMask", "draws", "the", "Sprite", "onto", "the", "provided", "Target", ".", "The", "Sprite", "will", "be", "transformed", "by", "the", "given", "Matrix", "and", "all", "of", "it", "s", "color", "will", "be", "multiplied", "by", "the", "given", "mask", ".", "If", "the", "mask", "is", "nil", "a", "fully", "opaque", "white", "mask", "will", "be", "used", "which", "causes", "no", "effect", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/sprite.go#L68-L88
train
faiface/pixel
compose.go
Compose
func (cm ComposeMethod) Compose(a, b RGBA) RGBA { var fa, fb float64 switch cm { case ComposeOver: fa, fb = 1, 1-a.A case ComposeIn: fa, fb = b.A, 0 case ComposeOut: fa, fb = 1-b.A, 0 case ComposeAtop: fa, fb = b.A, 1-a.A case ComposeRover: fa, fb = 1-b.A, 1 case ComposeRin: fa, fb = 0, a.A case ComposeRout: fa, fb = 0, 1-a.A case ComposeRatop: fa, fb = 1-b.A, a.A case ComposeXor: fa, fb = 1-b.A, 1-a.A case ComposePlus: fa, fb = 1, 1 case ComposeCopy: fa, fb = 1, 0 default: panic(errors.New("Compose: invalid ComposeMethod")) } return a.Mul(Alpha(fa)).Add(b.Mul(Alpha(fb))) }
go
func (cm ComposeMethod) Compose(a, b RGBA) RGBA { var fa, fb float64 switch cm { case ComposeOver: fa, fb = 1, 1-a.A case ComposeIn: fa, fb = b.A, 0 case ComposeOut: fa, fb = 1-b.A, 0 case ComposeAtop: fa, fb = b.A, 1-a.A case ComposeRover: fa, fb = 1-b.A, 1 case ComposeRin: fa, fb = 0, a.A case ComposeRout: fa, fb = 0, 1-a.A case ComposeRatop: fa, fb = 1-b.A, a.A case ComposeXor: fa, fb = 1-b.A, 1-a.A case ComposePlus: fa, fb = 1, 1 case ComposeCopy: fa, fb = 1, 0 default: panic(errors.New("Compose: invalid ComposeMethod")) } return a.Mul(Alpha(fa)).Add(b.Mul(Alpha(fb))) }
[ "func", "(", "cm", "ComposeMethod", ")", "Compose", "(", "a", ",", "b", "RGBA", ")", "RGBA", "{", "var", "fa", ",", "fb", "float64", "\n", "switch", "cm", "{", "case", "ComposeOver", ":", "fa", ",", "fb", "=", "1", ",", "1", "-", "a", ".", "A", "\n", "case", "ComposeIn", ":", "fa", ",", "fb", "=", "b", ".", "A", ",", "0", "\n", "case", "ComposeOut", ":", "fa", ",", "fb", "=", "1", "-", "b", ".", "A", ",", "0", "\n", "case", "ComposeAtop", ":", "fa", ",", "fb", "=", "b", ".", "A", ",", "1", "-", "a", ".", "A", "\n", "case", "ComposeRover", ":", "fa", ",", "fb", "=", "1", "-", "b", ".", "A", ",", "1", "\n", "case", "ComposeRin", ":", "fa", ",", "fb", "=", "0", ",", "a", ".", "A", "\n", "case", "ComposeRout", ":", "fa", ",", "fb", "=", "0", ",", "1", "-", "a", ".", "A", "\n", "case", "ComposeRatop", ":", "fa", ",", "fb", "=", "1", "-", "b", ".", "A", ",", "a", ".", "A", "\n", "case", "ComposeXor", ":", "fa", ",", "fb", "=", "1", "-", "b", ".", "A", ",", "1", "-", "a", ".", "A", "\n", "case", "ComposePlus", ":", "fa", ",", "fb", "=", "1", ",", "1", "\n", "case", "ComposeCopy", ":", "fa", ",", "fb", "=", "1", ",", "0", "\n", "default", ":", "panic", "(", "errors", ".", "New", "(", "\"Compose: invalid ComposeMethod\"", ")", ")", "\n", "}", "\n", "return", "a", ".", "Mul", "(", "Alpha", "(", "fa", ")", ")", ".", "Add", "(", "b", ".", "Mul", "(", "Alpha", "(", "fb", ")", ")", ")", "\n", "}" ]
// Compose composes two colors together according to the ComposeMethod. A is the foreground, B is // the background.
[ "Compose", "composes", "two", "colors", "together", "according", "to", "the", "ComposeMethod", ".", "A", "is", "the", "foreground", "B", "is", "the", "background", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/compose.go#L34-L65
train
faiface/pixel
batch.go
NewBatch
func NewBatch(container Triangles, pic Picture) *Batch { b := &Batch{cont: Drawer{Triangles: container, Picture: pic}} b.SetMatrix(IM) b.SetColorMask(Alpha(1)) return b }
go
func NewBatch(container Triangles, pic Picture) *Batch { b := &Batch{cont: Drawer{Triangles: container, Picture: pic}} b.SetMatrix(IM) b.SetColorMask(Alpha(1)) return b }
[ "func", "NewBatch", "(", "container", "Triangles", ",", "pic", "Picture", ")", "*", "Batch", "{", "b", ":=", "&", "Batch", "{", "cont", ":", "Drawer", "{", "Triangles", ":", "container", ",", "Picture", ":", "pic", "}", "}", "\n", "b", ".", "SetMatrix", "(", "IM", ")", "\n", "b", ".", "SetColorMask", "(", "Alpha", "(", "1", ")", ")", "\n", "return", "b", "\n", "}" ]
// NewBatch creates an empty Batch with the specified Picture and container. // // The container is where objects get accumulated. Batch will support precisely those Triangles // properties, that the supplied container supports. If you retain access to the container and // change it, call Dirty to notify Batch about the change. // // Note, that if the container does not support TrianglesColor, color masking will not work.
[ "NewBatch", "creates", "an", "empty", "Batch", "with", "the", "specified", "Picture", "and", "container", ".", "The", "container", "is", "where", "objects", "get", "accumulated", ".", "Batch", "will", "support", "precisely", "those", "Triangles", "properties", "that", "the", "supplied", "container", "supports", ".", "If", "you", "retain", "access", "to", "the", "container", "and", "change", "it", "call", "Dirty", "to", "notify", "Batch", "about", "the", "change", ".", "Note", "that", "if", "the", "container", "does", "not", "support", "TrianglesColor", "color", "masking", "will", "not", "work", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/batch.go#L28-L33
train
faiface/pixel
batch.go
Clear
func (b *Batch) Clear() { b.cont.Triangles.SetLen(0) b.cont.Dirty() }
go
func (b *Batch) Clear() { b.cont.Triangles.SetLen(0) b.cont.Dirty() }
[ "func", "(", "b", "*", "Batch", ")", "Clear", "(", ")", "{", "b", ".", "cont", ".", "Triangles", ".", "SetLen", "(", "0", ")", "\n", "b", ".", "cont", ".", "Dirty", "(", ")", "\n", "}" ]
// Clear removes all objects from the Batch.
[ "Clear", "removes", "all", "objects", "from", "the", "Batch", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/batch.go#L47-L50
train
faiface/pixel
batch.go
SetColorMask
func (b *Batch) SetColorMask(c color.Color) { if c == nil { b.col = Alpha(1) return } b.col = ToRGBA(c) }
go
func (b *Batch) SetColorMask(c color.Color) { if c == nil { b.col = Alpha(1) return } b.col = ToRGBA(c) }
[ "func", "(", "b", "*", "Batch", ")", "SetColorMask", "(", "c", "color", ".", "Color", ")", "{", "if", "c", "==", "nil", "{", "b", ".", "col", "=", "Alpha", "(", "1", ")", "\n", "return", "\n", "}", "\n", "b", ".", "col", "=", "ToRGBA", "(", "c", ")", "\n", "}" ]
// SetColorMask sets a mask color used in the following draws onto the Batch.
[ "SetColorMask", "sets", "a", "mask", "color", "used", "in", "the", "following", "draws", "onto", "the", "Batch", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/batch.go#L63-L69
train
faiface/pixel
batch.go
MakeTriangles
func (b *Batch) MakeTriangles(t Triangles) TargetTriangles { bt := &batchTriangles{ tri: t.Copy(), tmp: MakeTrianglesData(t.Len()), dst: b, } return bt }
go
func (b *Batch) MakeTriangles(t Triangles) TargetTriangles { bt := &batchTriangles{ tri: t.Copy(), tmp: MakeTrianglesData(t.Len()), dst: b, } return bt }
[ "func", "(", "b", "*", "Batch", ")", "MakeTriangles", "(", "t", "Triangles", ")", "TargetTriangles", "{", "bt", ":=", "&", "batchTriangles", "{", "tri", ":", "t", ".", "Copy", "(", ")", ",", "tmp", ":", "MakeTrianglesData", "(", "t", ".", "Len", "(", ")", ")", ",", "dst", ":", "b", ",", "}", "\n", "return", "bt", "\n", "}" ]
// MakeTriangles returns a specialized copy of the provided Triangles that draws onto this Batch.
[ "MakeTriangles", "returns", "a", "specialized", "copy", "of", "the", "provided", "Triangles", "that", "draws", "onto", "this", "Batch", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/batch.go#L72-L79
train
faiface/pixel
batch.go
MakePicture
func (b *Batch) MakePicture(p Picture) TargetPicture { if p != b.cont.Picture { panic(fmt.Errorf("(%T).MakePicture: Picture is not the Batch's Picture", b)) } bp := &batchPicture{ pic: p, dst: b, } return bp }
go
func (b *Batch) MakePicture(p Picture) TargetPicture { if p != b.cont.Picture { panic(fmt.Errorf("(%T).MakePicture: Picture is not the Batch's Picture", b)) } bp := &batchPicture{ pic: p, dst: b, } return bp }
[ "func", "(", "b", "*", "Batch", ")", "MakePicture", "(", "p", "Picture", ")", "TargetPicture", "{", "if", "p", "!=", "b", ".", "cont", ".", "Picture", "{", "panic", "(", "fmt", ".", "Errorf", "(", "\"(%T).MakePicture: Picture is not the Batch's Picture\"", ",", "b", ")", ")", "\n", "}", "\n", "bp", ":=", "&", "batchPicture", "{", "pic", ":", "p", ",", "dst", ":", "b", ",", "}", "\n", "return", "bp", "\n", "}" ]
// MakePicture returns a specialized copy of the provided Picture that draws onto this Batch.
[ "MakePicture", "returns", "a", "specialized", "copy", "of", "the", "provided", "Picture", "that", "draws", "onto", "this", "Batch", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/batch.go#L82-L91
train
faiface/pixel
drawer.go
Dirty
func (d *Drawer) Dirty() { d.lazyInit() for _, t := range d.targets { t.clean = false } }
go
func (d *Drawer) Dirty() { d.lazyInit() for _, t := range d.targets { t.clean = false } }
[ "func", "(", "d", "*", "Drawer", ")", "Dirty", "(", ")", "{", "d", ".", "lazyInit", "(", ")", "\n", "for", "_", ",", "t", ":=", "range", "d", ".", "targets", "{", "t", ".", "clean", "=", "false", "\n", "}", "\n", "}" ]
// Dirty marks the Triangles of this Drawer as changed. If not called, changes will not be visible // when drawing.
[ "Dirty", "marks", "the", "Triangles", "of", "this", "Drawer", "as", "changed", ".", "If", "not", "called", "changes", "will", "not", "be", "visible", "when", "drawing", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/drawer.go#L46-L52
train
faiface/pixel
drawer.go
Draw
func (d *Drawer) Draw(t Target) { d.lazyInit() if d.Triangles == nil { return } dt := d.targets[t] if dt == nil { dt = &drawerTarget{ pics: make(map[Picture]TargetPicture), } d.targets[t] = dt } if dt.tris == nil { dt.tris = t.MakeTriangles(d.Triangles) dt.clean = true } if !dt.clean { dt.tris.SetLen(d.Triangles.Len()) dt.tris.Update(d.Triangles) dt.clean = true } if d.Picture == nil { dt.tris.Draw() return } pic := dt.pics[d.Picture] if pic == nil { pic = t.MakePicture(d.Picture) dt.pics[d.Picture] = pic } pic.Draw(dt.tris) }
go
func (d *Drawer) Draw(t Target) { d.lazyInit() if d.Triangles == nil { return } dt := d.targets[t] if dt == nil { dt = &drawerTarget{ pics: make(map[Picture]TargetPicture), } d.targets[t] = dt } if dt.tris == nil { dt.tris = t.MakeTriangles(d.Triangles) dt.clean = true } if !dt.clean { dt.tris.SetLen(d.Triangles.Len()) dt.tris.Update(d.Triangles) dt.clean = true } if d.Picture == nil { dt.tris.Draw() return } pic := dt.pics[d.Picture] if pic == nil { pic = t.MakePicture(d.Picture) dt.pics[d.Picture] = pic } pic.Draw(dt.tris) }
[ "func", "(", "d", "*", "Drawer", ")", "Draw", "(", "t", "Target", ")", "{", "d", ".", "lazyInit", "(", ")", "\n", "if", "d", ".", "Triangles", "==", "nil", "{", "return", "\n", "}", "\n", "dt", ":=", "d", ".", "targets", "[", "t", "]", "\n", "if", "dt", "==", "nil", "{", "dt", "=", "&", "drawerTarget", "{", "pics", ":", "make", "(", "map", "[", "Picture", "]", "TargetPicture", ")", ",", "}", "\n", "d", ".", "targets", "[", "t", "]", "=", "dt", "\n", "}", "\n", "if", "dt", ".", "tris", "==", "nil", "{", "dt", ".", "tris", "=", "t", ".", "MakeTriangles", "(", "d", ".", "Triangles", ")", "\n", "dt", ".", "clean", "=", "true", "\n", "}", "\n", "if", "!", "dt", ".", "clean", "{", "dt", ".", "tris", ".", "SetLen", "(", "d", ".", "Triangles", ".", "Len", "(", ")", ")", "\n", "dt", ".", "tris", ".", "Update", "(", "d", ".", "Triangles", ")", "\n", "dt", ".", "clean", "=", "true", "\n", "}", "\n", "if", "d", ".", "Picture", "==", "nil", "{", "dt", ".", "tris", ".", "Draw", "(", ")", "\n", "return", "\n", "}", "\n", "pic", ":=", "dt", ".", "pics", "[", "d", ".", "Picture", "]", "\n", "if", "pic", "==", "nil", "{", "pic", "=", "t", ".", "MakePicture", "(", "d", ".", "Picture", ")", "\n", "dt", ".", "pics", "[", "d", ".", "Picture", "]", "=", "pic", "\n", "}", "\n", "pic", ".", "Draw", "(", "dt", ".", "tris", ")", "\n", "}" ]
// Draw efficiently draws Triangles with Picture onto the provided Target. // // If Triangles is nil, nothing will be drawn. If Picture is nil, Triangles will be drawn without a // Picture.
[ "Draw", "efficiently", "draws", "Triangles", "with", "Picture", "onto", "the", "provided", "Target", ".", "If", "Triangles", "is", "nil", "nothing", "will", "be", "drawn", ".", "If", "Picture", "is", "nil", "Triangles", "will", "be", "drawn", "without", "a", "Picture", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/drawer.go#L58-L96
train
faiface/pixel
pixelgl/glframe.go
NewGLFrame
func NewGLFrame(bounds pixel.Rect) *GLFrame { gf := new(GLFrame) gf.SetBounds(bounds) return gf }
go
func NewGLFrame(bounds pixel.Rect) *GLFrame { gf := new(GLFrame) gf.SetBounds(bounds) return gf }
[ "func", "NewGLFrame", "(", "bounds", "pixel", ".", "Rect", ")", "*", "GLFrame", "{", "gf", ":=", "new", "(", "GLFrame", ")", "\n", "gf", ".", "SetBounds", "(", "bounds", ")", "\n", "return", "gf", "\n", "}" ]
// NewGLFrame creates a new GLFrame with the given bounds.
[ "NewGLFrame", "creates", "a", "new", "GLFrame", "with", "the", "given", "bounds", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/pixelgl/glframe.go#L19-L23
train
faiface/pixel
pixelgl/glframe.go
SetBounds
func (gf *GLFrame) SetBounds(bounds pixel.Rect) { if bounds == gf.Bounds() { return } mainthread.Call(func() { oldF := gf.frame _, _, w, h := intBounds(bounds) if w <= 0 { w = 1 } if h <= 0 { h = 1 } gf.frame = glhf.NewFrame(w, h, false) // preserve old content if oldF != nil { ox, oy, ow, oh := intBounds(bounds) oldF.Blit( gf.frame, ox, oy, ox+ow, oy+oh, ox, oy, ox+ow, oy+oh, ) } }) gf.bounds = bounds gf.pixels = nil gf.dirty = true }
go
func (gf *GLFrame) SetBounds(bounds pixel.Rect) { if bounds == gf.Bounds() { return } mainthread.Call(func() { oldF := gf.frame _, _, w, h := intBounds(bounds) if w <= 0 { w = 1 } if h <= 0 { h = 1 } gf.frame = glhf.NewFrame(w, h, false) // preserve old content if oldF != nil { ox, oy, ow, oh := intBounds(bounds) oldF.Blit( gf.frame, ox, oy, ox+ow, oy+oh, ox, oy, ox+ow, oy+oh, ) } }) gf.bounds = bounds gf.pixels = nil gf.dirty = true }
[ "func", "(", "gf", "*", "GLFrame", ")", "SetBounds", "(", "bounds", "pixel", ".", "Rect", ")", "{", "if", "bounds", "==", "gf", ".", "Bounds", "(", ")", "{", "return", "\n", "}", "\n", "mainthread", ".", "Call", "(", "func", "(", ")", "{", "oldF", ":=", "gf", ".", "frame", "\n", "_", ",", "_", ",", "w", ",", "h", ":=", "intBounds", "(", "bounds", ")", "\n", "if", "w", "<=", "0", "{", "w", "=", "1", "\n", "}", "\n", "if", "h", "<=", "0", "{", "h", "=", "1", "\n", "}", "\n", "gf", ".", "frame", "=", "glhf", ".", "NewFrame", "(", "w", ",", "h", ",", "false", ")", "\n", "if", "oldF", "!=", "nil", "{", "ox", ",", "oy", ",", "ow", ",", "oh", ":=", "intBounds", "(", "bounds", ")", "\n", "oldF", ".", "Blit", "(", "gf", ".", "frame", ",", "ox", ",", "oy", ",", "ox", "+", "ow", ",", "oy", "+", "oh", ",", "ox", ",", "oy", ",", "ox", "+", "ow", ",", "oy", "+", "oh", ",", ")", "\n", "}", "\n", "}", ")", "\n", "gf", ".", "bounds", "=", "bounds", "\n", "gf", ".", "pixels", "=", "nil", "\n", "gf", ".", "dirty", "=", "true", "\n", "}" ]
// SetBounds resizes the GLFrame to the new bounds.
[ "SetBounds", "resizes", "the", "GLFrame", "to", "the", "new", "bounds", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/pixelgl/glframe.go#L26-L57
train
faiface/pixel
pixelgl/glframe.go
Color
func (gf *GLFrame) Color(at pixel.Vec) pixel.RGBA { if gf.dirty { mainthread.Call(func() { tex := gf.frame.Texture() tex.Begin() gf.pixels = tex.Pixels(0, 0, tex.Width(), tex.Height()) tex.End() }) gf.dirty = false } if !gf.bounds.Contains(at) { return pixel.Alpha(0) } bx, by, bw, _ := intBounds(gf.bounds) x, y := int(at.X)-bx, int(at.Y)-by off := y*bw + x return pixel.RGBA{ R: float64(gf.pixels[off*4+0]) / 255, G: float64(gf.pixels[off*4+1]) / 255, B: float64(gf.pixels[off*4+2]) / 255, A: float64(gf.pixels[off*4+3]) / 255, } }
go
func (gf *GLFrame) Color(at pixel.Vec) pixel.RGBA { if gf.dirty { mainthread.Call(func() { tex := gf.frame.Texture() tex.Begin() gf.pixels = tex.Pixels(0, 0, tex.Width(), tex.Height()) tex.End() }) gf.dirty = false } if !gf.bounds.Contains(at) { return pixel.Alpha(0) } bx, by, bw, _ := intBounds(gf.bounds) x, y := int(at.X)-bx, int(at.Y)-by off := y*bw + x return pixel.RGBA{ R: float64(gf.pixels[off*4+0]) / 255, G: float64(gf.pixels[off*4+1]) / 255, B: float64(gf.pixels[off*4+2]) / 255, A: float64(gf.pixels[off*4+3]) / 255, } }
[ "func", "(", "gf", "*", "GLFrame", ")", "Color", "(", "at", "pixel", ".", "Vec", ")", "pixel", ".", "RGBA", "{", "if", "gf", ".", "dirty", "{", "mainthread", ".", "Call", "(", "func", "(", ")", "{", "tex", ":=", "gf", ".", "frame", ".", "Texture", "(", ")", "\n", "tex", ".", "Begin", "(", ")", "\n", "gf", ".", "pixels", "=", "tex", ".", "Pixels", "(", "0", ",", "0", ",", "tex", ".", "Width", "(", ")", ",", "tex", ".", "Height", "(", ")", ")", "\n", "tex", ".", "End", "(", ")", "\n", "}", ")", "\n", "gf", ".", "dirty", "=", "false", "\n", "}", "\n", "if", "!", "gf", ".", "bounds", ".", "Contains", "(", "at", ")", "{", "return", "pixel", ".", "Alpha", "(", "0", ")", "\n", "}", "\n", "bx", ",", "by", ",", "bw", ",", "_", ":=", "intBounds", "(", "gf", ".", "bounds", ")", "\n", "x", ",", "y", ":=", "int", "(", "at", ".", "X", ")", "-", "bx", ",", "int", "(", "at", ".", "Y", ")", "-", "by", "\n", "off", ":=", "y", "*", "bw", "+", "x", "\n", "return", "pixel", ".", "RGBA", "{", "R", ":", "float64", "(", "gf", ".", "pixels", "[", "off", "*", "4", "+", "0", "]", ")", "/", "255", ",", "G", ":", "float64", "(", "gf", ".", "pixels", "[", "off", "*", "4", "+", "1", "]", ")", "/", "255", ",", "B", ":", "float64", "(", "gf", ".", "pixels", "[", "off", "*", "4", "+", "2", "]", ")", "/", "255", ",", "A", ":", "float64", "(", "gf", ".", "pixels", "[", "off", "*", "4", "+", "3", "]", ")", "/", "255", ",", "}", "\n", "}" ]
// Color returns the color of the pixel under the specified position.
[ "Color", "returns", "the", "color", "of", "the", "pixel", "under", "the", "specified", "position", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/pixelgl/glframe.go#L65-L87
train
faiface/pixel
pixelgl/gltriangles.go
NewGLTriangles
func NewGLTriangles(shader *glhf.Shader, t pixel.Triangles) *GLTriangles { var gt *GLTriangles mainthread.Call(func() { gt = &GLTriangles{ vs: glhf.MakeVertexSlice(shader, 0, t.Len()), shader: shader, } }) gt.SetLen(t.Len()) gt.Update(t) return gt }
go
func NewGLTriangles(shader *glhf.Shader, t pixel.Triangles) *GLTriangles { var gt *GLTriangles mainthread.Call(func() { gt = &GLTriangles{ vs: glhf.MakeVertexSlice(shader, 0, t.Len()), shader: shader, } }) gt.SetLen(t.Len()) gt.Update(t) return gt }
[ "func", "NewGLTriangles", "(", "shader", "*", "glhf", ".", "Shader", ",", "t", "pixel", ".", "Triangles", ")", "*", "GLTriangles", "{", "var", "gt", "*", "GLTriangles", "\n", "mainthread", ".", "Call", "(", "func", "(", ")", "{", "gt", "=", "&", "GLTriangles", "{", "vs", ":", "glhf", ".", "MakeVertexSlice", "(", "shader", ",", "0", ",", "t", ".", "Len", "(", ")", ")", ",", "shader", ":", "shader", ",", "}", "\n", "}", ")", "\n", "gt", ".", "SetLen", "(", "t", ".", "Len", "(", ")", ")", "\n", "gt", ".", "Update", "(", "t", ")", "\n", "return", "gt", "\n", "}" ]
// NewGLTriangles returns GLTriangles initialized with the data from the supplied Triangles. // // Only draw the Triangles using the provided Shader.
[ "NewGLTriangles", "returns", "GLTriangles", "initialized", "with", "the", "data", "from", "the", "supplied", "Triangles", ".", "Only", "draw", "the", "Triangles", "using", "the", "provided", "Shader", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/pixelgl/gltriangles.go#L30-L41
train
faiface/pixel
pixelgl/gltriangles.go
Len
func (gt *GLTriangles) Len() int { return len(gt.data) / gt.vs.Stride() }
go
func (gt *GLTriangles) Len() int { return len(gt.data) / gt.vs.Stride() }
[ "func", "(", "gt", "*", "GLTriangles", ")", "Len", "(", ")", "int", "{", "return", "len", "(", "gt", ".", "data", ")", "/", "gt", ".", "vs", ".", "Stride", "(", ")", "\n", "}" ]
// Len returns the number of vertices.
[ "Len", "returns", "the", "number", "of", "vertices", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/pixelgl/gltriangles.go#L56-L58
train
faiface/pixel
pixelgl/gltriangles.go
Slice
func (gt *GLTriangles) Slice(i, j int) pixel.Triangles { return &GLTriangles{ vs: gt.vs.Slice(i, j), data: gt.data[i*gt.vs.Stride() : j*gt.vs.Stride()], shader: gt.shader, } }
go
func (gt *GLTriangles) Slice(i, j int) pixel.Triangles { return &GLTriangles{ vs: gt.vs.Slice(i, j), data: gt.data[i*gt.vs.Stride() : j*gt.vs.Stride()], shader: gt.shader, } }
[ "func", "(", "gt", "*", "GLTriangles", ")", "Slice", "(", "i", ",", "j", "int", ")", "pixel", ".", "Triangles", "{", "return", "&", "GLTriangles", "{", "vs", ":", "gt", ".", "vs", ".", "Slice", "(", "i", ",", "j", ")", ",", "data", ":", "gt", ".", "data", "[", "i", "*", "gt", ".", "vs", ".", "Stride", "(", ")", ":", "j", "*", "gt", ".", "vs", ".", "Stride", "(", ")", "]", ",", "shader", ":", "gt", ".", "shader", ",", "}", "\n", "}" ]
// Slice returns a sub-Triangles of this GLTriangles in range [i, j).
[ "Slice", "returns", "a", "sub", "-", "Triangles", "of", "this", "GLTriangles", "in", "range", "[", "i", "j", ")", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/pixelgl/gltriangles.go#L88-L94
train
faiface/pixel
pixelgl/gltriangles.go
Position
func (gt *GLTriangles) Position(i int) pixel.Vec { px := gt.data[i*gt.vs.Stride()+0] py := gt.data[i*gt.vs.Stride()+1] return pixel.V(float64(px), float64(py)) }
go
func (gt *GLTriangles) Position(i int) pixel.Vec { px := gt.data[i*gt.vs.Stride()+0] py := gt.data[i*gt.vs.Stride()+1] return pixel.V(float64(px), float64(py)) }
[ "func", "(", "gt", "*", "GLTriangles", ")", "Position", "(", "i", "int", ")", "pixel", ".", "Vec", "{", "px", ":=", "gt", ".", "data", "[", "i", "*", "gt", ".", "vs", ".", "Stride", "(", ")", "+", "0", "]", "\n", "py", ":=", "gt", ".", "data", "[", "i", "*", "gt", ".", "vs", ".", "Stride", "(", ")", "+", "1", "]", "\n", "return", "pixel", ".", "V", "(", "float64", "(", "px", ")", ",", "float64", "(", "py", ")", ")", "\n", "}" ]
// Position returns the Position property of the i-th vertex.
[ "Position", "returns", "the", "Position", "property", "of", "the", "i", "-", "th", "vertex", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/pixelgl/gltriangles.go#L189-L193
train
faiface/pixel
pixelgl/gltriangles.go
Color
func (gt *GLTriangles) Color(i int) pixel.RGBA { r := gt.data[i*gt.vs.Stride()+2] g := gt.data[i*gt.vs.Stride()+3] b := gt.data[i*gt.vs.Stride()+4] a := gt.data[i*gt.vs.Stride()+5] return pixel.RGBA{ R: float64(r), G: float64(g), B: float64(b), A: float64(a), } }
go
func (gt *GLTriangles) Color(i int) pixel.RGBA { r := gt.data[i*gt.vs.Stride()+2] g := gt.data[i*gt.vs.Stride()+3] b := gt.data[i*gt.vs.Stride()+4] a := gt.data[i*gt.vs.Stride()+5] return pixel.RGBA{ R: float64(r), G: float64(g), B: float64(b), A: float64(a), } }
[ "func", "(", "gt", "*", "GLTriangles", ")", "Color", "(", "i", "int", ")", "pixel", ".", "RGBA", "{", "r", ":=", "gt", ".", "data", "[", "i", "*", "gt", ".", "vs", ".", "Stride", "(", ")", "+", "2", "]", "\n", "g", ":=", "gt", ".", "data", "[", "i", "*", "gt", ".", "vs", ".", "Stride", "(", ")", "+", "3", "]", "\n", "b", ":=", "gt", ".", "data", "[", "i", "*", "gt", ".", "vs", ".", "Stride", "(", ")", "+", "4", "]", "\n", "a", ":=", "gt", ".", "data", "[", "i", "*", "gt", ".", "vs", ".", "Stride", "(", ")", "+", "5", "]", "\n", "return", "pixel", ".", "RGBA", "{", "R", ":", "float64", "(", "r", ")", ",", "G", ":", "float64", "(", "g", ")", ",", "B", ":", "float64", "(", "b", ")", ",", "A", ":", "float64", "(", "a", ")", ",", "}", "\n", "}" ]
// Color returns the Color property of the i-th vertex.
[ "Color", "returns", "the", "Color", "property", "of", "the", "i", "-", "th", "vertex", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/pixelgl/gltriangles.go#L196-L207
train
faiface/pixel
pixelgl/gltriangles.go
Picture
func (gt *GLTriangles) Picture(i int) (pic pixel.Vec, intensity float64) { tx := gt.data[i*gt.vs.Stride()+6] ty := gt.data[i*gt.vs.Stride()+7] intensity = float64(gt.data[i*gt.vs.Stride()+8]) return pixel.V(float64(tx), float64(ty)), intensity }
go
func (gt *GLTriangles) Picture(i int) (pic pixel.Vec, intensity float64) { tx := gt.data[i*gt.vs.Stride()+6] ty := gt.data[i*gt.vs.Stride()+7] intensity = float64(gt.data[i*gt.vs.Stride()+8]) return pixel.V(float64(tx), float64(ty)), intensity }
[ "func", "(", "gt", "*", "GLTriangles", ")", "Picture", "(", "i", "int", ")", "(", "pic", "pixel", ".", "Vec", ",", "intensity", "float64", ")", "{", "tx", ":=", "gt", ".", "data", "[", "i", "*", "gt", ".", "vs", ".", "Stride", "(", ")", "+", "6", "]", "\n", "ty", ":=", "gt", ".", "data", "[", "i", "*", "gt", ".", "vs", ".", "Stride", "(", ")", "+", "7", "]", "\n", "intensity", "=", "float64", "(", "gt", ".", "data", "[", "i", "*", "gt", ".", "vs", ".", "Stride", "(", ")", "+", "8", "]", ")", "\n", "return", "pixel", ".", "V", "(", "float64", "(", "tx", ")", ",", "float64", "(", "ty", ")", ")", ",", "intensity", "\n", "}" ]
// Picture returns the Picture property of the i-th vertex.
[ "Picture", "returns", "the", "Picture", "property", "of", "the", "i", "-", "th", "vertex", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/pixelgl/gltriangles.go#L210-L215
train
faiface/pixel
color.go
RGB
func RGB(r, g, b float64) RGBA { return RGBA{r, g, b, 1} }
go
func RGB(r, g, b float64) RGBA { return RGBA{r, g, b, 1} }
[ "func", "RGB", "(", "r", ",", "g", ",", "b", "float64", ")", "RGBA", "{", "return", "RGBA", "{", "r", ",", "g", ",", "b", ",", "1", "}", "\n", "}" ]
// RGB returns a fully opaque RGBA color with the given RGB values. // // A common way to construct a transparent color is to create one with RGB constructor, then // multiply it by a color obtained from the Alpha constructor.
[ "RGB", "returns", "a", "fully", "opaque", "RGBA", "color", "with", "the", "given", "RGB", "values", ".", "A", "common", "way", "to", "construct", "a", "transparent", "color", "is", "to", "create", "one", "with", "RGB", "constructor", "then", "multiply", "it", "by", "a", "color", "obtained", "from", "the", "Alpha", "constructor", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/color.go#L16-L18
train
faiface/pixel
color.go
RGBA
func (c RGBA) RGBA() (r, g, b, a uint32) { r = uint32(0xffff * c.R) g = uint32(0xffff * c.G) b = uint32(0xffff * c.B) a = uint32(0xffff * c.A) return }
go
func (c RGBA) RGBA() (r, g, b, a uint32) { r = uint32(0xffff * c.R) g = uint32(0xffff * c.G) b = uint32(0xffff * c.B) a = uint32(0xffff * c.A) return }
[ "func", "(", "c", "RGBA", ")", "RGBA", "(", ")", "(", "r", ",", "g", ",", "b", ",", "a", "uint32", ")", "{", "r", "=", "uint32", "(", "0xffff", "*", "c", ".", "R", ")", "\n", "g", "=", "uint32", "(", "0xffff", "*", "c", ".", "G", ")", "\n", "b", "=", "uint32", "(", "0xffff", "*", "c", ".", "B", ")", "\n", "a", "=", "uint32", "(", "0xffff", "*", "c", ".", "A", ")", "\n", "return", "\n", "}" ]
// RGBA returns alpha-premultiplied red, green, blue and alpha components of the RGBA color.
[ "RGBA", "returns", "alpha", "-", "premultiplied", "red", "green", "blue", "and", "alpha", "components", "of", "the", "RGBA", "color", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/color.go#L69-L75
train
faiface/pixel
pixelgl/monitor.go
Monitors
func Monitors() []*Monitor { var monitors []*Monitor mainthread.Call(func() { for _, monitor := range glfw.GetMonitors() { monitors = append(monitors, &Monitor{monitor: monitor}) } }) return monitors }
go
func Monitors() []*Monitor { var monitors []*Monitor mainthread.Call(func() { for _, monitor := range glfw.GetMonitors() { monitors = append(monitors, &Monitor{monitor: monitor}) } }) return monitors }
[ "func", "Monitors", "(", ")", "[", "]", "*", "Monitor", "{", "var", "monitors", "[", "]", "*", "Monitor", "\n", "mainthread", ".", "Call", "(", "func", "(", ")", "{", "for", "_", ",", "monitor", ":=", "range", "glfw", ".", "GetMonitors", "(", ")", "{", "monitors", "=", "append", "(", "monitors", ",", "&", "Monitor", "{", "monitor", ":", "monitor", "}", ")", "\n", "}", "\n", "}", ")", "\n", "return", "monitors", "\n", "}" ]
// Monitors returns a slice of all currently available monitors.
[ "Monitors", "returns", "a", "slice", "of", "all", "currently", "available", "monitors", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/pixelgl/monitor.go#L36-L44
train
faiface/pixel
pixelgl/monitor.go
Name
func (m *Monitor) Name() string { var name string mainthread.Call(func() { name = m.monitor.GetName() }) return name }
go
func (m *Monitor) Name() string { var name string mainthread.Call(func() { name = m.monitor.GetName() }) return name }
[ "func", "(", "m", "*", "Monitor", ")", "Name", "(", ")", "string", "{", "var", "name", "string", "\n", "mainthread", ".", "Call", "(", "func", "(", ")", "{", "name", "=", "m", ".", "monitor", ".", "GetName", "(", ")", "\n", "}", ")", "\n", "return", "name", "\n", "}" ]
// Name returns a human-readable name of the Monitor.
[ "Name", "returns", "a", "human", "-", "readable", "name", "of", "the", "Monitor", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/pixelgl/monitor.go#L47-L53
train
faiface/pixel
pixelgl/monitor.go
PhysicalSize
func (m *Monitor) PhysicalSize() (width, height float64) { var wi, hi int mainthread.Call(func() { wi, hi = m.monitor.GetPhysicalSize() }) width = float64(wi) height = float64(hi) return }
go
func (m *Monitor) PhysicalSize() (width, height float64) { var wi, hi int mainthread.Call(func() { wi, hi = m.monitor.GetPhysicalSize() }) width = float64(wi) height = float64(hi) return }
[ "func", "(", "m", "*", "Monitor", ")", "PhysicalSize", "(", ")", "(", "width", ",", "height", "float64", ")", "{", "var", "wi", ",", "hi", "int", "\n", "mainthread", ".", "Call", "(", "func", "(", ")", "{", "wi", ",", "hi", "=", "m", ".", "monitor", ".", "GetPhysicalSize", "(", ")", "\n", "}", ")", "\n", "width", "=", "float64", "(", "wi", ")", "\n", "height", "=", "float64", "(", "hi", ")", "\n", "return", "\n", "}" ]
// PhysicalSize returns the size of the display area of the Monitor in millimeters.
[ "PhysicalSize", "returns", "the", "size", "of", "the", "display", "area", "of", "the", "Monitor", "in", "millimeters", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/pixelgl/monitor.go#L56-L64
train
faiface/pixel
pixelgl/monitor.go
Position
func (m *Monitor) Position() (x, y float64) { var xi, yi int mainthread.Call(func() { xi, yi = m.monitor.GetPos() }) x = float64(xi) y = float64(yi) return }
go
func (m *Monitor) Position() (x, y float64) { var xi, yi int mainthread.Call(func() { xi, yi = m.monitor.GetPos() }) x = float64(xi) y = float64(yi) return }
[ "func", "(", "m", "*", "Monitor", ")", "Position", "(", ")", "(", "x", ",", "y", "float64", ")", "{", "var", "xi", ",", "yi", "int", "\n", "mainthread", ".", "Call", "(", "func", "(", ")", "{", "xi", ",", "yi", "=", "m", ".", "monitor", ".", "GetPos", "(", ")", "\n", "}", ")", "\n", "x", "=", "float64", "(", "xi", ")", "\n", "y", "=", "float64", "(", "yi", ")", "\n", "return", "\n", "}" ]
// Position returns the position of the upper-left corner of the Monitor in screen coordinates.
[ "Position", "returns", "the", "position", "of", "the", "upper", "-", "left", "corner", "of", "the", "Monitor", "in", "screen", "coordinates", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/pixelgl/monitor.go#L67-L75
train
faiface/pixel
pixelgl/monitor.go
Size
func (m *Monitor) Size() (width, height float64) { var mode *glfw.VidMode mainthread.Call(func() { mode = m.monitor.GetVideoMode() }) width = float64(mode.Width) height = float64(mode.Height) return }
go
func (m *Monitor) Size() (width, height float64) { var mode *glfw.VidMode mainthread.Call(func() { mode = m.monitor.GetVideoMode() }) width = float64(mode.Width) height = float64(mode.Height) return }
[ "func", "(", "m", "*", "Monitor", ")", "Size", "(", ")", "(", "width", ",", "height", "float64", ")", "{", "var", "mode", "*", "glfw", ".", "VidMode", "\n", "mainthread", ".", "Call", "(", "func", "(", ")", "{", "mode", "=", "m", ".", "monitor", ".", "GetVideoMode", "(", ")", "\n", "}", ")", "\n", "width", "=", "float64", "(", "mode", ".", "Width", ")", "\n", "height", "=", "float64", "(", "mode", ".", "Height", ")", "\n", "return", "\n", "}" ]
// Size returns the resolution of the Monitor in pixels.
[ "Size", "returns", "the", "resolution", "of", "the", "Monitor", "in", "pixels", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/pixelgl/monitor.go#L78-L86
train
faiface/pixel
pixelgl/monitor.go
BitDepth
func (m *Monitor) BitDepth() (red, green, blue int) { var mode *glfw.VidMode mainthread.Call(func() { mode = m.monitor.GetVideoMode() }) red = mode.RedBits green = mode.GreenBits blue = mode.BlueBits return }
go
func (m *Monitor) BitDepth() (red, green, blue int) { var mode *glfw.VidMode mainthread.Call(func() { mode = m.monitor.GetVideoMode() }) red = mode.RedBits green = mode.GreenBits blue = mode.BlueBits return }
[ "func", "(", "m", "*", "Monitor", ")", "BitDepth", "(", ")", "(", "red", ",", "green", ",", "blue", "int", ")", "{", "var", "mode", "*", "glfw", ".", "VidMode", "\n", "mainthread", ".", "Call", "(", "func", "(", ")", "{", "mode", "=", "m", ".", "monitor", ".", "GetVideoMode", "(", ")", "\n", "}", ")", "\n", "red", "=", "mode", ".", "RedBits", "\n", "green", "=", "mode", ".", "GreenBits", "\n", "blue", "=", "mode", ".", "BlueBits", "\n", "return", "\n", "}" ]
// BitDepth returns the number of bits per color of the Monitor.
[ "BitDepth", "returns", "the", "number", "of", "bits", "per", "color", "of", "the", "Monitor", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/pixelgl/monitor.go#L89-L98
train
faiface/pixel
pixelgl/monitor.go
VideoModes
func (m *Monitor) VideoModes() (vmodes []VideoMode) { var modes []*glfw.VidMode mainthread.Call(func() { modes = m.monitor.GetVideoModes() }) for _, mode := range modes { vmodes = append(vmodes, VideoMode{ Width: mode.Width, Height: mode.Height, RefreshRate: mode.RefreshRate, }) } return }
go
func (m *Monitor) VideoModes() (vmodes []VideoMode) { var modes []*glfw.VidMode mainthread.Call(func() { modes = m.monitor.GetVideoModes() }) for _, mode := range modes { vmodes = append(vmodes, VideoMode{ Width: mode.Width, Height: mode.Height, RefreshRate: mode.RefreshRate, }) } return }
[ "func", "(", "m", "*", "Monitor", ")", "VideoModes", "(", ")", "(", "vmodes", "[", "]", "VideoMode", ")", "{", "var", "modes", "[", "]", "*", "glfw", ".", "VidMode", "\n", "mainthread", ".", "Call", "(", "func", "(", ")", "{", "modes", "=", "m", ".", "monitor", ".", "GetVideoModes", "(", ")", "\n", "}", ")", "\n", "for", "_", ",", "mode", ":=", "range", "modes", "{", "vmodes", "=", "append", "(", "vmodes", ",", "VideoMode", "{", "Width", ":", "mode", ".", "Width", ",", "Height", ":", "mode", ".", "Height", ",", "RefreshRate", ":", "mode", ".", "RefreshRate", ",", "}", ")", "\n", "}", "\n", "return", "\n", "}" ]
// VideoModes returns all available video modes for the monitor.
[ "VideoModes", "returns", "all", "available", "video", "modes", "for", "the", "monitor", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/pixelgl/monitor.go#L111-L124
train
faiface/pixel
geometry.go
nearlyEqual
func nearlyEqual(a, b float64) bool { epsilon := 0.000001 if a == b { return true } diff := math.Abs(a - b) if a == 0.0 || b == 0.0 || diff < math.SmallestNonzeroFloat64 { return diff < (epsilon * math.SmallestNonzeroFloat64) } absA := math.Abs(a) absB := math.Abs(b) return diff/math.Min(absA+absB, math.MaxFloat64) < epsilon }
go
func nearlyEqual(a, b float64) bool { epsilon := 0.000001 if a == b { return true } diff := math.Abs(a - b) if a == 0.0 || b == 0.0 || diff < math.SmallestNonzeroFloat64 { return diff < (epsilon * math.SmallestNonzeroFloat64) } absA := math.Abs(a) absB := math.Abs(b) return diff/math.Min(absA+absB, math.MaxFloat64) < epsilon }
[ "func", "nearlyEqual", "(", "a", ",", "b", "float64", ")", "bool", "{", "epsilon", ":=", "0.000001", "\n", "if", "a", "==", "b", "{", "return", "true", "\n", "}", "\n", "diff", ":=", "math", ".", "Abs", "(", "a", "-", "b", ")", "\n", "if", "a", "==", "0.0", "||", "b", "==", "0.0", "||", "diff", "<", "math", ".", "SmallestNonzeroFloat64", "{", "return", "diff", "<", "(", "epsilon", "*", "math", ".", "SmallestNonzeroFloat64", ")", "\n", "}", "\n", "absA", ":=", "math", ".", "Abs", "(", "a", ")", "\n", "absB", ":=", "math", ".", "Abs", "(", "b", ")", "\n", "return", "diff", "/", "math", ".", "Min", "(", "absA", "+", "absB", ",", "math", ".", "MaxFloat64", ")", "<", "epsilon", "\n", "}" ]
// nearlyEqual compares two float64s and returns whether they are equal, accounting for rounding errors.At worst, the // result is correct to 7 significant digits.
[ "nearlyEqual", "compares", "two", "float64s", "and", "returns", "whether", "they", "are", "equal", "accounting", "for", "rounding", "errors", ".", "At", "worst", "the", "result", "is", "correct", "to", "7", "significant", "digits", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/geometry.go#L54-L71
train
faiface/pixel
geometry.go
Eq
func (u Vec) Eq(v Vec) bool { return nearlyEqual(u.X, v.X) && nearlyEqual(u.Y, v.Y) }
go
func (u Vec) Eq(v Vec) bool { return nearlyEqual(u.X, v.X) && nearlyEqual(u.Y, v.Y) }
[ "func", "(", "u", "Vec", ")", "Eq", "(", "v", "Vec", ")", "bool", "{", "return", "nearlyEqual", "(", "u", ".", "X", ",", "v", ".", "X", ")", "&&", "nearlyEqual", "(", "u", ".", "Y", ",", "v", ".", "Y", ")", "\n", "}" ]
// Eq will compare two vectors and return whether they are equal accounting for rounding errors. At worst, the result // is correct to 7 significant digits.
[ "Eq", "will", "compare", "two", "vectors", "and", "return", "whether", "they", "are", "equal", "accounting", "for", "rounding", "errors", ".", "At", "worst", "the", "result", "is", "correct", "to", "7", "significant", "digits", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/geometry.go#L75-L77
train
faiface/pixel
geometry.go
XY
func (u Vec) XY() (x, y float64) { return u.X, u.Y }
go
func (u Vec) XY() (x, y float64) { return u.X, u.Y }
[ "func", "(", "u", "Vec", ")", "XY", "(", ")", "(", "x", ",", "y", "float64", ")", "{", "return", "u", ".", "X", ",", "u", ".", "Y", "\n", "}" ]
// XY returns the components of the vector in two return values.
[ "XY", "returns", "the", "components", "of", "the", "vector", "in", "two", "return", "values", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/geometry.go#L94-L96
train
faiface/pixel
geometry.go
Add
func (u Vec) Add(v Vec) Vec { return Vec{ u.X + v.X, u.Y + v.Y, } }
go
func (u Vec) Add(v Vec) Vec { return Vec{ u.X + v.X, u.Y + v.Y, } }
[ "func", "(", "u", "Vec", ")", "Add", "(", "v", "Vec", ")", "Vec", "{", "return", "Vec", "{", "u", ".", "X", "+", "v", ".", "X", ",", "u", ".", "Y", "+", "v", ".", "Y", ",", "}", "\n", "}" ]
// Add returns the sum of vectors u and v.
[ "Add", "returns", "the", "sum", "of", "vectors", "u", "and", "v", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/geometry.go#L99-L104
train
faiface/pixel
geometry.go
Sub
func (u Vec) Sub(v Vec) Vec { return Vec{ u.X - v.X, u.Y - v.Y, } }
go
func (u Vec) Sub(v Vec) Vec { return Vec{ u.X - v.X, u.Y - v.Y, } }
[ "func", "(", "u", "Vec", ")", "Sub", "(", "v", "Vec", ")", "Vec", "{", "return", "Vec", "{", "u", ".", "X", "-", "v", ".", "X", ",", "u", ".", "Y", "-", "v", ".", "Y", ",", "}", "\n", "}" ]
// Sub returns the difference betweeen vectors u and v.
[ "Sub", "returns", "the", "difference", "betweeen", "vectors", "u", "and", "v", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/geometry.go#L107-L112
train
faiface/pixel
geometry.go
Floor
func (u Vec) Floor() Vec { return Vec{ math.Floor(u.X), math.Floor(u.Y), } }
go
func (u Vec) Floor() Vec { return Vec{ math.Floor(u.X), math.Floor(u.Y), } }
[ "func", "(", "u", "Vec", ")", "Floor", "(", ")", "Vec", "{", "return", "Vec", "{", "math", ".", "Floor", "(", "u", ".", "X", ")", ",", "math", ".", "Floor", "(", "u", ".", "Y", ")", ",", "}", "\n", "}" ]
// Floor converts x and y to their integer equivalents.
[ "Floor", "converts", "x", "and", "y", "to", "their", "integer", "equivalents", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/geometry.go#L115-L120
train
faiface/pixel
geometry.go
Scaled
func (u Vec) Scaled(c float64) Vec { return Vec{u.X * c, u.Y * c} }
go
func (u Vec) Scaled(c float64) Vec { return Vec{u.X * c, u.Y * c} }
[ "func", "(", "u", "Vec", ")", "Scaled", "(", "c", "float64", ")", "Vec", "{", "return", "Vec", "{", "u", ".", "X", "*", "c", ",", "u", ".", "Y", "*", "c", "}", "\n", "}" ]
// Scaled returns the vector u multiplied by c.
[ "Scaled", "returns", "the", "vector", "u", "multiplied", "by", "c", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/geometry.go#L131-L133
train
faiface/pixel
geometry.go
ScaledXY
func (u Vec) ScaledXY(v Vec) Vec { return Vec{u.X * v.X, u.Y * v.Y} }
go
func (u Vec) ScaledXY(v Vec) Vec { return Vec{u.X * v.X, u.Y * v.Y} }
[ "func", "(", "u", "Vec", ")", "ScaledXY", "(", "v", "Vec", ")", "Vec", "{", "return", "Vec", "{", "u", ".", "X", "*", "v", ".", "X", ",", "u", ".", "Y", "*", "v", ".", "Y", "}", "\n", "}" ]
// ScaledXY returns the vector u multiplied by the vector v component-wise.
[ "ScaledXY", "returns", "the", "vector", "u", "multiplied", "by", "the", "vector", "v", "component", "-", "wise", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/geometry.go#L136-L138
train
faiface/pixel
geometry.go
Len
func (u Vec) Len() float64 { return math.Hypot(u.X, u.Y) }
go
func (u Vec) Len() float64 { return math.Hypot(u.X, u.Y) }
[ "func", "(", "u", "Vec", ")", "Len", "(", ")", "float64", "{", "return", "math", ".", "Hypot", "(", "u", ".", "X", ",", "u", ".", "Y", ")", "\n", "}" ]
// Len returns the length of the vector u.
[ "Len", "returns", "the", "length", "of", "the", "vector", "u", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/geometry.go#L141-L143
train
faiface/pixel
geometry.go
Rotated
func (u Vec) Rotated(angle float64) Vec { sin, cos := math.Sincos(angle) return Vec{ u.X*cos - u.Y*sin, u.X*sin + u.Y*cos, } }
go
func (u Vec) Rotated(angle float64) Vec { sin, cos := math.Sincos(angle) return Vec{ u.X*cos - u.Y*sin, u.X*sin + u.Y*cos, } }
[ "func", "(", "u", "Vec", ")", "Rotated", "(", "angle", "float64", ")", "Vec", "{", "sin", ",", "cos", ":=", "math", ".", "Sincos", "(", "angle", ")", "\n", "return", "Vec", "{", "u", ".", "X", "*", "cos", "-", "u", ".", "Y", "*", "sin", ",", "u", ".", "X", "*", "sin", "+", "u", ".", "Y", "*", "cos", ",", "}", "\n", "}" ]
// Rotated returns the vector u rotated by the given angle in radians.
[ "Rotated", "returns", "the", "vector", "u", "rotated", "by", "the", "given", "angle", "in", "radians", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/geometry.go#L159-L165
train
faiface/pixel
geometry.go
Dot
func (u Vec) Dot(v Vec) float64 { return u.X*v.X + u.Y*v.Y }
go
func (u Vec) Dot(v Vec) float64 { return u.X*v.X + u.Y*v.Y }
[ "func", "(", "u", "Vec", ")", "Dot", "(", "v", "Vec", ")", "float64", "{", "return", "u", ".", "X", "*", "v", ".", "X", "+", "u", ".", "Y", "*", "v", ".", "Y", "\n", "}" ]
// Dot returns the dot product of vectors u and v.
[ "Dot", "returns", "the", "dot", "product", "of", "vectors", "u", "and", "v", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/geometry.go#L173-L175
train
faiface/pixel
geometry.go
Cross
func (u Vec) Cross(v Vec) float64 { return u.X*v.Y - v.X*u.Y }
go
func (u Vec) Cross(v Vec) float64 { return u.X*v.Y - v.X*u.Y }
[ "func", "(", "u", "Vec", ")", "Cross", "(", "v", "Vec", ")", "float64", "{", "return", "u", ".", "X", "*", "v", ".", "Y", "-", "v", ".", "X", "*", "u", ".", "Y", "\n", "}" ]
// Cross return the cross product of vectors u and v.
[ "Cross", "return", "the", "cross", "product", "of", "vectors", "u", "and", "v", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/geometry.go#L178-L180
train
faiface/pixel
geometry.go
Lerp
func Lerp(a, b Vec, t float64) Vec { return a.Scaled(1 - t).Add(b.Scaled(t)) }
go
func Lerp(a, b Vec, t float64) Vec { return a.Scaled(1 - t).Add(b.Scaled(t)) }
[ "func", "Lerp", "(", "a", ",", "b", "Vec", ",", "t", "float64", ")", "Vec", "{", "return", "a", ".", "Scaled", "(", "1", "-", "t", ")", ".", "Add", "(", "b", ".", "Scaled", "(", "t", ")", ")", "\n", "}" ]
// Lerp returns a linear interpolation between vectors a and b. // // This function basically returns a point along the line between a and b and t chooses which one. // If t is 0, then a will be returned, if t is 1, b will be returned. Anything between 0 and 1 will // return the appropriate point between a and b and so on.
[ "Lerp", "returns", "a", "linear", "interpolation", "between", "vectors", "a", "and", "b", ".", "This", "function", "basically", "returns", "a", "point", "along", "the", "line", "between", "a", "and", "b", "and", "t", "chooses", "which", "one", ".", "If", "t", "is", "0", "then", "a", "will", "be", "returned", "if", "t", "is", "1", "b", "will", "be", "returned", ".", "Anything", "between", "0", "and", "1", "will", "return", "the", "appropriate", "point", "between", "a", "and", "b", "and", "so", "on", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/geometry.go#L207-L209
train
faiface/pixel
geometry.go
L
func L(from, to Vec) Line { return Line{ A: from, B: to, } }
go
func L(from, to Vec) Line { return Line{ A: from, B: to, } }
[ "func", "L", "(", "from", ",", "to", "Vec", ")", "Line", "{", "return", "Line", "{", "A", ":", "from", ",", "B", ":", "to", ",", "}", "\n", "}" ]
// L creates and returns a new Line.
[ "L", "creates", "and", "returns", "a", "new", "Line", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/geometry.go#L217-L222
train
faiface/pixel
geometry.go
Bounds
func (l Line) Bounds() Rect { return R(l.A.X, l.A.Y, l.B.X, l.B.Y).Norm() }
go
func (l Line) Bounds() Rect { return R(l.A.X, l.A.Y, l.B.X, l.B.Y).Norm() }
[ "func", "(", "l", "Line", ")", "Bounds", "(", ")", "Rect", "{", "return", "R", "(", "l", ".", "A", ".", "X", ",", "l", ".", "A", ".", "Y", ",", "l", ".", "B", ".", "X", ",", "l", ".", "B", ".", "Y", ")", ".", "Norm", "(", ")", "\n", "}" ]
// Bounds returns the lines bounding box. This is in the form of a normalized Rect.
[ "Bounds", "returns", "the", "lines", "bounding", "box", ".", "This", "is", "in", "the", "form", "of", "a", "normalized", "Rect", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/geometry.go#L225-L227
train
faiface/pixel
geometry.go
Center
func (l Line) Center() Vec { return l.A.Add(l.A.To(l.B).Scaled(0.5)) }
go
func (l Line) Center() Vec { return l.A.Add(l.A.To(l.B).Scaled(0.5)) }
[ "func", "(", "l", "Line", ")", "Center", "(", ")", "Vec", "{", "return", "l", ".", "A", ".", "Add", "(", "l", ".", "A", ".", "To", "(", "l", ".", "B", ")", ".", "Scaled", "(", "0.5", ")", ")", "\n", "}" ]
// Center will return the point at center of the line; that is, the point equidistant from either end.
[ "Center", "will", "return", "the", "point", "at", "center", "of", "the", "line", ";", "that", "is", "the", "point", "equidistant", "from", "either", "end", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/geometry.go#L230-L232
train
faiface/pixel
geometry.go
Closest
func (l Line) Closest(v Vec) Vec { // between is a helper function which determines whether x is greater than min(a, b) and less than max(a, b) between := func(a, b, x float64) bool { min := math.Min(a, b) max := math.Max(a, b) return min < x && x < max } // Closest point will be on a line which perpendicular to this line. // If and only if the infinite perpendicular line intersects the segment. m, b := l.Formula() // Account for horizontal lines if m == 0 { x := v.X y := l.A.Y // check if the X coordinate of v is on the line if between(l.A.X, l.B.X, v.X) { return V(x, y) } // Otherwise get the closest endpoint if l.A.To(v).Len() < l.B.To(v).Len() { return l.A } return l.B } // Account for vertical lines if math.IsInf(math.Abs(m), 1) { x := l.A.X y := v.Y // check if the Y coordinate of v is on the line if between(l.A.Y, l.B.Y, v.Y) { return V(x, y) } // Otherwise get the closest endpoint if l.A.To(v).Len() < l.B.To(v).Len() { return l.A } return l.B } perpendicularM := -1 / m perpendicularB := v.Y - (perpendicularM * v.X) // Coordinates of intersect (of infinite lines) x := (perpendicularB - b) / (m - perpendicularM) y := m*x + b // Check if the point lies between the x and y bounds of the segment if !between(l.A.X, l.B.X, x) && !between(l.A.Y, l.B.Y, y) { // Not within bounding box toStart := v.To(l.A) toEnd := v.To(l.B) if toStart.Len() < toEnd.Len() { return l.A } return l.B } return V(x, y) }
go
func (l Line) Closest(v Vec) Vec { // between is a helper function which determines whether x is greater than min(a, b) and less than max(a, b) between := func(a, b, x float64) bool { min := math.Min(a, b) max := math.Max(a, b) return min < x && x < max } // Closest point will be on a line which perpendicular to this line. // If and only if the infinite perpendicular line intersects the segment. m, b := l.Formula() // Account for horizontal lines if m == 0 { x := v.X y := l.A.Y // check if the X coordinate of v is on the line if between(l.A.X, l.B.X, v.X) { return V(x, y) } // Otherwise get the closest endpoint if l.A.To(v).Len() < l.B.To(v).Len() { return l.A } return l.B } // Account for vertical lines if math.IsInf(math.Abs(m), 1) { x := l.A.X y := v.Y // check if the Y coordinate of v is on the line if between(l.A.Y, l.B.Y, v.Y) { return V(x, y) } // Otherwise get the closest endpoint if l.A.To(v).Len() < l.B.To(v).Len() { return l.A } return l.B } perpendicularM := -1 / m perpendicularB := v.Y - (perpendicularM * v.X) // Coordinates of intersect (of infinite lines) x := (perpendicularB - b) / (m - perpendicularM) y := m*x + b // Check if the point lies between the x and y bounds of the segment if !between(l.A.X, l.B.X, x) && !between(l.A.Y, l.B.Y, y) { // Not within bounding box toStart := v.To(l.A) toEnd := v.To(l.B) if toStart.Len() < toEnd.Len() { return l.A } return l.B } return V(x, y) }
[ "func", "(", "l", "Line", ")", "Closest", "(", "v", "Vec", ")", "Vec", "{", "between", ":=", "func", "(", "a", ",", "b", ",", "x", "float64", ")", "bool", "{", "min", ":=", "math", ".", "Min", "(", "a", ",", "b", ")", "\n", "max", ":=", "math", ".", "Max", "(", "a", ",", "b", ")", "\n", "return", "min", "<", "x", "&&", "x", "<", "max", "\n", "}", "\n", "m", ",", "b", ":=", "l", ".", "Formula", "(", ")", "\n", "if", "m", "==", "0", "{", "x", ":=", "v", ".", "X", "\n", "y", ":=", "l", ".", "A", ".", "Y", "\n", "if", "between", "(", "l", ".", "A", ".", "X", ",", "l", ".", "B", ".", "X", ",", "v", ".", "X", ")", "{", "return", "V", "(", "x", ",", "y", ")", "\n", "}", "\n", "if", "l", ".", "A", ".", "To", "(", "v", ")", ".", "Len", "(", ")", "<", "l", ".", "B", ".", "To", "(", "v", ")", ".", "Len", "(", ")", "{", "return", "l", ".", "A", "\n", "}", "\n", "return", "l", ".", "B", "\n", "}", "\n", "if", "math", ".", "IsInf", "(", "math", ".", "Abs", "(", "m", ")", ",", "1", ")", "{", "x", ":=", "l", ".", "A", ".", "X", "\n", "y", ":=", "v", ".", "Y", "\n", "if", "between", "(", "l", ".", "A", ".", "Y", ",", "l", ".", "B", ".", "Y", ",", "v", ".", "Y", ")", "{", "return", "V", "(", "x", ",", "y", ")", "\n", "}", "\n", "if", "l", ".", "A", ".", "To", "(", "v", ")", ".", "Len", "(", ")", "<", "l", ".", "B", ".", "To", "(", "v", ")", ".", "Len", "(", ")", "{", "return", "l", ".", "A", "\n", "}", "\n", "return", "l", ".", "B", "\n", "}", "\n", "perpendicularM", ":=", "-", "1", "/", "m", "\n", "perpendicularB", ":=", "v", ".", "Y", "-", "(", "perpendicularM", "*", "v", ".", "X", ")", "\n", "x", ":=", "(", "perpendicularB", "-", "b", ")", "/", "(", "m", "-", "perpendicularM", ")", "\n", "y", ":=", "m", "*", "x", "+", "b", "\n", "if", "!", "between", "(", "l", ".", "A", ".", "X", ",", "l", ".", "B", ".", "X", ",", "x", ")", "&&", "!", "between", "(", "l", ".", "A", ".", "Y", ",", "l", ".", "B", ".", "Y", ",", "y", ")", "{", "toStart", ":=", "v", ".", "To", "(", "l", ".", "A", ")", "\n", "toEnd", ":=", "v", ".", "To", "(", "l", ".", "B", ")", "\n", "if", "toStart", ".", "Len", "(", ")", "<", "toEnd", ".", "Len", "(", ")", "{", "return", "l", ".", "A", "\n", "}", "\n", "return", "l", ".", "B", "\n", "}", "\n", "return", "V", "(", "x", ",", "y", ")", "\n", "}" ]
// Closest will return the point on the line which is closest to the Vec provided.
[ "Closest", "will", "return", "the", "point", "on", "the", "line", "which", "is", "closest", "to", "the", "Vec", "provided", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/geometry.go#L235-L301
train
faiface/pixel
geometry.go
Contains
func (l Line) Contains(v Vec) bool { return l.Closest(v).Eq(v) }
go
func (l Line) Contains(v Vec) bool { return l.Closest(v).Eq(v) }
[ "func", "(", "l", "Line", ")", "Contains", "(", "v", "Vec", ")", "bool", "{", "return", "l", ".", "Closest", "(", "v", ")", ".", "Eq", "(", "v", ")", "\n", "}" ]
// Contains returns whether the provided Vec lies on the line.
[ "Contains", "returns", "whether", "the", "provided", "Vec", "lies", "on", "the", "line", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/geometry.go#L304-L306
train
faiface/pixel
geometry.go
Intersect
func (l Line) Intersect(k Line) (Vec, bool) { // Check if the lines are parallel lDir := l.A.To(l.B) kDir := k.A.To(k.B) if lDir.X == kDir.X && lDir.Y == kDir.Y { return ZV, false } // The lines intersect - but potentially not within the line segments. // Get the intersection point for the lines if they were infinitely long, check if the point exists on both of the // segments lm, lb := l.Formula() km, kb := k.Formula() // Account for vertical lines if math.IsInf(math.Abs(lm), 1) && math.IsInf(math.Abs(km), 1) { // Both vertical, therefore parallel return ZV, false } var x, y float64 if math.IsInf(math.Abs(lm), 1) || math.IsInf(math.Abs(km), 1) { // One line is vertical intersectM := lm intersectB := lb verticalLine := k if math.IsInf(math.Abs(lm), 1) { intersectM = km intersectB = kb verticalLine = l } y = intersectM*verticalLine.A.X + intersectB x = verticalLine.A.X } else { // Coordinates of intersect x = (kb - lb) / (lm - km) y = lm*x + lb } if l.Contains(V(x, y)) && k.Contains(V(x, y)) { // The intersect point is on both line segments, they intersect. return V(x, y), true } return ZV, false }
go
func (l Line) Intersect(k Line) (Vec, bool) { // Check if the lines are parallel lDir := l.A.To(l.B) kDir := k.A.To(k.B) if lDir.X == kDir.X && lDir.Y == kDir.Y { return ZV, false } // The lines intersect - but potentially not within the line segments. // Get the intersection point for the lines if they were infinitely long, check if the point exists on both of the // segments lm, lb := l.Formula() km, kb := k.Formula() // Account for vertical lines if math.IsInf(math.Abs(lm), 1) && math.IsInf(math.Abs(km), 1) { // Both vertical, therefore parallel return ZV, false } var x, y float64 if math.IsInf(math.Abs(lm), 1) || math.IsInf(math.Abs(km), 1) { // One line is vertical intersectM := lm intersectB := lb verticalLine := k if math.IsInf(math.Abs(lm), 1) { intersectM = km intersectB = kb verticalLine = l } y = intersectM*verticalLine.A.X + intersectB x = verticalLine.A.X } else { // Coordinates of intersect x = (kb - lb) / (lm - km) y = lm*x + lb } if l.Contains(V(x, y)) && k.Contains(V(x, y)) { // The intersect point is on both line segments, they intersect. return V(x, y), true } return ZV, false }
[ "func", "(", "l", "Line", ")", "Intersect", "(", "k", "Line", ")", "(", "Vec", ",", "bool", ")", "{", "lDir", ":=", "l", ".", "A", ".", "To", "(", "l", ".", "B", ")", "\n", "kDir", ":=", "k", ".", "A", ".", "To", "(", "k", ".", "B", ")", "\n", "if", "lDir", ".", "X", "==", "kDir", ".", "X", "&&", "lDir", ".", "Y", "==", "kDir", ".", "Y", "{", "return", "ZV", ",", "false", "\n", "}", "\n", "lm", ",", "lb", ":=", "l", ".", "Formula", "(", ")", "\n", "km", ",", "kb", ":=", "k", ".", "Formula", "(", ")", "\n", "if", "math", ".", "IsInf", "(", "math", ".", "Abs", "(", "lm", ")", ",", "1", ")", "&&", "math", ".", "IsInf", "(", "math", ".", "Abs", "(", "km", ")", ",", "1", ")", "{", "return", "ZV", ",", "false", "\n", "}", "\n", "var", "x", ",", "y", "float64", "\n", "if", "math", ".", "IsInf", "(", "math", ".", "Abs", "(", "lm", ")", ",", "1", ")", "||", "math", ".", "IsInf", "(", "math", ".", "Abs", "(", "km", ")", ",", "1", ")", "{", "intersectM", ":=", "lm", "\n", "intersectB", ":=", "lb", "\n", "verticalLine", ":=", "k", "\n", "if", "math", ".", "IsInf", "(", "math", ".", "Abs", "(", "lm", ")", ",", "1", ")", "{", "intersectM", "=", "km", "\n", "intersectB", "=", "kb", "\n", "verticalLine", "=", "l", "\n", "}", "\n", "y", "=", "intersectM", "*", "verticalLine", ".", "A", ".", "X", "+", "intersectB", "\n", "x", "=", "verticalLine", ".", "A", ".", "X", "\n", "}", "else", "{", "x", "=", "(", "kb", "-", "lb", ")", "/", "(", "lm", "-", "km", ")", "\n", "y", "=", "lm", "*", "x", "+", "lb", "\n", "}", "\n", "if", "l", ".", "Contains", "(", "V", "(", "x", ",", "y", ")", ")", "&&", "k", ".", "Contains", "(", "V", "(", "x", ",", "y", ")", ")", "{", "return", "V", "(", "x", ",", "y", ")", ",", "true", "\n", "}", "\n", "return", "ZV", ",", "false", "\n", "}" ]
// Intersect will return the point of intersection for the two line segments. If the line segments do not intersect, // this function will return the zero-vector and false.
[ "Intersect", "will", "return", "the", "point", "of", "intersection", "for", "the", "two", "line", "segments", ".", "If", "the", "line", "segments", "do", "not", "intersect", "this", "function", "will", "return", "the", "zero", "-", "vector", "and", "false", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/geometry.go#L324-L372
train
faiface/pixel
geometry.go
IntersectCircle
func (l Line) IntersectCircle(c Circle) Vec { // Get the point on the line closest to the center of the circle. closest := l.Closest(c.Center) cirToClosest := c.Center.To(closest) if cirToClosest.Len() >= c.Radius { return ZV } return cirToClosest.Scaled(cirToClosest.Len() - c.Radius) }
go
func (l Line) IntersectCircle(c Circle) Vec { // Get the point on the line closest to the center of the circle. closest := l.Closest(c.Center) cirToClosest := c.Center.To(closest) if cirToClosest.Len() >= c.Radius { return ZV } return cirToClosest.Scaled(cirToClosest.Len() - c.Radius) }
[ "func", "(", "l", "Line", ")", "IntersectCircle", "(", "c", "Circle", ")", "Vec", "{", "closest", ":=", "l", ".", "Closest", "(", "c", ".", "Center", ")", "\n", "cirToClosest", ":=", "c", ".", "Center", ".", "To", "(", "closest", ")", "\n", "if", "cirToClosest", ".", "Len", "(", ")", ">=", "c", ".", "Radius", "{", "return", "ZV", "\n", "}", "\n", "return", "cirToClosest", ".", "Scaled", "(", "cirToClosest", ".", "Len", "(", ")", "-", "c", ".", "Radius", ")", "\n", "}" ]
// IntersectCircle will return the shortest Vec such that moving the Line by that Vec will cause the Line and Circle // to no longer intesect. If they do not intersect at all, this function will return a zero-vector.
[ "IntersectCircle", "will", "return", "the", "shortest", "Vec", "such", "that", "moving", "the", "Line", "by", "that", "Vec", "will", "cause", "the", "Line", "and", "Circle", "to", "no", "longer", "intesect", ".", "If", "they", "do", "not", "intersect", "at", "all", "this", "function", "will", "return", "a", "zero", "-", "vector", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/geometry.go#L376-L386
train
faiface/pixel
geometry.go
IntersectRect
func (l Line) IntersectRect(r Rect) Vec { // Check if either end of the line segment are within the rectangle if r.Contains(l.A) || r.Contains(l.B) { // Use the Rect.Intersect to get minimal return value rIntersect := l.Bounds().Intersect(r) if rIntersect.H() > rIntersect.W() { // Go vertical return V(0, rIntersect.H()) } return V(rIntersect.W(), 0) } // Check if any of the rectangles' edges intersect with this line. for _, edge := range r.Edges() { if _, ok := l.Intersect(edge); ok { // Get the closest points on the line to each corner, where: // - the point is contained by the rectangle // - the point is not the corner itself corners := r.Vertices() closest := ZV closestCorner := corners[0] for _, c := range corners { cc := l.Closest(c) if closest == ZV || (closest.Len() > cc.Len() && r.Contains(cc)) { closest = cc closestCorner = c } } return closest.To(closestCorner) } } // No intersect return ZV }
go
func (l Line) IntersectRect(r Rect) Vec { // Check if either end of the line segment are within the rectangle if r.Contains(l.A) || r.Contains(l.B) { // Use the Rect.Intersect to get minimal return value rIntersect := l.Bounds().Intersect(r) if rIntersect.H() > rIntersect.W() { // Go vertical return V(0, rIntersect.H()) } return V(rIntersect.W(), 0) } // Check if any of the rectangles' edges intersect with this line. for _, edge := range r.Edges() { if _, ok := l.Intersect(edge); ok { // Get the closest points on the line to each corner, where: // - the point is contained by the rectangle // - the point is not the corner itself corners := r.Vertices() closest := ZV closestCorner := corners[0] for _, c := range corners { cc := l.Closest(c) if closest == ZV || (closest.Len() > cc.Len() && r.Contains(cc)) { closest = cc closestCorner = c } } return closest.To(closestCorner) } } // No intersect return ZV }
[ "func", "(", "l", "Line", ")", "IntersectRect", "(", "r", "Rect", ")", "Vec", "{", "if", "r", ".", "Contains", "(", "l", ".", "A", ")", "||", "r", ".", "Contains", "(", "l", ".", "B", ")", "{", "rIntersect", ":=", "l", ".", "Bounds", "(", ")", ".", "Intersect", "(", "r", ")", "\n", "if", "rIntersect", ".", "H", "(", ")", ">", "rIntersect", ".", "W", "(", ")", "{", "return", "V", "(", "0", ",", "rIntersect", ".", "H", "(", ")", ")", "\n", "}", "\n", "return", "V", "(", "rIntersect", ".", "W", "(", ")", ",", "0", ")", "\n", "}", "\n", "for", "_", ",", "edge", ":=", "range", "r", ".", "Edges", "(", ")", "{", "if", "_", ",", "ok", ":=", "l", ".", "Intersect", "(", "edge", ")", ";", "ok", "{", "corners", ":=", "r", ".", "Vertices", "(", ")", "\n", "closest", ":=", "ZV", "\n", "closestCorner", ":=", "corners", "[", "0", "]", "\n", "for", "_", ",", "c", ":=", "range", "corners", "{", "cc", ":=", "l", ".", "Closest", "(", "c", ")", "\n", "if", "closest", "==", "ZV", "||", "(", "closest", ".", "Len", "(", ")", ">", "cc", ".", "Len", "(", ")", "&&", "r", ".", "Contains", "(", "cc", ")", ")", "{", "closest", "=", "cc", "\n", "closestCorner", "=", "c", "\n", "}", "\n", "}", "\n", "return", "closest", ".", "To", "(", "closestCorner", ")", "\n", "}", "\n", "}", "\n", "return", "ZV", "\n", "}" ]
// IntersectRect will return the shortest Vec such that moving the Line by that Vec will cause the Line and Rect to // no longer intesect. If they do not intersect at all, this function will return a zero-vector.
[ "IntersectRect", "will", "return", "the", "shortest", "Vec", "such", "that", "moving", "the", "Line", "by", "that", "Vec", "will", "cause", "the", "Line", "and", "Rect", "to", "no", "longer", "intesect", ".", "If", "they", "do", "not", "intersect", "at", "all", "this", "function", "will", "return", "a", "zero", "-", "vector", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/geometry.go#L390-L425
train
faiface/pixel
geometry.go
Len
func (l Line) Len() float64 { return l.A.To(l.B).Len() }
go
func (l Line) Len() float64 { return l.A.To(l.B).Len() }
[ "func", "(", "l", "Line", ")", "Len", "(", ")", "float64", "{", "return", "l", ".", "A", ".", "To", "(", "l", ".", "B", ")", ".", "Len", "(", ")", "\n", "}" ]
// Len returns the length of the line segment.
[ "Len", "returns", "the", "length", "of", "the", "line", "segment", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/geometry.go#L428-L430
train
faiface/pixel
geometry.go
Moved
func (l Line) Moved(delta Vec) Line { return Line{ A: l.A.Add(delta), B: l.B.Add(delta), } }
go
func (l Line) Moved(delta Vec) Line { return Line{ A: l.A.Add(delta), B: l.B.Add(delta), } }
[ "func", "(", "l", "Line", ")", "Moved", "(", "delta", "Vec", ")", "Line", "{", "return", "Line", "{", "A", ":", "l", ".", "A", ".", "Add", "(", "delta", ")", ",", "B", ":", "l", ".", "B", ".", "Add", "(", "delta", ")", ",", "}", "\n", "}" ]
// Moved will return a line moved by the delta Vec provided.
[ "Moved", "will", "return", "a", "line", "moved", "by", "the", "delta", "Vec", "provided", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/geometry.go#L433-L438
train
faiface/pixel
geometry.go
Rotated
func (l Line) Rotated(around Vec, angle float64) Line { // Move the line so we can use `Vec.Rotated` lineShifted := l.Moved(around.Scaled(-1)) lineRotated := Line{ A: lineShifted.A.Rotated(angle), B: lineShifted.B.Rotated(angle), } return lineRotated.Moved(around) }
go
func (l Line) Rotated(around Vec, angle float64) Line { // Move the line so we can use `Vec.Rotated` lineShifted := l.Moved(around.Scaled(-1)) lineRotated := Line{ A: lineShifted.A.Rotated(angle), B: lineShifted.B.Rotated(angle), } return lineRotated.Moved(around) }
[ "func", "(", "l", "Line", ")", "Rotated", "(", "around", "Vec", ",", "angle", "float64", ")", "Line", "{", "lineShifted", ":=", "l", ".", "Moved", "(", "around", ".", "Scaled", "(", "-", "1", ")", ")", "\n", "lineRotated", ":=", "Line", "{", "A", ":", "lineShifted", ".", "A", ".", "Rotated", "(", "angle", ")", ",", "B", ":", "lineShifted", ".", "B", ".", "Rotated", "(", "angle", ")", ",", "}", "\n", "return", "lineRotated", ".", "Moved", "(", "around", ")", "\n", "}" ]
// Rotated will rotate the line around the provided Vec.
[ "Rotated", "will", "rotate", "the", "line", "around", "the", "provided", "Vec", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/geometry.go#L441-L451
train
faiface/pixel
geometry.go
Scaled
func (l Line) Scaled(scale float64) Line { return l.ScaledXY(l.Center(), scale) }
go
func (l Line) Scaled(scale float64) Line { return l.ScaledXY(l.Center(), scale) }
[ "func", "(", "l", "Line", ")", "Scaled", "(", "scale", "float64", ")", "Line", "{", "return", "l", ".", "ScaledXY", "(", "l", ".", "Center", "(", ")", ",", "scale", ")", "\n", "}" ]
// Scaled will return the line scaled around the center point.
[ "Scaled", "will", "return", "the", "line", "scaled", "around", "the", "center", "point", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/geometry.go#L454-L456
train
faiface/pixel
geometry.go
ScaledXY
func (l Line) ScaledXY(around Vec, scale float64) Line { toA := around.To(l.A).Scaled(scale) toB := around.To(l.B).Scaled(scale) return Line{ A: around.Add(toA), B: around.Add(toB), } }
go
func (l Line) ScaledXY(around Vec, scale float64) Line { toA := around.To(l.A).Scaled(scale) toB := around.To(l.B).Scaled(scale) return Line{ A: around.Add(toA), B: around.Add(toB), } }
[ "func", "(", "l", "Line", ")", "ScaledXY", "(", "around", "Vec", ",", "scale", "float64", ")", "Line", "{", "toA", ":=", "around", ".", "To", "(", "l", ".", "A", ")", ".", "Scaled", "(", "scale", ")", "\n", "toB", ":=", "around", ".", "To", "(", "l", ".", "B", ")", ".", "Scaled", "(", "scale", ")", "\n", "return", "Line", "{", "A", ":", "around", ".", "Add", "(", "toA", ")", ",", "B", ":", "around", ".", "Add", "(", "toB", ")", ",", "}", "\n", "}" ]
// ScaledXY will return the line scaled around the Vec provided.
[ "ScaledXY", "will", "return", "the", "line", "scaled", "around", "the", "Vec", "provided", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/geometry.go#L459-L467
train
faiface/pixel
geometry.go
R
func R(minX, minY, maxX, maxY float64) Rect { return Rect{ Min: Vec{minX, minY}, Max: Vec{maxX, maxY}, } }
go
func R(minX, minY, maxX, maxY float64) Rect { return Rect{ Min: Vec{minX, minY}, Max: Vec{maxX, maxY}, } }
[ "func", "R", "(", "minX", ",", "minY", ",", "maxX", ",", "maxY", "float64", ")", "Rect", "{", "return", "Rect", "{", "Min", ":", "Vec", "{", "minX", ",", "minY", "}", ",", "Max", ":", "Vec", "{", "maxX", ",", "maxY", "}", ",", "}", "\n", "}" ]
// R returns a new Rect with given the Min and Max coordinates. // // Note that the returned rectangle is not automatically normalized.
[ "R", "returns", "a", "new", "Rect", "with", "given", "the", "Min", "and", "Max", "coordinates", ".", "Note", "that", "the", "returned", "rectangle", "is", "not", "automatically", "normalized", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/geometry.go#L485-L490
train
faiface/pixel
geometry.go
Norm
func (r Rect) Norm() Rect { return Rect{ Min: Vec{ math.Min(r.Min.X, r.Max.X), math.Min(r.Min.Y, r.Max.Y), }, Max: Vec{ math.Max(r.Min.X, r.Max.X), math.Max(r.Min.Y, r.Max.Y), }, } }
go
func (r Rect) Norm() Rect { return Rect{ Min: Vec{ math.Min(r.Min.X, r.Max.X), math.Min(r.Min.Y, r.Max.Y), }, Max: Vec{ math.Max(r.Min.X, r.Max.X), math.Max(r.Min.Y, r.Max.Y), }, } }
[ "func", "(", "r", "Rect", ")", "Norm", "(", ")", "Rect", "{", "return", "Rect", "{", "Min", ":", "Vec", "{", "math", ".", "Min", "(", "r", ".", "Min", ".", "X", ",", "r", ".", "Max", ".", "X", ")", ",", "math", ".", "Min", "(", "r", ".", "Min", ".", "Y", ",", "r", ".", "Max", ".", "Y", ")", ",", "}", ",", "Max", ":", "Vec", "{", "math", ".", "Max", "(", "r", ".", "Min", ".", "X", ",", "r", ".", "Max", ".", "X", ")", ",", "math", ".", "Max", "(", "r", ".", "Min", ".", "Y", ",", "r", ".", "Max", ".", "Y", ")", ",", "}", ",", "}", "\n", "}" ]
// Norm returns the Rect in normal form, such that Max is component-wise greater or equal than Min.
[ "Norm", "returns", "the", "Rect", "in", "normal", "form", "such", "that", "Max", "is", "component", "-", "wise", "greater", "or", "equal", "than", "Min", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/geometry.go#L502-L513
train
faiface/pixel
geometry.go
W
func (r Rect) W() float64 { return r.Max.X - r.Min.X }
go
func (r Rect) W() float64 { return r.Max.X - r.Min.X }
[ "func", "(", "r", "Rect", ")", "W", "(", ")", "float64", "{", "return", "r", ".", "Max", ".", "X", "-", "r", ".", "Min", ".", "X", "\n", "}" ]
// W returns the width of the Rect.
[ "W", "returns", "the", "width", "of", "the", "Rect", "." ]
a68a4e38b42dde3869de57fddbaea6da106d5940
https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/geometry.go#L516-L518
train