# LayerIndex

The `LayerIndex` type is used to specify which conductor layer in the board stackup that a particular statement or property affects.

## Outline

``````
defstruct LayerIndex :
index:Int
side:Side

defn LayerIndex (index:Int, side:Side = Top) -> LayerIndex:
...

``````

The `LayerIndex` type expects two arguments:

1. `index` - If we consider the conductor layers in board stackup an zero-indexed array, the `index` is the offset into the array from either the `Top` or the `Bottom`.
2. `side` - This parameter determines whether the `index` applies from the `Top` going down, or from the `Bottom` going up.

## Symmetry of Top and Bottom Indices

The `Bottom` side indices can be considered a reverse indexing scheme.

Notice that there is a way to index every layer in the stackup in either direction.

## Shortcuts based on `Side`

In some applications of the `LayerIndex` type, you will often see the type `LayerIndex|Side` used. This means that the user can pass either a `LayerIndex` or a `Side` parameter in the form of `Top` or `Bottom` enumerated values.

These `Side` values are a shortcut for:

1. `Top` => `LayerIndex(0, Top)`
2. `Bottom` => `LayerIndex(0, Bottom)`

## Operators

Currently the `plus` and `minus` operators are defined for the `LayerIndex` and `Side` types. This provides a short cut for indexing:

``````
val inner-1 = Top + 1
println("Inner 1: %_" % [inner-1])

val inner-N-1 = Bottom - 1
println("Inner N-1: %_" % [inner-N-1])

val inner-skip = inner-1 + 2
println("Inner Skip: %_" % [inner-skip])

``````

When run this will generate:

``````Inner 1: LayerIndex(1)
Inner N-1: LayerIndex(1, Bottom)
Inner Skip: LayerIndex(3)
``````