# The Subdivision Split

The split operation can be used to model shapes and to set up geometry by splitting a larger geometry object to smaller ones. The split operation is central to creating designs with the CGA shape rules.

The basic definition for split is split(axis) { selector : operations } (see CGA Reference).

The following examples show the most important possibilities of the split operation. We will start with a simple example and proceed with more advanced ones.

## Simple Resize In this introductory example we place a cuboid on a lot and assign its dimensions. First, we define the length of the cuboid as 5. Then, we run the lot rule, which comprises of a scaling and the inserted geometry. At last, we assign a color in hexadecimal.

```attr cuboid_length = 5
Lot -->
s(cuboid_length,1,1) primitiveCube() color("#84c0fc")
```

The cuboid can be simply resized by assigning another value to the parameter cuboid_length. ```...
attr cuboid_length = 3
...
```

## Split Example 1: Simple Split In the following example, the split operation is introduced:

```attr green = "#46c820"
attr blue2= "#84c0fc"
attr cuboid_length = 5
Lot -->
s(cuboid_length,1,1) primitiveCube() split_example01
split_example01 --> split(x){ 3 : X }
// Value 3 results in a length of three for "X".
// "X" results into a new cuboid with a length of 3.
X --> color("blue2")
```

The operation "split(x) { 3 : X }" stands for: split a geometry along x-axis, cut it at 3 and replace it with the successive cuboid "X". "X" gets color "blue2".

## Split Example 2: Split and Fill In this example the geometry with a length of 5 is split at 3. The resulting cuboids are left, green with a length of 3 and right, blue with a length of 2. The symbol "~1" denotes a float operation. The remaining space of 2 is filled since no other rule is applied and because the float operation.

```attr cuboid_height1 = 2
...
split_example02 --> split(x){ 3 : X | ~1 : X(cuboid_height1) }
// splits into { left geometry with an absolute length of 3 |
// right geometry with a float value of 1 }
X --> color(green) s('1,'1,'1)
// The left X becomes green.
X(a) --> color(blue2) s('1,'a,'1)
// The right X becomes blue and gets a height of 2 through the overload mechanism.
```

The float value ~20 fills the space between the two absolute Xs. ```...
split_example03 --> split(x){ 1: X(1.5) | ~20: Y(1) | 1: X(.5) }
...
```

The next two examples illustrate what happens if multiple float splits are applied: ```...
split_example02 --> split(x){ 3 : X | ~1 : X(cuboid_height1) | ~1 : X(cuboid_height2)}
...
``` ```...
split_example02
--> split(x){ 3 : X | ~1 : X(cuboid_height1) | ~1 : X(cuboid_height2) | ~1 : X(cuboid_height3)}
...
```

If there is no space left for a float operation the corresponding shape is not generated (Z in this case): ```...
split_example02 --> split(x){ 5 : X | ~1 : Z }
...
```

## Split Example 3: Split with Absolute Values This example shows what happens if absolute split values are used ( left 3 and right 1 ). Note that the preceding geometry had a length of 5. After the split the total resulting length is 4.

```...
split_example03 --> split(x){ 3 : X | 1 : X(cuboid_height1) }
...
``` The effect of absolute values within a scope is shown in the following. The resulting shape "Y" gets a length of 1 since there is total length of 5. The rightmost shape "Z" will not be generated at all.

```...
split_example03 --> split(x){ 2 : X | 1 : X | 1 : Z | 2 : Y | 1 : Z }
...
```

No splits will be produced with negative or zero-sized values. Y and rightmost Z are not possible. Leftmost Z will start at 1.5. X is cut at the total length of 5.

```...
split_example03 --> split(x){ 1.5 : X | -2 : Y | 1.5 : Z | 1.5 : X | 0 : Z | 1.5 : X }
...
``` 