MCPcopy Index your code
hub / github.com/processing/p5.js / primitiveConstructorNode

Function primitiveConstructorNode

src/strands/ir_builders.js:293–327  ·  view source on GitHub ↗
(strandsContext, typeInfo, dependsOn)

Source from the content-addressed store, hash-verified

291}
292
293export function primitiveConstructorNode(strandsContext, typeInfo, dependsOn) {
294 const cfg = strandsContext.cfg;
295 dependsOn = (Array.isArray(dependsOn) ? dependsOn : [dependsOn])
296 .flat(Infinity)
297 .map(a => {
298 if (
299 a.isStrandsNode &&
300 a.typeInfo().baseType === BaseType.INT &&
301 // TODO: handle ivec inputs instead of just int scalars
302 a.typeInfo().dimension === 1
303 ) {
304 return castToFloat(strandsContext, a);
305 } else {
306 return a;
307 }
308 });
309 const { mappedDependencies, inferredTypeInfo } = mapPrimitiveDepsToIDs(strandsContext, typeInfo, dependsOn);
310
311 const finalType = {
312 // We might have inferred a non numeric type. Currently this is
313 // just used for booleans. Maybe this needs to be something more robust
314 // if we ever want to support inference of e.g. int vectors?
315 baseType: inferredTypeInfo.baseType === BaseType.BOOL
316 ? BaseType.BOOL
317 : typeInfo.baseType,
318 dimension: inferredTypeInfo.dimension
319 };
320
321 const id = constructTypeFromIDs(strandsContext, finalType, mappedDependencies);
322 if (typeInfo.baseType !== BaseType.DEFER) {
323 CFG.recordInBasicBlock(cfg, cfg.currentBlock, id);
324 }
325
326 return { id, dimension: finalType.dimension, components: mappedDependencies };
327}
328
329export function castToFloat(strandsContext, dep) {
330 const { id, dimension } = functionCallNode(

Callers 9

bridgeMethod · 0.90
bridgeSwizzleMethod · 0.90
unaryOpNodeFunction · 0.85
binaryOpNodeFunction · 0.85
setFunction · 0.85
arrayAccessNodeFunction · 0.85
arrayAssignmentNodeFunction · 0.85

Calls 4

castToFloatFunction · 0.85
mapPrimitiveDepsToIDsFunction · 0.85
constructTypeFromIDsFunction · 0.85
typeInfoMethod · 0.80

Tested by

no test coverage detected