Ruckus
04/24/2018, 7:27 PMclass Basis(
var xx: Double = 1.0, var xy: Double = 0.0, var xz: Double = 0.0,
var yx: Double = 0.0, var yy: Double = 1.0, var yz: Double = 0.0,
var zx: Double = 0.0, var zy: Double = 0.0, var zz: Double = 1.0
) {
constructor(x: Vector3 = Vector3.x(), y: Vector3 = Vector3.y(), z: Vector3 = Vector3.z()) : this(
x.x, x.y, x.z,
y.x, y.y, y.z,
z.x, z.y, z.z
)
companion object {
fun ident() = Basis()
fun scale(x: Double = 1.0, y: Double = 1.0, z: Double = 1.0) = Basis(xx = x, yy = y, zz = z)
}
}
The ident
function in the companion object is calling the secondary constructor, and so is creating extra Vector3
objects when there is no need to. Wouldn't it make more sense to use the primary constructor whenever possible (that is the point of primary, is it not)?