comp function

float[]string[]bool[] comp(component) { selector operator expression | ... }
float[]string[]bool[] comp(component, scopeAlignment) { selector operator expression | ... }

component, scopeAlignment, selector, operator These parameters are the same as for the comp operation.

expression floatstringbool Expression evaluated per component. All expressions must be of the same type.

Returns an array that contains the evaluated expression for each component.

Like the comp operation, the comp function divides a shape into topological components with respect to component, selector, and operator. In contrast to the operation, the function does not process the selected components with shape operations. Instead, a functional expression is evaluated on each selected component shape and the results are returned as an ordered array.

The returned array has these properties:

  • Its size equals the number of faces, edges, and so on for component set to f, e, and so on.
  • For example, with component set to f, the array contains the value of expression for each face in face-index order.
  • Values from combined component shapes, where operator is =, are copied into all respective index positions.
  • Topological entities not selected by a selector are inserted with a default value: 0, "", or false.
The comp function lets you gather information about the current shape and its components without changing the current shape or adding successor shapes to the shape tree.
The size of the returned array is limited. It can be configured in the Procedural Runtime preferences. The default is 100000.

Related

Explanatory examples

Vertices | Comp shape attributes

comp vertices
const array = comp(v) { all : comp.index }

Lot --> print(array)

(6)[0,1,2,3,4,5]

A shape is split into all six of its vertices. Each vertex component is asked for its component index. These values are then organized in vertex-index order.

Edges | Scope shape attributes

comp edges
edgeLength = scope.sx

const array = comp(e) { border : edgeLength }

(7)[7,15,0,17,15,10,16]

The shape with seven edges is split into its six border edges. Each selected edge component is asked for its length via its scope attribute. Edge 2 is not selected and is therefore inserted with the default value 0.

Face edges | Combine shape operator

comp face edges
const array = comp(fe) { front : comp.sel + comp.index |
                         back  = str(comp.index)       }

(8)[front0,,0,,,0,,front1]

The shape with eight face edges is split into its two front face edges and into a combined shape consisting of two back face edges. The second expression is evaluated only once, but its return value is inserted at all respective back-edge indices. Unselected edges are inserted with the default value "".

Faces | Occlusion query

comp faces
const array = comp(f) { side = touches }

(6)[false,true,true,true,true,false]

The shape with six faces is split into one shape consisting of four side faces. An occlusion query is evaluated once and the result is inserted for all side faces. The remaining faces are inserted with the default value false.

See the setback operation for further applications.