Module: Sekki24::Lunar::PhaseFinder
- Defined in:
- lib/sekki24/lunar/phase_finder.rb
Constant Summary collapse
- MEAN_NEW_MOON_EPOCH =
2_451_550.09765- SYNODIC_MONTH =
29.530588853- DERIVATIVE_HALF_WINDOW =
1.0 / 24.0
- ANGULAR_TOLERANCE =
1e-7- NEWTON_ATTEMPTS =
8
Class Method Summary collapse
- .clear_cache! ⇒ Object
- .new_moon_after(time) ⇒ Object
- .new_moon_before(time) ⇒ Object
- .new_moons(year, tz:) ⇒ Object
- .new_moons_for_calendar(calendar_year, tz:) ⇒ Object
Class Method Details
.clear_cache! ⇒ Object
54 55 56 57 58 59 |
# File 'lib/sekki24/lunar/phase_finder.rb', line 54 def clear_cache! @cache_mutex.synchronize do @root_cache.clear @year_cache.clear end end |
.new_moon_after(time) ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/sekki24/lunar/phase_finder.rb', line 45 def new_moon_after(time) raise TypeError, "expected Time, got #{time.class}" unless time.is_a?(Time) jde = TimeScale.utc_to_jde(time) lunation = ((jde - MEAN_NEW_MOON_EPOCH) / SYNODIC_MONTH).ceil root = root_for(lunation) root <= time ? root_for(lunation + 1) : root end |
.new_moon_before(time) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/sekki24/lunar/phase_finder.rb', line 36 def new_moon_before(time) raise TypeError, "expected Time, got #{time.class}" unless time.is_a?(Time) jde = TimeScale.utc_to_jde(time) lunation = ((jde - MEAN_NEW_MOON_EPOCH) / SYNODIC_MONTH).floor root = root_for(lunation) root > time ? root_for(lunation - 1) : root end |
.new_moons(year, tz:) ⇒ Object
19 20 21 22 |
# File 'lib/sekki24/lunar/phase_finder.rb', line 19 def new_moons(year, tz:) calendar_year = validate_year(year) new_moons_for_calendar(calendar_year, tz: tz) end |
.new_moons_for_calendar(calendar_year, tz:) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/sekki24/lunar/phase_finder.rb', line 24 def new_moons_for_calendar(calendar_year, tz:) cache_key = [calendar_year, TimeScale.timezone_key(tz)].freeze cached = @cache_mutex.synchronize { @year_cache[cache_key] } return cached if cached roots = roots_near_year(calendar_year).filter_map do |time| local = TimeScale.localize(time, tz) local.freeze if local.year == calendar_year end.freeze @cache_mutex.synchronize { @year_cache[cache_key] ||= roots } end |