onekiloparsec / SwiftAA

The most comprehensive collection of accurate astronomical algorithms in (C++, Objective-C and) Swift.
http://www.onekiloparsec.dev/
MIT License
171 stars 31 forks source link

Saturn magnitude is still buggy in some cases #76

Open alex-vasenin opened 6 years ago

alex-vasenin commented 6 years ago

Saturn magnitude is still buggy in some cases:

    let jd = JulianDay(year: 2018, month: 1, day: 1) // Could be any date
    let jupiter = Jupiter(julianDay: jd)
    let saturn = Saturn(julianDay: jd)
    let uranus = Uranus(julianDay: jd)
    let neptune = Neptune(julianDay: jd)
    let gasGiants = [jupiter, saturn, uranus, neptune]
    print(saturn.magnitude.value) // Prints 0.479, as expected
    print(gasGiants[1].magnitude.value) // Prints nan !!!

This is one of the very few cases where Swift language itself falls short. Saturn's object is both Planet and Saturn. Planet has it's own magnitude as default implementation of IlluminatedFraction protocol. Saturn has it's own magnitude as computed property. Due to static dispatch Swift calls wrong implementation for magnitude in some cases. More info in SR-103.

onekiloparsec commented 6 years ago

Thanks Alexander, you're really up-to-date with these issues I have a hard time to follow. I remember wondering whether a "filling-empty-space" default implementation would be a good idea or not. It is not. I am focused on other things right now. If you have an idea on how to get around this problem... well, of course, I'm sure you'll submit it here. Thanks again!

onekiloparsec commented 5 years ago

Just checked right now, and this is not yet fixed. Damn.

I would like to keep the default implementation. The solution I see for now is to switch from a var to a func. But this will break APIs.

Oups, no. Funcs won't work either, according to https://bugs.swift.org/browse/SR-103

onekiloparsec commented 5 years ago

print((gasGiants[1] as! Saturn).magnitude.value) works, but this is not satisfactory.