package com.ruoyi.bst.area.utils;

import java.math.BigDecimal;

import org.locationtech.jts.geom.Geometry;

import com.ruoyi.bst.area.domain.Area;
import com.ruoyi.bst.area.domain.AreaVO;
import com.ruoyi.common.utils.map.GeoUtils;

public class AreaUtil {


    // 是否在运营区内
    public static boolean isInArea(Area area, BigDecimal longitude, BigDecimal latitude) {
        Geometry geometry = GeoUtils.fromWkt(area.getBoundary());
        if (geometry == null) {
            return false;
        }
        return GeoUtils.isInPolygonWithTolerance(longitude, latitude, geometry, area.getOutageDistance());
    }

    // 是否在运营区最小内边界
    public static boolean isInAreaMin(AreaVO area, BigDecimal longitude, BigDecimal latitude) {
        if (area == null) {
            return false;
        }
        Geometry geometry = GeoUtils.fromWkt(area.getBoundary());
        if (geometry == null) {
            return false;
        }
        return GeoUtils.isInPolygonWithShorten(longitude, latitude, geometry, area.getBoundaryDistance());
    }

    // 是否在运营区最大外边界
    public static boolean isInAreaMax(AreaVO area, BigDecimal longitude, BigDecimal latitude) {
        if (area == null) {
            return false;
        }
        Geometry geometry = GeoUtils.fromWkt(area.getBoundary());
        if (geometry == null) {
            return false;
        }
        return GeoUtils.isInPolygonWithTolerance(longitude, latitude, geometry, area.getOutageDistance());
    }

}
