All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.openlr.encoder.PathSplitter Maven / Gradle / Ivy

The newest version!
package org.openlr.encoder;

import org.apache.commons.lang3.tuple.Pair;
import org.openlr.map.Line;
import org.openlr.map.MapOperations;
import org.openlr.map.Path;

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

class PathSplitter {
    private final IntermediateProcessor intermediateProcessor;
    private final MapOperations mapOperations;

    PathSplitter(IntermediateProcessor intermediateProcessor, MapOperations mapOperations) {
        this.intermediateProcessor = intermediateProcessor;
        this.mapOperations = mapOperations;
    }

    > List> split(Path path) {
        List> subPaths = new ArrayList<>();
        Path remaining = path;

        while (true) {
            OptionalDouble distanceToNext = intermediateProcessor.getDistanceToNext(remaining);

            if (distanceToNext.isEmpty()) {
                break;
            }

            Pair, Path> split = mapOperations.splitPath(remaining, distanceToNext.getAsDouble());

            subPaths.add(split.getLeft());
            remaining = split.getRight();
        }

        subPaths.add(remaining);

        return subPaths;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy