package com.mosty.sjzx.service.impl;

import com.mosty.base.model.dto.sjzx.BxdCreatedDto;
import com.mosty.base.model.dto.sjzx.NeighborDTO;
import com.mosty.base.utils.PositionUtil;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class DistanceRunnable implements Runnable {

    private BxdCreatedDto point;
    private List<BxdCreatedDto> points;
    private List<NeighborDTO> neighborList;
    private long scope;

    public DistanceRunnable(BxdCreatedDto point, List<BxdCreatedDto> points, List<NeighborDTO> neighborList, long scope) {
        super();
        this.point = point;
        this.points = points;
        this.neighborList = neighborList;
        this.scope = scope;
    }

    @Override
    public void run() {
        Map<BxdCreatedDto, Long> map = new HashMap<>();
        for (BxdCreatedDto point2 : points) {
            if (point.equals(point2)) {
                continue;
            }
            long distance = PositionUtil.getDistance(point.getWd().doubleValue(), point.getJd().doubleValue(),
                    point2.getWd().doubleValue(), point2.getJd().doubleValue());
            if (distance < scope) {
                map.put(point2, distance);
            }
        }
        neighborList.add(new NeighborDTO(point, map));
    }

}
