本文整理汇总了TypeScript中lodash-es/partialRight.default函数的典型用法代码示例。如果您正苦于以下问题:TypeScript default函数的具体用法?TypeScript default怎么用?TypeScript default使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了default函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: generateGlsl
function generateGlsl(codeAst: ICodeAst, tables: ISymbolTables, glslFuncs: string[]): string {
const generateNode = (ast) => {
if (ast instanceof Ast.BinaryExpr) {
return "(" + generateNode(ast.leftOperand) + ast.operator + generateNode(ast.rightOperand) + ")";
}
if (ast instanceof Ast.UnaryExpr) {
return "(" + ast.operator + generateNode(ast.operand) + ")";
}
if (ast instanceof Ast.FuncCall) {
if (ast.preComputeUniformName) {
return "(" + ast.preComputeUniformName + ")";
}
switch (ast.funcName) {
case "above":
return [
"(",
generateNode(ast.args[0]),
">",
generateNode(ast.args[1]),
"?1.0:0.0)",
].join("");
case "below":
return [
"(",
generateNode(ast.args[0]),
"<",
generateNode(ast.args[1]),
"?1.0:0.0)",
].join("");
case "equal":
return [
"(",
generateNode(ast.args[0]),
"==",
generateNode(ast.args[1]),
"?1.0:0.0)",
].join("");
case "if":
return [
"(",
generateNode(ast.args[0]),
"!=0.0?",
generateNode(ast.args[1]),
":",
generateNode(ast.args[2]),
")",
].join("");
case "select": {
const selectExpr = generateNode(ast.args[0]);
const generateSelect = (args, i) => {
if (args.length === 1) {
return generateNode(args[0]);
} else {
return [
"((" + selectExpr + " === " + i + ")?",
"(" + generateNode(args[0]) + "):",
"(" + generateSelect(takeRight(args, args.length - 1), i + 1) + "))",
].join("");
}
};
return generateSelect(takeRight(ast.args, ast.args.length - 1), 0);
}
case "sqr":
return "(pow((" + generateNode(ast.args[0]) + "), 2))";
case "band":
return "(float((" + generateNode(ast.args[0]) + ")&&(" + generateNode(ast.args[1]) + ")))";
case "bor":
return "(float((" + generateNode(ast.args[0]) + ")||(" + generateNode(ast.args[1]) + ")))";
case "bnot":
return "(float(!(" + generateNode(ast.args[0]) + ")))";
case "invsqrt":
return "(inversesqrt(" + generateNode(ast.args[0]) + "))";
case "atan2":
return "(atan((" + generateNode(ast.args[0]) + "),(" + generateNode(ast.args[1]) + "))";
default: {
const args = map(ast.args, (arg) => generateNode(arg)).join(",");
return "(" + ast.funcName + "(" + args + "))";
}
}
}
if (ast instanceof Ast.Assignment) {
return generateNode(ast.lhs) + "=" + generateNode(ast.expr);
}
if (ast instanceof Ast.Program) {
const stmts = map(ast.statements, (stmt) => generateNode(stmt));
return stmts.join(";\n") + ";";
}
if (ast instanceof Ast.PrimaryExpr && ast.type === "VALUE") {
return glslFloatRepr(ast.value);
}
if (ast instanceof Ast.PrimaryExpr && ast.type === "CONST") {
return translateConstants(ast.value).toString();
}
if (ast instanceof Ast.PrimaryExpr && (ast.type === "ID" || ast.type === "REG")) {
return ast.value;
}
};
let glslCode = [];
//.........这里部分代码省略.........
示例2: parseColor
export function parseColor(color: string | Color): Color {
if (isColor(color)) {
return color;
} else {
color = color.toLowerCase();
let match = color.match(/^#([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})$/);
if (match) {
return flow([
pr(takeRight, 3),
pr(map, (channel) => {
return parseInt(channel, 16);
}),
])(match) as Color;
}
match = color.match(/^rgb\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)$/);
if (match) {
return flow([
pr(takeRight, 3),
pr(map, (channel) => {
return Math.min(parseInt(channel, 10), 255);
}),
])(match) as Color;
}
}
throw new Error("Invalid Color Format");
}
示例3: processAst
function processAst(
codeAst: ICodeAst,
jsFuncs: string[],
glslFuncs: string[],
extraNonUniforms: string[],
): ISymbolTables {
const funcCall: {[name: string]: string[]} = {};
const variable: {[name: string]: string[]} = {};
const register: {[name: string]: string[]} = {};
const preCompute: {[uniformName: string]: string[]} = {};
let preComputeCounter = 0;
const processNode = (ast, name) => {
if (ast instanceof Ast.Program) {
for (const statement of ast.statements) {
processNode(statement, name);
}
} else if (ast instanceof Ast.BinaryExpr) {
processNode(ast.leftOperand, name);
processNode(ast.rightOperand, name);
} else if (ast instanceof Ast.UnaryExpr) {
processNode(ast.operand, name);
} else if (ast instanceof Ast.FuncCall) {
checkFunc(ast);
// if its a precomputable function to be generated in glsl
// then build a table entry
if (glslFuncs.indexOf(name) >= 0 && glslPreComputeFuncs.indexOf(ast.funcName) >= 0) {
const args = ast.args;
if (!isStaticExprList(args)) {
throw new Error(
`Non Pre-Computable arguments for ${ast.funcName} in shader code, use variables or constants`,
);
}
const entry = [ast.funcName].concat(map(args, (arg) => arg.value));
let uniformName;
for (const key in preCompute) {
if (isEqual(preCompute[key], entry)) {
uniformName = key;
break;
}
}
if (!uniformName) {
uniformName = "__PC_" + ast.funcName + "_" + preComputeCounter++;
preCompute[uniformName] = entry;
}
ast.preComputeUniformName = uniformName;
}
funcCall[name].push(ast.funcName);
for (const arg of ast.args) {
processNode(arg, name);
}
} else if (ast instanceof Ast.Assignment) {
processNode(ast.lhs, name);
processNode(ast.expr, name);
} else if (ast instanceof Ast.PrimaryExpr && ast.type === "ID") {
variable[name].push(ast.value);
} else if (ast instanceof Ast.PrimaryExpr && ast.type === "REG") {
register[name].push(ast.value);
}
};
for (const name in codeAst) {
if (!codeAst.hasOwnProperty(name)) {
continue;
}
funcCall[name] = [];
variable[name] = [];
register[name] = [];
processNode(codeAst[name], name);
funcCall[name] = uniq(funcCall[name]);
variable[name] = uniq(variable[name]);
register[name] = uniq(register[name]);
}
const jsVars: string[] = flow([pr(pick, jsFuncs), values, flatten, uniq])(variable);
const glslVars: string[] = flow([pr(pick, glslFuncs), values, flatten, uniq])(variable);
const nonUniforms: string[] = flow([pr(difference, jsVars), pr(union, extraNonUniforms), uniq])(glslVars);
const uniforms: string[] = intersection(glslVars, jsVars);
const glslUsedFuncs: string[] = flow([pr(pick, glslFuncs), values, flatten, uniq])(funcCall);
const glslRegisters: string[] = flow([pr(pick, glslFuncs), values, flatten, uniq])(register);
return {
glslRegisters, glslUsedFuncs, glslVars, jsVars, nonUniforms, preCompute, register, uniforms,
};
}