<commit_before>module Tsuga::Model

  # Represents a position in the 0..1 x 0..1 square, modeling points on the
  # Earth as represented by their longitude/latitude coordinates.
  # 
  # Concretions have the following accessors:
  # - :geohash (64-bit integer)
  # 
  # - :lat (float, -90..90)
  # - :lng (float, -180..180)
  # 
  module PointTrait
    include Comparable

    def <=>(other)
      geohash <=> other.geohash
    end


    def distance_to(other)
      Math.sqrt((self.lat - other.lat) ** 2 + (self.lng - other.lng) ** 2)
    end


    def &(other)
      distance_to(other)
    end


    def geohash(autoupdate=true)
      autoupdate ? (super() || _update_geohash) : super()
    end


    def geohash=(value, dirty=true)
      self.lat = self.lng = nil if value && dirty
      super(value)
    end


    def lat(autoupdate=true)
      autoupdate ? (super() || _update_latlng.first) : super()
    end


    def lng(autoupdate=true)
      autoupdate ? (super() || _update_latlng.last) : super()
    end


    def lat=(value, dirty=true)
      self.geohash = nil if value && dirty
      super(value)
    end


    def lng=(value, dirty=true)
      self.geohash = nil if value && dirty
      super(value)
    end


    def set_coords(_lat, _lng)
      _validate_latlng(_lat, _lng)

      self.lat = _lat
      self.lng = _lng
      self
    end


    def inspect
      "<%s lat:%s lng:%s geohash:%s>" % [
        self.class.name.gsub(/.*::/, ''),
        lat(false) ? ("%.3f" % lat(false)) : 'nil',
        lng(false) ? ("%.3f" % lng(false)) : 'nil',
        geohash(false) ? ("%016x" % geohash(false)) : 'nil'
      ]
    end


    private


    def _validate_latlng(_lat, _lng)
      raise ArgumentError, 'bad lat' unless ( -90.0 ...  90.0).include?(_lat)
      raise ArgumentError, 'bad lng' unless (-180.0 ... 180.0).include?(_lng)
    end


    # Convert the geohash into lat/lng
    def _update_latlng<commit_msg>Fixes naming issue for tests<commit_after>module Tsuga::Model

  # Represents a position in the 0..1 x 0..1 square, modeling points on the
  # Earth as represented by their longitude/latitude coordinates.
  # 
  # Concretions have the following accessors:
  # - :geohash (64-bit integer)
  # 
  # - :lat (float, -90..90)
  # - :lng (float, -180..180)
  # 
  module PointTrait
    include Comparable

    def <=>(other)
      geohash <=> other.geohash
    end


    def distance_to(other)
      Math.sqrt((self.lat - other.lat) ** 2 + (self.lng - other.lng) ** 2)
    end


    def &(other)
      distance_to(other)
    end


    def geohash(autoupdate=true)
      autoupdate ? (super() || _update_geohash) : super()
    end


    def geohash=(value, dirty=true)
      self.lat = self.lng = nil if value && dirty
      super(value)
    end


    def lat(autoupdate=true)
      autoupdate ? (super() || _update_latlng.first) : super()
    end


    def lng(autoupdate=true)
      autoupdate ? (super() || _update_latlng.last) : super()
    end


    def lat=(value, dirty=true)
      self.geohash = nil if value && dirty
      super(value)
    end


    def lng=(value, dirty=true)
      self.geohash = nil if value && dirty
      super(value)
    end


    def set_coords(_lat, _lng)
      _validate_latlng(_lat, _lng)

      self.lat = _lat
      self.lng = _lng
      self
    end


    def inspect
      "<%s lat:%s lng:%s geohash:%s>" % [
        (self.class.name || 'Point').gsub(/.*::/, ''),
        lat(false) ? ("%.3f" % lat(false)) : 'nil',
        lng(false) ? ("%.3f" % lng(false)) : 'nil',
        geohash(false) ? ("%016x" % geohash(false)) : 'nil'
      ]
    end


    private


    def _validate_latlng(_lat, _lng)
      raise ArgumentError, 'bad lat' unless ( -90.0 ...  90.0).include?(_lat)
      raise ArgumentError, 'bad lng' unless (-180.0 ... 180.0).include?(_lng)
    end


    # Convert the geohash into lat/lng
    def _update_latlng
{'fraction_non_alphanumeric': 0.14204837879567678, 'fraction_numerical': 0.019042717447246525, 'mean_word_length': 2.2691337258200166, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '628532', 'n_tokens_mistral': 1489, 'n_tokens_neox': 1383, 'n_words': 338}