官术网_书友最值得收藏!

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)
}
主站蜘蛛池模板: 湖南省| 新巴尔虎右旗| 灌云县| 资中县| 凤凰县| 禹州市| 祥云县| 获嘉县| 定兴县| 新昌县| 称多县| 五莲县| 荣昌县| 丰都县| 山东省| 新巴尔虎左旗| 琼中| 河西区| 乐昌市| 吴旗县| 连云港市| 溧阳市| 海盐县| 库尔勒市| 阳山县| 六安市| 赤水市| 青阳县| 胶州市| 琼海市| 晋宁县| 吉林市| 灌南县| 宿松县| 德令哈市| 德令哈市| 乌拉特后旗| 南昌县| 万载县| 靖安县| 平遥县|