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

Method set

src/strands/strands_node.js:187–215  ·  view source on GitHub ↗
(index, value)

Source from the content-addressed store, hash-verified

185 }
186
187 set(index, value) {
188 // Validate baseType is 'storage' and has _originalIdentifier
189 const nodeData = getNodeDataFromID(this.strandsContext.dag, this.id);
190 if (nodeData.baseType !== 'storage') {
191 throw new Error('set() can only be used on storage buffers');
192 }
193 if (!this._originalIdentifier) {
194 throw new Error('set() can only be used on storage buffers with an identifier');
195 }
196
197 // If value is a plain object (struct literal), expand to per-field assignments
198 // e.g. buf[idx] = { position: pos, velocity: vel }
199 // becomes buf[idx].position = pos; buf[idx].velocity = vel;
200 if (value !== null && typeof value === 'object' && !value.isStrandsNode && this._schema) {
201 const proxy = createStructArrayElementProxy(this.strandsContext, this, index, this._schema);
202 for (const [fieldName, fieldValue] of Object.entries(value)) {
203 proxy[fieldName] = fieldValue;
204 }
205 return this;
206 }
207
208 // Create array assignment node: buffer.set(index, value) -> buffer[index] = value
209 // This creates an ASSIGNMENT node and records it in the CFG basic block
210 // CFG preserves sequential order, preventing reordering of assignments
211 arrayAssignmentNode(this.strandsContext, this, index, value);
212
213 // Return this for chaining
214 return this;
215 }
216}
217export function createStrandsNode(id, dimension, strandsContext, onRebind) {
218 return new Proxy(

Callers 6

setFunction · 0.45
addCopyingAndReturnFunction · 0.45
CallExpressionFunction · 0.45
getOrCreateUniformNodeFunction · 0.45
initGlobalStrandsAPIFunction · 0.45
setupHookFunction · 0.45

Calls 3

getNodeDataFromIDFunction · 0.90
arrayAssignmentNodeFunction · 0.90

Tested by

no test coverage detected