<commit_before>/*
 * Java Genetic Algorithm Library (@__identifier__@).
 * Copyright (c) @__year__@ <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Author:
 *    <NAME> (<EMAIL>)
 */
package org.jenetics.example.tsp;

import static java.lang.Math.PI;
import static java.lang.Math.cos;
import static java.lang.Math.sin;
import static java.lang.String.format;

/**
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 * @version !__version__!
 * @since !__version__!
 */
public final class Location {

	// The earth radius used for calculating distances.
	private static final double R = 6_371_000.785;

	private final double _latitude;
	private final double _longitude;
	private static final double _height = 0;

	private Location(final double latitude, final double longitude) {
		_latitude = latitude;
		_longitude = longitude;
	}

	public double dist(final Location other) {
		final double phi1 = _latitude;
		final double theta1 = PI/2.0 - _latitude;
		final double r1 = R + _height;

		final double phi2 = other._latitude;
		final double theta2 = PI/2.0 - other._latitude;
		final double r2 = R + other._latitude;

		final double x1 = r1*sin(theta1)*cos(phi1);
		final double y1 = r1*sin(theta1)*sin(phi1);
		final double z1 = r1*cos(theta1);

		final double x2 = r2*sin(theta2)*cos(phi2);
		final double y2 = r2*sin(theta2)*sin(phi2);
		final double z2 = r2*cos(theta2);

		return Math.sqrt(
			(x1 - x2)*(x1 - x2) +
			(y1 - y2)*(y1 - y2) +
			(z1 - z2)*(z1 - z2)
		);<commit_msg>Add arithmetic methods to 'Location' class.<commit_after>/*
 * Java Genetic Algorithm Library (@__identifier__@).
 * Copyright (c) @__year__@ <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Author:
 *    <NAME> (<EMAIL>)
 */
package org.jenetics.example.tsp;

import static java.lang.Math.PI;
import static java.lang.Math.cos;
import static java.lang.Math.sin;
import static java.lang.String.format;

/**
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 * @version !__version__!
 * @since !__version__!
 */
public final class Location {

	// The earth radius used for calculating distances.
	private static final double R = 6_371_000.785;

	private final double _latitude;
	private final double _longitude;
	private static final double _height = 0;

	private Location(final double latitude, final double longitude) {
		_latitude = latitude;
		_longitude = longitude;
	}

	public Location minus(final Location other) {
		return Location.of(
			_latitude - other._latitude,
			_longitude - other._longitude
		);
	}

	public Location mult(final double factor) {
		return Location.of(_latitude*factor, _longitude*factor);
	}

	public double dist(final Location other) {
		final double phi1 = _latitude;
		final double theta1 = PI/2.0 - _latitude;
		final double r1 = R + _height;

		final double phi2 = other._latitude;
		final double theta2 = PI/2.0 - other._latitude;
		final double r2 = R + other._latitude;

		final double x1 = r1*sin(theta1)*cos(phi1);
		final double y1 = r1*sin(theta1)*sin(phi1);
		final double z1 = r1*cos(theta1);

		final double x2 = r2*sin(theta2)*cos(phi2);
		final double y2 = r2*sin(theta2)*sin(phi2);
		final double z2 = r2*cos(theta2);

		return Math.sqrt(
			(x1 - x2)*(x1 - x2) +
			(y1 - y2)*(y1 - y2) +
			(z1 - z2)*(z1 - z2)
		);
{'fraction_non_alphanumeric': 0.11302726637147519, 'fraction_numerical': 0.02749941738522489, 'mean_word_length': 3.7848383500557414, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1920476', 'n_tokens_mistral': 1487, 'n_tokens_neox': 1370, 'n_words': 468}