Class: Astronoby::Constellations::Finder

Inherits:
Object
  • Object
show all
Defined in:
lib/astronoby/constellations/finder.rb

Class Method Summary collapse

Class Method Details

.find(equatorial_coordinates) ⇒ Astronoby::Constellation?

Finds the constellation that contains the given B1875 equatorial

coordinates.

Parameters:

Returns:



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/astronoby/constellations/finder.rb', line 12

def self.find(equatorial_coordinates)
  ra_hours = equatorial_coordinates.right_ascension.hours
  dec_degrees = equatorial_coordinates.declination.degrees
  ra_index = Data
    .sorted_right_ascensions
    .bsearch_index { _1 >= ra_hours }
  dec_index = Data
    .sorted_declinations
    .bsearch_index { _1 > dec_degrees }

  return if ra_index.nil? || dec_index.nil?

  abbreviation_index = Data.radec_to_index.dig(ra_index, dec_index)

  return if abbreviation_index.nil?

  constellation_abbreviation =
    Data.indexed_abbreviations[abbreviation_index]

  Repository.get(constellation_abbreviation)
end