id
int32
0
58k
repo
stringlengths
5
67
path
stringlengths
4
116
func_name
stringlengths
0
58
original_string
stringlengths
52
373k
language
stringclasses
1 value
code
stringlengths
52
373k
code_tokens
list
docstring
stringlengths
4
11.8k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
86
226
19,300
MarkBind/markbind
__mocks__/fs-extra-promise.js
createDir
function createDir(pathArg) { const { dir, ext } = path.parse(pathArg); const dirNames = (ext === '') ? pathArg.split(path.sep) : dir.split(pathArg.sep); dirNames.reduce((accumDir, currentdir) => { const jointDir = path.join(accumDir, currentdir); if (!fs.existsSync(jointDir)) { fs.mkdirSync(jointDir); } return jointDir; }, ''); }
javascript
function createDir(pathArg) { const { dir, ext } = path.parse(pathArg); const dirNames = (ext === '') ? pathArg.split(path.sep) : dir.split(pathArg.sep); dirNames.reduce((accumDir, currentdir) => { const jointDir = path.join(accumDir, currentdir); if (!fs.existsSync(jointDir)) { fs.mkdirSync(jointDir); } return jointDir; }, ''); }
[ "function", "createDir", "(", "pathArg", ")", "{", "const", "{", "dir", ",", "ext", "}", "=", "path", ".", "parse", "(", "pathArg", ")", ";", "const", "dirNames", "=", "(", "ext", "===", "''", ")", "?", "pathArg", ".", "split", "(", "path", ".", "sep", ")", ":", "dir", ".", "split", "(", "pathArg", ".", "sep", ")", ";", "dirNames", ".", "reduce", "(", "(", "accumDir", ",", "currentdir", ")", "=>", "{", "const", "jointDir", "=", "path", ".", "join", "(", "accumDir", ",", "currentdir", ")", ";", "if", "(", "!", "fs", ".", "existsSync", "(", "jointDir", ")", ")", "{", "fs", ".", "mkdirSync", "(", "jointDir", ")", ";", "}", "return", "jointDir", ";", "}", ",", "''", ")", ";", "}" ]
Iteratively creates directories to the file or directory @param pathArg
[ "Iteratively", "creates", "directories", "to", "the", "file", "or", "directory" ]
4d1101243781742448475993b43b6da2921836ab
https://github.com/MarkBind/markbind/blob/4d1101243781742448475993b43b6da2921836ab/__mocks__/fs-extra-promise.js#L32-L45
19,301
MarkBind/markbind
__mocks__/fs-extra-promise.js
copyDirSync
function copyDirSync(src, dest) { if (fs.lstatSync(src).isDirectory()) { const files = fs.readdirSync(src); files.forEach((file) => { const curSource = path.join(src, file); const curDest = path.join(dest, file); if (fs.lstatSync(curSource).isDirectory()) { if (!fs.existsSync(curDest)) { createDir(curDest); } copyDirSync(curSource, curDest); } else { copyFileSync(curSource, curDest); } }); } }
javascript
function copyDirSync(src, dest) { if (fs.lstatSync(src).isDirectory()) { const files = fs.readdirSync(src); files.forEach((file) => { const curSource = path.join(src, file); const curDest = path.join(dest, file); if (fs.lstatSync(curSource).isDirectory()) { if (!fs.existsSync(curDest)) { createDir(curDest); } copyDirSync(curSource, curDest); } else { copyFileSync(curSource, curDest); } }); } }
[ "function", "copyDirSync", "(", "src", ",", "dest", ")", "{", "if", "(", "fs", ".", "lstatSync", "(", "src", ")", ".", "isDirectory", "(", ")", ")", "{", "const", "files", "=", "fs", ".", "readdirSync", "(", "src", ")", ";", "files", ".", "forEach", "(", "(", "file", ")", "=>", "{", "const", "curSource", "=", "path", ".", "join", "(", "src", ",", "file", ")", ";", "const", "curDest", "=", "path", ".", "join", "(", "dest", ",", "file", ")", ";", "if", "(", "fs", ".", "lstatSync", "(", "curSource", ")", ".", "isDirectory", "(", ")", ")", "{", "if", "(", "!", "fs", ".", "existsSync", "(", "curDest", ")", ")", "{", "createDir", "(", "curDest", ")", ";", "}", "copyDirSync", "(", "curSource", ",", "curDest", ")", ";", "}", "else", "{", "copyFileSync", "(", "curSource", ",", "curDest", ")", ";", "}", "}", ")", ";", "}", "}" ]
Utility function to copy a directory to a destination recursively
[ "Utility", "function", "to", "copy", "a", "directory", "to", "a", "destination", "recursively" ]
4d1101243781742448475993b43b6da2921836ab
https://github.com/MarkBind/markbind/blob/4d1101243781742448475993b43b6da2921836ab/__mocks__/fs-extra-promise.js#L60-L76
19,302
MarkBind/markbind
__mocks__/fs-extra-promise.js
copyDirAsync
function copyDirAsync(src, dest) { if (fs.lstatSync(src).isDirectory()) { const files = fs.readdirSync(src); files.forEach((file) => { const curSource = path.join(src, file); const curDest = path.join(dest, file); if (fs.lstatSync(curSource).isDirectory()) { if (!fs.existsSync(curDest)) { createDir(curDest); } copyDirAsync(curSource, curDest); } else { fs.copyAsync(curSource, curDest); } }); } }
javascript
function copyDirAsync(src, dest) { if (fs.lstatSync(src).isDirectory()) { const files = fs.readdirSync(src); files.forEach((file) => { const curSource = path.join(src, file); const curDest = path.join(dest, file); if (fs.lstatSync(curSource).isDirectory()) { if (!fs.existsSync(curDest)) { createDir(curDest); } copyDirAsync(curSource, curDest); } else { fs.copyAsync(curSource, curDest); } }); } }
[ "function", "copyDirAsync", "(", "src", ",", "dest", ")", "{", "if", "(", "fs", ".", "lstatSync", "(", "src", ")", ".", "isDirectory", "(", ")", ")", "{", "const", "files", "=", "fs", ".", "readdirSync", "(", "src", ")", ";", "files", ".", "forEach", "(", "(", "file", ")", "=>", "{", "const", "curSource", "=", "path", ".", "join", "(", "src", ",", "file", ")", ";", "const", "curDest", "=", "path", ".", "join", "(", "dest", ",", "file", ")", ";", "if", "(", "fs", ".", "lstatSync", "(", "curSource", ")", ".", "isDirectory", "(", ")", ")", "{", "if", "(", "!", "fs", ".", "existsSync", "(", "curDest", ")", ")", "{", "createDir", "(", "curDest", ")", ";", "}", "copyDirAsync", "(", "curSource", ",", "curDest", ")", ";", "}", "else", "{", "fs", ".", "copyAsync", "(", "curSource", ",", "curDest", ")", ";", "}", "}", ")", ";", "}", "}" ]
Utility function to copy a directory to a destination recursively for copyAsync
[ "Utility", "function", "to", "copy", "a", "directory", "to", "a", "destination", "recursively", "for", "copyAsync" ]
4d1101243781742448475993b43b6da2921836ab
https://github.com/MarkBind/markbind/blob/4d1101243781742448475993b43b6da2921836ab/__mocks__/fs-extra-promise.js#L81-L97
19,303
MarkBind/markbind
src/plugins/default/markbind-plugin-anchors.js
generateHeadingSelector
function generateHeadingSelector(headingIndexingLevel) { let headingsSelector = 'h1'; for (let i = 2; i <= headingIndexingLevel; i += 1) { headingsSelector += `, h${i}`; } return headingsSelector; }
javascript
function generateHeadingSelector(headingIndexingLevel) { let headingsSelector = 'h1'; for (let i = 2; i <= headingIndexingLevel; i += 1) { headingsSelector += `, h${i}`; } return headingsSelector; }
[ "function", "generateHeadingSelector", "(", "headingIndexingLevel", ")", "{", "let", "headingsSelector", "=", "'h1'", ";", "for", "(", "let", "i", "=", "2", ";", "i", "<=", "headingIndexingLevel", ";", "i", "+=", "1", ")", "{", "headingsSelector", "+=", "`", "${", "i", "}", "`", ";", "}", "return", "headingsSelector", ";", "}" ]
Generates a heading selector based on the indexing level @param headingIndexingLevel to generate
[ "Generates", "a", "heading", "selector", "based", "on", "the", "indexing", "level" ]
4d1101243781742448475993b43b6da2921836ab
https://github.com/MarkBind/markbind/blob/4d1101243781742448475993b43b6da2921836ab/src/plugins/default/markbind-plugin-anchors.js#L10-L16
19,304
MarkBind/markbind
src/Page.js
Page
function Page(pageConfig) { this.asset = pageConfig.asset; this.baseUrl = pageConfig.baseUrl; this.baseUrlMap = pageConfig.baseUrlMap; this.content = pageConfig.content || ''; this.faviconUrl = pageConfig.faviconUrl; this.frontmatterOverride = pageConfig.frontmatter || {}; this.layout = pageConfig.layout; this.layoutsAssetPath = pageConfig.layoutsAssetPath; this.rootPath = pageConfig.rootPath; this.enableSearch = pageConfig.enableSearch; this.globalOverride = pageConfig.globalOverride; this.plugins = pageConfig.plugins; this.pluginsContext = pageConfig.pluginsContext; this.searchable = pageConfig.searchable; this.src = pageConfig.src; this.template = pageConfig.pageTemplate; this.title = pageConfig.title || ''; this.titlePrefix = pageConfig.titlePrefix; this.userDefinedVariablesMap = pageConfig.userDefinedVariablesMap; // the source file for rendering this page this.sourcePath = pageConfig.sourcePath; // the temp path for writing intermediate result this.tempPath = pageConfig.tempPath; // the output path of this page this.resultPath = pageConfig.resultPath; this.frontMatter = {}; this.headFileBottomContent = ''; this.headFileTopContent = ''; this.headings = {}; this.headingIndexingLevel = pageConfig.headingIndexingLevel; this.includedFiles = {}; this.keywords = {}; this.navigableHeadings = {}; this.pageSectionsHtml = {}; // Flag to indicate whether this page has a site nav this.hasSiteNav = false; }
javascript
function Page(pageConfig) { this.asset = pageConfig.asset; this.baseUrl = pageConfig.baseUrl; this.baseUrlMap = pageConfig.baseUrlMap; this.content = pageConfig.content || ''; this.faviconUrl = pageConfig.faviconUrl; this.frontmatterOverride = pageConfig.frontmatter || {}; this.layout = pageConfig.layout; this.layoutsAssetPath = pageConfig.layoutsAssetPath; this.rootPath = pageConfig.rootPath; this.enableSearch = pageConfig.enableSearch; this.globalOverride = pageConfig.globalOverride; this.plugins = pageConfig.plugins; this.pluginsContext = pageConfig.pluginsContext; this.searchable = pageConfig.searchable; this.src = pageConfig.src; this.template = pageConfig.pageTemplate; this.title = pageConfig.title || ''; this.titlePrefix = pageConfig.titlePrefix; this.userDefinedVariablesMap = pageConfig.userDefinedVariablesMap; // the source file for rendering this page this.sourcePath = pageConfig.sourcePath; // the temp path for writing intermediate result this.tempPath = pageConfig.tempPath; // the output path of this page this.resultPath = pageConfig.resultPath; this.frontMatter = {}; this.headFileBottomContent = ''; this.headFileTopContent = ''; this.headings = {}; this.headingIndexingLevel = pageConfig.headingIndexingLevel; this.includedFiles = {}; this.keywords = {}; this.navigableHeadings = {}; this.pageSectionsHtml = {}; // Flag to indicate whether this page has a site nav this.hasSiteNav = false; }
[ "function", "Page", "(", "pageConfig", ")", "{", "this", ".", "asset", "=", "pageConfig", ".", "asset", ";", "this", ".", "baseUrl", "=", "pageConfig", ".", "baseUrl", ";", "this", ".", "baseUrlMap", "=", "pageConfig", ".", "baseUrlMap", ";", "this", ".", "content", "=", "pageConfig", ".", "content", "||", "''", ";", "this", ".", "faviconUrl", "=", "pageConfig", ".", "faviconUrl", ";", "this", ".", "frontmatterOverride", "=", "pageConfig", ".", "frontmatter", "||", "{", "}", ";", "this", ".", "layout", "=", "pageConfig", ".", "layout", ";", "this", ".", "layoutsAssetPath", "=", "pageConfig", ".", "layoutsAssetPath", ";", "this", ".", "rootPath", "=", "pageConfig", ".", "rootPath", ";", "this", ".", "enableSearch", "=", "pageConfig", ".", "enableSearch", ";", "this", ".", "globalOverride", "=", "pageConfig", ".", "globalOverride", ";", "this", ".", "plugins", "=", "pageConfig", ".", "plugins", ";", "this", ".", "pluginsContext", "=", "pageConfig", ".", "pluginsContext", ";", "this", ".", "searchable", "=", "pageConfig", ".", "searchable", ";", "this", ".", "src", "=", "pageConfig", ".", "src", ";", "this", ".", "template", "=", "pageConfig", ".", "pageTemplate", ";", "this", ".", "title", "=", "pageConfig", ".", "title", "||", "''", ";", "this", ".", "titlePrefix", "=", "pageConfig", ".", "titlePrefix", ";", "this", ".", "userDefinedVariablesMap", "=", "pageConfig", ".", "userDefinedVariablesMap", ";", "// the source file for rendering this page", "this", ".", "sourcePath", "=", "pageConfig", ".", "sourcePath", ";", "// the temp path for writing intermediate result", "this", ".", "tempPath", "=", "pageConfig", ".", "tempPath", ";", "// the output path of this page", "this", ".", "resultPath", "=", "pageConfig", ".", "resultPath", ";", "this", ".", "frontMatter", "=", "{", "}", ";", "this", ".", "headFileBottomContent", "=", "''", ";", "this", ".", "headFileTopContent", "=", "''", ";", "this", ".", "headings", "=", "{", "}", ";", "this", ".", "headingIndexingLevel", "=", "pageConfig", ".", "headingIndexingLevel", ";", "this", ".", "includedFiles", "=", "{", "}", ";", "this", ".", "keywords", "=", "{", "}", ";", "this", ".", "navigableHeadings", "=", "{", "}", ";", "this", ".", "pageSectionsHtml", "=", "{", "}", ";", "// Flag to indicate whether this page has a site nav", "this", ".", "hasSiteNav", "=", "false", ";", "}" ]
Don't escape HTML entities
[ "Don", "t", "escape", "HTML", "entities" ]
4d1101243781742448475993b43b6da2921836ab
https://github.com/MarkBind/markbind/blob/4d1101243781742448475993b43b6da2921836ab/src/Page.js#L53-L93
19,305
MarkBind/markbind
src/Page.js
generateHeadingSelector
function generateHeadingSelector(headingIndexingLevel) { let headingsSelectors = ['.always-index:header', 'h1']; for (let i = 2; i <= headingIndexingLevel; i += 1) { headingsSelectors.push(`h${i}`); } headingsSelectors = headingsSelectors.map(selector => `${selector}:not(.no-index)`); return headingsSelectors.join(','); }
javascript
function generateHeadingSelector(headingIndexingLevel) { let headingsSelectors = ['.always-index:header', 'h1']; for (let i = 2; i <= headingIndexingLevel; i += 1) { headingsSelectors.push(`h${i}`); } headingsSelectors = headingsSelectors.map(selector => `${selector}:not(.no-index)`); return headingsSelectors.join(','); }
[ "function", "generateHeadingSelector", "(", "headingIndexingLevel", ")", "{", "let", "headingsSelectors", "=", "[", "'.always-index:header'", ",", "'h1'", "]", ";", "for", "(", "let", "i", "=", "2", ";", "i", "<=", "headingIndexingLevel", ";", "i", "+=", "1", ")", "{", "headingsSelectors", ".", "push", "(", "`", "${", "i", "}", "`", ")", ";", "}", "headingsSelectors", "=", "headingsSelectors", ".", "map", "(", "selector", "=>", "`", "${", "selector", "}", "`", ")", ";", "return", "headingsSelectors", ".", "join", "(", "','", ")", ";", "}" ]
Generates a selector for headings with level inside the headingIndexLevel or with the index attribute, that do not also have the noindex attribute @param headingIndexingLevel to generate
[ "Generates", "a", "selector", "for", "headings", "with", "level", "inside", "the", "headingIndexLevel", "or", "with", "the", "index", "attribute", "that", "do", "not", "also", "have", "the", "noindex", "attribute" ]
4d1101243781742448475993b43b6da2921836ab
https://github.com/MarkBind/markbind/blob/4d1101243781742448475993b43b6da2921836ab/src/Page.js#L201-L208
19,306
MarkBind/markbind
src/Page.js
getClosestHeading
function getClosestHeading($, headingsSelector, element) { const prevElements = $(element).prevAll(); for (let i = 0; i < prevElements.length; i += 1) { const currentElement = $(prevElements[i]); if (currentElement.is(headingsSelector)) { return currentElement; } const childHeadings = currentElement.find(headingsSelector); if (childHeadings.length > 0) { return childHeadings.last(); } } if ($(element).parent().length === 0) { return null; } return getClosestHeading($, headingsSelector, $(element).parent()); }
javascript
function getClosestHeading($, headingsSelector, element) { const prevElements = $(element).prevAll(); for (let i = 0; i < prevElements.length; i += 1) { const currentElement = $(prevElements[i]); if (currentElement.is(headingsSelector)) { return currentElement; } const childHeadings = currentElement.find(headingsSelector); if (childHeadings.length > 0) { return childHeadings.last(); } } if ($(element).parent().length === 0) { return null; } return getClosestHeading($, headingsSelector, $(element).parent()); }
[ "function", "getClosestHeading", "(", "$", ",", "headingsSelector", ",", "element", ")", "{", "const", "prevElements", "=", "$", "(", "element", ")", ".", "prevAll", "(", ")", ";", "for", "(", "let", "i", "=", "0", ";", "i", "<", "prevElements", ".", "length", ";", "i", "+=", "1", ")", "{", "const", "currentElement", "=", "$", "(", "prevElements", "[", "i", "]", ")", ";", "if", "(", "currentElement", ".", "is", "(", "headingsSelector", ")", ")", "{", "return", "currentElement", ";", "}", "const", "childHeadings", "=", "currentElement", ".", "find", "(", "headingsSelector", ")", ";", "if", "(", "childHeadings", ".", "length", ">", "0", ")", "{", "return", "childHeadings", ".", "last", "(", ")", ";", "}", "}", "if", "(", "$", "(", "element", ")", ".", "parent", "(", ")", ".", "length", "===", "0", ")", "{", "return", "null", ";", "}", "return", "getClosestHeading", "(", "$", ",", "headingsSelector", ",", "$", "(", "element", ")", ".", "parent", "(", ")", ")", ";", "}" ]
Gets the closest heading to an element @param $ a Cheerio object @param headingsSelector jQuery selector for selecting headings @param element to find closest heading
[ "Gets", "the", "closest", "heading", "to", "an", "element" ]
4d1101243781742448475993b43b6da2921836ab
https://github.com/MarkBind/markbind/blob/4d1101243781742448475993b43b6da2921836ab/src/Page.js#L250-L266
19,307
MarkBind/markbind
src/lib/markbind/src/parser.js
extractIncludeVariables
function extractIncludeVariables(includeElement, contextVariables) { const includedVariables = { ...contextVariables }; Object.keys(includeElement.attribs).forEach((attribute) => { if (!attribute.startsWith('var-')) { return; } const variableName = attribute.replace(/^var-/, ''); if (!includedVariables[variableName]) { includedVariables[variableName] = includeElement.attribs[attribute]; } }); if (includeElement.children) { includeElement.children.forEach((child) => { if (child.name !== 'variable' && child.name !== 'span') { return; } const variableName = child.attribs.name || child.attribs.id; if (!variableName) { // eslint-disable-next-line no-console console.warn(`Missing reference in ${includeElement.attribs[ATTRIB_CWF]}\n` + `Missing 'name' or 'id' in variable for ${includeElement.attribs.src} include.`); return; } if (!includedVariables[variableName]) { includedVariables[variableName] = cheerio.html(child.children); } }); } return includedVariables; }
javascript
function extractIncludeVariables(includeElement, contextVariables) { const includedVariables = { ...contextVariables }; Object.keys(includeElement.attribs).forEach((attribute) => { if (!attribute.startsWith('var-')) { return; } const variableName = attribute.replace(/^var-/, ''); if (!includedVariables[variableName]) { includedVariables[variableName] = includeElement.attribs[attribute]; } }); if (includeElement.children) { includeElement.children.forEach((child) => { if (child.name !== 'variable' && child.name !== 'span') { return; } const variableName = child.attribs.name || child.attribs.id; if (!variableName) { // eslint-disable-next-line no-console console.warn(`Missing reference in ${includeElement.attribs[ATTRIB_CWF]}\n` + `Missing 'name' or 'id' in variable for ${includeElement.attribs.src} include.`); return; } if (!includedVariables[variableName]) { includedVariables[variableName] = cheerio.html(child.children); } }); } return includedVariables; }
[ "function", "extractIncludeVariables", "(", "includeElement", ",", "contextVariables", ")", "{", "const", "includedVariables", "=", "{", "...", "contextVariables", "}", ";", "Object", ".", "keys", "(", "includeElement", ".", "attribs", ")", ".", "forEach", "(", "(", "attribute", ")", "=>", "{", "if", "(", "!", "attribute", ".", "startsWith", "(", "'var-'", ")", ")", "{", "return", ";", "}", "const", "variableName", "=", "attribute", ".", "replace", "(", "/", "^var-", "/", ",", "''", ")", ";", "if", "(", "!", "includedVariables", "[", "variableName", "]", ")", "{", "includedVariables", "[", "variableName", "]", "=", "includeElement", ".", "attribs", "[", "attribute", "]", ";", "}", "}", ")", ";", "if", "(", "includeElement", ".", "children", ")", "{", "includeElement", ".", "children", ".", "forEach", "(", "(", "child", ")", "=>", "{", "if", "(", "child", ".", "name", "!==", "'variable'", "&&", "child", ".", "name", "!==", "'span'", ")", "{", "return", ";", "}", "const", "variableName", "=", "child", ".", "attribs", ".", "name", "||", "child", ".", "attribs", ".", "id", ";", "if", "(", "!", "variableName", ")", "{", "// eslint-disable-next-line no-console", "console", ".", "warn", "(", "`", "${", "includeElement", ".", "attribs", "[", "ATTRIB_CWF", "]", "}", "\\n", "`", "+", "`", "${", "includeElement", ".", "attribs", ".", "src", "}", "`", ")", ";", "return", ";", "}", "if", "(", "!", "includedVariables", "[", "variableName", "]", ")", "{", "includedVariables", "[", "variableName", "]", "=", "cheerio", ".", "html", "(", "child", ".", "children", ")", ";", "}", "}", ")", ";", "}", "return", "includedVariables", ";", "}" ]
Extract variables from an include element @param includeElement include element to extract variables from @param contextVariables variables defined by parent pages
[ "Extract", "variables", "from", "an", "include", "element" ]
4d1101243781742448475993b43b6da2921836ab
https://github.com/MarkBind/markbind/blob/4d1101243781742448475993b43b6da2921836ab/src/lib/markbind/src/parser.js#L97-L126
19,308
MarkBind/markbind
src/lib/markbind/src/parser.js
extractPageVariables
function extractPageVariables(fileName, data, userDefinedVariables, includedVariables) { const $ = cheerio.load(data); const pageVariables = { }; $('variable').each(function () { const variableElement = $(this); const variableName = variableElement.attr('name'); if (!variableName) { // eslint-disable-next-line no-console console.warn(`Missing 'name' for variable in ${fileName}\n`); return; } if (!pageVariables[variableName]) { const variableValue = nunjucks.renderString(md.renderInline(variableElement.html()), { ...pageVariables, ...userDefinedVariables, ...includedVariables }); pageVariables[variableName] = variableValue; if (!VARIABLE_LOOKUP[fileName]) { VARIABLE_LOOKUP[fileName] = {}; } VARIABLE_LOOKUP[fileName][variableName] = variableValue; } }); return pageVariables; }
javascript
function extractPageVariables(fileName, data, userDefinedVariables, includedVariables) { const $ = cheerio.load(data); const pageVariables = { }; $('variable').each(function () { const variableElement = $(this); const variableName = variableElement.attr('name'); if (!variableName) { // eslint-disable-next-line no-console console.warn(`Missing 'name' for variable in ${fileName}\n`); return; } if (!pageVariables[variableName]) { const variableValue = nunjucks.renderString(md.renderInline(variableElement.html()), { ...pageVariables, ...userDefinedVariables, ...includedVariables }); pageVariables[variableName] = variableValue; if (!VARIABLE_LOOKUP[fileName]) { VARIABLE_LOOKUP[fileName] = {}; } VARIABLE_LOOKUP[fileName][variableName] = variableValue; } }); return pageVariables; }
[ "function", "extractPageVariables", "(", "fileName", ",", "data", ",", "userDefinedVariables", ",", "includedVariables", ")", "{", "const", "$", "=", "cheerio", ".", "load", "(", "data", ")", ";", "const", "pageVariables", "=", "{", "}", ";", "$", "(", "'variable'", ")", ".", "each", "(", "function", "(", ")", "{", "const", "variableElement", "=", "$", "(", "this", ")", ";", "const", "variableName", "=", "variableElement", ".", "attr", "(", "'name'", ")", ";", "if", "(", "!", "variableName", ")", "{", "// eslint-disable-next-line no-console", "console", ".", "warn", "(", "`", "${", "fileName", "}", "\\n", "`", ")", ";", "return", ";", "}", "if", "(", "!", "pageVariables", "[", "variableName", "]", ")", "{", "const", "variableValue", "=", "nunjucks", ".", "renderString", "(", "md", ".", "renderInline", "(", "variableElement", ".", "html", "(", ")", ")", ",", "{", "...", "pageVariables", ",", "...", "userDefinedVariables", ",", "...", "includedVariables", "}", ")", ";", "pageVariables", "[", "variableName", "]", "=", "variableValue", ";", "if", "(", "!", "VARIABLE_LOOKUP", "[", "fileName", "]", ")", "{", "VARIABLE_LOOKUP", "[", "fileName", "]", "=", "{", "}", ";", "}", "VARIABLE_LOOKUP", "[", "fileName", "]", "[", "variableName", "]", "=", "variableValue", ";", "}", "}", ")", ";", "return", "pageVariables", ";", "}" ]
Extract page variables from a page @param filename for error printing @param data to extract variables from @param userDefinedVariables global variables @param includedVariables variables from parent include
[ "Extract", "page", "variables", "from", "a", "page" ]
4d1101243781742448475993b43b6da2921836ab
https://github.com/MarkBind/markbind/blob/4d1101243781742448475993b43b6da2921836ab/src/lib/markbind/src/parser.js#L135-L158
19,309
MarkBind/markbind
src/lib/markbind/src/parser.js
extractImportedVariables
function extractImportedVariables(context) { if (!context.importedVariables) { return {}; } const importedVariables = {}; Object.entries(context.importedVariables).forEach(([src, variables]) => { variables.forEach((variableName) => { const actualFilePath = utils.isUrl() ? src : path.resolve(path.dirname(context.cwf), decodeURIComponent(url.parse(src).path)); if (!VARIABLE_LOOKUP[actualFilePath] || !VARIABLE_LOOKUP[actualFilePath][variableName]) { // eslint-disable-next-line no-console console.warn(`Missing variable ${variableName} in ${src} referenced by ${context.cwf}\n`); return; } const variableValue = VARIABLE_LOOKUP[actualFilePath][variableName]; if (!importedVariables[variableName]) { importedVariables[variableName] = variableValue; } }); }); return importedVariables; }
javascript
function extractImportedVariables(context) { if (!context.importedVariables) { return {}; } const importedVariables = {}; Object.entries(context.importedVariables).forEach(([src, variables]) => { variables.forEach((variableName) => { const actualFilePath = utils.isUrl() ? src : path.resolve(path.dirname(context.cwf), decodeURIComponent(url.parse(src).path)); if (!VARIABLE_LOOKUP[actualFilePath] || !VARIABLE_LOOKUP[actualFilePath][variableName]) { // eslint-disable-next-line no-console console.warn(`Missing variable ${variableName} in ${src} referenced by ${context.cwf}\n`); return; } const variableValue = VARIABLE_LOOKUP[actualFilePath][variableName]; if (!importedVariables[variableName]) { importedVariables[variableName] = variableValue; } }); }); return importedVariables; }
[ "function", "extractImportedVariables", "(", "context", ")", "{", "if", "(", "!", "context", ".", "importedVariables", ")", "{", "return", "{", "}", ";", "}", "const", "importedVariables", "=", "{", "}", ";", "Object", ".", "entries", "(", "context", ".", "importedVariables", ")", ".", "forEach", "(", "(", "[", "src", ",", "variables", "]", ")", "=>", "{", "variables", ".", "forEach", "(", "(", "variableName", ")", "=>", "{", "const", "actualFilePath", "=", "utils", ".", "isUrl", "(", ")", "?", "src", ":", "path", ".", "resolve", "(", "path", ".", "dirname", "(", "context", ".", "cwf", ")", ",", "decodeURIComponent", "(", "url", ".", "parse", "(", "src", ")", ".", "path", ")", ")", ";", "if", "(", "!", "VARIABLE_LOOKUP", "[", "actualFilePath", "]", "||", "!", "VARIABLE_LOOKUP", "[", "actualFilePath", "]", "[", "variableName", "]", ")", "{", "// eslint-disable-next-line no-console", "console", ".", "warn", "(", "`", "${", "variableName", "}", "${", "src", "}", "${", "context", ".", "cwf", "}", "\\n", "`", ")", ";", "return", ";", "}", "const", "variableValue", "=", "VARIABLE_LOOKUP", "[", "actualFilePath", "]", "[", "variableName", "]", ";", "if", "(", "!", "importedVariables", "[", "variableName", "]", ")", "{", "importedVariables", "[", "variableName", "]", "=", "variableValue", ";", "}", "}", ")", ";", "}", ")", ";", "return", "importedVariables", ";", "}" ]
Extract imported page variables from a page @param context of the page
[ "Extract", "imported", "page", "variables", "from", "a", "page" ]
4d1101243781742448475993b43b6da2921836ab
https://github.com/MarkBind/markbind/blob/4d1101243781742448475993b43b6da2921836ab/src/lib/markbind/src/parser.js#L164-L186
19,310
riyadhalnur/node-base64-image
dist/node-base64-image.js
encode
function encode(url) { var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { string: false, local: false }; var callback = arguments[2]; // eslint-disable-line if (_lodash2.default.isUndefined(url) || _lodash2.default.isNull(url) || !_lodash2.default.isString(url)) { return callback(new Error('URL is undefined or not properly formatted')); } if (options.local) { (0, _fs.readFile)(url, function (err, body) { if (err) { return callback(err); } /** * @todo Handle this better. */ var result = options.string ? body.toString('base64') : new Buffer(body, 'base64'); return callback(null, result); }); } else { (0, _request2.default)({ url: url, encoding: null }, function (err, response, body) { if (err) { return callback(err); } if (!body) { return callback(new Error('Error retrieving image - Empty Body!')); } if (body && response.statusCode === 200) { /** * @todo Handle this better. */ var result = options.string ? body.toString('base64') : new Buffer(body, 'base64'); return callback(null, result); } return callback(new Error('Error retrieving image - Status Code ' + response.statusCode)); }); } }
javascript
function encode(url) { var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { string: false, local: false }; var callback = arguments[2]; // eslint-disable-line if (_lodash2.default.isUndefined(url) || _lodash2.default.isNull(url) || !_lodash2.default.isString(url)) { return callback(new Error('URL is undefined or not properly formatted')); } if (options.local) { (0, _fs.readFile)(url, function (err, body) { if (err) { return callback(err); } /** * @todo Handle this better. */ var result = options.string ? body.toString('base64') : new Buffer(body, 'base64'); return callback(null, result); }); } else { (0, _request2.default)({ url: url, encoding: null }, function (err, response, body) { if (err) { return callback(err); } if (!body) { return callback(new Error('Error retrieving image - Empty Body!')); } if (body && response.statusCode === 200) { /** * @todo Handle this better. */ var result = options.string ? body.toString('base64') : new Buffer(body, 'base64'); return callback(null, result); } return callback(new Error('Error retrieving image - Status Code ' + response.statusCode)); }); } }
[ "function", "encode", "(", "url", ")", "{", "var", "options", "=", "arguments", ".", "length", ">", "1", "&&", "arguments", "[", "1", "]", "!==", "undefined", "?", "arguments", "[", "1", "]", ":", "{", "string", ":", "false", ",", "local", ":", "false", "}", ";", "var", "callback", "=", "arguments", "[", "2", "]", ";", "// eslint-disable-line", "if", "(", "_lodash2", ".", "default", ".", "isUndefined", "(", "url", ")", "||", "_lodash2", ".", "default", ".", "isNull", "(", "url", ")", "||", "!", "_lodash2", ".", "default", ".", "isString", "(", "url", ")", ")", "{", "return", "callback", "(", "new", "Error", "(", "'URL is undefined or not properly formatted'", ")", ")", ";", "}", "if", "(", "options", ".", "local", ")", "{", "(", "0", ",", "_fs", ".", "readFile", ")", "(", "url", ",", "function", "(", "err", ",", "body", ")", "{", "if", "(", "err", ")", "{", "return", "callback", "(", "err", ")", ";", "}", "/**\n * @todo Handle this better.\n */", "var", "result", "=", "options", ".", "string", "?", "body", ".", "toString", "(", "'base64'", ")", ":", "new", "Buffer", "(", "body", ",", "'base64'", ")", ";", "return", "callback", "(", "null", ",", "result", ")", ";", "}", ")", ";", "}", "else", "{", "(", "0", ",", "_request2", ".", "default", ")", "(", "{", "url", ":", "url", ",", "encoding", ":", "null", "}", ",", "function", "(", "err", ",", "response", ",", "body", ")", "{", "if", "(", "err", ")", "{", "return", "callback", "(", "err", ")", ";", "}", "if", "(", "!", "body", ")", "{", "return", "callback", "(", "new", "Error", "(", "'Error retrieving image - Empty Body!'", ")", ")", ";", "}", "if", "(", "body", "&&", "response", ".", "statusCode", "===", "200", ")", "{", "/**\n * @todo Handle this better.\n */", "var", "result", "=", "options", ".", "string", "?", "body", ".", "toString", "(", "'base64'", ")", ":", "new", "Buffer", "(", "body", ",", "'base64'", ")", ";", "return", "callback", "(", "null", ",", "result", ")", ";", "}", "return", "callback", "(", "new", "Error", "(", "'Error retrieving image - Status Code '", "+", "response", ".", "statusCode", ")", ")", ";", "}", ")", ";", "}", "}" ]
Encodes a remote or local image to Base64 encoded string or Buffer @name encode @param {string} url - URL of remote image or local path to image @param {Object} [options={}] - Options object for extra configuration @param {boolean} options.string - Returns a Base64 encoded string. Defaults to Buffer object @param {boolean} options.local - Encode a local image file instead of a remote image @param {fnCallback} callback - Callback function @todo Option to wrap string every 76 characters for strings larger than 76 characters @return {fnCallback} - Returns the callback Callback for encode/decode functions @callback fnCallback @param {Object} Error object @param {(string|Object)} Response string or Buffer object
[ "Encodes", "a", "remote", "or", "local", "image", "to", "Base64", "encoded", "string", "or", "Buffer" ]
0fac0cdb9ff687e074f338e85a950899f00223b1
https://github.com/riyadhalnur/node-base64-image/blob/0fac0cdb9ff687e074f338e85a950899f00223b1/dist/node-base64-image.js#L42-L83
19,311
riyadhalnur/node-base64-image
dist/node-base64-image.js
decode
function decode(imageBuffer) { var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { filename: 'saved-image' }; var callback = arguments[2]; // eslint-disable-line if (!_lodash2.default.isBuffer(imageBuffer)) { return callback(new Error('The image is not a Buffer object type')); } (0, _fs.writeFile)(options.filename + '.jpg', imageBuffer, 'base64', function (err) { if (err) { return callback(err); } return callback(null, 'Image saved successfully to disk!'); }); }
javascript
function decode(imageBuffer) { var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { filename: 'saved-image' }; var callback = arguments[2]; // eslint-disable-line if (!_lodash2.default.isBuffer(imageBuffer)) { return callback(new Error('The image is not a Buffer object type')); } (0, _fs.writeFile)(options.filename + '.jpg', imageBuffer, 'base64', function (err) { if (err) { return callback(err); } return callback(null, 'Image saved successfully to disk!'); }); }
[ "function", "decode", "(", "imageBuffer", ")", "{", "var", "options", "=", "arguments", ".", "length", ">", "1", "&&", "arguments", "[", "1", "]", "!==", "undefined", "?", "arguments", "[", "1", "]", ":", "{", "filename", ":", "'saved-image'", "}", ";", "var", "callback", "=", "arguments", "[", "2", "]", ";", "// eslint-disable-line", "if", "(", "!", "_lodash2", ".", "default", ".", "isBuffer", "(", "imageBuffer", ")", ")", "{", "return", "callback", "(", "new", "Error", "(", "'The image is not a Buffer object type'", ")", ")", ";", "}", "(", "0", ",", "_fs", ".", "writeFile", ")", "(", "options", ".", "filename", "+", "'.jpg'", ",", "imageBuffer", ",", "'base64'", ",", "function", "(", "err", ")", "{", "if", "(", "err", ")", "{", "return", "callback", "(", "err", ")", ";", "}", "return", "callback", "(", "null", ",", "'Image saved successfully to disk!'", ")", ";", "}", ")", ";", "}" ]
Decodes an base64 encoded image buffer and saves it to disk @name decode @param {Buffer} imageBuffer - Image Buffer object @param {Object} [options={}] - Options object for extra configuration @param {string} options.filename - Filename for the final image file @param {fnCallback} callback - Callback function @return {fnCallback} - Returns the callback
[ "Decodes", "an", "base64", "encoded", "image", "buffer", "and", "saves", "it", "to", "disk" ]
0fac0cdb9ff687e074f338e85a950899f00223b1
https://github.com/riyadhalnur/node-base64-image/blob/0fac0cdb9ff687e074f338e85a950899f00223b1/dist/node-base64-image.js#L96-L111
19,312
silverwind/uppie
uppie.js
newDirectoryApi
function newDirectoryApi(input, opts, cb) { var fd = new FormData(), files = []; var iterate = function(entries, path, resolve) { var promises = []; entries.forEach(function(entry) { promises.push(new Promise(function(resolve) { if ("getFilesAndDirectories" in entry) { entry.getFilesAndDirectories().then(function(entries) { iterate(entries, entry.path + "/", resolve); }); } else { if (entry.name) { var p = (path + entry.name).replace(/^[/\\]/, ""); fd.append(opts.name, entry, p); files.push(p); } resolve(); } })); }); Promise.all(promises).then(resolve); }; input.getFilesAndDirectories().then(function(entries) { new Promise(function(resolve) { iterate(entries, "/", resolve); }).then(cb.bind(null, fd, files)); }); }
javascript
function newDirectoryApi(input, opts, cb) { var fd = new FormData(), files = []; var iterate = function(entries, path, resolve) { var promises = []; entries.forEach(function(entry) { promises.push(new Promise(function(resolve) { if ("getFilesAndDirectories" in entry) { entry.getFilesAndDirectories().then(function(entries) { iterate(entries, entry.path + "/", resolve); }); } else { if (entry.name) { var p = (path + entry.name).replace(/^[/\\]/, ""); fd.append(opts.name, entry, p); files.push(p); } resolve(); } })); }); Promise.all(promises).then(resolve); }; input.getFilesAndDirectories().then(function(entries) { new Promise(function(resolve) { iterate(entries, "/", resolve); }).then(cb.bind(null, fd, files)); }); }
[ "function", "newDirectoryApi", "(", "input", ",", "opts", ",", "cb", ")", "{", "var", "fd", "=", "new", "FormData", "(", ")", ",", "files", "=", "[", "]", ";", "var", "iterate", "=", "function", "(", "entries", ",", "path", ",", "resolve", ")", "{", "var", "promises", "=", "[", "]", ";", "entries", ".", "forEach", "(", "function", "(", "entry", ")", "{", "promises", ".", "push", "(", "new", "Promise", "(", "function", "(", "resolve", ")", "{", "if", "(", "\"getFilesAndDirectories\"", "in", "entry", ")", "{", "entry", ".", "getFilesAndDirectories", "(", ")", ".", "then", "(", "function", "(", "entries", ")", "{", "iterate", "(", "entries", ",", "entry", ".", "path", "+", "\"/\"", ",", "resolve", ")", ";", "}", ")", ";", "}", "else", "{", "if", "(", "entry", ".", "name", ")", "{", "var", "p", "=", "(", "path", "+", "entry", ".", "name", ")", ".", "replace", "(", "/", "^[/\\\\]", "/", ",", "\"\"", ")", ";", "fd", ".", "append", "(", "opts", ".", "name", ",", "entry", ",", "p", ")", ";", "files", ".", "push", "(", "p", ")", ";", "}", "resolve", "(", ")", ";", "}", "}", ")", ")", ";", "}", ")", ";", "Promise", ".", "all", "(", "promises", ")", ".", "then", "(", "resolve", ")", ";", "}", ";", "input", ".", "getFilesAndDirectories", "(", ")", ".", "then", "(", "function", "(", "entries", ")", "{", "new", "Promise", "(", "function", "(", "resolve", ")", "{", "iterate", "(", "entries", ",", "\"/\"", ",", "resolve", ")", ";", "}", ")", ".", "then", "(", "cb", ".", "bind", "(", "null", ",", "fd", ",", "files", ")", ")", ";", "}", ")", ";", "}" ]
API implemented in Firefox 42+ and Edge
[ "API", "implemented", "in", "Firefox", "42", "+", "and", "Edge" ]
be6d20fe135001c42605a0168fb2c1723874bd74
https://github.com/silverwind/uppie/blob/be6d20fe135001c42605a0168fb2c1723874bd74/uppie.js#L67-L94
19,313
silverwind/uppie
uppie.js
arrayApi
function arrayApi(input, opts, cb) { var fd = new FormData(), files = []; [].slice.call(input.files).forEach(function(file) { fd.append(opts.name, file, file.webkitRelativePath || file.name); files.push(file.webkitRelativePath || file.name); }); cb(fd, files); }
javascript
function arrayApi(input, opts, cb) { var fd = new FormData(), files = []; [].slice.call(input.files).forEach(function(file) { fd.append(opts.name, file, file.webkitRelativePath || file.name); files.push(file.webkitRelativePath || file.name); }); cb(fd, files); }
[ "function", "arrayApi", "(", "input", ",", "opts", ",", "cb", ")", "{", "var", "fd", "=", "new", "FormData", "(", ")", ",", "files", "=", "[", "]", ";", "[", "]", ".", "slice", ".", "call", "(", "input", ".", "files", ")", ".", "forEach", "(", "function", "(", "file", ")", "{", "fd", ".", "append", "(", "opts", ".", "name", ",", "file", ",", "file", ".", "webkitRelativePath", "||", "file", ".", "name", ")", ";", "files", ".", "push", "(", "file", ".", "webkitRelativePath", "||", "file", ".", "name", ")", ";", "}", ")", ";", "cb", "(", "fd", ",", "files", ")", ";", "}" ]
old prefixed API implemented in Chrome 11+ as well as array fallback
[ "old", "prefixed", "API", "implemented", "in", "Chrome", "11", "+", "as", "well", "as", "array", "fallback" ]
be6d20fe135001c42605a0168fb2c1723874bd74
https://github.com/silverwind/uppie/blob/be6d20fe135001c42605a0168fb2c1723874bd74/uppie.js#L97-L104
19,314
silverwind/uppie
uppie.js
entriesApi
function entriesApi(items, opts, cb) { var fd = new FormData(), files = [], rootPromises = []; function readEntries(entry, reader, oldEntries, cb) { var dirReader = reader || entry.createReader(); dirReader.readEntries(function(entries) { var newEntries = oldEntries ? oldEntries.concat(entries) : entries; if (entries.length) { setTimeout(readEntries.bind(null, entry, dirReader, newEntries, cb), 0); } else { cb(newEntries); } }); } function readDirectory(entry, path, resolve) { if (!path) path = entry.name; readEntries(entry, 0, 0, function(entries) { var promises = []; entries.forEach(function(entry) { promises.push(new Promise(function(resolve) { if (entry.isFile) { entry.file(function(file) { var p = path + "/" + file.name; fd.append(opts.name, file, p); files.push(p); resolve(); }, resolve.bind()); } else readDirectory(entry, path + "/" + entry.name, resolve); })); }); Promise.all(promises).then(resolve.bind()); }); } [].slice.call(items).forEach(function(entry) { entry = entry.webkitGetAsEntry(); if (entry) { rootPromises.push(new Promise(function(resolve) { if (entry.isFile) { entry.file(function(file) { fd.append(opts.name, file, file.name); files.push(file.name); resolve(); }, resolve.bind()); } else if (entry.isDirectory) { readDirectory(entry, null, resolve); } })); } }); Promise.all(rootPromises).then(cb.bind(null, fd, files)); }
javascript
function entriesApi(items, opts, cb) { var fd = new FormData(), files = [], rootPromises = []; function readEntries(entry, reader, oldEntries, cb) { var dirReader = reader || entry.createReader(); dirReader.readEntries(function(entries) { var newEntries = oldEntries ? oldEntries.concat(entries) : entries; if (entries.length) { setTimeout(readEntries.bind(null, entry, dirReader, newEntries, cb), 0); } else { cb(newEntries); } }); } function readDirectory(entry, path, resolve) { if (!path) path = entry.name; readEntries(entry, 0, 0, function(entries) { var promises = []; entries.forEach(function(entry) { promises.push(new Promise(function(resolve) { if (entry.isFile) { entry.file(function(file) { var p = path + "/" + file.name; fd.append(opts.name, file, p); files.push(p); resolve(); }, resolve.bind()); } else readDirectory(entry, path + "/" + entry.name, resolve); })); }); Promise.all(promises).then(resolve.bind()); }); } [].slice.call(items).forEach(function(entry) { entry = entry.webkitGetAsEntry(); if (entry) { rootPromises.push(new Promise(function(resolve) { if (entry.isFile) { entry.file(function(file) { fd.append(opts.name, file, file.name); files.push(file.name); resolve(); }, resolve.bind()); } else if (entry.isDirectory) { readDirectory(entry, null, resolve); } })); } }); Promise.all(rootPromises).then(cb.bind(null, fd, files)); }
[ "function", "entriesApi", "(", "items", ",", "opts", ",", "cb", ")", "{", "var", "fd", "=", "new", "FormData", "(", ")", ",", "files", "=", "[", "]", ",", "rootPromises", "=", "[", "]", ";", "function", "readEntries", "(", "entry", ",", "reader", ",", "oldEntries", ",", "cb", ")", "{", "var", "dirReader", "=", "reader", "||", "entry", ".", "createReader", "(", ")", ";", "dirReader", ".", "readEntries", "(", "function", "(", "entries", ")", "{", "var", "newEntries", "=", "oldEntries", "?", "oldEntries", ".", "concat", "(", "entries", ")", ":", "entries", ";", "if", "(", "entries", ".", "length", ")", "{", "setTimeout", "(", "readEntries", ".", "bind", "(", "null", ",", "entry", ",", "dirReader", ",", "newEntries", ",", "cb", ")", ",", "0", ")", ";", "}", "else", "{", "cb", "(", "newEntries", ")", ";", "}", "}", ")", ";", "}", "function", "readDirectory", "(", "entry", ",", "path", ",", "resolve", ")", "{", "if", "(", "!", "path", ")", "path", "=", "entry", ".", "name", ";", "readEntries", "(", "entry", ",", "0", ",", "0", ",", "function", "(", "entries", ")", "{", "var", "promises", "=", "[", "]", ";", "entries", ".", "forEach", "(", "function", "(", "entry", ")", "{", "promises", ".", "push", "(", "new", "Promise", "(", "function", "(", "resolve", ")", "{", "if", "(", "entry", ".", "isFile", ")", "{", "entry", ".", "file", "(", "function", "(", "file", ")", "{", "var", "p", "=", "path", "+", "\"/\"", "+", "file", ".", "name", ";", "fd", ".", "append", "(", "opts", ".", "name", ",", "file", ",", "p", ")", ";", "files", ".", "push", "(", "p", ")", ";", "resolve", "(", ")", ";", "}", ",", "resolve", ".", "bind", "(", ")", ")", ";", "}", "else", "readDirectory", "(", "entry", ",", "path", "+", "\"/\"", "+", "entry", ".", "name", ",", "resolve", ")", ";", "}", ")", ")", ";", "}", ")", ";", "Promise", ".", "all", "(", "promises", ")", ".", "then", "(", "resolve", ".", "bind", "(", ")", ")", ";", "}", ")", ";", "}", "[", "]", ".", "slice", ".", "call", "(", "items", ")", ".", "forEach", "(", "function", "(", "entry", ")", "{", "entry", "=", "entry", ".", "webkitGetAsEntry", "(", ")", ";", "if", "(", "entry", ")", "{", "rootPromises", ".", "push", "(", "new", "Promise", "(", "function", "(", "resolve", ")", "{", "if", "(", "entry", ".", "isFile", ")", "{", "entry", ".", "file", "(", "function", "(", "file", ")", "{", "fd", ".", "append", "(", "opts", ".", "name", ",", "file", ",", "file", ".", "name", ")", ";", "files", ".", "push", "(", "file", ".", "name", ")", ";", "resolve", "(", ")", ";", "}", ",", "resolve", ".", "bind", "(", ")", ")", ";", "}", "else", "if", "(", "entry", ".", "isDirectory", ")", "{", "readDirectory", "(", "entry", ",", "null", ",", "resolve", ")", ";", "}", "}", ")", ")", ";", "}", "}", ")", ";", "Promise", ".", "all", "(", "rootPromises", ")", ".", "then", "(", "cb", ".", "bind", "(", "null", ",", "fd", ",", "files", ")", ")", ";", "}" ]
old drag and drop API implemented in Chrome 11+
[ "old", "drag", "and", "drop", "API", "implemented", "in", "Chrome", "11", "+" ]
be6d20fe135001c42605a0168fb2c1723874bd74
https://github.com/silverwind/uppie/blob/be6d20fe135001c42605a0168fb2c1723874bd74/uppie.js#L107-L159
19,315
hapticdata/toxiclibsjs
lib/toxi/geom/Matrix4x4.js
function(axis, theta) { var x, y, z, s, c, t, tx, ty; x = axis.x; y = axis.y; z = axis.z; s = Math.sin(theta); c = Math.cos(theta); t = 1 - c; tx = t * x; ty = t * y; _TEMP.set( tx * x + c, tx * y + s * z, tx * z - s * y, 0, tx * y - s * z, ty * y + c, ty * z + s * x, 0, tx * z + s * y, ty * z - s * x, t * z * z + c, 0, 0, 0, 0, 1 ); return this.multiplySelf(_TEMP); }
javascript
function(axis, theta) { var x, y, z, s, c, t, tx, ty; x = axis.x; y = axis.y; z = axis.z; s = Math.sin(theta); c = Math.cos(theta); t = 1 - c; tx = t * x; ty = t * y; _TEMP.set( tx * x + c, tx * y + s * z, tx * z - s * y, 0, tx * y - s * z, ty * y + c, ty * z + s * x, 0, tx * z + s * y, ty * z - s * x, t * z * z + c, 0, 0, 0, 0, 1 ); return this.multiplySelf(_TEMP); }
[ "function", "(", "axis", ",", "theta", ")", "{", "var", "x", ",", "y", ",", "z", ",", "s", ",", "c", ",", "t", ",", "tx", ",", "ty", ";", "x", "=", "axis", ".", "x", ";", "y", "=", "axis", ".", "y", ";", "z", "=", "axis", ".", "z", ";", "s", "=", "Math", ".", "sin", "(", "theta", ")", ";", "c", "=", "Math", ".", "cos", "(", "theta", ")", ";", "t", "=", "1", "-", "c", ";", "tx", "=", "t", "*", "x", ";", "ty", "=", "t", "*", "y", ";", "_TEMP", ".", "set", "(", "tx", "*", "x", "+", "c", ",", "tx", "*", "y", "+", "s", "*", "z", ",", "tx", "*", "z", "-", "s", "*", "y", ",", "0", ",", "tx", "*", "y", "-", "s", "*", "z", ",", "ty", "*", "y", "+", "c", ",", "ty", "*", "z", "+", "s", "*", "x", ",", "0", ",", "tx", "*", "z", "+", "s", "*", "y", ",", "ty", "*", "z", "-", "s", "*", "x", ",", "t", "*", "z", "*", "z", "+", "c", ",", "0", ",", "0", ",", "0", ",", "0", ",", "1", ")", ";", "return", "this", ".", "multiplySelf", "(", "_TEMP", ")", ";", "}" ]
Applies rotation about arbitrary axis to matrix @param axis @param theta @return rotation applied to this matrix
[ "Applies", "rotation", "about", "arbitrary", "axis", "to", "matrix" ]
3712b44242128245084f18cbad7f0dfa0fc41d9b
https://github.com/hapticdata/toxiclibsjs/blob/3712b44242128245084f18cbad7f0dfa0fc41d9b/lib/toxi/geom/Matrix4x4.js#L324-L340
19,316
hapticdata/toxiclibsjs
lib/toxi/geom/Matrix4x4.js
function(theta) { _TEMP.identity(); _TEMP.matrix[1][1] = _TEMP.matrix[2][2] = Math.cos(theta); _TEMP.matrix[2][1] = Math.sin(theta); _TEMP.matrix[1][2] = -_TEMP.matrix[2][1]; return this.multiplySelf(_TEMP); }
javascript
function(theta) { _TEMP.identity(); _TEMP.matrix[1][1] = _TEMP.matrix[2][2] = Math.cos(theta); _TEMP.matrix[2][1] = Math.sin(theta); _TEMP.matrix[1][2] = -_TEMP.matrix[2][1]; return this.multiplySelf(_TEMP); }
[ "function", "(", "theta", ")", "{", "_TEMP", ".", "identity", "(", ")", ";", "_TEMP", ".", "matrix", "[", "1", "]", "[", "1", "]", "=", "_TEMP", ".", "matrix", "[", "2", "]", "[", "2", "]", "=", "Math", ".", "cos", "(", "theta", ")", ";", "_TEMP", ".", "matrix", "[", "2", "]", "[", "1", "]", "=", "Math", ".", "sin", "(", "theta", ")", ";", "_TEMP", ".", "matrix", "[", "1", "]", "[", "2", "]", "=", "-", "_TEMP", ".", "matrix", "[", "2", "]", "[", "1", "]", ";", "return", "this", ".", "multiplySelf", "(", "_TEMP", ")", ";", "}" ]
Applies rotation about X to this matrix. @param theta rotation angle in radians @return itself
[ "Applies", "rotation", "about", "X", "to", "this", "matrix", "." ]
3712b44242128245084f18cbad7f0dfa0fc41d9b
https://github.com/hapticdata/toxiclibsjs/blob/3712b44242128245084f18cbad7f0dfa0fc41d9b/lib/toxi/geom/Matrix4x4.js#L349-L355
19,317
hapticdata/toxiclibsjs
lib/toxi/geom/Line3D.js
function(p) { var v = this.b.sub(this.a); var t = p.sub(this.a).dot(v) / v.magSquared(); // Check to see if t is beyond the extents of the line segment if (t < 0.0) { return this.a.copy(); } else if (t > 1.0) { return this.b.copy(); } // Return the point between 'a' and 'b' return this.a.add(v.scaleSelf(t)); }
javascript
function(p) { var v = this.b.sub(this.a); var t = p.sub(this.a).dot(v) / v.magSquared(); // Check to see if t is beyond the extents of the line segment if (t < 0.0) { return this.a.copy(); } else if (t > 1.0) { return this.b.copy(); } // Return the point between 'a' and 'b' return this.a.add(v.scaleSelf(t)); }
[ "function", "(", "p", ")", "{", "var", "v", "=", "this", ".", "b", ".", "sub", "(", "this", ".", "a", ")", ";", "var", "t", "=", "p", ".", "sub", "(", "this", ".", "a", ")", ".", "dot", "(", "v", ")", "/", "v", ".", "magSquared", "(", ")", ";", "// Check to see if t is beyond the extents of the line segment", "if", "(", "t", "<", "0.0", ")", "{", "return", "this", ".", "a", ".", "copy", "(", ")", ";", "}", "else", "if", "(", "t", ">", "1.0", ")", "{", "return", "this", ".", "b", ".", "copy", "(", ")", ";", "}", "// Return the point between 'a' and 'b'", "return", "this", ".", "a", ".", "add", "(", "v", ".", "scaleSelf", "(", "t", ")", ")", ";", "}" ]
Computes the closest point on this line to the given one. @param p point to check against @return closest point on the line
[ "Computes", "the", "closest", "point", "on", "this", "line", "to", "the", "given", "one", "." ]
3712b44242128245084f18cbad7f0dfa0fc41d9b
https://github.com/hapticdata/toxiclibsjs/blob/3712b44242128245084f18cbad7f0dfa0fc41d9b/lib/toxi/geom/Line3D.js#L62-L73
19,318
hapticdata/toxiclibsjs
lib/toxi/THREE/ToxiclibsSupport.js
function(obj_or_mesh,threeMaterials){ var toxiTriangleMesh; if(arguments.length == 1){ //it needs to be an param object toxiTriangleMesh = obj_or_mesh.geometry; threeMaterials = obj_or_mesh.materials; } else { toxiTriangleMesh = obj_or_mesh; } var threeMesh = this.createMesh(toxiTriangleMesh,threeMaterials); this.scene.add(threeMesh); return threeMesh; }
javascript
function(obj_or_mesh,threeMaterials){ var toxiTriangleMesh; if(arguments.length == 1){ //it needs to be an param object toxiTriangleMesh = obj_or_mesh.geometry; threeMaterials = obj_or_mesh.materials; } else { toxiTriangleMesh = obj_or_mesh; } var threeMesh = this.createMesh(toxiTriangleMesh,threeMaterials); this.scene.add(threeMesh); return threeMesh; }
[ "function", "(", "obj_or_mesh", ",", "threeMaterials", ")", "{", "var", "toxiTriangleMesh", ";", "if", "(", "arguments", ".", "length", "==", "1", ")", "{", "//it needs to be an param object", "toxiTriangleMesh", "=", "obj_or_mesh", ".", "geometry", ";", "threeMaterials", "=", "obj_or_mesh", ".", "materials", ";", "}", "else", "{", "toxiTriangleMesh", "=", "obj_or_mesh", ";", "}", "var", "threeMesh", "=", "this", ".", "createMesh", "(", "toxiTriangleMesh", ",", "threeMaterials", ")", ";", "this", ".", "scene", ".", "add", "(", "threeMesh", ")", ";", "return", "threeMesh", ";", "}" ]
add a toxiclibs.js mesh to the three.js scene @param {Object|toxi.geom.mesh.TriangleMesh} obj_or_mesh either an options object or the toxiclibsjs mesh -- @param {toxi.geom.mesh.Trianglemesh} [obj_or_mesh.geometry] the mesh in the options object @param {THREE.Material} [obj_or_mesh.material] the three.js material for the mesh @param {boolean} [obj_or_mesh.holdInDictionary] should ToxiclibsSupport hold a reference? -- @param {THREE.Material} [threeMaterials] the three.js material for the mesh
[ "add", "a", "toxiclibs", ".", "js", "mesh", "to", "the", "three", ".", "js", "scene" ]
3712b44242128245084f18cbad7f0dfa0fc41d9b
https://github.com/hapticdata/toxiclibsjs/blob/3712b44242128245084f18cbad7f0dfa0fc41d9b/lib/toxi/THREE/ToxiclibsSupport.js#L104-L115
19,319
hapticdata/toxiclibsjs
lib/toxi/geom/Triangle2D.js
function(_p){ var v1 = _p.sub(this.a).normalize(), v2 = _p.sub(this.b).normalize(), v3 = _p.sub(this.c).normalize(), totalAngles = Math.acos(v1.dot(v2)); totalAngles += Math.acos(v2.dot(v3)); totalAngles += Math.acos(v3.dot(v1)); return (mathUtils.abs(totalAngles- mathUtils.TWO_PI) <= 0.01); }
javascript
function(_p){ var v1 = _p.sub(this.a).normalize(), v2 = _p.sub(this.b).normalize(), v3 = _p.sub(this.c).normalize(), totalAngles = Math.acos(v1.dot(v2)); totalAngles += Math.acos(v2.dot(v3)); totalAngles += Math.acos(v3.dot(v1)); return (mathUtils.abs(totalAngles- mathUtils.TWO_PI) <= 0.01); }
[ "function", "(", "_p", ")", "{", "var", "v1", "=", "_p", ".", "sub", "(", "this", ".", "a", ")", ".", "normalize", "(", ")", ",", "v2", "=", "_p", ".", "sub", "(", "this", ".", "b", ")", ".", "normalize", "(", ")", ",", "v3", "=", "_p", ".", "sub", "(", "this", ".", "c", ")", ".", "normalize", "(", ")", ",", "totalAngles", "=", "Math", ".", "acos", "(", "v1", ".", "dot", "(", "v2", ")", ")", ";", "totalAngles", "+=", "Math", ".", "acos", "(", "v2", ".", "dot", "(", "v3", ")", ")", ";", "totalAngles", "+=", "Math", ".", "acos", "(", "v3", ".", "dot", "(", "v1", ")", ")", ";", "return", "(", "mathUtils", ".", "abs", "(", "totalAngles", "-", "mathUtils", ".", "TWO_PI", ")", "<=", "0.01", ")", ";", "}" ]
Checks if point vector is inside the triangle created by the points a, b and c. These points will create a plane and the point checked will have to be on this plane in the region between a,b,c. Note: The triangle must be defined in clockwise order a,b,c @return true, if point is in triangle.
[ "Checks", "if", "point", "vector", "is", "inside", "the", "triangle", "created", "by", "the", "points", "a", "b", "and", "c", ".", "These", "points", "will", "create", "a", "plane", "and", "the", "point", "checked", "will", "have", "to", "be", "on", "this", "plane", "in", "the", "region", "between", "a", "b", "c", "." ]
3712b44242128245084f18cbad7f0dfa0fc41d9b
https://github.com/hapticdata/toxiclibsjs/blob/3712b44242128245084f18cbad7f0dfa0fc41d9b/lib/toxi/geom/Triangle2D.js#L70-L78
19,320
hapticdata/toxiclibsjs
lib/toxi/geom/ConvexPolygonClipper.js
function(list, q){ for(var i=0, l=list.length; i<l; i++){ if( list[i].equalsWitTolerance(q, 0.001) ){ return true; } } return false; }
javascript
function(list, q){ for(var i=0, l=list.length; i<l; i++){ if( list[i].equalsWitTolerance(q, 0.001) ){ return true; } } return false; }
[ "function", "(", "list", ",", "q", ")", "{", "for", "(", "var", "i", "=", "0", ",", "l", "=", "list", ".", "length", ";", "i", "<", "l", ";", "i", "++", ")", "{", "if", "(", "list", "[", "i", "]", ".", "equalsWitTolerance", "(", "q", ",", "0.001", ")", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
unused but included to match, source
[ "unused", "but", "included", "to", "match", "source" ]
3712b44242128245084f18cbad7f0dfa0fc41d9b
https://github.com/hapticdata/toxiclibsjs/blob/3712b44242128245084f18cbad7f0dfa0fc41d9b/lib/toxi/geom/ConvexPolygonClipper.js#L83-L90
19,321
hapticdata/toxiclibsjs
lib/toxi/processing/ToxiclibsSupport.js
function(iterator, shapeID, closed){ //if first param wasnt passed in as a pjs Iterator, make it one if(iterator.hasNext === undefined || iterator.next === undefined){ iterator = new this.app.ObjectIterator( iterator ); } this.gfx.beginShape(shapeID); for(var v = void(0); iterator.hasNext() && ((v = iterator.next()) || true);){ this.gfx.vertex(v.x,v.y); } /*var i=0, len = points.length; for(i=0;i<len;i++){ var v = points[i]; this.gfx.vertex(v.x,v.y); }*/ if(closed){ this.gfx.endShape(this.app.CLOSE); } else { this.gfx.endShape(); } }
javascript
function(iterator, shapeID, closed){ //if first param wasnt passed in as a pjs Iterator, make it one if(iterator.hasNext === undefined || iterator.next === undefined){ iterator = new this.app.ObjectIterator( iterator ); } this.gfx.beginShape(shapeID); for(var v = void(0); iterator.hasNext() && ((v = iterator.next()) || true);){ this.gfx.vertex(v.x,v.y); } /*var i=0, len = points.length; for(i=0;i<len;i++){ var v = points[i]; this.gfx.vertex(v.x,v.y); }*/ if(closed){ this.gfx.endShape(this.app.CLOSE); } else { this.gfx.endShape(); } }
[ "function", "(", "iterator", ",", "shapeID", ",", "closed", ")", "{", "//if first param wasnt passed in as a pjs Iterator, make it one", "if", "(", "iterator", ".", "hasNext", "===", "undefined", "||", "iterator", ".", "next", "===", "undefined", ")", "{", "iterator", "=", "new", "this", ".", "app", ".", "ObjectIterator", "(", "iterator", ")", ";", "}", "this", ".", "gfx", ".", "beginShape", "(", "shapeID", ")", ";", "for", "(", "var", "v", "=", "void", "(", "0", ")", ";", "iterator", ".", "hasNext", "(", ")", "&&", "(", "(", "v", "=", "iterator", ".", "next", "(", ")", ")", "||", "true", ")", ";", ")", "{", "this", ".", "gfx", ".", "vertex", "(", "v", ".", "x", ",", "v", ".", "y", ")", ";", "}", "/*var i=0,\n\t\t\tlen = points.length;\n\t\tfor(i=0;i<len;i++){\n\t\t\tvar v = points[i];\n\t\t\tthis.gfx.vertex(v.x,v.y);\n\t\t}*/", "if", "(", "closed", ")", "{", "this", ".", "gfx", ".", "endShape", "(", "this", ".", "app", ".", "CLOSE", ")", ";", "}", "else", "{", "this", ".", "gfx", ".", "endShape", "(", ")", ";", "}", "}" ]
Processes the 2D vertices from a Processing.js Iterator object @params {Iterator} iterator @params {Number} shapeID @params {Boolean} closed
[ "Processes", "the", "2D", "vertices", "from", "a", "Processing", ".", "js", "Iterator", "object" ]
3712b44242128245084f18cbad7f0dfa0fc41d9b
https://github.com/hapticdata/toxiclibsjs/blob/3712b44242128245084f18cbad7f0dfa0fc41d9b/lib/toxi/processing/ToxiclibsSupport.js#L314-L334
19,322
hapticdata/toxiclibsjs
lib/toxi/processing/ToxiclibsSupport.js
function(tri,isFullShape){ var isTriangle = function(){ if(tri.a !== undefined && tri.b !== undefined && tri.c !== undefined){ return (tri.a.x !== undefined); } return false; }, isTriangle3D = function(){ if(isTriangle()){ return (tri.a.z !== undefined); } return false; }; if(isFullShape || isFullShape === undefined){ this.gfx.beginShape(this.app.TRIANGLES); } if(isTriangle3D()){ var n = tri.computeNormal(); this.gfx.normal(n.x,n.y,n.z); this.gfx.vertex(tri.a.x, tri.a.y, tri.a.z); this.gfx.vertex(tri.b.x, tri.b.y, tri.b.z); this.gfx.vertex(tri.c.x, tri.c.y, tri.c.z); } else { //should be Triangle2D this.gfx.vertex(tri.a.x,tri.a.y); this.gfx.vertex(tri.b.x,tri.b.y); this.gfx.vertex(tri.c.x,tri.c.y); } if(isFullShape || isFullShape === undefined){ this.gfx.endShape(); } }
javascript
function(tri,isFullShape){ var isTriangle = function(){ if(tri.a !== undefined && tri.b !== undefined && tri.c !== undefined){ return (tri.a.x !== undefined); } return false; }, isTriangle3D = function(){ if(isTriangle()){ return (tri.a.z !== undefined); } return false; }; if(isFullShape || isFullShape === undefined){ this.gfx.beginShape(this.app.TRIANGLES); } if(isTriangle3D()){ var n = tri.computeNormal(); this.gfx.normal(n.x,n.y,n.z); this.gfx.vertex(tri.a.x, tri.a.y, tri.a.z); this.gfx.vertex(tri.b.x, tri.b.y, tri.b.z); this.gfx.vertex(tri.c.x, tri.c.y, tri.c.z); } else { //should be Triangle2D this.gfx.vertex(tri.a.x,tri.a.y); this.gfx.vertex(tri.b.x,tri.b.y); this.gfx.vertex(tri.c.x,tri.c.y); } if(isFullShape || isFullShape === undefined){ this.gfx.endShape(); } }
[ "function", "(", "tri", ",", "isFullShape", ")", "{", "var", "isTriangle", "=", "function", "(", ")", "{", "if", "(", "tri", ".", "a", "!==", "undefined", "&&", "tri", ".", "b", "!==", "undefined", "&&", "tri", ".", "c", "!==", "undefined", ")", "{", "return", "(", "tri", ".", "a", ".", "x", "!==", "undefined", ")", ";", "}", "return", "false", ";", "}", ",", "isTriangle3D", "=", "function", "(", ")", "{", "if", "(", "isTriangle", "(", ")", ")", "{", "return", "(", "tri", ".", "a", ".", "z", "!==", "undefined", ")", ";", "}", "return", "false", ";", "}", ";", "if", "(", "isFullShape", "||", "isFullShape", "===", "undefined", ")", "{", "this", ".", "gfx", ".", "beginShape", "(", "this", ".", "app", ".", "TRIANGLES", ")", ";", "}", "if", "(", "isTriangle3D", "(", ")", ")", "{", "var", "n", "=", "tri", ".", "computeNormal", "(", ")", ";", "this", ".", "gfx", ".", "normal", "(", "n", ".", "x", ",", "n", ".", "y", ",", "n", ".", "z", ")", ";", "this", ".", "gfx", ".", "vertex", "(", "tri", ".", "a", ".", "x", ",", "tri", ".", "a", ".", "y", ",", "tri", ".", "a", ".", "z", ")", ";", "this", ".", "gfx", ".", "vertex", "(", "tri", ".", "b", ".", "x", ",", "tri", ".", "b", ".", "y", ",", "tri", ".", "b", ".", "z", ")", ";", "this", ".", "gfx", ".", "vertex", "(", "tri", ".", "c", ".", "x", ",", "tri", ".", "c", ".", "y", ",", "tri", ".", "c", ".", "z", ")", ";", "}", "else", "{", "//should be Triangle2D", "this", ".", "gfx", ".", "vertex", "(", "tri", ".", "a", ".", "x", ",", "tri", ".", "a", ".", "y", ")", ";", "this", ".", "gfx", ".", "vertex", "(", "tri", ".", "b", ".", "x", ",", "tri", ".", "b", ".", "y", ")", ";", "this", ".", "gfx", ".", "vertex", "(", "tri", ".", "c", ".", "x", ",", "tri", ".", "c", ".", "y", ")", ";", "}", "if", "(", "isFullShape", "||", "isFullShape", "===", "undefined", ")", "{", "this", ".", "gfx", ".", "endShape", "(", ")", ";", "}", "}" ]
works for Triangle3D or Triangle2D
[ "works", "for", "Triangle3D", "or", "Triangle2D" ]
3712b44242128245084f18cbad7f0dfa0fc41d9b
https://github.com/hapticdata/toxiclibsjs/blob/3712b44242128245084f18cbad7f0dfa0fc41d9b/lib/toxi/processing/ToxiclibsSupport.js#L441-L473
19,323
hapticdata/toxiclibsjs
lib/toxi/geom/vectors.js
function(a,b) { if( hasXY( a ) && hasXY( b ) ){ this.x = mathUtils.clip(this.x, a.x, b.x); this.y = mathUtils.clip(this.y, a.y, b.y); } else if( isRect( a ) ){ this.x = mathUtils.clip(this.x, a.x, a.x + a.width); this.y = mathUtils.clip(this.y, a.y, a.y + a.height); } return this; }
javascript
function(a,b) { if( hasXY( a ) && hasXY( b ) ){ this.x = mathUtils.clip(this.x, a.x, b.x); this.y = mathUtils.clip(this.y, a.y, b.y); } else if( isRect( a ) ){ this.x = mathUtils.clip(this.x, a.x, a.x + a.width); this.y = mathUtils.clip(this.y, a.y, a.y + a.height); } return this; }
[ "function", "(", "a", ",", "b", ")", "{", "if", "(", "hasXY", "(", "a", ")", "&&", "hasXY", "(", "b", ")", ")", "{", "this", ".", "x", "=", "mathUtils", ".", "clip", "(", "this", ".", "x", ",", "a", ".", "x", ",", "b", ".", "x", ")", ";", "this", ".", "y", "=", "mathUtils", ".", "clip", "(", "this", ".", "y", ",", "a", ".", "y", ",", "b", ".", "y", ")", ";", "}", "else", "if", "(", "isRect", "(", "a", ")", ")", "{", "this", ".", "x", "=", "mathUtils", ".", "clip", "(", "this", ".", "x", ",", "a", ".", "x", ",", "a", ".", "x", "+", "a", ".", "width", ")", ";", "this", ".", "y", "=", "mathUtils", ".", "clip", "(", "this", ".", "y", ",", "a", ".", "y", ",", "a", ".", "y", "+", "a", ".", "height", ")", ";", "}", "return", "this", ";", "}" ]
Forcefully fits the vector in the given rectangle. @param a either a Rectangle by itself or the Vec2D min @param b Vec2D max @return itself
[ "Forcefully", "fits", "the", "vector", "in", "the", "given", "rectangle", "." ]
3712b44242128245084f18cbad7f0dfa0fc41d9b
https://github.com/hapticdata/toxiclibsjs/blob/3712b44242128245084f18cbad7f0dfa0fc41d9b/lib/toxi/geom/vectors.js#L133-L142
19,324
hapticdata/toxiclibsjs
lib/toxi/geom/vectors.js
function() { var mag = this.x * this.x + this.y * this.y; if (mag > 0) { mag = 1.0 / Math.sqrt(mag); this.x *= mag; this.y *= mag; } return this; }
javascript
function() { var mag = this.x * this.x + this.y * this.y; if (mag > 0) { mag = 1.0 / Math.sqrt(mag); this.x *= mag; this.y *= mag; } return this; }
[ "function", "(", ")", "{", "var", "mag", "=", "this", ".", "x", "*", "this", ".", "x", "+", "this", ".", "y", "*", "this", ".", "y", ";", "if", "(", "mag", ">", "0", ")", "{", "mag", "=", "1.0", "/", "Math", ".", "sqrt", "(", "mag", ")", ";", "this", ".", "x", "*=", "mag", ";", "this", ".", "y", "*=", "mag", ";", "}", "return", "this", ";", "}" ]
Normalizes the vector so that its magnitude = 1 @return itself
[ "Normalizes", "the", "vector", "so", "that", "its", "magnitude", "=", "1" ]
3712b44242128245084f18cbad7f0dfa0fc41d9b
https://github.com/hapticdata/toxiclibsjs/blob/3712b44242128245084f18cbad7f0dfa0fc41d9b/lib/toxi/geom/vectors.js#L419-L427
19,325
hapticdata/toxiclibsjs
lib/toxi/geom/vectors.js
function(theta) { var co = Math.cos(theta); var si = Math.sin(theta); var xx = co * this.x - si * this.y; this.y = si * this.x + co * this.y; this.x = xx; return this; }
javascript
function(theta) { var co = Math.cos(theta); var si = Math.sin(theta); var xx = co * this.x - si * this.y; this.y = si * this.x + co * this.y; this.x = xx; return this; }
[ "function", "(", "theta", ")", "{", "var", "co", "=", "Math", ".", "cos", "(", "theta", ")", ";", "var", "si", "=", "Math", ".", "sin", "(", "theta", ")", ";", "var", "xx", "=", "co", "*", "this", ".", "x", "-", "si", "*", "this", ".", "y", ";", "this", ".", "y", "=", "si", "*", "this", ".", "x", "+", "co", "*", "this", ".", "y", ";", "this", ".", "x", "=", "xx", ";", "return", "this", ";", "}" ]
Rotates the vector by the given angle around the Z axis. @param theta @return itself
[ "Rotates", "the", "vector", "by", "the", "given", "angle", "around", "the", "Z", "axis", "." ]
3712b44242128245084f18cbad7f0dfa0fc41d9b
https://github.com/hapticdata/toxiclibsjs/blob/3712b44242128245084f18cbad7f0dfa0fc41d9b/lib/toxi/geom/vectors.js#L477-L484
19,326
hapticdata/toxiclibsjs
lib/toxi/geom/vectors.js
function(box_or_min, max){ var min; if( is.AABB( box_or_min ) ){ max = box_or_min.getMax(); min = box_or_min.getMin(); } else { min = box_or_min; } this.x = mathUtils.clip(this.x, min.x, max.x); this.y = mathUtils.clip(this.y, min.y, max.y); this.z = mathUtils.clip(this.z, min.z, max.z); return this; }
javascript
function(box_or_min, max){ var min; if( is.AABB( box_or_min ) ){ max = box_or_min.getMax(); min = box_or_min.getMin(); } else { min = box_or_min; } this.x = mathUtils.clip(this.x, min.x, max.x); this.y = mathUtils.clip(this.y, min.y, max.y); this.z = mathUtils.clip(this.z, min.z, max.z); return this; }
[ "function", "(", "box_or_min", ",", "max", ")", "{", "var", "min", ";", "if", "(", "is", ".", "AABB", "(", "box_or_min", ")", ")", "{", "max", "=", "box_or_min", ".", "getMax", "(", ")", ";", "min", "=", "box_or_min", ".", "getMin", "(", ")", ";", "}", "else", "{", "min", "=", "box_or_min", ";", "}", "this", ".", "x", "=", "mathUtils", ".", "clip", "(", "this", ".", "x", ",", "min", ".", "x", ",", "max", ".", "x", ")", ";", "this", ".", "y", "=", "mathUtils", ".", "clip", "(", "this", ".", "y", ",", "min", ".", "y", ",", "max", ".", "y", ")", ";", "this", ".", "z", "=", "mathUtils", ".", "clip", "(", "this", ".", "z", ",", "min", ".", "z", ",", "max", ".", "z", ")", ";", "return", "this", ";", "}" ]
Forcefully fits the vector in the given AABB specified by the 2 given points. @param box_or_min either the AABB box by itself, or your min Vec3D with accompanying max @param max @return itself
[ "Forcefully", "fits", "the", "vector", "in", "the", "given", "AABB", "specified", "by", "the", "2", "given", "points", "." ]
3712b44242128245084f18cbad7f0dfa0fc41d9b
https://github.com/hapticdata/toxiclibsjs/blob/3712b44242128245084f18cbad7f0dfa0fc41d9b/lib/toxi/geom/vectors.js#L740-L752
19,327
hapticdata/toxiclibsjs
lib/toxi/geom/vectors.js
function(vec){ var cx = this.y * vec.z - vec.y * this.z; var cy = this.z * vec.x - vec.z * this.x; this.z = this.x * vec.y - vec.x * this.y; this.y = cy; this.x = cx; return this; }
javascript
function(vec){ var cx = this.y * vec.z - vec.y * this.z; var cy = this.z * vec.x - vec.z * this.x; this.z = this.x * vec.y - vec.x * this.y; this.y = cy; this.x = cx; return this; }
[ "function", "(", "vec", ")", "{", "var", "cx", "=", "this", ".", "y", "*", "vec", ".", "z", "-", "vec", ".", "y", "*", "this", ".", "z", ";", "var", "cy", "=", "this", ".", "z", "*", "vec", ".", "x", "-", "vec", ".", "z", "*", "this", ".", "x", ";", "this", ".", "z", "=", "this", ".", "x", "*", "vec", ".", "y", "-", "vec", ".", "x", "*", "this", ".", "y", ";", "this", ".", "y", "=", "cy", ";", "this", ".", "x", "=", "cx", ";", "return", "this", ";", "}" ]
Calculates cross-product with vector v. The resulting vector is perpendicular to both the current and supplied vector and overrides the current. @param v the v @return itself
[ "Calculates", "cross", "-", "product", "with", "vector", "v", ".", "The", "resulting", "vector", "is", "perpendicular", "to", "both", "the", "current", "and", "supplied", "vector", "and", "overrides", "the", "current", "." ]
3712b44242128245084f18cbad7f0dfa0fc41d9b
https://github.com/hapticdata/toxiclibsjs/blob/3712b44242128245084f18cbad7f0dfa0fc41d9b/lib/toxi/geom/vectors.js#L781-L788
19,328
hapticdata/toxiclibsjs
lib/toxi/geom/vectors.js
function(vec_axis,theta){ var ax = vec_axis.x, ay = vec_axis.y, az = vec_axis.z, ux = ax * this.x, uy = ax * this.y, uz = ax * this.z, vx = ay * this.x, vy = ay * this.y, vz = ay * this.z, wx = az * this.x, wy = az * this.y, wz = az * this.z, si = Math.sin(theta), co = Math.cos(theta); var xx = (ax * (ux + vy + wz) + (this.x * (ay * ay + az * az) - ax * (vy + wz)) * co + (-wy + vz) * si); var yy = (ay * (ux + vy + wz) + (this.y * (ax * ax + az * az) - ay * (ux + wz)) * co + (wx - uz) * si); var zz = (az * (ux + vy + wz) + (this.z * (ax * ax + ay * ay) - az * (ux + vy)) * co + (-vx + uy) * si); this.x = xx; this.y = yy; this.z = zz; return this; }
javascript
function(vec_axis,theta){ var ax = vec_axis.x, ay = vec_axis.y, az = vec_axis.z, ux = ax * this.x, uy = ax * this.y, uz = ax * this.z, vx = ay * this.x, vy = ay * this.y, vz = ay * this.z, wx = az * this.x, wy = az * this.y, wz = az * this.z, si = Math.sin(theta), co = Math.cos(theta); var xx = (ax * (ux + vy + wz) + (this.x * (ay * ay + az * az) - ax * (vy + wz)) * co + (-wy + vz) * si); var yy = (ay * (ux + vy + wz) + (this.y * (ax * ax + az * az) - ay * (ux + wz)) * co + (wx - uz) * si); var zz = (az * (ux + vy + wz) + (this.z * (ax * ax + ay * ay) - az * (ux + vy)) * co + (-vx + uy) * si); this.x = xx; this.y = yy; this.z = zz; return this; }
[ "function", "(", "vec_axis", ",", "theta", ")", "{", "var", "ax", "=", "vec_axis", ".", "x", ",", "ay", "=", "vec_axis", ".", "y", ",", "az", "=", "vec_axis", ".", "z", ",", "ux", "=", "ax", "*", "this", ".", "x", ",", "uy", "=", "ax", "*", "this", ".", "y", ",", "uz", "=", "ax", "*", "this", ".", "z", ",", "vx", "=", "ay", "*", "this", ".", "x", ",", "vy", "=", "ay", "*", "this", ".", "y", ",", "vz", "=", "ay", "*", "this", ".", "z", ",", "wx", "=", "az", "*", "this", ".", "x", ",", "wy", "=", "az", "*", "this", ".", "y", ",", "wz", "=", "az", "*", "this", ".", "z", ",", "si", "=", "Math", ".", "sin", "(", "theta", ")", ",", "co", "=", "Math", ".", "cos", "(", "theta", ")", ";", "var", "xx", "=", "(", "ax", "*", "(", "ux", "+", "vy", "+", "wz", ")", "+", "(", "this", ".", "x", "*", "(", "ay", "*", "ay", "+", "az", "*", "az", ")", "-", "ax", "*", "(", "vy", "+", "wz", ")", ")", "*", "co", "+", "(", "-", "wy", "+", "vz", ")", "*", "si", ")", ";", "var", "yy", "=", "(", "ay", "*", "(", "ux", "+", "vy", "+", "wz", ")", "+", "(", "this", ".", "y", "*", "(", "ax", "*", "ax", "+", "az", "*", "az", ")", "-", "ay", "*", "(", "ux", "+", "wz", ")", ")", "*", "co", "+", "(", "wx", "-", "uz", ")", "*", "si", ")", ";", "var", "zz", "=", "(", "az", "*", "(", "ux", "+", "vy", "+", "wz", ")", "+", "(", "this", ".", "z", "*", "(", "ax", "*", "ax", "+", "ay", "*", "ay", ")", "-", "az", "*", "(", "ux", "+", "vy", ")", ")", "*", "co", "+", "(", "-", "vx", "+", "uy", ")", "*", "si", ")", ";", "this", ".", "x", "=", "xx", ";", "this", ".", "y", "=", "yy", ";", "this", ".", "z", "=", "zz", ";", "return", "this", ";", "}" ]
Rotates the vector around the giving axis. @param axis rotation axis vector @param theta rotation angle (in radians) @return itself
[ "Rotates", "the", "vector", "around", "the", "giving", "axis", "." ]
3712b44242128245084f18cbad7f0dfa0fc41d9b
https://github.com/hapticdata/toxiclibsjs/blob/3712b44242128245084f18cbad7f0dfa0fc41d9b/lib/toxi/geom/vectors.js#L1133-L1155
19,329
hapticdata/toxiclibsjs
lib/toxi/geom/vectors.js
function(theta){ var co = Math.cos(theta); var si = Math.sin(theta); var zz = co *this.z - si * this.y; this.y = si * this.z + co * this.y; this.z = zz; return this; }
javascript
function(theta){ var co = Math.cos(theta); var si = Math.sin(theta); var zz = co *this.z - si * this.y; this.y = si * this.z + co * this.y; this.z = zz; return this; }
[ "function", "(", "theta", ")", "{", "var", "co", "=", "Math", ".", "cos", "(", "theta", ")", ";", "var", "si", "=", "Math", ".", "sin", "(", "theta", ")", ";", "var", "zz", "=", "co", "*", "this", ".", "z", "-", "si", "*", "this", ".", "y", ";", "this", ".", "y", "=", "si", "*", "this", ".", "z", "+", "co", "*", "this", ".", "y", ";", "this", ".", "z", "=", "zz", ";", "return", "this", ";", "}" ]
Rotates the vector by the given angle around the X axis. @param theta the theta @return itself
[ "Rotates", "the", "vector", "by", "the", "given", "angle", "around", "the", "X", "axis", "." ]
3712b44242128245084f18cbad7f0dfa0fc41d9b
https://github.com/hapticdata/toxiclibsjs/blob/3712b44242128245084f18cbad7f0dfa0fc41d9b/lib/toxi/geom/vectors.js#L1164-L1171
19,330
hapticdata/toxiclibsjs
lib/toxi/geom/vectors.js
function() { if (Math.abs(this.x) < 0.5) { this.x = 0; } else { this.x = this.x < 0 ? -1 : 1; this.y = this.z = 0; } if (Math.abs(this.y) < 0.5) { this.y = 0; } else { this.y = this.y < 0 ? -1 : 1; this.x = this.z = 0; } if (Math.abs(this.z) < 0.5) { this.z = 0; } else { this.z = this.z < 0 ? -1 : 1; this.x = this.y = 0; } return this; }
javascript
function() { if (Math.abs(this.x) < 0.5) { this.x = 0; } else { this.x = this.x < 0 ? -1 : 1; this.y = this.z = 0; } if (Math.abs(this.y) < 0.5) { this.y = 0; } else { this.y = this.y < 0 ? -1 : 1; this.x = this.z = 0; } if (Math.abs(this.z) < 0.5) { this.z = 0; } else { this.z = this.z < 0 ? -1 : 1; this.x = this.y = 0; } return this; }
[ "function", "(", ")", "{", "if", "(", "Math", ".", "abs", "(", "this", ".", "x", ")", "<", "0.5", ")", "{", "this", ".", "x", "=", "0", ";", "}", "else", "{", "this", ".", "x", "=", "this", ".", "x", "<", "0", "?", "-", "1", ":", "1", ";", "this", ".", "y", "=", "this", ".", "z", "=", "0", ";", "}", "if", "(", "Math", ".", "abs", "(", "this", ".", "y", ")", "<", "0.5", ")", "{", "this", ".", "y", "=", "0", ";", "}", "else", "{", "this", ".", "y", "=", "this", ".", "y", "<", "0", "?", "-", "1", ":", "1", ";", "this", ".", "x", "=", "this", ".", "z", "=", "0", ";", "}", "if", "(", "Math", ".", "abs", "(", "this", ".", "z", ")", "<", "0.5", ")", "{", "this", ".", "z", "=", "0", ";", "}", "else", "{", "this", ".", "z", "=", "this", ".", "z", "<", "0", "?", "-", "1", ":", "1", ";", "this", ".", "x", "=", "this", ".", "y", "=", "0", ";", "}", "return", "this", ";", "}" ]
Rounds the vector to the closest major axis. Assumes the vector is normalized. @return itself
[ "Rounds", "the", "vector", "to", "the", "closest", "major", "axis", ".", "Assumes", "the", "vector", "is", "normalized", "." ]
3712b44242128245084f18cbad7f0dfa0fc41d9b
https://github.com/hapticdata/toxiclibsjs/blob/3712b44242128245084f18cbad7f0dfa0fc41d9b/lib/toxi/geom/vectors.js#L1212-L1232
19,331
hapticdata/toxiclibsjs
lib/toxi/color/ToneMap.js
function( t ){ var idx; if( this.colors.size() > 2 ){ idx = Math.floor( this.map.getClippedValueFor(t) + 0.5 ); } else { idx = t >= this.map.getInputMedian() ? 1 : 0; } return this.colors.get(idx); }
javascript
function( t ){ var idx; if( this.colors.size() > 2 ){ idx = Math.floor( this.map.getClippedValueFor(t) + 0.5 ); } else { idx = t >= this.map.getInputMedian() ? 1 : 0; } return this.colors.get(idx); }
[ "function", "(", "t", ")", "{", "var", "idx", ";", "if", "(", "this", ".", "colors", ".", "size", "(", ")", ">", "2", ")", "{", "idx", "=", "Math", ".", "floor", "(", "this", ".", "map", ".", "getClippedValueFor", "(", "t", ")", "+", "0.5", ")", ";", "}", "else", "{", "idx", "=", "t", ">=", "this", ".", "map", ".", "getInputMedian", "(", ")", "?", "1", ":", "0", ";", "}", "return", "this", ".", "colors", ".", "get", "(", "idx", ")", ";", "}" ]
get a color from a tonal value @param {Number} t @return {toxi.color.TColor}
[ "get", "a", "color", "from", "a", "tonal", "value" ]
3712b44242128245084f18cbad7f0dfa0fc41d9b
https://github.com/hapticdata/toxiclibsjs/blob/3712b44242128245084f18cbad7f0dfa0fc41d9b/lib/toxi/color/ToneMap.js#L63-L71
19,332
hapticdata/toxiclibsjs
lib/toxi/color/ToneMap.js
function( src, pixels, offset ){ if( typeof offset !== 'number'){ offset = 0; } else if ( offset < 0 ){ throw new Error("offset into target pixel array is negative"); } pixels = pixels || new Array(src.length); for(var i=0, l=src.length; i<l; i++){ pixels[offset++] = this.getToneFor(src[i]).toARGB(); } return pixels; }
javascript
function( src, pixels, offset ){ if( typeof offset !== 'number'){ offset = 0; } else if ( offset < 0 ){ throw new Error("offset into target pixel array is negative"); } pixels = pixels || new Array(src.length); for(var i=0, l=src.length; i<l; i++){ pixels[offset++] = this.getToneFor(src[i]).toARGB(); } return pixels; }
[ "function", "(", "src", ",", "pixels", ",", "offset", ")", "{", "if", "(", "typeof", "offset", "!==", "'number'", ")", "{", "offset", "=", "0", ";", "}", "else", "if", "(", "offset", "<", "0", ")", "{", "throw", "new", "Error", "(", "\"offset into target pixel array is negative\"", ")", ";", "}", "pixels", "=", "pixels", "||", "new", "Array", "(", "src", ".", "length", ")", ";", "for", "(", "var", "i", "=", "0", ",", "l", "=", "src", ".", "length", ";", "i", "<", "l", ";", "i", "++", ")", "{", "pixels", "[", "offset", "++", "]", "=", "this", ".", "getToneFor", "(", "src", "[", "i", "]", ")", ".", "toARGB", "(", ")", ";", "}", "return", "pixels", ";", "}" ]
Applies the tonemap to all elements in the given source array of values and places the resulting ARGB color in the corresponding index of the target pixel buffer. If the target buffer is null, a new one will be created automatically. @param {Array<Number>}src source array of values to be tone mapped @param {Array<Number>}pixels target pixel buffer @param {Number} [offset] optionally provide an index-offset to start at in the destination pixels array @return pixel array
[ "Applies", "the", "tonemap", "to", "all", "elements", "in", "the", "given", "source", "array", "of", "values", "and", "places", "the", "resulting", "ARGB", "color", "in", "the", "corresponding", "index", "of", "the", "target", "pixel", "buffer", ".", "If", "the", "target", "buffer", "is", "null", "a", "new", "one", "will", "be", "created", "automatically", "." ]
3712b44242128245084f18cbad7f0dfa0fc41d9b
https://github.com/hapticdata/toxiclibsjs/blob/3712b44242128245084f18cbad7f0dfa0fc41d9b/lib/toxi/color/ToneMap.js#L84-L95
19,333
hapticdata/toxiclibsjs
lib/toxi/geom/SutherlandHodgemanClipper.js
function( list, q ){ for( var i=0, l=list.length; i<l; i++){ if( list[i].equalsWithTolerance(q, 0.0001) ){ return true; } } return false; }
javascript
function( list, q ){ for( var i=0, l=list.length; i<l; i++){ if( list[i].equalsWithTolerance(q, 0.0001) ){ return true; } } return false; }
[ "function", "(", "list", ",", "q", ")", "{", "for", "(", "var", "i", "=", "0", ",", "l", "=", "list", ".", "length", ";", "i", "<", "l", ";", "i", "++", ")", "{", "if", "(", "list", "[", "i", "]", ".", "equalsWithTolerance", "(", "q", ",", "0.0001", ")", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
protected + unused in java
[ "protected", "+", "unused", "in", "java" ]
3712b44242128245084f18cbad7f0dfa0fc41d9b
https://github.com/hapticdata/toxiclibsjs/blob/3712b44242128245084f18cbad7f0dfa0fc41d9b/lib/toxi/geom/SutherlandHodgemanClipper.js#L127-L134
19,334
hapticdata/toxiclibsjs
lib/toxi/math/waves/AbstractWave.js
function(freq){ if(freq === undefined)freq = 0; this.phase = (this.phase + freq) % AbstractWave.TWO_PI; if(this.phase < 0){ this.phase += AbstractWave.TWO_PI; } return this.phase; }
javascript
function(freq){ if(freq === undefined)freq = 0; this.phase = (this.phase + freq) % AbstractWave.TWO_PI; if(this.phase < 0){ this.phase += AbstractWave.TWO_PI; } return this.phase; }
[ "function", "(", "freq", ")", "{", "if", "(", "freq", "===", "undefined", ")", "freq", "=", "0", ";", "this", ".", "phase", "=", "(", "this", ".", "phase", "+", "freq", ")", "%", "AbstractWave", ".", "TWO_PI", ";", "if", "(", "this", ".", "phase", "<", "0", ")", "{", "this", ".", "phase", "+=", "AbstractWave", ".", "TWO_PI", ";", "}", "return", "this", ".", "phase", ";", "}" ]
Ensures phase remains in the 0...TWO_PI interval. @param {Number} freq normalized progress frequency @return {Number} current phase
[ "Ensures", "phase", "remains", "in", "the", "0", "...", "TWO_PI", "interval", "." ]
3712b44242128245084f18cbad7f0dfa0fc41d9b
https://github.com/hapticdata/toxiclibsjs/blob/3712b44242128245084f18cbad7f0dfa0fc41d9b/lib/toxi/math/waves/AbstractWave.js#L39-L46
19,335
hapticdata/toxiclibsjs
examples/js/three.js
paramThreeToGL
function paramThreeToGL ( p ) { if ( p === THREE.RepeatWrapping ) return _gl.REPEAT; if ( p === THREE.ClampToEdgeWrapping ) return _gl.CLAMP_TO_EDGE; if ( p === THREE.MirroredRepeatWrapping ) return _gl.MIRRORED_REPEAT; if ( p === THREE.NearestFilter ) return _gl.NEAREST; if ( p === THREE.NearestMipMapNearestFilter ) return _gl.NEAREST_MIPMAP_NEAREST; if ( p === THREE.NearestMipMapLinearFilter ) return _gl.NEAREST_MIPMAP_LINEAR; if ( p === THREE.LinearFilter ) return _gl.LINEAR; if ( p === THREE.LinearMipMapNearestFilter ) return _gl.LINEAR_MIPMAP_NEAREST; if ( p === THREE.LinearMipMapLinearFilter ) return _gl.LINEAR_MIPMAP_LINEAR; if ( p === THREE.UnsignedByteType ) return _gl.UNSIGNED_BYTE; if ( p === THREE.UnsignedShort4444Type ) return _gl.UNSIGNED_SHORT_4_4_4_4; if ( p === THREE.UnsignedShort5551Type ) return _gl.UNSIGNED_SHORT_5_5_5_1; if ( p === THREE.UnsignedShort565Type ) return _gl.UNSIGNED_SHORT_5_6_5; if ( p === THREE.ByteType ) return _gl.BYTE; if ( p === THREE.ShortType ) return _gl.SHORT; if ( p === THREE.UnsignedShortType ) return _gl.UNSIGNED_SHORT; if ( p === THREE.IntType ) return _gl.INT; if ( p === THREE.UnsignedIntType ) return _gl.UNSIGNED_INT; if ( p === THREE.FloatType ) return _gl.FLOAT; if ( p === THREE.AlphaFormat ) return _gl.ALPHA; if ( p === THREE.RGBFormat ) return _gl.RGB; if ( p === THREE.RGBAFormat ) return _gl.RGBA; if ( p === THREE.LuminanceFormat ) return _gl.LUMINANCE; if ( p === THREE.LuminanceAlphaFormat ) return _gl.LUMINANCE_ALPHA; if ( p === THREE.AddEquation ) return _gl.FUNC_ADD; if ( p === THREE.SubtractEquation ) return _gl.FUNC_SUBTRACT; if ( p === THREE.ReverseSubtractEquation ) return _gl.FUNC_REVERSE_SUBTRACT; if ( p === THREE.ZeroFactor ) return _gl.ZERO; if ( p === THREE.OneFactor ) return _gl.ONE; if ( p === THREE.SrcColorFactor ) return _gl.SRC_COLOR; if ( p === THREE.OneMinusSrcColorFactor ) return _gl.ONE_MINUS_SRC_COLOR; if ( p === THREE.SrcAlphaFactor ) return _gl.SRC_ALPHA; if ( p === THREE.OneMinusSrcAlphaFactor ) return _gl.ONE_MINUS_SRC_ALPHA; if ( p === THREE.DstAlphaFactor ) return _gl.DST_ALPHA; if ( p === THREE.OneMinusDstAlphaFactor ) return _gl.ONE_MINUS_DST_ALPHA; if ( p === THREE.DstColorFactor ) return _gl.DST_COLOR; if ( p === THREE.OneMinusDstColorFactor ) return _gl.ONE_MINUS_DST_COLOR; if ( p === THREE.SrcAlphaSaturateFactor ) return _gl.SRC_ALPHA_SATURATE; return 0; }
javascript
function paramThreeToGL ( p ) { if ( p === THREE.RepeatWrapping ) return _gl.REPEAT; if ( p === THREE.ClampToEdgeWrapping ) return _gl.CLAMP_TO_EDGE; if ( p === THREE.MirroredRepeatWrapping ) return _gl.MIRRORED_REPEAT; if ( p === THREE.NearestFilter ) return _gl.NEAREST; if ( p === THREE.NearestMipMapNearestFilter ) return _gl.NEAREST_MIPMAP_NEAREST; if ( p === THREE.NearestMipMapLinearFilter ) return _gl.NEAREST_MIPMAP_LINEAR; if ( p === THREE.LinearFilter ) return _gl.LINEAR; if ( p === THREE.LinearMipMapNearestFilter ) return _gl.LINEAR_MIPMAP_NEAREST; if ( p === THREE.LinearMipMapLinearFilter ) return _gl.LINEAR_MIPMAP_LINEAR; if ( p === THREE.UnsignedByteType ) return _gl.UNSIGNED_BYTE; if ( p === THREE.UnsignedShort4444Type ) return _gl.UNSIGNED_SHORT_4_4_4_4; if ( p === THREE.UnsignedShort5551Type ) return _gl.UNSIGNED_SHORT_5_5_5_1; if ( p === THREE.UnsignedShort565Type ) return _gl.UNSIGNED_SHORT_5_6_5; if ( p === THREE.ByteType ) return _gl.BYTE; if ( p === THREE.ShortType ) return _gl.SHORT; if ( p === THREE.UnsignedShortType ) return _gl.UNSIGNED_SHORT; if ( p === THREE.IntType ) return _gl.INT; if ( p === THREE.UnsignedIntType ) return _gl.UNSIGNED_INT; if ( p === THREE.FloatType ) return _gl.FLOAT; if ( p === THREE.AlphaFormat ) return _gl.ALPHA; if ( p === THREE.RGBFormat ) return _gl.RGB; if ( p === THREE.RGBAFormat ) return _gl.RGBA; if ( p === THREE.LuminanceFormat ) return _gl.LUMINANCE; if ( p === THREE.LuminanceAlphaFormat ) return _gl.LUMINANCE_ALPHA; if ( p === THREE.AddEquation ) return _gl.FUNC_ADD; if ( p === THREE.SubtractEquation ) return _gl.FUNC_SUBTRACT; if ( p === THREE.ReverseSubtractEquation ) return _gl.FUNC_REVERSE_SUBTRACT; if ( p === THREE.ZeroFactor ) return _gl.ZERO; if ( p === THREE.OneFactor ) return _gl.ONE; if ( p === THREE.SrcColorFactor ) return _gl.SRC_COLOR; if ( p === THREE.OneMinusSrcColorFactor ) return _gl.ONE_MINUS_SRC_COLOR; if ( p === THREE.SrcAlphaFactor ) return _gl.SRC_ALPHA; if ( p === THREE.OneMinusSrcAlphaFactor ) return _gl.ONE_MINUS_SRC_ALPHA; if ( p === THREE.DstAlphaFactor ) return _gl.DST_ALPHA; if ( p === THREE.OneMinusDstAlphaFactor ) return _gl.ONE_MINUS_DST_ALPHA; if ( p === THREE.DstColorFactor ) return _gl.DST_COLOR; if ( p === THREE.OneMinusDstColorFactor ) return _gl.ONE_MINUS_DST_COLOR; if ( p === THREE.SrcAlphaSaturateFactor ) return _gl.SRC_ALPHA_SATURATE; return 0; }
[ "function", "paramThreeToGL", "(", "p", ")", "{", "if", "(", "p", "===", "THREE", ".", "RepeatWrapping", ")", "return", "_gl", ".", "REPEAT", ";", "if", "(", "p", "===", "THREE", ".", "ClampToEdgeWrapping", ")", "return", "_gl", ".", "CLAMP_TO_EDGE", ";", "if", "(", "p", "===", "THREE", ".", "MirroredRepeatWrapping", ")", "return", "_gl", ".", "MIRRORED_REPEAT", ";", "if", "(", "p", "===", "THREE", ".", "NearestFilter", ")", "return", "_gl", ".", "NEAREST", ";", "if", "(", "p", "===", "THREE", ".", "NearestMipMapNearestFilter", ")", "return", "_gl", ".", "NEAREST_MIPMAP_NEAREST", ";", "if", "(", "p", "===", "THREE", ".", "NearestMipMapLinearFilter", ")", "return", "_gl", ".", "NEAREST_MIPMAP_LINEAR", ";", "if", "(", "p", "===", "THREE", ".", "LinearFilter", ")", "return", "_gl", ".", "LINEAR", ";", "if", "(", "p", "===", "THREE", ".", "LinearMipMapNearestFilter", ")", "return", "_gl", ".", "LINEAR_MIPMAP_NEAREST", ";", "if", "(", "p", "===", "THREE", ".", "LinearMipMapLinearFilter", ")", "return", "_gl", ".", "LINEAR_MIPMAP_LINEAR", ";", "if", "(", "p", "===", "THREE", ".", "UnsignedByteType", ")", "return", "_gl", ".", "UNSIGNED_BYTE", ";", "if", "(", "p", "===", "THREE", ".", "UnsignedShort4444Type", ")", "return", "_gl", ".", "UNSIGNED_SHORT_4_4_4_4", ";", "if", "(", "p", "===", "THREE", ".", "UnsignedShort5551Type", ")", "return", "_gl", ".", "UNSIGNED_SHORT_5_5_5_1", ";", "if", "(", "p", "===", "THREE", ".", "UnsignedShort565Type", ")", "return", "_gl", ".", "UNSIGNED_SHORT_5_6_5", ";", "if", "(", "p", "===", "THREE", ".", "ByteType", ")", "return", "_gl", ".", "BYTE", ";", "if", "(", "p", "===", "THREE", ".", "ShortType", ")", "return", "_gl", ".", "SHORT", ";", "if", "(", "p", "===", "THREE", ".", "UnsignedShortType", ")", "return", "_gl", ".", "UNSIGNED_SHORT", ";", "if", "(", "p", "===", "THREE", ".", "IntType", ")", "return", "_gl", ".", "INT", ";", "if", "(", "p", "===", "THREE", ".", "UnsignedIntType", ")", "return", "_gl", ".", "UNSIGNED_INT", ";", "if", "(", "p", "===", "THREE", ".", "FloatType", ")", "return", "_gl", ".", "FLOAT", ";", "if", "(", "p", "===", "THREE", ".", "AlphaFormat", ")", "return", "_gl", ".", "ALPHA", ";", "if", "(", "p", "===", "THREE", ".", "RGBFormat", ")", "return", "_gl", ".", "RGB", ";", "if", "(", "p", "===", "THREE", ".", "RGBAFormat", ")", "return", "_gl", ".", "RGBA", ";", "if", "(", "p", "===", "THREE", ".", "LuminanceFormat", ")", "return", "_gl", ".", "LUMINANCE", ";", "if", "(", "p", "===", "THREE", ".", "LuminanceAlphaFormat", ")", "return", "_gl", ".", "LUMINANCE_ALPHA", ";", "if", "(", "p", "===", "THREE", ".", "AddEquation", ")", "return", "_gl", ".", "FUNC_ADD", ";", "if", "(", "p", "===", "THREE", ".", "SubtractEquation", ")", "return", "_gl", ".", "FUNC_SUBTRACT", ";", "if", "(", "p", "===", "THREE", ".", "ReverseSubtractEquation", ")", "return", "_gl", ".", "FUNC_REVERSE_SUBTRACT", ";", "if", "(", "p", "===", "THREE", ".", "ZeroFactor", ")", "return", "_gl", ".", "ZERO", ";", "if", "(", "p", "===", "THREE", ".", "OneFactor", ")", "return", "_gl", ".", "ONE", ";", "if", "(", "p", "===", "THREE", ".", "SrcColorFactor", ")", "return", "_gl", ".", "SRC_COLOR", ";", "if", "(", "p", "===", "THREE", ".", "OneMinusSrcColorFactor", ")", "return", "_gl", ".", "ONE_MINUS_SRC_COLOR", ";", "if", "(", "p", "===", "THREE", ".", "SrcAlphaFactor", ")", "return", "_gl", ".", "SRC_ALPHA", ";", "if", "(", "p", "===", "THREE", ".", "OneMinusSrcAlphaFactor", ")", "return", "_gl", ".", "ONE_MINUS_SRC_ALPHA", ";", "if", "(", "p", "===", "THREE", ".", "DstAlphaFactor", ")", "return", "_gl", ".", "DST_ALPHA", ";", "if", "(", "p", "===", "THREE", ".", "OneMinusDstAlphaFactor", ")", "return", "_gl", ".", "ONE_MINUS_DST_ALPHA", ";", "if", "(", "p", "===", "THREE", ".", "DstColorFactor", ")", "return", "_gl", ".", "DST_COLOR", ";", "if", "(", "p", "===", "THREE", ".", "OneMinusDstColorFactor", ")", "return", "_gl", ".", "ONE_MINUS_DST_COLOR", ";", "if", "(", "p", "===", "THREE", ".", "SrcAlphaSaturateFactor", ")", "return", "_gl", ".", "SRC_ALPHA_SATURATE", ";", "return", "0", ";", "}" ]
Map three.js constants to WebGL constants
[ "Map", "three", ".", "js", "constants", "to", "WebGL", "constants" ]
3712b44242128245084f18cbad7f0dfa0fc41d9b
https://github.com/hapticdata/toxiclibsjs/blob/3712b44242128245084f18cbad7f0dfa0fc41d9b/examples/js/three.js#L21255-L21306
19,336
hapticdata/toxiclibsjs
examples/js/three.js
prepare
function prepare( vector ) { var vertex = vector.normalize().clone(); vertex.index = that.vertices.push( vertex ) - 1; // Texture coords are equivalent to map coords, calculate angle and convert to fraction of a circle. var u = azimuth( vector ) / 2 / Math.PI + 0.5; var v = inclination( vector ) / Math.PI + 0.5; vertex.uv = new THREE.UV( u, 1 - v ); return vertex; }
javascript
function prepare( vector ) { var vertex = vector.normalize().clone(); vertex.index = that.vertices.push( vertex ) - 1; // Texture coords are equivalent to map coords, calculate angle and convert to fraction of a circle. var u = azimuth( vector ) / 2 / Math.PI + 0.5; var v = inclination( vector ) / Math.PI + 0.5; vertex.uv = new THREE.UV( u, 1 - v ); return vertex; }
[ "function", "prepare", "(", "vector", ")", "{", "var", "vertex", "=", "vector", ".", "normalize", "(", ")", ".", "clone", "(", ")", ";", "vertex", ".", "index", "=", "that", ".", "vertices", ".", "push", "(", "vertex", ")", "-", "1", ";", "// Texture coords are equivalent to map coords, calculate angle and convert to fraction of a circle.", "var", "u", "=", "azimuth", "(", "vector", ")", "/", "2", "/", "Math", ".", "PI", "+", "0.5", ";", "var", "v", "=", "inclination", "(", "vector", ")", "/", "Math", ".", "PI", "+", "0.5", ";", "vertex", ".", "uv", "=", "new", "THREE", ".", "UV", "(", "u", ",", "1", "-", "v", ")", ";", "return", "vertex", ";", "}" ]
Project vector onto sphere's surface
[ "Project", "vector", "onto", "sphere", "s", "surface" ]
3712b44242128245084f18cbad7f0dfa0fc41d9b
https://github.com/hapticdata/toxiclibsjs/blob/3712b44242128245084f18cbad7f0dfa0fc41d9b/examples/js/three.js#L31817-L31830
19,337
hapticdata/toxiclibsjs
examples/js/three.js
visible
function visible( face, vertex ) { var va = vertices[ face[ 0 ] ]; var vb = vertices[ face[ 1 ] ]; var vc = vertices[ face[ 2 ] ]; var n = normal( va, vb, vc ); // distance from face to origin var dist = n.dot( va ); return n.dot( vertex ) >= dist; }
javascript
function visible( face, vertex ) { var va = vertices[ face[ 0 ] ]; var vb = vertices[ face[ 1 ] ]; var vc = vertices[ face[ 2 ] ]; var n = normal( va, vb, vc ); // distance from face to origin var dist = n.dot( va ); return n.dot( vertex ) >= dist; }
[ "function", "visible", "(", "face", ",", "vertex", ")", "{", "var", "va", "=", "vertices", "[", "face", "[", "0", "]", "]", ";", "var", "vb", "=", "vertices", "[", "face", "[", "1", "]", "]", ";", "var", "vc", "=", "vertices", "[", "face", "[", "2", "]", "]", ";", "var", "n", "=", "normal", "(", "va", ",", "vb", ",", "vc", ")", ";", "// distance from face to origin", "var", "dist", "=", "n", ".", "dot", "(", "va", ")", ";", "return", "n", ".", "dot", "(", "vertex", ")", ">=", "dist", ";", "}" ]
Whether the face is visible from the vertex
[ "Whether", "the", "face", "is", "visible", "from", "the", "vertex" ]
3712b44242128245084f18cbad7f0dfa0fc41d9b
https://github.com/hapticdata/toxiclibsjs/blob/3712b44242128245084f18cbad7f0dfa0fc41d9b/examples/js/three.js#L32177-L32190
19,338
hapticdata/toxiclibsjs
lib/toxi/geom/mesh/VertexSelector.js
function() { var newSel = []; var vertices = this.mesh.getVertices(); var l = vertices.length; for (var i=0;i<l;i++) { var v = vertices[i]; if (this.selection.indexOf(v) < 0 ) { newSel.push(v); } } this.selection = newSel; return this; }
javascript
function() { var newSel = []; var vertices = this.mesh.getVertices(); var l = vertices.length; for (var i=0;i<l;i++) { var v = vertices[i]; if (this.selection.indexOf(v) < 0 ) { newSel.push(v); } } this.selection = newSel; return this; }
[ "function", "(", ")", "{", "var", "newSel", "=", "[", "]", ";", "var", "vertices", "=", "this", ".", "mesh", ".", "getVertices", "(", ")", ";", "var", "l", "=", "vertices", ".", "length", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "l", ";", "i", "++", ")", "{", "var", "v", "=", "vertices", "[", "i", "]", ";", "if", "(", "this", ".", "selection", ".", "indexOf", "(", "v", ")", "<", "0", ")", "{", "newSel", ".", "push", "(", "v", ")", ";", "}", "}", "this", ".", "selection", "=", "newSel", ";", "return", "this", ";", "}" ]
Creates a new selection of all vertices NOT currently selected. @return itself
[ "Creates", "a", "new", "selection", "of", "all", "vertices", "NOT", "currently", "selected", "." ]
3712b44242128245084f18cbad7f0dfa0fc41d9b
https://github.com/hapticdata/toxiclibsjs/blob/3712b44242128245084f18cbad7f0dfa0fc41d9b/lib/toxi/geom/mesh/VertexSelector.js#L50-L62
19,339
hapticdata/toxiclibsjs
lib/toxi/geom/mesh/VertexSelector.js
function(points) { var l = points.length; for (var i=0;i<l;i++) { var v = points[i]; this.selection.push( this.mesh.getClosestVertexToPoint(v) ); } return this; }
javascript
function(points) { var l = points.length; for (var i=0;i<l;i++) { var v = points[i]; this.selection.push( this.mesh.getClosestVertexToPoint(v) ); } return this; }
[ "function", "(", "points", ")", "{", "var", "l", "=", "points", ".", "length", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "l", ";", "i", "++", ")", "{", "var", "v", "=", "points", "[", "i", "]", ";", "this", ".", "selection", ".", "push", "(", "this", ".", "mesh", ".", "getClosestVertexToPoint", "(", "v", ")", ")", ";", "}", "return", "this", ";", "}" ]
Selects vertices identical or closest to the ones given in the list of points. @param points @return itself
[ "Selects", "vertices", "identical", "or", "closest", "to", "the", "ones", "given", "in", "the", "list", "of", "points", "." ]
3712b44242128245084f18cbad7f0dfa0fc41d9b
https://github.com/hapticdata/toxiclibsjs/blob/3712b44242128245084f18cbad7f0dfa0fc41d9b/lib/toxi/geom/mesh/VertexSelector.js#L70-L77
19,340
hapticdata/toxiclibsjs
lib/toxi/geom/mesh/VertexSelector.js
function(sel2) { this.checkMeshIdentity(sel2.getMesh()); var removeThese = sel2.getSelection(); var i,l = removeThese.length; for ( i=0; i<l; i++ ) { this.selection.splice( this.selection.indexOf(removeThese[i]), 1 ); } return this; }
javascript
function(sel2) { this.checkMeshIdentity(sel2.getMesh()); var removeThese = sel2.getSelection(); var i,l = removeThese.length; for ( i=0; i<l; i++ ) { this.selection.splice( this.selection.indexOf(removeThese[i]), 1 ); } return this; }
[ "function", "(", "sel2", ")", "{", "this", ".", "checkMeshIdentity", "(", "sel2", ".", "getMesh", "(", ")", ")", ";", "var", "removeThese", "=", "sel2", ".", "getSelection", "(", ")", ";", "var", "i", ",", "l", "=", "removeThese", ".", "length", ";", "for", "(", "i", "=", "0", ";", "i", "<", "l", ";", "i", "++", ")", "{", "this", ".", "selection", ".", "splice", "(", "this", ".", "selection", ".", "indexOf", "(", "removeThese", "[", "i", "]", ")", ",", "1", ")", ";", "}", "return", "this", ";", "}" ]
Removes all vertices selected by the given selector from the current selection. The other selector needs to be assigned to the same mesh instance. @param sel2 other selector @return itself
[ "Removes", "all", "vertices", "selected", "by", "the", "given", "selector", "from", "the", "current", "selection", ".", "The", "other", "selector", "needs", "to", "be", "assigned", "to", "the", "same", "mesh", "instance", "." ]
3712b44242128245084f18cbad7f0dfa0fc41d9b
https://github.com/hapticdata/toxiclibsjs/blob/3712b44242128245084f18cbad7f0dfa0fc41d9b/lib/toxi/geom/mesh/VertexSelector.js#L103-L111
19,341
hapticdata/toxiclibsjs
lib/toxi/color/ColorRange.js
function( rc ){ if( is.ColorRange(rc) ){ addAll(this.hueConstraint, rc.hueConstraint); addAll(this.saturationConstraint, rc.saturationConstraint); addAll(this.brightnessConstraint, rc.brightnessConstraint); addAll(this.alphaConstraint, rc.alphaConstraint); this.black.min = Math.min( this.black.min, rc.black.min ); this.black.max = Math.max( this.black.max, rc.black.max ); this.white.min = Math.min( this.white.min, rc.white.min ); this.white.max = Math.max( this.white.max, rc.white.max ); } else { this.hueConstraint.push( new FloatRange(rc.hue(),rc.hue()) ); this.saturationConstraint.push( new FloatRange(rc.saturation(),rc.saturation()) ); this.brightnessConstraint.push( new FloatRange(rc.brightness(),rc.brightness()) ); this.alphaConstraint.push( new FloatRange(rc.alpha(),rc.alpha()) ); } return this; }
javascript
function( rc ){ if( is.ColorRange(rc) ){ addAll(this.hueConstraint, rc.hueConstraint); addAll(this.saturationConstraint, rc.saturationConstraint); addAll(this.brightnessConstraint, rc.brightnessConstraint); addAll(this.alphaConstraint, rc.alphaConstraint); this.black.min = Math.min( this.black.min, rc.black.min ); this.black.max = Math.max( this.black.max, rc.black.max ); this.white.min = Math.min( this.white.min, rc.white.min ); this.white.max = Math.max( this.white.max, rc.white.max ); } else { this.hueConstraint.push( new FloatRange(rc.hue(),rc.hue()) ); this.saturationConstraint.push( new FloatRange(rc.saturation(),rc.saturation()) ); this.brightnessConstraint.push( new FloatRange(rc.brightness(),rc.brightness()) ); this.alphaConstraint.push( new FloatRange(rc.alpha(),rc.alpha()) ); } return this; }
[ "function", "(", "rc", ")", "{", "if", "(", "is", ".", "ColorRange", "(", "rc", ")", ")", "{", "addAll", "(", "this", ".", "hueConstraint", ",", "rc", ".", "hueConstraint", ")", ";", "addAll", "(", "this", ".", "saturationConstraint", ",", "rc", ".", "saturationConstraint", ")", ";", "addAll", "(", "this", ".", "brightnessConstraint", ",", "rc", ".", "brightnessConstraint", ")", ";", "addAll", "(", "this", ".", "alphaConstraint", ",", "rc", ".", "alphaConstraint", ")", ";", "this", ".", "black", ".", "min", "=", "Math", ".", "min", "(", "this", ".", "black", ".", "min", ",", "rc", ".", "black", ".", "min", ")", ";", "this", ".", "black", ".", "max", "=", "Math", ".", "max", "(", "this", ".", "black", ".", "max", ",", "rc", ".", "black", ".", "max", ")", ";", "this", ".", "white", ".", "min", "=", "Math", ".", "min", "(", "this", ".", "white", ".", "min", ",", "rc", ".", "white", ".", "min", ")", ";", "this", ".", "white", ".", "max", "=", "Math", ".", "max", "(", "this", ".", "white", ".", "max", ",", "rc", ".", "white", ".", "max", ")", ";", "}", "else", "{", "this", ".", "hueConstraint", ".", "push", "(", "new", "FloatRange", "(", "rc", ".", "hue", "(", ")", ",", "rc", ".", "hue", "(", ")", ")", ")", ";", "this", ".", "saturationConstraint", ".", "push", "(", "new", "FloatRange", "(", "rc", ".", "saturation", "(", ")", ",", "rc", ".", "saturation", "(", ")", ")", ")", ";", "this", ".", "brightnessConstraint", ".", "push", "(", "new", "FloatRange", "(", "rc", ".", "brightness", "(", ")", ",", "rc", ".", "brightness", "(", ")", ")", ")", ";", "this", ".", "alphaConstraint", ".", "push", "(", "new", "FloatRange", "(", "rc", ".", "alpha", "(", ")", ",", "rc", ".", "alpha", "(", ")", ")", ")", ";", "}", "return", "this", ";", "}" ]
Adds the HSV color components as constraints @param {toxi.color.ColorRange | toxi.color.TColor} rc @return itself
[ "Adds", "the", "HSV", "color", "components", "as", "constraints" ]
3712b44242128245084f18cbad7f0dfa0fc41d9b
https://github.com/hapticdata/toxiclibsjs/blob/3712b44242128245084f18cbad7f0dfa0fc41d9b/lib/toxi/color/ColorRange.js#L135-L152
19,342
hapticdata/toxiclibsjs
lib/toxi/color/ColorRange.js
function( c ){ var isInRange = this.isValueInConstraint(c.hue(), this.hueConstraint); isInRange &= this.isValueInConstraint(c.saturation(), this.saturationConstraint); isInRange &= this.isValueInConstraint(c.brightness(), this.brightnessConstraint); isInRange &= this.isValueInConstraint(c.alpha(), this.alphaConstraint); return isInRange || false; //if its 0, return false }
javascript
function( c ){ var isInRange = this.isValueInConstraint(c.hue(), this.hueConstraint); isInRange &= this.isValueInConstraint(c.saturation(), this.saturationConstraint); isInRange &= this.isValueInConstraint(c.brightness(), this.brightnessConstraint); isInRange &= this.isValueInConstraint(c.alpha(), this.alphaConstraint); return isInRange || false; //if its 0, return false }
[ "function", "(", "c", ")", "{", "var", "isInRange", "=", "this", ".", "isValueInConstraint", "(", "c", ".", "hue", "(", ")", ",", "this", ".", "hueConstraint", ")", ";", "isInRange", "&=", "this", ".", "isValueInConstraint", "(", "c", ".", "saturation", "(", ")", ",", "this", ".", "saturationConstraint", ")", ";", "isInRange", "&=", "this", ".", "isValueInConstraint", "(", "c", ".", "brightness", "(", ")", ",", "this", ".", "brightnessConstraint", ")", ";", "isInRange", "&=", "this", ".", "isValueInConstraint", "(", "c", ".", "alpha", "(", ")", ",", "this", ".", "alphaConstraint", ")", ";", "return", "isInRange", "||", "false", ";", "//if its 0, return false", "}" ]
checks if all HSVA components of the given color are within the constraints define for this range @param {toxi.color.TColor} c @return true if is contained
[ "checks", "if", "all", "HSVA", "components", "of", "the", "given", "color", "are", "within", "the", "constraints", "define", "for", "this", "range" ]
3712b44242128245084f18cbad7f0dfa0fc41d9b
https://github.com/hapticdata/toxiclibsjs/blob/3712b44242128245084f18cbad7f0dfa0fc41d9b/lib/toxi/color/ColorRange.js#L173-L179
19,343
hapticdata/toxiclibsjs
lib/toxi/color/ColorRange.js
function( c, num, variance ){ if( arguments.length < 3 ){ variance = ColorRange.DEFAULT_VARIANCE; } if( arguments.length === 1 ){ num = c; c = undefined; } var list = new ColorList(); for( var i=0; i<num; i++){ list.add(this.getColor(c, variance)); } return list; }
javascript
function( c, num, variance ){ if( arguments.length < 3 ){ variance = ColorRange.DEFAULT_VARIANCE; } if( arguments.length === 1 ){ num = c; c = undefined; } var list = new ColorList(); for( var i=0; i<num; i++){ list.add(this.getColor(c, variance)); } return list; }
[ "function", "(", "c", ",", "num", ",", "variance", ")", "{", "if", "(", "arguments", ".", "length", "<", "3", ")", "{", "variance", "=", "ColorRange", ".", "DEFAULT_VARIANCE", ";", "}", "if", "(", "arguments", ".", "length", "===", "1", ")", "{", "num", "=", "c", ";", "c", "=", "undefined", ";", "}", "var", "list", "=", "new", "ColorList", "(", ")", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "num", ";", "i", "++", ")", "{", "list", ".", "add", "(", "this", ".", "getColor", "(", "c", ",", "variance", ")", ")", ";", "}", "return", "list", ";", "}" ]
creates a new `toxi.color.ColorList` of colors based on constraints of this range 1. @param {Number} num integer of how many colors to get 2. @param {toxi.color.TColor} c @param {Number} num @param {Number} variance @return {toxi.color.ColorList} list
[ "creates", "a", "new", "toxi", ".", "color", ".", "ColorList", "of", "colors", "based", "on", "constraints", "of", "this", "range", "1", "." ]
3712b44242128245084f18cbad7f0dfa0fc41d9b
https://github.com/hapticdata/toxiclibsjs/blob/3712b44242128245084f18cbad7f0dfa0fc41d9b/lib/toxi/color/ColorRange.js#L261-L274
19,344
hapticdata/toxiclibsjs
lib/toxi/util/datatypes/FloatRange.js
function(min, max){ min = min || 0.0; max = typeof max === 'number' ? max : 1.0; // swap if necessary if(min > max){ var t= max; max = min; min = t; } this.min = min; this.max = max; this.currValue = min; }
javascript
function(min, max){ min = min || 0.0; max = typeof max === 'number' ? max : 1.0; // swap if necessary if(min > max){ var t= max; max = min; min = t; } this.min = min; this.max = max; this.currValue = min; }
[ "function", "(", "min", ",", "max", ")", "{", "min", "=", "min", "||", "0.0", ";", "max", "=", "typeof", "max", "===", "'number'", "?", "max", ":", "1.0", ";", "// swap if necessary", "if", "(", "min", ">", "max", ")", "{", "var", "t", "=", "max", ";", "max", "=", "min", ";", "min", "=", "t", ";", "}", "this", ".", "min", "=", "min", ";", "this", ".", "max", "=", "max", ";", "this", ".", "currValue", "=", "min", ";", "}" ]
construct a new `FloatRange` provides utilities for dealing with a range of Numbers. @param {Number} [min=0] the minimum in the range @param {Number} [max=1.0] the maximum in the range @constructor
[ "construct", "a", "new", "FloatRange", "provides", "utilities", "for", "dealing", "with", "a", "range", "of", "Numbers", "." ]
3712b44242128245084f18cbad7f0dfa0fc41d9b
https://github.com/hapticdata/toxiclibsjs/blob/3712b44242128245084f18cbad7f0dfa0fc41d9b/lib/toxi/util/datatypes/FloatRange.js#L12-L24
19,345
hapticdata/toxiclibsjs
lib/toxi/geom/mesh/meshCommon.js
function(a,b,c,n,uvA,uvB,uvC){ //can be 3 args, 4 args, 6 args, or 7 args //if it was 6 swap vars around, if( arguments.length == 6 ){ uvC = uvB; uvB = uvA; uvA = n; n = undefined; } //7 param method var va = this.__checkVertex(a); var vb = this.__checkVertex(b); var vc = this.__checkVertex(c); if(va.id === vb.id || va.id === vc.id || vb.id === vc.id){ //console.log("ignoring invalid face: "+a + ", " +b+ ", "+c); } else { if(n != null ){ var nc = va.sub(vc).crossSelf(va.sub(vb)); if(n.dot(nc)<0){ var t = va; va = vb; vb = t; } } var f = new Face(va,vb,vc,uvA,uvB,uvC); this.faces.push(f); } return this; }
javascript
function(a,b,c,n,uvA,uvB,uvC){ //can be 3 args, 4 args, 6 args, or 7 args //if it was 6 swap vars around, if( arguments.length == 6 ){ uvC = uvB; uvB = uvA; uvA = n; n = undefined; } //7 param method var va = this.__checkVertex(a); var vb = this.__checkVertex(b); var vc = this.__checkVertex(c); if(va.id === vb.id || va.id === vc.id || vb.id === vc.id){ //console.log("ignoring invalid face: "+a + ", " +b+ ", "+c); } else { if(n != null ){ var nc = va.sub(vc).crossSelf(va.sub(vb)); if(n.dot(nc)<0){ var t = va; va = vb; vb = t; } } var f = new Face(va,vb,vc,uvA,uvB,uvC); this.faces.push(f); } return this; }
[ "function", "(", "a", ",", "b", ",", "c", ",", "n", ",", "uvA", ",", "uvB", ",", "uvC", ")", "{", "//can be 3 args, 4 args, 6 args, or 7 args", "//if it was 6 swap vars around,", "if", "(", "arguments", ".", "length", "==", "6", ")", "{", "uvC", "=", "uvB", ";", "uvB", "=", "uvA", ";", "uvA", "=", "n", ";", "n", "=", "undefined", ";", "}", "//7 param method", "var", "va", "=", "this", ".", "__checkVertex", "(", "a", ")", ";", "var", "vb", "=", "this", ".", "__checkVertex", "(", "b", ")", ";", "var", "vc", "=", "this", ".", "__checkVertex", "(", "c", ")", ";", "if", "(", "va", ".", "id", "===", "vb", ".", "id", "||", "va", ".", "id", "===", "vc", ".", "id", "||", "vb", ".", "id", "===", "vc", ".", "id", ")", "{", "//console.log(\"ignoring invalid face: \"+a + \", \" +b+ \", \"+c);", "}", "else", "{", "if", "(", "n", "!=", "null", ")", "{", "var", "nc", "=", "va", ".", "sub", "(", "vc", ")", ".", "crossSelf", "(", "va", ".", "sub", "(", "vb", ")", ")", ";", "if", "(", "n", ".", "dot", "(", "nc", ")", "<", "0", ")", "{", "var", "t", "=", "va", ";", "va", "=", "vb", ";", "vb", "=", "t", ";", "}", "}", "var", "f", "=", "new", "Face", "(", "va", ",", "vb", ",", "vc", ",", "uvA", ",", "uvB", ",", "uvC", ")", ";", "this", ".", "faces", ".", "push", "(", "f", ")", ";", "}", "return", "this", ";", "}" ]
add a Face to the mesh @param {Vec3D} a @param {Vec3D} b @param {Vec3D} c @param {Vec3D} [n] the normal @param {Vec2D} [uvA] @param {Vec2D} [uvB] @param {Vec2D} [uvC] @returns itself
[ "add", "a", "Face", "to", "the", "mesh" ]
3712b44242128245084f18cbad7f0dfa0fc41d9b
https://github.com/hapticdata/toxiclibsjs/blob/3712b44242128245084f18cbad7f0dfa0fc41d9b/lib/toxi/geom/mesh/meshCommon.js#L64-L93
19,346
hapticdata/toxiclibsjs
lib/toxi/geom/mesh/meshCommon.js
function(m){ var l = m.getFaces().length; for(var i=0;i<l;i++){ var f = m.getFaces()[i]; this.addFace(f.a,f.b,f.c); } return this; }
javascript
function(m){ var l = m.getFaces().length; for(var i=0;i<l;i++){ var f = m.getFaces()[i]; this.addFace(f.a,f.b,f.c); } return this; }
[ "function", "(", "m", ")", "{", "var", "l", "=", "m", ".", "getFaces", "(", ")", ".", "length", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "l", ";", "i", "++", ")", "{", "var", "f", "=", "m", ".", "getFaces", "(", ")", "[", "i", "]", ";", "this", ".", "addFace", "(", "f", ".", "a", ",", "f", ".", "b", ",", "f", ".", "c", ")", ";", "}", "return", "this", ";", "}" ]
add the contents of a TriangleMesh to this TriangleMesh @param {TriangleMesh} m @returns itself
[ "add", "the", "contents", "of", "a", "TriangleMesh", "to", "this", "TriangleMesh" ]
3712b44242128245084f18cbad7f0dfa0fc41d9b
https://github.com/hapticdata/toxiclibsjs/blob/3712b44242128245084f18cbad7f0dfa0fc41d9b/lib/toxi/geom/mesh/meshCommon.js#L100-L107
19,347
hapticdata/toxiclibsjs
lib/toxi/geom/mesh/meshCommon.js
function(array) { array = array || []; var i = 0; var l = this.vertices.length; for (var j=0;j<l;j++) { var v = this.vertices[j]; array[i++] = v.x; array[i++] = v.y; array[i++] = v.z; } return array; }
javascript
function(array) { array = array || []; var i = 0; var l = this.vertices.length; for (var j=0;j<l;j++) { var v = this.vertices[j]; array[i++] = v.x; array[i++] = v.y; array[i++] = v.z; } return array; }
[ "function", "(", "array", ")", "{", "array", "=", "array", "||", "[", "]", ";", "var", "i", "=", "0", ";", "var", "l", "=", "this", ".", "vertices", ".", "length", ";", "for", "(", "var", "j", "=", "0", ";", "j", "<", "l", ";", "j", "++", ")", "{", "var", "v", "=", "this", ".", "vertices", "[", "j", "]", ";", "array", "[", "i", "++", "]", "=", "v", ".", "x", ";", "array", "[", "i", "++", "]", "=", "v", ".", "y", ";", "array", "[", "i", "++", "]", "=", "v", ".", "z", ";", "}", "return", "array", ";", "}" ]
flatten each vertex once into an array, useful for OpenGL attributes @param {Array|Float32Array} [array] optionally pass in an array or typed-array to reuse @return {Array|Float32Array}
[ "flatten", "each", "vertex", "once", "into", "an", "array", "useful", "for", "OpenGL", "attributes" ]
3712b44242128245084f18cbad7f0dfa0fc41d9b
https://github.com/hapticdata/toxiclibsjs/blob/3712b44242128245084f18cbad7f0dfa0fc41d9b/lib/toxi/geom/mesh/meshCommon.js#L472-L483
19,348
hapticdata/toxiclibsjs
lib/toxi/geom/mesh/meshCommon.js
function(array){ array = array || []; var n = 0; for(i=0; i<this.vertices.length; i++){ var v = this.vertices[i]; array[n++] = v.normal.x; array[n++] = v.normal.y; array[n++] = v.normal.z; } return array; }
javascript
function(array){ array = array || []; var n = 0; for(i=0; i<this.vertices.length; i++){ var v = this.vertices[i]; array[n++] = v.normal.x; array[n++] = v.normal.y; array[n++] = v.normal.z; } return array; }
[ "function", "(", "array", ")", "{", "array", "=", "array", "||", "[", "]", ";", "var", "n", "=", "0", ";", "for", "(", "i", "=", "0", ";", "i", "<", "this", ".", "vertices", ".", "length", ";", "i", "++", ")", "{", "var", "v", "=", "this", ".", "vertices", "[", "i", "]", ";", "array", "[", "n", "++", "]", "=", "v", ".", "normal", ".", "x", ";", "array", "[", "n", "++", "]", "=", "v", ".", "normal", ".", "y", ";", "array", "[", "n", "++", "]", "=", "v", ".", "normal", ".", "z", ";", "}", "return", "array", ";", "}" ]
flatten each vertex normal once into an array, useful for OpenGL attributes @param {Array|Float32Array} [array] optionally pass in an array or typed-array to reuse @return {Array|Float32Array}
[ "flatten", "each", "vertex", "normal", "once", "into", "an", "array", "useful", "for", "OpenGL", "attributes" ]
3712b44242128245084f18cbad7f0dfa0fc41d9b
https://github.com/hapticdata/toxiclibsjs/blob/3712b44242128245084f18cbad7f0dfa0fc41d9b/lib/toxi/geom/mesh/meshCommon.js#L490-L501
19,349
hapticdata/toxiclibsjs
lib/toxi/geom/mesh/meshCommon.js
function(array){ array = array || []; var i = 0; for(f=0; f<this.faces.length; f++){ var face = this.faces[f]; array[i++] = face.uvA ? face.uvA.x : 0; array[i++] = face.uvA ? face.uvA.y : 0; array[i++] = face.uvB ? face.uvB.x : 0; array[i++] = face.uvB ? face.uvB.y : 0; array[i++] = face.uvC ? face.uvC.x : 0; array[i++] = face.uvC ? face.uvC.y : 0; } return array; }
javascript
function(array){ array = array || []; var i = 0; for(f=0; f<this.faces.length; f++){ var face = this.faces[f]; array[i++] = face.uvA ? face.uvA.x : 0; array[i++] = face.uvA ? face.uvA.y : 0; array[i++] = face.uvB ? face.uvB.x : 0; array[i++] = face.uvB ? face.uvB.y : 0; array[i++] = face.uvC ? face.uvC.x : 0; array[i++] = face.uvC ? face.uvC.y : 0; } return array; }
[ "function", "(", "array", ")", "{", "array", "=", "array", "||", "[", "]", ";", "var", "i", "=", "0", ";", "for", "(", "f", "=", "0", ";", "f", "<", "this", ".", "faces", ".", "length", ";", "f", "++", ")", "{", "var", "face", "=", "this", ".", "faces", "[", "f", "]", ";", "array", "[", "i", "++", "]", "=", "face", ".", "uvA", "?", "face", ".", "uvA", ".", "x", ":", "0", ";", "array", "[", "i", "++", "]", "=", "face", ".", "uvA", "?", "face", ".", "uvA", ".", "y", ":", "0", ";", "array", "[", "i", "++", "]", "=", "face", ".", "uvB", "?", "face", ".", "uvB", ".", "x", ":", "0", ";", "array", "[", "i", "++", "]", "=", "face", ".", "uvB", "?", "face", ".", "uvB", ".", "y", ":", "0", ";", "array", "[", "i", "++", "]", "=", "face", ".", "uvC", "?", "face", ".", "uvC", ".", "x", ":", "0", ";", "array", "[", "i", "++", "]", "=", "face", ".", "uvC", "?", "face", ".", "uvC", ".", "y", ":", "0", ";", "}", "return", "array", ";", "}" ]
get the UVs of all faces in flattened array that is, usefl for OpenGL attributes any missing UV coordinates are returned as 0 @param {Array|Float32Array} [array] optionally pass in an array or typed-array to reuse @return {Array|Float32Array}
[ "get", "the", "UVs", "of", "all", "faces", "in", "flattened", "array", "that", "is", "usefl", "for", "OpenGL", "attributes", "any", "missing", "UV", "coordinates", "are", "returned", "as", "0" ]
3712b44242128245084f18cbad7f0dfa0fc41d9b
https://github.com/hapticdata/toxiclibsjs/blob/3712b44242128245084f18cbad7f0dfa0fc41d9b/lib/toxi/geom/mesh/meshCommon.js#L509-L523
19,350
hapticdata/toxiclibsjs
lib/toxi/geom/mesh/meshCommon.js
function(vec) { var matchedVertex = -1; var l = this.vertices.length; for(var i=0;i<l;i++) { var vert = this.vertices[i]; if(vert.equals(vec)) { matchedVertex =i; } } return matchedVertex; }
javascript
function(vec) { var matchedVertex = -1; var l = this.vertices.length; for(var i=0;i<l;i++) { var vert = this.vertices[i]; if(vert.equals(vec)) { matchedVertex =i; } } return matchedVertex; }
[ "function", "(", "vec", ")", "{", "var", "matchedVertex", "=", "-", "1", ";", "var", "l", "=", "this", ".", "vertices", ".", "length", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "l", ";", "i", "++", ")", "{", "var", "vert", "=", "this", ".", "vertices", "[", "i", "]", ";", "if", "(", "vert", ".", "equals", "(", "vec", ")", ")", "{", "matchedVertex", "=", "i", ";", "}", "}", "return", "matchedVertex", ";", "}" ]
my own method to help
[ "my", "own", "method", "to", "help" ]
3712b44242128245084f18cbad7f0dfa0fc41d9b
https://github.com/hapticdata/toxiclibsjs/blob/3712b44242128245084f18cbad7f0dfa0fc41d9b/lib/toxi/geom/mesh/meshCommon.js#L535-L548
19,351
hapticdata/toxiclibsjs
lib/toxi/geom/mesh/meshCommon.js
function(dir, forward) { forward = forward || Vec3D.Z_AXIS; return this.transform( Quaternion.getAlignmentQuat(dir, forward).toMatrix4x4(this.matrix), true); }
javascript
function(dir, forward) { forward = forward || Vec3D.Z_AXIS; return this.transform( Quaternion.getAlignmentQuat(dir, forward).toMatrix4x4(this.matrix), true); }
[ "function", "(", "dir", ",", "forward", ")", "{", "forward", "=", "forward", "||", "Vec3D", ".", "Z_AXIS", ";", "return", "this", ".", "transform", "(", "Quaternion", ".", "getAlignmentQuat", "(", "dir", ",", "forward", ")", ".", "toMatrix4x4", "(", "this", ".", "matrix", ")", ",", "true", ")", ";", "}" ]
Rotates the mesh in such a way so that its "forward" axis is aligned with the given direction. This version uses the positive Z-axis as default forward direction. @param dir, new target direction to point in @param [forward], optional vector, defaults to Vec3D.Z_AXIS @return itself
[ "Rotates", "the", "mesh", "in", "such", "a", "way", "so", "that", "its", "forward", "axis", "is", "aligned", "with", "the", "given", "direction", ".", "This", "version", "uses", "the", "positive", "Z", "-", "axis", "as", "default", "forward", "direction", "." ]
3712b44242128245084f18cbad7f0dfa0fc41d9b
https://github.com/hapticdata/toxiclibsjs/blob/3712b44242128245084f18cbad7f0dfa0fc41d9b/lib/toxi/geom/mesh/meshCommon.js#L680-L683
19,352
hapticdata/toxiclibsjs
lib/toxi/geom/mesh/meshCommon.js
function(mat,updateNormals) { if(updateNormals === undefined){ updateNormals = true; } var l = this.vertices.length; for(var i=0;i<l;i++){ var v = this.vertices[i]; v.set(mat.applyTo(v)); } if(updateNormals){ this.computeFaceNormals(); } return this; }
javascript
function(mat,updateNormals) { if(updateNormals === undefined){ updateNormals = true; } var l = this.vertices.length; for(var i=0;i<l;i++){ var v = this.vertices[i]; v.set(mat.applyTo(v)); } if(updateNormals){ this.computeFaceNormals(); } return this; }
[ "function", "(", "mat", ",", "updateNormals", ")", "{", "if", "(", "updateNormals", "===", "undefined", ")", "{", "updateNormals", "=", "true", ";", "}", "var", "l", "=", "this", ".", "vertices", ".", "length", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "l", ";", "i", "++", ")", "{", "var", "v", "=", "this", ".", "vertices", "[", "i", "]", ";", "v", ".", "set", "(", "mat", ".", "applyTo", "(", "v", ")", ")", ";", "}", "if", "(", "updateNormals", ")", "{", "this", ".", "computeFaceNormals", "(", ")", ";", "}", "return", "this", ";", "}" ]
Applies the given matrix transform to all mesh vertices. If the updateNormals flag is true, all face normals are updated automatically, however vertex normals need a manual update. @param mat @param updateNormals @return itself
[ "Applies", "the", "given", "matrix", "transform", "to", "all", "mesh", "vertices", ".", "If", "the", "updateNormals", "flag", "is", "true", "all", "face", "normals", "are", "updated", "automatically", "however", "vertex", "normals", "need", "a", "manual", "update", "." ]
3712b44242128245084f18cbad7f0dfa0fc41d9b
https://github.com/hapticdata/toxiclibsjs/blob/3712b44242128245084f18cbad7f0dfa0fc41d9b/lib/toxi/geom/mesh/meshCommon.js#L778-L791
19,353
hapticdata/toxiclibsjs
lib/toxi/geom/mesh/meshCommon.js
function(elevation){ if(this.__elevationLength == elevation.length){ for(var i = 0, len = elevation.length; i<len; i++){ this.vertices[i].y = this.elevation[i] = elevation[i]; } } else { throw new Error("the given elevation array size does not match terrain"); } return this; }
javascript
function(elevation){ if(this.__elevationLength == elevation.length){ for(var i = 0, len = elevation.length; i<len; i++){ this.vertices[i].y = this.elevation[i] = elevation[i]; } } else { throw new Error("the given elevation array size does not match terrain"); } return this; }
[ "function", "(", "elevation", ")", "{", "if", "(", "this", ".", "__elevationLength", "==", "elevation", ".", "length", ")", "{", "for", "(", "var", "i", "=", "0", ",", "len", "=", "elevation", ".", "length", ";", "i", "<", "len", ";", "i", "++", ")", "{", "this", ".", "vertices", "[", "i", "]", ".", "y", "=", "this", ".", "elevation", "[", "i", "]", "=", "elevation", "[", "i", "]", ";", "}", "}", "else", "{", "throw", "new", "Error", "(", "\"the given elevation array size does not match terrain\"", ")", ";", "}", "return", "this", ";", "}" ]
Sets the elevation of all cells to those of the given array values. @param {Array} elevation array of height values @return itself
[ "Sets", "the", "elevation", "of", "all", "cells", "to", "those", "of", "the", "given", "array", "values", "." ]
3712b44242128245084f18cbad7f0dfa0fc41d9b
https://github.com/hapticdata/toxiclibsjs/blob/3712b44242128245084f18cbad7f0dfa0fc41d9b/lib/toxi/geom/mesh/meshCommon.js#L1315-L1324
19,354
hapticdata/toxiclibsjs
lib/toxi/geom/mesh/meshCommon.js
function(x,z,h){ var index = this._getIndex(x,z); this.elevation[index] = h; this.vertices[index].y = h; return this; }
javascript
function(x,z,h){ var index = this._getIndex(x,z); this.elevation[index] = h; this.vertices[index].y = h; return this; }
[ "function", "(", "x", ",", "z", ",", "h", ")", "{", "var", "index", "=", "this", ".", "_getIndex", "(", "x", ",", "z", ")", ";", "this", ".", "elevation", "[", "index", "]", "=", "h", ";", "this", ".", "vertices", "[", "index", "]", ".", "y", "=", "h", ";", "return", "this", ";", "}" ]
Sets the elevation for a single given grid cell. @param {Number} x @param {Number} z @param {Number} h new elevation value @return itself
[ "Sets", "the", "elevation", "for", "a", "single", "given", "grid", "cell", "." ]
3712b44242128245084f18cbad7f0dfa0fc41d9b
https://github.com/hapticdata/toxiclibsjs/blob/3712b44242128245084f18cbad7f0dfa0fc41d9b/lib/toxi/geom/mesh/meshCommon.js#L1332-L1337
19,355
hapticdata/toxiclibsjs
lib/toxi/color/theory/AnalagousStrategy.js
function( theta, contrast ){ this.contrast = typeof contrast === 'number' ? contrast : 0.25; this.theta = MathUtils.radians( typeof theta === 'number' ? theta : 10 ); }
javascript
function( theta, contrast ){ this.contrast = typeof contrast === 'number' ? contrast : 0.25; this.theta = MathUtils.radians( typeof theta === 'number' ? theta : 10 ); }
[ "function", "(", "theta", ",", "contrast", ")", "{", "this", ".", "contrast", "=", "typeof", "contrast", "===", "'number'", "?", "contrast", ":", "0.25", ";", "this", ".", "theta", "=", "MathUtils", ".", "radians", "(", "typeof", "theta", "===", "'number'", "?", "theta", ":", "10", ")", ";", "}" ]
Creates a new instance @param {Number} [theta] optionally provide an angle in degrees, defaults to 10 @param {Number} [contrast] optionally provide a contrast, defaults to 0.25
[ "Creates", "a", "new", "instance" ]
3712b44242128245084f18cbad7f0dfa0fc41d9b
https://github.com/hapticdata/toxiclibsjs/blob/3712b44242128245084f18cbad7f0dfa0fc41d9b/lib/toxi/color/theory/AnalagousStrategy.js#L25-L28
19,356
hapticdata/toxiclibsjs
lib/toxi/geom/AxisAlignedCylinder.js
function(a,b,c) { var opts = { mesh: undefined, steps: 12, thetaOffset: 0 }; if(arguments.length == 1 && typeof arguments[0] == 'object'){ //options object for(var prop in arguments[0]){ opts[prop] = arguments[0][prop]; } } else if(arguments.length == 2){ opts.steps = arguments[0]; opts.thetaOffset = arguments[1]; } var cone = new Cone(this.pos,this.getMajorAxis().getVector(), this.radius, this.radius, this.length); return cone.toMesh(opts.mesh,opts.steps,opts.thetaOffset,true,true); }
javascript
function(a,b,c) { var opts = { mesh: undefined, steps: 12, thetaOffset: 0 }; if(arguments.length == 1 && typeof arguments[0] == 'object'){ //options object for(var prop in arguments[0]){ opts[prop] = arguments[0][prop]; } } else if(arguments.length == 2){ opts.steps = arguments[0]; opts.thetaOffset = arguments[1]; } var cone = new Cone(this.pos,this.getMajorAxis().getVector(), this.radius, this.radius, this.length); return cone.toMesh(opts.mesh,opts.steps,opts.thetaOffset,true,true); }
[ "function", "(", "a", ",", "b", ",", "c", ")", "{", "var", "opts", "=", "{", "mesh", ":", "undefined", ",", "steps", ":", "12", ",", "thetaOffset", ":", "0", "}", ";", "if", "(", "arguments", ".", "length", "==", "1", "&&", "typeof", "arguments", "[", "0", "]", "==", "'object'", ")", "{", "//options object", "for", "(", "var", "prop", "in", "arguments", "[", "0", "]", ")", "{", "opts", "[", "prop", "]", "=", "arguments", "[", "0", "]", "[", "prop", "]", ";", "}", "}", "else", "if", "(", "arguments", ".", "length", "==", "2", ")", "{", "opts", ".", "steps", "=", "arguments", "[", "0", "]", ";", "opts", ".", "thetaOffset", "=", "arguments", "[", "1", "]", ";", "}", "var", "cone", "=", "new", "Cone", "(", "this", ".", "pos", ",", "this", ".", "getMajorAxis", "(", ")", ".", "getVector", "(", ")", ",", "this", ".", "radius", ",", "this", ".", "radius", ",", "this", ".", "length", ")", ";", "return", "cone", ".", "toMesh", "(", "opts", ".", "mesh", ",", "opts", ".", "steps", ",", "opts", ".", "thetaOffset", ",", "true", ",", "true", ")", ";", "}" ]
Builds a TriangleMesh representation of the cylinder at a default resolution 30 degrees. @return mesh instance
[ "Builds", "a", "TriangleMesh", "representation", "of", "the", "cylinder", "at", "a", "default", "resolution", "30", "degrees", "." ]
3712b44242128245084f18cbad7f0dfa0fc41d9b
https://github.com/hapticdata/toxiclibsjs/blob/3712b44242128245084f18cbad7f0dfa0fc41d9b/lib/toxi/geom/AxisAlignedCylinder.js#L79-L95
19,357
hapticdata/toxiclibsjs
lib/toxi/math/SinCosLUT.js
function(theta) { while (theta < 0) { theta += mathUtils.TWO_PI; } return this.sinLUT[((theta * this.rad2deg) + this.quadrant) % this.period]; }
javascript
function(theta) { while (theta < 0) { theta += mathUtils.TWO_PI; } return this.sinLUT[((theta * this.rad2deg) + this.quadrant) % this.period]; }
[ "function", "(", "theta", ")", "{", "while", "(", "theta", "<", "0", ")", "{", "theta", "+=", "mathUtils", ".", "TWO_PI", ";", "}", "return", "this", ".", "sinLUT", "[", "(", "(", "theta", "*", "this", ".", "rad2deg", ")", "+", "this", ".", "quadrant", ")", "%", "this", ".", "period", "]", ";", "}" ]
Calculate cosine for the passed in angle in radians. @param theta @return cosine value for theta
[ "Calculate", "cosine", "for", "the", "passed", "in", "angle", "in", "radians", "." ]
3712b44242128245084f18cbad7f0dfa0fc41d9b
https://github.com/hapticdata/toxiclibsjs/blob/3712b44242128245084f18cbad7f0dfa0fc41d9b/lib/toxi/math/SinCosLUT.js#L37-L42
19,358
hapticdata/toxiclibsjs
lib/toxi/geom/LineStrip3D.js
function( x, y, z ){ if( hasXYZ( x ) ){ //it was 1 param, it was a vector or object this.vertices.push( new Vec3D(x) ); } else { this.vertices.push( new Vec3D(x,y,z) ); } return this; }
javascript
function( x, y, z ){ if( hasXYZ( x ) ){ //it was 1 param, it was a vector or object this.vertices.push( new Vec3D(x) ); } else { this.vertices.push( new Vec3D(x,y,z) ); } return this; }
[ "function", "(", "x", ",", "y", ",", "z", ")", "{", "if", "(", "hasXYZ", "(", "x", ")", ")", "{", "//it was 1 param, it was a vector or object", "this", ".", "vertices", ".", "push", "(", "new", "Vec3D", "(", "x", ")", ")", ";", "}", "else", "{", "this", ".", "vertices", ".", "push", "(", "new", "Vec3D", "(", "x", ",", "y", ",", "z", ")", ")", ";", "}", "return", "this", ";", "}" ]
add a vector to the line-strip, it will always be a copy @param {Vec3D | Number } x either a Vec3D or an x coordinate @param {Number} [y] @param {Number} [z] @return itself
[ "add", "a", "vector", "to", "the", "line", "-", "strip", "it", "will", "always", "be", "a", "copy" ]
3712b44242128245084f18cbad7f0dfa0fc41d9b
https://github.com/hapticdata/toxiclibsjs/blob/3712b44242128245084f18cbad7f0dfa0fc41d9b/lib/toxi/geom/LineStrip3D.js#L34-L42
19,359
hapticdata/toxiclibsjs
lib/toxi/geom/LineStrip3D.js
function( step, doAddFinalVertex ){ if( doAddFinalVertex !== false ){ doAddFinalVertex = true; } var uniform = []; if( this.vertices.length < 3 ){ if( this.vertices.length === 2 ){ new Line3D( this.vertices[0], this.vertices[1]) .splitIntoSegments( uniform, step, true ); if( !doAddFinalVertex ){ uniform.pop(); } } else { return; } } var arcLen = this.getEstimatedArcLength(), delta = step / arcLen, currIdx = 0, currT, t, p, q, frac, i; for( t = 0; t<1.0; t+=delta ){ currT = t * arcLen; while( currT >= this.arcLenIndex[currIdx] ){ currIdx++; } p = this.get(currIdx-1); q = this.get(currIdx); frac = ((currT-this.arcLenIndex[currIdx-1]) / (this.arcLenIndex[currIdx] - this.arcLenIndex[currIdx-1]) ); i = p.interpolateTo( q, frac ); uniform.push( i ); } if( doAddFinalVertex ){ uniform.push( this.get(-1).copy() ); } return uniform; }
javascript
function( step, doAddFinalVertex ){ if( doAddFinalVertex !== false ){ doAddFinalVertex = true; } var uniform = []; if( this.vertices.length < 3 ){ if( this.vertices.length === 2 ){ new Line3D( this.vertices[0], this.vertices[1]) .splitIntoSegments( uniform, step, true ); if( !doAddFinalVertex ){ uniform.pop(); } } else { return; } } var arcLen = this.getEstimatedArcLength(), delta = step / arcLen, currIdx = 0, currT, t, p, q, frac, i; for( t = 0; t<1.0; t+=delta ){ currT = t * arcLen; while( currT >= this.arcLenIndex[currIdx] ){ currIdx++; } p = this.get(currIdx-1); q = this.get(currIdx); frac = ((currT-this.arcLenIndex[currIdx-1]) / (this.arcLenIndex[currIdx] - this.arcLenIndex[currIdx-1]) ); i = p.interpolateTo( q, frac ); uniform.push( i ); } if( doAddFinalVertex ){ uniform.push( this.get(-1).copy() ); } return uniform; }
[ "function", "(", "step", ",", "doAddFinalVertex", ")", "{", "if", "(", "doAddFinalVertex", "!==", "false", ")", "{", "doAddFinalVertex", "=", "true", ";", "}", "var", "uniform", "=", "[", "]", ";", "if", "(", "this", ".", "vertices", ".", "length", "<", "3", ")", "{", "if", "(", "this", ".", "vertices", ".", "length", "===", "2", ")", "{", "new", "Line3D", "(", "this", ".", "vertices", "[", "0", "]", ",", "this", ".", "vertices", "[", "1", "]", ")", ".", "splitIntoSegments", "(", "uniform", ",", "step", ",", "true", ")", ";", "if", "(", "!", "doAddFinalVertex", ")", "{", "uniform", ".", "pop", "(", ")", ";", "}", "}", "else", "{", "return", ";", "}", "}", "var", "arcLen", "=", "this", ".", "getEstimatedArcLength", "(", ")", ",", "delta", "=", "step", "/", "arcLen", ",", "currIdx", "=", "0", ",", "currT", ",", "t", ",", "p", ",", "q", ",", "frac", ",", "i", ";", "for", "(", "t", "=", "0", ";", "t", "<", "1.0", ";", "t", "+=", "delta", ")", "{", "currT", "=", "t", "*", "arcLen", ";", "while", "(", "currT", ">=", "this", ".", "arcLenIndex", "[", "currIdx", "]", ")", "{", "currIdx", "++", ";", "}", "p", "=", "this", ".", "get", "(", "currIdx", "-", "1", ")", ";", "q", "=", "this", ".", "get", "(", "currIdx", ")", ";", "frac", "=", "(", "(", "currT", "-", "this", ".", "arcLenIndex", "[", "currIdx", "-", "1", "]", ")", "/", "(", "this", ".", "arcLenIndex", "[", "currIdx", "]", "-", "this", ".", "arcLenIndex", "[", "currIdx", "-", "1", "]", ")", ")", ";", "i", "=", "p", ".", "interpolateTo", "(", "q", ",", "frac", ")", ";", "uniform", ".", "push", "(", "i", ")", ";", "}", "if", "(", "doAddFinalVertex", ")", "{", "uniform", ".", "push", "(", "this", ".", "get", "(", "-", "1", ")", ".", "copy", "(", ")", ")", ";", "}", "return", "uniform", ";", "}" ]
Computes a list of points along the spline which are uniformly separated by the given step distance. @param {Number} step @param {Boolean} [doAddFinalVertex] true by default @return {Vec3D[]} point list
[ "Computes", "a", "list", "of", "points", "along", "the", "spline", "which", "are", "uniformly", "separated", "by", "the", "given", "step", "distance", "." ]
3712b44242128245084f18cbad7f0dfa0fc41d9b
https://github.com/hapticdata/toxiclibsjs/blob/3712b44242128245084f18cbad7f0dfa0fc41d9b/lib/toxi/geom/LineStrip3D.js#L57-L98
19,360
hapticdata/toxiclibsjs
lib/toxi/geom/mesh/SphericalHarmonics.js
function(p,phi,theta) { var r = 0; r += Math.pow(mathUtils.sin(this.m[0] * theta), this.m[1]); r += Math.pow(mathUtils.cos(this.m[2] * theta), this.m[3]); r += Math.pow(mathUtils.sin(this.m[4] * phi), this.m[5]); r += Math.pow(mathUtils.cos(this.m[6] * phi), this.m[7]); var sinTheta = mathUtils.sin(theta); p.x = r * sinTheta * mathUtils.cos(phi); p.y = r * mathUtils.cos(theta); p.z = r * sinTheta * mathUtils.sin(phi); return p; }
javascript
function(p,phi,theta) { var r = 0; r += Math.pow(mathUtils.sin(this.m[0] * theta), this.m[1]); r += Math.pow(mathUtils.cos(this.m[2] * theta), this.m[3]); r += Math.pow(mathUtils.sin(this.m[4] * phi), this.m[5]); r += Math.pow(mathUtils.cos(this.m[6] * phi), this.m[7]); var sinTheta = mathUtils.sin(theta); p.x = r * sinTheta * mathUtils.cos(phi); p.y = r * mathUtils.cos(theta); p.z = r * sinTheta * mathUtils.sin(phi); return p; }
[ "function", "(", "p", ",", "phi", ",", "theta", ")", "{", "var", "r", "=", "0", ";", "r", "+=", "Math", ".", "pow", "(", "mathUtils", ".", "sin", "(", "this", ".", "m", "[", "0", "]", "*", "theta", ")", ",", "this", ".", "m", "[", "1", "]", ")", ";", "r", "+=", "Math", ".", "pow", "(", "mathUtils", ".", "cos", "(", "this", ".", "m", "[", "2", "]", "*", "theta", ")", ",", "this", ".", "m", "[", "3", "]", ")", ";", "r", "+=", "Math", ".", "pow", "(", "mathUtils", ".", "sin", "(", "this", ".", "m", "[", "4", "]", "*", "phi", ")", ",", "this", ".", "m", "[", "5", "]", ")", ";", "r", "+=", "Math", ".", "pow", "(", "mathUtils", ".", "cos", "(", "this", ".", "m", "[", "6", "]", "*", "phi", ")", ",", "this", ".", "m", "[", "7", "]", ")", ";", "var", "sinTheta", "=", "mathUtils", ".", "sin", "(", "theta", ")", ";", "p", ".", "x", "=", "r", "*", "sinTheta", "*", "mathUtils", ".", "cos", "(", "phi", ")", ";", "p", ".", "y", "=", "r", "*", "mathUtils", ".", "cos", "(", "theta", ")", ";", "p", ".", "z", "=", "r", "*", "sinTheta", "*", "mathUtils", ".", "sin", "(", "phi", ")", ";", "return", "p", ";", "}" ]
toxiclibs - FIXME check where flipped vertex order is coming from sometimes
[ "toxiclibs", "-", "FIXME", "check", "where", "flipped", "vertex", "order", "is", "coming", "from", "sometimes" ]
3712b44242128245084f18cbad7f0dfa0fc41d9b
https://github.com/hapticdata/toxiclibsjs/blob/3712b44242128245084f18cbad7f0dfa0fc41d9b/lib/toxi/geom/mesh/SphericalHarmonics.js#L16-L28
19,361
hapticdata/toxiclibsjs
lib/toxi/color/TColor.js
function(h, s, v) { return this.setHSV([ this.hsv[0] + h, this.hsv[1] + s, this.hsv[2] + v ]); }
javascript
function(h, s, v) { return this.setHSV([ this.hsv[0] + h, this.hsv[1] + s, this.hsv[2] + v ]); }
[ "function", "(", "h", ",", "s", ",", "v", ")", "{", "return", "this", ".", "setHSV", "(", "[", "this", ".", "hsv", "[", "0", "]", "+", "h", ",", "this", ".", "hsv", "[", "1", "]", "+", "s", ",", "this", ".", "hsv", "[", "2", "]", "+", "v", "]", ")", ";", "}" ]
Adds the given HSV values as offsets to the current color. Hue will automatically wrap. @param h @param s @param v @return itself
[ "Adds", "the", "given", "HSV", "values", "as", "offsets", "to", "the", "current", "color", ".", "Hue", "will", "automatically", "wrap", "." ]
3712b44242128245084f18cbad7f0dfa0fc41d9b
https://github.com/hapticdata/toxiclibsjs/blob/3712b44242128245084f18cbad7f0dfa0fc41d9b/lib/toxi/color/TColor.js#L83-L85
19,362
hapticdata/toxiclibsjs
lib/toxi/color/TColor.js
function(r, g,b) { return this.setRGB([this.rgb[0] + r, this.rgb[1] + g, this.rgb[2] + b]); }
javascript
function(r, g,b) { return this.setRGB([this.rgb[0] + r, this.rgb[1] + g, this.rgb[2] + b]); }
[ "function", "(", "r", ",", "g", ",", "b", ")", "{", "return", "this", ".", "setRGB", "(", "[", "this", ".", "rgb", "[", "0", "]", "+", "r", ",", "this", ".", "rgb", "[", "1", "]", "+", "g", ",", "this", ".", "rgb", "[", "2", "]", "+", "b", "]", ")", ";", "}" ]
Adds the given RGB values as offsets to the current color. TColor will clip at black or white. @param r @param g @param b @return itself
[ "Adds", "the", "given", "RGB", "values", "as", "offsets", "to", "the", "current", "color", ".", "TColor", "will", "clip", "at", "black", "or", "white", "." ]
3712b44242128245084f18cbad7f0dfa0fc41d9b
https://github.com/hapticdata/toxiclibsjs/blob/3712b44242128245084f18cbad7f0dfa0fc41d9b/lib/toxi/color/TColor.js#L95-L97
19,363
hapticdata/toxiclibsjs
lib/toxi/color/TColor.js
function(c, t) { if(t === undefined) { t = 0.5; } var crgb = c.toRGBAArray(); this.rgb[0] += (crgb[0] - this.rgb[0]) * t; this.rgb[1] += (crgb[1] - this.rgb[1]) * t; this.rgb[2] += (crgb[2] - this.rgb[2]) * t; this._alpha += (c._alpha - this._alpha) * t; return this.setRGB(this.rgb); }
javascript
function(c, t) { if(t === undefined) { t = 0.5; } var crgb = c.toRGBAArray(); this.rgb[0] += (crgb[0] - this.rgb[0]) * t; this.rgb[1] += (crgb[1] - this.rgb[1]) * t; this.rgb[2] += (crgb[2] - this.rgb[2]) * t; this._alpha += (c._alpha - this._alpha) * t; return this.setRGB(this.rgb); }
[ "function", "(", "c", ",", "t", ")", "{", "if", "(", "t", "===", "undefined", ")", "{", "t", "=", "0.5", ";", "}", "var", "crgb", "=", "c", ".", "toRGBAArray", "(", ")", ";", "this", ".", "rgb", "[", "0", "]", "+=", "(", "crgb", "[", "0", "]", "-", "this", ".", "rgb", "[", "0", "]", ")", "*", "t", ";", "this", ".", "rgb", "[", "1", "]", "+=", "(", "crgb", "[", "1", "]", "-", "this", ".", "rgb", "[", "1", "]", ")", "*", "t", ";", "this", ".", "rgb", "[", "2", "]", "+=", "(", "crgb", "[", "2", "]", "-", "this", ".", "rgb", "[", "2", "]", ")", "*", "t", ";", "this", ".", "_alpha", "+=", "(", "c", ".", "_alpha", "-", "this", ".", "_alpha", ")", "*", "t", ";", "return", "this", ".", "setRGB", "(", "this", ".", "rgb", ")", ";", "}" ]
Blends the color with the given one by the stated amount @param c target color @param t interpolation factor @return itself
[ "Blends", "the", "color", "with", "the", "given", "one", "by", "the", "stated", "amount" ]
3712b44242128245084f18cbad7f0dfa0fc41d9b
https://github.com/hapticdata/toxiclibsjs/blob/3712b44242128245084f18cbad7f0dfa0fc41d9b/lib/toxi/color/TColor.js#L133-L141
19,364
hapticdata/toxiclibsjs
lib/toxi/color/TColor.js
function(rgba, offset) { rgba = rgba || []; offset = offset || 0; rgba[offset++] = this.rgb[0]; rgba[offset++] = this.rgb[1]; rgba[offset++] = this.rgb[2]; rgba[offset] = this._alpha; return rgba; }
javascript
function(rgba, offset) { rgba = rgba || []; offset = offset || 0; rgba[offset++] = this.rgb[0]; rgba[offset++] = this.rgb[1]; rgba[offset++] = this.rgb[2]; rgba[offset] = this._alpha; return rgba; }
[ "function", "(", "rgba", ",", "offset", ")", "{", "rgba", "=", "rgba", "||", "[", "]", ";", "offset", "=", "offset", "||", "0", ";", "rgba", "[", "offset", "++", "]", "=", "this", ".", "rgb", "[", "0", "]", ";", "rgba", "[", "offset", "++", "]", "=", "this", ".", "rgb", "[", "1", "]", ";", "rgba", "[", "offset", "++", "]", "=", "this", ".", "rgb", "[", "2", "]", ";", "rgba", "[", "offset", "]", "=", "this", ".", "_alpha", ";", "return", "rgba", ";", "}" ]
to an Array of RGBA values @param rgba @param offset (optional) @return rgba array
[ "to", "an", "Array", "of", "RGBA", "values" ]
3712b44242128245084f18cbad7f0dfa0fc41d9b
https://github.com/hapticdata/toxiclibsjs/blob/3712b44242128245084f18cbad7f0dfa0fc41d9b/lib/toxi/color/TColor.js#L584-L592
19,365
hapticdata/toxiclibsjs
lib/toxi/color/ColorList.js
function(color){ for( var i=0, l= this.colors.length; i<l; i++){ if( this.colors[i].equals( color ) ){ return true; } } return false; }
javascript
function(color){ for( var i=0, l= this.colors.length; i<l; i++){ if( this.colors[i].equals( color ) ){ return true; } } return false; }
[ "function", "(", "color", ")", "{", "for", "(", "var", "i", "=", "0", ",", "l", "=", "this", ".", "colors", ".", "length", ";", "i", "<", "l", ";", "i", "++", ")", "{", "if", "(", "this", ".", "colors", "[", "i", "]", ".", "equals", "(", "color", ")", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Checks if the given color is part of the list. Check is done by value, not instance. @param color @return true, if the color is present.
[ "Checks", "if", "the", "given", "color", "is", "part", "of", "the", "list", ".", "Check", "is", "done", "by", "value", "not", "instance", "." ]
3712b44242128245084f18cbad7f0dfa0fc41d9b
https://github.com/hapticdata/toxiclibsjs/blob/3712b44242128245084f18cbad7f0dfa0fc41d9b/lib/toxi/color/ColorList.js#L160-L167
19,366
hapticdata/toxiclibsjs
lib/toxi/color/ColorList.js
function(){ var r = 0, g = 0, b = 0, a = 0; this.each(function(c){ r += c.rgb[0]; g += c.rgb[1]; b += c.rgb[2]; a += c.alpha(); }); var num = this.colors.length; if(num > 0){ return TColor.newRGBA(r / num, g / num, b / num, a / num); } return undefined; }
javascript
function(){ var r = 0, g = 0, b = 0, a = 0; this.each(function(c){ r += c.rgb[0]; g += c.rgb[1]; b += c.rgb[2]; a += c.alpha(); }); var num = this.colors.length; if(num > 0){ return TColor.newRGBA(r / num, g / num, b / num, a / num); } return undefined; }
[ "function", "(", ")", "{", "var", "r", "=", "0", ",", "g", "=", "0", ",", "b", "=", "0", ",", "a", "=", "0", ";", "this", ".", "each", "(", "function", "(", "c", ")", "{", "r", "+=", "c", ".", "rgb", "[", "0", "]", ";", "g", "+=", "c", ".", "rgb", "[", "1", "]", ";", "b", "+=", "c", ".", "rgb", "[", "2", "]", ";", "a", "+=", "c", ".", "alpha", "(", ")", ";", "}", ")", ";", "var", "num", "=", "this", ".", "colors", ".", "length", ";", "if", "(", "num", ">", "0", ")", "{", "return", "TColor", ".", "newRGBA", "(", "r", "/", "num", ",", "g", "/", "num", ",", "b", "/", "num", ",", "a", "/", "num", ")", ";", "}", "return", "undefined", ";", "}" ]
Calculates and returns the average color of the list. @return average color or null, if there're no entries yet.
[ "Calculates", "and", "returns", "the", "average", "color", "of", "the", "list", "." ]
3712b44242128245084f18cbad7f0dfa0fc41d9b
https://github.com/hapticdata/toxiclibsjs/blob/3712b44242128245084f18cbad7f0dfa0fc41d9b/lib/toxi/color/ColorList.js#L191-L209
19,367
hapticdata/toxiclibsjs
lib/toxi/color/ColorList.js
function(){ var darkest, minBrightness = Number.MAX_VALUE; this.each(function(c){ var luma = c.luminance(); if(luma < minBrightness){ darkest = c; minBrightness = luma; } }); return darkest; }
javascript
function(){ var darkest, minBrightness = Number.MAX_VALUE; this.each(function(c){ var luma = c.luminance(); if(luma < minBrightness){ darkest = c; minBrightness = luma; } }); return darkest; }
[ "function", "(", ")", "{", "var", "darkest", ",", "minBrightness", "=", "Number", ".", "MAX_VALUE", ";", "this", ".", "each", "(", "function", "(", "c", ")", "{", "var", "luma", "=", "c", ".", "luminance", "(", ")", ";", "if", "(", "luma", "<", "minBrightness", ")", "{", "darkest", "=", "c", ";", "minBrightness", "=", "luma", ";", "}", "}", ")", ";", "return", "darkest", ";", "}" ]
Finds and returns the darkest color of the list. @return darkest color or null if there're no entries yet.
[ "Finds", "and", "returns", "the", "darkest", "color", "of", "the", "list", "." ]
3712b44242128245084f18cbad7f0dfa0fc41d9b
https://github.com/hapticdata/toxiclibsjs/blob/3712b44242128245084f18cbad7f0dfa0fc41d9b/lib/toxi/color/ColorList.js#L231-L242
19,368
hapticdata/toxiclibsjs
lib/toxi/color/ColorList.js
function(comp, isReversed){ //if a normal ( a, b ) sort function instead of an AccessCriteria, //wrap it so it can be invoked the same if( typeof comp === 'function' && typeof comp.compare === 'undefined' ){ comp = { compare: comp }; } this.colors.sort( comp.compare ); if(isReversed){ this.colors.reverse(); } return this; }
javascript
function(comp, isReversed){ //if a normal ( a, b ) sort function instead of an AccessCriteria, //wrap it so it can be invoked the same if( typeof comp === 'function' && typeof comp.compare === 'undefined' ){ comp = { compare: comp }; } this.colors.sort( comp.compare ); if(isReversed){ this.colors.reverse(); } return this; }
[ "function", "(", "comp", ",", "isReversed", ")", "{", "//if a normal ( a, b ) sort function instead of an AccessCriteria,", "//wrap it so it can be invoked the same", "if", "(", "typeof", "comp", "===", "'function'", "&&", "typeof", "comp", ".", "compare", "===", "'undefined'", ")", "{", "comp", "=", "{", "compare", ":", "comp", "}", ";", "}", "this", ".", "colors", ".", "sort", "(", "comp", ".", "compare", ")", ";", "if", "(", "isReversed", ")", "{", "this", ".", "colors", ".", "reverse", "(", ")", ";", "}", "return", "this", ";", "}" ]
Sorts the list using the given comparator. @param comp comparator @param isReversed true, if reversed sort @return itself
[ "Sorts", "the", "list", "using", "the", "given", "comparator", "." ]
3712b44242128245084f18cbad7f0dfa0fc41d9b
https://github.com/hapticdata/toxiclibsjs/blob/3712b44242128245084f18cbad7f0dfa0fc41d9b/lib/toxi/color/ColorList.js#L313-L324
19,369
hapticdata/toxiclibsjs
lib/toxi/color/ColorList.js
function(proxy, isReversed){ if(arguments.length === 1){ isReversed = arguments[0]; proxy = new HSVDistanceProxy(); } if(this.colors.length === 0){ return this; } // Remove the darkest color from the stack, // put it in the sorted list as starting element. var root = this.getDarkest(), stack = this.colors.slice(0), sorted = []; stack.splice(stack.indexOf(root),1); sorted.push(root); // Now find the color in the stack closest to that color. // Take this color from the stack and add it to the sorted list. // Now find the color closest to that color, etc. var sortedCount = 0; while(stack.length > 1){ var closest = stack[0], lastSorted = sorted[sortedCount], distance = proxy.distanceBetween(closest, lastSorted); for(var i = stack.length - 1; i >= 0; i--){ var c = stack[i], d = proxy.distanceBetween(c, lastSorted); if(d < distance){ closest = c; distance = d; } } stack.splice(stack.indexOf(closest),1); sorted.push(closest); sortedCount++; } sorted.push(stack[0]); if(isReversed){ sorted.reverse(); } this.colors = sorted; return this; }
javascript
function(proxy, isReversed){ if(arguments.length === 1){ isReversed = arguments[0]; proxy = new HSVDistanceProxy(); } if(this.colors.length === 0){ return this; } // Remove the darkest color from the stack, // put it in the sorted list as starting element. var root = this.getDarkest(), stack = this.colors.slice(0), sorted = []; stack.splice(stack.indexOf(root),1); sorted.push(root); // Now find the color in the stack closest to that color. // Take this color from the stack and add it to the sorted list. // Now find the color closest to that color, etc. var sortedCount = 0; while(stack.length > 1){ var closest = stack[0], lastSorted = sorted[sortedCount], distance = proxy.distanceBetween(closest, lastSorted); for(var i = stack.length - 1; i >= 0; i--){ var c = stack[i], d = proxy.distanceBetween(c, lastSorted); if(d < distance){ closest = c; distance = d; } } stack.splice(stack.indexOf(closest),1); sorted.push(closest); sortedCount++; } sorted.push(stack[0]); if(isReversed){ sorted.reverse(); } this.colors = sorted; return this; }
[ "function", "(", "proxy", ",", "isReversed", ")", "{", "if", "(", "arguments", ".", "length", "===", "1", ")", "{", "isReversed", "=", "arguments", "[", "0", "]", ";", "proxy", "=", "new", "HSVDistanceProxy", "(", ")", ";", "}", "if", "(", "this", ".", "colors", ".", "length", "===", "0", ")", "{", "return", "this", ";", "}", "// Remove the darkest color from the stack,", "// put it in the sorted list as starting element.", "var", "root", "=", "this", ".", "getDarkest", "(", ")", ",", "stack", "=", "this", ".", "colors", ".", "slice", "(", "0", ")", ",", "sorted", "=", "[", "]", ";", "stack", ".", "splice", "(", "stack", ".", "indexOf", "(", "root", ")", ",", "1", ")", ";", "sorted", ".", "push", "(", "root", ")", ";", "// Now find the color in the stack closest to that color.", "// Take this color from the stack and add it to the sorted list.", "// Now find the color closest to that color, etc.", "var", "sortedCount", "=", "0", ";", "while", "(", "stack", ".", "length", ">", "1", ")", "{", "var", "closest", "=", "stack", "[", "0", "]", ",", "lastSorted", "=", "sorted", "[", "sortedCount", "]", ",", "distance", "=", "proxy", ".", "distanceBetween", "(", "closest", ",", "lastSorted", ")", ";", "for", "(", "var", "i", "=", "stack", ".", "length", "-", "1", ";", "i", ">=", "0", ";", "i", "--", ")", "{", "var", "c", "=", "stack", "[", "i", "]", ",", "d", "=", "proxy", ".", "distanceBetween", "(", "c", ",", "lastSorted", ")", ";", "if", "(", "d", "<", "distance", ")", "{", "closest", "=", "c", ";", "distance", "=", "d", ";", "}", "}", "stack", ".", "splice", "(", "stack", ".", "indexOf", "(", "closest", ")", ",", "1", ")", ";", "sorted", ".", "push", "(", "closest", ")", ";", "sortedCount", "++", ";", "}", "sorted", ".", "push", "(", "stack", "[", "0", "]", ")", ";", "if", "(", "isReversed", ")", "{", "sorted", ".", "reverse", "(", ")", ";", "}", "this", ".", "colors", "=", "sorted", ";", "return", "this", ";", "}" ]
Sorts the list by relative distance to each predecessor, starting with the darkest color in the list. @param {toxi.color.*{DistanceProxy}} proxy @param isReversed true, if list is to be sorted in reverse. @return itself
[ "Sorts", "the", "list", "by", "relative", "distance", "to", "each", "predecessor", "starting", "with", "the", "darkest", "color", "in", "the", "list", "." ]
3712b44242128245084f18cbad7f0dfa0fc41d9b
https://github.com/hapticdata/toxiclibsjs/blob/3712b44242128245084f18cbad7f0dfa0fc41d9b/lib/toxi/color/ColorList.js#L345-L391
19,370
hapticdata/toxiclibsjs
lib/toxi/math/noise/simplexNoise.js
function(g, x, y, z, w) { var n = g[0] * x + g[1] * y; if(z){ n += g[2] * z; if(w){ n += g[3] * w; } } return n; }
javascript
function(g, x, y, z, w) { var n = g[0] * x + g[1] * y; if(z){ n += g[2] * z; if(w){ n += g[3] * w; } } return n; }
[ "function", "(", "g", ",", "x", ",", "y", ",", "z", ",", "w", ")", "{", "var", "n", "=", "g", "[", "0", "]", "*", "x", "+", "g", "[", "1", "]", "*", "y", ";", "if", "(", "z", ")", "{", "n", "+=", "g", "[", "2", "]", "*", "z", ";", "if", "(", "w", ")", "{", "n", "+=", "g", "[", "3", "]", "*", "w", ";", "}", "}", "return", "n", ";", "}" ]
Computes dot product in 2D. @param g 2-vector (grid offset) @param {Number} x @param {Number} y @param {Number} z @param {Number} w @return {Number} dot product @api private
[ "Computes", "dot", "product", "in", "2D", "." ]
3712b44242128245084f18cbad7f0dfa0fc41d9b
https://github.com/hapticdata/toxiclibsjs/blob/3712b44242128245084f18cbad7f0dfa0fc41d9b/lib/toxi/math/noise/simplexNoise.js#L190-L199
19,371
hapticdata/toxiclibsjs
lib/toxi/color/accessors.js
make
function make( type, setters ){ var name = type + 'Accessor', arry = type.toLowerCase(); //make HSV hsv etc exports[name] = function( comp ){ this.component = comp; //compare() could easily be used in incorrect scope, bind it this.compare = bind( this.compare, this ); }; exports[name].prototype.compare = function( a, b ){ var ca = a[arry][this.component], cb = b[arry][this.component]; return numberComparator( ca, cb ); }; exports[name].prototype.getComponentValueFor = function( col ){ return col[arry][this.component]; }; exports[name].prototype.setComponentValueFor = function( col, val ){ col[ 'set'+setters[this.component] ]( val ); }; }
javascript
function make( type, setters ){ var name = type + 'Accessor', arry = type.toLowerCase(); //make HSV hsv etc exports[name] = function( comp ){ this.component = comp; //compare() could easily be used in incorrect scope, bind it this.compare = bind( this.compare, this ); }; exports[name].prototype.compare = function( a, b ){ var ca = a[arry][this.component], cb = b[arry][this.component]; return numberComparator( ca, cb ); }; exports[name].prototype.getComponentValueFor = function( col ){ return col[arry][this.component]; }; exports[name].prototype.setComponentValueFor = function( col, val ){ col[ 'set'+setters[this.component] ]( val ); }; }
[ "function", "make", "(", "type", ",", "setters", ")", "{", "var", "name", "=", "type", "+", "'Accessor'", ",", "arry", "=", "type", ".", "toLowerCase", "(", ")", ";", "//make HSV hsv etc", "exports", "[", "name", "]", "=", "function", "(", "comp", ")", "{", "this", ".", "component", "=", "comp", ";", "//compare() could easily be used in incorrect scope, bind it", "this", ".", "compare", "=", "bind", "(", "this", ".", "compare", ",", "this", ")", ";", "}", ";", "exports", "[", "name", "]", ".", "prototype", ".", "compare", "=", "function", "(", "a", ",", "b", ")", "{", "var", "ca", "=", "a", "[", "arry", "]", "[", "this", ".", "component", "]", ",", "cb", "=", "b", "[", "arry", "]", "[", "this", ".", "component", "]", ";", "return", "numberComparator", "(", "ca", ",", "cb", ")", ";", "}", ";", "exports", "[", "name", "]", ".", "prototype", ".", "getComponentValueFor", "=", "function", "(", "col", ")", "{", "return", "col", "[", "arry", "]", "[", "this", ".", "component", "]", ";", "}", ";", "exports", "[", "name", "]", ".", "prototype", ".", "setComponentValueFor", "=", "function", "(", "col", ",", "val", ")", "{", "col", "[", "'set'", "+", "setters", "[", "this", ".", "component", "]", "]", "(", "val", ")", ";", "}", ";", "}" ]
this will attach proper exported objects for each accessor
[ "this", "will", "attach", "proper", "exported", "objects", "for", "each", "accessor" ]
3712b44242128245084f18cbad7f0dfa0fc41d9b
https://github.com/hapticdata/toxiclibsjs/blob/3712b44242128245084f18cbad7f0dfa0fc41d9b/lib/toxi/color/accessors.js#L7-L29
19,372
hapticdata/toxiclibsjs
lib/toxi/physics2d/constraints/AngularConstraint.js
function(theta_p,theta){ if(arguments.length > 1){ this.theta = theta; this.rootPos = new Vec2D(theta_p); } else { this.rootPos = new Vec2D(); this.theta = theta_p; } //due to lack-of int/float types, no support of theta in degrees }
javascript
function(theta_p,theta){ if(arguments.length > 1){ this.theta = theta; this.rootPos = new Vec2D(theta_p); } else { this.rootPos = new Vec2D(); this.theta = theta_p; } //due to lack-of int/float types, no support of theta in degrees }
[ "function", "(", "theta_p", ",", "theta", ")", "{", "if", "(", "arguments", ".", "length", ">", "1", ")", "{", "this", ".", "theta", "=", "theta", ";", "this", ".", "rootPos", "=", "new", "Vec2D", "(", "theta_p", ")", ";", "}", "else", "{", "this", ".", "rootPos", "=", "new", "Vec2D", "(", ")", ";", "this", ".", "theta", "=", "theta_p", ";", "}", "//due to lack-of int/float types, no support of theta in degrees", "}" ]
either Vec2D + angle @param {Vec2D | Number} vector | angle @param {Number} [theta]
[ "either", "Vec2D", "+", "angle" ]
3712b44242128245084f18cbad7f0dfa0fc41d9b
https://github.com/hapticdata/toxiclibsjs/blob/3712b44242128245084f18cbad7f0dfa0fc41d9b/lib/toxi/physics2d/constraints/AngularConstraint.js#L10-L19
19,373
hapticdata/toxiclibsjs
lib/toxi/geom/Polygon2D.js
function( origin ){ var centroid = this.getCentroid(); var delta = origin !== undefined ? origin.sub( centroid ) : centroid.invert(); for( var i=0, l = this.vertices.length; i<l; i++){ this.vertices[i].addSelf( delta ); } return this; }
javascript
function( origin ){ var centroid = this.getCentroid(); var delta = origin !== undefined ? origin.sub( centroid ) : centroid.invert(); for( var i=0, l = this.vertices.length; i<l; i++){ this.vertices[i].addSelf( delta ); } return this; }
[ "function", "(", "origin", ")", "{", "var", "centroid", "=", "this", ".", "getCentroid", "(", ")", ";", "var", "delta", "=", "origin", "!==", "undefined", "?", "origin", ".", "sub", "(", "centroid", ")", ":", "centroid", ".", "invert", "(", ")", ";", "for", "(", "var", "i", "=", "0", ",", "l", "=", "this", ".", "vertices", ".", "length", ";", "i", "<", "l", ";", "i", "++", ")", "{", "this", ".", "vertices", "[", "i", "]", ".", "addSelf", "(", "delta", ")", ";", "}", "return", "this", ";", "}" ]
centers the polygon so that its new centroid is at the given point @param {Vec2D} [origin] @return itself
[ "centers", "the", "polygon", "so", "that", "its", "new", "centroid", "is", "at", "the", "given", "point" ]
3712b44242128245084f18cbad7f0dfa0fc41d9b
https://github.com/hapticdata/toxiclibsjs/blob/3712b44242128245084f18cbad7f0dfa0fc41d9b/lib/toxi/geom/Polygon2D.js#L60-L67
19,374
hapticdata/toxiclibsjs
lib/toxi/geom/Polygon2D.js
function( count ){ var num = this.vertices.length, longestID = 0, maxD = 0, i = 0, d, m; while( num < count ){ //find longest edge longestID = 0; maxD = 0; for( i=0; i<num; i++ ){ d = this.vertices[i].distanceToSquared( this.vertices[ (i+1) % num ] ); if( d > maxD ){ longestID = i; maxD = d; } } //insert mid point of longest segment m = this.vertices[longestID] .add(this.vertices[(longestID + 1) % num]) .scaleSelf(0.5); //push this into the array inbetween the 2 points this.vertices.splice( longestID+1, 0, m ); num++; } return this; }
javascript
function( count ){ var num = this.vertices.length, longestID = 0, maxD = 0, i = 0, d, m; while( num < count ){ //find longest edge longestID = 0; maxD = 0; for( i=0; i<num; i++ ){ d = this.vertices[i].distanceToSquared( this.vertices[ (i+1) % num ] ); if( d > maxD ){ longestID = i; maxD = d; } } //insert mid point of longest segment m = this.vertices[longestID] .add(this.vertices[(longestID + 1) % num]) .scaleSelf(0.5); //push this into the array inbetween the 2 points this.vertices.splice( longestID+1, 0, m ); num++; } return this; }
[ "function", "(", "count", ")", "{", "var", "num", "=", "this", ".", "vertices", ".", "length", ",", "longestID", "=", "0", ",", "maxD", "=", "0", ",", "i", "=", "0", ",", "d", ",", "m", ";", "while", "(", "num", "<", "count", ")", "{", "//find longest edge", "longestID", "=", "0", ";", "maxD", "=", "0", ";", "for", "(", "i", "=", "0", ";", "i", "<", "num", ";", "i", "++", ")", "{", "d", "=", "this", ".", "vertices", "[", "i", "]", ".", "distanceToSquared", "(", "this", ".", "vertices", "[", "(", "i", "+", "1", ")", "%", "num", "]", ")", ";", "if", "(", "d", ">", "maxD", ")", "{", "longestID", "=", "i", ";", "maxD", "=", "d", ";", "}", "}", "//insert mid point of longest segment", "m", "=", "this", ".", "vertices", "[", "longestID", "]", ".", "add", "(", "this", ".", "vertices", "[", "(", "longestID", "+", "1", ")", "%", "num", "]", ")", ".", "scaleSelf", "(", "0.5", ")", ";", "//push this into the array inbetween the 2 points", "this", ".", "vertices", ".", "splice", "(", "longestID", "+", "1", ",", "0", ",", "m", ")", ";", "num", "++", ";", "}", "return", "this", ";", "}" ]
Repeatedly inserts vertices as mid points of the longest edges until the new vertex count is reached. @param {Number} count new vertex count @return itself
[ "Repeatedly", "inserts", "vertices", "as", "mid", "points", "of", "the", "longest", "edges", "until", "the", "new", "vertex", "count", "is", "reached", "." ]
3712b44242128245084f18cbad7f0dfa0fc41d9b
https://github.com/hapticdata/toxiclibsjs/blob/3712b44242128245084f18cbad7f0dfa0fc41d9b/lib/toxi/geom/Polygon2D.js#L246-L274
19,375
hapticdata/toxiclibsjs
lib/toxi/geom/Polygon2D.js
function(){ var isPositive = false, num = this.vertices.length, prev, next, d0, d1, newIsP; for( var i = 0; i < num; i++ ){ prev = (i===0) ? num -1 : i - 1; next = (i===num-1) ? 0 : i + 1; d0 = this.vertices[i].sub(this.vertices[prev]); d1 = this.vertices[next].sub(this.vertices[i]); newIsP = (d0.cross(d1) > 0); if( i === 0 ) { isPositive = true; } else if( isPositive != newIsP ) { return false; } } return true; }
javascript
function(){ var isPositive = false, num = this.vertices.length, prev, next, d0, d1, newIsP; for( var i = 0; i < num; i++ ){ prev = (i===0) ? num -1 : i - 1; next = (i===num-1) ? 0 : i + 1; d0 = this.vertices[i].sub(this.vertices[prev]); d1 = this.vertices[next].sub(this.vertices[i]); newIsP = (d0.cross(d1) > 0); if( i === 0 ) { isPositive = true; } else if( isPositive != newIsP ) { return false; } } return true; }
[ "function", "(", ")", "{", "var", "isPositive", "=", "false", ",", "num", "=", "this", ".", "vertices", ".", "length", ",", "prev", ",", "next", ",", "d0", ",", "d1", ",", "newIsP", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "num", ";", "i", "++", ")", "{", "prev", "=", "(", "i", "===", "0", ")", "?", "num", "-", "1", ":", "i", "-", "1", ";", "next", "=", "(", "i", "===", "num", "-", "1", ")", "?", "0", ":", "i", "+", "1", ";", "d0", "=", "this", ".", "vertices", "[", "i", "]", ".", "sub", "(", "this", ".", "vertices", "[", "prev", "]", ")", ";", "d1", "=", "this", ".", "vertices", "[", "next", "]", ".", "sub", "(", "this", ".", "vertices", "[", "i", "]", ")", ";", "newIsP", "=", "(", "d0", ".", "cross", "(", "d1", ")", ">", "0", ")", ";", "if", "(", "i", "===", "0", ")", "{", "isPositive", "=", "true", ";", "}", "else", "if", "(", "isPositive", "!=", "newIsP", ")", "{", "return", "false", ";", "}", "}", "return", "true", ";", "}" ]
Checks if the polygon is convex. @return true, if convex.
[ "Checks", "if", "the", "polygon", "is", "convex", "." ]
3712b44242128245084f18cbad7f0dfa0fc41d9b
https://github.com/hapticdata/toxiclibsjs/blob/3712b44242128245084f18cbad7f0dfa0fc41d9b/lib/toxi/geom/Polygon2D.js#L301-L323
19,376
hapticdata/toxiclibsjs
lib/toxi/geom/Polygon2D.js
function( x1, y1, x2, y2, x3, y3, distance, out ){ var c1 = x2, d1 = y2, c2 = x2, d2 = y2; var dx1, dy1, dist1, dx2, dy2, dist2, insetX, insetY; dx1 = x2-x1; dy1 = y2-y1; dist1 = Math.sqrt(dx1*dx1 + dy1*dy1); dx2 = x3-x2; dy2 = y3-y2; dist2 = Math.sqrt(dx2*dx2 + dy2*dy2); if( dist1 < MathUtils.EPS || dist2 < MathUtils.EPS ){ return; } dist1 = distance / dist1; dist2 = distance / dist2; insetX = dy1 * dist1; insetY = -dx1 * dist1; x1 += insetX; c1 += insetX; y1 += insetY; d1 += insetY; insetX = dy2 * dist2; insetY = -dx2 * dist2; x3 += insetX; c2 += insetX; y3 += insetY; d2 += insetY; if( c1 === c2 && d1 === d2 ){ out.set(c1,d1); return; } var l1 = new Line2D( new Vec2D(x1,y1), new Vec2D(c1,d1) ), l2 = new Line2D( new Vec2D(c2,d2), new Vec2D(x3,y3) ), isec = l1.intersectLine(l2), ipos = isec.getPos(); if( ipos !== null || ipos !== undefined ){ out.set(ipos); } }
javascript
function( x1, y1, x2, y2, x3, y3, distance, out ){ var c1 = x2, d1 = y2, c2 = x2, d2 = y2; var dx1, dy1, dist1, dx2, dy2, dist2, insetX, insetY; dx1 = x2-x1; dy1 = y2-y1; dist1 = Math.sqrt(dx1*dx1 + dy1*dy1); dx2 = x3-x2; dy2 = y3-y2; dist2 = Math.sqrt(dx2*dx2 + dy2*dy2); if( dist1 < MathUtils.EPS || dist2 < MathUtils.EPS ){ return; } dist1 = distance / dist1; dist2 = distance / dist2; insetX = dy1 * dist1; insetY = -dx1 * dist1; x1 += insetX; c1 += insetX; y1 += insetY; d1 += insetY; insetX = dy2 * dist2; insetY = -dx2 * dist2; x3 += insetX; c2 += insetX; y3 += insetY; d2 += insetY; if( c1 === c2 && d1 === d2 ){ out.set(c1,d1); return; } var l1 = new Line2D( new Vec2D(x1,y1), new Vec2D(c1,d1) ), l2 = new Line2D( new Vec2D(c2,d2), new Vec2D(x3,y3) ), isec = l1.intersectLine(l2), ipos = isec.getPos(); if( ipos !== null || ipos !== undefined ){ out.set(ipos); } }
[ "function", "(", "x1", ",", "y1", ",", "x2", ",", "y2", ",", "x3", ",", "y3", ",", "distance", ",", "out", ")", "{", "var", "c1", "=", "x2", ",", "d1", "=", "y2", ",", "c2", "=", "x2", ",", "d2", "=", "y2", ";", "var", "dx1", ",", "dy1", ",", "dist1", ",", "dx2", ",", "dy2", ",", "dist2", ",", "insetX", ",", "insetY", ";", "dx1", "=", "x2", "-", "x1", ";", "dy1", "=", "y2", "-", "y1", ";", "dist1", "=", "Math", ".", "sqrt", "(", "dx1", "*", "dx1", "+", "dy1", "*", "dy1", ")", ";", "dx2", "=", "x3", "-", "x2", ";", "dy2", "=", "y3", "-", "y2", ";", "dist2", "=", "Math", ".", "sqrt", "(", "dx2", "*", "dx2", "+", "dy2", "*", "dy2", ")", ";", "if", "(", "dist1", "<", "MathUtils", ".", "EPS", "||", "dist2", "<", "MathUtils", ".", "EPS", ")", "{", "return", ";", "}", "dist1", "=", "distance", "/", "dist1", ";", "dist2", "=", "distance", "/", "dist2", ";", "insetX", "=", "dy1", "*", "dist1", ";", "insetY", "=", "-", "dx1", "*", "dist1", ";", "x1", "+=", "insetX", ";", "c1", "+=", "insetX", ";", "y1", "+=", "insetY", ";", "d1", "+=", "insetY", ";", "insetX", "=", "dy2", "*", "dist2", ";", "insetY", "=", "-", "dx2", "*", "dist2", ";", "x3", "+=", "insetX", ";", "c2", "+=", "insetX", ";", "y3", "+=", "insetY", ";", "d2", "+=", "insetY", ";", "if", "(", "c1", "===", "c2", "&&", "d1", "===", "d2", ")", "{", "out", ".", "set", "(", "c1", ",", "d1", ")", ";", "return", ";", "}", "var", "l1", "=", "new", "Line2D", "(", "new", "Vec2D", "(", "x1", ",", "y1", ")", ",", "new", "Vec2D", "(", "c1", ",", "d1", ")", ")", ",", "l2", "=", "new", "Line2D", "(", "new", "Vec2D", "(", "c2", ",", "d2", ")", ",", "new", "Vec2D", "(", "x3", ",", "y3", ")", ")", ",", "isec", "=", "l1", ".", "intersectLine", "(", "l2", ")", ",", "ipos", "=", "isec", ".", "getPos", "(", ")", ";", "if", "(", "ipos", "!==", "null", "||", "ipos", "!==", "undefined", ")", "{", "out", ".", "set", "(", "ipos", ")", ";", "}", "}" ]
Given the sequentially connected points p1, p2, p3, this function returns a bevel-offset replacement for point p2. Note: If vectors p1->p2 and p2->p3 are exactly 180 degrees opposed, or if either segment is zero then no offset will be applied. @param x1 @param y1 @param x2 @param y2 @param x3 @param y3 @param distance @param out @see http://alienryderflex.com/polygon_inset/
[ "Given", "the", "sequentially", "connected", "points", "p1", "p2", "p3", "this", "function", "returns", "a", "bevel", "-", "offset", "replacement", "for", "point", "p2", "." ]
3712b44242128245084f18cbad7f0dfa0fc41d9b
https://github.com/hapticdata/toxiclibsjs/blob/3712b44242128245084f18cbad7f0dfa0fc41d9b/lib/toxi/geom/Polygon2D.js#L343-L396
19,377
hapticdata/toxiclibsjs
lib/toxi/geom/Polygon2D.js
function( minEdgeLen ){ minEdgeLen *= minEdgeLen; var vs = this.vertices, reduced = [], prev = vs[0], num = vs.length - 1, vec; reduced.push(prev); for( var i = 0; i < num; i++ ){ vec = vs[i]; if( prev.distanceToSquared(vec) >= minEdgeLen ){ reduced.push(vec); prev = vec; } } if( vs[0].distanceToSquared(vs[num]) >= minEdgeLen ){ reduced.push(vs[num]); } this.vertices = reduced; return this; }
javascript
function( minEdgeLen ){ minEdgeLen *= minEdgeLen; var vs = this.vertices, reduced = [], prev = vs[0], num = vs.length - 1, vec; reduced.push(prev); for( var i = 0; i < num; i++ ){ vec = vs[i]; if( prev.distanceToSquared(vec) >= minEdgeLen ){ reduced.push(vec); prev = vec; } } if( vs[0].distanceToSquared(vs[num]) >= minEdgeLen ){ reduced.push(vs[num]); } this.vertices = reduced; return this; }
[ "function", "(", "minEdgeLen", ")", "{", "minEdgeLen", "*=", "minEdgeLen", ";", "var", "vs", "=", "this", ".", "vertices", ",", "reduced", "=", "[", "]", ",", "prev", "=", "vs", "[", "0", "]", ",", "num", "=", "vs", ".", "length", "-", "1", ",", "vec", ";", "reduced", ".", "push", "(", "prev", ")", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "num", ";", "i", "++", ")", "{", "vec", "=", "vs", "[", "i", "]", ";", "if", "(", "prev", ".", "distanceToSquared", "(", "vec", ")", ">=", "minEdgeLen", ")", "{", "reduced", ".", "push", "(", "vec", ")", ";", "prev", "=", "vec", ";", "}", "}", "if", "(", "vs", "[", "0", "]", ".", "distanceToSquared", "(", "vs", "[", "num", "]", ")", ">=", "minEdgeLen", ")", "{", "reduced", ".", "push", "(", "vs", "[", "num", "]", ")", ";", "}", "this", ".", "vertices", "=", "reduced", ";", "return", "this", ";", "}" ]
Reduces the number of vertices in the polygon based on the given minimum edge length. Only vertices with at least this distance between them will be kept. @param minEdgeLen @return itself
[ "Reduces", "the", "number", "of", "vertices", "in", "the", "polygon", "based", "on", "the", "given", "minimum", "edge", "length", ".", "Only", "vertices", "with", "at", "least", "this", "distance", "between", "them", "will", "be", "kept", "." ]
3712b44242128245084f18cbad7f0dfa0fc41d9b
https://github.com/hapticdata/toxiclibsjs/blob/3712b44242128245084f18cbad7f0dfa0fc41d9b/lib/toxi/geom/Polygon2D.js#L444-L464
19,378
hapticdata/toxiclibsjs
lib/toxi/geom/Polygon2D.js
function( tolerance ){ //if tolerance is 0, it will be faster to just use 'equals' method var equals = tolerance ? 'equalsWithTolerance' : 'equals'; var p, prev, i = 0, num = this.vertices.length; var last; for( ; i<num; i++ ){ p = this.vertices[i]; //if its the 'equals' method tolerance will just be ingored if( p[equals]( prev, tolerance ) ){ //remove from array, step back counter this.vertices.splice( i, 1 ); i--; num--; } else { prev = p; } } num = this.vertices.length; if( num > 0 ){ last = this.vertices[num-1]; if( last[equals]( this.vertices[0], tolerance ) ){ this.vertices.splice( num-1, 1 ); } } return this; }
javascript
function( tolerance ){ //if tolerance is 0, it will be faster to just use 'equals' method var equals = tolerance ? 'equalsWithTolerance' : 'equals'; var p, prev, i = 0, num = this.vertices.length; var last; for( ; i<num; i++ ){ p = this.vertices[i]; //if its the 'equals' method tolerance will just be ingored if( p[equals]( prev, tolerance ) ){ //remove from array, step back counter this.vertices.splice( i, 1 ); i--; num--; } else { prev = p; } } num = this.vertices.length; if( num > 0 ){ last = this.vertices[num-1]; if( last[equals]( this.vertices[0], tolerance ) ){ this.vertices.splice( num-1, 1 ); } } return this; }
[ "function", "(", "tolerance", ")", "{", "//if tolerance is 0, it will be faster to just use 'equals' method", "var", "equals", "=", "tolerance", "?", "'equalsWithTolerance'", ":", "'equals'", ";", "var", "p", ",", "prev", ",", "i", "=", "0", ",", "num", "=", "this", ".", "vertices", ".", "length", ";", "var", "last", ";", "for", "(", ";", "i", "<", "num", ";", "i", "++", ")", "{", "p", "=", "this", ".", "vertices", "[", "i", "]", ";", "//if its the 'equals' method tolerance will just be ingored", "if", "(", "p", "[", "equals", "]", "(", "prev", ",", "tolerance", ")", ")", "{", "//remove from array, step back counter", "this", ".", "vertices", ".", "splice", "(", "i", ",", "1", ")", ";", "i", "--", ";", "num", "--", ";", "}", "else", "{", "prev", "=", "p", ";", "}", "}", "num", "=", "this", ".", "vertices", ".", "length", ";", "if", "(", "num", ">", "0", ")", "{", "last", "=", "this", ".", "vertices", "[", "num", "-", "1", "]", ";", "if", "(", "last", "[", "equals", "]", "(", "this", ".", "vertices", "[", "0", "]", ",", "tolerance", ")", ")", "{", "this", ".", "vertices", ".", "splice", "(", "num", "-", "1", ",", "1", ")", ";", "}", "}", "return", "this", ";", "}" ]
Removes duplicate vertices from the polygon. Only successive points are recognized as duplicates. @param {Number} tolerance snap distance for finding duplicates @return itself
[ "Removes", "duplicate", "vertices", "from", "the", "polygon", ".", "Only", "successive", "points", "are", "recognized", "as", "duplicates", "." ]
3712b44242128245084f18cbad7f0dfa0fc41d9b
https://github.com/hapticdata/toxiclibsjs/blob/3712b44242128245084f18cbad7f0dfa0fc41d9b/lib/toxi/geom/Polygon2D.js#L473-L498
19,379
hapticdata/toxiclibsjs
lib/toxi/math/ScaleMap.js
function(val) { var t = ((val - this._in.min) / this._interval); return this.mapFunction.interpolate(0, this.mapRange, t) + this._out.min; }
javascript
function(val) { var t = ((val - this._in.min) / this._interval); return this.mapFunction.interpolate(0, this.mapRange, t) + this._out.min; }
[ "function", "(", "val", ")", "{", "var", "t", "=", "(", "(", "val", "-", "this", ".", "_in", ".", "min", ")", "/", "this", ".", "_interval", ")", ";", "return", "this", ".", "mapFunction", ".", "interpolate", "(", "0", ",", "this", ".", "mapRange", ",", "t", ")", "+", "this", ".", "_out", ".", "min", ";", "}" ]
Computes mapped value in the target interval. Does check if input value is outside the input range. @param val @return mapped value
[ "Computes", "mapped", "value", "in", "the", "target", "interval", ".", "Does", "check", "if", "input", "value", "is", "outside", "the", "input", "range", "." ]
3712b44242128245084f18cbad7f0dfa0fc41d9b
https://github.com/hapticdata/toxiclibsjs/blob/3712b44242128245084f18cbad7f0dfa0fc41d9b/lib/toxi/math/ScaleMap.js#L89-L92
19,380
jonathantneal/media-player
src/index.js
onPlayChange
function onPlayChange() { if (paused !== media.paused) { paused = media.paused; $(self.play, { 'aria-label': paused ? lang.play || 'play' : lang.pause || 'pause' }); $(self.playSymbol, { 'aria-hidden': !paused }); $(self.pauseSymbol, { 'aria-hidden': paused }); clearInterval(interval); if (!paused) { // listen for time changes every 30th of a second interval = setInterval(onTimeChange, 34); } // dispatch new "playchange" event dispatchCustomEvent(media, 'playchange'); } }
javascript
function onPlayChange() { if (paused !== media.paused) { paused = media.paused; $(self.play, { 'aria-label': paused ? lang.play || 'play' : lang.pause || 'pause' }); $(self.playSymbol, { 'aria-hidden': !paused }); $(self.pauseSymbol, { 'aria-hidden': paused }); clearInterval(interval); if (!paused) { // listen for time changes every 30th of a second interval = setInterval(onTimeChange, 34); } // dispatch new "playchange" event dispatchCustomEvent(media, 'playchange'); } }
[ "function", "onPlayChange", "(", ")", "{", "if", "(", "paused", "!==", "media", ".", "paused", ")", "{", "paused", "=", "media", ".", "paused", ";", "$", "(", "self", ".", "play", ",", "{", "'aria-label'", ":", "paused", "?", "lang", ".", "play", "||", "'play'", ":", "lang", ".", "pause", "||", "'pause'", "}", ")", ";", "$", "(", "self", ".", "playSymbol", ",", "{", "'aria-hidden'", ":", "!", "paused", "}", ")", ";", "$", "(", "self", ".", "pauseSymbol", ",", "{", "'aria-hidden'", ":", "paused", "}", ")", ";", "clearInterval", "(", "interval", ")", ";", "if", "(", "!", "paused", ")", "{", "// listen for time changes every 30th of a second", "interval", "=", "setInterval", "(", "onTimeChange", ",", "34", ")", ";", "}", "// dispatch new \"playchange\" event", "dispatchCustomEvent", "(", "media", ",", "'playchange'", ")", ";", "}", "}" ]
when the play state changes
[ "when", "the", "play", "state", "changes" ]
f2ee40c4576269f06d14e1d54b3b17b292276f6f
https://github.com/jonathantneal/media-player/blob/f2ee40c4576269f06d14e1d54b3b17b292276f6f/src/index.js#L104-L122
19,381
jonathantneal/media-player
src/index.js
onTimeChange
function onTimeChange() { if (currentTime !== media.currentTime || duration !== media.duration) { currentTime = media.currentTime; duration = media.duration || 0; const currentTimePercentage = currentTime / duration; const currentTimeCode = timeToTimecode(currentTime); const remainingTimeCode = timeToTimecode(duration - Math.floor(currentTime)); if (currentTimeCode !== self.currentTimeText.nodeValue) { self.currentTimeText.nodeValue = currentTimeCode; $(self.currentTime, { title: `${timeToAural(currentTime, lang.minutes || 'minutes', lang.seconds || 'seconds')}` }); } if (remainingTimeCode !== self.remainingTimeText.nodeValue) { self.remainingTimeText.nodeValue = remainingTimeCode; $(self.remainingTime, { title: `${timeToAural(duration - currentTime, lang.minutes || 'minutes', lang.seconds || 'seconds')}` }); } $(self.time, { 'aria-valuenow': currentTime, 'aria-valuemin': 0, 'aria-valuemax': duration }); const dirIsInline = /^(ltr|rtl)$/i.test(timeDir); const axisProp = dirIsInline ? 'width' : 'height'; self.timeMeter.style[axisProp] = `${currentTimePercentage * 100}%`; // dispatch new "timechange" event dispatchCustomEvent(media, 'timechange'); } }
javascript
function onTimeChange() { if (currentTime !== media.currentTime || duration !== media.duration) { currentTime = media.currentTime; duration = media.duration || 0; const currentTimePercentage = currentTime / duration; const currentTimeCode = timeToTimecode(currentTime); const remainingTimeCode = timeToTimecode(duration - Math.floor(currentTime)); if (currentTimeCode !== self.currentTimeText.nodeValue) { self.currentTimeText.nodeValue = currentTimeCode; $(self.currentTime, { title: `${timeToAural(currentTime, lang.minutes || 'minutes', lang.seconds || 'seconds')}` }); } if (remainingTimeCode !== self.remainingTimeText.nodeValue) { self.remainingTimeText.nodeValue = remainingTimeCode; $(self.remainingTime, { title: `${timeToAural(duration - currentTime, lang.minutes || 'minutes', lang.seconds || 'seconds')}` }); } $(self.time, { 'aria-valuenow': currentTime, 'aria-valuemin': 0, 'aria-valuemax': duration }); const dirIsInline = /^(ltr|rtl)$/i.test(timeDir); const axisProp = dirIsInline ? 'width' : 'height'; self.timeMeter.style[axisProp] = `${currentTimePercentage * 100}%`; // dispatch new "timechange" event dispatchCustomEvent(media, 'timechange'); } }
[ "function", "onTimeChange", "(", ")", "{", "if", "(", "currentTime", "!==", "media", ".", "currentTime", "||", "duration", "!==", "media", ".", "duration", ")", "{", "currentTime", "=", "media", ".", "currentTime", ";", "duration", "=", "media", ".", "duration", "||", "0", ";", "const", "currentTimePercentage", "=", "currentTime", "/", "duration", ";", "const", "currentTimeCode", "=", "timeToTimecode", "(", "currentTime", ")", ";", "const", "remainingTimeCode", "=", "timeToTimecode", "(", "duration", "-", "Math", ".", "floor", "(", "currentTime", ")", ")", ";", "if", "(", "currentTimeCode", "!==", "self", ".", "currentTimeText", ".", "nodeValue", ")", "{", "self", ".", "currentTimeText", ".", "nodeValue", "=", "currentTimeCode", ";", "$", "(", "self", ".", "currentTime", ",", "{", "title", ":", "`", "${", "timeToAural", "(", "currentTime", ",", "lang", ".", "minutes", "||", "'minutes'", ",", "lang", ".", "seconds", "||", "'seconds'", ")", "}", "`", "}", ")", ";", "}", "if", "(", "remainingTimeCode", "!==", "self", ".", "remainingTimeText", ".", "nodeValue", ")", "{", "self", ".", "remainingTimeText", ".", "nodeValue", "=", "remainingTimeCode", ";", "$", "(", "self", ".", "remainingTime", ",", "{", "title", ":", "`", "${", "timeToAural", "(", "duration", "-", "currentTime", ",", "lang", ".", "minutes", "||", "'minutes'", ",", "lang", ".", "seconds", "||", "'seconds'", ")", "}", "`", "}", ")", ";", "}", "$", "(", "self", ".", "time", ",", "{", "'aria-valuenow'", ":", "currentTime", ",", "'aria-valuemin'", ":", "0", ",", "'aria-valuemax'", ":", "duration", "}", ")", ";", "const", "dirIsInline", "=", "/", "^(ltr|rtl)$", "/", "i", ".", "test", "(", "timeDir", ")", ";", "const", "axisProp", "=", "dirIsInline", "?", "'width'", ":", "'height'", ";", "self", ".", "timeMeter", ".", "style", "[", "axisProp", "]", "=", "`", "${", "currentTimePercentage", "*", "100", "}", "`", ";", "// dispatch new \"timechange\" event", "dispatchCustomEvent", "(", "media", ",", "'timechange'", ")", ";", "}", "}" ]
when the time changes
[ "when", "the", "time", "changes" ]
f2ee40c4576269f06d14e1d54b3b17b292276f6f
https://github.com/jonathantneal/media-player/blob/f2ee40c4576269f06d14e1d54b3b17b292276f6f/src/index.js#L125-L156
19,382
jonathantneal/media-player
src/index.js
onLoadStart
function onLoadStart() { media.removeEventListener('canplaythrough', onCanPlayStart); $(media, { canplaythrough: onCanPlayStart }); $(self.download, { href: media.src, download: media.src }); onPlayChange(); onVolumeChange(); onFullscreenChange(); onTimeChange(); }
javascript
function onLoadStart() { media.removeEventListener('canplaythrough', onCanPlayStart); $(media, { canplaythrough: onCanPlayStart }); $(self.download, { href: media.src, download: media.src }); onPlayChange(); onVolumeChange(); onFullscreenChange(); onTimeChange(); }
[ "function", "onLoadStart", "(", ")", "{", "media", ".", "removeEventListener", "(", "'canplaythrough'", ",", "onCanPlayStart", ")", ";", "$", "(", "media", ",", "{", "canplaythrough", ":", "onCanPlayStart", "}", ")", ";", "$", "(", "self", ".", "download", ",", "{", "href", ":", "media", ".", "src", ",", "download", ":", "media", ".", "src", "}", ")", ";", "onPlayChange", "(", ")", ";", "onVolumeChange", "(", ")", ";", "onFullscreenChange", "(", ")", ";", "onTimeChange", "(", ")", ";", "}" ]
when media loads for the first time
[ "when", "media", "loads", "for", "the", "first", "time" ]
f2ee40c4576269f06d14e1d54b3b17b292276f6f
https://github.com/jonathantneal/media-player/blob/f2ee40c4576269f06d14e1d54b3b17b292276f6f/src/index.js#L159-L170
19,383
jonathantneal/media-player
src/index.js
onCanPlayStart
function onCanPlayStart() { media.removeEventListener('canplaythrough', onCanPlayStart); // dispatch new "canplaystart" event dispatchCustomEvent(media, 'canplaystart'); if (!paused || media.autoplay) { media.play(); } }
javascript
function onCanPlayStart() { media.removeEventListener('canplaythrough', onCanPlayStart); // dispatch new "canplaystart" event dispatchCustomEvent(media, 'canplaystart'); if (!paused || media.autoplay) { media.play(); } }
[ "function", "onCanPlayStart", "(", ")", "{", "media", ".", "removeEventListener", "(", "'canplaythrough'", ",", "onCanPlayStart", ")", ";", "// dispatch new \"canplaystart\" event", "dispatchCustomEvent", "(", "media", ",", "'canplaystart'", ")", ";", "if", "(", "!", "paused", "||", "media", ".", "autoplay", ")", "{", "media", ".", "play", "(", ")", ";", "}", "}" ]
when the media can play
[ "when", "the", "media", "can", "play" ]
f2ee40c4576269f06d14e1d54b3b17b292276f6f
https://github.com/jonathantneal/media-player/blob/f2ee40c4576269f06d14e1d54b3b17b292276f6f/src/index.js#L178-L187
19,384
jonathantneal/media-player
src/index.js
onVolumeChange
function onVolumeChange() { const volumePercentage = media.muted ? 0 : media.volume; const isMuted = !volumePercentage; $(self.volume, { 'aria-valuenow': volumePercentage, 'aria-valuemin': 0, 'aria-valuemax': 1 }); const dirIsInline = /^(ltr|rtl)$/i.test(volumeDir); const axisProp = dirIsInline ? 'width' : 'height'; self.volumeMeter.style[axisProp] = `${volumePercentage * 100}%`; $(self.mute, { 'aria-label': isMuted ? lang.unmute || 'unmute' : lang.mute || 'mute' }); $(self.muteSymbol, { 'aria-hidden': isMuted }); $(self.unmuteSymbol, { 'aria-hidden': !isMuted }); }
javascript
function onVolumeChange() { const volumePercentage = media.muted ? 0 : media.volume; const isMuted = !volumePercentage; $(self.volume, { 'aria-valuenow': volumePercentage, 'aria-valuemin': 0, 'aria-valuemax': 1 }); const dirIsInline = /^(ltr|rtl)$/i.test(volumeDir); const axisProp = dirIsInline ? 'width' : 'height'; self.volumeMeter.style[axisProp] = `${volumePercentage * 100}%`; $(self.mute, { 'aria-label': isMuted ? lang.unmute || 'unmute' : lang.mute || 'mute' }); $(self.muteSymbol, { 'aria-hidden': isMuted }); $(self.unmuteSymbol, { 'aria-hidden': !isMuted }); }
[ "function", "onVolumeChange", "(", ")", "{", "const", "volumePercentage", "=", "media", ".", "muted", "?", "0", ":", "media", ".", "volume", ";", "const", "isMuted", "=", "!", "volumePercentage", ";", "$", "(", "self", ".", "volume", ",", "{", "'aria-valuenow'", ":", "volumePercentage", ",", "'aria-valuemin'", ":", "0", ",", "'aria-valuemax'", ":", "1", "}", ")", ";", "const", "dirIsInline", "=", "/", "^(ltr|rtl)$", "/", "i", ".", "test", "(", "volumeDir", ")", ";", "const", "axisProp", "=", "dirIsInline", "?", "'width'", ":", "'height'", ";", "self", ".", "volumeMeter", ".", "style", "[", "axisProp", "]", "=", "`", "${", "volumePercentage", "*", "100", "}", "`", ";", "$", "(", "self", ".", "mute", ",", "{", "'aria-label'", ":", "isMuted", "?", "lang", ".", "unmute", "||", "'unmute'", ":", "lang", ".", "mute", "||", "'mute'", "}", ")", ";", "$", "(", "self", ".", "muteSymbol", ",", "{", "'aria-hidden'", ":", "isMuted", "}", ")", ";", "$", "(", "self", ".", "unmuteSymbol", ",", "{", "'aria-hidden'", ":", "!", "isMuted", "}", ")", ";", "}" ]
when the volume changes
[ "when", "the", "volume", "changes" ]
f2ee40c4576269f06d14e1d54b3b17b292276f6f
https://github.com/jonathantneal/media-player/blob/f2ee40c4576269f06d14e1d54b3b17b292276f6f/src/index.js#L190-L204
19,385
jonathantneal/media-player
src/index.js
onDownloadClick
function onDownloadClick() { const a = document.head.appendChild($('a', { download: '', href: media.src })); a.click(); document.head.removeChild(a); }
javascript
function onDownloadClick() { const a = document.head.appendChild($('a', { download: '', href: media.src })); a.click(); document.head.removeChild(a); }
[ "function", "onDownloadClick", "(", ")", "{", "const", "a", "=", "document", ".", "head", ".", "appendChild", "(", "$", "(", "'a'", ",", "{", "download", ":", "''", ",", "href", ":", "media", ".", "src", "}", ")", ")", ";", "a", ".", "click", "(", ")", ";", "document", ".", "head", ".", "removeChild", "(", "a", ")", ";", "}" ]
click from download control
[ "click", "from", "download", "control" ]
f2ee40c4576269f06d14e1d54b3b17b292276f6f
https://github.com/jonathantneal/media-player/blob/f2ee40c4576269f06d14e1d54b3b17b292276f6f/src/index.js#L248-L254
19,386
jonathantneal/media-player
src/index.js
onFullscreenClick
function onFullscreenClick() { if (requestFullscreen) { if (player === fullscreenElement()) { // exit fullscreen exitFullscreen().call(document); } else { // enter fullscreen requestFullscreen.call(player); // maintain focus in internet explorer self.fullscreen.focus(); // maintain focus in safari setTimeout(() => { self.fullscreen.focus(); }, 200); } } else if (media.webkitSupportsFullscreen) { // iOS allows fullscreen of the video itself if (media.webkitDisplayingFullscreen) { // exit ios fullscreen media.webkitExitFullscreen(); } else { // enter ios fullscreen media.webkitEnterFullscreen(); } onFullscreenChange(); } }
javascript
function onFullscreenClick() { if (requestFullscreen) { if (player === fullscreenElement()) { // exit fullscreen exitFullscreen().call(document); } else { // enter fullscreen requestFullscreen.call(player); // maintain focus in internet explorer self.fullscreen.focus(); // maintain focus in safari setTimeout(() => { self.fullscreen.focus(); }, 200); } } else if (media.webkitSupportsFullscreen) { // iOS allows fullscreen of the video itself if (media.webkitDisplayingFullscreen) { // exit ios fullscreen media.webkitExitFullscreen(); } else { // enter ios fullscreen media.webkitEnterFullscreen(); } onFullscreenChange(); } }
[ "function", "onFullscreenClick", "(", ")", "{", "if", "(", "requestFullscreen", ")", "{", "if", "(", "player", "===", "fullscreenElement", "(", ")", ")", "{", "// exit fullscreen", "exitFullscreen", "(", ")", ".", "call", "(", "document", ")", ";", "}", "else", "{", "// enter fullscreen", "requestFullscreen", ".", "call", "(", "player", ")", ";", "// maintain focus in internet explorer", "self", ".", "fullscreen", ".", "focus", "(", ")", ";", "// maintain focus in safari", "setTimeout", "(", "(", ")", "=>", "{", "self", ".", "fullscreen", ".", "focus", "(", ")", ";", "}", ",", "200", ")", ";", "}", "}", "else", "if", "(", "media", ".", "webkitSupportsFullscreen", ")", "{", "// iOS allows fullscreen of the video itself", "if", "(", "media", ".", "webkitDisplayingFullscreen", ")", "{", "// exit ios fullscreen", "media", ".", "webkitExitFullscreen", "(", ")", ";", "}", "else", "{", "// enter ios fullscreen", "media", ".", "webkitEnterFullscreen", "(", ")", ";", "}", "onFullscreenChange", "(", ")", ";", "}", "}" ]
click from fullscreen control
[ "click", "from", "fullscreen", "control" ]
f2ee40c4576269f06d14e1d54b3b17b292276f6f
https://github.com/jonathantneal/media-player/blob/f2ee40c4576269f06d14e1d54b3b17b292276f6f/src/index.js#L257-L286
19,387
jonathantneal/media-player
src/index.js
onTimeKeydown
function onTimeKeydown(event) { const { keyCode, shiftKey } = event; // 37: LEFT, 38: UP, 39: RIGHT, 40: DOWN if (37 <= keyCode && 40 >= keyCode) { event.preventDefault(); const isLTR = /^(btt|ltr)$/.test(timeDir); const offset = 37 === keyCode || 39 === keyCode ? keyCode - 38 : keyCode - 39; media.currentTime = Math.max(0, Math.min(duration, currentTime + offset * (isLTR ? 1 : -1) * (shiftKey ? 10 : 1))); onTimeChange(); } }
javascript
function onTimeKeydown(event) { const { keyCode, shiftKey } = event; // 37: LEFT, 38: UP, 39: RIGHT, 40: DOWN if (37 <= keyCode && 40 >= keyCode) { event.preventDefault(); const isLTR = /^(btt|ltr)$/.test(timeDir); const offset = 37 === keyCode || 39 === keyCode ? keyCode - 38 : keyCode - 39; media.currentTime = Math.max(0, Math.min(duration, currentTime + offset * (isLTR ? 1 : -1) * (shiftKey ? 10 : 1))); onTimeChange(); } }
[ "function", "onTimeKeydown", "(", "event", ")", "{", "const", "{", "keyCode", ",", "shiftKey", "}", "=", "event", ";", "// 37: LEFT, 38: UP, 39: RIGHT, 40: DOWN", "if", "(", "37", "<=", "keyCode", "&&", "40", ">=", "keyCode", ")", "{", "event", ".", "preventDefault", "(", ")", ";", "const", "isLTR", "=", "/", "^(btt|ltr)$", "/", ".", "test", "(", "timeDir", ")", ";", "const", "offset", "=", "37", "===", "keyCode", "||", "39", "===", "keyCode", "?", "keyCode", "-", "38", ":", "keyCode", "-", "39", ";", "media", ".", "currentTime", "=", "Math", ".", "max", "(", "0", ",", "Math", ".", "min", "(", "duration", ",", "currentTime", "+", "offset", "*", "(", "isLTR", "?", "1", ":", "-", "1", ")", "*", "(", "shiftKey", "?", "10", ":", "1", ")", ")", ")", ";", "onTimeChange", "(", ")", ";", "}", "}" ]
keydown from play control or current time control
[ "keydown", "from", "play", "control", "or", "current", "time", "control" ]
f2ee40c4576269f06d14e1d54b3b17b292276f6f
https://github.com/jonathantneal/media-player/blob/f2ee40c4576269f06d14e1d54b3b17b292276f6f/src/index.js#L289-L303
19,388
jonathantneal/media-player
src/index.js
onVolumeKeydown
function onVolumeKeydown(event) { const { keyCode, shiftKey } = event; // 37: LEFT, 38: UP, 39: RIGHT, 40: DOWN if (37 <= keyCode && 40 >= keyCode) { event.preventDefault(); const isLTR = /^(btt|ltr)$/.test(volumeDir); const offset = 37 === keyCode || 39 === keyCode ? keyCode - 38 : isLTR ? 39 - keyCode : keyCode - 39; media.volume = Math.max(0, Math.min(1, media.volume + offset * (isLTR ? 0.1 : -0.1) * (shiftKey ? 1 : 0.2))); } }
javascript
function onVolumeKeydown(event) { const { keyCode, shiftKey } = event; // 37: LEFT, 38: UP, 39: RIGHT, 40: DOWN if (37 <= keyCode && 40 >= keyCode) { event.preventDefault(); const isLTR = /^(btt|ltr)$/.test(volumeDir); const offset = 37 === keyCode || 39 === keyCode ? keyCode - 38 : isLTR ? 39 - keyCode : keyCode - 39; media.volume = Math.max(0, Math.min(1, media.volume + offset * (isLTR ? 0.1 : -0.1) * (shiftKey ? 1 : 0.2))); } }
[ "function", "onVolumeKeydown", "(", "event", ")", "{", "const", "{", "keyCode", ",", "shiftKey", "}", "=", "event", ";", "// 37: LEFT, 38: UP, 39: RIGHT, 40: DOWN", "if", "(", "37", "<=", "keyCode", "&&", "40", ">=", "keyCode", ")", "{", "event", ".", "preventDefault", "(", ")", ";", "const", "isLTR", "=", "/", "^(btt|ltr)$", "/", ".", "test", "(", "volumeDir", ")", ";", "const", "offset", "=", "37", "===", "keyCode", "||", "39", "===", "keyCode", "?", "keyCode", "-", "38", ":", "isLTR", "?", "39", "-", "keyCode", ":", "keyCode", "-", "39", ";", "media", ".", "volume", "=", "Math", ".", "max", "(", "0", ",", "Math", ".", "min", "(", "1", ",", "media", ".", "volume", "+", "offset", "*", "(", "isLTR", "?", "0.1", ":", "-", "0.1", ")", "*", "(", "shiftKey", "?", "1", ":", "0.2", ")", ")", ")", ";", "}", "}" ]
keydown from mute control or volume control
[ "keydown", "from", "mute", "control", "or", "volume", "control" ]
f2ee40c4576269f06d14e1d54b3b17b292276f6f
https://github.com/jonathantneal/media-player/blob/f2ee40c4576269f06d14e1d54b3b17b292276f6f/src/index.js#L306-L318
19,389
riot/compiler
src/generators/template/builder.js
createBindingsTag
function createBindingsTag(sourceNode, bindingsSelector) { if (!bindingsSelector) return sourceNode return { ...sourceNode, // inject the selector bindings into the node attributes attributes: [{ name: bindingsSelector }, ...getNodeAttributes(sourceNode)] } }
javascript
function createBindingsTag(sourceNode, bindingsSelector) { if (!bindingsSelector) return sourceNode return { ...sourceNode, // inject the selector bindings into the node attributes attributes: [{ name: bindingsSelector }, ...getNodeAttributes(sourceNode)] } }
[ "function", "createBindingsTag", "(", "sourceNode", ",", "bindingsSelector", ")", "{", "if", "(", "!", "bindingsSelector", ")", "return", "sourceNode", "return", "{", "...", "sourceNode", ",", "// inject the selector bindings into the node attributes", "attributes", ":", "[", "{", "name", ":", "bindingsSelector", "}", ",", "...", "getNodeAttributes", "(", "sourceNode", ")", "]", "}", "}" ]
Nodes having bindings should be cloned and new selector properties should be added to them @param {RiotParser.Node} sourceNode - any kind of node parsed via riot parser @param {string} bindingsSelector - temporary string to identify the current node @returns {RiotParser.Node} the original node parsed having the new binding selector attribute
[ "Nodes", "having", "bindings", "should", "be", "cloned", "and", "new", "selector", "properties", "should", "be", "added", "to", "them" ]
fa9cea9cf6b8a369e057c966c4e2698940a3fafc
https://github.com/riot/compiler/blob/fa9cea9cf6b8a369e057c966c4e2698940a3fafc/src/generators/template/builder.js#L36-L46
19,390
riot/compiler
src/generators/template/builder.js
createTagWithBindings
function createTagWithBindings(sourceNode, sourceFile, sourceCode) { const bindingsSelector = isRootNode(sourceNode) ? null : createBindingSelector() const cloneNode = createBindingsTag(sourceNode, bindingsSelector) const tagOpeningHTML = nodeToString(cloneNode) switch(true) { // EACH bindings have prio 1 case hasEachAttribute(cloneNode): return [tagOpeningHTML, [eachBinding(cloneNode, bindingsSelector, sourceFile, sourceCode)]] // IF bindings have prio 2 case hasIfAttribute(cloneNode): return [tagOpeningHTML, [ifBinding(cloneNode, bindingsSelector, sourceFile, sourceCode)]] // TAG bindings have prio 3 case isCustomNode(cloneNode): return [tagOpeningHTML, [tagBinding(cloneNode, bindingsSelector, sourceFile, sourceCode)]] // this node has expressions bound to it default: return [tagOpeningHTML, [simpleBinding(cloneNode, bindingsSelector, sourceFile, sourceCode)]] } }
javascript
function createTagWithBindings(sourceNode, sourceFile, sourceCode) { const bindingsSelector = isRootNode(sourceNode) ? null : createBindingSelector() const cloneNode = createBindingsTag(sourceNode, bindingsSelector) const tagOpeningHTML = nodeToString(cloneNode) switch(true) { // EACH bindings have prio 1 case hasEachAttribute(cloneNode): return [tagOpeningHTML, [eachBinding(cloneNode, bindingsSelector, sourceFile, sourceCode)]] // IF bindings have prio 2 case hasIfAttribute(cloneNode): return [tagOpeningHTML, [ifBinding(cloneNode, bindingsSelector, sourceFile, sourceCode)]] // TAG bindings have prio 3 case isCustomNode(cloneNode): return [tagOpeningHTML, [tagBinding(cloneNode, bindingsSelector, sourceFile, sourceCode)]] // this node has expressions bound to it default: return [tagOpeningHTML, [simpleBinding(cloneNode, bindingsSelector, sourceFile, sourceCode)]] } }
[ "function", "createTagWithBindings", "(", "sourceNode", ",", "sourceFile", ",", "sourceCode", ")", "{", "const", "bindingsSelector", "=", "isRootNode", "(", "sourceNode", ")", "?", "null", ":", "createBindingSelector", "(", ")", "const", "cloneNode", "=", "createBindingsTag", "(", "sourceNode", ",", "bindingsSelector", ")", "const", "tagOpeningHTML", "=", "nodeToString", "(", "cloneNode", ")", "switch", "(", "true", ")", "{", "// EACH bindings have prio 1", "case", "hasEachAttribute", "(", "cloneNode", ")", ":", "return", "[", "tagOpeningHTML", ",", "[", "eachBinding", "(", "cloneNode", ",", "bindingsSelector", ",", "sourceFile", ",", "sourceCode", ")", "]", "]", "// IF bindings have prio 2", "case", "hasIfAttribute", "(", "cloneNode", ")", ":", "return", "[", "tagOpeningHTML", ",", "[", "ifBinding", "(", "cloneNode", ",", "bindingsSelector", ",", "sourceFile", ",", "sourceCode", ")", "]", "]", "// TAG bindings have prio 3", "case", "isCustomNode", "(", "cloneNode", ")", ":", "return", "[", "tagOpeningHTML", ",", "[", "tagBinding", "(", "cloneNode", ",", "bindingsSelector", ",", "sourceFile", ",", "sourceCode", ")", "]", "]", "// this node has expressions bound to it", "default", ":", "return", "[", "tagOpeningHTML", ",", "[", "simpleBinding", "(", "cloneNode", ",", "bindingsSelector", ",", "sourceFile", ",", "sourceCode", ")", "]", "]", "}", "}" ]
Create only a dynamic tag node with generating a custom selector and its bindings @param {RiotParser.Node} sourceNode - any kind of node parsed via riot parser @param {stiring} sourceFile - source file path @param {string} sourceCode - original source @param {BuildingState} state - state representing the current building tree state during the recursion @returns {Array} array containing the html output and bindings for the current node
[ "Create", "only", "a", "dynamic", "tag", "node", "with", "generating", "a", "custom", "selector", "and", "its", "bindings" ]
fa9cea9cf6b8a369e057c966c4e2698940a3fafc
https://github.com/riot/compiler/blob/fa9cea9cf6b8a369e057c966c4e2698940a3fafc/src/generators/template/builder.js#L74-L93
19,391
riot/compiler
src/generators/template/builder.js
parseNode
function parseNode(sourceNode, sourceFile, sourceCode, state) { // static nodes have no bindings if (isStaticNode(sourceNode)) return [nodeToString(sourceNode), []] return createDynamicNode(sourceNode, sourceFile, sourceCode, state) }
javascript
function parseNode(sourceNode, sourceFile, sourceCode, state) { // static nodes have no bindings if (isStaticNode(sourceNode)) return [nodeToString(sourceNode), []] return createDynamicNode(sourceNode, sourceFile, sourceCode, state) }
[ "function", "parseNode", "(", "sourceNode", ",", "sourceFile", ",", "sourceCode", ",", "state", ")", "{", "// static nodes have no bindings", "if", "(", "isStaticNode", "(", "sourceNode", ")", ")", "return", "[", "nodeToString", "(", "sourceNode", ")", ",", "[", "]", "]", "return", "createDynamicNode", "(", "sourceNode", ",", "sourceFile", ",", "sourceCode", ",", "state", ")", "}" ]
Parse a node trying to extract its template and bindings @param {RiotParser.Node} sourceNode - any kind of node parsed via riot parser @param {stiring} sourceFile - source file path @param {string} sourceCode - original source @param {BuildingState} state - state representing the current building tree state during the recursion @returns {Array} array containing the html output and bindings for the current node
[ "Parse", "a", "node", "trying", "to", "extract", "its", "template", "and", "bindings" ]
fa9cea9cf6b8a369e057c966c4e2698940a3fafc
https://github.com/riot/compiler/blob/fa9cea9cf6b8a369e057c966c4e2698940a3fafc/src/generators/template/builder.js#L103-L107
19,392
riot/compiler
src/generators/template/bindings/simple.js
createAttributeExpressions
function createAttributeExpressions(sourceNode, sourceFile, sourceCode) { return findDynamicAttributes(sourceNode) .map(attribute => createExpression(attribute, sourceFile, sourceCode)) }
javascript
function createAttributeExpressions(sourceNode, sourceFile, sourceCode) { return findDynamicAttributes(sourceNode) .map(attribute => createExpression(attribute, sourceFile, sourceCode)) }
[ "function", "createAttributeExpressions", "(", "sourceNode", ",", "sourceFile", ",", "sourceCode", ")", "{", "return", "findDynamicAttributes", "(", "sourceNode", ")", ".", "map", "(", "attribute", "=>", "createExpression", "(", "attribute", ",", "sourceFile", ",", "sourceCode", ")", ")", "}" ]
Create the attribute expressions @param {RiotParser.Node} sourceNode - any kind of node parsed via riot parser @param {stiring} sourceFile - source file path @param {string} sourceCode - original source @returns {Array} array containing all the attribute expressions
[ "Create", "the", "attribute", "expressions" ]
fa9cea9cf6b8a369e057c966c4e2698940a3fafc
https://github.com/riot/compiler/blob/fa9cea9cf6b8a369e057c966c4e2698940a3fafc/src/generators/template/bindings/simple.js#L38-L41
19,393
riot/compiler
src/generators/template/bindings/simple.js
createTextNodeExpressions
function createTextNodeExpressions(sourceNode, sourceFile, sourceCode) { const childrenNodes = getChildrenNodes(sourceNode) return childrenNodes .filter(isTextNode) .filter(hasExpressions) .map(node => createExpression( node, sourceFile, sourceCode, childrenNodes.indexOf(node) )) }
javascript
function createTextNodeExpressions(sourceNode, sourceFile, sourceCode) { const childrenNodes = getChildrenNodes(sourceNode) return childrenNodes .filter(isTextNode) .filter(hasExpressions) .map(node => createExpression( node, sourceFile, sourceCode, childrenNodes.indexOf(node) )) }
[ "function", "createTextNodeExpressions", "(", "sourceNode", ",", "sourceFile", ",", "sourceCode", ")", "{", "const", "childrenNodes", "=", "getChildrenNodes", "(", "sourceNode", ")", "return", "childrenNodes", ".", "filter", "(", "isTextNode", ")", ".", "filter", "(", "hasExpressions", ")", ".", "map", "(", "node", "=>", "createExpression", "(", "node", ",", "sourceFile", ",", "sourceCode", ",", "childrenNodes", ".", "indexOf", "(", "node", ")", ")", ")", "}" ]
Create the text node expressions @param {RiotParser.Node} sourceNode - any kind of node parsed via riot parser @param {stiring} sourceFile - source file path @param {string} sourceCode - original source @returns {Array} array containing all the text node expressions
[ "Create", "the", "text", "node", "expressions" ]
fa9cea9cf6b8a369e057c966c4e2698940a3fafc
https://github.com/riot/compiler/blob/fa9cea9cf6b8a369e057c966c4e2698940a3fafc/src/generators/template/bindings/simple.js#L50-L62
19,394
riot/compiler
src/generators/template/index.js
extendTemplateProperty
function extendTemplateProperty(ast, sourceFile, sourceCode, sourceNode) { types.visit(ast, { visitProperty(path) { if (path.value.key.value === TAG_TEMPLATE_PROPERTY) { path.value.value = builders.functionExpression( null, [ TEMPLATE_FN, EXPRESSION_TYPES, BINDING_TYPES, GET_COMPONENT_FN ].map(builders.identifier), builders.blockStatement([ builders.returnStatement( callTemplateFunction( ...build( createRootNode(sourceNode), sourceFile, sourceCode ) ) ) ]) ) return false } this.traverse(path) } }) return ast }
javascript
function extendTemplateProperty(ast, sourceFile, sourceCode, sourceNode) { types.visit(ast, { visitProperty(path) { if (path.value.key.value === TAG_TEMPLATE_PROPERTY) { path.value.value = builders.functionExpression( null, [ TEMPLATE_FN, EXPRESSION_TYPES, BINDING_TYPES, GET_COMPONENT_FN ].map(builders.identifier), builders.blockStatement([ builders.returnStatement( callTemplateFunction( ...build( createRootNode(sourceNode), sourceFile, sourceCode ) ) ) ]) ) return false } this.traverse(path) } }) return ast }
[ "function", "extendTemplateProperty", "(", "ast", ",", "sourceFile", ",", "sourceCode", ",", "sourceNode", ")", "{", "types", ".", "visit", "(", "ast", ",", "{", "visitProperty", "(", "path", ")", "{", "if", "(", "path", ".", "value", ".", "key", ".", "value", "===", "TAG_TEMPLATE_PROPERTY", ")", "{", "path", ".", "value", ".", "value", "=", "builders", ".", "functionExpression", "(", "null", ",", "[", "TEMPLATE_FN", ",", "EXPRESSION_TYPES", ",", "BINDING_TYPES", ",", "GET_COMPONENT_FN", "]", ".", "map", "(", "builders", ".", "identifier", ")", ",", "builders", ".", "blockStatement", "(", "[", "builders", ".", "returnStatement", "(", "callTemplateFunction", "(", "...", "build", "(", "createRootNode", "(", "sourceNode", ")", ",", "sourceFile", ",", "sourceCode", ")", ")", ")", "]", ")", ")", "return", "false", "}", "this", ".", "traverse", "(", "path", ")", "}", "}", ")", "return", "ast", "}" ]
Extend the AST adding the new template property containing our template call to render the component @param { Object } ast - current output ast @param { stiring } sourceFile - source file path @param { string } sourceCode - original source @param { Object } sourceNode - node generated by the riot compiler @returns { Object } the output ast having the "template" key
[ "Extend", "the", "AST", "adding", "the", "new", "template", "property", "containing", "our", "template", "call", "to", "render", "the", "component" ]
fa9cea9cf6b8a369e057c966c4e2698940a3fafc
https://github.com/riot/compiler/blob/fa9cea9cf6b8a369e057c966c4e2698940a3fafc/src/generators/template/index.js#L15-L48
19,395
riot/compiler
src/generators/javascript/index.js
extendTagProperty
function extendTagProperty(ast, exportDefaultNode) { types.visit(ast, { visitProperty(path) { if (path.value.key.value === TAG_LOGIC_PROPERTY) { path.value.value = exportDefaultNode.declaration return false } this.traverse(path) } }) return ast }
javascript
function extendTagProperty(ast, exportDefaultNode) { types.visit(ast, { visitProperty(path) { if (path.value.key.value === TAG_LOGIC_PROPERTY) { path.value.value = exportDefaultNode.declaration return false } this.traverse(path) } }) return ast }
[ "function", "extendTagProperty", "(", "ast", ",", "exportDefaultNode", ")", "{", "types", ".", "visit", "(", "ast", ",", "{", "visitProperty", "(", "path", ")", "{", "if", "(", "path", ".", "value", ".", "key", ".", "value", "===", "TAG_LOGIC_PROPERTY", ")", "{", "path", ".", "value", ".", "value", "=", "exportDefaultNode", ".", "declaration", "return", "false", "}", "this", ".", "traverse", "(", "path", ")", "}", "}", ")", "return", "ast", "}" ]
Extend the AST adding the new tag method containing our tag sourcecode @param { Object } ast - current output ast @param { Object } exportDefaultNode - tag export default node @returns { Object } the output ast having the "tag" key extended with the content of the export default
[ "Extend", "the", "AST", "adding", "the", "new", "tag", "method", "containing", "our", "tag", "sourcecode" ]
fa9cea9cf6b8a369e057c966c4e2698940a3fafc
https://github.com/riot/compiler/blob/fa9cea9cf6b8a369e057c966c4e2698940a3fafc/src/generators/javascript/index.js#L44-L57
19,396
riot/compiler
src/generators/template/bindings/tag.js
groupSlots
function groupSlots(sourceNode) { return getChildrenNodes(sourceNode).reduce((acc, node) => { const slotAttribute = findSlotAttribute(node) if (slotAttribute) { acc[slotAttribute.value] = node } else { acc.default = createRootNode({ nodes: [...getChildrenNodes(acc.default), node] }) } return acc }, { default: null }) }
javascript
function groupSlots(sourceNode) { return getChildrenNodes(sourceNode).reduce((acc, node) => { const slotAttribute = findSlotAttribute(node) if (slotAttribute) { acc[slotAttribute.value] = node } else { acc.default = createRootNode({ nodes: [...getChildrenNodes(acc.default), node] }) } return acc }, { default: null }) }
[ "function", "groupSlots", "(", "sourceNode", ")", "{", "return", "getChildrenNodes", "(", "sourceNode", ")", ".", "reduce", "(", "(", "acc", ",", "node", ")", "=>", "{", "const", "slotAttribute", "=", "findSlotAttribute", "(", "node", ")", "if", "(", "slotAttribute", ")", "{", "acc", "[", "slotAttribute", ".", "value", "]", "=", "node", "}", "else", "{", "acc", ".", "default", "=", "createRootNode", "(", "{", "nodes", ":", "[", "...", "getChildrenNodes", "(", "acc", ".", "default", ")", ",", "node", "]", "}", ")", "}", "return", "acc", "}", ",", "{", "default", ":", "null", "}", ")", "}" ]
Find the slots in the current component and group them under the same id @param {RiotParser.Node.Tag} sourceNode - the custom tag @returns {Object} object containing all the slots grouped by name
[ "Find", "the", "slots", "in", "the", "current", "component", "and", "group", "them", "under", "the", "same", "id" ]
fa9cea9cf6b8a369e057c966c4e2698940a3fafc
https://github.com/riot/compiler/blob/fa9cea9cf6b8a369e057c966c4e2698940a3fafc/src/generators/template/bindings/tag.js#L34-L50
19,397
riot/compiler
src/generators/template/bindings/tag.js
buildSlot
function buildSlot(id, sourceNode, sourceFile, sourceCode) { const cloneNode = { ...sourceNode, // avoid to render the slot attribute attributes: getNodeAttributes(sourceNode).filter(attribute => attribute.name !== SLOT_ATTRIBUTE) } const [html, bindings] = build(cloneNode, sourceFile, sourceCode) return builders.objectExpression([ simplePropertyNode(BINDING_ID_KEY, builders.literal(id)), simplePropertyNode(BINDING_HTML_KEY, builders.literal(html)), simplePropertyNode(BINDING_BINDINGS_KEY, builders.arrayExpression(bindings)) ]) }
javascript
function buildSlot(id, sourceNode, sourceFile, sourceCode) { const cloneNode = { ...sourceNode, // avoid to render the slot attribute attributes: getNodeAttributes(sourceNode).filter(attribute => attribute.name !== SLOT_ATTRIBUTE) } const [html, bindings] = build(cloneNode, sourceFile, sourceCode) return builders.objectExpression([ simplePropertyNode(BINDING_ID_KEY, builders.literal(id)), simplePropertyNode(BINDING_HTML_KEY, builders.literal(html)), simplePropertyNode(BINDING_BINDINGS_KEY, builders.arrayExpression(bindings)) ]) }
[ "function", "buildSlot", "(", "id", ",", "sourceNode", ",", "sourceFile", ",", "sourceCode", ")", "{", "const", "cloneNode", "=", "{", "...", "sourceNode", ",", "// avoid to render the slot attribute", "attributes", ":", "getNodeAttributes", "(", "sourceNode", ")", ".", "filter", "(", "attribute", "=>", "attribute", ".", "name", "!==", "SLOT_ATTRIBUTE", ")", "}", "const", "[", "html", ",", "bindings", "]", "=", "build", "(", "cloneNode", ",", "sourceFile", ",", "sourceCode", ")", "return", "builders", ".", "objectExpression", "(", "[", "simplePropertyNode", "(", "BINDING_ID_KEY", ",", "builders", ".", "literal", "(", "id", ")", ")", ",", "simplePropertyNode", "(", "BINDING_HTML_KEY", ",", "builders", ".", "literal", "(", "html", ")", ")", ",", "simplePropertyNode", "(", "BINDING_BINDINGS_KEY", ",", "builders", ".", "arrayExpression", "(", "bindings", ")", ")", "]", ")", "}" ]
Create the slot entity to pass to the riot-dom bindings @param {string} id - slot id @param {RiotParser.Node.Tag} sourceNode - slot root node @param {stiring} sourceFile - source file path @param {string} sourceCode - original source @returns {AST.Node} ast node containing the slot object properties
[ "Create", "the", "slot", "entity", "to", "pass", "to", "the", "riot", "-", "dom", "bindings" ]
fa9cea9cf6b8a369e057c966c4e2698940a3fafc
https://github.com/riot/compiler/blob/fa9cea9cf6b8a369e057c966c4e2698940a3fafc/src/generators/template/bindings/tag.js#L60-L73
19,398
riot/compiler
src/generators/template/expressions/text.js
generateLiteralStringChunksFromNode
function generateLiteralStringChunksFromNode(node, sourceCode) { return node.expressions.reduce((chunks, expression, index) => { const start = index ? node.expressions[index - 1].end : node.start chunks.push(sourceCode.substring(start, expression.start)) // add the tail to the string if (index === node.expressions.length - 1) chunks.push(sourceCode.substring(expression.end, node.end)) return chunks }, []).map(str => node.unescape ? unescapeChar(str, node.unescape) : str) }
javascript
function generateLiteralStringChunksFromNode(node, sourceCode) { return node.expressions.reduce((chunks, expression, index) => { const start = index ? node.expressions[index - 1].end : node.start chunks.push(sourceCode.substring(start, expression.start)) // add the tail to the string if (index === node.expressions.length - 1) chunks.push(sourceCode.substring(expression.end, node.end)) return chunks }, []).map(str => node.unescape ? unescapeChar(str, node.unescape) : str) }
[ "function", "generateLiteralStringChunksFromNode", "(", "node", ",", "sourceCode", ")", "{", "return", "node", ".", "expressions", ".", "reduce", "(", "(", "chunks", ",", "expression", ",", "index", ")", "=>", "{", "const", "start", "=", "index", "?", "node", ".", "expressions", "[", "index", "-", "1", "]", ".", "end", ":", "node", ".", "start", "chunks", ".", "push", "(", "sourceCode", ".", "substring", "(", "start", ",", "expression", ".", "start", ")", ")", "// add the tail to the string", "if", "(", "index", "===", "node", ".", "expressions", ".", "length", "-", "1", ")", "chunks", ".", "push", "(", "sourceCode", ".", "substring", "(", "expression", ".", "end", ",", "node", ".", "end", ")", ")", "return", "chunks", "}", ",", "[", "]", ")", ".", "map", "(", "str", "=>", "node", ".", "unescape", "?", "unescapeChar", "(", "str", ",", "node", ".", "unescape", ")", ":", "str", ")", "}" ]
Generate the pure immutable string chunks from a RiotParser.Node.Text @param {RiotParser.Node.Text} node - riot parser text node @param {string} sourceCode sourceCode - source code @returns {Array} array containing the immutable string chunks
[ "Generate", "the", "pure", "immutable", "string", "chunks", "from", "a", "RiotParser", ".", "Node", ".", "Text" ]
fa9cea9cf6b8a369e057c966c4e2698940a3fafc
https://github.com/riot/compiler/blob/fa9cea9cf6b8a369e057c966c4e2698940a3fafc/src/generators/template/expressions/text.js#L20-L32
19,399
riot/compiler
src/generators/template/utils.js
replacePathScope
function replacePathScope(path, property) { path.replace(builders.memberExpression( scope, property, false )) }
javascript
function replacePathScope(path, property) { path.replace(builders.memberExpression( scope, property, false )) }
[ "function", "replacePathScope", "(", "path", ",", "property", ")", "{", "path", ".", "replace", "(", "builders", ".", "memberExpression", "(", "scope", ",", "property", ",", "false", ")", ")", "}" ]
Replace the path scope with a member Expression @param { types.NodePath } path - containing the current node visited @param { types.Node } property - node we want to prefix with the scope identifier @returns {undefined} this is a void function
[ "Replace", "the", "path", "scope", "with", "a", "member", "Expression" ]
fa9cea9cf6b8a369e057c966c4e2698940a3fafc
https://github.com/riot/compiler/blob/fa9cea9cf6b8a369e057c966c4e2698940a3fafc/src/generators/template/utils.js#L72-L78