within
within
finds pairs of objects that are within a specified distance of each other. It also accepts a filter to further restrict the pairs.
Context | Type |
---|---|
Input | set of objects |
Output | set of (object, object) pairs |
Parameter | Type |
---|---|
radius | number |
Examples
Finds
object(type="bicycle").within(10, type="car")
This example first finds bicycles, then finds pairs where a bicycle is within 10 meters of a car.
The within function also extends the attributes filtering, so you can use this()
to refer to the objects that
are being checked against.
object(type="vehicle").within(100, type="bridge", minClearance<this().get("maxClearance"))
This example checks for bridges that are within 100 meters of vehicles that don't fit under them.
Notes
The function this()
is only available in the parameters of the within
function. It returns an object set containing only a single object - the object from the original set that is being checked against. In the example above, we find the maxClearance from the attributes of the vehicle, and compare those to the minClearance in the attributes of the near bridges.
For efficiency, you should make the set that within
operates on as small as possible. If it doesn't matter which order the objects appear in the set, then choose the ordering of object/near filters so that the group likely to be smallest is chosen by the object filter.