package com.ltgk.boat.utils;


import com.ltgk.port.domain.vo.ParkedAreaForAppVO;
import net.sf.geographiclib.Geodesic;
import net.sf.geographiclib.GeodesicData;
import net.sf.geographiclib.GeodesicLine;
import net.sf.geographiclib.GeodesicMask;

import java.util.ArrayList;
import java.util.List;

/**
 * 计算大圆航线方法
 *
 * @author Qi ChengBin
 * @date 2025/05/26
 */
public class ComputeGreatCircle {

    /**
     * 根据起点的纬度、起点的经度  终点的纬度、终点的经度 和点位之间间隔的距离来计算两个点位之间的大圆航线
     *
     * @param lat1:     起点的纬度
     * @param lon1：     起点的经度
     * @param lat2：     终点的纬度
     * @param lon2：     终点的经度
     * @param interval： 间隔的距离
     * @return java.util.List<double [ ]>
     * @author Qi ChengBin
     * @date 2025/5/26
     */
    public static List<ParkedAreaForAppVO.Point> computeGreatCircle(double lat1, double lon1, double lat2, double lon2, double interval) {
        Geodesic geode = Geodesic.WGS84;
        GeodesicLine line = geode.InverseLine(lat1, lon1, lat2, lon2, GeodesicMask.ALL);

        List<ParkedAreaForAppVO.Point> pathPoint = new ArrayList<>();

        double totalDistance = line.Distance();  // ✅ 使用标准API获取总距离
        double step = Math.min(interval, totalDistance);

        for (double s = 0; s <= totalDistance; s += step) {
            GeodesicData pos = line.Position(s, GeodesicMask.LATITUDE | GeodesicMask.LONGITUDE);
            pathPoint.add(
                    new ParkedAreaForAppVO.Point()
                            .setLatitude(pos.lat2)
                            .setLongitude(pos.lon2));
        }
        return pathPoint;
    }
}
