<commit_before>package com.njackson.gps;


import android.location.Location;
import android.net.Uri;
import android.util.Log;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;

import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.InputStreamReader;

import javax.inject.Singleton;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathFactory;

@Singleton
public class Navigator {

    private static final String TAG = "PB-Navigator";

    protected class Poi extends Location {
        public boolean seen = false;
        public float distance = 0;
        public int index = 0;

        public Poi(Location l) {
            super(l);
        }
    }

    Poi[] _pointsIni;
    private int _nbPointsIni = 0;
    Poi[] _pointsSimpl;
    private int _nbPointsSimpl = 0;
    private float _nextDistance = 0;
    private float _nextBearing = 0;
    private int _nextIndex = 0;
    private int _maxSeenIndex = -1;
    private float _error = 0;

    public Navigator() {
    }

    public void onLocationChanged(Location location) {
        if (_nbPointsIni == 0) {
            return;
        }
        Log.d(TAG, "onLocationChanged: lat:"+location.getLatitude()+",lon:"+location.getLongitude() + " nbPointsSimpl:" + _nbPointsSimpl);
        float minDist = 1000000;
        int minPoint = -1;
        float minBearing = 0;
        float minError = 0;
        for(int i = 0; i < _nbPointsSimpl; i++) {
            float dist = location.distanceTo(_pointsSimpl[i]);
            float bearing = (location.bearingTo(_pointsSimpl[i]) + 360) % 360;
            float error = i > 0 ? crossTrackError(_pointsSimpl[i-1], _pointsSimpl[i], location) : 0;
            Log.d(TAG, i + "[" + _pointsSimpl[i].index + "] dist:" + dist + " bearing:" + bearing + " error:" + error + " seen:" + (_pointsSimpl[i].seen ? "y" : "n"));
            if (dist < minDist && _maxSeenIndex < i) {
                minDist = dist;
                minPoint = i;<commit_msg>navigation: fix crash at the end<commit_after>package com.njackson.gps;


import android.location.Location;
import android.net.Uri;
import android.util.Log;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;

import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.InputStreamReader;

import javax.inject.Singleton;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathFactory;

@Singleton
public class Navigator {

    private static final String TAG = "PB-Navigator";

    protected class Poi extends Location {
        public boolean seen = false;
        public float distance = 0;
        public int index = 0;

        public Poi(Location l) {
            super(l);
        }
    }

    Poi[] _pointsIni;
    private int _nbPointsIni = 0;
    Poi[] _pointsSimpl;
    private int _nbPointsSimpl = 0;
    private float _nextDistance = 0;
    private float _nextBearing = 0;
    private int _nextIndex = 0;
    private int _maxSeenIndex = -1;
    private float _error = 0;

    public Navigator() {
    }

    public void onLocationChanged(Location location) {
        if (_nbPointsIni == 0) {
            return;
        }
        Log.d(TAG, "onLocationChanged: lat:"+location.getLatitude()+",lon:"+location.getLongitude() + " nbPointsSimpl:" + _nbPointsSimpl);
        float minDist = 1000000;
        int minPoint = 0;
        float minBearing = 0;
        float minError = 0;
        for(int i = 0; i < _nbPointsSimpl; i++) {
            float dist = location.distanceTo(_pointsSimpl[i]);
            float bearing = (location.bearingTo(_pointsSimpl[i]) + 360) % 360;
            float error = i > 0 ? crossTrackError(_pointsSimpl[i-1], _pointsSimpl[i], location) : 0;
            Log.d(TAG, i + "[" + _pointsSimpl[i].index + "] dist:" + dist + " bearing:" + bearing + " error:" + error + " seen:" + (_pointsSimpl[i].seen ? "y" : "n"));
            if (dist < minDist && _maxSeenIndex < i) {
                minDist = dist;
                minPoint = i;
{'fraction_non_alphanumeric': 0.11650045330915684, 'fraction_numerical': 0.015412511332728921, 'mean_word_length': 2.7750213857998287, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 12}, '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': '7052477', 'n_tokens_mistral': 1469, 'n_tokens_neox': 1388, 'n_words': 344}