contextCompare function

float contextCompare(target, label, comparisonType)

target selector

intra Checks against labeled shapes in the same shape tree, that is, from the same initial shape.
inter Checks against labeled shapes in other shape trees, that is, generated by other initial shapes in the neighborhood.
all Checks both intra and inter.

label string The context query is performed only on shapes that match the requested label. It must not be empty. If the label is empty, 0 is returned.

comparisonType selector

world.northernmostRanks shapes by their northernmost bounds starting from the northernmost.
world.southernmostRanks shapes by their southernmost bounds starting from the southernmost.
world.easternmostRanks shapes by their easternmost bounds starting from the easternmost.
world.westernmostRanks shapes by their westernmost bounds starting from the westernmost.
world.highestRanks shapes by their highest bounds starting from the highest.
world.lowestRanks shapes by their lowest bounds starting from the lowest.
area.largestRanks shapes by their areas starting from the largest.
area.smallestRanks shapes by their areas starting from the smallest.

Returns the rank of the current shape among all shapes that match the given label. The comparison is performed with respect to comparisonType. Ranks are 0-based. If several shapes share an equal comparison value, the lowest possible rank is returned. If no shape is found matching the specified label, 0 is returned.

A context query that returns the rank of the current shape geometry among other labeled shape geometries according to a specific comparator.

Learn more about important characteristics for context queries in conditions and inter context.
Each label operation does not label the current shape. Instead, it creates a new labeled shape that counts as one rank position separately.

Related

Example

contextCompare
Lot --> extrude(rand(10)) label("label") Color

Color -->
    case contextCompare(inter, "label", world.highest) == 0 :
        color(1,0,0)
    case contextCompare(inter, "label", world.lowest) == 0 :
        color(0,1,0)
    else :
        color(0,0,1)

This example applies the Lot rule to a set of initial shapes, using inter context. Each lot is extruded by a random value and labeled with "label". The highest geometry is colored red. In the second case statement, all geometries share the lowest ranking, so the remaining geometries are colored green.