> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dairy.foundation/llms.txt
> Use this file to discover all available pages before exploring further.

# Defining custom units

The `Unit` system makes it easy to define your own custom `Unit`s in a
pre-existing `Unit` family.

Lets look at defining our own `DistanceUnit`s for use with `Distance`s

<CodeGroup>
  ```java Java theme={null}
  private enum MyDistanceUnits implements DistanceUnit {
  	FATHOM(1828.8),
  	LEAGUE(5556000),
  	TILE(609.6);
  	private final double toCommonRatio;
  	MyDistanceUnits(double toCommonRatio) {
  		this.toCommonRatio = toCommonRatio;
  	}
  	@Override
  	public double getToCommonRatio() {
  		return toCommonRatio;
  	}
  }
  ```

  ```kt Kotlin theme={null}
  enum class MyDistanceUnits(override val toCommonRatio: Double) : DistanceUnit {
  	FATHOM(1828.8),
  	LEAGUE(5556000.0),
  	TILE(609.6)
  }
  ```
</CodeGroup>

`DistanceUnit` is the unit family that `Distance` uses. Its an interface, so we
can implement it on an enum.

All we need to do is define a ratio of this unit, to millimeters.

Essentially: let `x` be some value represented in unit `u`, `r` be unit `u`'s
`toCommonRatio`, `c` be the common unit for the unit family `u` belongs to.
Then, `x / r` is equal to `x` in `c`.

For example: `DistanceUnits.METER` has a `toCommonRatio` of `1000.0` as to
convert Meters to Millimeters, you divide by 1000.

Dairy does this for the enums `DistanceUnits`, `CurrentUnits` and `AngleUnits`.

now:

<CodeGroup>
  ```java Java theme={null}
  Distances.mm(10).into(MyDistanceUnits.TILE);
  ```

  ```kt Kotlin theme={null}
  10.mm.into(MyDistanceUnits.TILE);
  ```
</CodeGroup>

While `FATHOM` and `LEAGUE` might be totally useless units, `TILE` is genuinely
useful! This season, try doing all your pathplanning using `Distance`s using
measurements relative to the size of your practice field's tiles, then, when you
go to competition, remeasure the size of the tiles, and update a single number
in your code, to instantly remap your auto to the changed tile size. Just
remember to reset it after the event.
