0

I needed to compare speeds in my game therefore I used an extension to declare the '>' and '<'symbols. My code is seen below:

extension CGVector {
var speed: CGFloat {
    return hypot(dx, dy)
}

static func > (lhs: CGVector, rhs: CGVector) -> Bool {
    return lhs.speed > rhs.speed
}

static func < (lhs: CGVector, rhs: CGVector) -> Bool {
    return lhs.speed < rhs.speed
}

After some research I understood I should use the code above and it worked. However Im confused at a parts of the code. What does lhs and rhs stand for?

Thanks

Knight0fDragon
  • 16,609
  • 2
  • 23
  • 44
  • 2
    That are the function *parameters.* Here "lhs" stands for "left-hand side" but you can name them as you like: `static func > (foo: CGVector, bar: CGVector) -> Bool { return foo.speed > bar.speed }` – See https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Functions.html – Martin R Nov 03 '16 at 20:26
  • ok understood thanks –  Nov 03 '16 at 20:31
  • 3
    Unrelated to your question, but with these definitions you can have that for two vectors `v1` and `v2`, *none* of `v1v2` is true, so I doubt the usefulness. – Martin R Nov 03 '16 at 20:32

0 Answers0