repo
stringlengths 5
54
| path
stringlengths 4
155
| func_name
stringlengths 1
118
| original_string
stringlengths 52
85.5k
| language
stringclasses 1
value | code
stringlengths 52
85.5k
| code_tokens
sequence | docstring
stringlengths 6
2.61k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 85
252
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
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",
"//c.sprite.SetMatrix(pixel.IM.Moved(c.Bounds().Center()))",
"}"
] | // 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\n",
"rgba",
":=",
"pixel",
".",
"ToRGBA",
"(",
"color",
")",
"\n\n",
"// 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",
"]",
")",
",",
"}",
")",
"\n\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\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\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",
"++",
"{",
"// Determine and store if the joystick was connected",
"joystickPresent",
":=",
"glfw",
".",
"JoystickPresent",
"(",
"glfw",
".",
"Joystick",
"(",
"js",
")",
")",
"\n",
"w",
".",
"tempJoy",
".",
"connected",
"[",
"js",
"]",
"=",
"joystickPresent",
"\n\n",
"if",
"joystickPresent",
"{",
"w",
".",
"tempJoy",
".",
"buttons",
"[",
"js",
"]",
"=",
"glfw",
".",
"GetJoystickButtons",
"(",
"glfw",
".",
"Joystick",
"(",
"js",
")",
")",
"\n",
"w",
".",
"tempJoy",
".",
"axis",
"[",
"js",
"]",
"=",
"glfw",
".",
"GetJoystickAxes",
"(",
"glfw",
".",
"Joystick",
"(",
"js",
")",
")",
"\n\n",
"if",
"!",
"w",
".",
"currJoy",
".",
"connected",
"[",
"js",
"]",
"{",
"// The joystick was recently connected, we get the name",
"w",
".",
"tempJoy",
".",
"name",
"[",
"js",
"]",
"=",
"glfw",
".",
"GetJoystickName",
"(",
"glfw",
".",
"Joystick",
"(",
"js",
")",
")",
"\n",
"}",
"else",
"{",
"// Use the name from the previous one",
"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\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",
"{",
"// 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",
"\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",
"{",
"// 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",
"\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\n",
"if",
"dirty",
"{",
"s",
".",
"calcData",
"(",
")",
"\n",
"}",
"\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\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",
"(",
"\"",
"\"",
")",
")",
"\n",
"}",
"\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",
"(",
"\"",
"\"",
",",
"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\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\n",
"if",
"d",
".",
"Triangles",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"dt",
":=",
"d",
".",
"targets",
"[",
"t",
"]",
"\n",
"if",
"dt",
"==",
"nil",
"{",
"dt",
"=",
"&",
"drawerTarget",
"{",
"pics",
":",
"make",
"(",
"map",
"[",
"Picture",
"]",
"TargetPicture",
")",
",",
"}",
"\n",
"d",
".",
"targets",
"[",
"t",
"]",
"=",
"dt",
"\n",
"}",
"\n\n",
"if",
"dt",
".",
"tris",
"==",
"nil",
"{",
"dt",
".",
"tris",
"=",
"t",
".",
"MakeTriangles",
"(",
"d",
".",
"Triangles",
")",
"\n",
"dt",
".",
"clean",
"=",
"true",
"\n",
"}",
"\n\n",
"if",
"!",
"dt",
".",
"clean",
"{",
"dt",
".",
"tris",
".",
"SetLen",
"(",
"d",
".",
"Triangles",
".",
"Len",
"(",
")",
")",
"\n",
"dt",
".",
"tris",
".",
"Update",
"(",
"d",
".",
"Triangles",
")",
"\n",
"dt",
".",
"clean",
"=",
"true",
"\n",
"}",
"\n\n",
"if",
"d",
".",
"Picture",
"==",
"nil",
"{",
"dt",
".",
"tris",
".",
"Draw",
"(",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"pic",
":=",
"dt",
".",
"pics",
"[",
"d",
".",
"Picture",
"]",
"\n",
"if",
"pic",
"==",
"nil",
"{",
"pic",
"=",
"t",
".",
"MakePicture",
"(",
"d",
".",
"Picture",
")",
"\n",
"dt",
".",
"pics",
"[",
"d",
".",
"Picture",
"]",
"=",
"pic",
"\n",
"}",
"\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\n",
"mainthread",
".",
"Call",
"(",
"func",
"(",
")",
"{",
"oldF",
":=",
"gf",
".",
"frame",
"\n\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\n",
"// preserve old content",
"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\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\n",
"if",
"a",
"==",
"b",
"{",
"return",
"true",
"\n",
"}",
"\n\n",
"diff",
":=",
"math",
".",
"Abs",
"(",
"a",
"-",
"b",
")",
"\n\n",
"if",
"a",
"==",
"0.0",
"||",
"b",
"==",
"0.0",
"||",
"diff",
"<",
"math",
".",
"SmallestNonzeroFloat64",
"{",
"return",
"diff",
"<",
"(",
"epsilon",
"*",
"math",
".",
"SmallestNonzeroFloat64",
")",
"\n",
"}",
"\n\n",
"absA",
":=",
"math",
".",
"Abs",
"(",
"a",
")",
"\n",
"absB",
":=",
"math",
".",
"Abs",
"(",
"b",
")",
"\n\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 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",
")",
"\n",
"max",
":=",
"math",
".",
"Max",
"(",
"a",
",",
"b",
")",
"\n",
"return",
"min",
"<",
"x",
"&&",
"x",
"<",
"max",
"\n",
"}",
"\n\n",
"// 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",
"(",
")",
"\n\n",
"// Account for horizontal lines",
"if",
"m",
"==",
"0",
"{",
"x",
":=",
"v",
".",
"X",
"\n",
"y",
":=",
"l",
".",
"A",
".",
"Y",
"\n\n",
"// 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",
")",
"\n",
"}",
"\n\n",
"// Otherwise get the closest endpoint",
"if",
"l",
".",
"A",
".",
"To",
"(",
"v",
")",
".",
"Len",
"(",
")",
"<",
"l",
".",
"B",
".",
"To",
"(",
"v",
")",
".",
"Len",
"(",
")",
"{",
"return",
"l",
".",
"A",
"\n",
"}",
"\n",
"return",
"l",
".",
"B",
"\n",
"}",
"\n\n",
"// Account for vertical lines",
"if",
"math",
".",
"IsInf",
"(",
"math",
".",
"Abs",
"(",
"m",
")",
",",
"1",
")",
"{",
"x",
":=",
"l",
".",
"A",
".",
"X",
"\n",
"y",
":=",
"v",
".",
"Y",
"\n\n",
"// 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",
")",
"\n",
"}",
"\n\n",
"// Otherwise get the closest endpoint",
"if",
"l",
".",
"A",
".",
"To",
"(",
"v",
")",
".",
"Len",
"(",
")",
"<",
"l",
".",
"B",
".",
"To",
"(",
"v",
")",
".",
"Len",
"(",
")",
"{",
"return",
"l",
".",
"A",
"\n",
"}",
"\n",
"return",
"l",
".",
"B",
"\n",
"}",
"\n\n",
"perpendicularM",
":=",
"-",
"1",
"/",
"m",
"\n",
"perpendicularB",
":=",
"v",
".",
"Y",
"-",
"(",
"perpendicularM",
"*",
"v",
".",
"X",
")",
"\n\n",
"// Coordinates of intersect (of infinite lines)",
"x",
":=",
"(",
"perpendicularB",
"-",
"b",
")",
"/",
"(",
"m",
"-",
"perpendicularM",
")",
"\n",
"y",
":=",
"m",
"*",
"x",
"+",
"b",
"\n\n",
"// 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",
")",
"\n",
"toEnd",
":=",
"v",
".",
"To",
"(",
"l",
".",
"B",
")",
"\n\n",
"if",
"toStart",
".",
"Len",
"(",
")",
"<",
"toEnd",
".",
"Len",
"(",
")",
"{",
"return",
"l",
".",
"A",
"\n",
"}",
"\n",
"return",
"l",
".",
"B",
"\n",
"}",
"\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",
")",
"{",
"// Check if the lines are parallel",
"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\n",
"// 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",
"(",
")",
"\n",
"km",
",",
"kb",
":=",
"k",
".",
"Formula",
"(",
")",
"\n\n",
"// Account for vertical lines",
"if",
"math",
".",
"IsInf",
"(",
"math",
".",
"Abs",
"(",
"lm",
")",
",",
"1",
")",
"&&",
"math",
".",
"IsInf",
"(",
"math",
".",
"Abs",
"(",
"km",
")",
",",
"1",
")",
"{",
"// Both vertical, therefore parallel",
"return",
"ZV",
",",
"false",
"\n",
"}",
"\n\n",
"var",
"x",
",",
"y",
"float64",
"\n\n",
"if",
"math",
".",
"IsInf",
"(",
"math",
".",
"Abs",
"(",
"lm",
")",
",",
"1",
")",
"||",
"math",
".",
"IsInf",
"(",
"math",
".",
"Abs",
"(",
"km",
")",
",",
"1",
")",
"{",
"// One line is vertical",
"intersectM",
":=",
"lm",
"\n",
"intersectB",
":=",
"lb",
"\n",
"verticalLine",
":=",
"k",
"\n\n",
"if",
"math",
".",
"IsInf",
"(",
"math",
".",
"Abs",
"(",
"lm",
")",
",",
"1",
")",
"{",
"intersectM",
"=",
"km",
"\n",
"intersectB",
"=",
"kb",
"\n",
"verticalLine",
"=",
"l",
"\n",
"}",
"\n\n",
"y",
"=",
"intersectM",
"*",
"verticalLine",
".",
"A",
".",
"X",
"+",
"intersectB",
"\n",
"x",
"=",
"verticalLine",
".",
"A",
".",
"X",
"\n",
"}",
"else",
"{",
"// Coordinates of intersect",
"x",
"=",
"(",
"kb",
"-",
"lb",
")",
"/",
"(",
"lm",
"-",
"km",
")",
"\n",
"y",
"=",
"lm",
"*",
"x",
"+",
"lb",
"\n",
"}",
"\n\n",
"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",
"\n",
"}",
"\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",
"{",
"// Get the point on the line closest to the center of the circle.",
"closest",
":=",
"l",
".",
"Closest",
"(",
"c",
".",
"Center",
")",
"\n",
"cirToClosest",
":=",
"c",
".",
"Center",
".",
"To",
"(",
"closest",
")",
"\n\n",
"if",
"cirToClosest",
".",
"Len",
"(",
")",
">=",
"c",
".",
"Radius",
"{",
"return",
"ZV",
"\n",
"}",
"\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",
"{",
"// 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",
")",
"\n",
"if",
"rIntersect",
".",
"H",
"(",
")",
">",
"rIntersect",
".",
"W",
"(",
")",
"{",
"// Go vertical",
"return",
"V",
"(",
"0",
",",
"rIntersect",
".",
"H",
"(",
")",
")",
"\n",
"}",
"\n",
"return",
"V",
"(",
"rIntersect",
".",
"W",
"(",
")",
",",
"0",
")",
"\n",
"}",
"\n\n",
"// 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",
"(",
")",
"\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\n",
"return",
"closest",
".",
"To",
"(",
"closestCorner",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"// No intersect",
"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",
"{",
"// Move the line so we can use `Vec.Rotated`",
"lineShifted",
":=",
"l",
".",
"Moved",
"(",
"around",
".",
"Scaled",
"(",
"-",
"1",
")",
")",
"\n\n",
"lineRotated",
":=",
"Line",
"{",
"A",
":",
"lineShifted",
".",
"A",
".",
"Rotated",
"(",
"angle",
")",
",",
"B",
":",
"lineShifted",
".",
"B",
".",
"Rotated",
"(",
"angle",
")",
",",
"}",
"\n\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\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 |
faiface/pixel | geometry.go | H | func (r Rect) H() float64 {
return r.Max.Y - r.Min.Y
} | go | func (r Rect) H() float64 {
return r.Max.Y - r.Min.Y
} | [
"func",
"(",
"r",
"Rect",
")",
"H",
"(",
")",
"float64",
"{",
"return",
"r",
".",
"Max",
".",
"Y",
"-",
"r",
".",
"Min",
".",
"Y",
"\n",
"}"
] | // H returns the height of the Rect. | [
"H",
"returns",
"the",
"height",
"of",
"the",
"Rect",
"."
] | a68a4e38b42dde3869de57fddbaea6da106d5940 | https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/geometry.go#L521-L523 | train |
faiface/pixel | geometry.go | Edges | func (r Rect) Edges() [4]Line {
corners := r.Vertices()
return [4]Line{
{A: corners[0], B: corners[1]},
{A: corners[1], B: corners[2]},
{A: corners[2], B: corners[3]},
{A: corners[3], B: corners[0]},
}
} | go | func (r Rect) Edges() [4]Line {
corners := r.Vertices()
return [4]Line{
{A: corners[0], B: corners[1]},
{A: corners[1], B: corners[2]},
{A: corners[2], B: corners[3]},
{A: corners[3], B: corners[0]},
}
} | [
"func",
"(",
"r",
"Rect",
")",
"Edges",
"(",
")",
"[",
"4",
"]",
"Line",
"{",
"corners",
":=",
"r",
".",
"Vertices",
"(",
")",
"\n\n",
"return",
"[",
"4",
"]",
"Line",
"{",
"{",
"A",
":",
"corners",
"[",
"0",
"]",
",",
"B",
":",
"corners",
"[",
"1",
"]",
"}",
",",
"{",
"A",
":",
"corners",
"[",
"1",
"]",
",",
"B",
":",
"corners",
"[",
"2",
"]",
"}",
",",
"{",
"A",
":",
"corners",
"[",
"2",
"]",
",",
"B",
":",
"corners",
"[",
"3",
"]",
"}",
",",
"{",
"A",
":",
"corners",
"[",
"3",
"]",
",",
"B",
":",
"corners",
"[",
"0",
"]",
"}",
",",
"}",
"\n",
"}"
] | // Edges will return the four lines which make up the edges of the rectangle. | [
"Edges",
"will",
"return",
"the",
"four",
"lines",
"which",
"make",
"up",
"the",
"edges",
"of",
"the",
"rectangle",
"."
] | a68a4e38b42dde3869de57fddbaea6da106d5940 | https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/geometry.go#L536-L545 | train |
faiface/pixel | geometry.go | ResizedMin | func (r Rect) ResizedMin(size Vec) Rect {
return Rect{
Min: r.Min,
Max: r.Min.Add(size),
}
} | go | func (r Rect) ResizedMin(size Vec) Rect {
return Rect{
Min: r.Min,
Max: r.Min.Add(size),
}
} | [
"func",
"(",
"r",
"Rect",
")",
"ResizedMin",
"(",
"size",
"Vec",
")",
"Rect",
"{",
"return",
"Rect",
"{",
"Min",
":",
"r",
".",
"Min",
",",
"Max",
":",
"r",
".",
"Min",
".",
"Add",
"(",
"size",
")",
",",
"}",
"\n",
"}"
] | // ResizedMin returns the Rect resized to the given size while keeping the position of the Rect's
// Min.
//
// Sizes of zero area are safe here. | [
"ResizedMin",
"returns",
"the",
"Rect",
"resized",
"to",
"the",
"given",
"size",
"while",
"keeping",
"the",
"position",
"of",
"the",
"Rect",
"s",
"Min",
".",
"Sizes",
"of",
"zero",
"area",
"are",
"safe",
"here",
"."
] | a68a4e38b42dde3869de57fddbaea6da106d5940 | https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/geometry.go#L584-L589 | train |
faiface/pixel | geometry.go | Union | func (r Rect) Union(s Rect) Rect {
return R(
math.Min(r.Min.X, s.Min.X),
math.Min(r.Min.Y, s.Min.Y),
math.Max(r.Max.X, s.Max.X),
math.Max(r.Max.Y, s.Max.Y),
)
} | go | func (r Rect) Union(s Rect) Rect {
return R(
math.Min(r.Min.X, s.Min.X),
math.Min(r.Min.Y, s.Min.Y),
math.Max(r.Max.X, s.Max.X),
math.Max(r.Max.Y, s.Max.Y),
)
} | [
"func",
"(",
"r",
"Rect",
")",
"Union",
"(",
"s",
"Rect",
")",
"Rect",
"{",
"return",
"R",
"(",
"math",
".",
"Min",
"(",
"r",
".",
"Min",
".",
"X",
",",
"s",
".",
"Min",
".",
"X",
")",
",",
"math",
".",
"Min",
"(",
"r",
".",
"Min",
".",
"Y",
",",
"s",
".",
"Min",
".",
"Y",
")",
",",
"math",
".",
"Max",
"(",
"r",
".",
"Max",
".",
"X",
",",
"s",
".",
"Max",
".",
"X",
")",
",",
"math",
".",
"Max",
"(",
"r",
".",
"Max",
".",
"Y",
",",
"s",
".",
"Max",
".",
"Y",
")",
",",
")",
"\n",
"}"
] | // Union returns the minimal Rect which covers both r and s. Rects r and s must be normalized. | [
"Union",
"returns",
"the",
"minimal",
"Rect",
"which",
"covers",
"both",
"r",
"and",
"s",
".",
"Rects",
"r",
"and",
"s",
"must",
"be",
"normalized",
"."
] | a68a4e38b42dde3869de57fddbaea6da106d5940 | https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/geometry.go#L597-L604 | train |
faiface/pixel | geometry.go | IntersectionPoints | func (r Rect) IntersectionPoints(l Line) []Vec {
// Use map keys to ensure unique points
pointMap := make(map[Vec]struct{})
for _, edge := range r.Edges() {
if intersect, ok := l.Intersect(edge); ok {
pointMap[intersect] = struct{}{}
}
}
points := make([]Vec, 0, len(pointMap))
for point := range pointMap {
points = append(points, point)
}
// Order the points
if len(points) == 2 {
if points[1].To(l.A).Len() < points[0].To(l.A).Len() {
return []Vec{points[1], points[0]}
}
}
return points
} | go | func (r Rect) IntersectionPoints(l Line) []Vec {
// Use map keys to ensure unique points
pointMap := make(map[Vec]struct{})
for _, edge := range r.Edges() {
if intersect, ok := l.Intersect(edge); ok {
pointMap[intersect] = struct{}{}
}
}
points := make([]Vec, 0, len(pointMap))
for point := range pointMap {
points = append(points, point)
}
// Order the points
if len(points) == 2 {
if points[1].To(l.A).Len() < points[0].To(l.A).Len() {
return []Vec{points[1], points[0]}
}
}
return points
} | [
"func",
"(",
"r",
"Rect",
")",
"IntersectionPoints",
"(",
"l",
"Line",
")",
"[",
"]",
"Vec",
"{",
"// Use map keys to ensure unique points",
"pointMap",
":=",
"make",
"(",
"map",
"[",
"Vec",
"]",
"struct",
"{",
"}",
")",
"\n\n",
"for",
"_",
",",
"edge",
":=",
"range",
"r",
".",
"Edges",
"(",
")",
"{",
"if",
"intersect",
",",
"ok",
":=",
"l",
".",
"Intersect",
"(",
"edge",
")",
";",
"ok",
"{",
"pointMap",
"[",
"intersect",
"]",
"=",
"struct",
"{",
"}",
"{",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"points",
":=",
"make",
"(",
"[",
"]",
"Vec",
",",
"0",
",",
"len",
"(",
"pointMap",
")",
")",
"\n",
"for",
"point",
":=",
"range",
"pointMap",
"{",
"points",
"=",
"append",
"(",
"points",
",",
"point",
")",
"\n",
"}",
"\n\n",
"// Order the points",
"if",
"len",
"(",
"points",
")",
"==",
"2",
"{",
"if",
"points",
"[",
"1",
"]",
".",
"To",
"(",
"l",
".",
"A",
")",
".",
"Len",
"(",
")",
"<",
"points",
"[",
"0",
"]",
".",
"To",
"(",
"l",
".",
"A",
")",
".",
"Len",
"(",
")",
"{",
"return",
"[",
"]",
"Vec",
"{",
"points",
"[",
"1",
"]",
",",
"points",
"[",
"0",
"]",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"points",
"\n",
"}"
] | // IntersectionPoints returns all the points where the Rect intersects with the line provided. This can be zero, one or
// two points, depending on the location of the shapes. The points of intersection will be returned in order of
// closest-to-l.A to closest-to-l.B. | [
"IntersectionPoints",
"returns",
"all",
"the",
"points",
"where",
"the",
"Rect",
"intersects",
"with",
"the",
"line",
"provided",
".",
"This",
"can",
"be",
"zero",
"one",
"or",
"two",
"points",
"depending",
"on",
"the",
"location",
"of",
"the",
"shapes",
".",
"The",
"points",
"of",
"intersection",
"will",
"be",
"returned",
"in",
"order",
"of",
"closest",
"-",
"to",
"-",
"l",
".",
"A",
"to",
"closest",
"-",
"to",
"-",
"l",
".",
"B",
"."
] | a68a4e38b42dde3869de57fddbaea6da106d5940 | https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/geometry.go#L642-L665 | train |
faiface/pixel | geometry.go | Vertices | func (r Rect) Vertices() [4]Vec {
return [4]Vec{
r.Min,
V(r.Min.X, r.Max.Y),
r.Max,
V(r.Max.X, r.Min.Y),
}
} | go | func (r Rect) Vertices() [4]Vec {
return [4]Vec{
r.Min,
V(r.Min.X, r.Max.Y),
r.Max,
V(r.Max.X, r.Min.Y),
}
} | [
"func",
"(",
"r",
"Rect",
")",
"Vertices",
"(",
")",
"[",
"4",
"]",
"Vec",
"{",
"return",
"[",
"4",
"]",
"Vec",
"{",
"r",
".",
"Min",
",",
"V",
"(",
"r",
".",
"Min",
".",
"X",
",",
"r",
".",
"Max",
".",
"Y",
")",
",",
"r",
".",
"Max",
",",
"V",
"(",
"r",
".",
"Max",
".",
"X",
",",
"r",
".",
"Min",
".",
"Y",
")",
",",
"}",
"\n",
"}"
] | // Vertices returns a slice of the four corners which make up the rectangle. | [
"Vertices",
"returns",
"a",
"slice",
"of",
"the",
"four",
"corners",
"which",
"make",
"up",
"the",
"rectangle",
"."
] | a68a4e38b42dde3869de57fddbaea6da106d5940 | https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/geometry.go#L668-L675 | train |
faiface/pixel | geometry.go | C | func C(center Vec, radius float64) Circle {
return Circle{
Center: center,
Radius: radius,
}
} | go | func C(center Vec, radius float64) Circle {
return Circle{
Center: center,
Radius: radius,
}
} | [
"func",
"C",
"(",
"center",
"Vec",
",",
"radius",
"float64",
")",
"Circle",
"{",
"return",
"Circle",
"{",
"Center",
":",
"center",
",",
"Radius",
":",
"radius",
",",
"}",
"\n",
"}"
] | // C returns a new Circle with the given radius and center coordinates.
//
// Note that a negative radius is valid. | [
"C",
"returns",
"a",
"new",
"Circle",
"with",
"the",
"given",
"radius",
"and",
"center",
"coordinates",
".",
"Note",
"that",
"a",
"negative",
"radius",
"is",
"valid",
"."
] | a68a4e38b42dde3869de57fddbaea6da106d5940 | https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/geometry.go#L688-L693 | train |
faiface/pixel | geometry.go | Area | func (c Circle) Area() float64 {
return math.Pi * math.Pow(c.Radius, 2)
} | go | func (c Circle) Area() float64 {
return math.Pi * math.Pow(c.Radius, 2)
} | [
"func",
"(",
"c",
"Circle",
")",
"Area",
"(",
")",
"float64",
"{",
"return",
"math",
".",
"Pi",
"*",
"math",
".",
"Pow",
"(",
"c",
".",
"Radius",
",",
"2",
")",
"\n",
"}"
] | // Area returns the area of the Circle. | [
"Area",
"returns",
"the",
"area",
"of",
"the",
"Circle",
"."
] | a68a4e38b42dde3869de57fddbaea6da106d5940 | https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/geometry.go#L716-L718 | train |
faiface/pixel | geometry.go | Moved | func (c Circle) Moved(delta Vec) Circle {
return Circle{
Center: c.Center.Add(delta),
Radius: c.Radius,
}
} | go | func (c Circle) Moved(delta Vec) Circle {
return Circle{
Center: c.Center.Add(delta),
Radius: c.Radius,
}
} | [
"func",
"(",
"c",
"Circle",
")",
"Moved",
"(",
"delta",
"Vec",
")",
"Circle",
"{",
"return",
"Circle",
"{",
"Center",
":",
"c",
".",
"Center",
".",
"Add",
"(",
"delta",
")",
",",
"Radius",
":",
"c",
".",
"Radius",
",",
"}",
"\n",
"}"
] | // Moved returns the Circle moved by the given vector delta. | [
"Moved",
"returns",
"the",
"Circle",
"moved",
"by",
"the",
"given",
"vector",
"delta",
"."
] | a68a4e38b42dde3869de57fddbaea6da106d5940 | https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/geometry.go#L721-L726 | train |
faiface/pixel | geometry.go | maxCircle | func maxCircle(c, d Circle) Circle {
if c.Radius < d.Radius {
return d
}
return c
} | go | func maxCircle(c, d Circle) Circle {
if c.Radius < d.Radius {
return d
}
return c
} | [
"func",
"maxCircle",
"(",
"c",
",",
"d",
"Circle",
")",
"Circle",
"{",
"if",
"c",
".",
"Radius",
"<",
"d",
".",
"Radius",
"{",
"return",
"d",
"\n",
"}",
"\n",
"return",
"c",
"\n",
"}"
] | // maxCircle will return the larger circle based on the radius. | [
"maxCircle",
"will",
"return",
"the",
"larger",
"circle",
"based",
"on",
"the",
"radius",
"."
] | a68a4e38b42dde3869de57fddbaea6da106d5940 | https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/geometry.go#L753-L758 | train |
faiface/pixel | geometry.go | minCircle | func minCircle(c, d Circle) Circle {
if c.Radius < d.Radius {
return c
}
return d
} | go | func minCircle(c, d Circle) Circle {
if c.Radius < d.Radius {
return c
}
return d
} | [
"func",
"minCircle",
"(",
"c",
",",
"d",
"Circle",
")",
"Circle",
"{",
"if",
"c",
".",
"Radius",
"<",
"d",
".",
"Radius",
"{",
"return",
"c",
"\n",
"}",
"\n",
"return",
"d",
"\n",
"}"
] | // minCircle will return the smaller circle based on the radius. | [
"minCircle",
"will",
"return",
"the",
"smaller",
"circle",
"based",
"on",
"the",
"radius",
"."
] | a68a4e38b42dde3869de57fddbaea6da106d5940 | https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/geometry.go#L761-L766 | train |
faiface/pixel | geometry.go | Union | func (c Circle) Union(d Circle) Circle {
biggerC := maxCircle(c.Norm(), d.Norm())
smallerC := minCircle(c.Norm(), d.Norm())
// Get distance between centers
dist := c.Center.To(d.Center).Len()
// If the bigger Circle encompasses the smaller one, we have the result
if dist+smallerC.Radius <= biggerC.Radius {
return biggerC
}
// Calculate radius for encompassing Circle
r := (dist + biggerC.Radius + smallerC.Radius) / 2
// Calculate center for encompassing Circle
theta := .5 + (biggerC.Radius-smallerC.Radius)/(2*dist)
center := Lerp(smallerC.Center, biggerC.Center, theta)
return Circle{
Center: center,
Radius: r,
}
} | go | func (c Circle) Union(d Circle) Circle {
biggerC := maxCircle(c.Norm(), d.Norm())
smallerC := minCircle(c.Norm(), d.Norm())
// Get distance between centers
dist := c.Center.To(d.Center).Len()
// If the bigger Circle encompasses the smaller one, we have the result
if dist+smallerC.Radius <= biggerC.Radius {
return biggerC
}
// Calculate radius for encompassing Circle
r := (dist + biggerC.Radius + smallerC.Radius) / 2
// Calculate center for encompassing Circle
theta := .5 + (biggerC.Radius-smallerC.Radius)/(2*dist)
center := Lerp(smallerC.Center, biggerC.Center, theta)
return Circle{
Center: center,
Radius: r,
}
} | [
"func",
"(",
"c",
"Circle",
")",
"Union",
"(",
"d",
"Circle",
")",
"Circle",
"{",
"biggerC",
":=",
"maxCircle",
"(",
"c",
".",
"Norm",
"(",
")",
",",
"d",
".",
"Norm",
"(",
")",
")",
"\n",
"smallerC",
":=",
"minCircle",
"(",
"c",
".",
"Norm",
"(",
")",
",",
"d",
".",
"Norm",
"(",
")",
")",
"\n\n",
"// Get distance between centers",
"dist",
":=",
"c",
".",
"Center",
".",
"To",
"(",
"d",
".",
"Center",
")",
".",
"Len",
"(",
")",
"\n\n",
"// If the bigger Circle encompasses the smaller one, we have the result",
"if",
"dist",
"+",
"smallerC",
".",
"Radius",
"<=",
"biggerC",
".",
"Radius",
"{",
"return",
"biggerC",
"\n",
"}",
"\n\n",
"// Calculate radius for encompassing Circle",
"r",
":=",
"(",
"dist",
"+",
"biggerC",
".",
"Radius",
"+",
"smallerC",
".",
"Radius",
")",
"/",
"2",
"\n\n",
"// Calculate center for encompassing Circle",
"theta",
":=",
".5",
"+",
"(",
"biggerC",
".",
"Radius",
"-",
"smallerC",
".",
"Radius",
")",
"/",
"(",
"2",
"*",
"dist",
")",
"\n",
"center",
":=",
"Lerp",
"(",
"smallerC",
".",
"Center",
",",
"biggerC",
".",
"Center",
",",
"theta",
")",
"\n\n",
"return",
"Circle",
"{",
"Center",
":",
"center",
",",
"Radius",
":",
"r",
",",
"}",
"\n",
"}"
] | // Union returns the minimal Circle which covers both `c` and `d`. | [
"Union",
"returns",
"the",
"minimal",
"Circle",
"which",
"covers",
"both",
"c",
"and",
"d",
"."
] | a68a4e38b42dde3869de57fddbaea6da106d5940 | https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/geometry.go#L769-L792 | train |
faiface/pixel | geometry.go | Intersect | func (c Circle) Intersect(d Circle) Circle {
// Check if one of the circles encompasses the other; if so, return that one
biggerC := maxCircle(c.Norm(), d.Norm())
smallerC := minCircle(c.Norm(), d.Norm())
if biggerC.Radius >= biggerC.Center.To(smallerC.Center).Len()+smallerC.Radius {
return biggerC
}
// Calculate the midpoint between the two radii
// Distance between centers
dist := c.Center.To(d.Center).Len()
// Difference between radii
diff := dist - (c.Radius + d.Radius)
// Distance from c.Center to the weighted midpoint
distToMidpoint := c.Radius + 0.5*diff
// Weighted midpoint
center := Lerp(c.Center, d.Center, distToMidpoint/dist)
// No need to calculate radius if the circles do not overlap
if c.Center.To(d.Center).Len() >= c.Radius+d.Radius {
return C(center, 0)
}
radius := c.Center.To(d.Center).Len() - (c.Radius + d.Radius)
return Circle{
Center: center,
Radius: math.Abs(radius),
}
} | go | func (c Circle) Intersect(d Circle) Circle {
// Check if one of the circles encompasses the other; if so, return that one
biggerC := maxCircle(c.Norm(), d.Norm())
smallerC := minCircle(c.Norm(), d.Norm())
if biggerC.Radius >= biggerC.Center.To(smallerC.Center).Len()+smallerC.Radius {
return biggerC
}
// Calculate the midpoint between the two radii
// Distance between centers
dist := c.Center.To(d.Center).Len()
// Difference between radii
diff := dist - (c.Radius + d.Radius)
// Distance from c.Center to the weighted midpoint
distToMidpoint := c.Radius + 0.5*diff
// Weighted midpoint
center := Lerp(c.Center, d.Center, distToMidpoint/dist)
// No need to calculate radius if the circles do not overlap
if c.Center.To(d.Center).Len() >= c.Radius+d.Radius {
return C(center, 0)
}
radius := c.Center.To(d.Center).Len() - (c.Radius + d.Radius)
return Circle{
Center: center,
Radius: math.Abs(radius),
}
} | [
"func",
"(",
"c",
"Circle",
")",
"Intersect",
"(",
"d",
"Circle",
")",
"Circle",
"{",
"// Check if one of the circles encompasses the other; if so, return that one",
"biggerC",
":=",
"maxCircle",
"(",
"c",
".",
"Norm",
"(",
")",
",",
"d",
".",
"Norm",
"(",
")",
")",
"\n",
"smallerC",
":=",
"minCircle",
"(",
"c",
".",
"Norm",
"(",
")",
",",
"d",
".",
"Norm",
"(",
")",
")",
"\n\n",
"if",
"biggerC",
".",
"Radius",
">=",
"biggerC",
".",
"Center",
".",
"To",
"(",
"smallerC",
".",
"Center",
")",
".",
"Len",
"(",
")",
"+",
"smallerC",
".",
"Radius",
"{",
"return",
"biggerC",
"\n",
"}",
"\n\n",
"// Calculate the midpoint between the two radii",
"// Distance between centers",
"dist",
":=",
"c",
".",
"Center",
".",
"To",
"(",
"d",
".",
"Center",
")",
".",
"Len",
"(",
")",
"\n",
"// Difference between radii",
"diff",
":=",
"dist",
"-",
"(",
"c",
".",
"Radius",
"+",
"d",
".",
"Radius",
")",
"\n",
"// Distance from c.Center to the weighted midpoint",
"distToMidpoint",
":=",
"c",
".",
"Radius",
"+",
"0.5",
"*",
"diff",
"\n",
"// Weighted midpoint",
"center",
":=",
"Lerp",
"(",
"c",
".",
"Center",
",",
"d",
".",
"Center",
",",
"distToMidpoint",
"/",
"dist",
")",
"\n\n",
"// No need to calculate radius if the circles do not overlap",
"if",
"c",
".",
"Center",
".",
"To",
"(",
"d",
".",
"Center",
")",
".",
"Len",
"(",
")",
">=",
"c",
".",
"Radius",
"+",
"d",
".",
"Radius",
"{",
"return",
"C",
"(",
"center",
",",
"0",
")",
"\n",
"}",
"\n\n",
"radius",
":=",
"c",
".",
"Center",
".",
"To",
"(",
"d",
".",
"Center",
")",
".",
"Len",
"(",
")",
"-",
"(",
"c",
".",
"Radius",
"+",
"d",
".",
"Radius",
")",
"\n\n",
"return",
"Circle",
"{",
"Center",
":",
"center",
",",
"Radius",
":",
"math",
".",
"Abs",
"(",
"radius",
")",
",",
"}",
"\n",
"}"
] | // Intersect returns the maximal Circle which is covered by both `c` and `d`.
//
// If `c` and `d` don't overlap, this function returns a zero-sized circle at the centerpoint between the two Circle's
// centers. | [
"Intersect",
"returns",
"the",
"maximal",
"Circle",
"which",
"is",
"covered",
"by",
"both",
"c",
"and",
"d",
".",
"If",
"c",
"and",
"d",
"don",
"t",
"overlap",
"this",
"function",
"returns",
"a",
"zero",
"-",
"sized",
"circle",
"at",
"the",
"centerpoint",
"between",
"the",
"two",
"Circle",
"s",
"centers",
"."
] | a68a4e38b42dde3869de57fddbaea6da106d5940 | https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/geometry.go#L798-L828 | train |
faiface/pixel | geometry.go | Moved | func (m Matrix) Moved(delta Vec) Matrix {
m[4], m[5] = m[4]+delta.X, m[5]+delta.Y
return m
} | go | func (m Matrix) Moved(delta Vec) Matrix {
m[4], m[5] = m[4]+delta.X, m[5]+delta.Y
return m
} | [
"func",
"(",
"m",
"Matrix",
")",
"Moved",
"(",
"delta",
"Vec",
")",
"Matrix",
"{",
"m",
"[",
"4",
"]",
",",
"m",
"[",
"5",
"]",
"=",
"m",
"[",
"4",
"]",
"+",
"delta",
".",
"X",
",",
"m",
"[",
"5",
"]",
"+",
"delta",
".",
"Y",
"\n",
"return",
"m",
"\n",
"}"
] | // Moved moves everything by the delta vector. | [
"Moved",
"moves",
"everything",
"by",
"the",
"delta",
"vector",
"."
] | a68a4e38b42dde3869de57fddbaea6da106d5940 | https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/geometry.go#L1038-L1041 | train |
faiface/pixel | geometry.go | ScaledXY | func (m Matrix) ScaledXY(around Vec, scale Vec) Matrix {
m[4], m[5] = m[4]-around.X, m[5]-around.Y
m[0], m[2], m[4] = m[0]*scale.X, m[2]*scale.X, m[4]*scale.X
m[1], m[3], m[5] = m[1]*scale.Y, m[3]*scale.Y, m[5]*scale.Y
m[4], m[5] = m[4]+around.X, m[5]+around.Y
return m
} | go | func (m Matrix) ScaledXY(around Vec, scale Vec) Matrix {
m[4], m[5] = m[4]-around.X, m[5]-around.Y
m[0], m[2], m[4] = m[0]*scale.X, m[2]*scale.X, m[4]*scale.X
m[1], m[3], m[5] = m[1]*scale.Y, m[3]*scale.Y, m[5]*scale.Y
m[4], m[5] = m[4]+around.X, m[5]+around.Y
return m
} | [
"func",
"(",
"m",
"Matrix",
")",
"ScaledXY",
"(",
"around",
"Vec",
",",
"scale",
"Vec",
")",
"Matrix",
"{",
"m",
"[",
"4",
"]",
",",
"m",
"[",
"5",
"]",
"=",
"m",
"[",
"4",
"]",
"-",
"around",
".",
"X",
",",
"m",
"[",
"5",
"]",
"-",
"around",
".",
"Y",
"\n",
"m",
"[",
"0",
"]",
",",
"m",
"[",
"2",
"]",
",",
"m",
"[",
"4",
"]",
"=",
"m",
"[",
"0",
"]",
"*",
"scale",
".",
"X",
",",
"m",
"[",
"2",
"]",
"*",
"scale",
".",
"X",
",",
"m",
"[",
"4",
"]",
"*",
"scale",
".",
"X",
"\n",
"m",
"[",
"1",
"]",
",",
"m",
"[",
"3",
"]",
",",
"m",
"[",
"5",
"]",
"=",
"m",
"[",
"1",
"]",
"*",
"scale",
".",
"Y",
",",
"m",
"[",
"3",
"]",
"*",
"scale",
".",
"Y",
",",
"m",
"[",
"5",
"]",
"*",
"scale",
".",
"Y",
"\n",
"m",
"[",
"4",
"]",
",",
"m",
"[",
"5",
"]",
"=",
"m",
"[",
"4",
"]",
"+",
"around",
".",
"X",
",",
"m",
"[",
"5",
"]",
"+",
"around",
".",
"Y",
"\n",
"return",
"m",
"\n",
"}"
] | // ScaledXY scales everything around a given point by the scale factor in each axis respectively. | [
"ScaledXY",
"scales",
"everything",
"around",
"a",
"given",
"point",
"by",
"the",
"scale",
"factor",
"in",
"each",
"axis",
"respectively",
"."
] | a68a4e38b42dde3869de57fddbaea6da106d5940 | https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/geometry.go#L1044-L1050 | train |
faiface/pixel | geometry.go | Scaled | func (m Matrix) Scaled(around Vec, scale float64) Matrix {
return m.ScaledXY(around, V(scale, scale))
} | go | func (m Matrix) Scaled(around Vec, scale float64) Matrix {
return m.ScaledXY(around, V(scale, scale))
} | [
"func",
"(",
"m",
"Matrix",
")",
"Scaled",
"(",
"around",
"Vec",
",",
"scale",
"float64",
")",
"Matrix",
"{",
"return",
"m",
".",
"ScaledXY",
"(",
"around",
",",
"V",
"(",
"scale",
",",
"scale",
")",
")",
"\n",
"}"
] | // Scaled scales everything around a given point by the scale factor. | [
"Scaled",
"scales",
"everything",
"around",
"a",
"given",
"point",
"by",
"the",
"scale",
"factor",
"."
] | a68a4e38b42dde3869de57fddbaea6da106d5940 | https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/geometry.go#L1053-L1055 | train |
faiface/pixel | geometry.go | Rotated | func (m Matrix) Rotated(around Vec, angle float64) Matrix {
sint, cost := math.Sincos(angle)
m[4], m[5] = m[4]-around.X, m[5]-around.Y
m = m.Chained(Matrix{cost, sint, -sint, cost, 0, 0})
m[4], m[5] = m[4]+around.X, m[5]+around.Y
return m
} | go | func (m Matrix) Rotated(around Vec, angle float64) Matrix {
sint, cost := math.Sincos(angle)
m[4], m[5] = m[4]-around.X, m[5]-around.Y
m = m.Chained(Matrix{cost, sint, -sint, cost, 0, 0})
m[4], m[5] = m[4]+around.X, m[5]+around.Y
return m
} | [
"func",
"(",
"m",
"Matrix",
")",
"Rotated",
"(",
"around",
"Vec",
",",
"angle",
"float64",
")",
"Matrix",
"{",
"sint",
",",
"cost",
":=",
"math",
".",
"Sincos",
"(",
"angle",
")",
"\n",
"m",
"[",
"4",
"]",
",",
"m",
"[",
"5",
"]",
"=",
"m",
"[",
"4",
"]",
"-",
"around",
".",
"X",
",",
"m",
"[",
"5",
"]",
"-",
"around",
".",
"Y",
"\n",
"m",
"=",
"m",
".",
"Chained",
"(",
"Matrix",
"{",
"cost",
",",
"sint",
",",
"-",
"sint",
",",
"cost",
",",
"0",
",",
"0",
"}",
")",
"\n",
"m",
"[",
"4",
"]",
",",
"m",
"[",
"5",
"]",
"=",
"m",
"[",
"4",
"]",
"+",
"around",
".",
"X",
",",
"m",
"[",
"5",
"]",
"+",
"around",
".",
"Y",
"\n",
"return",
"m",
"\n",
"}"
] | // Rotated rotates everything around a given point by the given angle in radians. | [
"Rotated",
"rotates",
"everything",
"around",
"a",
"given",
"point",
"by",
"the",
"given",
"angle",
"in",
"radians",
"."
] | a68a4e38b42dde3869de57fddbaea6da106d5940 | https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/geometry.go#L1058-L1064 | train |
faiface/pixel | geometry.go | Chained | func (m Matrix) Chained(next Matrix) Matrix {
return Matrix{
next[0]*m[0] + next[2]*m[1],
next[1]*m[0] + next[3]*m[1],
next[0]*m[2] + next[2]*m[3],
next[1]*m[2] + next[3]*m[3],
next[0]*m[4] + next[2]*m[5] + next[4],
next[1]*m[4] + next[3]*m[5] + next[5],
}
} | go | func (m Matrix) Chained(next Matrix) Matrix {
return Matrix{
next[0]*m[0] + next[2]*m[1],
next[1]*m[0] + next[3]*m[1],
next[0]*m[2] + next[2]*m[3],
next[1]*m[2] + next[3]*m[3],
next[0]*m[4] + next[2]*m[5] + next[4],
next[1]*m[4] + next[3]*m[5] + next[5],
}
} | [
"func",
"(",
"m",
"Matrix",
")",
"Chained",
"(",
"next",
"Matrix",
")",
"Matrix",
"{",
"return",
"Matrix",
"{",
"next",
"[",
"0",
"]",
"*",
"m",
"[",
"0",
"]",
"+",
"next",
"[",
"2",
"]",
"*",
"m",
"[",
"1",
"]",
",",
"next",
"[",
"1",
"]",
"*",
"m",
"[",
"0",
"]",
"+",
"next",
"[",
"3",
"]",
"*",
"m",
"[",
"1",
"]",
",",
"next",
"[",
"0",
"]",
"*",
"m",
"[",
"2",
"]",
"+",
"next",
"[",
"2",
"]",
"*",
"m",
"[",
"3",
"]",
",",
"next",
"[",
"1",
"]",
"*",
"m",
"[",
"2",
"]",
"+",
"next",
"[",
"3",
"]",
"*",
"m",
"[",
"3",
"]",
",",
"next",
"[",
"0",
"]",
"*",
"m",
"[",
"4",
"]",
"+",
"next",
"[",
"2",
"]",
"*",
"m",
"[",
"5",
"]",
"+",
"next",
"[",
"4",
"]",
",",
"next",
"[",
"1",
"]",
"*",
"m",
"[",
"4",
"]",
"+",
"next",
"[",
"3",
"]",
"*",
"m",
"[",
"5",
"]",
"+",
"next",
"[",
"5",
"]",
",",
"}",
"\n",
"}"
] | // Chained adds another Matrix to this one. All tranformations by the next Matrix will be applied
// after the transformations of this Matrix. | [
"Chained",
"adds",
"another",
"Matrix",
"to",
"this",
"one",
".",
"All",
"tranformations",
"by",
"the",
"next",
"Matrix",
"will",
"be",
"applied",
"after",
"the",
"transformations",
"of",
"this",
"Matrix",
"."
] | a68a4e38b42dde3869de57fddbaea6da106d5940 | https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/geometry.go#L1068-L1077 | train |
faiface/pixel | text/text.go | BoundsOf | func (txt *Text) BoundsOf(s string) pixel.Rect {
dot := txt.Dot
prevR := txt.prevR
bounds := pixel.Rect{}
for _, r := range s {
var control bool
dot, control = txt.controlRune(r, dot)
if control {
continue
}
var b pixel.Rect
_, _, b, dot = txt.Atlas().DrawRune(prevR, r, dot)
if bounds.W()*bounds.H() == 0 {
bounds = b
} else {
bounds = bounds.Union(b)
}
prevR = r
}
return bounds
} | go | func (txt *Text) BoundsOf(s string) pixel.Rect {
dot := txt.Dot
prevR := txt.prevR
bounds := pixel.Rect{}
for _, r := range s {
var control bool
dot, control = txt.controlRune(r, dot)
if control {
continue
}
var b pixel.Rect
_, _, b, dot = txt.Atlas().DrawRune(prevR, r, dot)
if bounds.W()*bounds.H() == 0 {
bounds = b
} else {
bounds = bounds.Union(b)
}
prevR = r
}
return bounds
} | [
"func",
"(",
"txt",
"*",
"Text",
")",
"BoundsOf",
"(",
"s",
"string",
")",
"pixel",
".",
"Rect",
"{",
"dot",
":=",
"txt",
".",
"Dot",
"\n",
"prevR",
":=",
"txt",
".",
"prevR",
"\n",
"bounds",
":=",
"pixel",
".",
"Rect",
"{",
"}",
"\n\n",
"for",
"_",
",",
"r",
":=",
"range",
"s",
"{",
"var",
"control",
"bool",
"\n",
"dot",
",",
"control",
"=",
"txt",
".",
"controlRune",
"(",
"r",
",",
"dot",
")",
"\n",
"if",
"control",
"{",
"continue",
"\n",
"}",
"\n\n",
"var",
"b",
"pixel",
".",
"Rect",
"\n",
"_",
",",
"_",
",",
"b",
",",
"dot",
"=",
"txt",
".",
"Atlas",
"(",
")",
".",
"DrawRune",
"(",
"prevR",
",",
"r",
",",
"dot",
")",
"\n\n",
"if",
"bounds",
".",
"W",
"(",
")",
"*",
"bounds",
".",
"H",
"(",
")",
"==",
"0",
"{",
"bounds",
"=",
"b",
"\n",
"}",
"else",
"{",
"bounds",
"=",
"bounds",
".",
"Union",
"(",
"b",
")",
"\n",
"}",
"\n\n",
"prevR",
"=",
"r",
"\n",
"}",
"\n\n",
"return",
"bounds",
"\n",
"}"
] | // BoundsOf returns the bounding box of s if it was to be written to the Text right now. | [
"BoundsOf",
"returns",
"the",
"bounding",
"box",
"of",
"s",
"if",
"it",
"was",
"to",
"be",
"written",
"to",
"the",
"Text",
"right",
"now",
"."
] | a68a4e38b42dde3869de57fddbaea6da106d5940 | https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/text/text.go#L158-L183 | train |
faiface/pixel | text/text.go | Clear | func (txt *Text) Clear() {
txt.prevR = -1
txt.bounds = pixel.Rect{}
txt.tris.SetLen(0)
txt.dirty = true
txt.Dot = txt.Orig
} | go | func (txt *Text) Clear() {
txt.prevR = -1
txt.bounds = pixel.Rect{}
txt.tris.SetLen(0)
txt.dirty = true
txt.Dot = txt.Orig
} | [
"func",
"(",
"txt",
"*",
"Text",
")",
"Clear",
"(",
")",
"{",
"txt",
".",
"prevR",
"=",
"-",
"1",
"\n",
"txt",
".",
"bounds",
"=",
"pixel",
".",
"Rect",
"{",
"}",
"\n",
"txt",
".",
"tris",
".",
"SetLen",
"(",
"0",
")",
"\n",
"txt",
".",
"dirty",
"=",
"true",
"\n",
"txt",
".",
"Dot",
"=",
"txt",
".",
"Orig",
"\n",
"}"
] | // Clear removes all written text from the Text. The Dot field is reset to Orig. | [
"Clear",
"removes",
"all",
"written",
"text",
"from",
"the",
"Text",
".",
"The",
"Dot",
"field",
"is",
"reset",
"to",
"Orig",
"."
] | a68a4e38b42dde3869de57fddbaea6da106d5940 | https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/text/text.go#L186-L192 | train |
faiface/pixel | text/text.go | WriteByte | func (txt *Text) WriteByte(c byte) error {
txt.buf = append(txt.buf, c)
txt.drawBuf()
return nil
} | go | func (txt *Text) WriteByte(c byte) error {
txt.buf = append(txt.buf, c)
txt.drawBuf()
return nil
} | [
"func",
"(",
"txt",
"*",
"Text",
")",
"WriteByte",
"(",
"c",
"byte",
")",
"error",
"{",
"txt",
".",
"buf",
"=",
"append",
"(",
"txt",
".",
"buf",
",",
"c",
")",
"\n",
"txt",
".",
"drawBuf",
"(",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // WriteByte writes a byte to the Text. This method never fails, always returns nil.
//
// Writing a multi-byte rune byte-by-byte is perfectly supported. | [
"WriteByte",
"writes",
"a",
"byte",
"to",
"the",
"Text",
".",
"This",
"method",
"never",
"fails",
"always",
"returns",
"nil",
".",
"Writing",
"a",
"multi",
"-",
"byte",
"rune",
"byte",
"-",
"by",
"-",
"byte",
"is",
"perfectly",
"supported",
"."
] | a68a4e38b42dde3869de57fddbaea6da106d5940 | https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/text/text.go#L211-L215 | train |
faiface/pixel | text/text.go | Draw | func (txt *Text) Draw(t pixel.Target, matrix pixel.Matrix) {
txt.DrawColorMask(t, matrix, nil)
} | go | func (txt *Text) Draw(t pixel.Target, matrix pixel.Matrix) {
txt.DrawColorMask(t, matrix, nil)
} | [
"func",
"(",
"txt",
"*",
"Text",
")",
"Draw",
"(",
"t",
"pixel",
".",
"Target",
",",
"matrix",
"pixel",
".",
"Matrix",
")",
"{",
"txt",
".",
"DrawColorMask",
"(",
"t",
",",
"matrix",
",",
"nil",
")",
"\n",
"}"
] | // Draw draws all text written to the Text to the provided Target. The text is transformed by the
// provided Matrix.
//
// This method is equivalent to calling DrawColorMask with nil color mask.
//
// If there's a lot of text written to the Text, changing a matrix or a color mask often might hurt
// performance. Consider using your Target's SetMatrix or SetColorMask methods if available. | [
"Draw",
"draws",
"all",
"text",
"written",
"to",
"the",
"Text",
"to",
"the",
"provided",
"Target",
".",
"The",
"text",
"is",
"transformed",
"by",
"the",
"provided",
"Matrix",
".",
"This",
"method",
"is",
"equivalent",
"to",
"calling",
"DrawColorMask",
"with",
"nil",
"color",
"mask",
".",
"If",
"there",
"s",
"a",
"lot",
"of",
"text",
"written",
"to",
"the",
"Text",
"changing",
"a",
"matrix",
"or",
"a",
"color",
"mask",
"often",
"might",
"hurt",
"performance",
".",
"Consider",
"using",
"your",
"Target",
"s",
"SetMatrix",
"or",
"SetColorMask",
"methods",
"if",
"available",
"."
] | a68a4e38b42dde3869de57fddbaea6da106d5940 | https://github.com/faiface/pixel/blob/a68a4e38b42dde3869de57fddbaea6da106d5940/text/text.go#L233-L235 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.