326925 (5) [Avatar] Offline
#1
I am on Listing 7.3 page 176.
operator fun Point.times(scale: Double): Point {

return Point((scale*x ).toInt(), ( scale*y).toInt())
}
I am trying to commutate the operation times.
The author says use:
operator fun Double.times(p: Point) : Point
There is no body to this function however
How do you write (p* 1.5) as well as (1.5*p).
Thanks
Norman
Mark Elston (111) [Avatar] Offline
#2
I would suspect you have to create two different extension functions. One for Point and one for Double. In fact, the error message you mentioned indicated as much.
326925 (5) [Avatar] Offline
#3
operator fun Double.times(psmilieoint)smilieoint {
val z = toDouble()
val t = ((p.x) * z).toInt()
val q = ((p.y) * z).toInt()
return Point(t, q)
}