- Kotlin Standard Library Cookbook
- Samuel Urbanowicz
- 122字
- 2021-07-23 19:06:00
How to do it...
- 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)
}
推薦閱讀
- SPSS數據挖掘與案例分析應用實踐
- Mastering JavaScript Functional Programming
- GeoServer Cookbook
- Learning Flask Framework
- Apache Hive Essentials
- OpenNI Cookbook
- MATLAB 2020從入門到精通
- 大學計算機基礎實驗指導
- Create React App 2 Quick Start Guide
- 寫給程序員的Python教程
- R語言數據可視化:科技圖表繪制
- Hack與HHVM權威指南
- Sitecore Cookbook for Developers
- MATLAB 2020 GUI程序設計從入門到精通
- Learning D3.js 5 Mapping(Second Edition)