<commit_before>#--
# Copyright (c) 2006  <NAME> 
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#++
module GPX

   # A segment is the basic container in a GPX file.  A Segment contains points
   # (in this lib, they're called TrackPoints).  A Track contains Segments.  An
   # instance of Segment knows its highest point, lowest point, earliest and
   # latest points, distance, and bounds.
   class Segment < Base

      attr_reader :earliest_point, :latest_point, :bounds, :highest_point, :lowest_point, :distance
      attr_accessor :points, :track 

      # If a REXML::Element object is passed-in, this will initialize a new
      # Segment based on its contents.  Otherwise, a blank Segment is created.
      def initialize(opts = {})
         @track = opts[:track]
         @points = []
         @earliest_point = nil
         @latest_point = nil
         @highest_point = nil
         @lowest_point = nil
         @distance = 0.0
         @bounds = Bounds.new
         if(opts[:element])
            segment_element = opts[:element]
            last_pt = nil
            unless segment_element.is_a?(Text)
               XPath.each(segment_element, "child::trkpt") do |trkpt| 
                  pt = TrackPoint.new(:element => trkpt, :segment => self)  
                  unless pt.time.nil?
                     @earliest_point = pt if(@earliest_point.nil? or pt.time < @earliest_point.time)
                     @latest_point   = pt if(@latest_point.nil? or pt.time > @latest_point.time)
                  end
                  unless pt.elevation.nil?
                     @lowest_point   = pt if(@lowest_point.nil? or pt.elevation < @lowest_point.elevation)
                     @highest_point  = pt if(@highest_point.nil? or pt.elevation > @highest_point.elevation)
                  end
                  @bounds.min_lat = pt.lat if pt.lat < @bounds.min_lat
                  @bounds.min_lon = pt.lon if pt.lon < @bounds.min_lon
                  @bounds.max_lat = pt.lat if pt.lat > @bounds.max_lat
                  @bounds.max_lon = pt.lon if pt.lon > @bounds.max_lon

                  @distance += haversine_distance(last_pt, pt) unless last_pt.nil?

                  @points << pt
                  last_pt  = pt
               end
            end
         end
      end

      # Tack on a point to this Segment.  All meta-data will be updated.
      def append_point(pt)
         last_pt = @points[-1]
         @earliest_point = pt if(@earliest_point.nil? or pt.time < @earliest_point.time)
         @latest_point   = pt if(@latest_point.nil? or pt.time > @latest_point.time)
         @lowest_point   = pt if(@lowest_point.nil? or pt.elevation < @lowest_point.elevation)
         @highest_point  = pt if(@highest_point.nil? or pt.elevation > @highest_point.elevation)
         @bounds.min_lat = pt.lat if pt.lat < @bounds.min_lat
         @bounds.min_lon = pt.lon if pt.lon < @bounds.min_lon
         @bounds.max_lat = pt.lat if pt.lat > @bounds.max_lat
         @bounds.max_lon = pt.lon if pt.lon > @bounds.max_lon
         @distance += haversine_distance(last_pt, pt) unless last_pt.nil?
         @points << pt
      end

      # Returns true if the given time is within this Segment.
      def contains_time?(time)
         (time >= @earliest_point.time and time <= @latest_point.time)
      end

      # Finds the closest point in time to the passed-in time argument.  Useful
      # for matching up time-based objects (photos, video, etc) with a
      # geographic location.
      def closest_point(time)<commit_msg>Fixing an exception in contains_time?.<commit_after>#--
# Copyright (c) 2006  <NAME> 
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#++
module GPX

   # A segment is the basic container in a GPX file.  A Segment contains points
   # (in this lib, they're called TrackPoints).  A Track contains Segments.  An
   # instance of Segment knows its highest point, lowest point, earliest and
   # latest points, distance, and bounds.
   class Segment < Base

      attr_reader :earliest_point, :latest_point, :bounds, :highest_point, :lowest_point, :distance
      attr_accessor :points, :track 

      # If a REXML::Element object is passed-in, this will initialize a new
      # Segment based on its contents.  Otherwise, a blank Segment is created.
      def initialize(opts = {})
         @track = opts[:track]
         @points = []
         @earliest_point = nil
         @latest_point = nil
         @highest_point = nil
         @lowest_point = nil
         @distance = 0.0
         @bounds = Bounds.new
         if(opts[:element])
            segment_element = opts[:element]
            last_pt = nil
            unless segment_element.is_a?(Text)
               XPath.each(segment_element, "child::trkpt") do |trkpt| 
                  pt = TrackPoint.new(:element => trkpt, :segment => self)  
                  unless pt.time.nil?
                     @earliest_point = pt if(@earliest_point.nil? or pt.time < @earliest_point.time)
                     @latest_point   = pt if(@latest_point.nil? or pt.time > @latest_point.time)
                  end
                  unless pt.elevation.nil?
                     @lowest_point   = pt if(@lowest_point.nil? or pt.elevation < @lowest_point.elevation)
                     @highest_point  = pt if(@highest_point.nil? or pt.elevation > @highest_point.elevation)
                  end
                  @bounds.min_lat = pt.lat if pt.lat < @bounds.min_lat
                  @bounds.min_lon = pt.lon if pt.lon < @bounds.min_lon
                  @bounds.max_lat = pt.lat if pt.lat > @bounds.max_lat
                  @bounds.max_lon = pt.lon if pt.lon > @bounds.max_lon

                  @distance += haversine_distance(last_pt, pt) unless last_pt.nil?

                  @points << pt
                  last_pt  = pt
               end
            end
         end
      end

      # Tack on a point to this Segment.  All meta-data will be updated.
      def append_point(pt)
         last_pt = @points[-1]
         @earliest_point = pt if(@earliest_point.nil? or pt.time < @earliest_point.time)
         @latest_point   = pt if(@latest_point.nil? or pt.time > @latest_point.time)
         @lowest_point   = pt if(@lowest_point.nil? or pt.elevation < @lowest_point.elevation)
         @highest_point  = pt if(@highest_point.nil? or pt.elevation > @highest_point.elevation)
         @bounds.min_lat = pt.lat if pt.lat < @bounds.min_lat
         @bounds.min_lon = pt.lon if pt.lon < @bounds.min_lon
         @bounds.max_lat = pt.lat if pt.lat > @bounds.max_lat
         @bounds.max_lon = pt.lon if pt.lon > @bounds.max_lon
         @distance += haversine_distance(last_pt, pt) unless last_pt.nil?
         @points << pt
      end

      # Returns true if the given time is within this Segment.
      def contains_time?(time)
         (time >= @earliest_point.time and time <= @latest_point.time) rescue false
      end

      # Finds the closest point in time to the passed-in time argument.  Useful
      # for matching up time-based objects (photos, video, etc) with a
      # geographic location.
      def closest_point(time)
{'fraction_non_alphanumeric': 0.08526453869698294, 'fraction_numerical': 0.001530389156099694, 'mean_word_length': 2.3785081240768093, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 27, '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': '1310857', 'n_tokens_mistral': 2713, 'n_tokens_neox': 2567, 'n_words': 911}