Conditional rule

It is possible to generate different successors for different conditions. Conditions can be expressed by rule parameters, shape attributes, or geometry functions.

PredecessorShape --> 
                     case condition1 : Successor1 
                     case condition2 : Successor2
                     ...
                     else: SuccessorN

Example 1

Footprint(type) -->
      case type == "residential" : extrude(10)
      case geometry.area/2 < 200 : extrude(30)
      else : NIL

In this example, the Footprint rule takes one parameter, type, of type string. If the string is equal to "residental", the first successor is taken (in other words, the current shape is extruded by 10 units).

  • If the string is not equal to "residential", and the area of the current shape's geometry is smaller than 400, the second successor is taken (in other words, the current shape is extruded by 30 units).
  • If none of the two conditions above is true, the third successor is taken and a NIL shape is generated (NIL is a special shape symbol and means that no shape is generated).
  • Conditions can arbitrarily be combined with operators && and || (Boolean and/or operations), and mathematical expressions can be used.
  • It is also possible to nest conditions. There is no limit on the nesting level.

Example 2

Footprint(type) -->
      case type == "residential" || type == "park": 
        case geometry.area/2 < 200 && geometry.area > 10 : extrude(10)
        else: extrude(15)
      case type == "industrial" : extrude(100)
      else : NIL

Example 2 demonstrates nested conditions and Boolean operations.

Note:

The and the statements must build a consecutive block and cannot be interrupted with successors (like a block, and they are different from if statements in well-known programming languages).

The case and the else statements must build a consecutive block and cannot be interrupted with successors. They are similar to switch-case blocks and different from if statements in well-known programming languages.


In this topic
  1. Example 1
  2. Example 2