How to do it...

  1. Declare the Position data class with x, y, z  properties related to the current position in the Cartesian coordinates system:
data class Position(val x: Float, val y: Float, val z: Float)
  1. Add a plus operator implementation for the Position class:
data class Position(val x: Float, val y: Float, val z: Float) {
operator fun plus(other: Position) =
Position(x + other.x, y + other.y, z + other.z)
}
  1. Overload the minus operator:
data class Position(val x: Float, val y: Float, val z: Float) {
operator fun plus(other: Position) =
Position(x + other.x, y + other.y, z + other.z)

operator fun minus(other: Position) =
Position(x - other.x, y - other.y, z - other.z)
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.0.133