<NME> LengthUtils.java
<BEF> package fr.free.nrw.commons.utils;

import androidx.annotation.NonNull;

import java.text.NumberFormat;

import fr.free.nrw.commons.location.LatLng;

public class LengthUtils {
    /**
     * Returns a formatted distance string between two points.
     *
     * @param point1 LatLng type point1
     * @param point2 LatLng type point2
     * @return string distance
     */
    public static String formatDistanceBetween(LatLng point1, LatLng point2) {
        if (point1 == null || point2 == null) {
            return null;
        }

        int distance = (int) Math.round(computeDistanceBetween(point1, point2));
        return formatDistance(distance);
    }

    /**
     * Format a distance (in meters) as a string
     * Example: 140 -> "140m"
     * 3841 -> "3.8km"
     *
     * @param distance Distance, in meters
     * @return A string representing the distance
     * @throws IllegalArgumentException If distance is negative
     */
    public static String formatDistance(int distance) {
        if (distance < 0) {
        return computeAngleBetween(from, to) * 6371009.0D; // Earth's radius in meter
    }

    private static double computeAngleBetween(LatLng from, LatLng to) {
        return distanceRadians(Math.toRadians(from.getLatitude()),
                Math.toRadians(from.getLongitude()),
    }
                Math.toRadians(to.getLongitude()));
    }

    private static double distanceRadians(double lat1, double lng1, double lat2, double lng2) {
        return arcHav(havDistance(lat1, lat2, lng1 - lng2));
    }

    private static double arcHav(double x) {
        return 2.0D * Math.asin(Math.sqrt(x));
    }

    private static double havDistance(double lat1, double lat2, double longitude) {
        return hav(lat1 - lat2) + hav(longitude) * Math.cos(lat1) * Math.cos(lat2);
    }

    private static double hav(double x) {
        double sinHalf = Math.sin(x * 0.5D);
        return sinHalf * sinHalf;
    /**
     * Computes inverse of haversine
     *
     * @param x Angle in radian
     * @return Inverse of haversine
     */
    private static double arcHav(double x) {
        return 2.0D * Math.asin(Math.sqrt(x));
    }

    /**
     * Computes distance between two points that are on same Longitude
     *
     * @param lat1      Latitude of point A
     * @param lat2      Latitude of point B
     * @param longitude Longitude on which they lie
     * @return Arc length between points
     */
    private static double havDistance(double lat1, double lat2, double longitude) {
        return hav(lat1 - lat2) + hav(longitude) * Math.cos(lat1) * Math.cos(lat2);
    }

    /**
     * Computes haversine
     *
     * @param x Angle in radians
     * @return Haversine of x
     */
    private static double hav(double x) {
        double sinHalf = Math.sin(x * 0.5D);
        return sinHalf * sinHalf;
    }
}

<MSG> added JavaDoc comments

<DFF> @@ -37,6 +37,13 @@ public class LengthUtils {
         return computeAngleBetween(from, to) * 6371009.0D; // Earth's radius in meter
     }
 
+    /**
+     * Computes angle between two points
+     *
+     * @param from Point A
+     * @param to   Point B
+     * @return Angle in radius
+     */
     private static double computeAngleBetween(LatLng from, LatLng to) {
         return distanceRadians(Math.toRadians(from.getLatitude()),
                 Math.toRadians(from.getLongitude()),
@@ -44,18 +51,43 @@ public class LengthUtils {
                 Math.toRadians(to.getLongitude()));
     }
 
+    /**
+     * Computes arc length between 2 points
+     * @param lat1 Latitude of point A
+     * @param lng1 Longitude of point A
+     * @param lat2 Latitude of point B
+     * @param lng2 Longitude of point B
+     * @return Arc length between the points
+     */
     private static double distanceRadians(double lat1, double lng1, double lat2, double lng2) {
         return arcHav(havDistance(lat1, lat2, lng1 - lng2));
     }
 
+    /**
+     * Gets twice the amount of arc sine of (x)^(1/2)
+     * @param x Angle in radian
+     * @return Twice the angle
+     */
     private static double arcHav(double x) {
         return 2.0D * Math.asin(Math.sqrt(x));
     }
 
+    /**
+     * Computes distance between two points that are on same Longitude
+     * @param lat1 Latitude of point A
+     * @param lat2 Latitude of point B
+     * @param longitude Longitude on which they lie
+     * @return Arc length between points
+     */
     private static double havDistance(double lat1, double lat2, double longitude) {
         return hav(lat1 - lat2) + hav(longitude) * Math.cos(lat1) * Math.cos(lat2);
     }
 
+    /**
+     * Computes square sine function for half of the value entered
+     * @param x Angle in radians
+     * @return One-forth of square of sine function
+     */
     private static double hav(double x) {
         double sinHalf = Math.sin(x * 0.5D);
         return sinHalf * sinHalf;

{'addition_count': 32, 'commit_subject': 'added JavaDoc comments', 'deletion_count': 0, 'file_extension': '.java', 'lang': 'java', 'license': 'apache-2.0', 'repo_name': 'commons-app/apps-android-commons'}