- 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)
- 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)
}
- 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.