<commit_before>Meteor.methods({
	/* numVert: number of vertices
	 * vertices: array of vertices
	 * current: current location 
	 *
	 * Determines if a given Point is located within a polygon of n vertices
	 * Algorithm from http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html */
	pointIncluded: function(vertices, current) {
		included = false;
		numVert = vertices.length;

		// create arrays of the x and y coordinates of the polygon
		var xArray = [];
		for (var i = 0; i < numVert; i++) {
			xArray.push(vertices[i][0]);
		}
		
		var yArray = [];
		for (var i = 0; i < numVert; i++) {
			yArray.push(vertices[i][1]);
		}

		for (var i = 0, j = numVert - 1; i < numVert; j = i++) {
			if ((yArray[i] >= current.y) != (yArray[j] >= current.y) &&
				(current.x <= (xArray[j] - xArray[i]) * 
					(current.y - yArray[i]) / (yArray[j] - yArray[i]) +
					xArray[i])
				) {
				included = !included;

			}
		}
	
		return included;
	},

	/* Search through all locations to see where you are */
	searchLocations: function(current) {
		location = null;
		locatedHere = null;

		for (var i = 0; i < Locations.find().count(); i++) {
			// if the given Point is in the location, return the location
			Meteor.call("pointIncluded",
				Locations.find().fetch()[i].coordinates.coordinates[0],
				current,
				function(error, data) {
					if (error) {
						console.log(error);
					}
					else {
						locatedHere = data;
					}
			});
			
			
			if (locatedHere) {
				location = [Locations.find().fetch()[i], "in"];
				return location;
			}


		}
						
		if (!locatedHere) {
			var nearestPoint = CornerPoints.find({
				"coordinate":{
					$near: {
						$geometry: {
							type: "Point" ,
							"coordinates": [ current.y , current.x ]
						}
					}
				}
			});		
			var theNearest = nearestPoint.fetch()[0];
			console.log(nearestPoint.fetch());
			console.log(nearestPoint.fetch().length);
			var theNearestDistance = 1000000000;
			Meteor.call("distance",
				current,
				{"x":theNearest.coordinate.coordinates[0],"y":theNearest.coordinate.coordinates[1]},
				function(error,data) {
					if (error) {
						console.log(error);
					}
					else {
						//console.log("returned" + data);
						theNearestDistance = data;
						if (theNearestDistance < 1000000) {	
							console.log(Locations.findOne({"name":theNearest.name}));
							return [theNearest,"near",theNearestDistance];
						}
						else {
							console.log("off campus");
							return null;
						}
					}
				}
			);

		}
	},


	/* returns the distance between two points 
	* adapted from http://www.movable-type.co.uk/scripts/latlong.html */
	distance: function(start, end) {
		//console.log(JSON.stringify(start)+JSON.stringify(end));
		var R = 6371000; // metres

		var lat1 = start.x;
		var lat2 = end.x;
		var lon1 = start.y;
		var lon2 = end.y;

		var p1 = lat1 * (Math.PI / 180);
		var p2 = lat2 * (Math.PI / 180);
		var dp = (lat2-lat1) * (Math.PI / 180);<commit_msg>return the Location object<commit_after>Meteor.methods({
	/* numVert: number of vertices
	 * vertices: array of vertices
	 * current: current location 
	 *
	 * Determines if a given Point is located within a polygon of n vertices
	 * Algorithm from http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html */
	pointIncluded: function(vertices, current) {
		included = false;
		numVert = vertices.length;

		// create arrays of the x and y coordinates of the polygon
		var xArray = [];
		for (var i = 0; i < numVert; i++) {
			xArray.push(vertices[i][0]);
		}
		
		var yArray = [];
		for (var i = 0; i < numVert; i++) {
			yArray.push(vertices[i][1]);
		}

		for (var i = 0, j = numVert - 1; i < numVert; j = i++) {
			if ((yArray[i] >= current.y) != (yArray[j] >= current.y) &&
				(current.x <= (xArray[j] - xArray[i]) * 
					(current.y - yArray[i]) / (yArray[j] - yArray[i]) +
					xArray[i])
				) {
				included = !included;

			}
		}
	
		return included;
	},

	/* Search through all locations to see where you are */
	searchLocations: function(current) {
		location = null;
		locatedHere = null;

		for (var i = 0; i < Locations.find().count(); i++) {
			// if the given Point is in the location, return the location
			Meteor.call("pointIncluded",
				Locations.find().fetch()[i].coordinates.coordinates[0],
				current,
				function(error, data) {
					if (error) {
						console.log(error);
					}
					else {
						locatedHere = data;
					}
			});
			
			
			if (locatedHere) {
				location = [Locations.find().fetch()[i], "in"];
				return location;
			}


		}
						
		if (!locatedHere) {
			var nearestPoint = CornerPoints.find({
				"coordinate":{
					$near: {
						$geometry: {
							type: "Point" ,
							"coordinates": [ current.y , current.x ]
						}
					}
				}
			});		
			var theNearest = nearestPoint.fetch()[0];
			console.log(nearestPoint.fetch());
			console.log(nearestPoint.fetch().length);
			var theNearestDistance = 1000000000;
			Meteor.call("distance",
				current,
				{"x":theNearest.coordinate.coordinates[0],"y":theNearest.coordinate.coordinates[1]},
				function(error,data) {
					if (error) {
						console.log(error);
					}
					else {
						//console.log("returned" + data);
						theNearestDistance = data;
						if (theNearestDistance < 1000000) {	
							console.log(Locations.findOne({"name":theNearest.name}));
							return [Locations.findOne({"name":theNearest.name}),"near",theNearestDistance];
						}
						else {
							console.log("off campus");
							return null;
						}
					}
				}
			);

		}
	},


	/* returns the distance between two points 
	* adapted from http://www.movable-type.co.uk/scripts/latlong.html */
	distance: function(start, end) {
		//console.log(JSON.stringify(start)+JSON.stringify(end));
		var R = 6371000; // metres

		var lat1 = start.x;
		var lat2 = end.x;
		var lon1 = start.y;
		var lon2 = end.y;

		var p1 = lat1 * (Math.PI / 180);
		var p2 = lat2 * (Math.PI / 180);
		var dp = (lat2-lat1) * (Math.PI / 180);
{'fraction_non_alphanumeric': 0.1583082581076563, 'fraction_numerical': 0.01805416248746239, 'mean_word_length': 2.6085645355850424, 'pattern_counts': {'":': 11, '<': 15, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '61712', 'n_tokens_mistral': 2708, 'n_tokens_neox': 2037, 'n_words': 468}